119 * own symbol tables, so do not get placed in this symbol table! |
119 * own symbol tables, so do not get placed in this symbol table! |
120 */ |
120 */ |
121 symbol_c null_symbol4; |
121 symbol_c null_symbol4; |
122 symtable_c<symbol_c *, &null_symbol4> type_symtable; |
122 symtable_c<symbol_c *, &null_symbol4> type_symtable; |
123 |
123 |
|
124 /* A symbol table with all values declared for enumerated type... */ |
|
125 /* Note that if the value is defined multiple times the value |
|
126 * is the null pointer. |
|
127 */ |
|
128 symtable_c<symbol_c *, &null_symbol4> enumerated_value_symtable; |
124 |
129 |
125 |
130 |
126 /***********************************************************************/ |
131 /***********************************************************************/ |
127 /***********************************************************************/ |
132 /***********************************************************************/ |
128 /***********************************************************************/ |
133 /***********************************************************************/ |
129 /***********************************************************************/ |
134 /***********************************************************************/ |
130 |
135 |
131 |
136 |
132 class populate_symtables_c: public iterator_visitor_c { |
137 class populate_symtables_c: public iterator_visitor_c { |
133 |
138 |
134 public: |
139 private: |
135 populate_symtables_c(void) {}; |
140 symbol_c *current_enumerated_type; |
|
141 |
|
142 public: |
|
143 populate_symtables_c(void) { |
|
144 current_enumerated_type = NULL; |
|
145 }; |
136 virtual ~populate_symtables_c(void) {} |
146 virtual ~populate_symtables_c(void) {} |
137 |
147 |
138 |
148 |
139 public: |
149 public: |
140 |
150 |
185 |
195 |
186 /* enumerated_type_name ':' enumerated_spec_init */ |
196 /* enumerated_type_name ':' enumerated_spec_init */ |
187 void *visit(enumerated_type_declaration_c *symbol) { |
197 void *visit(enumerated_type_declaration_c *symbol) { |
188 TRACE("enumerated_type_declaration_c"); |
198 TRACE("enumerated_type_declaration_c"); |
189 type_symtable.insert(symbol->enumerated_type_name, symbol->enumerated_spec_init); |
199 type_symtable.insert(symbol->enumerated_type_name, symbol->enumerated_spec_init); |
190 return NULL; |
200 current_enumerated_type = symbol->enumerated_type_name; |
191 } |
201 symbol->enumerated_spec_init->accept(*this); |
192 |
202 current_enumerated_type = NULL; |
|
203 return NULL; |
|
204 } |
|
205 |
|
206 /* enumerated_specification ASSIGN enumerated_value */ |
|
207 void *visit(enumerated_spec_init_c *symbol) { |
|
208 return symbol->enumerated_specification->accept(*this); |
|
209 } |
|
210 |
|
211 /* [enumerated_type_name '#'] identifier */ |
|
212 void *visit(enumerated_value_c *symbol) { |
|
213 if (current_enumerated_type != NULL) { |
|
214 if (symbol->type != NULL) ERROR; |
|
215 |
|
216 symbol_c *value_type = enumerated_value_symtable.find_value(symbol->value); |
|
217 if (value_type == current_enumerated_type) ERROR; |
|
218 |
|
219 if (value_type == enumerated_value_symtable.end_value()) |
|
220 enumerated_value_symtable.insert(symbol->value, current_enumerated_type); |
|
221 else if (value_type != NULL) |
|
222 enumerated_value_symtable.set(symbol->value, NULL); |
|
223 } |
|
224 return NULL; |
|
225 } |
193 |
226 |
194 /* identifier ':' array_spec_init */ |
227 /* identifier ':' array_spec_init */ |
195 void *visit(array_type_declaration_c *symbol) { |
228 void *visit(array_type_declaration_c *symbol) { |
196 TRACE("array_type_declaration_c"); |
229 TRACE("array_type_declaration_c"); |
197 type_symtable.insert(symbol->identifier, symbol->array_spec_init); |
230 type_symtable.insert(symbol->identifier, symbol->array_spec_init); |