|
1 /* |
|
2 * matiec - a compiler for the programming languages defined in IEC 61131-3 |
|
3 * |
|
4 * Copyright (C) 2009-2012 Mario de Sousa (msousa@fe.up.pt) |
|
5 * Copyright (C) 2012 Manuele Conti (conti.ma@alice.it) |
|
6 * |
|
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 /* Expressions on the left hand side of assignment statements have aditional restrictions on their datatype. |
|
37 * For example, they cannot be literals, CONSTANT type variables, function invocations, etc... |
|
38 * This class wil do those checks. |
|
39 * |
|
40 * Note that assignment may also be done when passing variables to OUTPUT or IN_OUT function parameters,so we check those too. |
|
41 */ |
|
42 |
|
43 |
|
44 |
|
45 #include "lvalue_check.hh" |
|
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(error_level, symbol1, symbol2, ...) { \ |
|
51 if (current_display_error_level >= error_level) { \ |
|
52 fprintf(stderr, "%s:%d-%d..%d-%d: error: ", \ |
|
53 FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column,\ |
|
54 LAST_(symbol1,symbol2) ->last_line, LAST_(symbol1,symbol2) ->last_column);\ |
|
55 fprintf(stderr, __VA_ARGS__); \ |
|
56 fprintf(stderr, "\n"); \ |
|
57 error_count++; \ |
|
58 } \ |
|
59 } |
|
60 |
|
61 |
|
62 #define STAGE3_WARNING(symbol1, symbol2, ...) { \ |
|
63 fprintf(stderr, "%s:%d-%d..%d-%d: warning: ", \ |
|
64 FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column,\ |
|
65 LAST_(symbol1,symbol2) ->last_line, LAST_(symbol1,symbol2) ->last_column);\ |
|
66 fprintf(stderr, __VA_ARGS__); \ |
|
67 fprintf(stderr, "\n"); \ |
|
68 warning_found = true; \ |
|
69 } |
|
70 |
|
71 |
|
72 lvalue_check_c::lvalue_check_c(symbol_c *ignore) { |
|
73 error_count = 0; |
|
74 current_display_error_level = 0; |
|
75 current_il_operand = NULL; |
|
76 } |
|
77 |
|
78 lvalue_check_c::~lvalue_check_c(void) { |
|
79 } |
|
80 |
|
81 int lvalue_check_c::get_error_count() { |
|
82 return error_count; |
|
83 } |
|
84 |
|
85 |
|
86 #include <strings.h> |
|
87 /* No writing to iterator variables (used in FOR loops) inside the loop itself */ |
|
88 void lvalue_check_c::check_assignment_to_controlvar(symbol_c *lvalue) { |
|
89 for (unsigned int i = 0; i < control_variables.size(); i++) { |
|
90 token_c *lvalue_name = get_var_name_c::get_name(lvalue); |
|
91 if (compare_identifiers(lvalue_name, control_variables[i]) == 0) { |
|
92 STAGE3_ERROR(0, lvalue, lvalue, "Assignment to FOR control variable is not allowed."); |
|
93 break; |
|
94 } |
|
95 } |
|
96 } |
|
97 |
|
98 |
|
99 /* fb_instance.var := ... is not valid if var is output variable */ |
|
100 /* NOTE, if a fb_instance1.fb_instance2.fb_instance3.var is used, we must iteratively check that none of the |
|
101 * FB records are declared as OUTPUT variables!! |
|
102 * This is the reason why we have the while() loop in this function! |
|
103 * |
|
104 * Note, however, that the first record (fb_instance1 in the above example) may be an output variable! |
|
105 */ |
|
106 void lvalue_check_c::check_assignment_to_output(symbol_c *lvalue) { |
|
107 decompose_var_instance_name_c decompose_lvalue(lvalue); |
|
108 search_base_type_c search_base_type; |
|
109 |
|
110 /* Get the first element/record of the potentially structured variable symbol */ |
|
111 /* Note that if symbol is pointing to an expression (or simply a literal value), it will return a NULL. |
|
112 * Once we have implemented the check_assignment_to_expression() method, and abort calling the other checks (including this one) |
|
113 * when an expression is found, we may replace this check with an assertion... |
|
114 * if (NULL == struct_elem) ERROR; |
|
115 */ |
|
116 symbol_c *struct_elem = decompose_lvalue.next_part(); |
|
117 if (NULL == struct_elem) return; |
|
118 |
|
119 symbol_c *type_decl = search_var_instance_decl->get_decl(struct_elem); |
|
120 // symbol_c *type_id = spec_init_sperator_c::get_spec(type_decl); /* this is not required! search_base_type_c can handle spec_init symbols! */ |
|
121 symbol_c *basetype_id = search_base_type.get_basetype_id(/*type_id*/ type_decl); |
|
122 /* If we can not determine the data type of the element, then the code must have a data type semantic error. |
|
123 * This will have been caught by the data type semantic verifier, so we do not bother with this anymore! |
|
124 */ |
|
125 if (NULL == basetype_id) return; |
|
126 |
|
127 /* Determine if the record/structure element is of a FB type. */ |
|
128 /* NOTE: If the structure element is not a FB type, then we can quit this check. |
|
129 * Remember that the standard does not allow a STRUCT data type to have elements that are FB instances! |
|
130 * Similarly, arrays of FB instances is also not allowed. |
|
131 * So, as soon as we find one record/structure element that is not a FB, no other record/structure element |
|
132 * will be of FB type, which means we can quit this check! |
|
133 */ |
|
134 function_block_declaration_c *fb_decl = function_block_type_symtable.find_value(basetype_id); |
|
135 if (function_block_type_symtable.end_value() == fb_decl) return; |
|
136 |
|
137 while (NULL != (struct_elem = decompose_lvalue.next_part())) { |
|
138 search_var_instance_decl_c fb_search_var_instance_decl(fb_decl); |
|
139 if (search_var_instance_decl_c::output_vt == fb_search_var_instance_decl.get_vartype(struct_elem)) { |
|
140 STAGE3_ERROR(0, struct_elem, struct_elem, "Assignment to FB output variable is not allowed."); |
|
141 return; /* no need to carry on checking once the first error is found! */ |
|
142 } |
|
143 |
|
144 /* prepare for any possible further record/structure elements */ |
|
145 type_decl = fb_search_var_instance_decl.get_decl(struct_elem); |
|
146 basetype_id = search_base_type.get_basetype_id(type_decl); |
|
147 if (NULL == basetype_id) return; /* same comment as above... */ |
|
148 fb_decl = function_block_type_symtable.find_value(basetype_id); |
|
149 if (function_block_type_symtable.end_value() == fb_decl) return; /* same comment as above... */ |
|
150 } |
|
151 } |
|
152 |
|
153 |
|
154 /* No writing to CONSTANTs */ |
|
155 void lvalue_check_c::check_assignment_to_constant(symbol_c *lvalue) { |
|
156 unsigned int option = search_var_instance_decl->get_option(lvalue); |
|
157 if (option == search_var_instance_decl_c::constant_opt) { |
|
158 STAGE3_ERROR(0, lvalue, lvalue, "Assignment to CONSTANT variables is not be allowed."); |
|
159 } |
|
160 } |
|
161 |
|
162 |
|
163 /* No assigning values to expressions. */ |
|
164 void lvalue_check_c::check_assignment_to_expression(symbol_c *lvalue) { |
|
165 /* This may occur in function invocations, when passing values (possibly an expression) to one |
|
166 * of the function's OUTPUT or IN_OUT parameters. |
|
167 */ |
|
168 /* This may occur in function invocations, when passing values (possibly an expression) to one |
|
169 * of the function's OUTPUT or IN_OUT parameters. |
|
170 */ |
|
171 if ( |
|
172 /*********************/ |
|
173 /* B 1.2 - Constants */ |
|
174 /*********************/ |
|
175 /******************************/ |
|
176 /* B 1.2.1 - Numeric Literals */ |
|
177 /******************************/ |
|
178 (typeid( *lvalue ) == typeid( real_c )) || |
|
179 (typeid( *lvalue ) == typeid( integer_c )) || |
|
180 (typeid( *lvalue ) == typeid( binary_integer_c )) || |
|
181 (typeid( *lvalue ) == typeid( octal_integer_c )) || |
|
182 (typeid( *lvalue ) == typeid( hex_integer_c )) || |
|
183 (typeid( *lvalue ) == typeid( neg_real_c )) || |
|
184 (typeid( *lvalue ) == typeid( neg_integer_c )) || |
|
185 (typeid( *lvalue ) == typeid( integer_literal_c )) || |
|
186 (typeid( *lvalue ) == typeid( real_literal_c )) || |
|
187 (typeid( *lvalue ) == typeid( bit_string_literal_c )) || |
|
188 (typeid( *lvalue ) == typeid( boolean_literal_c )) || |
|
189 (typeid( *lvalue ) == typeid( boolean_true_c )) || /* should not really be needed */ |
|
190 (typeid( *lvalue ) == typeid( boolean_false_c )) || /* should not really be needed */ |
|
191 /*******************************/ |
|
192 /* B.1.2.2 Character Strings */ |
|
193 /*******************************/ |
|
194 (typeid( *lvalue ) == typeid( double_byte_character_string_c )) || |
|
195 (typeid( *lvalue ) == typeid( single_byte_character_string_c )) || |
|
196 /***************************/ |
|
197 /* B 1.2.3 - Time Literals */ |
|
198 /***************************/ |
|
199 /************************/ |
|
200 /* B 1.2.3.1 - Duration */ |
|
201 /************************/ |
|
202 (typeid( *lvalue ) == typeid( duration_c )) || |
|
203 /************************************/ |
|
204 /* B 1.2.3.2 - Time of day and Date */ |
|
205 /************************************/ |
|
206 (typeid( *lvalue ) == typeid( time_of_day_c )) || |
|
207 (typeid( *lvalue ) == typeid( daytime_c )) || /* should not really be needed */ |
|
208 (typeid( *lvalue ) == typeid( date_c )) || /* should not really be needed */ |
|
209 (typeid( *lvalue ) == typeid( date_literal_c )) || |
|
210 (typeid( *lvalue ) == typeid( date_and_time_c )) || |
|
211 /***************************************/ |
|
212 /* B.3 - Language ST (Structured Text) */ |
|
213 /***************************************/ |
|
214 /***********************/ |
|
215 /* B 3.1 - Expressions */ |
|
216 /***********************/ |
|
217 (typeid( *lvalue ) == typeid( or_expression_c )) || |
|
218 (typeid( *lvalue ) == typeid( xor_expression_c )) || |
|
219 (typeid( *lvalue ) == typeid( and_expression_c )) || |
|
220 (typeid( *lvalue ) == typeid( equ_expression_c )) || |
|
221 (typeid( *lvalue ) == typeid( notequ_expression_c )) || |
|
222 (typeid( *lvalue ) == typeid( lt_expression_c )) || |
|
223 (typeid( *lvalue ) == typeid( gt_expression_c )) || |
|
224 (typeid( *lvalue ) == typeid( le_expression_c )) || |
|
225 (typeid( *lvalue ) == typeid( ge_expression_c )) || |
|
226 (typeid( *lvalue ) == typeid( add_expression_c )) || |
|
227 (typeid( *lvalue ) == typeid( sub_expression_c )) || |
|
228 (typeid( *lvalue ) == typeid( mul_expression_c )) || |
|
229 (typeid( *lvalue ) == typeid( div_expression_c )) || |
|
230 (typeid( *lvalue ) == typeid( mod_expression_c )) || |
|
231 (typeid( *lvalue ) == typeid( power_expression_c )) || |
|
232 (typeid( *lvalue ) == typeid( neg_expression_c )) || |
|
233 (typeid( *lvalue ) == typeid( not_expression_c )) || |
|
234 (typeid( *lvalue ) == typeid( function_invocation_c ))) |
|
235 STAGE3_ERROR(0, lvalue, lvalue, "Assigning an expression to an OUT or IN_OUT parameter is not allowed."); |
|
236 } |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 void lvalue_check_c::verify_is_lvalue(symbol_c *lvalue) { |
|
245 int init_error_count = error_count; /* stop the checks once an error has been found... */ |
|
246 if (error_count == init_error_count) check_assignment_to_expression(lvalue); |
|
247 if (error_count == init_error_count) check_assignment_to_controlvar(lvalue); |
|
248 if (error_count == init_error_count) check_assignment_to_output(lvalue); |
|
249 if (error_count == init_error_count) check_assignment_to_constant(lvalue); |
|
250 } |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 /* check whether all values passed to OUT or IN_OUT parameters are legal lvalues. */ |
|
256 /* |
|
257 * All parameters being passed to the called function MUST be in the parameter list to which f_call points to! |
|
258 * This means that, for non formal function calls in IL, de current (default value) must be artificially added to the |
|
259 * beginning of the parameter list BEFORE calling handle_function_call(). |
|
260 */ |
|
261 #include <string.h> /* required for strcmp() */ |
|
262 void lvalue_check_c::check_nonformal_call(symbol_c *f_call, symbol_c *f_decl) { |
|
263 symbol_c *call_param_value; |
|
264 identifier_c *param_name; |
|
265 function_param_iterator_c fp_iterator(f_decl); |
|
266 function_call_param_iterator_c fcp_iterator(f_call); |
|
267 |
|
268 /* Iterating through the non-formal parameters of the function call */ |
|
269 while((call_param_value = fcp_iterator.next_nf()) != NULL) { |
|
270 /* Iterate to the next parameter of the function being called. |
|
271 * Get the name of that parameter, and ignore if EN or ENO. |
|
272 */ |
|
273 do { |
|
274 param_name = fp_iterator.next(); |
|
275 /* If there is no other parameter declared, then we are passing too many parameters... */ |
|
276 /* This error should have been caught in data type verification, so we simply abandon our check! */ |
|
277 if(param_name == NULL) return; |
|
278 } while ((strcmp(param_name->value, "EN") == 0) || (strcmp(param_name->value, "ENO") == 0)); |
|
279 |
|
280 /* Determine the direction (IN, OUT, IN_OUT) of the parameter... */ |
|
281 function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
282 |
|
283 /* We only process the parameter value if the paramater itself is valid... */ |
|
284 if (param_name != NULL) { |
|
285 /* If the parameter is either OUT or IN_OUT, we check if 'call_param_value' is a valid lvalue */ |
|
286 if ((function_param_iterator_c::direction_out == param_direction) || (function_param_iterator_c::direction_inout == param_direction)) |
|
287 verify_is_lvalue(call_param_value); |
|
288 /* parameter values to IN parameters may be expressions with function invocations that must also be checked! */ |
|
289 if (function_param_iterator_c::direction_in == param_direction) |
|
290 call_param_value->accept(*this); |
|
291 } |
|
292 } |
|
293 } |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 /* check whether all values passed to OUT or IN_OUT parameters are legal lvalues. */ |
|
301 void lvalue_check_c::check_formal_call(symbol_c *f_call, symbol_c *f_decl) { |
|
302 /* if data type semantic verification was unable to determine which function is being called, |
|
303 * then it does not make sense to go ahead and check for lvalues to unknown parameters. |
|
304 * We simply bug out! |
|
305 */ |
|
306 if (NULL == f_decl) return; |
|
307 |
|
308 symbol_c *call_param_name; |
|
309 function_param_iterator_c fp_iterator(f_decl); |
|
310 function_call_param_iterator_c fcp_iterator(f_call); |
|
311 |
|
312 /* Iterating through the formal parameters of the function call */ |
|
313 while((call_param_name = fcp_iterator.next_f()) != NULL) { |
|
314 |
|
315 /* Obtaining the value being passed in the function call */ |
|
316 symbol_c *call_param_value = fcp_iterator.get_current_value(); |
|
317 if (NULL == call_param_value) ERROR; |
|
318 |
|
319 /* Find the corresponding parameter in function declaration, and it's direction (IN, OUT, IN_OUT) */ |
|
320 identifier_c *param_name = fp_iterator.search(call_param_name); |
|
321 function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
322 |
|
323 /* We only process the parameter value if the paramater itself is valid... */ |
|
324 if (param_name != NULL) { |
|
325 /* If the parameter is either OUT or IN_OUT, we check if 'call_param_value' is a valid lvalue */ |
|
326 if ((function_param_iterator_c::direction_out == param_direction) || (function_param_iterator_c::direction_inout == param_direction)) |
|
327 verify_is_lvalue(call_param_value); |
|
328 /* parameter values to IN parameters may be expressions with function invocations that must also be checked! */ |
|
329 if (function_param_iterator_c::direction_in == param_direction) |
|
330 call_param_value->accept(*this); |
|
331 |
|
332 } |
|
333 } |
|
334 } |
|
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 /**************************************/ |
|
343 /* B 1.5 - Program organisation units */ |
|
344 /**************************************/ |
|
345 /***********************/ |
|
346 /* B 1.5.1 - Functions */ |
|
347 /***********************/ |
|
348 void *lvalue_check_c::visit(function_declaration_c *symbol) { |
|
349 search_varfb_instance_type = new search_varfb_instance_type_c(symbol); |
|
350 search_var_instance_decl = new search_var_instance_decl_c(symbol); |
|
351 symbol->function_body->accept(*this); |
|
352 delete search_varfb_instance_type; |
|
353 delete search_var_instance_decl; |
|
354 search_varfb_instance_type = NULL; |
|
355 search_var_instance_decl = NULL; |
|
356 return NULL; |
|
357 } |
|
358 |
|
359 /*****************************/ |
|
360 /* B 1.5.2 - Function blocks */ |
|
361 /*****************************/ |
|
362 void *lvalue_check_c::visit(function_block_declaration_c *symbol) { |
|
363 search_varfb_instance_type = new search_varfb_instance_type_c(symbol); |
|
364 search_var_instance_decl = new search_var_instance_decl_c(symbol); |
|
365 symbol->fblock_body->accept(*this); |
|
366 delete search_varfb_instance_type; |
|
367 delete search_var_instance_decl; |
|
368 search_varfb_instance_type = NULL; |
|
369 search_var_instance_decl = NULL; |
|
370 return NULL; |
|
371 } |
|
372 |
|
373 /**********************/ |
|
374 /* B 1.5.3 - Programs */ |
|
375 /**********************/ |
|
376 void *lvalue_check_c::visit(program_declaration_c *symbol) { |
|
377 search_varfb_instance_type = new search_varfb_instance_type_c(symbol); |
|
378 search_var_instance_decl = new search_var_instance_decl_c(symbol); |
|
379 symbol->function_block_body->accept(*this); |
|
380 delete search_varfb_instance_type; |
|
381 delete search_var_instance_decl; |
|
382 search_varfb_instance_type = NULL; |
|
383 search_var_instance_decl = NULL; |
|
384 return NULL; |
|
385 } |
|
386 |
|
387 /****************************************/ |
|
388 /* B.2 - Language IL (Instruction List) */ |
|
389 /****************************************/ |
|
390 /***********************************/ |
|
391 /* B 2.1 Instructions and Operands */ |
|
392 /***********************************/ |
|
393 void *lvalue_check_c::visit(il_instruction_c *symbol) { |
|
394 /* il_instruction will be NULL when parsing a label with no instruction |
|
395 * e.g.: label1: <---- il_instruction = NULL! |
|
396 * LD 33 |
|
397 * ... |
|
398 */ |
|
399 if (NULL != symbol->il_instruction) |
|
400 symbol->il_instruction->accept(*this); |
|
401 return NULL; |
|
402 } |
|
403 |
|
404 void *lvalue_check_c::visit(il_simple_operation_c *symbol) { |
|
405 current_il_operand = symbol->il_operand; |
|
406 symbol->il_simple_operator->accept(*this); |
|
407 current_il_operand = NULL; |
|
408 return NULL; |
|
409 } |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 /* | function_name [il_operand_list] */ |
|
415 /* NOTE: The parameters 'called_function_declaration' and 'extensible_param_count' are used to pass data between the stage 3 and stage 4. */ |
|
416 // SYM_REF2(il_function_call_c, function_name, il_operand_list, symbol_c *called_function_declaration; int extensible_param_count;) |
|
417 void *lvalue_check_c::visit(il_function_call_c *symbol) { |
|
418 /* The first parameter of a non formal function call in IL will be the 'current value' (i.e. the prev_il_instruction) |
|
419 * In order to be able to handle this without coding special cases, we will simply prepend that symbol |
|
420 * to the il_operand_list, and remove it after calling handle_function_call(). |
|
421 * |
|
422 * However, if no further paramters are given, then il_operand_list will be NULL, and we will |
|
423 * need to create a new object to hold the pointer to prev_il_instruction. |
|
424 * This change will also be undone at the end of this method. |
|
425 */ |
|
426 /* TODO: Copying the location data will result in confusing error message. |
|
427 * We need to make this better, by inserting code to handle this special situation explicitly! |
|
428 */ |
|
429 /* NOTE: When calling a function, using the 'current value' as the first parameter of the function invocation |
|
430 * implies that we can only call functions whose first parameter is IN. It would not do to pass |
|
431 * the 'current value' to an OUT or IN_OUT parameter. |
|
432 * In order to make sure that this will be caught by the check_nonformal_call() function, |
|
433 * we add a symbol that cannot be an lvalue; in this case, a real_c (REAL literal). |
|
434 */ |
|
435 real_c param_value(NULL); |
|
436 *((symbol_c *)(¶m_value)) = *((symbol_c *)symbol); /* copy the symbol location (file, line, offset) data */ |
|
437 if (NULL == symbol->il_operand_list) symbol->il_operand_list = new il_operand_list_c; |
|
438 if (NULL == symbol->il_operand_list) ERROR; |
|
439 ((list_c *)symbol->il_operand_list)->insert_element(¶m_value, 0); |
|
440 |
|
441 check_nonformal_call(symbol, symbol->called_function_declaration); |
|
442 |
|
443 /* Undo the changes to the abstract syntax tree we made above... */ |
|
444 ((list_c *)symbol->il_operand_list)->remove_element(0); |
|
445 if (((list_c *)symbol->il_operand_list)->n == 0) { |
|
446 /* if the list becomes empty, then that means that it did not exist before we made these changes, so we delete it! */ |
|
447 delete symbol->il_operand_list; |
|
448 symbol->il_operand_list = NULL; |
|
449 } |
|
450 |
|
451 return NULL; |
|
452 } |
|
453 |
|
454 |
|
455 |
|
456 |
|
457 |
|
458 |
|
459 /* il_call_operator prev_declared_fb_name |
|
460 * | il_call_operator prev_declared_fb_name '(' ')' |
|
461 * | il_call_operator prev_declared_fb_name '(' eol_list ')' |
|
462 * | il_call_operator prev_declared_fb_name '(' il_operand_list ')' |
|
463 * | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')' |
|
464 */ |
|
465 /* NOTE: The parameter 'called_fb_declaration'is used to pass data between stage 3 and stage4 (although currently it is not used in stage 4 */ |
|
466 // SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list, symbol_c *called_fb_declaration) |
|
467 void *lvalue_check_c::visit(il_fb_call_c *symbol) { |
|
468 if (NULL != symbol->il_operand_list) check_nonformal_call(symbol, symbol->called_fb_declaration); |
|
469 if (NULL != symbol-> il_param_list) check_formal_call(symbol, symbol->called_fb_declaration); |
|
470 return NULL; |
|
471 } |
|
472 |
|
473 |
|
474 /* | function_name '(' eol_list [il_param_list] ')' */ |
|
475 /* NOTE: The parameter 'called_function_declaration' is used to pass data between the stage 3 and stage 4. */ |
|
476 // SYM_REF2(il_formal_funct_call_c, function_name, il_param_list, symbol_c *called_function_declaration; int extensible_param_count;) |
|
477 void *lvalue_check_c::visit(il_formal_funct_call_c *symbol) { |
|
478 check_formal_call(symbol, symbol->called_function_declaration); |
|
479 return NULL; |
|
480 } |
|
481 |
|
482 |
|
483 |
|
484 |
|
485 |
|
486 |
|
487 /*******************/ |
|
488 /* B 2.2 Operators */ |
|
489 /*******************/ |
|
490 void *lvalue_check_c::visit(ST_operator_c *symbol) { |
|
491 verify_is_lvalue(current_il_operand); |
|
492 return NULL; |
|
493 } |
|
494 |
|
495 void *lvalue_check_c::visit(STN_operator_c *symbol) { |
|
496 verify_is_lvalue(current_il_operand); |
|
497 return NULL; |
|
498 } |
|
499 |
|
500 void *lvalue_check_c::visit(S_operator_c *symbol) { |
|
501 verify_is_lvalue(current_il_operand); |
|
502 return NULL; |
|
503 } |
|
504 |
|
505 void *lvalue_check_c::visit(R_operator_c *symbol) { |
|
506 verify_is_lvalue(current_il_operand); |
|
507 return NULL; |
|
508 } |
|
509 |
|
510 |
|
511 /***************************************/ |
|
512 /* B.3 - Language ST (Structured Text) */ |
|
513 /***************************************/ |
|
514 /***********************/ |
|
515 /* B 3.1 - Expressions */ |
|
516 /***********************/ |
|
517 // SYM_REF3(function_invocation_c, function_name, formal_param_list, nonformal_param_list, symbol_c *called_function_declaration; int extensible_param_count; std::vector <symbol_c *> candidate_functions;) |
|
518 void *lvalue_check_c::visit(function_invocation_c *symbol) { |
|
519 if (NULL != symbol->formal_param_list ) check_formal_call (symbol, symbol->called_function_declaration); |
|
520 if (NULL != symbol->nonformal_param_list) check_nonformal_call(symbol, symbol->called_function_declaration); |
|
521 return NULL; |
|
522 } |
|
523 |
|
524 /*********************************/ |
|
525 /* B 3.2.1 Assignment Statements */ |
|
526 /*********************************/ |
|
527 void *lvalue_check_c::visit(assignment_statement_c *symbol) { |
|
528 verify_is_lvalue(symbol->l_exp); |
|
529 /* We call visit r_exp to check function_call */ |
|
530 symbol->r_exp->accept(*this); |
|
531 return NULL; |
|
532 } |
|
533 |
|
534 /*****************************************/ |
|
535 /* B 3.2.2 Subprogram Control Statements */ |
|
536 /*****************************************/ |
|
537 void *lvalue_check_c::visit(fb_invocation_c *symbol) { |
|
538 if (NULL != symbol->formal_param_list ) check_formal_call (symbol, symbol->called_fb_declaration); |
|
539 if (NULL != symbol->nonformal_param_list) check_nonformal_call(symbol, symbol->called_fb_declaration); |
|
540 return NULL; |
|
541 } |
|
542 |
|
543 /********************************/ |
|
544 /* B 3.2.4 Iteration Statements */ |
|
545 /********************************/ |
|
546 void *lvalue_check_c::visit(for_statement_c *symbol) { |
|
547 verify_is_lvalue(symbol->control_variable); |
|
548 control_variables.push_back(get_var_name_c::get_name(symbol->control_variable)); |
|
549 symbol->statement_list->accept(*this); |
|
550 control_variables.pop_back(); |
|
551 return NULL; |
|
552 } |
|
553 |
|
554 |
|
555 |
|
556 |
|
557 |
|
558 |
|
559 |