|
1 /* |
|
2 * matiec - a compiler for the programming languages defined in IEC 61131-3 |
|
3 * |
|
4 * Copyright (C) 2009-2011 Mario de Sousa (msousa@fe.up.pt) |
|
5 * Copyright (C) 20011-2012 Manuele Conti (manuele.conti@sirius-es.it) |
|
6 * Copyright (C) 20011-2012 Matteo Facchinetti (matteo.facchinetti@sirius-es.it) |
|
7 * |
|
8 * This program is free software: you can redistribute it and/or modify |
|
9 * it under the terms of the GNU General Public License as published by |
|
10 * the Free Software Foundation, either version 3 of the License, or |
|
11 * (at your option) any later version. |
|
12 * |
|
13 * This program is distributed in the hope that it will be useful, |
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 * GNU General Public License for more details. |
|
17 * |
|
18 * You should have received a copy of the GNU General Public License |
|
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
20 * |
|
21 * |
|
22 * This code is made available on the understanding that it will not be |
|
23 * used in safety-critical situations without a full and competent review. |
|
24 */ |
|
25 |
|
26 /* |
|
27 * An IEC 61131-3 compiler. |
|
28 * |
|
29 * Based on the |
|
30 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
31 * |
|
32 */ |
|
33 |
|
34 |
|
35 /* |
|
36 * Fill candidate list of data types for all symbols |
|
37 */ |
|
38 |
|
39 #include "print_datatypes_error.hh" |
|
40 #include <typeinfo> |
|
41 #include <list> |
|
42 #include <string> |
|
43 #include <string.h> |
|
44 #include <strings.h> |
|
45 |
|
46 |
|
47 #define FIRST_(symbol1, symbol2) (((symbol1)->first_order < (symbol2)->first_order) ? (symbol1) : (symbol2)) |
|
48 #define LAST_(symbol1, symbol2) (((symbol1)->last_order > (symbol2)->last_order) ? (symbol1) : (symbol2)) |
|
49 |
|
50 #define STAGE3_ERROR(symbol1, symbol2, ...) { \ |
|
51 fprintf(stderr, "%s:%d-%d..%d-%d: error : ", \ |
|
52 FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column, \ |
|
53 LAST_(symbol1,symbol2) ->last_line, LAST_(symbol1,symbol2) ->last_column); \ |
|
54 fprintf(stderr, __VA_ARGS__); \ |
|
55 fprintf(stderr, "\n"); \ |
|
56 il_error = true; \ |
|
57 error_found = true;\ |
|
58 } |
|
59 |
|
60 |
|
61 /* set to 1 to see debug info during execution */ |
|
62 static int debug = 0; |
|
63 |
|
64 print_datatypes_error_c::print_datatypes_error_c(symbol_c *ignore) { |
|
65 error_found = false; |
|
66 } |
|
67 |
|
68 print_datatypes_error_c::~print_datatypes_error_c(void) { |
|
69 error_found = false; |
|
70 } |
|
71 |
|
72 int print_datatypes_error_c::get_error_found() { |
|
73 return error_found; |
|
74 } |
|
75 |
|
76 /* a helper function... */ |
|
77 symbol_c *print_datatypes_error_c::base_type(symbol_c *symbol) { |
|
78 /* NOTE: symbol == NULL is valid. It will occur when, for e.g., an undefined/undeclared symbolic_variable is used |
|
79 * in the code. |
|
80 */ |
|
81 if (symbol == NULL) return NULL; |
|
82 return (symbol_c *)symbol->accept(search_base_type); |
|
83 } |
|
84 |
|
85 /*********************/ |
|
86 /* B 1.2 - Constants */ |
|
87 /*********************/ |
|
88 /******************************/ |
|
89 /* B 1.2.1 - Numeric Literals */ |
|
90 /******************************/ |
|
91 void *print_datatypes_error_c::visit(real_c *symbol) { |
|
92 if (symbol->candidate_datatypes.size() == 0) { |
|
93 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_REAL data type."); |
|
94 } else if (NULL == symbol->datatype) { |
|
95 STAGE3_ERROR(symbol, symbol, "ANY_REAL data type not valid in this location."); |
|
96 } |
|
97 return NULL; |
|
98 } |
|
99 |
|
100 void *print_datatypes_error_c::visit(integer_c *symbol) { |
|
101 if (symbol->candidate_datatypes.size() == 0) { |
|
102 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_INT data type."); |
|
103 } else if (NULL == symbol->datatype) { |
|
104 STAGE3_ERROR(symbol, symbol, "ANY_INT data type not valid in this location."); |
|
105 } |
|
106 return NULL; |
|
107 } |
|
108 |
|
109 void *print_datatypes_error_c::visit(neg_real_c *symbol) { |
|
110 if (symbol->candidate_datatypes.size() == 0) { |
|
111 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_REAL data type."); |
|
112 } else if (NULL == symbol->datatype) { |
|
113 STAGE3_ERROR(symbol, symbol, "ANY_REAL data type not valid in this location."); |
|
114 } |
|
115 return NULL; |
|
116 } |
|
117 |
|
118 void *print_datatypes_error_c::visit(neg_integer_c *symbol) { |
|
119 if (symbol->candidate_datatypes.size() == 0) { |
|
120 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_INT data type."); |
|
121 } else if (NULL == symbol->datatype) { |
|
122 STAGE3_ERROR(symbol, symbol, "ANY_INT data type not valid in this location."); |
|
123 } |
|
124 return NULL; |
|
125 } |
|
126 |
|
127 void *print_datatypes_error_c::visit(binary_integer_c *symbol) { |
|
128 if (symbol->candidate_datatypes.size() == 0) { |
|
129 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_INT data type."); |
|
130 } else if (NULL == symbol->datatype) { |
|
131 STAGE3_ERROR(symbol, symbol, "ANY_INT data type not valid in this location."); |
|
132 } |
|
133 return NULL; |
|
134 } |
|
135 |
|
136 void *print_datatypes_error_c::visit(octal_integer_c *symbol) { |
|
137 if (symbol->candidate_datatypes.size() == 0) { |
|
138 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_INT data type."); |
|
139 } else if (NULL == symbol->datatype) { |
|
140 STAGE3_ERROR(symbol, symbol, "ANY_INT data type not valid in this location."); |
|
141 } |
|
142 return NULL; |
|
143 } |
|
144 |
|
145 void *print_datatypes_error_c::visit(hex_integer_c *symbol) { |
|
146 if (symbol->candidate_datatypes.size() == 0) { |
|
147 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_INT data type."); |
|
148 } else if (NULL == symbol->datatype) { |
|
149 STAGE3_ERROR(symbol, symbol, "ANY_INT data type not valid in this location."); |
|
150 } |
|
151 return NULL; |
|
152 } |
|
153 |
|
154 void *print_datatypes_error_c::visit(integer_literal_c *symbol) { |
|
155 if (symbol->candidate_datatypes.size() == 0) { |
|
156 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_INT data type."); |
|
157 } else if (NULL == symbol->datatype) { |
|
158 STAGE3_ERROR(symbol, symbol, "ANY_INT data type not valid in this location."); |
|
159 } |
|
160 return NULL; |
|
161 } |
|
162 |
|
163 void *print_datatypes_error_c::visit(real_literal_c *symbol) { |
|
164 if (symbol->candidate_datatypes.size() == 0) { |
|
165 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_REAL data type."); |
|
166 } else if (NULL == symbol->datatype) { |
|
167 STAGE3_ERROR(symbol, symbol, "ANY_REAL data type not valid in this location."); |
|
168 } |
|
169 return NULL; |
|
170 } |
|
171 |
|
172 void *print_datatypes_error_c::visit(bit_string_literal_c *symbol) { |
|
173 if (symbol->candidate_datatypes.size() == 0) { |
|
174 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_BIT data type."); |
|
175 } else if (NULL == symbol->datatype) { |
|
176 STAGE3_ERROR(symbol, symbol, "ANY_BIT data type not valid in this location."); |
|
177 } |
|
178 return NULL; |
|
179 } |
|
180 |
|
181 void *print_datatypes_error_c::visit(boolean_literal_c *symbol) { |
|
182 if (symbol->candidate_datatypes.size() == 0) { |
|
183 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_BOOL data type."); |
|
184 } else if (NULL == symbol->datatype) { |
|
185 STAGE3_ERROR(symbol, symbol, "ANY_BOOL data type not valid in this location."); |
|
186 } |
|
187 return NULL; |
|
188 } |
|
189 |
|
190 void *print_datatypes_error_c::visit(boolean_true_c *symbol) { |
|
191 if (symbol->candidate_datatypes.size() == 0) { |
|
192 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_BOOL data type."); |
|
193 } else if (NULL == symbol->datatype) { |
|
194 STAGE3_ERROR(symbol, symbol, "ANY_BOOL data type not valid in this location."); |
|
195 } |
|
196 return NULL; |
|
197 } |
|
198 |
|
199 void *print_datatypes_error_c::visit(boolean_false_c *symbol) { |
|
200 if (symbol->candidate_datatypes.size() == 0) { |
|
201 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for ANY_BOOL data type."); |
|
202 } else if (NULL == symbol->datatype) { |
|
203 STAGE3_ERROR(symbol, symbol, "ANY_BOOL data type not valid in this location."); |
|
204 } |
|
205 return NULL; |
|
206 } |
|
207 |
|
208 /*******************************/ |
|
209 /* B.1.2.2 Character Strings */ |
|
210 /*******************************/ |
|
211 void *print_datatypes_error_c::visit(double_byte_character_string_c *symbol) { |
|
212 if (symbol->candidate_datatypes.size() == 0) { |
|
213 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for WSTRING data type."); |
|
214 } else if (NULL == symbol->datatype) { |
|
215 STAGE3_ERROR(symbol, symbol, "WSTRING data type not valid in this location."); |
|
216 } |
|
217 return NULL; |
|
218 } |
|
219 |
|
220 void *print_datatypes_error_c::visit(single_byte_character_string_c *symbol) { |
|
221 if (symbol->candidate_datatypes.size() == 0) { |
|
222 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for STRING data type."); |
|
223 } else if (NULL == symbol->datatype) { |
|
224 STAGE3_ERROR(symbol, symbol, "STRING data type not valid in this location."); |
|
225 } |
|
226 return NULL; |
|
227 } |
|
228 |
|
229 /***************************/ |
|
230 /* B 1.2.3 - Time Literals */ |
|
231 /***************************/ |
|
232 /************************/ |
|
233 /* B 1.2.3.1 - Duration */ |
|
234 /************************/ |
|
235 void *print_datatypes_error_c::visit(duration_c *symbol) { |
|
236 if (symbol->candidate_datatypes.size() == 0) { |
|
237 STAGE3_ERROR(symbol, symbol, "Invalid syntax for TIME data type."); |
|
238 } else if (NULL == symbol->datatype) { |
|
239 STAGE3_ERROR(symbol, symbol, "TIME data type not valid in this location."); |
|
240 } |
|
241 return NULL; |
|
242 } |
|
243 |
|
244 /************************************/ |
|
245 /* B 1.2.3.2 - Time of day and Date */ |
|
246 /************************************/ |
|
247 void *print_datatypes_error_c::visit(time_of_day_c *symbol) { |
|
248 if (symbol->candidate_datatypes.size() == 0) { |
|
249 STAGE3_ERROR(symbol, symbol, "Invalid syntax for TOD data type."); |
|
250 } else if (NULL == symbol->datatype) { |
|
251 STAGE3_ERROR(symbol, symbol, "TOD data type not valid in this location."); |
|
252 } |
|
253 return NULL; |
|
254 } |
|
255 |
|
256 void *print_datatypes_error_c::visit(date_c *symbol) { |
|
257 if (symbol->candidate_datatypes.size() == 0) { |
|
258 STAGE3_ERROR(symbol, symbol, "Invalid syntax for DATE data type."); |
|
259 } else if (NULL == symbol->datatype) { |
|
260 STAGE3_ERROR(symbol, symbol, "DATE data type not valid in this location."); |
|
261 } |
|
262 return NULL; |
|
263 } |
|
264 |
|
265 void *print_datatypes_error_c::visit(date_and_time_c *symbol) { |
|
266 if (symbol->candidate_datatypes.size() == 0) { |
|
267 STAGE3_ERROR(symbol, symbol, "Invalid syntax for DT data type."); |
|
268 } else if (NULL == symbol->datatype) { |
|
269 STAGE3_ERROR(symbol, symbol, "DT data type not valid in this location."); |
|
270 } |
|
271 return NULL; |
|
272 } |
|
273 |
|
274 /**********************/ |
|
275 /* B 1.3 - Data types */ |
|
276 /**********************/ |
|
277 /********************************/ |
|
278 /* B 1.3.3 - Derived data types */ |
|
279 /********************************/ |
|
280 void *print_datatypes_error_c::visit(data_type_declaration_c *symbol) { |
|
281 // TODO !!! |
|
282 /* for the moment we must return NULL so semantic analysis of remaining code is not interrupted! */ |
|
283 return NULL; |
|
284 } |
|
285 |
|
286 void *print_datatypes_error_c::visit(enumerated_value_c *symbol) { |
|
287 if (symbol->candidate_datatypes.size() == 0) |
|
288 STAGE3_ERROR(symbol, symbol, "Ambiguous enumerate value or Variable not declared in this scope."); |
|
289 return NULL; |
|
290 } |
|
291 |
|
292 |
|
293 /*********************/ |
|
294 /* B 1.4 - Variables */ |
|
295 /*********************/ |
|
296 void *print_datatypes_error_c::visit(symbolic_variable_c *symbol) { |
|
297 if (symbol->candidate_datatypes.size() == 0) |
|
298 STAGE3_ERROR(symbol, symbol, "Variable not declared in this scope."); |
|
299 return NULL; |
|
300 } |
|
301 |
|
302 /********************************************/ |
|
303 /* B 1.4.1 - Directly Represented Variables */ |
|
304 /********************************************/ |
|
305 void *print_datatypes_error_c::visit(direct_variable_c *symbol) { |
|
306 if (symbol->candidate_datatypes.size() == 0) |
|
307 STAGE3_ERROR(symbol, symbol, "Numerical result exceeds range for located variable data type."); |
|
308 return NULL; |
|
309 } |
|
310 |
|
311 /*************************************/ |
|
312 /* B 1.4.2 - Multi-element variables */ |
|
313 /*************************************/ |
|
314 /* subscripted_variable '[' subscript_list ']' */ |
|
315 // SYM_REF2(array_variable_c, subscripted_variable, subscript_list) |
|
316 void *print_datatypes_error_c::visit(array_variable_c *symbol) { |
|
317 if (symbol->candidate_datatypes.size() == 0) |
|
318 STAGE3_ERROR(symbol, symbol, "Array variable not declared in this scope."); |
|
319 |
|
320 /* recursively call the subscript list to print any errors in the expressions used in the subscript...*/ |
|
321 symbol->subscript_list->accept(*this); |
|
322 return NULL; |
|
323 } |
|
324 |
|
325 /* subscript_list ',' subscript */ |
|
326 // SYM_LIST(subscript_list_c) |
|
327 /* NOTE: we inherit from iterator visitor, so we do not need to implement this method... */ |
|
328 #if 0 |
|
329 void *print_datatypes_error_c::visit(subscript_list_c *symbol) { |
|
330 } |
|
331 #endif |
|
332 |
|
333 |
|
334 /* record_variable '.' field_selector */ |
|
335 /* WARNING: input and/or output variables of function blocks |
|
336 * may be accessed as fields of a structured variable! |
|
337 * Code handling a structured_variable_c must take |
|
338 * this into account! |
|
339 */ |
|
340 // SYM_REF2(structured_variable_c, record_variable, field_selector) |
|
341 /* NOTE: We do not recursively determine the data types of each field_selector in fill_candidate_datatypes_c, |
|
342 * so it does not make sense to recursively visit all the field_selectors to print out error messages. |
|
343 * Maybe in the future, if we find the need to print out more detailed error messages, we might do it that way. For now, we don't! |
|
344 */ |
|
345 void *print_datatypes_error_c::visit(structured_variable_c *symbol) { |
|
346 if (symbol->candidate_datatypes.size() == 0) |
|
347 STAGE3_ERROR(symbol, symbol, "Structure variable not declared in this scope."); |
|
348 return NULL; |
|
349 } |
|
350 |
|
351 /************************************/ |
|
352 /* B 1.5 Program organization units */ |
|
353 /************************************/ |
|
354 /*********************/ |
|
355 /* B 1.5.1 Functions */ |
|
356 /*********************/ |
|
357 void *print_datatypes_error_c::visit(function_declaration_c *symbol) { |
|
358 search_varfb_instance_type = new search_varfb_instance_type_c(symbol); |
|
359 /* We do not check for data type errors in variable declarations, Skip this for now... */ |
|
360 // symbol->var_declarations_list->accept(*this); |
|
361 if (debug) printf("Print error data types list in body of function %s\n", ((token_c *)(symbol->derived_function_name))->value); |
|
362 il_parenthesis_level = 0; |
|
363 il_error = false; |
|
364 prev_il_instruction = NULL; |
|
365 symbol->function_body->accept(*this); |
|
366 prev_il_instruction = NULL; |
|
367 delete search_varfb_instance_type; |
|
368 search_varfb_instance_type = NULL; |
|
369 return NULL; |
|
370 } |
|
371 |
|
372 /***************************/ |
|
373 /* B 1.5.2 Function blocks */ |
|
374 /***************************/ |
|
375 void *print_datatypes_error_c::visit(function_block_declaration_c *symbol) { |
|
376 search_varfb_instance_type = new search_varfb_instance_type_c(symbol); |
|
377 /* We do not check for data type errors in variable declarations, Skip this for now... */ |
|
378 // symbol->var_declarations->accept(*this); |
|
379 if (debug) printf("Print error data types list in body of FB %s\n", ((token_c *)(symbol->fblock_name))->value); |
|
380 il_parenthesis_level = 0; |
|
381 il_error = false; |
|
382 prev_il_instruction = NULL; |
|
383 symbol->fblock_body->accept(*this); |
|
384 prev_il_instruction = NULL; |
|
385 delete search_varfb_instance_type; |
|
386 search_varfb_instance_type = NULL; |
|
387 return NULL; |
|
388 } |
|
389 |
|
390 /**********************/ |
|
391 /* B 1.5.3 - Programs */ |
|
392 /**********************/ |
|
393 void *print_datatypes_error_c::visit(program_declaration_c *symbol) { |
|
394 search_varfb_instance_type = new search_varfb_instance_type_c(symbol); |
|
395 /* We do not check for data type errors in variable declarations, Skip this for now... */ |
|
396 // symbol->var_declarations->accept(*this); |
|
397 if (debug) printf("Print error data types list in body of program %s\n", ((token_c *)(symbol->program_type_name))->value); |
|
398 il_parenthesis_level = 0; |
|
399 il_error = false; |
|
400 prev_il_instruction = NULL; |
|
401 symbol->function_block_body->accept(*this); |
|
402 prev_il_instruction = NULL; |
|
403 delete search_varfb_instance_type; |
|
404 search_varfb_instance_type = NULL; |
|
405 return NULL; |
|
406 } |
|
407 |
|
408 |
|
409 |
|
410 /********************************/ |
|
411 /* B 1.7 Configuration elements */ |
|
412 /********************************/ |
|
413 void *print_datatypes_error_c::visit(configuration_declaration_c *symbol) { |
|
414 #if 0 |
|
415 // TODO !!! |
|
416 /* for the moment we must return NULL so semantic analysis of remaining code is not interrupted! */ |
|
417 #endif |
|
418 return NULL; |
|
419 } |
|
420 |
|
421 /****************************************/ |
|
422 /* B.2 - Language IL (Instruction List) */ |
|
423 /****************************************/ |
|
424 /***********************************/ |
|
425 /* B 2.1 Instructions and Operands */ |
|
426 /***********************************/ |
|
427 // void *visit(instruction_list_c *symbol); |
|
428 void *print_datatypes_error_c::visit(il_simple_operation_c *symbol) { |
|
429 il_operand = symbol->il_operand; |
|
430 if (NULL != symbol->il_operand) { |
|
431 symbol->il_operand->accept(*this); |
|
432 } |
|
433 /* recursive call to see whether data types are compatible */ |
|
434 symbol->il_simple_operator->accept(*this); |
|
435 il_operand = NULL; |
|
436 return NULL; |
|
437 } |
|
438 |
|
439 void *print_datatypes_error_c::visit(il_function_call_c *symbol) { |
|
440 return NULL; |
|
441 } |
|
442 |
|
443 void *print_datatypes_error_c::visit(il_expression_c *symbol) { |
|
444 return NULL; |
|
445 } |
|
446 |
|
447 void *print_datatypes_error_c::visit(il_fb_call_c *symbol) { |
|
448 return NULL; |
|
449 } |
|
450 |
|
451 void *print_datatypes_error_c::visit(il_formal_funct_call_c *symbol) { |
|
452 return NULL; |
|
453 } |
|
454 |
|
455 |
|
456 /* |
|
457 void *visit(il_operand_list_c *symbol); |
|
458 void *visit(simple_instr_list_c *symbol); |
|
459 void *visit(il_param_list_c *symbol); |
|
460 void *visit(il_param_assignment_c *symbol); |
|
461 void *visit(il_param_out_assignment_c *symbol); |
|
462 */ |
|
463 |
|
464 /*******************/ |
|
465 /* B 2.2 Operators */ |
|
466 /*******************/ |
|
467 void *print_datatypes_error_c::visit(LD_operator_c *symbol) { |
|
468 prev_il_instruction = symbol; |
|
469 return NULL; |
|
470 } |
|
471 |
|
472 void *print_datatypes_error_c::visit(LDN_operator_c *symbol) { |
|
473 if (NULL != symbol->datatype) return NULL; |
|
474 |
|
475 il_operand->accept(*this); |
|
476 if ((symbol->candidate_datatypes.size() == 0) && |
|
477 (il_operand->candidate_datatypes.size() > 0)) |
|
478 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'LDN' operator."); |
|
479 prev_il_instruction = symbol; |
|
480 return NULL; |
|
481 } |
|
482 |
|
483 void *print_datatypes_error_c::visit(ST_operator_c *symbol) { |
|
484 if (NULL != symbol->datatype) return NULL; |
|
485 /* MANU: |
|
486 * if prev_instruction is NULL we can print a message error or warning error like: |
|
487 * we can't use a ST like first instruction. |
|
488 * What do you think? |
|
489 */ |
|
490 il_operand->accept(*this); |
|
491 if ((symbol->candidate_datatypes.size() == 0) && |
|
492 (il_operand->candidate_datatypes.size() > 0)) |
|
493 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'ST' operator."); |
|
494 prev_il_instruction = symbol; |
|
495 return NULL; |
|
496 } |
|
497 |
|
498 void *print_datatypes_error_c::visit(STN_operator_c *symbol) { |
|
499 if (NULL != symbol->datatype) return NULL; |
|
500 /* MANU: |
|
501 * if prev_instruction is NULL we can print a message error or warning error like: |
|
502 * we can't use a ST like first instruction. |
|
503 * What do you think? |
|
504 */ |
|
505 il_operand->accept(*this); |
|
506 if ((symbol->candidate_datatypes.size() == 0) && |
|
507 (il_operand->candidate_datatypes.size() > 0)) |
|
508 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'STN' operator."); |
|
509 prev_il_instruction = symbol; |
|
510 return NULL; |
|
511 } |
|
512 |
|
513 void *print_datatypes_error_c::visit(NOT_operator_c *symbol) { |
|
514 prev_il_instruction = symbol; |
|
515 return NULL; |
|
516 } |
|
517 |
|
518 void *print_datatypes_error_c::visit(S_operator_c *symbol) { |
|
519 if (NULL != symbol->datatype) return NULL; |
|
520 |
|
521 il_operand->accept(*this); |
|
522 if ((symbol->candidate_datatypes.size() == 0) && |
|
523 (il_operand->candidate_datatypes.size() > 0)) |
|
524 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'S' operator."); |
|
525 prev_il_instruction = symbol; |
|
526 return NULL; |
|
527 } |
|
528 |
|
529 void *print_datatypes_error_c::visit(R_operator_c *symbol) { |
|
530 if (NULL != symbol->datatype) return NULL; |
|
531 |
|
532 il_operand->accept(*this); |
|
533 if ((symbol->candidate_datatypes.size() == 0) && |
|
534 (il_operand->candidate_datatypes.size() > 0)) |
|
535 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'R' operator."); |
|
536 prev_il_instruction = symbol; |
|
537 return NULL; |
|
538 } |
|
539 |
|
540 void *print_datatypes_error_c::visit(S1_operator_c *symbol) { |
|
541 if (NULL != symbol->datatype) return NULL; |
|
542 |
|
543 il_operand->accept(*this); |
|
544 if ((symbol->candidate_datatypes.size() == 0) && |
|
545 (il_operand->candidate_datatypes.size() > 0)) |
|
546 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'S1' operator."); |
|
547 prev_il_instruction = symbol; |
|
548 return NULL; |
|
549 } |
|
550 |
|
551 void *print_datatypes_error_c::visit(R1_operator_c *symbol) { |
|
552 if (NULL != symbol->datatype) return NULL; |
|
553 |
|
554 il_operand->accept(*this); |
|
555 if ((symbol->candidate_datatypes.size() == 0) && |
|
556 (il_operand->candidate_datatypes.size() > 0)) |
|
557 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'R1' operator."); |
|
558 prev_il_instruction = symbol; |
|
559 return NULL; |
|
560 } |
|
561 |
|
562 void *print_datatypes_error_c::visit(CLK_operator_c *symbol) { |
|
563 prev_il_instruction = symbol; |
|
564 return NULL; |
|
565 } |
|
566 |
|
567 void *print_datatypes_error_c::visit(CU_operator_c *symbol) { |
|
568 prev_il_instruction = symbol; |
|
569 return NULL; |
|
570 } |
|
571 |
|
572 void *print_datatypes_error_c::visit(CD_operator_c *symbol) { |
|
573 prev_il_instruction = symbol; |
|
574 return NULL; |
|
575 } |
|
576 |
|
577 void *print_datatypes_error_c::visit(PV_operator_c *symbol) { |
|
578 prev_il_instruction = symbol; |
|
579 return NULL; |
|
580 } |
|
581 |
|
582 void *print_datatypes_error_c::visit(IN_operator_c *symbol) { |
|
583 prev_il_instruction = symbol; |
|
584 return NULL; |
|
585 } |
|
586 |
|
587 void *print_datatypes_error_c::visit(PT_operator_c *symbol) { |
|
588 prev_il_instruction = symbol; |
|
589 return NULL; |
|
590 } |
|
591 |
|
592 void *print_datatypes_error_c::visit(AND_operator_c *symbol) { |
|
593 if (NULL != symbol->datatype) return NULL; |
|
594 |
|
595 il_operand->accept(*this); |
|
596 if ((symbol->candidate_datatypes.size() == 0) && |
|
597 (il_operand->candidate_datatypes.size() > 0)) |
|
598 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'AND' operator."); |
|
599 prev_il_instruction = symbol; |
|
600 return NULL; |
|
601 } |
|
602 |
|
603 void *print_datatypes_error_c::visit(OR_operator_c *symbol) { |
|
604 if (NULL != symbol->datatype) return NULL; |
|
605 |
|
606 il_operand->accept(*this); |
|
607 if ((symbol->candidate_datatypes.size() == 0) && |
|
608 (il_operand->candidate_datatypes.size() > 0)) |
|
609 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'OR' operator."); |
|
610 prev_il_instruction = symbol; |
|
611 return NULL; |
|
612 } |
|
613 |
|
614 void *print_datatypes_error_c::visit(XOR_operator_c *symbol) { |
|
615 if (NULL != symbol->datatype) return NULL; |
|
616 |
|
617 il_operand->accept(*this); |
|
618 if ((symbol->candidate_datatypes.size() == 0) && |
|
619 (il_operand->candidate_datatypes.size() > 0)) |
|
620 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'XOR' operator."); |
|
621 prev_il_instruction = symbol; |
|
622 return NULL; |
|
623 } |
|
624 |
|
625 void *print_datatypes_error_c::visit(ANDN_operator_c *symbol) { |
|
626 if (NULL != symbol->datatype) return NULL; |
|
627 |
|
628 il_operand->accept(*this); |
|
629 if ((symbol->candidate_datatypes.size() == 0) && |
|
630 (il_operand->candidate_datatypes.size() > 0)) |
|
631 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'ANDN' operator."); |
|
632 prev_il_instruction = symbol; |
|
633 return NULL; |
|
634 } |
|
635 |
|
636 void *print_datatypes_error_c::visit(ORN_operator_c *symbol) { |
|
637 if (NULL != symbol->datatype) return NULL; |
|
638 |
|
639 il_operand->accept(*this); |
|
640 if ((symbol->candidate_datatypes.size() == 0) && |
|
641 (il_operand->candidate_datatypes.size() > 0)) |
|
642 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'ORN' operator."); |
|
643 prev_il_instruction = symbol; |
|
644 return NULL; |
|
645 } |
|
646 |
|
647 void *print_datatypes_error_c::visit(XORN_operator_c *symbol) { |
|
648 if (NULL != symbol->datatype) return NULL; |
|
649 |
|
650 il_operand->accept(*this); |
|
651 if ((symbol->candidate_datatypes.size() == 0) && |
|
652 (il_operand->candidate_datatypes.size() > 0)) |
|
653 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'ORN' operator."); |
|
654 prev_il_instruction = symbol; |
|
655 return NULL; |
|
656 } |
|
657 |
|
658 void *print_datatypes_error_c::visit(ADD_operator_c *symbol) { |
|
659 if (NULL != symbol->datatype) return NULL; |
|
660 |
|
661 il_operand->accept(*this); |
|
662 if ((symbol->candidate_datatypes.size() == 0) && |
|
663 (il_operand->candidate_datatypes.size() > 0)) |
|
664 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'ADD' operator."); |
|
665 prev_il_instruction = symbol; |
|
666 return NULL; |
|
667 } |
|
668 |
|
669 void *print_datatypes_error_c::visit(SUB_operator_c *symbol) { |
|
670 if (NULL != symbol->datatype) return NULL; |
|
671 |
|
672 il_operand->accept(*this); |
|
673 if ((symbol->candidate_datatypes.size() == 0) && |
|
674 (il_operand->candidate_datatypes.size() > 0)) |
|
675 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'SUB' operator."); |
|
676 prev_il_instruction = symbol; |
|
677 return NULL; |
|
678 } |
|
679 |
|
680 void *print_datatypes_error_c::visit(MUL_operator_c *symbol) { |
|
681 if (NULL != symbol->datatype) return NULL; |
|
682 |
|
683 il_operand->accept(*this); |
|
684 if ((symbol->candidate_datatypes.size() == 0) && |
|
685 (il_operand->candidate_datatypes.size() > 0)) |
|
686 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'MUL' operator."); |
|
687 prev_il_instruction = symbol; |
|
688 return NULL; |
|
689 } |
|
690 |
|
691 void *print_datatypes_error_c::visit(DIV_operator_c *symbol) { |
|
692 if (NULL != symbol->datatype) return NULL; |
|
693 |
|
694 il_operand->accept(*this); |
|
695 if ((symbol->candidate_datatypes.size() == 0) && |
|
696 (il_operand->candidate_datatypes.size() > 0)) |
|
697 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'DIV' operator."); |
|
698 prev_il_instruction = symbol; |
|
699 return NULL; |
|
700 } |
|
701 |
|
702 void *print_datatypes_error_c::visit(MOD_operator_c *symbol) { |
|
703 if (NULL != symbol->datatype) return NULL; |
|
704 |
|
705 il_operand->accept(*this); |
|
706 if ((symbol->candidate_datatypes.size() == 0) && |
|
707 (il_operand->candidate_datatypes.size() > 0)) |
|
708 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'MOD' operator."); |
|
709 prev_il_instruction = symbol; |
|
710 return NULL; |
|
711 } |
|
712 |
|
713 void *print_datatypes_error_c::visit(GT_operator_c *symbol) { |
|
714 prev_il_instruction = symbol; |
|
715 return NULL; |
|
716 } |
|
717 |
|
718 void *print_datatypes_error_c::visit(GE_operator_c *symbol) { |
|
719 prev_il_instruction = symbol; |
|
720 return NULL; |
|
721 } |
|
722 |
|
723 void *print_datatypes_error_c::visit(EQ_operator_c *symbol) { |
|
724 prev_il_instruction = symbol; |
|
725 return NULL; |
|
726 } |
|
727 |
|
728 void *print_datatypes_error_c::visit(LT_operator_c *symbol) { |
|
729 prev_il_instruction = symbol; |
|
730 return NULL; |
|
731 } |
|
732 |
|
733 void *print_datatypes_error_c::visit(LE_operator_c *symbol) { |
|
734 prev_il_instruction = symbol; |
|
735 return NULL; |
|
736 } |
|
737 |
|
738 void *print_datatypes_error_c::visit(NE_operator_c *symbol) { |
|
739 prev_il_instruction = symbol; |
|
740 return NULL; |
|
741 } |
|
742 |
|
743 void *print_datatypes_error_c::visit(CAL_operator_c *symbol) { |
|
744 prev_il_instruction = symbol; |
|
745 return NULL; |
|
746 } |
|
747 |
|
748 void *print_datatypes_error_c::visit(CALC_operator_c *symbol) { |
|
749 prev_il_instruction = symbol; |
|
750 return NULL; |
|
751 } |
|
752 |
|
753 void *print_datatypes_error_c::visit(CALCN_operator_c *symbol) { |
|
754 prev_il_instruction = symbol; |
|
755 return NULL; |
|
756 } |
|
757 |
|
758 void *print_datatypes_error_c::visit(RET_operator_c *symbol) { |
|
759 prev_il_instruction = symbol; |
|
760 return NULL; |
|
761 } |
|
762 |
|
763 void *print_datatypes_error_c::visit(RETC_operator_c *symbol) { |
|
764 prev_il_instruction = symbol; |
|
765 return NULL; |
|
766 } |
|
767 |
|
768 void *print_datatypes_error_c::visit(RETCN_operator_c *symbol) { |
|
769 prev_il_instruction = symbol; |
|
770 return NULL; |
|
771 } |
|
772 |
|
773 void *print_datatypes_error_c::visit(JMP_operator_c *symbol) { |
|
774 prev_il_instruction = symbol; |
|
775 return NULL; |
|
776 } |
|
777 |
|
778 void *print_datatypes_error_c::visit(JMPC_operator_c *symbol) { |
|
779 prev_il_instruction = symbol; |
|
780 return NULL; |
|
781 } |
|
782 |
|
783 void *print_datatypes_error_c::visit(JMPCN_operator_c *symbol) { |
|
784 prev_il_instruction = symbol; |
|
785 return NULL; |
|
786 } |
|
787 |
|
788 /* Symbol class handled together with function call checks */ |
|
789 // void *visit(il_assign_operator_c *symbol, variable_name); |
|
790 /* Symbol class handled together with function call checks */ |
|
791 // void *visit(il_assign_operator_c *symbol, option, variable_name); |
|
792 |
|
793 /***************************************/ |
|
794 /* B.3 - Language ST (Structured Text) */ |
|
795 /***************************************/ |
|
796 /***********************/ |
|
797 /* B 3.1 - Expressions */ |
|
798 /***********************/ |
|
799 |
|
800 void *print_datatypes_error_c::visit(or_expression_c *symbol) { |
|
801 if (NULL != symbol->datatype) return NULL; |
|
802 |
|
803 symbol->l_exp->accept(*this); |
|
804 symbol->r_exp->accept(*this); |
|
805 if ((symbol->candidate_datatypes.size() == 0) && |
|
806 (symbol->l_exp->candidate_datatypes.size() > 0) && |
|
807 (symbol->r_exp->candidate_datatypes.size() > 0)) |
|
808 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'OR' expression."); |
|
809 return NULL; |
|
810 } |
|
811 |
|
812 |
|
813 void *print_datatypes_error_c::visit(xor_expression_c *symbol) { |
|
814 if (NULL != symbol->datatype) return NULL; |
|
815 |
|
816 symbol->l_exp->accept(*this); |
|
817 symbol->r_exp->accept(*this); |
|
818 if ((symbol->candidate_datatypes.size() == 0) && |
|
819 (symbol->l_exp->candidate_datatypes.size() > 0) && |
|
820 (symbol->r_exp->candidate_datatypes.size() > 0)) |
|
821 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'XOR' expression."); |
|
822 return NULL; |
|
823 } |
|
824 |
|
825 |
|
826 void *print_datatypes_error_c::visit(and_expression_c *symbol) { |
|
827 if (NULL != symbol->datatype) return NULL; |
|
828 |
|
829 symbol->l_exp->accept(*this); |
|
830 symbol->r_exp->accept(*this); |
|
831 if ((symbol->candidate_datatypes.size() == 0) && |
|
832 (symbol->l_exp->candidate_datatypes.size() > 0) && |
|
833 (symbol->r_exp->candidate_datatypes.size() > 0)) |
|
834 STAGE3_ERROR(symbol, symbol, "Data type mismatch for 'AND' expression."); |
|
835 return NULL; |
|
836 } |
|
837 |
|
838 |
|
839 void *print_datatypes_error_c::visit(equ_expression_c *symbol) { |
|
840 if (NULL != symbol->datatype) return NULL; |
|
841 |
|
842 symbol->l_exp->accept(*this); |
|
843 symbol->r_exp->accept(*this); |
|
844 if ((symbol->candidate_datatypes.size() == 0) && |
|
845 (symbol->l_exp->candidate_datatypes.size() > 0) && |
|
846 (symbol->r_exp->candidate_datatypes.size() > 0)) |
|
847 STAGE3_ERROR(symbol, symbol, "Data type mismatch for '=' expression."); |
|
848 return NULL; |
|
849 } |
|
850 |
|
851 |
|
852 void *print_datatypes_error_c::visit(notequ_expression_c *symbol) { |
|
853 if (NULL != symbol->datatype) return NULL; |
|
854 |
|
855 symbol->l_exp->accept(*this); |
|
856 symbol->r_exp->accept(*this); |
|
857 if ((symbol->candidate_datatypes.size() == 0) && |
|
858 (symbol->l_exp->candidate_datatypes.size() > 0) && |
|
859 (symbol->r_exp->candidate_datatypes.size() > 0)) |
|
860 STAGE3_ERROR(symbol, symbol, "Data type mismatch for '<>' expression."); |
|
861 return NULL; |
|
862 } |
|
863 |
|
864 |
|
865 void *print_datatypes_error_c::visit(lt_expression_c *symbol) { |
|
866 if (NULL != symbol->datatype) return NULL; |
|
867 |
|
868 symbol->l_exp->accept(*this); |
|
869 symbol->r_exp->accept(*this); |
|
870 if ((symbol->candidate_datatypes.size() == 0) && |
|
871 (symbol->l_exp->candidate_datatypes.size() > 0) && |
|
872 (symbol->r_exp->candidate_datatypes.size() > 0)) |
|
873 STAGE3_ERROR(symbol, symbol, "Data type mismatch for '<' expression."); |
|
874 return NULL; |
|
875 } |
|
876 |
|
877 |
|
878 void *print_datatypes_error_c::visit(gt_expression_c *symbol) { |
|
879 if (NULL != symbol->datatype) return NULL; |
|
880 |
|
881 symbol->l_exp->accept(*this); |
|
882 symbol->r_exp->accept(*this); |
|
883 if ((symbol->candidate_datatypes.size() == 0) && |
|
884 (symbol->l_exp->candidate_datatypes.size() > 0) && |
|
885 (symbol->r_exp->candidate_datatypes.size() > 0)) |
|
886 STAGE3_ERROR(symbol, symbol, "Data type mismatch for '>' expression."); |
|
887 return NULL; |
|
888 } |
|
889 |
|
890 |
|
891 void *print_datatypes_error_c::visit(le_expression_c *symbol) { |
|
892 if (NULL != symbol->datatype) return NULL; |
|
893 |
|
894 symbol->l_exp->accept(*this); |
|
895 symbol->r_exp->accept(*this); |
|
896 if ((symbol->candidate_datatypes.size() == 0) && |
|
897 (symbol->l_exp->candidate_datatypes.size() > 0) && |
|
898 (symbol->r_exp->candidate_datatypes.size() > 0)) |
|
899 STAGE3_ERROR(symbol, symbol, "Data type mismatch for '<=' expression."); |
|
900 return NULL; |
|
901 } |
|
902 |
|
903 |
|
904 void *print_datatypes_error_c::visit(ge_expression_c *symbol) { |
|
905 if (NULL != symbol->datatype) return NULL; |
|
906 |
|
907 symbol->l_exp->accept(*this); |
|
908 symbol->r_exp->accept(*this); |
|
909 if ((symbol->candidate_datatypes.size() == 0) && |
|
910 (symbol->l_exp->candidate_datatypes.size() > 0) && |
|
911 (symbol->r_exp->candidate_datatypes.size() > 0)) |
|
912 STAGE3_ERROR(symbol, symbol, "Data type mismatch for '>=' expression."); |
|
913 return NULL; |
|
914 } |
|
915 |
|
916 |
|
917 void *print_datatypes_error_c::visit(add_expression_c *symbol) { |
|
918 if (NULL != symbol->datatype) return NULL; |
|
919 |
|
920 symbol->l_exp->accept(*this); |
|
921 symbol->r_exp->accept(*this); |
|
922 if ((symbol->candidate_datatypes.size() == 0) && |
|
923 (symbol->l_exp->candidate_datatypes.size() > 0) && |
|
924 (symbol->r_exp->candidate_datatypes.size() > 0)) |
|
925 STAGE3_ERROR(symbol, symbol, "Current '+' result and operand not of same data type."); |
|
926 |
|
927 return NULL; |
|
928 } |
|
929 |
|
930 |
|
931 |
|
932 void *print_datatypes_error_c::visit(sub_expression_c *symbol) { |
|
933 if (NULL != symbol->datatype) return NULL; |
|
934 |
|
935 symbol->l_exp->accept(*this); |
|
936 symbol->r_exp->accept(*this); |
|
937 if ((symbol->candidate_datatypes.size() == 0) && |
|
938 (symbol->l_exp->candidate_datatypes.size() > 0) && |
|
939 (symbol->r_exp->candidate_datatypes.size() > 0)) |
|
940 STAGE3_ERROR(symbol, symbol, "Current '-' result and operand not of same data type."); |
|
941 return NULL; |
|
942 } |
|
943 |
|
944 void *print_datatypes_error_c::visit(mul_expression_c *symbol) { |
|
945 if (NULL != symbol->datatype) return NULL; |
|
946 |
|
947 symbol->l_exp->accept(*this); |
|
948 symbol->r_exp->accept(*this); |
|
949 if ((symbol->candidate_datatypes.size() == 0) && |
|
950 (symbol->l_exp->candidate_datatypes.size() > 0) && |
|
951 (symbol->r_exp->candidate_datatypes.size() > 0)) |
|
952 STAGE3_ERROR(symbol, symbol, "Current '*' result and operand not of same data type."); |
|
953 return NULL; |
|
954 } |
|
955 |
|
956 void *print_datatypes_error_c::visit(div_expression_c *symbol) { |
|
957 if (NULL != symbol->datatype) return NULL; |
|
958 |
|
959 symbol->l_exp->accept(*this); |
|
960 symbol->r_exp->accept(*this); |
|
961 if ((symbol->candidate_datatypes.size() == 0) && |
|
962 (symbol->l_exp->candidate_datatypes.size() > 0) && |
|
963 (symbol->r_exp->candidate_datatypes.size() > 0)) |
|
964 STAGE3_ERROR(symbol, symbol, "Current '/' result and operand not of same data type."); |
|
965 return NULL; |
|
966 } |
|
967 |
|
968 |
|
969 void *print_datatypes_error_c::visit(mod_expression_c *symbol) { |
|
970 if (NULL != symbol->datatype) return NULL; |
|
971 |
|
972 symbol->l_exp->accept(*this); |
|
973 symbol->r_exp->accept(*this); |
|
974 if ((symbol->candidate_datatypes.size() == 0) && |
|
975 (symbol->l_exp->candidate_datatypes.size() > 0) && |
|
976 (symbol->r_exp->candidate_datatypes.size() > 0)) |
|
977 STAGE3_ERROR(symbol, symbol, "Current 'MOD' result and operand not of same data type."); |
|
978 return NULL; |
|
979 } |
|
980 |
|
981 |
|
982 void *print_datatypes_error_c::visit(power_expression_c *symbol) { |
|
983 if (NULL != symbol->datatype) return NULL; |
|
984 |
|
985 symbol->l_exp->accept(*this); |
|
986 symbol->r_exp->accept(*this); |
|
987 if ((symbol->candidate_datatypes.size() == 0) && |
|
988 (symbol->l_exp->candidate_datatypes.size() > 0) && |
|
989 (symbol->r_exp->candidate_datatypes.size() > 0)) |
|
990 STAGE3_ERROR(symbol, symbol, "Data type mismatch for '**' expression."); |
|
991 return NULL; |
|
992 } |
|
993 |
|
994 |
|
995 void *print_datatypes_error_c::visit(neg_expression_c *symbol) { |
|
996 if (NULL != symbol->datatype) return NULL; |
|
997 |
|
998 symbol->exp->accept(*this); |
|
999 if ((symbol->candidate_datatypes.size() == 0) && |
|
1000 (symbol->exp->candidate_datatypes.size() > 0)) |
|
1001 STAGE3_ERROR(symbol, symbol, "Invalid data type for 'NEG' expression."); |
|
1002 return NULL; |
|
1003 } |
|
1004 |
|
1005 |
|
1006 void *print_datatypes_error_c::visit(not_expression_c *symbol) { |
|
1007 if (NULL != symbol->datatype) return NULL; |
|
1008 |
|
1009 symbol->exp->accept(*this); |
|
1010 if ((symbol->candidate_datatypes.size() == 0) && |
|
1011 (symbol->exp->candidate_datatypes.size() > 0)) |
|
1012 STAGE3_ERROR(symbol, symbol, "Invalid data type for 'NOT' expression."); |
|
1013 return NULL; |
|
1014 } |
|
1015 |
|
1016 |
|
1017 void *print_datatypes_error_c::visit(function_invocation_c *symbol) { |
|
1018 list_c *parameter_list; |
|
1019 function_declaration_c * f_decl; |
|
1020 |
|
1021 if (NULL != symbol->datatype) return NULL; |
|
1022 if (NULL != symbol->formal_param_list) |
|
1023 parameter_list = (list_c *)symbol->formal_param_list; |
|
1024 else if (NULL != symbol->nonformal_param_list) |
|
1025 parameter_list = (list_c *)symbol->nonformal_param_list; |
|
1026 else ERROR; |
|
1027 parameter_list->accept(*this); |
|
1028 if (symbol->candidate_datatypes.size() == 0) { |
|
1029 identifier_c *fname = (identifier_c *)symbol->function_name; |
|
1030 f_decl = (function_declaration_c *)symbol->called_function_declaration; |
|
1031 /* |
|
1032 * Manuele: In the future we have to test parameter number |
|
1033 * and show a specific message. |
|
1034 */ |
|
1035 STAGE3_ERROR(symbol, symbol, "No matching overloaded '%s' function call.", fname->value); |
|
1036 } |
|
1037 return NULL; |
|
1038 } |
|
1039 |
|
1040 /********************/ |
|
1041 /* B 3.2 Statements */ |
|
1042 /********************/ |
|
1043 |
|
1044 /*********************************/ |
|
1045 /* B 3.2.1 Assignment Statements */ |
|
1046 /*********************************/ |
|
1047 void *print_datatypes_error_c::visit(assignment_statement_c *symbol) { |
|
1048 symbol->l_exp->accept(*this); |
|
1049 symbol->r_exp->accept(*this); |
|
1050 if ((NULL == symbol->l_exp->datatype) && |
|
1051 (NULL == symbol->r_exp->datatype) && |
|
1052 (symbol->l_exp->candidate_datatypes.size() > 0) && |
|
1053 (symbol->r_exp->candidate_datatypes.size() > 0)) |
|
1054 STAGE3_ERROR(symbol, symbol, "Invalid data types for ':=' operation."); |
|
1055 return NULL; |
|
1056 } |
|
1057 |
|
1058 /********************************/ |
|
1059 /* B 3.2.3 Selection Statements */ |
|
1060 /********************************/ |
|
1061 |
|
1062 void *print_datatypes_error_c::visit(if_statement_c *symbol) { |
|
1063 symbol->expression->accept(*this); |
|
1064 if ((NULL == symbol->expression->datatype) && |
|
1065 (symbol->expression->candidate_datatypes.size() > 0)) { |
|
1066 STAGE3_ERROR(symbol, symbol, "Invalid data type for 'IF' condition."); |
|
1067 } |
|
1068 if (NULL != symbol->statement_list) |
|
1069 symbol->statement_list->accept(*this); |
|
1070 if (NULL != symbol->elseif_statement_list) |
|
1071 symbol->elseif_statement_list->accept(*this); |
|
1072 if (NULL != symbol->else_statement_list) |
|
1073 symbol->else_statement_list->accept(*this); |
|
1074 return NULL; |
|
1075 } |
|
1076 |
|
1077 void *print_datatypes_error_c::visit(elseif_statement_c *symbol) { |
|
1078 symbol->expression->accept(*this); |
|
1079 if ((NULL == symbol->expression->datatype) && |
|
1080 (symbol->expression->candidate_datatypes.size() > 0)) { |
|
1081 STAGE3_ERROR(symbol, symbol, "Invalid data type for 'ELSIF' condition."); |
|
1082 } |
|
1083 if (NULL != symbol->statement_list) |
|
1084 symbol->statement_list->accept(*this); |
|
1085 return NULL; |
|
1086 } |
|
1087 |
|
1088 |
|
1089 void *print_datatypes_error_c::visit(case_statement_c *symbol) { |
|
1090 symbol->expression->accept(*this); |
|
1091 if ((NULL == symbol->expression->datatype) && |
|
1092 (symbol->expression->candidate_datatypes.size() > 0)) { |
|
1093 STAGE3_ERROR(symbol, symbol, "'CASE' quantity not an integer or enumerated."); |
|
1094 } |
|
1095 symbol->case_element_list->accept(*this); |
|
1096 if (NULL != symbol->statement_list) |
|
1097 symbol->statement_list->accept(*this); |
|
1098 return NULL; |
|
1099 } |
|
1100 |
|
1101 /********************************/ |
|
1102 /* B 3.2.4 Iteration Statements */ |
|
1103 /********************************/ |
|
1104 |
|
1105 void *print_datatypes_error_c::visit(for_statement_c *symbol) { |
|
1106 symbol->control_variable->accept(*this); |
|
1107 symbol->beg_expression->accept(*this); |
|
1108 symbol->end_expression->accept(*this); |
|
1109 /* Control variable */ |
|
1110 if ((NULL == symbol->control_variable->datatype) && |
|
1111 (symbol->control_variable->candidate_datatypes.size() > 0)) { |
|
1112 STAGE3_ERROR(symbol, symbol, "Invalid data type for 'FOR' control variable."); |
|
1113 } |
|
1114 /* BEG expression */ |
|
1115 if ((NULL == symbol->beg_expression->datatype) && |
|
1116 (symbol->beg_expression->candidate_datatypes.size() > 0)) { |
|
1117 STAGE3_ERROR(symbol, symbol, "Invalid data type for 'FOR' begin expression."); |
|
1118 } |
|
1119 /* END expression */ |
|
1120 if ((NULL == symbol->end_expression->datatype) && |
|
1121 (symbol->end_expression->candidate_datatypes.size() > 0)) { |
|
1122 STAGE3_ERROR(symbol, symbol, "Invalid data type for 'FOR' end expression."); |
|
1123 } |
|
1124 /* BY expression */ |
|
1125 if ((NULL != symbol->by_expression) && |
|
1126 (NULL == symbol->by_expression->datatype) && |
|
1127 (symbol->end_expression->candidate_datatypes.size() > 0)) { |
|
1128 STAGE3_ERROR(symbol, symbol, "Invalid data type for 'FOR' by expression."); |
|
1129 } |
|
1130 /* DO statement */ |
|
1131 if (NULL != symbol->statement_list) |
|
1132 symbol->statement_list->accept(*this); |
|
1133 |
|
1134 return NULL; |
|
1135 } |
|
1136 |
|
1137 void *print_datatypes_error_c::visit(while_statement_c *symbol) { |
|
1138 symbol->expression->accept(*this); |
|
1139 if (symbol->candidate_datatypes.size() != 1) { |
|
1140 STAGE3_ERROR(symbol, symbol, "Invalid data type for 'WHILE' condition."); |
|
1141 return NULL; |
|
1142 } |
|
1143 if (NULL != symbol->statement_list) |
|
1144 symbol->statement_list->accept(*this); |
|
1145 return NULL; |
|
1146 } |
|
1147 |
|
1148 void *print_datatypes_error_c::visit(repeat_statement_c *symbol) { |
|
1149 if (symbol->candidate_datatypes.size() != 1) { |
|
1150 STAGE3_ERROR(symbol, symbol, "Invalid data type for 'REPEAT' condition."); |
|
1151 return NULL; |
|
1152 } |
|
1153 if (NULL != symbol->statement_list) |
|
1154 symbol->statement_list->accept(*this); |
|
1155 symbol->expression->accept(*this); |
|
1156 return NULL; |
|
1157 } |
|
1158 |
|
1159 |
|
1160 |
|
1161 |
|
1162 |