52 /* pointer to singleton instance */ |
52 /* pointer to singleton instance */ |
53 search_base_type_c *search_base_type_c::search_base_type_singleton = NULL; |
53 search_base_type_c *search_base_type_c::search_base_type_singleton = NULL; |
54 |
54 |
55 |
55 |
56 |
56 |
57 search_base_type_c::search_base_type_c(void) {current_type_name = NULL; current_basetype = NULL;} |
57 search_base_type_c::search_base_type_c(void) {current_basetype_name = NULL; current_basetype = NULL; current_equivtype = NULL;} |
58 |
58 |
59 /* static method! */ |
59 /* static method! */ |
60 void search_base_type_c::create_singleton(void) { |
60 void search_base_type_c::create_singleton(void) { |
61 if (NULL == search_base_type_singleton) search_base_type_singleton = new search_base_type_c(); |
61 if (NULL == search_base_type_singleton) search_base_type_singleton = new search_base_type_c(); |
62 if (NULL == search_base_type_singleton) ERROR; |
62 if (NULL == search_base_type_singleton) ERROR; |
63 } |
63 } |
64 |
64 |
65 /* static method! */ |
65 /* static method! */ |
|
66 symbol_c *search_base_type_c::get_equivtype_decl(symbol_c *symbol) { |
|
67 create_singleton(); |
|
68 if (NULL == symbol) return NULL; |
|
69 search_base_type_singleton->current_basetype_name = NULL; |
|
70 search_base_type_singleton->current_basetype = NULL; |
|
71 search_base_type_singleton->current_equivtype = NULL; |
|
72 symbol_c *basetype = (symbol_c *)symbol->accept(*search_base_type_singleton); |
|
73 if (NULL != search_base_type_singleton->current_equivtype) |
|
74 return search_base_type_singleton->current_equivtype; |
|
75 return basetype; |
|
76 } |
|
77 |
|
78 /* static method! */ |
66 symbol_c *search_base_type_c::get_basetype_decl(symbol_c *symbol) { |
79 symbol_c *search_base_type_c::get_basetype_decl(symbol_c *symbol) { |
67 create_singleton(); |
80 create_singleton(); |
68 if (NULL == symbol) return NULL; |
81 if (NULL == symbol) return NULL; |
69 search_base_type_singleton->current_type_name = NULL; |
82 search_base_type_singleton->current_basetype_name = NULL; |
70 search_base_type_singleton->current_basetype = NULL; |
83 search_base_type_singleton->current_basetype = NULL; |
|
84 search_base_type_singleton->current_equivtype = NULL; |
71 return (symbol_c *)symbol->accept(*search_base_type_singleton); |
85 return (symbol_c *)symbol->accept(*search_base_type_singleton); |
72 } |
86 } |
73 |
87 |
74 /* static method! */ |
88 /* static method! */ |
75 symbol_c *search_base_type_c::get_basetype_id (symbol_c *symbol) { |
89 symbol_c *search_base_type_c::get_basetype_id (symbol_c *symbol) { |
76 create_singleton(); |
90 create_singleton(); |
77 if (NULL == symbol) return NULL; |
91 if (NULL == symbol) return NULL; |
78 search_base_type_singleton->current_type_name = NULL; |
92 search_base_type_singleton->current_basetype_name = NULL; |
79 search_base_type_singleton->current_basetype = NULL; |
93 search_base_type_singleton->current_basetype = NULL; |
|
94 search_base_type_singleton->current_equivtype = NULL; |
80 symbol->accept(*search_base_type_singleton); |
95 symbol->accept(*search_base_type_singleton); |
81 return (symbol_c *)search_base_type_singleton->current_type_name; |
96 return (symbol_c *)search_base_type_singleton->current_basetype_name; |
82 } |
97 } |
83 |
98 |
84 |
99 |
85 |
100 |
86 /*************************/ |
101 /*************************/ |
91 /* B 1.1 - Letters, digits and identifiers */ |
106 /* B 1.1 - Letters, digits and identifiers */ |
92 /*******************************************/ |
107 /*******************************************/ |
93 void *search_base_type_c::visit(identifier_c *type_name) { |
108 void *search_base_type_c::visit(identifier_c *type_name) { |
94 symbol_c *type_decl; |
109 symbol_c *type_decl; |
95 |
110 |
96 this->current_type_name = type_name; |
111 this->current_basetype_name = type_name; |
97 /* if we have reached this point, it is because the current_basetype is not yet pointing to the base datatype we are looking for, |
112 /* if we have reached this point, it is because the current_basetype is not yet pointing to the base datatype we are looking for, |
98 * so we will be searching for the delcaration of the type named in type_name, which might be the base datatype (we search recursively!) |
113 * so we will be searching for the delcaration of the type named in type_name, which might be the base datatype (we search recursively!) |
99 */ |
114 */ |
100 this->current_basetype = NULL; |
115 this->current_basetype = NULL; |
101 |
116 |
208 return symbol->simple_specification->accept(*this); |
223 return symbol->simple_specification->accept(*this); |
209 } |
224 } |
210 |
225 |
211 /* subrange_type_name ':' subrange_spec_init */ |
226 /* subrange_type_name ':' subrange_spec_init */ |
212 void *search_base_type_c::visit(subrange_type_declaration_c *symbol) { |
227 void *search_base_type_c::visit(subrange_type_declaration_c *symbol) { |
|
228 this->current_equivtype = symbol; |
213 return symbol->subrange_spec_init->accept(*this); |
229 return symbol->subrange_spec_init->accept(*this); |
214 } |
230 } |
215 |
231 |
216 /* subrange_specification ASSIGN signed_integer */ |
232 /* subrange_specification ASSIGN signed_integer */ |
217 void *search_base_type_c::visit(subrange_spec_init_c *symbol) { |
233 void *search_base_type_c::visit(subrange_spec_init_c *symbol) { |
|
234 if (NULL == this->current_equivtype) |
|
235 this->current_equivtype = symbol; |
218 return symbol->subrange_specification->accept(*this); |
236 return symbol->subrange_specification->accept(*this); |
219 } |
237 } |
220 |
238 |
221 /* integer_type_name '(' subrange')' */ |
239 /* integer_type_name '(' subrange')' */ |
222 void *search_base_type_c::visit(subrange_specification_c *symbol) { |
240 void *search_base_type_c::visit(subrange_specification_c *symbol) { |
|
241 if (NULL == this->current_equivtype) |
|
242 this->current_equivtype = symbol; |
223 return symbol->integer_type_name->accept(*this); |
243 return symbol->integer_type_name->accept(*this); |
224 } |
244 } |
225 |
245 |
226 /* signed_integer DOTDOT signed_integer */ |
246 /* signed_integer DOTDOT signed_integer */ |
227 void *search_base_type_c::visit(subrange_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
247 void *search_base_type_c::visit(subrange_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
228 |
248 |
229 /* enumerated_type_name ':' enumerated_spec_init */ |
249 /* enumerated_type_name ':' enumerated_spec_init */ |
230 void *search_base_type_c::visit(enumerated_type_declaration_c *symbol) { |
250 void *search_base_type_c::visit(enumerated_type_declaration_c *symbol) { |
231 this->current_type_name = symbol->enumerated_type_name; |
251 this->current_basetype_name = symbol->enumerated_type_name; |
232 /* NOTE: We want search_base_type_c to return a enumerated_type_declaration_c as the base datatpe if possible |
252 /* NOTE: We want search_base_type_c to return a enumerated_type_declaration_c as the base datatpe if possible |
233 * (i.e. if it is a named datatype declared inside a TYPE ... END_TYPE declarations, as opposed to an |
253 * (i.e. if it is a named datatype declared inside a TYPE ... END_TYPE declarations, as opposed to an |
234 * anonymous datatype declared in a VAR ... AND_VAR declaration). |
254 * anonymous datatype declared in a VAR ... AND_VAR declaration). |
235 * However, we cannot return this symbol just yet, as it may not be the final base datatype. |
255 * However, we cannot return this symbol just yet, as it may not be the final base datatype. |
236 * So we store it in a temporary current_basetype variable! |
256 * So we store it in a temporary current_basetype variable! |
264 // SYM_REF2(enumerated_value_c, type, value) |
284 // SYM_REF2(enumerated_value_c, type, value) |
265 void *search_base_type_c::visit(enumerated_value_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
285 void *search_base_type_c::visit(enumerated_value_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
266 |
286 |
267 /* identifier ':' array_spec_init */ |
287 /* identifier ':' array_spec_init */ |
268 void *search_base_type_c::visit(array_type_declaration_c *symbol) { |
288 void *search_base_type_c::visit(array_type_declaration_c *symbol) { |
269 this->current_type_name = symbol->identifier; |
289 this->current_basetype_name = symbol->identifier; |
270 return symbol->array_spec_init->accept(*this); |
290 return symbol->array_spec_init->accept(*this); |
271 } |
291 } |
272 |
292 |
273 /* array_specification [ASSIGN array_initialization} */ |
293 /* array_specification [ASSIGN array_initialization} */ |
274 /* array_initialization may be NULL ! */ |
294 /* array_initialization may be NULL ! */ |
301 * initialized_structure_c |
321 * initialized_structure_c |
302 * OR A |
322 * OR A |
303 * structure_element_declaration_list_c |
323 * structure_element_declaration_list_c |
304 */ |
324 */ |
305 void *search_base_type_c::visit(structure_type_declaration_c *symbol) { |
325 void *search_base_type_c::visit(structure_type_declaration_c *symbol) { |
306 this->current_type_name = symbol->structure_type_name; |
326 this->current_basetype_name = symbol->structure_type_name; |
307 return symbol->structure_specification->accept(*this); |
327 return symbol->structure_specification->accept(*this); |
308 } |
328 } |
309 |
329 |
310 /* var1_list ':' structure_type_name */ |
330 /* var1_list ':' structure_type_name */ |
311 void *search_base_type_c::visit(structured_var_declaration_c *symbol) { |
331 void *search_base_type_c::visit(structured_var_declaration_c *symbol) { |
368 /* B.1.6 Sequential function chart elements */ |
388 /* B.1.6 Sequential function chart elements */ |
369 /*********************************************/ |
389 /*********************************************/ |
370 /* INITIAL_STEP step_name ':' action_association_list END_STEP */ |
390 /* INITIAL_STEP step_name ':' action_association_list END_STEP */ |
371 // SYM_REF2(initial_step_c, step_name, action_association_list) |
391 // SYM_REF2(initial_step_c, step_name, action_association_list) |
372 void *search_base_type_c::visit(initial_step_c *symbol) { |
392 void *search_base_type_c::visit(initial_step_c *symbol) { |
373 this->current_type_name = NULL; /* this pseudo data type does not have a type name! */ |
393 this->current_basetype_name = NULL; /* this pseudo data type does not have a type name! */ |
374 return (void *)symbol; |
394 return (void *)symbol; |
375 } |
395 } |
376 |
396 |
377 /* STEP step_name ':' action_association_list END_STEP */ |
397 /* STEP step_name ':' action_association_list END_STEP */ |
378 // SYM_REF2(step_c, step_name, action_association_list) |
398 // SYM_REF2(step_c, step_name, action_association_list) |
379 void *search_base_type_c::visit(step_c *symbol) { |
399 void *search_base_type_c::visit(step_c *symbol) { |
380 this->current_type_name = NULL; /* this pseudo data type does not have a type name! */ |
400 this->current_basetype_name = NULL; /* this pseudo data type does not have a type name! */ |
381 return (void *)symbol; |
401 return (void *)symbol; |
382 } |
402 } |
383 |
403 |