00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef CBZ_SYMBOL_H
00038 #define CBZ_SYMBOL_H
00039
00040
00041
00042
00043
00044
00045 template <class T>
00046 class SymbolTable {
00047
00048 private:
00049
00050
00051 bool _is_nested;
00052
00053
00054
00055 typedef map<string,
00056 T,
00057 less< string > > scope;
00058
00059 typedef scope::iterator scope_p;
00060
00061 typedef list< scope * > table;
00062 typedef table::iterator table_p;
00063
00064 table _table;
00065
00066 virtual void shadow(T create, T shadowed) =0;
00067 virtual void notify_exit_scope(T dead) =0;
00068
00069 public:
00070
00071 SymbolTable(bool is_nested)
00072 : _is_nested(is_nested), _table()
00073 { _table.push_front(new scope()); }
00074
00075 ~SymbolTable();
00076
00077 void mark_nodes (void);
00078 void reset();
00079 T insert(const string & name, T sym);
00080 T lookup(const string & name);
00081 void print(FILE * out);
00082 string insert_unique(const string & root, T sym);
00083 void enter_scope();
00084 void exit_scope();
00085
00086 };
00087
00088
00089
00090
00091
00092 class Identifiers_table : public SymbolTable< declNode * > {
00093
00094 public:
00095
00096 Identifiers_table();
00097 bool is_a_type(const string & name);
00098
00099 private:
00100
00101 void shadow(declNode * create, declNode * shadowed);
00102 void notify_exit_scope(declNode * dead);
00103 };
00104
00105 class Labels_table : public SymbolTable< labelNode * > {
00106
00107 public:
00108
00109 Labels_table();
00110
00111 private:
00112
00113 void shadow(labelNode * create, labelNode * shadowed);
00114 void notify_exit_scope(labelNode * dead);
00115 };
00116
00117 class Tags_table : public SymbolTable< suespecNode * > {
00118
00119 public:
00120
00121 Tags_table();
00122
00123 private:
00124
00125 void shadow(suespecNode * create, suespecNode * shadowed);
00126 void notify_exit_scope(suespecNode * dead);
00127 };
00128
00129 class Externals_table : public SymbolTable< declNode * > {
00130
00131 public:
00132
00133 Externals_table();
00134
00135 private:
00136
00137 void shadow(declNode * create, declNode * shadowed);
00138 void notify_exit_scope(declNode * dead);
00139 };
00140
00141
00142
00143
00144
00145
00146 class Symbols {
00147
00148 public:
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 static bool TrackScopeExits;
00170 static bool TrackInsertSymbol;
00171 static bool TrackIds;
00172
00173 static int Level;
00174 };
00175
00176
00177 #endif // CBZ_SYMBOL_H