204
|
1 |
/*
|
|
2 |
* (c) 2009 Mario de Sousa
|
|
3 |
*
|
|
4 |
* Offered to the public under the terms of the GNU General Public License
|
|
5 |
* as published by the Free Software Foundation; either version 2 of the
|
|
6 |
* License, or (at your option) any later version.
|
|
7 |
*
|
|
8 |
* This program is distributed in the hope that it will be useful, but
|
|
9 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
11 |
* Public License for more details.
|
|
12 |
*
|
|
13 |
* This code is made available on the understanding that it will not be
|
|
14 |
* used in safety-critical situations without a full and competent review.
|
|
15 |
*/
|
|
16 |
|
|
17 |
/*
|
|
18 |
* An IEC 61131-3 IL and ST compiler.
|
|
19 |
*
|
|
20 |
* Based on the
|
|
21 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
|
|
22 |
*
|
|
23 |
*/
|
|
24 |
|
|
25 |
|
|
26 |
/* Verify whether the semantic rules of data type compatibility are being followed.
|
|
27 |
*
|
|
28 |
* For example:
|
|
29 |
*/
|
|
30 |
|
|
31 |
#include "visit_expression_type.hh"
|
|
32 |
#include <typeinfo>
|
|
33 |
#include <list>
|
|
34 |
#include <string>
|
|
35 |
#include <string.h>
|
|
36 |
#include <strings.h>
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
#define FIRST_(symbol1, symbol2) (((symbol1)->first_line < (symbol2)->first_line) ? (symbol1) : \
|
|
41 |
((symbol1)->first_line > (symbol2)->first_line) ? (symbol2) : \
|
|
42 |
((symbol1)->first_column < (symbol2)->first_column) ? (symbol1) : \
|
|
43 |
((symbol1)->first_column > (symbol2)->first_column) ? (symbol2) : \
|
|
44 |
(symbol1))
|
|
45 |
|
|
46 |
#define LAST_(symbol1, symbol2) (((symbol1)->last_line < (symbol2)->last_line) ? (symbol2) : \
|
|
47 |
((symbol1)->last_line > (symbol2)->last_line) ? (symbol1) : \
|
|
48 |
((symbol1)->last_column < (symbol2)->last_column) ? (symbol2) : \
|
|
49 |
((symbol1)->last_column > (symbol2)->last_column) ? (symbol1) : \
|
|
50 |
(symbol1))
|
|
51 |
|
|
52 |
#define STAGE3_ERROR(symbol1, symbol2, msg) { \
|
|
53 |
printf("semantic error between (%d:%d) and (%d:%d): %s\n", \
|
|
54 |
FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column, \
|
|
55 |
LAST_(symbol1,symbol2) ->last_line, LAST_(symbol1,symbol2) ->last_column, \
|
|
56 |
msg); \
|
|
57 |
il_error = true; \
|
|
58 |
}
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
void *visit_expression_type_c::visit(program_declaration_c *symbol) {
|
|
65 |
search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
|
|
66 |
symbol->var_declarations->accept(*this);
|
|
67 |
printf("checking semantics in body of program %s\n", ((token_c *)(symbol->program_type_name))->value);
|
|
68 |
il_parenthesis_level = 0;
|
|
69 |
il_error = false;
|
|
70 |
il_default_variable_type = NULL;
|
|
71 |
symbol->function_block_body->accept(*this);
|
|
72 |
il_default_variable_type = NULL;
|
|
73 |
delete search_varfb_instance_type;
|
|
74 |
return NULL;
|
|
75 |
}
|
|
76 |
|
|
77 |
void *visit_expression_type_c::visit(function_declaration_c *symbol) {
|
|
78 |
search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
|
|
79 |
symbol->var_declarations_list->accept(*this);
|
|
80 |
printf("checking semantics in body of function %s\n", ((token_c *)(symbol->derived_function_name))->value);
|
|
81 |
il_parenthesis_level = 0;
|
|
82 |
il_error = false;
|
|
83 |
il_default_variable_type = NULL;
|
|
84 |
symbol->function_body->accept(*this);
|
|
85 |
il_default_variable_type = NULL;
|
|
86 |
delete search_varfb_instance_type;
|
|
87 |
return NULL;
|
|
88 |
}
|
|
89 |
|
|
90 |
void *visit_expression_type_c::visit(function_block_declaration_c *symbol) {
|
|
91 |
search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
|
|
92 |
symbol->var_declarations->accept(*this);
|
|
93 |
printf("checking semantics in body of FB %s\n", ((token_c *)(symbol->fblock_name))->value);
|
|
94 |
il_parenthesis_level = 0;
|
|
95 |
il_error = false;
|
|
96 |
il_default_variable_type = NULL;
|
|
97 |
symbol->fblock_body->accept(*this);
|
|
98 |
il_default_variable_type = NULL;
|
|
99 |
delete search_varfb_instance_type;
|
|
100 |
return NULL;
|
|
101 |
}
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
visit_expression_type_c::visit_expression_type_c(symbol_c *search_scope) {
|
|
112 |
}
|
|
113 |
|
|
114 |
visit_expression_type_c::~visit_expression_type_c(void) {
|
|
115 |
}
|
|
116 |
|
|
117 |
|
|
118 |
/* A helper function... */
|
|
119 |
bool visit_expression_type_c::is_ANY_ELEMENTARY_type(symbol_c *type_symbol) {
|
|
120 |
if (type_symbol == NULL) {ERROR;}
|
|
121 |
return is_ANY_MAGNITUDE_type(type_symbol)
|
|
122 |
|| is_ANY_BIT_type(type_symbol)
|
|
123 |
|| is_ANY_STRING_type(type_symbol)
|
|
124 |
|| is_ANY_DATE_type(type_symbol);
|
|
125 |
}
|
|
126 |
|
|
127 |
|
|
128 |
/* A helper function... */
|
|
129 |
bool visit_expression_type_c::is_ANY_MAGNITUDE_type(symbol_c *type_symbol) {
|
|
130 |
if (type_symbol == NULL) {ERROR;}
|
|
131 |
if (typeid(*type_symbol) == typeid(time_type_name_c)) {return true;}
|
|
132 |
return is_ANY_NUM_type(type_symbol);
|
|
133 |
}
|
|
134 |
|
|
135 |
|
|
136 |
/* A helper function... */
|
|
137 |
bool visit_expression_type_c::is_ANY_NUM_type(symbol_c *type_symbol) {
|
|
138 |
if (type_symbol == NULL) {ERROR;}
|
|
139 |
return is_ANY_REAL_type(type_symbol) || is_ANY_INT_type(type_symbol);
|
|
140 |
}
|
|
141 |
|
|
142 |
|
|
143 |
/* A helper function... */
|
|
144 |
bool visit_expression_type_c::is_ANY_DATE_type(symbol_c *type_symbol) {
|
|
145 |
if (type_symbol == NULL) {ERROR;}
|
|
146 |
if (typeid(*type_symbol) == typeid(date_type_name_c)) {return true;}
|
|
147 |
if (typeid(*type_symbol) == typeid(tod_type_name_c)) {return true;}
|
|
148 |
if (typeid(*type_symbol) == typeid(dt_type_name_c)) {return true;}
|
|
149 |
return false;
|
|
150 |
}
|
|
151 |
|
|
152 |
|
|
153 |
/* A helper function... */
|
|
154 |
bool visit_expression_type_c::is_ANY_STRING_type(symbol_c *type_symbol) {
|
|
155 |
if (type_symbol == NULL) {ERROR;}
|
|
156 |
if (typeid(*type_symbol) == typeid(string_type_name_c)) {return true;}
|
|
157 |
if (typeid(*type_symbol) == typeid(wstring_type_name_c)) {return true;}
|
|
158 |
return false;
|
|
159 |
}
|
|
160 |
|
|
161 |
|
|
162 |
/* A helper function... */
|
|
163 |
bool visit_expression_type_c::is_ANY_INT_type(symbol_c *type_symbol) {
|
|
164 |
if (type_symbol == NULL) {ERROR;}
|
|
165 |
if (typeid(*type_symbol) == typeid(sint_type_name_c)) {return true;}
|
|
166 |
if (typeid(*type_symbol) == typeid(int_type_name_c)) {return true;}
|
|
167 |
if (typeid(*type_symbol) == typeid(dint_type_name_c)) {return true;}
|
|
168 |
if (typeid(*type_symbol) == typeid(lint_type_name_c)) {return true;}
|
|
169 |
if (typeid(*type_symbol) == typeid(usint_type_name_c)) {return true;}
|
|
170 |
if (typeid(*type_symbol) == typeid(uint_type_name_c)) {return true;}
|
|
171 |
if (typeid(*type_symbol) == typeid(udint_type_name_c)) {return true;}
|
|
172 |
if (typeid(*type_symbol) == typeid(ulint_type_name_c)) {return true;}
|
|
173 |
if (is_literal_integer_type(type_symbol)) {return true;}
|
|
174 |
return false;
|
|
175 |
}
|
|
176 |
|
|
177 |
|
|
178 |
/* A helper function... */
|
|
179 |
bool visit_expression_type_c::is_ANY_REAL_type(symbol_c *type_symbol) {
|
|
180 |
if (type_symbol == NULL) {ERROR;}
|
|
181 |
if (typeid(*type_symbol) == typeid(real_type_name_c)) {return true;}
|
|
182 |
if (typeid(*type_symbol) == typeid(lreal_type_name_c)) {return true;}
|
|
183 |
if (is_literal_real_type(type_symbol)) {return true;}
|
|
184 |
return false;
|
|
185 |
}
|
|
186 |
|
|
187 |
|
|
188 |
/* A helper function... */
|
|
189 |
bool visit_expression_type_c::is_ANY_BIT_type(symbol_c *type_symbol) {
|
|
190 |
if (type_symbol == NULL) {ERROR;}
|
|
191 |
if (typeid(*type_symbol) == typeid(bool_type_name_c)) {return true;}
|
|
192 |
if (typeid(*type_symbol) == typeid(byte_type_name_c)) {return true;}
|
|
193 |
if (typeid(*type_symbol) == typeid(word_type_name_c)) {return true;}
|
|
194 |
if (typeid(*type_symbol) == typeid(dword_type_name_c)) {return true;}
|
|
195 |
if (typeid(*type_symbol) == typeid(lword_type_name_c)) {return true;}
|
|
196 |
if (is_literal_integer_type(type_symbol)) {return true;}
|
|
197 |
return false;
|
|
198 |
}
|
|
199 |
|
|
200 |
|
|
201 |
/* A helper function... */
|
|
202 |
bool visit_expression_type_c::is_BOOL_type(symbol_c *type_symbol) {
|
|
203 |
if (type_symbol == NULL) {ERROR;}
|
|
204 |
if (typeid(*type_symbol) == typeid(bool_type_name_c)) {return true;}
|
|
205 |
if (is_literal_bool_type(type_symbol)) {return true;}
|
|
206 |
return false;
|
|
207 |
}
|
|
208 |
|
|
209 |
|
|
210 |
#define sizeoftype(symbol) get_sizeof_datatype_c::getsize(symbol)
|
|
211 |
|
|
212 |
|
|
213 |
/* A helper function... */
|
|
214 |
bool visit_expression_type_c::is_literal_integer_type(symbol_c *type_symbol) {
|
|
215 |
if (type_symbol == NULL) {return true;}
|
|
216 |
if (typeid(*type_symbol) == typeid(integer_c)) {return true;}
|
|
217 |
if (typeid(*type_symbol) == typeid(binary_integer_c)) {return true;}
|
|
218 |
if (typeid(*type_symbol) == typeid(octal_integer_c)) {return true;}
|
|
219 |
if (typeid(*type_symbol) == typeid(hex_integer_c)) {return true;}
|
|
220 |
return false;
|
|
221 |
}
|
|
222 |
|
|
223 |
|
|
224 |
/* A helper function... */
|
|
225 |
bool visit_expression_type_c::is_literal_real_type(symbol_c *type_symbol) {
|
|
226 |
if (type_symbol == NULL) {return true;}
|
|
227 |
if (typeid(*type_symbol) == typeid(real_c)) {return true;}
|
|
228 |
return false;
|
|
229 |
}
|
|
230 |
|
|
231 |
|
|
232 |
/* A helper function... */
|
|
233 |
bool visit_expression_type_c::is_literal_bool_type(symbol_c *type_symbol) {
|
|
234 |
bool_type_name_c bool_t;
|
|
235 |
|
|
236 |
if (type_symbol == NULL) {return true;}
|
|
237 |
if (typeid(*type_symbol) == typeid(boolean_true_c)) {return true;}
|
|
238 |
if (typeid(*type_symbol) == typeid(boolean_false_c)) {return true;}
|
|
239 |
if (is_literal_integer_type(type_symbol))
|
|
240 |
if (sizeoftype(&bool_t) >= sizeoftype(type_symbol)) {return true;}
|
|
241 |
return false;
|
|
242 |
}
|
|
243 |
|
|
244 |
|
|
245 |
/* Determine the common data type between two data types.
|
|
246 |
* If no common data type found, return NULL.
|
|
247 |
*
|
|
248 |
* If data types are identical, return the first (actually any would do...).
|
|
249 |
* If any of the data types is a literal, we confirm that
|
|
250 |
* the literal uses less bits than the fixed size data type.
|
|
251 |
* e.g. BYTE and 1024 returns NULL
|
|
252 |
* BYTE and 255 returns BYTE
|
|
253 |
*
|
|
254 |
* If two literals, then return the literal that requires more bits...
|
|
255 |
*/
|
|
256 |
symbol_c *visit_expression_type_c::common_type__(symbol_c *first_type, symbol_c *second_type) {
|
|
257 |
if (first_type == NULL && second_type == NULL) {ERROR;}
|
|
258 |
if (first_type == NULL) {return second_type;}
|
|
259 |
if (second_type == NULL) {return first_type;}
|
|
260 |
|
|
261 |
if (is_literal_integer_type(first_type) && is_literal_integer_type(second_type))
|
|
262 |
{return ((sizeoftype(first_type) > sizeoftype(second_type))? first_type:second_type);}
|
|
263 |
|
|
264 |
if (is_literal_real_type(first_type) && is_literal_real_type(second_type))
|
|
265 |
{return ((sizeoftype(first_type) > sizeoftype(second_type))? first_type:second_type);}
|
|
266 |
|
|
267 |
if (is_literal_bool_type(first_type) && is_literal_bool_type(second_type))
|
|
268 |
{return first_type;}
|
|
269 |
|
|
270 |
/* This check can only be made after the is_literal_XXXX checks */
|
|
271 |
/* When two literals of the same type, with identical typeid's are checked,
|
|
272 |
* we must return the one that occupies more bits...
|
|
273 |
*/
|
|
274 |
if (typeid(*first_type) == typeid(*second_type)) {return first_type;}
|
|
275 |
|
|
276 |
if (is_BOOL_type(first_type) && is_literal_bool_type(second_type)) {return first_type;}
|
|
277 |
if (is_BOOL_type(second_type) && is_literal_bool_type(first_type)) {return second_type;}
|
|
278 |
|
|
279 |
if (is_ANY_BIT_type(first_type) && is_literal_integer_type(second_type))
|
|
280 |
{return ((sizeoftype(first_type) >= sizeoftype(second_type))? first_type :NULL);}
|
|
281 |
if (is_ANY_BIT_type(second_type) && is_literal_integer_type(first_type))
|
|
282 |
{return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
|
|
283 |
|
|
284 |
if (is_ANY_INT_type(first_type) && is_literal_integer_type(second_type))
|
|
285 |
{return ((sizeoftype(first_type) >= sizeoftype(second_type))? first_type :NULL);}
|
|
286 |
if (is_ANY_INT_type(second_type) && is_literal_integer_type(first_type))
|
|
287 |
{return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
|
|
288 |
|
|
289 |
if (is_ANY_REAL_type(first_type) && is_literal_real_type(second_type))
|
|
290 |
{return ((sizeoftype(first_type) >= sizeoftype(second_type))? first_type :NULL);}
|
|
291 |
if (is_ANY_REAL_type(second_type) && is_literal_real_type(first_type))
|
|
292 |
{return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
|
|
293 |
|
|
294 |
/* no common type */
|
|
295 |
return NULL;
|
|
296 |
}
|
|
297 |
|
|
298 |
/* Determine the common data type between two data types.
|
|
299 |
* Unlike the common_type__() function, we stop the compiler with an ERROR
|
|
300 |
* if no common data type is found.
|
|
301 |
*/
|
|
302 |
symbol_c *visit_expression_type_c::common_type(symbol_c *first_type, symbol_c *second_type) {
|
|
303 |
symbol_c *res = common_type__(first_type, second_type);
|
|
304 |
if (NULL == res) ERROR;
|
|
305 |
return res;
|
|
306 |
}
|
|
307 |
|
|
308 |
|
|
309 |
/* Return TRUE if there is a common data type, otherwise return FALSE
|
|
310 |
*/
|
|
311 |
bool visit_expression_type_c::is_compatible_type(symbol_c *first_type, symbol_c *second_type) {
|
|
312 |
if (first_type == NULL || second_type == NULL) {ERROR;}
|
|
313 |
return (NULL != common_type__(first_type, second_type));
|
|
314 |
}
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
#define is_num_type is_ANY_NUM_type
|
|
319 |
#define is_integer_type is_ANY_INT_type
|
|
320 |
#define is_real_type is_ANY_REAL_type
|
|
321 |
#define is_binary_type is_ANY_BIT_type
|
|
322 |
/* actually the ROR, ROL, SHL, and SHR function also accept boolean type! */
|
|
323 |
#define is_nbinary_type is_ANY_BIT_type
|
|
324 |
#define compute_standard_function_default visit_expression_type_c::compute_standard_function_default
|
|
325 |
#define compute_standard_function_il visit_expression_type_c::compute_standard_function_il
|
|
326 |
#define search_expression_type_c visit_expression_type_c
|
|
327 |
#define search(x) search_f(x)
|
|
328 |
#define next() next_nf()
|
|
329 |
// #define search_constant_type_c::constant_int_type_name search_expression_type_c::integer
|
|
330 |
#define constant_int_type_name integer
|
|
331 |
#define is_same_type is_compatible_type
|
|
332 |
#include "../absyntax_utils/search_type_code.c"
|
|
333 |
#undef is_same_type
|
|
334 |
#undef constant_int_type_name
|
|
335 |
// #undef search_constant_type_c::constant_int_type_name
|
|
336 |
#undef next
|
|
337 |
#undef search
|
|
338 |
#undef compute_standard_function_default
|
|
339 |
#undef compute_standard_function_il
|
|
340 |
#undef search_expression_type_c
|
|
341 |
#undef is_real_type
|
|
342 |
#undef is_binary_type
|
|
343 |
#undef is_nbinary_type
|
|
344 |
#undef is_integer_type
|
|
345 |
#undef is_num_type
|
|
346 |
|
|
347 |
|
|
348 |
|
|
349 |
|
|
350 |
|
|
351 |
|
|
352 |
/* A helper function... */
|
|
353 |
symbol_c *visit_expression_type_c::compute_boolean_expression(symbol_c *left_type, symbol_c *right_type,
|
|
354 |
is_data_type_t is_data_type) {
|
|
355 |
bool error = false;
|
|
356 |
|
|
357 |
if (!(this->*is_data_type)(left_type)) {
|
|
358 |
STAGE3_ERROR(left_type, left_type, "invalid data type of first operand.");
|
|
359 |
error = true;
|
|
360 |
}
|
|
361 |
if (!(this->*is_data_type)(right_type)) {
|
|
362 |
STAGE3_ERROR(right_type, right_type, "invalid data type of second operand.");
|
|
363 |
error = true;
|
|
364 |
}
|
|
365 |
if (!is_compatible_type(left_type, right_type)) {
|
|
366 |
STAGE3_ERROR(left_type, right_type, "type mismatch between operands.");
|
|
367 |
error = true;
|
|
368 |
}
|
|
369 |
|
|
370 |
if (error)
|
|
371 |
return NULL;
|
|
372 |
else
|
|
373 |
return common_type(left_type, right_type);
|
|
374 |
}
|
|
375 |
|
|
376 |
|
|
377 |
/* A helper function... */
|
|
378 |
symbol_c *visit_expression_type_c::compute_numeric_expression(symbol_c *left_type, symbol_c *right_type,
|
|
379 |
is_data_type_t is_data_type) {
|
|
380 |
if (!(this->*is_data_type)(left_type))
|
|
381 |
STAGE3_ERROR(left_type, right_type, "Both parts of the equation must be the same type.");
|
|
382 |
if (!(this->*is_data_type)(right_type))
|
|
383 |
STAGE3_ERROR(left_type, right_type, "Both parts of the equation must be the same type.");
|
|
384 |
if (!is_compatible_type(left_type, right_type))
|
|
385 |
STAGE3_ERROR(left_type, right_type, "Both parts of the equation must be the same type.");
|
|
386 |
|
|
387 |
if (is_literal_integer_type(left_type) || is_literal_real_type(left_type)) {
|
|
388 |
return right_type;
|
|
389 |
} else {
|
|
390 |
return left_type;
|
|
391 |
}
|
|
392 |
|
|
393 |
/* humour the compiler... */
|
|
394 |
return NULL;
|
|
395 |
}
|
|
396 |
|
|
397 |
|
|
398 |
|
|
399 |
|
|
400 |
|
|
401 |
|
|
402 |
/* A helper function... */
|
|
403 |
/* check the semantics of a FB or Function non-formal call */
|
|
404 |
/* e.g. foo(1, 2, 3, 4); */
|
|
405 |
void visit_expression_type_c::check_nonformal_call(symbol_c *f_call, symbol_c *f_decl, bool use_il_defvar) {
|
|
406 |
symbol_c *call_param_value, *call_param_type, *param_type;
|
|
407 |
identifier_c *param_name;
|
|
408 |
function_param_iterator_c fp_iterator(f_decl);
|
|
409 |
function_call_param_iterator_c fcp_iterator(f_call);
|
|
410 |
|
|
411 |
/* if use_il_defvar, then the first parameter for the call comes from the il_default_variable */
|
|
412 |
if (use_il_defvar) {
|
|
413 |
/* The first parameter of the function corresponds to the il_default_variable_type of the function call */
|
|
414 |
do {
|
|
415 |
param_name = fp_iterator.next();
|
|
416 |
if(param_name == NULL) break;
|
|
417 |
/* The EN and ENO parameters are default parameters.
|
|
418 |
* In the non-formal invocation of a function there can be no assignment of
|
|
419 |
* values to these parameters. Therefore, we ignore the parameters declared
|
|
420 |
* in the function.
|
|
421 |
*/
|
|
422 |
} while ((strcmp(param_name->value, "EN") == 0) || (strcmp(param_name->value, "ENO") == 0));
|
|
423 |
/* If the function does not have any parameters (param_name == NULL)
|
|
424 |
* then we cannot compare its type with the il_default_variable_type.
|
|
425 |
*/
|
|
426 |
if(param_name != NULL) {
|
|
427 |
param_type = fp_iterator.param_type();
|
|
428 |
if(!is_compatible_type(il_default_variable_type,param_type))
|
|
429 |
STAGE3_ERROR(f_call, f_call, "In function/FB call, first parameter has invalid data type.");
|
|
430 |
}
|
|
431 |
} // if (use_il_defvar)
|
|
432 |
|
|
433 |
/* Iterating through the non-formal parameters of the function call */
|
|
434 |
while((call_param_value = fcp_iterator.next_nf()) != NULL) {
|
|
435 |
/* Obtaining the type of the current parameter in the function call */
|
|
436 |
call_param_type = base_type((symbol_c*)call_param_value->accept(*this));
|
|
437 |
if (call_param_type == NULL) STAGE3_ERROR(call_param_value, call_param_value, "Could not determine data type of value being passed in function/FB call.");;
|
|
438 |
|
|
439 |
/* Iterate to the next parameter of the function being called.
|
|
440 |
* Get the name of that parameter, and ignore if EN or ENO.
|
|
441 |
*/
|
|
442 |
do {
|
|
443 |
param_name = fp_iterator.next();
|
|
444 |
/* If there is no parameter declared with that name */
|
|
445 |
if(param_name == NULL) {STAGE3_ERROR(f_call, f_call, "Too many parameters in function/FB call."); break;}
|
|
446 |
} while ((strcmp(param_name->value, "EN") == 0) || (strcmp(param_name->value, "ENO") == 0));
|
|
447 |
|
|
448 |
if(param_name != NULL) {
|
|
449 |
/* Get the parameter type */
|
|
450 |
param_type = fp_iterator.param_type();
|
|
451 |
/* If the declared parameter and the parameter from the function call do no have the same type */
|
|
452 |
if(!is_compatible_type(call_param_type,param_type)) STAGE3_ERROR(call_param_value, call_param_value, "Type mismatch in function/FB call parameter.");
|
|
453 |
}
|
|
454 |
}
|
|
455 |
}
|
|
456 |
|
|
457 |
void visit_expression_type_c::compute_input_operatores(symbol_c *symbol, const char *input_operator){
|
|
458 |
symbol_c *call_param_type;
|
|
459 |
symbol_c *fb_decl = il_operand_type;
|
|
460 |
/* The following should never occur. The function block must be defined,
|
|
461 |
* and the FB type being called MUST be in the symtable...
|
|
462 |
* This was all already checked at stage 2!
|
|
463 |
*/
|
|
464 |
if (NULL == fb_decl){
|
|
465 |
STAGE3_ERROR(symbol, symbol, "Parameter operator needs an instance of a function block operand.");
|
|
466 |
ERROR;
|
|
467 |
}
|
|
468 |
|
|
469 |
/* Iterating through the formal parameters of the function call */
|
|
470 |
identifier_c call_param_name(input_operator);
|
|
471 |
|
|
472 |
/* Obtaining the type of the value being passed in the function call */
|
|
473 |
call_param_type = il_default_variable_type;
|
|
474 |
if (call_param_type == NULL) {
|
|
475 |
STAGE3_ERROR(&call_param_name, &call_param_name, "Could not determine data type of value being passed in function/FB call.");
|
|
476 |
/* The data value being passed is possibly any enumerated type value.
|
|
477 |
* We do not yet handle semantic verification of enumerated types.
|
|
478 |
*/
|
|
479 |
ERROR;
|
|
480 |
}
|
|
481 |
call_param_type = base_type(call_param_type);
|
|
482 |
if (call_param_type == NULL) STAGE3_ERROR(&call_param_name, &call_param_name, "Could not determine data type of value being passed in function/FB call.");
|
|
483 |
|
|
484 |
|
|
485 |
check_formal_parameter(&call_param_name, call_param_type, fb_decl);
|
|
486 |
// return NULL;
|
|
487 |
}
|
|
488 |
|
|
489 |
void visit_expression_type_c::check_formal_parameter(symbol_c *call_param_name, symbol_c *call_param_type, symbol_c *f_decl) {
|
|
490 |
symbol_c *param_type;
|
|
491 |
identifier_c *param_name;
|
|
492 |
function_param_iterator_c fp_iterator(f_decl);
|
|
493 |
|
|
494 |
/* Find the corresponding parameter of the function being called */
|
|
495 |
param_name = fp_iterator.search(call_param_name);
|
|
496 |
if(param_name == NULL) {
|
|
497 |
STAGE3_ERROR(call_param_name, call_param_name, "Invalid parameter in function/FB call.");
|
|
498 |
} else {
|
|
499 |
/* Get the parameter type */
|
|
500 |
param_type = fp_iterator.param_type();
|
|
501 |
/* If the declared parameter and the parameter from the function call have the same type */
|
|
502 |
// if(!is_compatible_type(call_param_type, param_type)) STAGE3_ERROR(call_param_name, call_param_value, "Type mismatch function/FB call parameter.");
|
|
503 |
if(!is_compatible_type(call_param_type, param_type)) STAGE3_ERROR(call_param_name, call_param_name, "Type mismatch function/FB call parameter.");
|
|
504 |
}
|
|
505 |
}
|
|
506 |
|
|
507 |
|
|
508 |
/* A helper function... */
|
|
509 |
/* check the semantics of a FB or Function formal call */
|
|
510 |
/* e.g. foo(IN1 := 1, OUT1 =>x, EN := true); */
|
|
511 |
void visit_expression_type_c::check_formal_call(symbol_c *f_call, symbol_c *f_decl) {
|
|
512 |
symbol_c *call_param_value, *call_param_type, *call_param_name, *param_type;
|
|
513 |
symbol_c *verify_duplicate_param;
|
|
514 |
identifier_c *param_name;
|
|
515 |
function_param_iterator_c fp_iterator(f_decl);
|
|
516 |
function_call_param_iterator_c fcp_iterator(f_call);
|
|
517 |
|
|
518 |
/* Iterating through the formal parameters of the function call */
|
|
519 |
while((call_param_name = fcp_iterator.next_f()) != NULL) {
|
|
520 |
|
|
521 |
/* Obtaining the value being passed in the function call */
|
|
522 |
call_param_value = fcp_iterator.get_current_value();
|
|
523 |
/* the following should never occur. If it does, then we have a bug in our code... */
|
|
524 |
if (NULL == call_param_value) ERROR;
|
|
525 |
|
|
526 |
/* Checking if there are duplicated parameter values */
|
|
527 |
verify_duplicate_param = fcp_iterator.search_f(call_param_name);
|
|
528 |
if(verify_duplicate_param != call_param_value){
|
|
529 |
STAGE3_ERROR(call_param_name, verify_duplicate_param, "Duplicated parameter values.");
|
|
530 |
}
|
|
531 |
|
|
532 |
/* Obtaining the type of the value being passed in the function call */
|
|
533 |
call_param_type = (symbol_c*)call_param_value->accept(*this);
|
|
534 |
if (call_param_type == NULL) {
|
|
535 |
STAGE3_ERROR(call_param_name, call_param_value, "Could not determine data type of value being passed in function/FB call.");
|
|
536 |
/* The data value being passed is possibly any enumerated type value.
|
|
537 |
* We do not yet handle semantic verification of enumerated types.
|
|
538 |
*/
|
|
539 |
ERROR;
|
|
540 |
}
|
|
541 |
call_param_type = base_type(call_param_type);
|
|
542 |
if (call_param_type == NULL) STAGE3_ERROR(call_param_name, call_param_value, "Could not determine data type of value being passed in function/FB call.");
|
|
543 |
|
|
544 |
/* Find the corresponding parameter of the function being called */
|
|
545 |
param_name = fp_iterator.search(call_param_name);
|
|
546 |
if(param_name == NULL) {
|
|
547 |
STAGE3_ERROR(call_param_name, call_param_name, "Invalid parameter in function/FB call.");
|
|
548 |
} else {
|
|
549 |
/* Get the parameter type */
|
|
550 |
param_type = fp_iterator.param_type();
|
|
551 |
/* If the declared parameter and the parameter from the function call have the same type */
|
|
552 |
if(!is_compatible_type(call_param_type, param_type)) STAGE3_ERROR(call_param_name, call_param_value, "Type mismatch function/FB call parameter.");
|
|
553 |
}
|
|
554 |
}
|
|
555 |
}
|
|
556 |
|
|
557 |
|
|
558 |
|
|
559 |
|
|
560 |
/* a helper function... */
|
|
561 |
symbol_c *visit_expression_type_c::base_type(symbol_c *symbol) {
|
|
562 |
return (symbol_c *)symbol->accept(search_base_type);
|
|
563 |
}
|
|
564 |
|
|
565 |
|
|
566 |
/* a helper function... */
|
|
567 |
void *visit_expression_type_c::verify_null(symbol_c *symbol){
|
|
568 |
if(il_default_variable_type == NULL){
|
|
569 |
STAGE3_ERROR(symbol, symbol, "Il default variable can't be NULL.");
|
|
570 |
}
|
|
571 |
if(il_operand_type == NULL){
|
|
572 |
STAGE3_ERROR(symbol, symbol, "function requires an operand.");
|
|
573 |
}
|
|
574 |
return NULL;
|
|
575 |
}
|
|
576 |
|
|
577 |
|
|
578 |
|
|
579 |
|
|
580 |
/*********************/
|
|
581 |
/* B 1.4 - Variables */
|
|
582 |
/*********************/
|
|
583 |
|
|
584 |
void *visit_expression_type_c::visit(symbolic_variable_c *symbol) {
|
|
585 |
return search_varfb_instance_type->get_type(symbol);
|
|
586 |
}
|
|
587 |
|
|
588 |
/********************************************/
|
|
589 |
/* B 1.4.1 - Directly Represented Variables */
|
|
590 |
/********************************************/
|
|
591 |
void *visit_expression_type_c::visit(direct_variable_c *symbol) {
|
|
592 |
switch (symbol->value[2]) {
|
|
593 |
case 'X': // bit - 1 bit
|
|
594 |
return (void *)&bool_type_name;
|
|
595 |
case 'B': // byte - 8 bits
|
|
596 |
return (void *)&byte_type_name;
|
|
597 |
case 'W': // word - 16 bits
|
|
598 |
return (void *)&word_type_name;
|
|
599 |
case 'D': // double word - 32 bits
|
|
600 |
return (void *)&dword_type_name;
|
|
601 |
case 'L': // long word - 64 bits
|
|
602 |
return (void *)&lword_type_name;
|
|
603 |
default: // if none of the above, then the empty string was used <=> boolean
|
|
604 |
return (void *)&bool_type_name;
|
|
605 |
}
|
|
606 |
}
|
|
607 |
|
|
608 |
/*************************************/
|
|
609 |
/* B 1.4.2 - Multi-element variables */
|
|
610 |
/*************************************/
|
|
611 |
void *visit_expression_type_c::visit(array_variable_c *symbol) {
|
|
612 |
return search_varfb_instance_type->get_type(symbol);
|
|
613 |
}
|
|
614 |
|
|
615 |
void *visit_expression_type_c::visit(structured_variable_c *symbol) {
|
|
616 |
return search_varfb_instance_type->get_type(symbol);
|
|
617 |
}
|
|
618 |
|
|
619 |
|
|
620 |
|
|
621 |
/****************************************/
|
|
622 |
/* B.2 - Language IL (Instruction List) */
|
|
623 |
/****************************************/
|
|
624 |
/***********************************/
|
|
625 |
/* B 2.1 Instructions and Operands */
|
|
626 |
/***********************************/
|
|
627 |
/*| instruction_list il_instruction */
|
|
628 |
/* The visitor of the base class search_visitor_c will handle calling each instruction in the list.
|
|
629 |
* We do not need to do anything here...
|
|
630 |
*/
|
|
631 |
// void *visit_expression_type_c::visit(instruction_list_c *symbol)
|
|
632 |
|
|
633 |
/* | label ':' [il_incomplete_instruction] eol_list */
|
|
634 |
//SYM_REF2(il_instruction_c, label, il_instruction)
|
|
635 |
// void *visit_expression_type_c::visit(il_instruction_c *symbol);
|
|
636 |
|
|
637 |
|
|
638 |
/* | il_simple_operator [il_operand] */
|
|
639 |
// SYM_REF2(il_simple_operation_c, il_simple_operator, il_operand)
|
|
640 |
void *visit_expression_type_c::visit(il_simple_operation_c *symbol) {
|
|
641 |
if (il_error)
|
|
642 |
return NULL;
|
|
643 |
|
|
644 |
/* determine the data type of the operand */
|
|
645 |
if (symbol->il_operand != NULL){
|
|
646 |
il_operand_type = base_type((symbol_c *)symbol->il_operand->accept(*this));
|
|
647 |
} else {
|
|
648 |
il_operand_type = NULL;
|
|
649 |
}
|
|
650 |
/* recursive call to see whether data types are compatible */
|
|
651 |
symbol->il_simple_operator->accept(*this);
|
|
652 |
|
|
653 |
il_operand_type = NULL;
|
|
654 |
return NULL;
|
|
655 |
}
|
|
656 |
|
|
657 |
// | function_name [il_operand_list] */
|
|
658 |
//SYM_REF2(il_function_call_c, function_name, il_operand_list)
|
|
659 |
void *visit_expression_type_c::visit(il_function_call_c *symbol) {
|
|
660 |
if (il_error)
|
|
661 |
return NULL;
|
|
662 |
|
|
663 |
/* First find the declaration of the function being called! */
|
|
664 |
function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name);
|
|
665 |
|
|
666 |
symbol_c *return_data_type = NULL;
|
|
667 |
|
|
668 |
if (f_decl == function_symtable.end_value()) {
|
|
669 |
function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name);
|
|
670 |
if (current_function_type == function_none) ERROR;
|
|
671 |
/* This code is for the functions that the user did not declare and that are
|
|
672 |
* part of the IL or ST languagem (built-in functions).
|
|
673 |
* For now we won't do the semantics analysis for that kind of functions.
|
|
674 |
*/
|
|
675 |
/*
|
|
676 |
return_data_type = (symbol_c *)search_expression_type->compute_standard_function_default(NULL, symbol);
|
|
677 |
if (NULL == return_data_type) ERROR;
|
|
678 |
|
|
679 |
function_call_param_iterator_c fcp_iterator(symbol);
|
|
680 |
|
|
681 |
int nb_param = 0;
|
|
682 |
if (symbol->il_param_list != NULL)
|
|
683 |
nb_param += ((list_c *)symbol->il_param_list)->n;
|
|
684 |
|
|
685 |
identifier_c en_param_name("EN");*/
|
|
686 |
/* Get the value from EN param */
|
|
687 |
/*symbol_c *EN_param_value = fcp_iterator.search(&en_param_name);
|
|
688 |
if (EN_param_value == NULL)
|
|
689 |
EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c()));
|
|
690 |
else
|
|
691 |
nb_param --;
|
|
692 |
ADD_PARAM_LIST(EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in)
|
|
693 |
|
|
694 |
identifier_c eno_param_name("EN0");*/
|
|
695 |
/* Get the value from ENO param */
|
|
696 |
/*symbol_c *ENO_param_value = fcp_iterator.search(&eno_param_name);
|
|
697 |
if (ENO_param_value != NULL)
|
|
698 |
nb_param --;
|
|
699 |
ADD_PARAM_LIST(ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out)
|
|
700 |
|
|
701 |
#include "st_code_gen.c"
|
|
702 |
*/
|
|
703 |
} else {
|
|
704 |
/* determine the base data type returned by the function being called... */
|
|
705 |
return_data_type = base_type(f_decl->type_name);
|
|
706 |
/* If the following occurs, then we must have some big bug in the syntax parser (stage 2)... */
|
|
707 |
if (NULL == return_data_type) ERROR;
|
|
708 |
|
|
709 |
/* check semantics of data passed in the function call... */
|
|
710 |
check_nonformal_call(symbol, f_decl, true);
|
|
711 |
|
|
712 |
/* set the new ddata type of the default variable for the following verifications... */
|
|
713 |
il_default_variable_type = return_data_type;
|
|
714 |
}
|
|
715 |
return NULL;
|
|
716 |
}
|
|
717 |
|
|
718 |
|
|
719 |
/* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */
|
|
720 |
// SYM_REF3(il_expression_c, il_expr_operator, il_operand, simple_instr_list);
|
|
721 |
void *visit_expression_type_c::visit(il_expression_c *symbol) {
|
|
722 |
if (il_error)
|
|
723 |
return NULL;
|
|
724 |
|
|
725 |
symbol_c *il_default_variable_type_back = il_default_variable_type;
|
|
726 |
|
|
727 |
il_parenthesis_level++;
|
|
728 |
|
|
729 |
if(symbol->il_operand != NULL) {
|
|
730 |
il_default_variable_type = base_type((symbol_c *)symbol->il_operand->accept(*this));
|
|
731 |
} else {
|
|
732 |
il_default_variable_type = NULL;
|
|
733 |
}
|
|
734 |
|
|
735 |
if(symbol->simple_instr_list != NULL) {
|
|
736 |
symbol->simple_instr_list->accept(*this);
|
|
737 |
}
|
|
738 |
|
|
739 |
il_parenthesis_level--;
|
|
740 |
if (il_parenthesis_level < 0) ERROR;
|
|
741 |
|
|
742 |
il_operand_type = il_default_variable_type;
|
|
743 |
il_default_variable_type = il_default_variable_type_back;
|
|
744 |
|
|
745 |
/* Now check the if the data type semantics of operation are correct,
|
|
746 |
* but only if no previous error has been found...
|
|
747 |
*/
|
|
748 |
if (il_error)
|
|
749 |
return NULL;
|
|
750 |
symbol->il_expr_operator->accept(*this);
|
|
751 |
|
|
752 |
return NULL;
|
|
753 |
}
|
|
754 |
|
|
755 |
|
|
756 |
#if 0
|
|
757 |
/* il_jump_operator label */
|
|
758 |
SYM_REF2(il_jump_operation_c, il_jump_operator, label)
|
|
759 |
void *visit_expression_type_c::visit(il_jump_operation_c *symbol);
|
|
760 |
#endif
|
|
761 |
|
|
762 |
|
|
763 |
/* il_call_operator prev_declared_fb_name
|
|
764 |
* | il_call_operator prev_declared_fb_name '(' ')'
|
|
765 |
* | il_call_operator prev_declared_fb_name '(' eol_list ')'
|
|
766 |
* | il_call_operator prev_declared_fb_name '(' il_operand_list ')'
|
|
767 |
* | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')'
|
|
768 |
*/
|
|
769 |
/* SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list) */
|
|
770 |
void *visit_expression_type_c::visit(il_fb_call_c *symbol) {
|
|
771 |
if (il_error)
|
|
772 |
return NULL;
|
|
773 |
|
|
774 |
/* first check whether the il_default_variable is of the correct type
|
|
775 |
* for the CAL / CALC / CALCN operator being used...
|
|
776 |
*/
|
|
777 |
symbol->il_call_operator->accept(*this);
|
|
778 |
|
|
779 |
/* Now check the FB call itself... */
|
|
780 |
|
|
781 |
/* First we find the declaration of the FB type of the FB instance being called... */
|
|
782 |
/* e.g. Function_block foo_fb_type
|
|
783 |
* ...
|
|
784 |
* End_Function_Block
|
|
785 |
*
|
|
786 |
* Program test
|
|
787 |
* var fb1 : foo_fb_type; end_var
|
|
788 |
* fb1(...)
|
|
789 |
* End_Program
|
|
790 |
*
|
|
791 |
* search_varfb_instance_type->get_type( identifier_c("fb1") )
|
|
792 |
* in the scope of Program 'test'
|
|
793 |
* will return the fb declaration of foo_fb_type !!
|
|
794 |
*/
|
|
795 |
#if 0
|
|
796 |
symbol_c *fb_decl_symbol = search_varfb_instance_type->get_type(symbol->fb_name);
|
|
797 |
/* The following should never occur. The function block must be defined,
|
|
798 |
* and the FB type being called MUST be in the symtable...
|
|
799 |
* This was all already checked at stage 2!
|
|
800 |
*/
|
|
801 |
if (NULL == fb_decl_symbol) ERROR;
|
|
802 |
|
|
803 |
function_block_declaration_c *fb_decl = dynamic_cast<function_block_declaration_c *>(fb_decl_symbol);
|
|
804 |
/* should never occur. ... */
|
|
805 |
if (NULL == fb_decl) ERROR;
|
|
806 |
#endif
|
|
807 |
symbol_c *fb_decl = search_varfb_instance_type->get_type(symbol->fb_name);
|
|
808 |
/* The following should never occur. The function block must be defined,
|
|
809 |
* and the FB type being called MUST be in the symtable...
|
|
810 |
* This was all already checked at stage 2!
|
|
811 |
*/
|
|
812 |
if (NULL == fb_decl) ERROR;
|
|
813 |
|
|
814 |
/* now check the semantics of the fb call... */
|
|
815 |
/* If the syntax parser is working correctly, exactly one of the
|
|
816 |
* following two symbols will be NULL, while the other is != NULL.
|
|
817 |
*/
|
|
818 |
if (NULL != symbol->il_operand_list) check_nonformal_call(symbol, fb_decl);
|
|
819 |
if (NULL != symbol->il_param_list) check_formal_call (symbol, fb_decl);
|
|
820 |
|
|
821 |
return NULL;
|
|
822 |
}
|
|
823 |
|
|
824 |
|
|
825 |
|
|
826 |
/* | function_name '(' eol_list [il_param_list] ')' */
|
|
827 |
/* SYM_REF2(il_formal_funct_call_c, function_name, il_param_list) */
|
|
828 |
void *visit_expression_type_c::visit(il_formal_funct_call_c *symbol) {
|
|
829 |
if (il_error)
|
|
830 |
return NULL;
|
|
831 |
|
|
832 |
function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name);
|
|
833 |
|
|
834 |
symbol_c *return_data_type = NULL;
|
|
835 |
|
|
836 |
if (f_decl == function_symtable.end_value()) {
|
|
837 |
function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name);
|
|
838 |
if (current_function_type == function_none) ERROR;
|
|
839 |
|
|
840 |
/* This code is for the functions that the user did not declare and that are
|
|
841 |
* part of the IL or ST languagem (built-in functions).
|
|
842 |
* For now we won't do the semantics analysis for that kind of functions.
|
|
843 |
*/
|
|
844 |
#if 0
|
|
845 |
return_data_type = (symbol_c *)search_expression_type->compute_standard_function_default(NULL, symbol);
|
|
846 |
if (NULL == return_data_type) ERROR;
|
|
847 |
|
|
848 |
function_call_param_iterator_c fcp_iterator(symbol);
|
|
849 |
|
|
850 |
int nb_param = 0;
|
|
851 |
if (symbol->il_param_list != NULL)
|
|
852 |
nb_param += ((list_c *)symbol->il_param_list)->n;
|
|
853 |
|
|
854 |
identifier_c en_param_name("EN");
|
|
855 |
/* Get the value from EN param */
|
|
856 |
symbol_c *EN_param_value = fcp_iterator.search(&en_param_name);
|
|
857 |
if (EN_param_value == NULL)
|
|
858 |
EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c()));
|
|
859 |
else
|
|
860 |
nb_param --;
|
|
861 |
ADD_PARAM_LIST(EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in)
|
|
862 |
|
|
863 |
identifier_c eno_param_name("EN0");
|
|
864 |
/* Get the value from ENO param */
|
|
865 |
symbol_c *ENO_param_value = fcp_iterator.search(&eno_param_name);
|
|
866 |
if (ENO_param_value != NULL)
|
|
867 |
nb_param --;
|
|
868 |
ADD_PARAM_LIST(ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out)
|
|
869 |
|
|
870 |
#include "st_code_gen.c"
|
|
871 |
#endif
|
|
872 |
} else {
|
|
873 |
/* determine the base data type returned by the function being called... */
|
|
874 |
return_data_type = base_type(f_decl->type_name);
|
|
875 |
/* the following should never occur. If it does, then we have a bug in the syntax parser (stage 2)... */
|
|
876 |
if (NULL == return_data_type) ERROR;
|
|
877 |
|
|
878 |
/* check semantics of data passed in the function call... */
|
|
879 |
check_formal_call(symbol, f_decl);
|
|
880 |
|
|
881 |
/* the data type of the data returned by the function, and stored in the il default variable... */
|
|
882 |
il_default_variable_type = return_data_type;
|
|
883 |
}
|
|
884 |
return NULL;
|
|
885 |
}
|
|
886 |
|
|
887 |
|
|
888 |
#if 0
|
|
889 |
/* | il_operand_list ',' il_operand */
|
|
890 |
SYM_LIST(il_operand_list_c)
|
|
891 |
void *visit_expression_type_c::visit(il_operand_list_c *symbol);
|
|
892 |
|
|
893 |
/* | simple_instr_list il_simple_instruction */
|
|
894 |
SYM_LIST(simple_instr_list_c)
|
|
895 |
void *visit_expression_type_c::visit(simple_instr_list_c *symbol);
|
|
896 |
|
|
897 |
/* | il_initial_param_list il_param_instruction */
|
|
898 |
SYM_LIST(il_param_list_c)
|
|
899 |
void *visit_expression_type_c::visit(il_param_list_c *symbol);
|
|
900 |
|
|
901 |
/* il_assign_operator il_operand
|
|
902 |
* | il_assign_operator '(' eol_list simple_instr_list ')'
|
|
903 |
*/
|
|
904 |
SYM_REF3(il_param_assignment_c, il_assign_operator, il_operand, simple_instr_list)
|
|
905 |
void *visit_expression_type_c::visit(il_param_assignment_c *symbol);
|
|
906 |
/* il_assign_out_operator variable */
|
|
907 |
SYM_REF2(il_param_out_assignment_c, il_assign_out_operator, variable)
|
|
908 |
void *visit_expression_type_c::visit(il_param_out_assignment_c *symbol);
|
|
909 |
|
|
910 |
#endif
|
|
911 |
|
|
912 |
|
|
913 |
/*******************/
|
|
914 |
/* B 2.2 Operators */
|
|
915 |
/*******************/
|
|
916 |
|
|
917 |
//SYM_REF0(LD_operator_c)
|
|
918 |
void *visit_expression_type_c::visit(LD_operator_c *symbol) {
|
|
919 |
if (0 == il_parenthesis_level)
|
|
920 |
il_error = false;
|
|
921 |
|
|
922 |
if(il_operand_type == NULL)
|
|
923 |
STAGE3_ERROR(symbol, symbol, "LD operator requires an operand.");
|
|
924 |
il_default_variable_type = il_operand_type;
|
|
925 |
return NULL;
|
|
926 |
}
|
|
927 |
|
|
928 |
// SYM_REF0(LDN_operator_c)
|
|
929 |
void *visit_expression_type_c::visit(LDN_operator_c *symbol) {
|
|
930 |
if(il_operand_type == NULL)
|
|
931 |
STAGE3_ERROR(symbol, symbol, "LDN operator requires an operand.");
|
|
932 |
if(!is_ANY_BIT_type(il_operand_type))
|
|
933 |
STAGE3_ERROR(symbol, symbol, "invalid data type of LDN operand, should be of type ANY_BIT.");
|
|
934 |
il_default_variable_type = il_operand_type;
|
|
935 |
return NULL;
|
|
936 |
}
|
|
937 |
|
|
938 |
// SYM_REF0(ST_operator_c)
|
|
939 |
void *visit_expression_type_c::visit(ST_operator_c *symbol) {
|
|
940 |
verify_null(symbol);
|
|
941 |
if(!is_compatible_type(il_default_variable_type, il_operand_type))
|
|
942 |
STAGE3_ERROR(symbol, symbol, "Type mismatch in ST operation.");
|
|
943 |
/* TODO: check whether il_operand_type is an LVALUE !! */
|
|
944 |
/* data type of il_default_variable_type is unchanged... */
|
|
945 |
// il_default_variable_type = il_default_variable_type;
|
|
946 |
return NULL;
|
|
947 |
}
|
|
948 |
|
|
949 |
// SYM_REF0(STN_operator_c)
|
|
950 |
void *visit_expression_type_c::visit(STN_operator_c *symbol) {
|
|
951 |
verify_null(symbol);
|
|
952 |
if(!is_compatible_type(il_default_variable_type, il_operand_type))
|
|
953 |
STAGE3_ERROR(symbol, symbol, "Type mismatch in ST operation.");
|
|
954 |
/* TODO: check whether il_operand_type is an LVALUE !! */
|
|
955 |
if(!is_ANY_BIT_type(il_default_variable_type))
|
|
956 |
STAGE3_ERROR(symbol, symbol, "invalid data type of il_default_variable for STN operand, should be of type ANY_BIT.");
|
|
957 |
if(!is_ANY_BIT_type(il_operand_type))
|
|
958 |
STAGE3_ERROR(symbol, symbol, "invalid data type of STN operand, should be of type ANY_BIT.");
|
|
959 |
/* data type of il_default_variable_type is unchanged... */
|
|
960 |
// il_default_variable_type = il_default_variable_type;
|
|
961 |
return NULL;
|
|
962 |
}
|
|
963 |
|
|
964 |
//SYM_REF0(NOT_operator_c)
|
|
965 |
void *visit_expression_type_c::visit(NOT_operator_c *symbol) {
|
|
966 |
if(il_operand_type != NULL){
|
|
967 |
STAGE3_ERROR(symbol, symbol, "NOT operator may not have an operand.");
|
|
968 |
return NULL;
|
|
969 |
}
|
|
970 |
if(il_default_variable_type == NULL) {
|
|
971 |
STAGE3_ERROR(symbol, symbol, "Il default variable should not be NULL.");
|
|
972 |
return NULL;
|
|
973 |
}
|
|
974 |
if(!is_ANY_BIT_type(il_default_variable_type)) {
|
|
975 |
STAGE3_ERROR(symbol, symbol, "Il default variable should be of type ANY_BIT.");
|
|
976 |
return NULL;
|
|
977 |
}
|
|
978 |
/* data type of il_default_variable_type is unchanged... */
|
|
979 |
// il_default_variable_type = il_default_variable_type;
|
|
980 |
return NULL;
|
|
981 |
}
|
|
982 |
|
|
983 |
// SYM_REF0(S_operator_c)
|
|
984 |
void *visit_expression_type_c::visit(S_operator_c *symbol) {
|
|
985 |
verify_null(symbol);
|
|
986 |
if (!is_BOOL_type(il_default_variable_type)) {STAGE3_ERROR(symbol, symbol, "IL default variable should be BOOL type.");}
|
|
987 |
if (!is_BOOL_type(il_operand_type)) {STAGE3_ERROR(symbol, symbol, "operator S requires operand of type BOOL.");}
|
|
988 |
/* TODO: check whether il_operand_type is an LVALUE !! */
|
|
989 |
/* data type of il_default_variable_type is unchanged... */
|
|
990 |
// il_default_variable_type = il_default_variable_type;
|
|
991 |
return NULL;
|
|
992 |
}
|
|
993 |
|
|
994 |
// SYM_REF0(R_operator_c)
|
|
995 |
void *visit_expression_type_c::visit(R_operator_c *symbol) {
|
|
996 |
verify_null(symbol);
|
|
997 |
if (!is_BOOL_type(il_default_variable_type)) {STAGE3_ERROR(symbol, symbol, "IL default variable should be BOOL type.");}
|
|
998 |
if (!is_BOOL_type(il_operand_type)) {STAGE3_ERROR(symbol, symbol, "operator R requires operand of type BOOL.");}
|
|
999 |
/* TODO: check whether il_operand_type is an LVALUE !! */
|
|
1000 |
/* data type of il_default_variable_type is unchanged... */
|
|
1001 |
// il_default_variable_type = il_default_variable_type;
|
|
1002 |
return NULL;
|
|
1003 |
}
|
|
1004 |
|
|
1005 |
|
|
1006 |
// SYM_REF0(S1_operator_c)
|
|
1007 |
void *visit_expression_type_c::visit(S1_operator_c *symbol){
|
|
1008 |
compute_input_operatores(symbol, "S1");
|
|
1009 |
return NULL;
|
|
1010 |
}
|
|
1011 |
|
|
1012 |
// SYM_REF0(R1_operator_c)
|
|
1013 |
void *visit_expression_type_c::visit(R1_operator_c *symbol) {
|
|
1014 |
compute_input_operatores(symbol, "R1");
|
|
1015 |
return NULL;
|
|
1016 |
}
|
|
1017 |
|
|
1018 |
// SYM_REF0(CLK_operator_c)
|
|
1019 |
void *visit_expression_type_c::visit(CLK_operator_c *symbol) {
|
|
1020 |
compute_input_operatores(symbol, "CLK");
|
|
1021 |
return NULL;
|
|
1022 |
}
|
|
1023 |
|
|
1024 |
// SYM_REF0(CU_operator_c)
|
|
1025 |
void *visit_expression_type_c::visit(CU_operator_c *symbol) {
|
|
1026 |
compute_input_operatores(symbol, "CU");
|
|
1027 |
return NULL;
|
|
1028 |
}
|
|
1029 |
|
|
1030 |
// SYM_REF0(CD_operator_c)
|
|
1031 |
void *visit_expression_type_c::visit(CD_operator_c *symbol) {
|
|
1032 |
compute_input_operatores(symbol, "CD");
|
|
1033 |
return NULL;
|
|
1034 |
}
|
|
1035 |
|
|
1036 |
// SYM_REF0(PV_operator_c)
|
|
1037 |
void *visit_expression_type_c::visit(PV_operator_c *symbol) {
|
|
1038 |
compute_input_operatores(symbol, "PV");
|
|
1039 |
return NULL;
|
|
1040 |
}
|
|
1041 |
|
|
1042 |
// SYM_REF0(IN_operator_c)
|
|
1043 |
void *visit_expression_type_c::visit(IN_operator_c *symbol) {
|
|
1044 |
compute_input_operatores(symbol, "IN");
|
|
1045 |
return NULL;
|
|
1046 |
}
|
|
1047 |
|
|
1048 |
// SYM_REF0(PT_operator_c)
|
|
1049 |
void *visit_expression_type_c::visit(PT_operator_c *symbol) {
|
|
1050 |
compute_input_operatores(symbol, "PT");
|
|
1051 |
return NULL;
|
|
1052 |
}
|
|
1053 |
|
|
1054 |
//SYM_REF0(AND_operator_c)
|
|
1055 |
void *visit_expression_type_c::visit(AND_operator_c *symbol) {
|
|
1056 |
verify_null(symbol);
|
|
1057 |
il_default_variable_type = compute_boolean_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_BIT_type);
|
|
1058 |
return NULL;
|
|
1059 |
}
|
|
1060 |
|
|
1061 |
//SYM_REF0(OR_operator_c)
|
|
1062 |
void *visit_expression_type_c::visit(OR_operator_c *symbol) {
|
|
1063 |
verify_null(symbol);
|
|
1064 |
il_default_variable_type = compute_boolean_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_BIT_type);
|
|
1065 |
return NULL;
|
|
1066 |
}
|
|
1067 |
|
|
1068 |
//SYM_REF0(XOR_operator_c)
|
|
1069 |
void *visit_expression_type_c::visit(XOR_operator_c *symbol) {
|
|
1070 |
verify_null(symbol);
|
|
1071 |
il_default_variable_type = compute_boolean_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_BIT_type);
|
|
1072 |
return NULL;
|
|
1073 |
}
|
|
1074 |
|
|
1075 |
// SYM_REF0(ANDN_operator_c)
|
|
1076 |
void *visit_expression_type_c::visit(ANDN_operator_c *symbol) {
|
|
1077 |
verify_null(symbol);
|
|
1078 |
il_default_variable_type = compute_boolean_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_BIT_type);
|
|
1079 |
return NULL;
|
|
1080 |
}
|
|
1081 |
|
|
1082 |
// SYM_REF0(ORN_operator_c)
|
|
1083 |
void *visit_expression_type_c::visit(ORN_operator_c *symbol) {
|
|
1084 |
verify_null(symbol);
|
|
1085 |
il_default_variable_type = compute_boolean_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_BIT_type);
|
|
1086 |
return NULL;
|
|
1087 |
}
|
|
1088 |
|
|
1089 |
// SYM_REF0(XORN_operator_c)
|
|
1090 |
void *visit_expression_type_c::visit(XORN_operator_c *symbol) {
|
|
1091 |
verify_null(symbol);
|
|
1092 |
il_default_variable_type = compute_boolean_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_BIT_type);
|
|
1093 |
return NULL;
|
|
1094 |
}
|
|
1095 |
|
|
1096 |
// SYM_REF0(ADD_operator_c)
|
|
1097 |
void *visit_expression_type_c::visit(ADD_operator_c *symbol) {
|
|
1098 |
verify_null(symbol);
|
|
1099 |
symbol_c *left_type = il_default_variable_type;
|
|
1100 |
symbol_c *right_type = il_operand_type;
|
|
1101 |
if (typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c))
|
|
1102 |
il_default_variable_type = &time_type_name;
|
|
1103 |
else if (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c))
|
|
1104 |
il_default_variable_type = &tod_type_name;
|
|
1105 |
else if (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c))
|
|
1106 |
il_default_variable_type = &dt_type_name;
|
|
1107 |
else il_default_variable_type = compute_numeric_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_MAGNITUDE_type);
|
|
1108 |
return NULL;
|
|
1109 |
}
|
|
1110 |
|
|
1111 |
// SYM_REF0(SUB_operator_c)
|
|
1112 |
void *visit_expression_type_c::visit(SUB_operator_c *symbol) {
|
|
1113 |
verify_null(symbol);
|
|
1114 |
symbol_c *left_type = il_default_variable_type;
|
|
1115 |
symbol_c *right_type = il_operand_type;;
|
|
1116 |
if (typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c))
|
|
1117 |
il_default_variable_type = &time_type_name;
|
|
1118 |
else if (typeid(*left_type) == typeid(date_type_name_c) && typeid(*right_type) == typeid(date_type_name_c))
|
|
1119 |
il_default_variable_type = &time_type_name;
|
|
1120 |
else if (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c))
|
|
1121 |
il_default_variable_type = &tod_type_name;
|
|
1122 |
else if (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(tod_type_name_c))
|
|
1123 |
il_default_variable_type = &time_type_name;
|
|
1124 |
else if (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c))
|
|
1125 |
il_default_variable_type = &dt_type_name;
|
|
1126 |
else if (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(dt_type_name_c))
|
|
1127 |
il_default_variable_type = &time_type_name;
|
|
1128 |
else il_default_variable_type = compute_numeric_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_MAGNITUDE_type);
|
|
1129 |
return NULL;
|
|
1130 |
}
|
|
1131 |
|
|
1132 |
// SYM_REF0(MUL_operator_c)
|
|
1133 |
void *visit_expression_type_c::visit(MUL_operator_c *symbol) {
|
|
1134 |
verify_null(symbol);
|
|
1135 |
symbol_c *left_type = il_default_variable_type;
|
|
1136 |
symbol_c *right_type = il_operand_type;
|
|
1137 |
if (typeid(*left_type) == typeid(time_type_name_c) && is_ANY_NUM_type(right_type))
|
|
1138 |
il_default_variable_type = &time_type_name;
|
|
1139 |
else il_default_variable_type = compute_numeric_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_NUM_type);
|
|
1140 |
return NULL;
|
|
1141 |
}
|
|
1142 |
|
|
1143 |
// SYM_REF0(DIV_operator_c)
|
|
1144 |
void *visit_expression_type_c::visit(DIV_operator_c *symbol) {
|
|
1145 |
verify_null(symbol);
|
|
1146 |
symbol_c *left_type = il_default_variable_type;
|
|
1147 |
symbol_c *right_type = il_operand_type;
|
|
1148 |
if (typeid(*left_type) == typeid(time_type_name_c) && is_ANY_NUM_type(right_type))
|
|
1149 |
il_default_variable_type = &time_type_name;
|
|
1150 |
else il_default_variable_type = compute_numeric_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_NUM_type);
|
|
1151 |
return NULL;
|
|
1152 |
}
|
|
1153 |
|
|
1154 |
// SYM_REF0(MOD_operator_c)
|
|
1155 |
void *visit_expression_type_c::visit(MOD_operator_c *symbol) {
|
|
1156 |
verify_null(symbol);
|
|
1157 |
il_default_variable_type = compute_numeric_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_INT_type);
|
|
1158 |
return NULL;
|
|
1159 |
}
|
|
1160 |
|
|
1161 |
// SYM_REF0(GT_operator_c)
|
|
1162 |
void *visit_expression_type_c::visit(GT_operator_c *symbol) {
|
|
1163 |
verify_null(symbol);
|
|
1164 |
compute_boolean_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
|
|
1165 |
il_default_variable_type = &search_expression_type_c::bool_type_name;
|
|
1166 |
return NULL;
|
|
1167 |
}
|
|
1168 |
|
|
1169 |
//SYM_REF0(GE_operator_c)
|
|
1170 |
void *visit_expression_type_c::visit(GE_operator_c *symbol) {
|
|
1171 |
verify_null(symbol);
|
|
1172 |
compute_boolean_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
|
|
1173 |
il_default_variable_type = &search_expression_type_c::bool_type_name;
|
|
1174 |
return NULL;
|
|
1175 |
}
|
|
1176 |
|
|
1177 |
//SYM_REF0(EQ_operator_c)
|
|
1178 |
void *visit_expression_type_c::visit(EQ_operator_c *symbol) {
|
|
1179 |
verify_null(symbol);
|
|
1180 |
compute_boolean_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
|
|
1181 |
il_default_variable_type = &search_expression_type_c::bool_type_name;
|
|
1182 |
return NULL;
|
|
1183 |
}
|
|
1184 |
|
|
1185 |
//SYM_REF0(LT_operator_c)
|
|
1186 |
void *visit_expression_type_c::visit(LT_operator_c *symbol) {
|
|
1187 |
verify_null(symbol);
|
|
1188 |
compute_boolean_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
|
|
1189 |
il_default_variable_type = &search_expression_type_c::bool_type_name;
|
|
1190 |
return NULL;
|
|
1191 |
}
|
|
1192 |
|
|
1193 |
//SYM_REF0(LE_operator_c)
|
|
1194 |
void *visit_expression_type_c::visit(LE_operator_c *symbol) {
|
|
1195 |
verify_null(symbol);
|
|
1196 |
compute_boolean_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
|
|
1197 |
il_default_variable_type = &search_expression_type_c::bool_type_name;
|
|
1198 |
return NULL;
|
|
1199 |
}
|
|
1200 |
|
|
1201 |
//SYM_REF0(NE_operator_c)
|
|
1202 |
void *visit_expression_type_c::visit(NE_operator_c *symbol) {
|
|
1203 |
verify_null(symbol);
|
|
1204 |
compute_boolean_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
|
|
1205 |
il_default_variable_type = &search_expression_type_c::bool_type_name;
|
|
1206 |
return NULL;
|
|
1207 |
}
|
|
1208 |
|
|
1209 |
// SYM_REF0(CAL_operator_c)
|
|
1210 |
void *visit_expression_type_c::visit(CAL_operator_c *symbol) {
|
|
1211 |
return NULL;
|
|
1212 |
}
|
|
1213 |
|
|
1214 |
// SYM_REF0(CALC_operator_c)
|
|
1215 |
void *visit_expression_type_c::visit(CALC_operator_c *symbol) {
|
|
1216 |
if(il_default_variable_type == NULL)
|
|
1217 |
STAGE3_ERROR(symbol, symbol, "CALC: il default variable should not be NULL.");
|
|
1218 |
if (!is_BOOL_type(il_default_variable_type))
|
|
1219 |
STAGE3_ERROR(symbol, symbol, "CALC operator requires il_default_variable to be of type BOOL.");
|
|
1220 |
return NULL;
|
|
1221 |
}
|
|
1222 |
|
|
1223 |
// SYM_REF0(CALCN_operator_c)
|
|
1224 |
void *visit_expression_type_c::visit(CALCN_operator_c *symbol) {
|
|
1225 |
if(il_default_variable_type == NULL)
|
|
1226 |
STAGE3_ERROR(symbol, symbol, "CALCN: il_default_variable should not be NULL.");
|
|
1227 |
if (!is_BOOL_type(il_default_variable_type))
|
|
1228 |
STAGE3_ERROR(symbol, symbol, "CALCN operator requires il_default_variable to be of type BOOL.");
|
|
1229 |
return NULL;
|
|
1230 |
}
|
|
1231 |
|
|
1232 |
// SYM_REF0(RET_operator_c)
|
|
1233 |
void *visit_expression_type_c::visit(RET_operator_c *symbol) {
|
|
1234 |
return NULL;
|
|
1235 |
}
|
|
1236 |
|
|
1237 |
// SYM_REF0(RETC_operator_c)
|
|
1238 |
void *visit_expression_type_c::visit(RETC_operator_c *symbol) {
|
|
1239 |
if(il_default_variable_type == NULL)
|
|
1240 |
STAGE3_ERROR(symbol, symbol, "RETC: il default variable should not be NULL.");
|
|
1241 |
if (!is_BOOL_type(il_default_variable_type))
|
|
1242 |
STAGE3_ERROR(symbol, symbol, "RETC operator requires il_default_variable to be of type BOOL.");
|
|
1243 |
return NULL;
|
|
1244 |
}
|
|
1245 |
|
|
1246 |
// SYM_REF0(RETCN_operator_c)
|
|
1247 |
void *visit_expression_type_c::visit(RETCN_operator_c *symbol) {
|
|
1248 |
if(il_default_variable_type == NULL)
|
|
1249 |
STAGE3_ERROR(symbol, symbol, "RETCN: il_default_variable should not be NULL.");
|
|
1250 |
if (!is_BOOL_type(il_default_variable_type))
|
|
1251 |
STAGE3_ERROR(symbol, symbol, "RETCN operator requires il_default_variable to be of type BOOL.");
|
|
1252 |
return NULL;
|
|
1253 |
}
|
|
1254 |
|
|
1255 |
// SYM_REF0(JMP_operator_c)
|
|
1256 |
void *visit_expression_type_c::visit(JMP_operator_c *symbol){
|
|
1257 |
return NULL;
|
|
1258 |
}
|
|
1259 |
|
|
1260 |
// SYM_REF0(JMPC_operator_c)
|
|
1261 |
void *visit_expression_type_c::visit(JMPC_operator_c *symbol) {
|
|
1262 |
if(il_default_variable_type == NULL)
|
|
1263 |
STAGE3_ERROR(symbol, symbol, "JMPC: il default variable should not be NULL.");
|
|
1264 |
if (!is_BOOL_type(il_default_variable_type))
|
|
1265 |
STAGE3_ERROR(symbol, symbol, "JMPC operator requires il_default_variable to be of type BOOL.");
|
|
1266 |
return NULL;
|
|
1267 |
}
|
|
1268 |
|
|
1269 |
// SYM_REF0(JMPCN_operator_c)
|
|
1270 |
void *visit_expression_type_c::visit(JMPCN_operator_c *symbol) {
|
|
1271 |
if(il_default_variable_type == NULL)
|
|
1272 |
STAGE3_ERROR(symbol, symbol, "JMPCN: il_default_variable should not be NULL.");
|
|
1273 |
if (!is_BOOL_type(il_default_variable_type))
|
|
1274 |
STAGE3_ERROR(symbol, symbol, "JMPCN operator requires il_default_variable to be of type BOOL.");
|
|
1275 |
return NULL;
|
|
1276 |
}
|
|
1277 |
|
|
1278 |
/* Symbol class handled together with function call checks */
|
|
1279 |
/* any_identifier ASSIGN */
|
|
1280 |
// SYM_REF1(il_assign_operator_c, variable_name)
|
|
1281 |
// void *visit_expression_type_c::visit(il_assign_operator_c *symbol, variable_name);
|
|
1282 |
|
|
1283 |
/* Symbol class handled together with function call checks */
|
|
1284 |
/*| [NOT] any_identifier SENDTO */
|
|
1285 |
// SYM_REF2(il_assign_out_operator_c, option, variable_name)
|
|
1286 |
// void *visit_expression_type_c::visit(il_assign_operator_c *symbol, option, variable_name);
|
|
1287 |
|
|
1288 |
|
|
1289 |
|
|
1290 |
|
|
1291 |
|
|
1292 |
/***************************************/
|
|
1293 |
/* B.3 - Language ST (Structured Text) */
|
|
1294 |
/***************************************/
|
|
1295 |
/***********************/
|
|
1296 |
/* B 3.1 - Expressions */
|
|
1297 |
/***********************/
|
|
1298 |
|
|
1299 |
void *visit_expression_type_c::visit(or_expression_c *symbol) {
|
|
1300 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1301 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
|
1302 |
return compute_boolean_expression(left_type, right_type, &visit_expression_type_c::is_ANY_BIT_type);
|
|
1303 |
}
|
|
1304 |
|
|
1305 |
|
|
1306 |
void *visit_expression_type_c::visit(xor_expression_c *symbol) {
|
|
1307 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1308 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
|
1309 |
return compute_boolean_expression(left_type, right_type, &visit_expression_type_c::is_ANY_BIT_type);
|
|
1310 |
}
|
|
1311 |
|
|
1312 |
|
|
1313 |
void *visit_expression_type_c::visit(and_expression_c *symbol) {
|
|
1314 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1315 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
|
1316 |
return compute_boolean_expression(left_type, right_type, &visit_expression_type_c::is_ANY_BIT_type);
|
|
1317 |
}
|
|
1318 |
|
|
1319 |
|
|
1320 |
void *visit_expression_type_c::visit(equ_expression_c *symbol) {
|
|
1321 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1322 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
|
1323 |
compute_boolean_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
|
|
1324 |
return &search_expression_type_c::bool_type_name;
|
|
1325 |
}
|
|
1326 |
|
|
1327 |
|
|
1328 |
void *visit_expression_type_c::visit(notequ_expression_c *symbol) {
|
|
1329 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1330 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
|
1331 |
compute_boolean_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
|
|
1332 |
return &search_expression_type_c::bool_type_name;
|
|
1333 |
}
|
|
1334 |
|
|
1335 |
|
|
1336 |
void *visit_expression_type_c::visit(lt_expression_c *symbol) {
|
|
1337 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1338 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
|
1339 |
compute_boolean_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
|
|
1340 |
return &search_expression_type_c::bool_type_name;
|
|
1341 |
}
|
|
1342 |
|
|
1343 |
|
|
1344 |
void *visit_expression_type_c::visit(gt_expression_c *symbol) {
|
|
1345 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1346 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
|
1347 |
compute_boolean_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
|
|
1348 |
return &search_expression_type_c::bool_type_name;
|
|
1349 |
}
|
|
1350 |
|
|
1351 |
|
|
1352 |
void *visit_expression_type_c::visit(le_expression_c *symbol) {
|
|
1353 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1354 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
|
1355 |
compute_boolean_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
|
|
1356 |
return &search_expression_type_c::bool_type_name;
|
|
1357 |
}
|
|
1358 |
|
|
1359 |
|
|
1360 |
void *visit_expression_type_c::visit(ge_expression_c *symbol) {
|
|
1361 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1362 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
|
1363 |
compute_boolean_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_type);
|
|
1364 |
return &search_expression_type_c::bool_type_name;
|
|
1365 |
}
|
|
1366 |
|
|
1367 |
|
|
1368 |
void *visit_expression_type_c::visit(add_expression_c *symbol) {
|
|
1369 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1370 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
|
1371 |
if (typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&time_type_name;}
|
|
1372 |
if (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&tod_type_name;}
|
|
1373 |
if (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&dt_type_name;}
|
|
1374 |
return compute_numeric_expression(left_type, right_type, &visit_expression_type_c::is_ANY_MAGNITUDE_type);
|
|
1375 |
}
|
|
1376 |
|
|
1377 |
|
|
1378 |
void *visit_expression_type_c::visit(sub_expression_c *symbol) {
|
|
1379 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1380 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
|
1381 |
if (typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&time_type_name;}
|
|
1382 |
if (typeid(*left_type) == typeid(date_type_name_c) && typeid(*right_type) == typeid(date_type_name_c)) {return (void *)&time_type_name;}
|
|
1383 |
if (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&tod_type_name;}
|
|
1384 |
if (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(tod_type_name_c)) {return (void *)&time_type_name;}
|
|
1385 |
if (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&dt_type_name;}
|
|
1386 |
if (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(dt_type_name_c)) {return (void *)&time_type_name;}
|
|
1387 |
return compute_numeric_expression(left_type, right_type, &visit_expression_type_c::is_ANY_MAGNITUDE_type);
|
|
1388 |
}
|
|
1389 |
|
|
1390 |
|
|
1391 |
void *visit_expression_type_c::visit(mul_expression_c *symbol) {
|
|
1392 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1393 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
|
1394 |
if (typeid(*left_type) == typeid(time_type_name_c) && is_ANY_NUM_type(right_type)) {return (void *)&time_type_name;}
|
|
1395 |
return compute_numeric_expression(left_type, right_type, &visit_expression_type_c::is_ANY_NUM_type);
|
|
1396 |
}
|
|
1397 |
|
|
1398 |
|
|
1399 |
void *visit_expression_type_c::visit(div_expression_c *symbol) {
|
|
1400 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1401 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
|
1402 |
if (typeid(*left_type) == typeid(time_type_name_c) && is_ANY_NUM_type(right_type)){return (void *)&time_type_name;}
|
|
1403 |
return compute_numeric_expression(left_type, right_type, &visit_expression_type_c::is_ANY_NUM_type);
|
|
1404 |
}
|
|
1405 |
|
|
1406 |
|
|
1407 |
void *visit_expression_type_c::visit(mod_expression_c *symbol) {
|
|
1408 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1409 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
|
1410 |
return compute_numeric_expression(left_type, right_type, &visit_expression_type_c::is_ANY_INT_type);
|
|
1411 |
}
|
|
1412 |
|
|
1413 |
|
|
1414 |
void *visit_expression_type_c::visit(power_expression_c *symbol) {
|
|
1415 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1416 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
|
1417 |
if (!is_ANY_REAL_type(left_type))
|
|
1418 |
STAGE3_ERROR(symbol->l_exp, symbol->l_exp, "first operand of ** operator has invalid data type, should be of type ANY_REAL.");
|
|
1419 |
if (!is_ANY_NUM_type(right_type))
|
|
1420 |
STAGE3_ERROR(symbol->r_exp, symbol->r_exp, "second operand of ** operator has invalid data type, should be of type ANY_NUM.");
|
|
1421 |
|
|
1422 |
return (void *)left_type;
|
|
1423 |
}
|
|
1424 |
|
|
1425 |
|
|
1426 |
void *visit_expression_type_c::visit(neg_expression_c *symbol) {
|
|
1427 |
symbol_c *exp_type = base_type((symbol_c *)symbol->exp->accept(*this));
|
|
1428 |
if (!is_ANY_MAGNITUDE_type(exp_type))
|
|
1429 |
STAGE3_ERROR(symbol, symbol, "operand of negate expression '-' has invalid data type, should be of type ANY_MAGNITUDE.");
|
|
1430 |
|
|
1431 |
return exp_type;
|
|
1432 |
}
|
|
1433 |
|
|
1434 |
|
|
1435 |
void *visit_expression_type_c::visit(not_expression_c *symbol) {
|
|
1436 |
symbol_c *type = base_type((symbol_c *)symbol->exp->accept(*this));
|
|
1437 |
return compute_boolean_expression(type, type, &visit_expression_type_c::is_ANY_BIT_type);
|
|
1438 |
}
|
|
1439 |
|
|
1440 |
|
|
1441 |
void *visit_expression_type_c::visit(function_invocation_c *symbol) {
|
|
1442 |
function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name);
|
|
1443 |
if (f_decl == function_symtable.end_value()) {
|
|
1444 |
/* TODO: the following code is for standard library functions. We do not yet support this... */
|
|
1445 |
void *res = compute_standard_function_default(symbol);
|
|
1446 |
if (res != NULL) return res;
|
|
1447 |
ERROR;
|
|
1448 |
}
|
|
1449 |
|
|
1450 |
/* now check the semantics of the function call... */
|
|
1451 |
/* If the syntax parser is working correctly, exactly one of the
|
|
1452 |
* following two symbols will be NULL, while the other is != NULL.
|
|
1453 |
*/
|
|
1454 |
if (symbol-> formal_param_list != NULL) check_formal_call (symbol, f_decl);
|
|
1455 |
if (symbol->nonformal_param_list != NULL) check_nonformal_call(symbol, f_decl);
|
|
1456 |
|
|
1457 |
return base_type(f_decl->type_name);
|
|
1458 |
}
|
|
1459 |
|
|
1460 |
/********************/
|
|
1461 |
/* B 3.2 Statements */
|
|
1462 |
/********************/
|
|
1463 |
// SYM_LIST(statement_list_c)
|
|
1464 |
/* The visitor of the base class search_visitor_c will handle calling each instruction in the list.
|
|
1465 |
* We do not need to do anything here...
|
|
1466 |
*/
|
|
1467 |
// void *visit_expression_type_c::visit(statement_list_c *symbol)
|
|
1468 |
|
|
1469 |
|
|
1470 |
/*********************************/
|
|
1471 |
/* B 3.2.1 Assignment Statements */
|
|
1472 |
/*********************************/
|
|
1473 |
|
|
1474 |
void *visit_expression_type_c::visit(assignment_statement_c *symbol) {
|
|
1475 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1476 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
|
1477 |
|
|
1478 |
if (!is_compatible_type(left_type, right_type)) {
|
|
1479 |
STAGE3_ERROR(symbol, symbol, "data type mismatch in assignment statement!\n");
|
|
1480 |
}
|
|
1481 |
return NULL;
|
|
1482 |
}
|
|
1483 |
|
|
1484 |
|
|
1485 |
|
|
1486 |
/*****************************************/
|
|
1487 |
/* B 3.2.2 Subprogram Control Statements */
|
|
1488 |
/*****************************************/
|
|
1489 |
|
|
1490 |
/* RETURN */
|
|
1491 |
// SYM_REF0(return_statement_c)
|
|
1492 |
|
|
1493 |
|
|
1494 |
/* fb_name '(' [param_assignment_list] ')' */
|
|
1495 |
/* param_assignment_list -> may be NULL ! */
|
|
1496 |
// SYM_REF3(fb_invocation_c, fb_name, formal_param_list, nonformal_param_list)
|
|
1497 |
void *visit_expression_type_c::visit(fb_invocation_c *symbol) {
|
|
1498 |
symbol_c *fb_decl = search_varfb_instance_type->get_type(symbol->fb_name);
|
|
1499 |
/* The following should never occur. The function block must be defined,
|
|
1500 |
* and the FB type being called MUST be in the symtable...
|
|
1501 |
* This was all already checked at stage 2!
|
|
1502 |
*/
|
|
1503 |
if (NULL == fb_decl) ERROR;
|
|
1504 |
|
|
1505 |
/* now check the semantics of the fb call... */
|
|
1506 |
/* If the syntax parser is working correctly, exactly one of the
|
|
1507 |
* following two symbols will be NULL, while the other is != NULL.
|
|
1508 |
*/
|
|
1509 |
if (symbol-> formal_param_list != NULL) check_formal_call (symbol, fb_decl);
|
|
1510 |
if (symbol->nonformal_param_list != NULL) check_nonformal_call(symbol, fb_decl);
|
|
1511 |
|
|
1512 |
return NULL;
|
|
1513 |
}
|
|
1514 |
|
|
1515 |
|
|
1516 |
#if 0
|
|
1517 |
/* helper symbol for fb_invocation */
|
|
1518 |
/* param_assignment_list ',' param_assignment */
|
|
1519 |
SYM_LIST(param_assignment_list_c)
|
|
1520 |
|
|
1521 |
/* variable_name ASSIGN expression */
|
|
1522 |
SYM_REF2(input_variable_param_assignment_c, variable_name, expression)
|
|
1523 |
|
|
1524 |
/* [NOT] variable_name '=>' variable */
|
|
1525 |
SYM_REF3(output_variable_param_assignment_c, not_param, variable_name, variable)
|
|
1526 |
|
|
1527 |
/* helper CLASS for output_variable_param_assignment */
|
|
1528 |
SYM_REF0(not_paramassign_c)
|
|
1529 |
#endif
|
|
1530 |
|
|
1531 |
/********************************/
|
|
1532 |
/* B 3.2.3 Selection Statements */
|
|
1533 |
/********************************/
|
|
1534 |
|
|
1535 |
/* IF expression THEN statement_list elseif_statement_list ELSE statement_list END_IF */
|
|
1536 |
// SYM_REF4(if_statement_c, expression, statement_list, elseif_statement_list, else_statement_list)
|
|
1537 |
void *visit_expression_type_c::visit(if_statement_c *symbol) {
|
|
1538 |
symbol_c *expr_type = base_type((symbol_c*)symbol->expression->accept(*this));
|
|
1539 |
if (!is_BOOL_type(expr_type)) STAGE3_ERROR(symbol,symbol,"IF conditional expression is not of boolean type.");
|
|
1540 |
if (NULL != symbol->statement_list)
|
|
1541 |
symbol->statement_list->accept(*this);
|
|
1542 |
if (NULL != symbol->elseif_statement_list)
|
|
1543 |
symbol->elseif_statement_list->accept(*this);
|
|
1544 |
if (NULL != symbol->else_statement_list)
|
|
1545 |
symbol->else_statement_list->accept(*this);
|
|
1546 |
return NULL;
|
|
1547 |
}
|
|
1548 |
|
|
1549 |
/* helper symbol for if_statement */
|
|
1550 |
// SYM_LIST(elseif_statement_list_c)
|
|
1551 |
// void *visit_expression_type_c::visit(elseif_statement_list_c *symbol) { }
|
|
1552 |
|
|
1553 |
/* helper symbol for elseif_statement_list */
|
|
1554 |
/* ELSIF expression THEN statement_list */
|
|
1555 |
// SYM_REF2(elseif_statement_c, expression, statement_list)
|
|
1556 |
void *visit_expression_type_c::visit(elseif_statement_c *symbol) {
|
|
1557 |
symbol_c *elseif_expr_type = base_type((symbol_c*)symbol->expression->accept(*this));
|
|
1558 |
if(!is_BOOL_type(elseif_expr_type)) STAGE3_ERROR(symbol,symbol,"ELSIF conditional expression is not of boolean type.");
|
|
1559 |
if (NULL != symbol->statement_list)
|
|
1560 |
symbol->statement_list->accept(*this);
|
|
1561 |
return NULL;
|
|
1562 |
}
|
|
1563 |
|
|
1564 |
|
|
1565 |
/* CASE expression OF case_element_list ELSE statement_list END_CASE */
|
|
1566 |
// SYM_REF3(case_statement_c, expression, case_element_list, statement_list)
|
|
1567 |
void *visit_expression_type_c::visit(case_statement_c *symbol) {
|
|
1568 |
case_expression_type = base_type((symbol_c*)symbol->expression->accept(*this));
|
|
1569 |
if (NULL != case_expression_type) {
|
|
1570 |
if (NULL != symbol->case_element_list)
|
|
1571 |
symbol->case_element_list->accept(*this);
|
|
1572 |
}
|
|
1573 |
if (NULL != symbol->statement_list)
|
|
1574 |
symbol->statement_list->accept(*this);
|
|
1575 |
return NULL;
|
|
1576 |
}
|
|
1577 |
|
|
1578 |
#if 0
|
|
1579 |
/* helper symbol for case_statement */
|
|
1580 |
// SYM_LIST(case_element_list_c)
|
|
1581 |
// void *visit_expression_type_c::visit(case_element_list_c *symbol);
|
|
1582 |
|
|
1583 |
/* case_list ':' statement_list */
|
|
1584 |
// SYM_REF2(case_element_c, case_list, statement_list)
|
|
1585 |
void *visit_expression_type_c::visit(case_element_c *symbol);
|
|
1586 |
#endif
|
|
1587 |
|
|
1588 |
// SYM_LIST(case_list_c)
|
|
1589 |
void *visit_expression_type_c::visit(case_list_c *symbol) {
|
|
1590 |
symbol_c *element_type;
|
|
1591 |
for(int i = 0; i < symbol->n; i++) {
|
|
1592 |
element_type = (symbol_c *)symbol->elements[i]->accept(*this);
|
|
1593 |
if (NULL == element_type) {
|
|
1594 |
STAGE3_ERROR(symbol->elements[i], symbol->elements[i], "Case list element has undefined data type.");
|
|
1595 |
} else {
|
|
1596 |
element_type = base_type(element_type);
|
|
1597 |
if (NULL != element_type){
|
|
1598 |
if (!is_compatible_type(case_expression_type, element_type))
|
|
1599 |
STAGE3_ERROR(symbol->elements[i], symbol->elements[i], "Invalid data type of case list element.");
|
|
1600 |
}
|
|
1601 |
}
|
|
1602 |
}
|
|
1603 |
return NULL;
|
|
1604 |
}
|
|
1605 |
|
|
1606 |
/********************************/
|
|
1607 |
/* B 3.2.4 Iteration Statements */
|
|
1608 |
/********************************/
|
|
1609 |
|
|
1610 |
/* FOR control_variable ASSIGN expression TO expression [BY expression] DO statement_list END_FOR */
|
|
1611 |
// SYM_REF5(for_statement_c, control_variable, beg_expression, end_expression, by_expression, statement_list)
|
|
1612 |
void *visit_expression_type_c::visit(for_statement_c *symbol) {
|
|
1613 |
symbol_c *var_type = (symbol_c*)symbol->control_variable->accept(*this);
|
|
1614 |
if (NULL == var_type) ERROR;
|
|
1615 |
var_type = base_type(var_type);
|
|
1616 |
if (NULL == var_type) ERROR;
|
|
1617 |
// ASSIGN
|
|
1618 |
symbol_c *beg_expr_type = base_type((symbol_c*)symbol->beg_expression->accept(*this));
|
|
1619 |
if (NULL != beg_expr_type) {
|
|
1620 |
if(!is_compatible_type(var_type,beg_expr_type))
|
|
1621 |
STAGE3_ERROR(symbol, symbol, "Data type mismatch between control variable and initial value.");
|
|
1622 |
}
|
|
1623 |
// TO
|
|
1624 |
symbol_c *end_expr_type = base_type((symbol_c*)symbol->end_expression->accept(*this));
|
|
1625 |
if (NULL != end_expr_type) {
|
|
1626 |
if(!is_compatible_type(var_type,end_expr_type))
|
|
1627 |
STAGE3_ERROR(symbol, symbol, "Data type mismatch between control variable and final value.");
|
|
1628 |
}
|
|
1629 |
// BY
|
|
1630 |
if(symbol->by_expression != NULL) {
|
|
1631 |
symbol_c *by_expr_type = base_type((symbol_c*)symbol->by_expression->accept(*this));
|
|
1632 |
if (NULL != end_expr_type) {
|
|
1633 |
if(!is_compatible_type(var_type,by_expr_type))
|
|
1634 |
STAGE3_ERROR(symbol, symbol, "Data type mismatch between control variable and BY value.");
|
|
1635 |
}
|
|
1636 |
}
|
|
1637 |
// DO
|
|
1638 |
if (NULL != symbol->statement_list)
|
|
1639 |
symbol->statement_list->accept(*this);
|
|
1640 |
return NULL;
|
|
1641 |
}
|
|
1642 |
|
|
1643 |
|
|
1644 |
/* WHILE expression DO statement_list END_WHILE */
|
|
1645 |
// SYM_REF2(while_statement_c, expression, statement_list)
|
|
1646 |
void *visit_expression_type_c::visit(while_statement_c *symbol) {
|
|
1647 |
symbol_c *expr_type = base_type((symbol_c*)symbol->expression->accept(*this));
|
|
1648 |
if (NULL != expr_type) {
|
|
1649 |
if(!is_BOOL_type(expr_type))
|
|
1650 |
STAGE3_ERROR(symbol,symbol,"WHILE conditional expression is not of boolean type.");
|
|
1651 |
}
|
|
1652 |
|
|
1653 |
if (NULL != symbol->statement_list)
|
|
1654 |
symbol->statement_list->accept(*this);
|
|
1655 |
return NULL;
|
|
1656 |
}
|
|
1657 |
|
|
1658 |
/* REPEAT statement_list UNTIL expression END_REPEAT */
|
|
1659 |
// SYM_REF2(repeat_statement_c, statement_list, expression)
|
|
1660 |
void *visit_expression_type_c::visit(repeat_statement_c *symbol) {
|
|
1661 |
if (NULL != symbol->statement_list)
|
|
1662 |
symbol->statement_list->accept(*this);
|
|
1663 |
|
|
1664 |
symbol_c *expr_type = base_type((symbol_c*)symbol->expression->accept(*this));
|
|
1665 |
if (NULL != expr_type) {
|
|
1666 |
if(!is_BOOL_type(expr_type))
|
|
1667 |
STAGE3_ERROR(symbol,symbol,"REPEAT conditional expression is not of boolean type.");
|
|
1668 |
}
|
|
1669 |
return NULL;
|
|
1670 |
}
|
|
1671 |
|
|
1672 |
/* EXIT */
|
|
1673 |
// SYM_REF0(exit_statement_c)
|
|
1674 |
|
|
1675 |
|
|
1676 |
|