Branch data Line data Source code
1 : : // $Id: Scope.h 6219 2008-10-01 05:39:07Z vern $
2 : : //
3 : : // See the file "COPYING" in the main distribution directory for copyright.
4 : :
5 : : #ifndef scope_h
6 : : #define scope_h
7 : :
8 : : #include <string>
9 : :
10 : : #include "Dict.h"
11 : : #include "Obj.h"
12 : : #include "BroList.h"
13 : : #include "TraverseTypes.h"
14 : :
15 : : class ID;
16 : : class BroType;
17 : : class ListVal;
18 : :
19 [ - + ][ # # ]: 65865 : declare(PDict,ID);
[ # # ]
20 : :
21 : : class Scope : public BroObj {
22 : : public:
23 : : Scope(ID* id);
24 : : ~Scope();
25 : :
26 : 55751 : ID* Lookup(const char* name) const { return local->Lookup(name); }
27 : 8932 : void Insert(const char* name, ID* id) { local->Insert(name, id); }
28 : 0 : ID* Remove(const char* name)
29 : : {
30 : 0 : HashKey key(name);
31 : 0 : return (ID*) local->Remove(&key);
32 : : }
33 : :
34 : 3578 : ID* ScopeID() const { return scope_id; }
35 : : BroType* ReturnType() const { return return_type; }
36 : :
37 : 4817 : int Length() const { return local->Length(); }
38 : 0 : PDict(ID)* Vars() const { return local; }
39 : :
40 : : ID* GenerateTemporary(const char* name);
41 : :
42 : 0 : PDict(ID)* GetIDs() const { return local; }
43 : :
44 : : // Returns the list of variables needing initialization, and
45 : : // removes it from this Scope.
46 : : id_list* GetInits();
47 : :
48 : : // Adds a variable to the list.
49 : 103 : void AddInit(ID* id) { inits->append(id); }
50 : :
51 : : void Describe(ODesc* d) const;
52 : :
53 : : TraversalCode Traverse(TraversalCallback* cb) const;
54 : :
55 : : protected:
56 : : ID* scope_id;
57 : : BroType* return_type;
58 : : PDict(ID)* local;
59 : : id_list* inits;
60 : : };
61 : :
62 : : extern const char* GLOBAL_MODULE_NAME;
63 : :
64 : : extern string extract_module_name(const char* name);
65 : : extern string normalized_module_name(const char* module_name); // w/o ::
66 : :
67 : : // Concatenates module_name::var_name unless var_name is already fully
68 : : // qualified, in which case it is returned unmodified.
69 : : extern string make_full_var_name(const char* module_name, const char* var_name);
70 : :
71 : : extern bool in_debug;
72 : :
73 : : // If no_global is true, don't search in the default "global" namespace.
74 : : extern ID* lookup_ID(const char* name, const char* module,
75 : : bool no_global = false);
76 : : extern ID* install_ID(const char* name, const char* module_name,
77 : : bool is_global, bool is_export);
78 : :
79 : : extern void push_scope(ID* id);
80 : : extern void push_existing_scope(Scope* scope);
81 : :
82 : : // Returns the one popped off; it's not deleted.
83 : : extern Scope* pop_scope();
84 : : extern Scope* current_scope();
85 : : extern Scope* global_scope();
86 : :
87 : : // Current module (identified by its name).
88 : : extern string current_module;
89 : :
90 : : #endif
|