133 /* The global symbol tables... */ |
133 /* The global symbol tables... */ |
134 /*********************************/ |
134 /*********************************/ |
135 /* NOTE: only accessed indirectly by the lexical parser (flex) |
135 /* NOTE: only accessed indirectly by the lexical parser (flex) |
136 * through the function get_identifier_token() |
136 * through the function get_identifier_token() |
137 */ |
137 */ |
138 /* NOTE: BOGUS_TOKEN_ID is defined in the bison generated file iec_bison.hh. |
|
139 * We need this constant defined before we can declare the symbol tables. |
|
140 * However, we cannot #include "iec_bison.hh" in this file (stage1_2_priv.hh) directly |
|
141 * because of the way bison ver. 3.2 is copying all declarations in the prologue |
|
142 * of iec.y to the iec_bison.hh file (including an #include stage1_2_priv.hh). |
|
143 * So, if we were to include "iec_bison.hh" here, we would get a circular include. |
|
144 * All this means that whoever includes this file (stage1_2_priv.hh) will need |
|
145 * to take care to first inlcude iec_bison.hh !! |
|
146 */ |
|
147 /* A symbol table to store all the library elements */ |
138 /* A symbol table to store all the library elements */ |
148 /* e.g.: <function_name , function_decl> |
139 /* e.g.: <function_name , function_decl> |
149 * <fb_name , fb_decl> |
140 * <fb_name , fb_decl> |
150 * <type_name , type_decl> |
141 * <type_name , type_decl> |
151 * <program_name , program_decl> |
142 * <program_name , program_decl> |
152 * <configuration_name , configuration_decl> |
143 * <configuration_name , configuration_decl> |
153 */ |
144 */ |
154 /* static */ symtable_c<int, BOGUS_TOKEN_ID> library_element_symtable; |
145 /* static */ library_element_symtable_t library_element_symtable; |
155 |
146 |
156 /* A symbol table to store the declared variables of |
147 /* A symbol table to store the declared variables of |
157 * the function currently being parsed... |
148 * the function currently being parsed... |
158 */ |
149 */ |
159 /* static */ symtable_c<int, BOGUS_TOKEN_ID> variable_name_symtable; |
150 /* static */ variable_name_symtable_t variable_name_symtable; |
160 |
151 |
161 /* A symbol table to store the declared direct variables of |
152 /* A symbol table to store the declared direct variables of |
162 * the function currently being parsed... |
153 * the function currently being parsed... |
163 */ |
154 */ |
164 /* static */ symtable_c<int, BOGUS_TOKEN_ID> direct_variable_symtable; |
155 /* static */ direct_variable_symtable_t direct_variable_symtable; |
165 |
156 |
166 /* Function only called from within flex! |
157 /* Function only called from within flex! |
167 * |
158 * |
168 * search for a symbol in either of the two symbol tables |
159 * search for a symbol in either of the two symbol tables |
169 * declared above, and return the token id of the first |
160 * declared above, and return the token id of the first |
171 * Searches first in the variables, and only if not found |
162 * Searches first in the variables, and only if not found |
172 * does it continue searching in the library elements |
163 * does it continue searching in the library elements |
173 */ |
164 */ |
174 int get_identifier_token(const char *identifier_str) { |
165 int get_identifier_token(const char *identifier_str) { |
175 // std::cout << "get_identifier_token(" << identifier_str << "): \n"; |
166 // std::cout << "get_identifier_token(" << identifier_str << "): \n"; |
176 int token_id; |
167 variable_name_symtable_t ::iterator iter1; |
177 |
168 library_element_symtable_t::iterator iter2; |
178 if ((token_id = variable_name_symtable.find_value(identifier_str)) == variable_name_symtable.end_value()) |
169 |
179 if ((token_id = library_element_symtable.find_value(identifier_str)) == library_element_symtable.end_value()) |
170 if ((iter1 = variable_name_symtable.find(identifier_str)) != variable_name_symtable.end()) |
180 return identifier_token; |
171 return iter1->second; |
181 return token_id; |
172 |
|
173 if ((iter2 = library_element_symtable.find(identifier_str)) != library_element_symtable.end()) |
|
174 return iter2->second; |
|
175 |
|
176 return identifier_token; |
182 } |
177 } |
183 |
178 |
184 /* Function only called from within flex! |
179 /* Function only called from within flex! |
185 * |
180 * |
186 * search for a symbol in direct variables symbol table |
181 * search for a symbol in direct variables symbol table |
187 * declared above, and return the token id of the first |
182 * declared above, and return the token id of the first |
188 * symbol found. |
183 * symbol found. |
189 */ |
184 */ |
190 int get_direct_variable_token(const char *direct_variable_str) { |
185 int get_direct_variable_token(const char *direct_variable_str) { |
191 int token_id; |
186 direct_variable_symtable_t::iterator iter; |
192 |
187 |
193 if ((token_id = direct_variable_symtable.find_value(direct_variable_str)) == direct_variable_symtable.end_value()) |
188 if ((iter = direct_variable_symtable.find(direct_variable_str)) != direct_variable_symtable.end()) |
194 return direct_variable_token; |
189 return iter->second; |
195 return token_id; |
190 |
|
191 return direct_variable_token; |
196 } |
192 } |
197 |
193 |
198 /************************/ |
194 /************************/ |
199 /* Utility Functions... */ |
195 /* Utility Functions... */ |
200 /************************/ |
196 /************************/ |