Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/tools/build/jam_src/modules.c @ 12

Last change on this file since 12 was 12, checked in by landauf, 18 years ago

added boost

File size: 3.1 KB
Line 
1/*
2 *  Copyright 2001-2004 David Abrahams.
3 *  Distributed under the Boost Software License, Version 1.0.
4 *  (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
5 */
6#include "modules.h"
7#include "jam.h"
8#include "string.h"
9#include "hash.h"
10#include "newstr.h"
11#include "lists.h"
12#include "parse.h"
13#include "rules.h"
14#include "variable.h"
15#include "strings.h"
16#include <assert.h>
17
18static struct hash* module_hash = 0;
19
20static char* new_module_str( module_t* m, char* suffix )
21{
22    char* result;
23    string s;
24    string_copy( &s, m->name );
25    string_append( &s, suffix );
26    result = newstr( s.value );
27    string_free( &s );
28    return result;
29}
30
31module_t* bindmodule( char* name )
32{
33    string s;
34    module_t m_, *m = &m_;
35
36    if( !module_hash )
37        module_hash = hashinit( sizeof( module_t ), "modules" );
38
39    string_new( &s );
40    if (name)
41    {
42        string_append( &s, name );
43        string_push_back( &s, '.' );
44    }
45       
46    m->name = s.value;
47   
48    if ( hashenter( module_hash, (HASHDATA **)&m ) )
49    {
50        m->name = newstr( m->name );
51        m->variables = 0;
52        m->rules = 0;
53        m->imported_modules = 0;
54        m->class_module = 0;
55        m->native_rules = 0;
56        m->user_module = 0;
57    }
58    string_free( &s );
59    return m;
60}
61
62/*
63 * demand_rules() - Get the module's "rules" hash on demand
64 */
65struct hash* demand_rules( module_t* m )
66{
67    if ( !m->rules )
68        m->rules = hashinit( sizeof( RULE ), new_module_str( m, "rules" ) );
69    return m->rules;
70}
71
72/*
73 * delete_module() - wipe out the module's rules and variables
74 */
75static void delete_rule_( void* xrule, void* data )
76{
77    rule_free( (RULE*)xrule );
78}
79
80void delete_module( module_t* m )
81{
82    /* clear out all the rules */
83    if ( m->rules )
84    {
85        hashenumerate( m->rules, delete_rule_, (void*)0 );
86        hashdone( m->rules );
87        m->rules = 0;
88    }
89
90    if ( m->variables )
91    {
92        var_hash_swap( &m->variables );
93        var_done();
94        var_hash_swap( &m->variables );
95        m->variables = 0;
96    }
97}
98
99module_t* root_module()
100{
101    static module_t* root = 0;
102    if ( !root )
103        root = bindmodule(0);
104    return root;
105}
106
107void enter_module( module_t* m )
108{
109    var_hash_swap( &m->variables );
110}
111
112void exit_module( module_t* m )
113{
114    var_hash_swap( &m->variables );
115}
116
117void import_module(LIST* module_names, module_t* target_module)
118{ 
119    struct hash* h;
120
121    if (!target_module->imported_modules)
122        target_module->imported_modules = hashinit( sizeof(char*), "imported");
123    h = target_module->imported_modules;
124
125    for(;module_names; module_names = module_names->next) {
126       
127        char* s = module_names->string;
128        char** ss = &s;
129       
130        hashenter(h, (HASHDATA**)&ss);
131    }
132}
133
134static void add_module_name( void* r_, void* result_ )
135{
136    char** r = (char**)r_;
137    LIST** result = (LIST**)result_;
138
139    *result = list_new( *result, copystr( *r ) );
140}
141
142LIST* imported_modules(module_t* module)
143{
144    LIST *result = L0;
145
146    if ( module->imported_modules )
147        hashenumerate( module->imported_modules, add_module_name, &result );
148
149    return result;
150}
Note: See TracBrowser for help on using the repository browser.