44 * |
44 * |
45 * Note that a FB declaration is also considered a base type, as |
45 * Note that a FB declaration is also considered a base type, as |
46 * we may have FB instances declared of a specific FB type. |
46 * we may have FB instances declared of a specific FB type. |
47 */ |
47 */ |
48 #include "absyntax_utils.hh" |
48 #include "absyntax_utils.hh" |
49 |
49 #include "../main.hh" // required for ERROR() and ERROR_MSG() macros. |
50 #define ERROR error_exit(__FILE__,__LINE__) |
|
51 /* function defined in main.cc */ |
|
52 extern void error_exit(const char *file_name, int line_no); |
|
53 |
50 |
54 |
51 |
55 |
52 |
56 search_base_type_c::search_base_type_c(void) {current_type_name = NULL;} |
53 search_base_type_c::search_base_type_c(void) {current_type_name = NULL;} |
57 |
54 |
58 void *search_base_type_c::visit(identifier_c *type_name) { |
55 |
59 this->current_type_name = type_name; |
56 |
60 /* look up the type declaration... */ |
57 |
61 symbol_c *type_decl = type_symtable.find_value(type_name); |
58 symbol_c *search_base_type_c::get_basetype_decl(symbol_c *symbol) { |
62 if (type_decl == type_symtable.end_value()) |
59 if (NULL == symbol) |
63 /* Type declaration not found!! */ |
60 return NULL; |
64 ERROR; |
61 |
65 |
62 return (symbol_c *)symbol->accept(*this); |
66 return type_decl->accept(*this); |
63 } |
67 } |
64 |
|
65 symbol_c *search_base_type_c::get_basetype_id (symbol_c *symbol) { |
|
66 if (NULL == symbol) |
|
67 return NULL; |
|
68 |
|
69 current_type_name = NULL; /* just to be on the safe side... */ |
|
70 symbol->accept(*this); |
|
71 return (symbol_c *)current_type_name; |
|
72 } |
|
73 |
|
74 |
|
75 /* Note by MJS: The following two functions definately do not belong in this class!! Maybe create a new utility class? |
|
76 * I will need to clean this up when the opportunity arises! |
|
77 */ |
68 |
78 |
69 bool search_base_type_c::type_is_subrange(symbol_c* type_decl) { |
79 bool search_base_type_c::type_is_subrange(symbol_c* type_decl) { |
70 this->is_subrange = false; |
80 this->is_subrange = false; |
71 type_decl->accept(*this); |
81 type_decl->accept(*this); |
72 return this->is_subrange; |
82 return this->is_subrange; |
75 bool search_base_type_c::type_is_enumerated(symbol_c* type_decl) { |
85 bool search_base_type_c::type_is_enumerated(symbol_c* type_decl) { |
76 this->is_enumerated = false; |
86 this->is_enumerated = false; |
77 type_decl->accept(*this); |
87 type_decl->accept(*this); |
78 return this->is_enumerated; |
88 return this->is_enumerated; |
79 } |
89 } |
|
90 |
|
91 |
|
92 /*************************/ |
|
93 /* B.1 - Common elements */ |
|
94 /*************************/ |
|
95 |
|
96 /*******************************************/ |
|
97 /* B 1.1 - Letters, digits and identifiers */ |
|
98 /*******************************************/ |
|
99 void *search_base_type_c::visit(identifier_c *type_name) { |
|
100 symbol_c *type_decl; |
|
101 |
|
102 this->current_type_name = type_name; |
|
103 |
|
104 /* look up the type declaration... */ |
|
105 type_decl = type_symtable.find_value(type_name); |
|
106 if (type_decl != type_symtable.end_value()) |
|
107 return type_decl->accept(*this); |
|
108 |
|
109 type_decl = function_block_type_symtable.find_value(type_name); |
|
110 if (type_decl != function_block_type_symtable.end_value()) |
|
111 return type_decl->accept(*this); |
|
112 |
|
113 /* Type declaration not found!! */ |
|
114 ERROR; |
|
115 |
|
116 return NULL; |
|
117 } |
|
118 |
80 |
119 |
81 /*********************/ |
120 /*********************/ |
82 /* B 1.2 - Constants */ |
121 /* B 1.2 - Constants */ |
83 /*********************/ |
122 /*********************/ |
84 |
123 |
90 * they can be resolved (for example, when using '30+x' where 'x' is a LINT variable, the |
129 * they can be resolved (for example, when using '30+x' where 'x' is a LINT variable, the |
91 * numeric literal '30' must then be considered a LINT so the ADD function may be called |
130 * numeric literal '30' must then be considered a LINT so the ADD function may be called |
92 * with all inputs of the same data type. |
131 * with all inputs of the same data type. |
93 * If 'x' were a SINT, then the '30' would have to be a SINT too! |
132 * If 'x' were a SINT, then the '30' would have to be a SINT too! |
94 */ |
133 */ |
95 void *search_base_type_c::visit(real_c *symbol) {return (void *)symbol;} |
134 void *search_base_type_c::visit(real_c *symbol) {return (void *)symbol;} |
96 void *search_base_type_c::visit(neg_real_c *symbol) {return (void *)symbol;} |
135 void *search_base_type_c::visit(neg_real_c *symbol) {return (void *)symbol;} |
97 void *search_base_type_c::visit(integer_c *symbol) {return (void *)symbol;} |
136 void *search_base_type_c::visit(integer_c *symbol) {return (void *)symbol;} |
98 void *search_base_type_c::visit(neg_integer_c *symbol) {return (void *)symbol;} |
137 void *search_base_type_c::visit(neg_integer_c *symbol) {return (void *)symbol;} |
99 void *search_base_type_c::visit(binary_integer_c *symbol) {return (void *)symbol;} |
138 void *search_base_type_c::visit(binary_integer_c *symbol) {return (void *)symbol;} |
100 void *search_base_type_c::visit(octal_integer_c *symbol) {return (void *)symbol;} |
139 void *search_base_type_c::visit(octal_integer_c *symbol) {return (void *)symbol;} |
101 void *search_base_type_c::visit(hex_integer_c *symbol) {return (void *)symbol;} |
140 void *search_base_type_c::visit(hex_integer_c *symbol) {return (void *)symbol;} |
102 void *search_base_type_c::visit(boolean_true_c *symbol) {return (void *)symbol;} |
141 void *search_base_type_c::visit(boolean_true_c *symbol) {return (void *)symbol;} |
103 void *search_base_type_c::visit(boolean_false_c *symbol) {return (void *)symbol;} |
142 void *search_base_type_c::visit(boolean_false_c *symbol) {return (void *)symbol;} |
104 |
143 |
105 |
144 |
106 /***********************************/ |
145 /***********************************/ |
107 /* B 1.3.1 - Elementary Data Types */ |
146 /* B 1.3.1 - Elementary Data Types */ |
108 /***********************************/ |
147 /***********************************/ |
109 void *search_base_type_c::visit(time_type_name_c *symbol) {return (void *)symbol;} |
148 void *search_base_type_c::visit(time_type_name_c *symbol) {return (void *)symbol;} |
110 void *search_base_type_c::visit(bool_type_name_c *symbol) {return (void *)symbol;} |
149 void *search_base_type_c::visit(bool_type_name_c *symbol) {return (void *)symbol;} |
111 void *search_base_type_c::visit(sint_type_name_c *symbol) {return (void *)symbol;} |
150 void *search_base_type_c::visit(sint_type_name_c *symbol) {return (void *)symbol;} |
112 void *search_base_type_c::visit(int_type_name_c *symbol) {return (void *)symbol;} |
151 void *search_base_type_c::visit(int_type_name_c *symbol) {return (void *)symbol;} |
113 void *search_base_type_c::visit(dint_type_name_c *symbol) {return (void *)symbol;} |
152 void *search_base_type_c::visit(dint_type_name_c *symbol) {return (void *)symbol;} |
114 void *search_base_type_c::visit(lint_type_name_c *symbol) {return (void *)symbol;} |
153 void *search_base_type_c::visit(lint_type_name_c *symbol) {return (void *)symbol;} |
115 void *search_base_type_c::visit(usint_type_name_c *symbol) {return (void *)symbol;} |
154 void *search_base_type_c::visit(usint_type_name_c *symbol) {return (void *)symbol;} |
116 void *search_base_type_c::visit(uint_type_name_c *symbol) {return (void *)symbol;} |
155 void *search_base_type_c::visit(uint_type_name_c *symbol) {return (void *)symbol;} |
117 void *search_base_type_c::visit(udint_type_name_c *symbol) {return (void *)symbol;} |
156 void *search_base_type_c::visit(udint_type_name_c *symbol) {return (void *)symbol;} |
118 void *search_base_type_c::visit(ulint_type_name_c *symbol) {return (void *)symbol;} |
157 void *search_base_type_c::visit(ulint_type_name_c *symbol) {return (void *)symbol;} |
119 void *search_base_type_c::visit(real_type_name_c *symbol) {return (void *)symbol;} |
158 void *search_base_type_c::visit(real_type_name_c *symbol) {return (void *)symbol;} |
120 void *search_base_type_c::visit(lreal_type_name_c *symbol) {return (void *)symbol;} |
159 void *search_base_type_c::visit(lreal_type_name_c *symbol) {return (void *)symbol;} |
121 void *search_base_type_c::visit(date_type_name_c *symbol) {return (void *)symbol;} |
160 void *search_base_type_c::visit(date_type_name_c *symbol) {return (void *)symbol;} |
122 void *search_base_type_c::visit(tod_type_name_c *symbol) {return (void *)symbol;} |
161 void *search_base_type_c::visit(tod_type_name_c *symbol) {return (void *)symbol;} |
123 void *search_base_type_c::visit(dt_type_name_c *symbol) {return (void *)symbol;} |
162 void *search_base_type_c::visit(dt_type_name_c *symbol) {return (void *)symbol;} |
124 void *search_base_type_c::visit(byte_type_name_c *symbol) {return (void *)symbol;} |
163 void *search_base_type_c::visit(byte_type_name_c *symbol) {return (void *)symbol;} |
125 void *search_base_type_c::visit(word_type_name_c *symbol) {return (void *)symbol;} |
164 void *search_base_type_c::visit(word_type_name_c *symbol) {return (void *)symbol;} |
126 void *search_base_type_c::visit(dword_type_name_c *symbol) {return (void *)symbol;} |
165 void *search_base_type_c::visit(dword_type_name_c *symbol) {return (void *)symbol;} |
127 void *search_base_type_c::visit(lword_type_name_c *symbol) {return (void *)symbol;} |
166 void *search_base_type_c::visit(lword_type_name_c *symbol) {return (void *)symbol;} |
128 void *search_base_type_c::visit(string_type_name_c *symbol) {return (void *)symbol;} |
167 void *search_base_type_c::visit(string_type_name_c *symbol) {return (void *)symbol;} |
129 void *search_base_type_c::visit(wstring_type_name_c *symbol) {return (void *)symbol;} |
168 void *search_base_type_c::visit(wstring_type_name_c *symbol) {return (void *)symbol;} |
130 |
169 |
131 |
170 |
132 /******************************************************/ |
171 /******************************************************/ |
133 /* Extensions to the base standard as defined in */ |
172 /* Extensions to the base standard as defined in */ |
134 /* "Safety Software Technical Specification, */ |
173 /* "Safety Software Technical Specification, */ |
202 return symbol->enumerated_specification->accept(*this); |
241 return symbol->enumerated_specification->accept(*this); |
203 } |
242 } |
204 |
243 |
205 /* helper symbol for enumerated_specification->enumerated_spec_init */ |
244 /* helper symbol for enumerated_specification->enumerated_spec_init */ |
206 /* enumerated_value_list ',' enumerated_value */ |
245 /* enumerated_value_list ',' enumerated_value */ |
207 void *search_base_type_c::visit(enumerated_value_list_c *symbol) { |
246 void *search_base_type_c::visit(enumerated_value_list_c *symbol) {return (void *)symbol;} |
208 if (NULL == this->current_type_name) ERROR; |
|
209 return (void *)this->current_type_name; |
|
210 } |
|
211 |
247 |
212 /* enumerated_type_name '#' identifier */ |
248 /* enumerated_type_name '#' identifier */ |
213 // SYM_REF2(enumerated_value_c, type, value) |
249 // SYM_REF2(enumerated_value_c, type, value) |
214 void *search_base_type_c::visit(enumerated_value_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
250 void *search_base_type_c::visit(enumerated_value_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
215 |
251 |
216 /* identifier ':' array_spec_init */ |
252 /* identifier ':' array_spec_init */ |
217 void *search_base_type_c::visit(array_type_declaration_c *symbol) { |
253 void *search_base_type_c::visit(array_type_declaration_c *symbol) { |
218 this->current_type_name = symbol->identifier; |
254 this->current_type_name = symbol->identifier; |
219 return symbol->array_spec_init->accept(*this); |
255 return symbol->array_spec_init->accept(*this); |
220 } |
256 } |
221 |
257 |
222 /* array_specification [ASSIGN array_initialization} */ |
258 /* array_specification [ASSIGN array_initialization} */ |
223 /* array_initialization may be NULL ! */ |
259 /* array_initialization may be NULL ! */ |
224 void *search_base_type_c::visit(array_spec_init_c *symbol) { |
260 void *search_base_type_c::visit(array_spec_init_c *symbol) { |
|
261 /* Note that the 'array_specification' may be either an identifier of a previsously defined array type, |
|
262 * or an array_specification_c, so we can not stop here and simply return a array_spec_init_c, |
|
263 * especially if we are looking for the base class! |
|
264 */ |
225 return symbol->array_specification->accept(*this); |
265 return symbol->array_specification->accept(*this); |
226 } |
266 } |
227 |
267 |
228 /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */ |
268 /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */ |
229 void *search_base_type_c::visit(array_specification_c *symbol) { |
269 void *search_base_type_c::visit(array_specification_c *symbol) {return (void *)symbol;} |
230 if (NULL == this->current_type_name) |
|
231 this->current_type_name = symbol->non_generic_type_name; |
|
232 return symbol->non_generic_type_name->accept(*this); |
|
233 } |
|
234 |
270 |
235 /* helper symbol for array_specification */ |
271 /* helper symbol for array_specification */ |
236 /* array_subrange_list ',' subrange */ |
272 /* array_subrange_list ',' subrange */ |
237 void *search_base_type_c::visit(array_subrange_list_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
273 void *search_base_type_c::visit(array_subrange_list_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
238 |
274 |
239 /* array_initialization: '[' array_initial_elements_list ']' */ |
275 /* array_initialization: '[' array_initial_elements_list ']' */ |
240 /* helper symbol for array_initialization */ |
276 /* helper symbol for array_initialization */ |
241 /* array_initial_elements_list ',' array_initial_elements */ |
277 /* array_initial_elements_list ',' array_initial_elements */ |
242 void *search_base_type_c::visit(array_initial_elements_list_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
278 void *search_base_type_c::visit(array_initial_elements_list_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
243 |
279 |
244 /* integer '(' [array_initial_element] ')' */ |
280 /* integer '(' [array_initial_element] ')' */ |
245 /* array_initial_element may be NULL ! */ |
281 /* array_initial_element may be NULL ! */ |
246 void *search_base_type_c::visit(array_initial_elements_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
282 void *search_base_type_c::visit(array_initial_elements_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
247 |
283 |
248 /* structure_type_name ':' structure_specification */ |
284 /* structure_type_name ':' structure_specification */ |
249 /* NOTE: structure_specification will point to either a |
285 /* NOTE: structure_specification will point to either a |
250 * initialized_structure_c |
286 * initialized_structure_c |
251 * OR A |
287 * OR A |
268 } |
304 } |
269 |
305 |
270 /* helper symbol for structure_declaration */ |
306 /* helper symbol for structure_declaration */ |
271 /* structure_declaration: STRUCT structure_element_declaration_list END_STRUCT */ |
307 /* structure_declaration: STRUCT structure_element_declaration_list END_STRUCT */ |
272 /* structure_element_declaration_list structure_element_declaration ';' */ |
308 /* structure_element_declaration_list structure_element_declaration ';' */ |
273 void *search_base_type_c::visit(structure_element_declaration_list_c *symbol) { |
309 void *search_base_type_c::visit(structure_element_declaration_list_c *symbol) {return (void *)symbol;} |
274 return (void *)symbol; |
|
275 } |
|
276 |
310 |
277 /* structure_element_name ':' *_spec_init */ |
311 /* structure_element_name ':' *_spec_init */ |
278 void *search_base_type_c::visit(structure_element_declaration_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
312 void *search_base_type_c::visit(structure_element_declaration_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
279 |
313 |
280 /* helper symbol for structure_initialization */ |
314 /* helper symbol for structure_initialization */ |
281 /* structure_initialization: '(' structure_element_initialization_list ')' */ |
315 /* structure_initialization: '(' structure_element_initialization_list ')' */ |
282 /* structure_element_initialization_list ',' structure_element_initialization */ |
316 /* structure_element_initialization_list ',' structure_element_initialization */ |
283 void *search_base_type_c::visit(structure_element_initialization_list_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
317 void *search_base_type_c::visit(structure_element_initialization_list_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
284 |
318 |
285 /* structure_element_name ASSIGN value */ |
319 /* structure_element_name ASSIGN value */ |
286 void *search_base_type_c::visit(structure_element_initialization_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
320 void *search_base_type_c::visit(structure_element_initialization_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
287 |
321 |
288 /* string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */ |
322 /* string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */ |
289 /* |
323 /* |
290 SYM_REF4(string_type_declaration_c, string_type_name, |
324 SYM_REF4(string_type_declaration_c, string_type_name, |
291 elementary_string_type_name, |
325 elementary_string_type_name, |
292 string_type_declaration_size, |
326 string_type_declaration_size, |
293 string_type_declaration_init) // may be == NULL! |
327 string_type_declaration_init) // may be == NULL! |
294 */ |
328 */ |
295 void *search_base_type_c::visit(string_type_declaration_c *symbol) {return symbol;} |
329 void *search_base_type_c::visit(string_type_declaration_c *symbol) {return (void *)symbol;} |
296 |
330 |
297 |
331 |
298 |
332 |
299 /*****************************/ |
333 /*****************************/ |
300 /* B 1.5.2 - Function Blocks */ |
334 /* B 1.5.2 - Function Blocks */ |
301 /*****************************/ |
335 /*****************************/ |
302 /* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ |
336 /* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ |
303 // SYM_REF3(function_block_declaration_c, fblock_name, var_declarations, fblock_body) |
337 // SYM_REF3(function_block_declaration_c, fblock_name, var_declarations, fblock_body) |
304 void *search_base_type_c::visit(function_block_declaration_c *symbol) { |
338 void *search_base_type_c::visit(function_block_declaration_c *symbol) {return (void *)symbol;} |
305 return symbol; |
339 |
306 } |
340 |
307 |
341 |
|
342 /*********************************************/ |
|
343 /* B.1.6 Sequential function chart elements */ |
|
344 /*********************************************/ |
|
345 /* INITIAL_STEP step_name ':' action_association_list END_STEP */ |
|
346 // SYM_REF2(initial_step_c, step_name, action_association_list) |
|
347 void *search_base_type_c::visit(initial_step_c *symbol) { |
|
348 this->current_type_name = NULL; /* this pseudo data type does not have a type name! */ |
|
349 return (void *)symbol; |
|
350 } |
|
351 |
|
352 /* STEP step_name ':' action_association_list END_STEP */ |
|
353 // SYM_REF2(step_c, step_name, action_association_list) |
|
354 void *search_base_type_c::visit(step_c *symbol) { |
|
355 this->current_type_name = NULL; /* this pseudo data type does not have a type name! */ |
|
356 return (void *)symbol; |
|
357 } |
|
358 |