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;
|
257
|
74 |
search_varfb_instance_type = NULL;
|
204
|
75 |
return NULL;
|
|
76 |
}
|
|
77 |
|
|
78 |
void *visit_expression_type_c::visit(function_declaration_c *symbol) {
|
|
79 |
search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
|
|
80 |
symbol->var_declarations_list->accept(*this);
|
|
81 |
printf("checking semantics in body of function %s\n", ((token_c *)(symbol->derived_function_name))->value);
|
|
82 |
il_parenthesis_level = 0;
|
|
83 |
il_error = false;
|
|
84 |
il_default_variable_type = NULL;
|
|
85 |
symbol->function_body->accept(*this);
|
|
86 |
il_default_variable_type = NULL;
|
|
87 |
delete search_varfb_instance_type;
|
257
|
88 |
search_varfb_instance_type = NULL;
|
204
|
89 |
return NULL;
|
|
90 |
}
|
|
91 |
|
|
92 |
void *visit_expression_type_c::visit(function_block_declaration_c *symbol) {
|
|
93 |
search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
|
|
94 |
symbol->var_declarations->accept(*this);
|
|
95 |
printf("checking semantics in body of FB %s\n", ((token_c *)(symbol->fblock_name))->value);
|
|
96 |
il_parenthesis_level = 0;
|
|
97 |
il_error = false;
|
|
98 |
il_default_variable_type = NULL;
|
|
99 |
symbol->fblock_body->accept(*this);
|
|
100 |
il_default_variable_type = NULL;
|
|
101 |
delete search_varfb_instance_type;
|
257
|
102 |
search_varfb_instance_type = NULL;
|
204
|
103 |
return NULL;
|
|
104 |
}
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
visit_expression_type_c::visit_expression_type_c(symbol_c *search_scope) {
|
|
115 |
}
|
|
116 |
|
|
117 |
visit_expression_type_c::~visit_expression_type_c(void) {
|
|
118 |
}
|
|
119 |
|
|
120 |
|
257
|
121 |
|
|
122 |
|
|
123 |
/* NOTE on data type handling and literals...
|
|
124 |
* ==========================================
|
|
125 |
*
|
|
126 |
* Literals that are explicitly type cast
|
|
127 |
* e.g.: BYTE#42
|
|
128 |
* INT#65
|
|
129 |
* TIME#45h23m
|
|
130 |
* etc...
|
|
131 |
* are NOT considered literals in the following code.
|
|
132 |
* Since they are type cast, and their data type is fixed and well known,
|
|
133 |
* they are treated as a variable of that data type (except when determining lvalues)
|
|
134 |
* In other words, when calling search_constant_type_c on these constants, it returns
|
|
135 |
* a xxxxx_type_name_c, and not one of the xxxx_literal_c !
|
|
136 |
*
|
|
137 |
* When the following code handles a literal, it is really a literal of unknown data type.
|
|
138 |
* e.g. 42, may be considered an int, a byte, a word, etc...
|
|
139 |
*/
|
|
140 |
|
204
|
141 |
/* A helper function... */
|
|
142 |
bool visit_expression_type_c::is_ANY_ELEMENTARY_type(symbol_c *type_symbol) {
|
|
143 |
if (type_symbol == NULL) {ERROR;}
|
|
144 |
return is_ANY_MAGNITUDE_type(type_symbol)
|
257
|
145 |
|| is_ANY_BIT_type (type_symbol)
|
|
146 |
|| is_ANY_STRING_type (type_symbol)
|
|
147 |
|| is_ANY_DATE_type (type_symbol);
|
|
148 |
}
|
|
149 |
|
|
150 |
/* A helper function... */
|
|
151 |
bool visit_expression_type_c::is_ANY_SAFEELEMENTARY_type(symbol_c *type_symbol) {
|
|
152 |
if (type_symbol == NULL) {ERROR;}
|
|
153 |
return is_ANY_SAFEMAGNITUDE_type(type_symbol)
|
|
154 |
|| is_ANY_SAFEBIT_type (type_symbol)
|
|
155 |
|| is_ANY_SAFESTRING_type (type_symbol)
|
|
156 |
|| is_ANY_SAFEDATE_type (type_symbol);
|
|
157 |
}
|
|
158 |
|
|
159 |
/* A helper function... */
|
|
160 |
bool visit_expression_type_c::is_ANY_ELEMENTARY_compatible(symbol_c *type_symbol) {
|
|
161 |
if (type_symbol == NULL) {ERROR;}
|
|
162 |
/* NOTE: doing
|
|
163 |
* return is_ANY_SAFEELEMENTARY_type() || is_ANY_ELEMENTARY_type()
|
|
164 |
* is incorrect, as the literals would never be considered compatible...
|
|
165 |
*/
|
|
166 |
return is_ANY_MAGNITUDE_compatible(type_symbol)
|
|
167 |
|| is_ANY_BIT_compatible (type_symbol)
|
|
168 |
|| is_ANY_STRING_compatible (type_symbol)
|
|
169 |
|| is_ANY_DATE_compatible (type_symbol);
|
204
|
170 |
}
|
|
171 |
|
|
172 |
|
|
173 |
/* A helper function... */
|
|
174 |
bool visit_expression_type_c::is_ANY_MAGNITUDE_type(symbol_c *type_symbol) {
|
|
175 |
if (type_symbol == NULL) {ERROR;}
|
|
176 |
if (typeid(*type_symbol) == typeid(time_type_name_c)) {return true;}
|
|
177 |
return is_ANY_NUM_type(type_symbol);
|
|
178 |
}
|
|
179 |
|
257
|
180 |
/* A helper function... */
|
|
181 |
bool visit_expression_type_c::is_ANY_SAFEMAGNITUDE_type(symbol_c *type_symbol) {
|
|
182 |
if (type_symbol == NULL) {ERROR;}
|
|
183 |
if (typeid(*type_symbol) == typeid(safetime_type_name_c)) {return true;}
|
|
184 |
return is_ANY_SAFENUM_type(type_symbol);
|
|
185 |
}
|
|
186 |
|
|
187 |
/* A helper function... */
|
|
188 |
bool visit_expression_type_c::is_ANY_MAGNITUDE_compatible(symbol_c *type_symbol) {
|
|
189 |
if (type_symbol == NULL) {ERROR;}
|
|
190 |
if (is_ANY_MAGNITUDE_type (type_symbol)) {return true;}
|
|
191 |
if (is_ANY_SAFEMAGNITUDE_type(type_symbol)) {return true;}
|
|
192 |
|
|
193 |
return is_ANY_NUM_compatible(type_symbol);
|
|
194 |
}
|
204
|
195 |
|
|
196 |
/* A helper function... */
|
|
197 |
bool visit_expression_type_c::is_ANY_NUM_type(symbol_c *type_symbol) {
|
|
198 |
if (type_symbol == NULL) {ERROR;}
|
257
|
199 |
if (is_ANY_REAL_type(type_symbol)) {return true;}
|
|
200 |
if (is_ANY_INT_type(type_symbol)) {return true;}
|
|
201 |
return false;
|
|
202 |
}
|
|
203 |
|
|
204 |
/* A helper function... */
|
|
205 |
bool visit_expression_type_c::is_ANY_SAFENUM_type(symbol_c *type_symbol) {
|
|
206 |
if (type_symbol == NULL) {ERROR;}
|
|
207 |
return is_ANY_SAFEREAL_type(type_symbol)
|
|
208 |
|| is_ANY_SAFEINT_type (type_symbol);
|
|
209 |
}
|
|
210 |
|
|
211 |
/* A helper function... */
|
|
212 |
bool visit_expression_type_c::is_ANY_NUM_compatible(symbol_c *type_symbol) {
|
|
213 |
if (type_symbol == NULL) {ERROR;}
|
|
214 |
if (is_ANY_REAL_compatible(type_symbol)) {return true;}
|
|
215 |
if (is_ANY_INT_compatible(type_symbol)) {return true;}
|
|
216 |
return false;
|
|
217 |
}
|
204
|
218 |
|
|
219 |
/* A helper function... */
|
|
220 |
bool visit_expression_type_c::is_ANY_DATE_type(symbol_c *type_symbol) {
|
|
221 |
if (type_symbol == NULL) {ERROR;}
|
|
222 |
if (typeid(*type_symbol) == typeid(date_type_name_c)) {return true;}
|
257
|
223 |
if (typeid(*type_symbol) == typeid(tod_type_name_c)) {return true;}
|
|
224 |
if (typeid(*type_symbol) == typeid(dt_type_name_c)) {return true;}
|
204
|
225 |
return false;
|
|
226 |
}
|
|
227 |
|
257
|
228 |
/* A helper function... */
|
|
229 |
bool visit_expression_type_c::is_ANY_SAFEDATE_type(symbol_c *type_symbol) {
|
|
230 |
if (type_symbol == NULL) {ERROR;}
|
|
231 |
if (typeid(*type_symbol) == typeid(safedate_type_name_c)) {return true;}
|
|
232 |
if (typeid(*type_symbol) == typeid(safetod_type_name_c)) {return true;}
|
|
233 |
if (typeid(*type_symbol) == typeid(safedt_type_name_c)) {return true;}
|
|
234 |
return false;
|
|
235 |
}
|
|
236 |
|
|
237 |
/* A helper function... */
|
|
238 |
bool visit_expression_type_c::is_ANY_DATE_compatible(symbol_c *type_symbol) {
|
|
239 |
if (type_symbol == NULL) {ERROR;}
|
|
240 |
if (is_ANY_DATE_type (type_symbol)) {return true;}
|
|
241 |
if (is_ANY_SAFEDATE_type(type_symbol)) {return true;}
|
|
242 |
return false;
|
|
243 |
}
|
204
|
244 |
|
|
245 |
/* A helper function... */
|
|
246 |
bool visit_expression_type_c::is_ANY_STRING_type(symbol_c *type_symbol) {
|
|
247 |
if (type_symbol == NULL) {ERROR;}
|
|
248 |
if (typeid(*type_symbol) == typeid(string_type_name_c)) {return true;}
|
|
249 |
if (typeid(*type_symbol) == typeid(wstring_type_name_c)) {return true;}
|
257
|
250 |
// TODO literal_string ???
|
204
|
251 |
return false;
|
|
252 |
}
|
|
253 |
|
257
|
254 |
/* A helper function... */
|
|
255 |
bool visit_expression_type_c::is_ANY_SAFESTRING_type(symbol_c *type_symbol) {
|
|
256 |
if (type_symbol == NULL) {ERROR;}
|
|
257 |
if (typeid(*type_symbol) == typeid(safestring_type_name_c)) {return true;}
|
|
258 |
if (typeid(*type_symbol) == typeid(safewstring_type_name_c)) {return true;}
|
|
259 |
return false;
|
|
260 |
}
|
|
261 |
|
|
262 |
/* A helper function... */
|
|
263 |
bool visit_expression_type_c::is_ANY_STRING_compatible(symbol_c *type_symbol) {
|
|
264 |
if (type_symbol == NULL) {ERROR;}
|
|
265 |
if (is_ANY_STRING_type (type_symbol)) {return true;}
|
|
266 |
if (is_ANY_SAFESTRING_type(type_symbol)) {return true;}
|
|
267 |
return false;
|
|
268 |
}
|
204
|
269 |
|
|
270 |
/* A helper function... */
|
|
271 |
bool visit_expression_type_c::is_ANY_INT_type(symbol_c *type_symbol) {
|
|
272 |
if (type_symbol == NULL) {ERROR;}
|
|
273 |
if (typeid(*type_symbol) == typeid(sint_type_name_c)) {return true;}
|
|
274 |
if (typeid(*type_symbol) == typeid(int_type_name_c)) {return true;}
|
|
275 |
if (typeid(*type_symbol) == typeid(dint_type_name_c)) {return true;}
|
|
276 |
if (typeid(*type_symbol) == typeid(lint_type_name_c)) {return true;}
|
|
277 |
if (typeid(*type_symbol) == typeid(usint_type_name_c)) {return true;}
|
|
278 |
if (typeid(*type_symbol) == typeid(uint_type_name_c)) {return true;}
|
|
279 |
if (typeid(*type_symbol) == typeid(udint_type_name_c)) {return true;}
|
|
280 |
if (typeid(*type_symbol) == typeid(ulint_type_name_c)) {return true;}
|
|
281 |
return false;
|
|
282 |
}
|
|
283 |
|
257
|
284 |
/* A helper function... */
|
|
285 |
bool visit_expression_type_c::is_ANY_SAFEINT_type(symbol_c *type_symbol) {
|
|
286 |
if (type_symbol == NULL) {ERROR;}
|
|
287 |
if (typeid(*type_symbol) == typeid(safesint_type_name_c)) {return true;}
|
|
288 |
if (typeid(*type_symbol) == typeid(safeint_type_name_c)) {return true;}
|
|
289 |
if (typeid(*type_symbol) == typeid(safedint_type_name_c)) {return true;}
|
|
290 |
if (typeid(*type_symbol) == typeid(safelint_type_name_c)) {return true;}
|
|
291 |
if (typeid(*type_symbol) == typeid(safeusint_type_name_c)) {return true;}
|
|
292 |
if (typeid(*type_symbol) == typeid(safeuint_type_name_c)) {return true;}
|
|
293 |
if (typeid(*type_symbol) == typeid(safeudint_type_name_c)) {return true;}
|
|
294 |
if (typeid(*type_symbol) == typeid(safeulint_type_name_c)) {return true;}
|
|
295 |
return false;
|
|
296 |
}
|
|
297 |
|
|
298 |
/* A helper function... */
|
|
299 |
bool visit_expression_type_c::is_ANY_INT_compatible(symbol_c *type_symbol) {
|
|
300 |
if (type_symbol == NULL) {ERROR;}
|
|
301 |
if (is_ANY_INT_type (type_symbol)) {return true;}
|
|
302 |
if (is_ANY_SAFEINT_type(type_symbol)) {return true;}
|
|
303 |
if (is_literal_integer_type(type_symbol)) {return true;}
|
|
304 |
return false;
|
|
305 |
}
|
204
|
306 |
|
|
307 |
/* A helper function... */
|
|
308 |
bool visit_expression_type_c::is_ANY_REAL_type(symbol_c *type_symbol) {
|
|
309 |
if (type_symbol == NULL) {ERROR;}
|
|
310 |
if (typeid(*type_symbol) == typeid(real_type_name_c)) {return true;}
|
|
311 |
if (typeid(*type_symbol) == typeid(lreal_type_name_c)) {return true;}
|
|
312 |
return false;
|
|
313 |
}
|
|
314 |
|
257
|
315 |
/* A helper function... */
|
|
316 |
bool visit_expression_type_c::is_ANY_SAFEREAL_type(symbol_c *type_symbol) {
|
|
317 |
if (type_symbol == NULL) {ERROR;}
|
|
318 |
if (typeid(*type_symbol) == typeid(safereal_type_name_c)) {return true;}
|
|
319 |
if (typeid(*type_symbol) == typeid(safelreal_type_name_c)) {return true;}
|
|
320 |
return false;
|
|
321 |
}
|
|
322 |
|
|
323 |
/* A helper function... */
|
|
324 |
bool visit_expression_type_c::is_ANY_REAL_compatible(symbol_c *type_symbol) {
|
|
325 |
if (type_symbol == NULL) {ERROR;}
|
|
326 |
if (is_ANY_REAL_type (type_symbol)) {return true;}
|
|
327 |
if (is_ANY_SAFEREAL_type(type_symbol)) {return true;}
|
|
328 |
if (is_literal_real_type(type_symbol)) {return true;}
|
|
329 |
return false;
|
|
330 |
}
|
204
|
331 |
|
|
332 |
/* A helper function... */
|
|
333 |
bool visit_expression_type_c::is_ANY_BIT_type(symbol_c *type_symbol) {
|
|
334 |
if (type_symbol == NULL) {ERROR;}
|
257
|
335 |
if (typeid(*type_symbol) == typeid(bool_type_name_c)) {return true;}
|
|
336 |
if (typeid(*type_symbol) == typeid(byte_type_name_c)) {return true;}
|
|
337 |
if (typeid(*type_symbol) == typeid(word_type_name_c)) {return true;}
|
|
338 |
if (typeid(*type_symbol) == typeid(dword_type_name_c)) {return true;}
|
|
339 |
if (typeid(*type_symbol) == typeid(lword_type_name_c)) {return true;}
|
204
|
340 |
return false;
|
|
341 |
}
|
|
342 |
|
257
|
343 |
/* A helper function... */
|
|
344 |
bool visit_expression_type_c::is_ANY_SAFEBIT_type(symbol_c *type_symbol) {
|
|
345 |
if (type_symbol == NULL) {ERROR;}
|
|
346 |
if (typeid(*type_symbol) == typeid(safebool_type_name_c)) {return true;}
|
|
347 |
if (typeid(*type_symbol) == typeid(safebyte_type_name_c)) {return true;}
|
|
348 |
if (typeid(*type_symbol) == typeid(safeword_type_name_c)) {return true;}
|
|
349 |
if (typeid(*type_symbol) == typeid(safedword_type_name_c)) {return true;}
|
|
350 |
if (typeid(*type_symbol) == typeid(safelword_type_name_c)) {return true;}
|
|
351 |
return false;
|
|
352 |
}
|
|
353 |
|
|
354 |
/* A helper function... */
|
|
355 |
bool visit_expression_type_c::is_ANY_BIT_compatible(symbol_c *type_symbol) {
|
|
356 |
if (type_symbol == NULL) {ERROR;}
|
|
357 |
if (is_ANY_BIT_type (type_symbol)) {return true;}
|
|
358 |
if (is_ANY_SAFEBIT_type(type_symbol)) {return true;}
|
|
359 |
if (is_nonneg_literal_integer_type(type_symbol)) {return true;}
|
|
360 |
if (is_literal_bool_type(type_symbol)) {return true;}
|
|
361 |
return false;
|
|
362 |
}
|
204
|
363 |
|
|
364 |
/* A helper function... */
|
|
365 |
bool visit_expression_type_c::is_BOOL_type(symbol_c *type_symbol) {
|
|
366 |
if (type_symbol == NULL) {ERROR;}
|
257
|
367 |
if (typeid(*type_symbol) == typeid(bool_type_name_c)) {return true;}
|
204
|
368 |
return false;
|
|
369 |
}
|
|
370 |
|
257
|
371 |
/* A helper function... */
|
|
372 |
bool visit_expression_type_c::is_SAFEBOOL_type(symbol_c *type_symbol){
|
|
373 |
if (type_symbol == NULL) {ERROR;}
|
|
374 |
if (typeid(*type_symbol) == typeid(safebool_type_name_c)) {return true;}
|
|
375 |
return false;
|
|
376 |
}
|
|
377 |
|
|
378 |
/* A helper function... */
|
|
379 |
bool visit_expression_type_c::is_ANY_BOOL_compatible(symbol_c *type_symbol) {
|
|
380 |
if (type_symbol == NULL) {ERROR;}
|
|
381 |
if (is_BOOL_type (type_symbol)) {return true;}
|
|
382 |
if (is_SAFEBOOL_type(type_symbol)) {return true;}
|
|
383 |
if (is_literal_bool_type(type_symbol)) {return true;}
|
|
384 |
return false;
|
|
385 |
}
|
|
386 |
|
|
387 |
|
|
388 |
#define is_type(type_name_symbol, type_name_class) (typeid(*type_name_symbol) == typeid(type_name_class))
|
|
389 |
|
204
|
390 |
|
|
391 |
#define sizeoftype(symbol) get_sizeof_datatype_c::getsize(symbol)
|
|
392 |
|
|
393 |
|
|
394 |
/* A helper function... */
|
|
395 |
bool visit_expression_type_c::is_literal_integer_type(symbol_c *type_symbol) {
|
257
|
396 |
if (type_symbol == NULL) {ERROR;}
|
|
397 |
if (typeid(*type_symbol) == typeid(neg_integer_c)) {return true;}
|
|
398 |
return is_nonneg_literal_integer_type(type_symbol);
|
|
399 |
}
|
|
400 |
|
|
401 |
|
|
402 |
/* A helper function... */
|
|
403 |
bool visit_expression_type_c::is_nonneg_literal_integer_type(symbol_c *type_symbol) {
|
|
404 |
if (type_symbol == NULL) {ERROR;}
|
204
|
405 |
if (typeid(*type_symbol) == typeid(integer_c)) {return true;}
|
|
406 |
if (typeid(*type_symbol) == typeid(binary_integer_c)) {return true;}
|
|
407 |
if (typeid(*type_symbol) == typeid(octal_integer_c)) {return true;}
|
|
408 |
if (typeid(*type_symbol) == typeid(hex_integer_c)) {return true;}
|
|
409 |
return false;
|
|
410 |
}
|
|
411 |
|
|
412 |
|
|
413 |
/* A helper function... */
|
|
414 |
bool visit_expression_type_c::is_literal_real_type(symbol_c *type_symbol) {
|
257
|
415 |
if (type_symbol == NULL) {ERROR;}
|
|
416 |
if (typeid(*type_symbol) == typeid(real_c)) {return true;}
|
|
417 |
if (typeid(*type_symbol) == typeid(neg_real_c)) {return true;}
|
204
|
418 |
return false;
|
|
419 |
}
|
|
420 |
|
|
421 |
|
|
422 |
/* A helper function... */
|
|
423 |
bool visit_expression_type_c::is_literal_bool_type(symbol_c *type_symbol) {
|
|
424 |
bool_type_name_c bool_t;
|
|
425 |
|
257
|
426 |
if (type_symbol == NULL) {ERROR;}
|
204
|
427 |
if (typeid(*type_symbol) == typeid(boolean_true_c)) {return true;}
|
|
428 |
if (typeid(*type_symbol) == typeid(boolean_false_c)) {return true;}
|
257
|
429 |
if (is_nonneg_literal_integer_type(type_symbol))
|
204
|
430 |
if (sizeoftype(&bool_t) >= sizeoftype(type_symbol)) {return true;}
|
|
431 |
return false;
|
|
432 |
}
|
|
433 |
|
|
434 |
/* Determine the common data type between two data types.
|
|
435 |
* If no common data type found, return NULL.
|
|
436 |
*
|
|
437 |
* If data types are identical, return the first (actually any would do...).
|
|
438 |
* If any of the data types is a literal, we confirm that
|
|
439 |
* the literal uses less bits than the fixed size data type.
|
|
440 |
* e.g. BYTE and 1024 returns NULL
|
|
441 |
* BYTE and 255 returns BYTE
|
|
442 |
*
|
|
443 |
* If two literals, then return the literal that requires more bits...
|
|
444 |
*/
|
257
|
445 |
|
204
|
446 |
symbol_c *visit_expression_type_c::common_type__(symbol_c *first_type, symbol_c *second_type) {
|
|
447 |
if (first_type == NULL && second_type == NULL) {ERROR;}
|
|
448 |
if (first_type == NULL) {return second_type;}
|
|
449 |
if (second_type == NULL) {return first_type;}
|
|
450 |
|
|
451 |
if (is_literal_integer_type(first_type) && is_literal_integer_type(second_type))
|
|
452 |
{return ((sizeoftype(first_type) > sizeoftype(second_type))? first_type:second_type);}
|
|
453 |
|
|
454 |
if (is_literal_real_type(first_type) && is_literal_real_type(second_type))
|
|
455 |
{return ((sizeoftype(first_type) > sizeoftype(second_type))? first_type:second_type);}
|
|
456 |
|
|
457 |
if (is_literal_bool_type(first_type) && is_literal_bool_type(second_type))
|
|
458 |
{return first_type;}
|
|
459 |
|
257
|
460 |
/* The following check can only be made after the is_literal_XXXX checks */
|
204
|
461 |
/* When two literals of the same type, with identical typeid's are checked,
|
257
|
462 |
* we must return the one that occupies more bits... This is done above.
|
204
|
463 |
*/
|
|
464 |
if (typeid(*first_type) == typeid(*second_type)) {return first_type;}
|
|
465 |
|
257
|
466 |
/* NOTE Although a BOOL is also an ANY_BIT, we must check it explicitly since some
|
|
467 |
* literal bool values are not literal integers...
|
|
468 |
*/
|
|
469 |
if (is_BOOL_type(first_type) && is_literal_bool_type(second_type)) {return first_type;}
|
|
470 |
if (is_BOOL_type(second_type) && is_literal_bool_type(first_type)) {return second_type;}
|
|
471 |
|
|
472 |
if (is_SAFEBOOL_type(first_type) && is_literal_bool_type(second_type)) {return first_type;}
|
|
473 |
if (is_SAFEBOOL_type(second_type) && is_literal_bool_type(first_type)) {return second_type;}
|
|
474 |
|
|
475 |
if (is_SAFEBOOL_type(first_type) && is_BOOL_type(second_type)) {return second_type;}
|
|
476 |
if (is_SAFEBOOL_type(second_type) && is_BOOL_type(first_type)) {return first_type;}
|
|
477 |
|
|
478 |
if (is_ANY_BIT_type(first_type) && is_nonneg_literal_integer_type(second_type))
|
204
|
479 |
{return ((sizeoftype(first_type) >= sizeoftype(second_type))? first_type :NULL);}
|
257
|
480 |
if (is_ANY_BIT_type(second_type) && is_nonneg_literal_integer_type(first_type))
|
204
|
481 |
{return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
|
|
482 |
|
257
|
483 |
if (is_ANY_SAFEBIT_type(first_type) && is_nonneg_literal_integer_type(second_type))
|
204
|
484 |
{return ((sizeoftype(first_type) >= sizeoftype(second_type))? first_type :NULL);}
|
257
|
485 |
if (is_ANY_SAFEBIT_type(second_type) && is_nonneg_literal_integer_type(first_type))
|
204
|
486 |
{return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
|
|
487 |
|
257
|
488 |
if (is_ANY_SAFEBIT_type(first_type) && is_ANY_BIT_type(second_type))
|
|
489 |
{return ((sizeoftype(first_type) == sizeoftype(second_type))? second_type:NULL);}
|
|
490 |
if (is_ANY_SAFEBIT_type(second_type) && is_ANY_BIT_type(first_type))
|
|
491 |
{return ((sizeoftype(first_type) == sizeoftype(second_type))? first_type :NULL);}
|
|
492 |
|
|
493 |
if (is_ANY_INT_type(first_type) && is_literal_integer_type(second_type))
|
204
|
494 |
{return ((sizeoftype(first_type) >= sizeoftype(second_type))? first_type :NULL);}
|
257
|
495 |
if (is_ANY_INT_type(second_type) && is_literal_integer_type(first_type))
|
204
|
496 |
{return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
|
|
497 |
|
257
|
498 |
if (is_ANY_SAFEINT_type(first_type) && is_literal_integer_type(second_type))
|
|
499 |
{return ((sizeoftype(first_type) >= sizeoftype(second_type))? first_type :NULL);}
|
|
500 |
if (is_ANY_SAFEINT_type(second_type) && is_literal_integer_type(first_type))
|
|
501 |
{return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
|
|
502 |
|
|
503 |
if (is_ANY_SAFEINT_type(first_type) && is_ANY_INT_type(second_type))
|
|
504 |
{return ((sizeoftype(first_type) == sizeoftype(second_type))? second_type:NULL);}
|
|
505 |
if (is_ANY_SAFEINT_type(second_type) && is_ANY_INT_type(first_type))
|
|
506 |
{return ((sizeoftype(first_type) == sizeoftype(second_type))? first_type :NULL);}
|
|
507 |
|
|
508 |
if (is_ANY_REAL_type(first_type) && is_literal_real_type(second_type))
|
|
509 |
{return ((sizeoftype(first_type) >= sizeoftype(second_type))? first_type :NULL);}
|
|
510 |
if (is_ANY_REAL_type(second_type) && is_literal_real_type(first_type))
|
|
511 |
{return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
|
|
512 |
|
|
513 |
if (is_ANY_SAFEREAL_type(first_type) && is_literal_real_type(second_type))
|
|
514 |
{return ((sizeoftype(first_type) >= sizeoftype(second_type))? first_type :NULL);}
|
|
515 |
if (is_ANY_SAFEREAL_type(second_type) && is_literal_real_type(first_type))
|
|
516 |
{return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
|
|
517 |
|
|
518 |
if (is_ANY_SAFEREAL_type(first_type) && is_ANY_REAL_type(second_type))
|
|
519 |
{return ((sizeoftype(first_type) == sizeoftype(second_type))? second_type:NULL);}
|
|
520 |
if (is_ANY_SAFEREAL_type(second_type) && is_ANY_REAL_type(first_type))
|
|
521 |
{return ((sizeoftype(first_type) == sizeoftype(second_type))? first_type :NULL);}
|
|
522 |
|
|
523 |
/* the Time and Date types... */
|
|
524 |
if (is_type(first_type, safetime_type_name_c) && is_type(second_type, time_type_name_c)) {return second_type;}
|
|
525 |
if (is_type(second_type, safetime_type_name_c) && is_type( first_type, time_type_name_c)) {return first_type;}
|
|
526 |
|
|
527 |
if (is_type(first_type, safedate_type_name_c) && is_type(second_type, date_type_name_c)) {return second_type;}
|
|
528 |
if (is_type(second_type, safedate_type_name_c) && is_type( first_type, date_type_name_c)) {return first_type;}
|
|
529 |
|
|
530 |
if (is_type(first_type, safedt_type_name_c) && is_type(second_type, dt_type_name_c)) {return second_type;}
|
|
531 |
if (is_type(second_type, safedt_type_name_c) && is_type( first_type, dt_type_name_c)) {return first_type;}
|
|
532 |
|
|
533 |
if (is_type(first_type, safetod_type_name_c) && is_type(second_type, tod_type_name_c)) {return second_type;}
|
|
534 |
if (is_type(second_type, safetod_type_name_c) && is_type( first_type, tod_type_name_c)) {return first_type;}
|
|
535 |
|
204
|
536 |
/* no common type */
|
|
537 |
return NULL;
|
|
538 |
}
|
|
539 |
|
|
540 |
/* Determine the common data type between two data types.
|
|
541 |
* Unlike the common_type__() function, we stop the compiler with an ERROR
|
|
542 |
* if no common data type is found.
|
|
543 |
*/
|
|
544 |
symbol_c *visit_expression_type_c::common_type(symbol_c *first_type, symbol_c *second_type) {
|
|
545 |
symbol_c *res = common_type__(first_type, second_type);
|
|
546 |
if (NULL == res) ERROR;
|
|
547 |
return res;
|
|
548 |
}
|
|
549 |
|
|
550 |
|
257
|
551 |
/* Return TRUE if the second (value) data type may be assigned to a variable of the first (variable) data type
|
|
552 |
* such as:
|
|
553 |
* var_type value_type
|
|
554 |
* BOOL BYTE#7 -> returns false
|
|
555 |
* INT INT#7 -> returns true
|
|
556 |
* INT 7 -> returns true
|
|
557 |
* REAL 7.89 -> returns true
|
|
558 |
* REAL 7 -> returns true
|
|
559 |
* INT 7.89 -> returns false
|
|
560 |
* SAFEBOOL BOOL#1 -> returns false !!!
|
|
561 |
* etc...
|
|
562 |
*
|
|
563 |
* NOTE: It is assumed that the var_type is the data type of an lvalue
|
|
564 |
*/
|
|
565 |
bool visit_expression_type_c::is_valid_assignment(symbol_c *var_type, symbol_c *value_type) {
|
|
566 |
if (var_type == NULL) {/* STAGE3_ERROR(value_type, value_type, "Var_type == NULL"); */ ERROR;}
|
|
567 |
if (value_type == NULL) {/* STAGE3_ERROR(var_type, var_type, "Value_type == NULL"); */ ERROR;}
|
|
568 |
if (var_type == NULL || value_type == NULL) {ERROR;}
|
|
569 |
|
|
570 |
symbol_c *common_type = common_type__(var_type, value_type);
|
|
571 |
if (NULL == common_type)
|
|
572 |
return false;
|
|
573 |
return (typeid(*var_type) == typeid(*common_type));
|
|
574 |
}
|
|
575 |
|
|
576 |
|
204
|
577 |
/* Return TRUE if there is a common data type, otherwise return FALSE
|
257
|
578 |
* i.e., return TRUE if both data types may be used simultaneously in an expression
|
|
579 |
* such as:
|
|
580 |
* BOOL#0 AND BYTE#7 -> returns false
|
|
581 |
* 0 AND BYTE#7 -> returns true
|
|
582 |
* INT#10 AND INT#7 -> returns true
|
|
583 |
* INT#10 AND 7 -> returns true
|
|
584 |
* REAL#34.3 AND 7.89 -> returns true
|
|
585 |
* REAL#34.3 AND 7 -> returns true
|
|
586 |
* INT#10 AND 7.89 -> returns false
|
|
587 |
* SAFEBOOL#0 AND BOOL#1 -> returns true !!!
|
|
588 |
* etc...
|
204
|
589 |
*/
|
|
590 |
bool visit_expression_type_c::is_compatible_type(symbol_c *first_type, symbol_c *second_type) {
|
|
591 |
if (first_type == NULL || second_type == NULL) {ERROR;}
|
|
592 |
return (NULL != common_type__(first_type, second_type));
|
|
593 |
}
|
|
594 |
|
|
595 |
|
|
596 |
|
257
|
597 |
#define is_num_type is_ANY_NUM_compatible
|
|
598 |
#define is_integer_type is_ANY_INT_compatible
|
|
599 |
#define is_real_type is_ANY_REAL_compatible
|
|
600 |
#define is_binary_type is_ANY_BIT_compatible
|
204
|
601 |
/* actually the ROR, ROL, SHL, and SHR function also accept boolean type! */
|
257
|
602 |
#define is_nbinary_type is_ANY_BIT_compatible
|
204
|
603 |
#define compute_standard_function_default visit_expression_type_c::compute_standard_function_default
|
|
604 |
#define compute_standard_function_il visit_expression_type_c::compute_standard_function_il
|
|
605 |
#define search_expression_type_c visit_expression_type_c
|
|
606 |
#define search(x) search_f(x)
|
|
607 |
#define next() next_nf()
|
|
608 |
// #define search_constant_type_c::constant_int_type_name search_expression_type_c::integer
|
|
609 |
#define constant_int_type_name integer
|
|
610 |
#define is_same_type is_compatible_type
|
|
611 |
#include "../absyntax_utils/search_type_code.c"
|
|
612 |
#undef is_same_type
|
|
613 |
#undef constant_int_type_name
|
|
614 |
// #undef search_constant_type_c::constant_int_type_name
|
|
615 |
#undef next
|
|
616 |
#undef search
|
|
617 |
#undef compute_standard_function_default
|
|
618 |
#undef compute_standard_function_il
|
|
619 |
#undef search_expression_type_c
|
|
620 |
#undef is_real_type
|
|
621 |
#undef is_binary_type
|
|
622 |
#undef is_nbinary_type
|
|
623 |
#undef is_integer_type
|
|
624 |
#undef is_num_type
|
|
625 |
|
|
626 |
|
|
627 |
|
|
628 |
|
|
629 |
|
|
630 |
|
|
631 |
/* A helper function... */
|
257
|
632 |
/*
|
204
|
633 |
symbol_c *visit_expression_type_c::compute_boolean_expression(symbol_c *left_type, symbol_c *right_type,
|
|
634 |
is_data_type_t is_data_type) {
|
257
|
635 |
*/
|
|
636 |
symbol_c *visit_expression_type_c::compute_expression(symbol_c *left_type, symbol_c *right_type,
|
|
637 |
is_data_type_t is_data_type) {
|
204
|
638 |
bool error = false;
|
|
639 |
|
|
640 |
if (!(this->*is_data_type)(left_type)) {
|
257
|
641 |
STAGE3_ERROR(left_type, left_type, "Invalid data type of left operand.");
|
204
|
642 |
error = true;
|
|
643 |
}
|
|
644 |
if (!(this->*is_data_type)(right_type)) {
|
257
|
645 |
STAGE3_ERROR(right_type, right_type, "Invalid data type of right operand.");
|
204
|
646 |
error = true;
|
|
647 |
}
|
|
648 |
if (!is_compatible_type(left_type, right_type)) {
|
257
|
649 |
STAGE3_ERROR(left_type, right_type, "Type mismatch between operands.");
|
204
|
650 |
error = true;
|
|
651 |
}
|
|
652 |
|
|
653 |
if (error)
|
|
654 |
return NULL;
|
|
655 |
else
|
|
656 |
return common_type(left_type, right_type);
|
|
657 |
}
|
|
658 |
|
|
659 |
|
257
|
660 |
# if 0
|
204
|
661 |
/* A helper function... */
|
|
662 |
symbol_c *visit_expression_type_c::compute_numeric_expression(symbol_c *left_type, symbol_c *right_type,
|
|
663 |
is_data_type_t is_data_type) {
|
257
|
664 |
bool error = false;
|
|
665 |
|
|
666 |
if (!(this->*is_data_type)(left_type)) {
|
|
667 |
STAGE3_ERROR(left_type, right_type, "Invalid data type of left operand.");
|
|
668 |
error = true;
|
|
669 |
}
|
|
670 |
if (!(this->*is_data_type)(right_type)) {
|
|
671 |
STAGE3_ERROR(left_type, right_type, "Invalid data type of right operand.");
|
|
672 |
error = true;
|
|
673 |
}
|
|
674 |
if (!is_compatible_type(left_type, right_type)) {
|
|
675 |
STAGE3_ERROR(left_type, right_type, "Type mismatch between operands.");
|
|
676 |
error = true;
|
|
677 |
}
|
|
678 |
|
|
679 |
/*
|
204
|
680 |
if (is_literal_integer_type(left_type) || is_literal_real_type(left_type)) {
|
|
681 |
return right_type;
|
|
682 |
} else {
|
|
683 |
return left_type;
|
|
684 |
}
|
257
|
685 |
*/
|
|
686 |
|
|
687 |
if (error)
|
|
688 |
return NULL;
|
|
689 |
else
|
|
690 |
return common_type(left_type, right_type);
|
204
|
691 |
|
|
692 |
/* humour the compiler... */
|
257
|
693 |
/*
|
|
694 |
return NULL;
|
|
695 |
*/
|
|
696 |
}
|
|
697 |
#endif
|
204
|
698 |
|
|
699 |
|
|
700 |
|
|
701 |
|
|
702 |
|
|
703 |
/* A helper function... */
|
|
704 |
/* check the semantics of a FB or Function non-formal call */
|
|
705 |
/* e.g. foo(1, 2, 3, 4); */
|
|
706 |
void visit_expression_type_c::check_nonformal_call(symbol_c *f_call, symbol_c *f_decl, bool use_il_defvar) {
|
|
707 |
symbol_c *call_param_value, *call_param_type, *param_type;
|
|
708 |
identifier_c *param_name;
|
|
709 |
function_param_iterator_c fp_iterator(f_decl);
|
|
710 |
function_call_param_iterator_c fcp_iterator(f_call);
|
|
711 |
|
|
712 |
/* if use_il_defvar, then the first parameter for the call comes from the il_default_variable */
|
|
713 |
if (use_il_defvar) {
|
|
714 |
/* The first parameter of the function corresponds to the il_default_variable_type of the function call */
|
|
715 |
do {
|
|
716 |
param_name = fp_iterator.next();
|
|
717 |
if(param_name == NULL) break;
|
|
718 |
/* The EN and ENO parameters are default parameters.
|
|
719 |
* In the non-formal invocation of a function there can be no assignment of
|
|
720 |
* values to these parameters. Therefore, we ignore the parameters declared
|
|
721 |
* in the function.
|
|
722 |
*/
|
|
723 |
} while ((strcmp(param_name->value, "EN") == 0) || (strcmp(param_name->value, "ENO") == 0));
|
|
724 |
/* If the function does not have any parameters (param_name == NULL)
|
|
725 |
* then we cannot compare its type with the il_default_variable_type.
|
|
726 |
*/
|
|
727 |
if(param_name != NULL) {
|
|
728 |
param_type = fp_iterator.param_type();
|
257
|
729 |
if(!is_valid_assignment(param_type, il_default_variable_type))
|
204
|
730 |
STAGE3_ERROR(f_call, f_call, "In function/FB call, first parameter has invalid data type.");
|
|
731 |
}
|
|
732 |
} // if (use_il_defvar)
|
|
733 |
|
|
734 |
/* Iterating through the non-formal parameters of the function call */
|
|
735 |
while((call_param_value = fcp_iterator.next_nf()) != NULL) {
|
|
736 |
/* Obtaining the type of the current parameter in the function call */
|
|
737 |
call_param_type = base_type((symbol_c*)call_param_value->accept(*this));
|
|
738 |
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.");;
|
|
739 |
|
|
740 |
/* Iterate to the next parameter of the function being called.
|
|
741 |
* Get the name of that parameter, and ignore if EN or ENO.
|
|
742 |
*/
|
|
743 |
do {
|
|
744 |
param_name = fp_iterator.next();
|
|
745 |
/* If there is no parameter declared with that name */
|
|
746 |
if(param_name == NULL) {STAGE3_ERROR(f_call, f_call, "Too many parameters in function/FB call."); break;}
|
|
747 |
} while ((strcmp(param_name->value, "EN") == 0) || (strcmp(param_name->value, "ENO") == 0));
|
|
748 |
|
|
749 |
if(param_name != NULL) {
|
|
750 |
/* Get the parameter type */
|
|
751 |
param_type = fp_iterator.param_type();
|
|
752 |
/* If the declared parameter and the parameter from the function call do no have the same type */
|
257
|
753 |
if(!is_valid_assignment(param_type, call_param_type)) STAGE3_ERROR(call_param_value, call_param_value, "Type mismatch in function/FB call parameter.");
|
204
|
754 |
}
|
|
755 |
}
|
|
756 |
}
|
|
757 |
|
|
758 |
void visit_expression_type_c::compute_input_operatores(symbol_c *symbol, const char *input_operator){
|
|
759 |
symbol_c *call_param_type;
|
|
760 |
symbol_c *fb_decl = il_operand_type;
|
|
761 |
/* The following should never occur. The function block must be defined,
|
|
762 |
* and the FB type being called MUST be in the symtable...
|
|
763 |
* This was all already checked at stage 2!
|
|
764 |
*/
|
|
765 |
if (NULL == fb_decl){
|
|
766 |
STAGE3_ERROR(symbol, symbol, "Parameter operator needs an instance of a function block operand.");
|
|
767 |
ERROR;
|
|
768 |
}
|
|
769 |
|
|
770 |
/* Iterating through the formal parameters of the function call */
|
|
771 |
identifier_c call_param_name(input_operator);
|
|
772 |
|
|
773 |
/* Obtaining the type of the value being passed in the function call */
|
|
774 |
call_param_type = il_default_variable_type;
|
|
775 |
if (call_param_type == NULL) {
|
|
776 |
STAGE3_ERROR(&call_param_name, &call_param_name, "Could not determine data type of value being passed in function/FB call.");
|
|
777 |
/* The data value being passed is possibly any enumerated type value.
|
|
778 |
* We do not yet handle semantic verification of enumerated types.
|
|
779 |
*/
|
|
780 |
ERROR;
|
|
781 |
}
|
|
782 |
call_param_type = base_type(call_param_type);
|
|
783 |
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.");
|
|
784 |
|
|
785 |
|
|
786 |
check_formal_parameter(&call_param_name, call_param_type, fb_decl);
|
|
787 |
// return NULL;
|
|
788 |
}
|
|
789 |
|
|
790 |
void visit_expression_type_c::check_formal_parameter(symbol_c *call_param_name, symbol_c *call_param_type, symbol_c *f_decl) {
|
|
791 |
symbol_c *param_type;
|
|
792 |
identifier_c *param_name;
|
|
793 |
function_param_iterator_c fp_iterator(f_decl);
|
|
794 |
|
|
795 |
/* Find the corresponding parameter of the function being called */
|
|
796 |
param_name = fp_iterator.search(call_param_name);
|
|
797 |
if(param_name == NULL) {
|
|
798 |
STAGE3_ERROR(call_param_name, call_param_name, "Invalid parameter in function/FB call.");
|
|
799 |
} else {
|
|
800 |
/* Get the parameter type */
|
|
801 |
param_type = fp_iterator.param_type();
|
|
802 |
/* If the declared parameter and the parameter from the function call have the same type */
|
257
|
803 |
if(!is_valid_assignment(param_type, call_param_type)) STAGE3_ERROR(call_param_name, call_param_name, "Type mismatch function/FB call parameter.");
|
204
|
804 |
}
|
|
805 |
}
|
|
806 |
|
|
807 |
|
|
808 |
/* A helper function... */
|
|
809 |
/* check the semantics of a FB or Function formal call */
|
|
810 |
/* e.g. foo(IN1 := 1, OUT1 =>x, EN := true); */
|
|
811 |
void visit_expression_type_c::check_formal_call(symbol_c *f_call, symbol_c *f_decl) {
|
|
812 |
symbol_c *call_param_value, *call_param_type, *call_param_name, *param_type;
|
|
813 |
symbol_c *verify_duplicate_param;
|
|
814 |
identifier_c *param_name;
|
|
815 |
function_param_iterator_c fp_iterator(f_decl);
|
|
816 |
function_call_param_iterator_c fcp_iterator(f_call);
|
|
817 |
|
|
818 |
/* Iterating through the formal parameters of the function call */
|
|
819 |
while((call_param_name = fcp_iterator.next_f()) != NULL) {
|
|
820 |
|
|
821 |
/* Obtaining the value being passed in the function call */
|
|
822 |
call_param_value = fcp_iterator.get_current_value();
|
|
823 |
/* the following should never occur. If it does, then we have a bug in our code... */
|
|
824 |
if (NULL == call_param_value) ERROR;
|
|
825 |
|
|
826 |
/* Checking if there are duplicated parameter values */
|
|
827 |
verify_duplicate_param = fcp_iterator.search_f(call_param_name);
|
|
828 |
if(verify_duplicate_param != call_param_value){
|
|
829 |
STAGE3_ERROR(call_param_name, verify_duplicate_param, "Duplicated parameter values.");
|
|
830 |
}
|
|
831 |
|
|
832 |
/* Obtaining the type of the value being passed in the function call */
|
|
833 |
call_param_type = (symbol_c*)call_param_value->accept(*this);
|
|
834 |
if (call_param_type == NULL) {
|
|
835 |
STAGE3_ERROR(call_param_name, call_param_value, "Could not determine data type of value being passed in function/FB call.");
|
|
836 |
/* The data value being passed is possibly any enumerated type value.
|
|
837 |
* We do not yet handle semantic verification of enumerated types.
|
|
838 |
*/
|
|
839 |
ERROR;
|
|
840 |
}
|
|
841 |
call_param_type = base_type(call_param_type);
|
|
842 |
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.");
|
|
843 |
|
|
844 |
/* Find the corresponding parameter of the function being called */
|
|
845 |
param_name = fp_iterator.search(call_param_name);
|
|
846 |
if(param_name == NULL) {
|
|
847 |
STAGE3_ERROR(call_param_name, call_param_name, "Invalid parameter in function/FB call.");
|
|
848 |
} else {
|
|
849 |
/* Get the parameter type */
|
|
850 |
param_type = fp_iterator.param_type();
|
|
851 |
/* If the declared parameter and the parameter from the function call have the same type */
|
257
|
852 |
if(!is_valid_assignment(param_type, call_param_type)) STAGE3_ERROR(call_param_name, call_param_value, "Type mismatch function/FB call parameter.");
|
204
|
853 |
}
|
|
854 |
}
|
|
855 |
}
|
|
856 |
|
|
857 |
|
|
858 |
|
|
859 |
|
|
860 |
/* a helper function... */
|
|
861 |
symbol_c *visit_expression_type_c::base_type(symbol_c *symbol) {
|
|
862 |
return (symbol_c *)symbol->accept(search_base_type);
|
|
863 |
}
|
|
864 |
|
|
865 |
|
|
866 |
/* a helper function... */
|
|
867 |
void *visit_expression_type_c::verify_null(symbol_c *symbol){
|
|
868 |
if(il_default_variable_type == NULL){
|
|
869 |
STAGE3_ERROR(symbol, symbol, "Il default variable can't be NULL.");
|
|
870 |
}
|
|
871 |
if(il_operand_type == NULL){
|
|
872 |
STAGE3_ERROR(symbol, symbol, "function requires an operand.");
|
|
873 |
}
|
|
874 |
return NULL;
|
|
875 |
}
|
|
876 |
|
|
877 |
|
|
878 |
|
|
879 |
|
|
880 |
/*********************/
|
|
881 |
/* B 1.4 - Variables */
|
|
882 |
/*********************/
|
|
883 |
|
|
884 |
void *visit_expression_type_c::visit(symbolic_variable_c *symbol) {
|
|
885 |
return search_varfb_instance_type->get_type(symbol);
|
|
886 |
}
|
|
887 |
|
|
888 |
/********************************************/
|
|
889 |
/* B 1.4.1 - Directly Represented Variables */
|
|
890 |
/********************************************/
|
|
891 |
void *visit_expression_type_c::visit(direct_variable_c *symbol) {
|
|
892 |
switch (symbol->value[2]) {
|
|
893 |
case 'X': // bit - 1 bit
|
|
894 |
return (void *)&bool_type_name;
|
|
895 |
case 'B': // byte - 8 bits
|
|
896 |
return (void *)&byte_type_name;
|
|
897 |
case 'W': // word - 16 bits
|
|
898 |
return (void *)&word_type_name;
|
|
899 |
case 'D': // double word - 32 bits
|
|
900 |
return (void *)&dword_type_name;
|
|
901 |
case 'L': // long word - 64 bits
|
|
902 |
return (void *)&lword_type_name;
|
|
903 |
default: // if none of the above, then the empty string was used <=> boolean
|
|
904 |
return (void *)&bool_type_name;
|
|
905 |
}
|
|
906 |
}
|
|
907 |
|
|
908 |
/*************************************/
|
|
909 |
/* B 1.4.2 - Multi-element variables */
|
|
910 |
/*************************************/
|
|
911 |
void *visit_expression_type_c::visit(array_variable_c *symbol) {
|
|
912 |
return search_varfb_instance_type->get_type(symbol);
|
|
913 |
}
|
|
914 |
|
|
915 |
void *visit_expression_type_c::visit(structured_variable_c *symbol) {
|
|
916 |
return search_varfb_instance_type->get_type(symbol);
|
|
917 |
}
|
|
918 |
|
|
919 |
|
|
920 |
|
|
921 |
/****************************************/
|
|
922 |
/* B.2 - Language IL (Instruction List) */
|
|
923 |
/****************************************/
|
|
924 |
/***********************************/
|
|
925 |
/* B 2.1 Instructions and Operands */
|
|
926 |
/***********************************/
|
|
927 |
/*| instruction_list il_instruction */
|
|
928 |
/* The visitor of the base class search_visitor_c will handle calling each instruction in the list.
|
|
929 |
* We do not need to do anything here...
|
|
930 |
*/
|
|
931 |
// void *visit_expression_type_c::visit(instruction_list_c *symbol)
|
|
932 |
|
|
933 |
/* | label ':' [il_incomplete_instruction] eol_list */
|
|
934 |
//SYM_REF2(il_instruction_c, label, il_instruction)
|
|
935 |
// void *visit_expression_type_c::visit(il_instruction_c *symbol);
|
|
936 |
|
|
937 |
|
|
938 |
/* | il_simple_operator [il_operand] */
|
|
939 |
// SYM_REF2(il_simple_operation_c, il_simple_operator, il_operand)
|
|
940 |
void *visit_expression_type_c::visit(il_simple_operation_c *symbol) {
|
|
941 |
if (il_error)
|
|
942 |
return NULL;
|
|
943 |
|
|
944 |
/* determine the data type of the operand */
|
|
945 |
if (symbol->il_operand != NULL){
|
|
946 |
il_operand_type = base_type((symbol_c *)symbol->il_operand->accept(*this));
|
|
947 |
} else {
|
|
948 |
il_operand_type = NULL;
|
|
949 |
}
|
|
950 |
/* recursive call to see whether data types are compatible */
|
|
951 |
symbol->il_simple_operator->accept(*this);
|
|
952 |
|
|
953 |
il_operand_type = NULL;
|
|
954 |
return NULL;
|
|
955 |
}
|
|
956 |
|
|
957 |
// | function_name [il_operand_list] */
|
|
958 |
//SYM_REF2(il_function_call_c, function_name, il_operand_list)
|
|
959 |
void *visit_expression_type_c::visit(il_function_call_c *symbol) {
|
|
960 |
if (il_error)
|
|
961 |
return NULL;
|
|
962 |
|
|
963 |
/* First find the declaration of the function being called! */
|
|
964 |
function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name);
|
|
965 |
|
|
966 |
symbol_c *return_data_type = NULL;
|
|
967 |
|
|
968 |
if (f_decl == function_symtable.end_value()) {
|
|
969 |
function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name);
|
|
970 |
if (current_function_type == function_none) ERROR;
|
|
971 |
/* This code is for the functions that the user did not declare and that are
|
|
972 |
* part of the IL or ST languagem (built-in functions).
|
|
973 |
* For now we won't do the semantics analysis for that kind of functions.
|
|
974 |
*/
|
|
975 |
/*
|
|
976 |
return_data_type = (symbol_c *)search_expression_type->compute_standard_function_default(NULL, symbol);
|
|
977 |
if (NULL == return_data_type) ERROR;
|
|
978 |
|
|
979 |
function_call_param_iterator_c fcp_iterator(symbol);
|
|
980 |
|
|
981 |
int nb_param = 0;
|
|
982 |
if (symbol->il_param_list != NULL)
|
|
983 |
nb_param += ((list_c *)symbol->il_param_list)->n;
|
|
984 |
|
|
985 |
identifier_c en_param_name("EN");*/
|
|
986 |
/* Get the value from EN param */
|
|
987 |
/*symbol_c *EN_param_value = fcp_iterator.search(&en_param_name);
|
|
988 |
if (EN_param_value == NULL)
|
|
989 |
EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c()));
|
|
990 |
else
|
|
991 |
nb_param --;
|
|
992 |
ADD_PARAM_LIST(EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in)
|
|
993 |
|
|
994 |
identifier_c eno_param_name("EN0");*/
|
|
995 |
/* Get the value from ENO param */
|
|
996 |
/*symbol_c *ENO_param_value = fcp_iterator.search(&eno_param_name);
|
|
997 |
if (ENO_param_value != NULL)
|
|
998 |
nb_param --;
|
|
999 |
ADD_PARAM_LIST(ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out)
|
|
1000 |
|
|
1001 |
#include "st_code_gen.c"
|
|
1002 |
*/
|
|
1003 |
} else {
|
|
1004 |
/* determine the base data type returned by the function being called... */
|
|
1005 |
return_data_type = base_type(f_decl->type_name);
|
|
1006 |
/* If the following occurs, then we must have some big bug in the syntax parser (stage 2)... */
|
|
1007 |
if (NULL == return_data_type) ERROR;
|
|
1008 |
|
|
1009 |
/* check semantics of data passed in the function call... */
|
|
1010 |
check_nonformal_call(symbol, f_decl, true);
|
|
1011 |
|
|
1012 |
/* set the new ddata type of the default variable for the following verifications... */
|
|
1013 |
il_default_variable_type = return_data_type;
|
|
1014 |
}
|
|
1015 |
return NULL;
|
|
1016 |
}
|
|
1017 |
|
|
1018 |
|
|
1019 |
/* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */
|
|
1020 |
// SYM_REF3(il_expression_c, il_expr_operator, il_operand, simple_instr_list);
|
|
1021 |
void *visit_expression_type_c::visit(il_expression_c *symbol) {
|
|
1022 |
if (il_error)
|
|
1023 |
return NULL;
|
|
1024 |
|
|
1025 |
symbol_c *il_default_variable_type_back = il_default_variable_type;
|
|
1026 |
|
|
1027 |
il_parenthesis_level++;
|
|
1028 |
|
|
1029 |
if(symbol->il_operand != NULL) {
|
|
1030 |
il_default_variable_type = base_type((symbol_c *)symbol->il_operand->accept(*this));
|
|
1031 |
} else {
|
|
1032 |
il_default_variable_type = NULL;
|
|
1033 |
}
|
|
1034 |
|
|
1035 |
if(symbol->simple_instr_list != NULL) {
|
|
1036 |
symbol->simple_instr_list->accept(*this);
|
|
1037 |
}
|
|
1038 |
|
|
1039 |
il_parenthesis_level--;
|
|
1040 |
if (il_parenthesis_level < 0) ERROR;
|
|
1041 |
|
|
1042 |
il_operand_type = il_default_variable_type;
|
|
1043 |
il_default_variable_type = il_default_variable_type_back;
|
|
1044 |
|
|
1045 |
/* Now check the if the data type semantics of operation are correct,
|
|
1046 |
* but only if no previous error has been found...
|
|
1047 |
*/
|
|
1048 |
if (il_error)
|
|
1049 |
return NULL;
|
|
1050 |
symbol->il_expr_operator->accept(*this);
|
|
1051 |
|
|
1052 |
return NULL;
|
|
1053 |
}
|
|
1054 |
|
|
1055 |
|
|
1056 |
#if 0
|
|
1057 |
/* il_jump_operator label */
|
|
1058 |
SYM_REF2(il_jump_operation_c, il_jump_operator, label)
|
|
1059 |
void *visit_expression_type_c::visit(il_jump_operation_c *symbol);
|
|
1060 |
#endif
|
|
1061 |
|
|
1062 |
|
|
1063 |
/* il_call_operator prev_declared_fb_name
|
|
1064 |
* | il_call_operator prev_declared_fb_name '(' ')'
|
|
1065 |
* | il_call_operator prev_declared_fb_name '(' eol_list ')'
|
|
1066 |
* | il_call_operator prev_declared_fb_name '(' il_operand_list ')'
|
|
1067 |
* | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')'
|
|
1068 |
*/
|
|
1069 |
/* SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list) */
|
|
1070 |
void *visit_expression_type_c::visit(il_fb_call_c *symbol) {
|
|
1071 |
if (il_error)
|
|
1072 |
return NULL;
|
|
1073 |
|
|
1074 |
/* first check whether the il_default_variable is of the correct type
|
|
1075 |
* for the CAL / CALC / CALCN operator being used...
|
|
1076 |
*/
|
|
1077 |
symbol->il_call_operator->accept(*this);
|
|
1078 |
|
|
1079 |
/* Now check the FB call itself... */
|
|
1080 |
|
|
1081 |
/* First we find the declaration of the FB type of the FB instance being called... */
|
|
1082 |
/* e.g. Function_block foo_fb_type
|
|
1083 |
* ...
|
|
1084 |
* End_Function_Block
|
|
1085 |
*
|
|
1086 |
* Program test
|
|
1087 |
* var fb1 : foo_fb_type; end_var
|
|
1088 |
* fb1(...)
|
|
1089 |
* End_Program
|
|
1090 |
*
|
|
1091 |
* search_varfb_instance_type->get_type( identifier_c("fb1") )
|
|
1092 |
* in the scope of Program 'test'
|
|
1093 |
* will return the fb declaration of foo_fb_type !!
|
|
1094 |
*/
|
|
1095 |
#if 0
|
|
1096 |
symbol_c *fb_decl_symbol = search_varfb_instance_type->get_type(symbol->fb_name);
|
|
1097 |
/* The following should never occur. The function block must be defined,
|
|
1098 |
* and the FB type being called MUST be in the symtable...
|
|
1099 |
* This was all already checked at stage 2!
|
|
1100 |
*/
|
|
1101 |
if (NULL == fb_decl_symbol) ERROR;
|
|
1102 |
|
|
1103 |
function_block_declaration_c *fb_decl = dynamic_cast<function_block_declaration_c *>(fb_decl_symbol);
|
|
1104 |
/* should never occur. ... */
|
|
1105 |
if (NULL == fb_decl) ERROR;
|
|
1106 |
#endif
|
|
1107 |
symbol_c *fb_decl = search_varfb_instance_type->get_type(symbol->fb_name);
|
|
1108 |
/* The following should never occur. The function block must be defined,
|
|
1109 |
* and the FB type being called MUST be in the symtable...
|
|
1110 |
* This was all already checked at stage 2!
|
|
1111 |
*/
|
|
1112 |
if (NULL == fb_decl) ERROR;
|
|
1113 |
|
|
1114 |
/* now check the semantics of the fb call... */
|
|
1115 |
/* If the syntax parser is working correctly, exactly one of the
|
|
1116 |
* following two symbols will be NULL, while the other is != NULL.
|
|
1117 |
*/
|
|
1118 |
if (NULL != symbol->il_operand_list) check_nonformal_call(symbol, fb_decl);
|
|
1119 |
if (NULL != symbol->il_param_list) check_formal_call (symbol, fb_decl);
|
|
1120 |
|
|
1121 |
return NULL;
|
|
1122 |
}
|
|
1123 |
|
|
1124 |
|
|
1125 |
|
|
1126 |
/* | function_name '(' eol_list [il_param_list] ')' */
|
|
1127 |
/* SYM_REF2(il_formal_funct_call_c, function_name, il_param_list) */
|
|
1128 |
void *visit_expression_type_c::visit(il_formal_funct_call_c *symbol) {
|
|
1129 |
if (il_error)
|
|
1130 |
return NULL;
|
|
1131 |
|
|
1132 |
function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name);
|
|
1133 |
|
|
1134 |
symbol_c *return_data_type = NULL;
|
|
1135 |
|
|
1136 |
if (f_decl == function_symtable.end_value()) {
|
|
1137 |
function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name);
|
|
1138 |
if (current_function_type == function_none) ERROR;
|
|
1139 |
|
|
1140 |
/* This code is for the functions that the user did not declare and that are
|
|
1141 |
* part of the IL or ST languagem (built-in functions).
|
|
1142 |
* For now we won't do the semantics analysis for that kind of functions.
|
|
1143 |
*/
|
|
1144 |
#if 0
|
|
1145 |
return_data_type = (symbol_c *)search_expression_type->compute_standard_function_default(NULL, symbol);
|
|
1146 |
if (NULL == return_data_type) ERROR;
|
|
1147 |
|
|
1148 |
function_call_param_iterator_c fcp_iterator(symbol);
|
|
1149 |
|
|
1150 |
int nb_param = 0;
|
|
1151 |
if (symbol->il_param_list != NULL)
|
|
1152 |
nb_param += ((list_c *)symbol->il_param_list)->n;
|
|
1153 |
|
|
1154 |
identifier_c en_param_name("EN");
|
|
1155 |
/* Get the value from EN param */
|
|
1156 |
symbol_c *EN_param_value = fcp_iterator.search(&en_param_name);
|
|
1157 |
if (EN_param_value == NULL)
|
|
1158 |
EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c()));
|
|
1159 |
else
|
|
1160 |
nb_param --;
|
|
1161 |
ADD_PARAM_LIST(EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in)
|
|
1162 |
|
|
1163 |
identifier_c eno_param_name("EN0");
|
|
1164 |
/* Get the value from ENO param */
|
|
1165 |
symbol_c *ENO_param_value = fcp_iterator.search(&eno_param_name);
|
|
1166 |
if (ENO_param_value != NULL)
|
|
1167 |
nb_param --;
|
|
1168 |
ADD_PARAM_LIST(ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out)
|
|
1169 |
|
|
1170 |
#include "st_code_gen.c"
|
|
1171 |
#endif
|
|
1172 |
} else {
|
|
1173 |
/* determine the base data type returned by the function being called... */
|
|
1174 |
return_data_type = base_type(f_decl->type_name);
|
|
1175 |
/* the following should never occur. If it does, then we have a bug in the syntax parser (stage 2)... */
|
|
1176 |
if (NULL == return_data_type) ERROR;
|
|
1177 |
|
|
1178 |
/* check semantics of data passed in the function call... */
|
|
1179 |
check_formal_call(symbol, f_decl);
|
|
1180 |
|
|
1181 |
/* the data type of the data returned by the function, and stored in the il default variable... */
|
|
1182 |
il_default_variable_type = return_data_type;
|
|
1183 |
}
|
|
1184 |
return NULL;
|
|
1185 |
}
|
|
1186 |
|
|
1187 |
|
|
1188 |
#if 0
|
|
1189 |
/* | il_operand_list ',' il_operand */
|
|
1190 |
SYM_LIST(il_operand_list_c)
|
|
1191 |
void *visit_expression_type_c::visit(il_operand_list_c *symbol);
|
|
1192 |
|
|
1193 |
/* | simple_instr_list il_simple_instruction */
|
|
1194 |
SYM_LIST(simple_instr_list_c)
|
|
1195 |
void *visit_expression_type_c::visit(simple_instr_list_c *symbol);
|
|
1196 |
|
|
1197 |
/* | il_initial_param_list il_param_instruction */
|
|
1198 |
SYM_LIST(il_param_list_c)
|
|
1199 |
void *visit_expression_type_c::visit(il_param_list_c *symbol);
|
|
1200 |
|
|
1201 |
/* il_assign_operator il_operand
|
|
1202 |
* | il_assign_operator '(' eol_list simple_instr_list ')'
|
|
1203 |
*/
|
|
1204 |
SYM_REF3(il_param_assignment_c, il_assign_operator, il_operand, simple_instr_list)
|
|
1205 |
void *visit_expression_type_c::visit(il_param_assignment_c *symbol);
|
|
1206 |
/* il_assign_out_operator variable */
|
|
1207 |
SYM_REF2(il_param_out_assignment_c, il_assign_out_operator, variable)
|
|
1208 |
void *visit_expression_type_c::visit(il_param_out_assignment_c *symbol);
|
|
1209 |
|
|
1210 |
#endif
|
|
1211 |
|
|
1212 |
|
|
1213 |
/*******************/
|
|
1214 |
/* B 2.2 Operators */
|
|
1215 |
/*******************/
|
|
1216 |
|
|
1217 |
//SYM_REF0(LD_operator_c)
|
|
1218 |
void *visit_expression_type_c::visit(LD_operator_c *symbol) {
|
|
1219 |
if (0 == il_parenthesis_level)
|
|
1220 |
il_error = false;
|
|
1221 |
|
|
1222 |
if(il_operand_type == NULL)
|
|
1223 |
STAGE3_ERROR(symbol, symbol, "LD operator requires an operand.");
|
|
1224 |
il_default_variable_type = il_operand_type;
|
|
1225 |
return NULL;
|
|
1226 |
}
|
|
1227 |
|
|
1228 |
// SYM_REF0(LDN_operator_c)
|
|
1229 |
void *visit_expression_type_c::visit(LDN_operator_c *symbol) {
|
|
1230 |
if(il_operand_type == NULL)
|
|
1231 |
STAGE3_ERROR(symbol, symbol, "LDN operator requires an operand.");
|
257
|
1232 |
if(!is_ANY_BIT_compatible(il_operand_type))
|
204
|
1233 |
STAGE3_ERROR(symbol, symbol, "invalid data type of LDN operand, should be of type ANY_BIT.");
|
|
1234 |
il_default_variable_type = il_operand_type;
|
|
1235 |
return NULL;
|
|
1236 |
}
|
|
1237 |
|
|
1238 |
// SYM_REF0(ST_operator_c)
|
|
1239 |
void *visit_expression_type_c::visit(ST_operator_c *symbol) {
|
|
1240 |
verify_null(symbol);
|
257
|
1241 |
|
|
1242 |
if(!is_valid_assignment(il_operand_type, il_default_variable_type))
|
204
|
1243 |
STAGE3_ERROR(symbol, symbol, "Type mismatch in ST operation.");
|
|
1244 |
/* TODO: check whether il_operand_type is an LVALUE !! */
|
|
1245 |
/* data type of il_default_variable_type is unchanged... */
|
|
1246 |
// il_default_variable_type = il_default_variable_type;
|
|
1247 |
return NULL;
|
|
1248 |
}
|
|
1249 |
|
|
1250 |
// SYM_REF0(STN_operator_c)
|
|
1251 |
void *visit_expression_type_c::visit(STN_operator_c *symbol) {
|
|
1252 |
verify_null(symbol);
|
257
|
1253 |
if(!is_valid_assignment(il_operand_type, il_default_variable_type))
|
204
|
1254 |
STAGE3_ERROR(symbol, symbol, "Type mismatch in ST operation.");
|
|
1255 |
/* TODO: check whether il_operand_type is an LVALUE !! */
|
257
|
1256 |
if(!is_ANY_BIT_compatible(il_default_variable_type))
|
204
|
1257 |
STAGE3_ERROR(symbol, symbol, "invalid data type of il_default_variable for STN operand, should be of type ANY_BIT.");
|
257
|
1258 |
if(!is_ANY_BIT_compatible(il_operand_type))
|
204
|
1259 |
STAGE3_ERROR(symbol, symbol, "invalid data type of STN operand, should be of type ANY_BIT.");
|
|
1260 |
/* data type of il_default_variable_type is unchanged... */
|
|
1261 |
// il_default_variable_type = il_default_variable_type;
|
|
1262 |
return NULL;
|
|
1263 |
}
|
|
1264 |
|
|
1265 |
//SYM_REF0(NOT_operator_c)
|
|
1266 |
void *visit_expression_type_c::visit(NOT_operator_c *symbol) {
|
|
1267 |
if(il_operand_type != NULL){
|
|
1268 |
STAGE3_ERROR(symbol, symbol, "NOT operator may not have an operand.");
|
|
1269 |
return NULL;
|
|
1270 |
}
|
|
1271 |
if(il_default_variable_type == NULL) {
|
|
1272 |
STAGE3_ERROR(symbol, symbol, "Il default variable should not be NULL.");
|
|
1273 |
return NULL;
|
|
1274 |
}
|
257
|
1275 |
if(!is_ANY_BIT_compatible(il_default_variable_type)) {
|
204
|
1276 |
STAGE3_ERROR(symbol, symbol, "Il default variable should be of type ANY_BIT.");
|
|
1277 |
return NULL;
|
|
1278 |
}
|
|
1279 |
/* data type of il_default_variable_type is unchanged... */
|
|
1280 |
// il_default_variable_type = il_default_variable_type;
|
|
1281 |
return NULL;
|
|
1282 |
}
|
|
1283 |
|
|
1284 |
// SYM_REF0(S_operator_c)
|
|
1285 |
void *visit_expression_type_c::visit(S_operator_c *symbol) {
|
|
1286 |
verify_null(symbol);
|
|
1287 |
if (!is_BOOL_type(il_default_variable_type)) {STAGE3_ERROR(symbol, symbol, "IL default variable should be BOOL type.");}
|
|
1288 |
if (!is_BOOL_type(il_operand_type)) {STAGE3_ERROR(symbol, symbol, "operator S requires operand of type BOOL.");}
|
|
1289 |
/* TODO: check whether il_operand_type is an LVALUE !! */
|
|
1290 |
/* data type of il_default_variable_type is unchanged... */
|
|
1291 |
// il_default_variable_type = il_default_variable_type;
|
|
1292 |
return NULL;
|
|
1293 |
}
|
|
1294 |
|
|
1295 |
// SYM_REF0(R_operator_c)
|
|
1296 |
void *visit_expression_type_c::visit(R_operator_c *symbol) {
|
|
1297 |
verify_null(symbol);
|
|
1298 |
if (!is_BOOL_type(il_default_variable_type)) {STAGE3_ERROR(symbol, symbol, "IL default variable should be BOOL type.");}
|
|
1299 |
if (!is_BOOL_type(il_operand_type)) {STAGE3_ERROR(symbol, symbol, "operator R requires operand of type BOOL.");}
|
|
1300 |
/* TODO: check whether il_operand_type is an LVALUE !! */
|
|
1301 |
/* data type of il_default_variable_type is unchanged... */
|
|
1302 |
// il_default_variable_type = il_default_variable_type;
|
|
1303 |
return NULL;
|
|
1304 |
}
|
|
1305 |
|
|
1306 |
|
|
1307 |
// SYM_REF0(S1_operator_c)
|
|
1308 |
void *visit_expression_type_c::visit(S1_operator_c *symbol){
|
|
1309 |
compute_input_operatores(symbol, "S1");
|
|
1310 |
return NULL;
|
|
1311 |
}
|
|
1312 |
|
|
1313 |
// SYM_REF0(R1_operator_c)
|
|
1314 |
void *visit_expression_type_c::visit(R1_operator_c *symbol) {
|
|
1315 |
compute_input_operatores(symbol, "R1");
|
|
1316 |
return NULL;
|
|
1317 |
}
|
|
1318 |
|
|
1319 |
// SYM_REF0(CLK_operator_c)
|
|
1320 |
void *visit_expression_type_c::visit(CLK_operator_c *symbol) {
|
|
1321 |
compute_input_operatores(symbol, "CLK");
|
|
1322 |
return NULL;
|
|
1323 |
}
|
|
1324 |
|
|
1325 |
// SYM_REF0(CU_operator_c)
|
|
1326 |
void *visit_expression_type_c::visit(CU_operator_c *symbol) {
|
|
1327 |
compute_input_operatores(symbol, "CU");
|
|
1328 |
return NULL;
|
|
1329 |
}
|
|
1330 |
|
|
1331 |
// SYM_REF0(CD_operator_c)
|
|
1332 |
void *visit_expression_type_c::visit(CD_operator_c *symbol) {
|
|
1333 |
compute_input_operatores(symbol, "CD");
|
|
1334 |
return NULL;
|
|
1335 |
}
|
|
1336 |
|
|
1337 |
// SYM_REF0(PV_operator_c)
|
|
1338 |
void *visit_expression_type_c::visit(PV_operator_c *symbol) {
|
|
1339 |
compute_input_operatores(symbol, "PV");
|
|
1340 |
return NULL;
|
|
1341 |
}
|
|
1342 |
|
|
1343 |
// SYM_REF0(IN_operator_c)
|
|
1344 |
void *visit_expression_type_c::visit(IN_operator_c *symbol) {
|
|
1345 |
compute_input_operatores(symbol, "IN");
|
|
1346 |
return NULL;
|
|
1347 |
}
|
|
1348 |
|
|
1349 |
// SYM_REF0(PT_operator_c)
|
|
1350 |
void *visit_expression_type_c::visit(PT_operator_c *symbol) {
|
|
1351 |
compute_input_operatores(symbol, "PT");
|
|
1352 |
return NULL;
|
|
1353 |
}
|
|
1354 |
|
|
1355 |
//SYM_REF0(AND_operator_c)
|
|
1356 |
void *visit_expression_type_c::visit(AND_operator_c *symbol) {
|
|
1357 |
verify_null(symbol);
|
257
|
1358 |
il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_BIT_compatible);
|
204
|
1359 |
return NULL;
|
|
1360 |
}
|
|
1361 |
|
|
1362 |
//SYM_REF0(OR_operator_c)
|
|
1363 |
void *visit_expression_type_c::visit(OR_operator_c *symbol) {
|
|
1364 |
verify_null(symbol);
|
257
|
1365 |
il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_BIT_compatible);
|
204
|
1366 |
return NULL;
|
|
1367 |
}
|
|
1368 |
|
|
1369 |
//SYM_REF0(XOR_operator_c)
|
|
1370 |
void *visit_expression_type_c::visit(XOR_operator_c *symbol) {
|
|
1371 |
verify_null(symbol);
|
257
|
1372 |
il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_BIT_compatible);
|
204
|
1373 |
return NULL;
|
|
1374 |
}
|
|
1375 |
|
|
1376 |
// SYM_REF0(ANDN_operator_c)
|
|
1377 |
void *visit_expression_type_c::visit(ANDN_operator_c *symbol) {
|
|
1378 |
verify_null(symbol);
|
257
|
1379 |
il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_BIT_compatible);
|
204
|
1380 |
return NULL;
|
|
1381 |
}
|
|
1382 |
|
|
1383 |
// SYM_REF0(ORN_operator_c)
|
|
1384 |
void *visit_expression_type_c::visit(ORN_operator_c *symbol) {
|
|
1385 |
verify_null(symbol);
|
257
|
1386 |
il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_BIT_compatible);
|
204
|
1387 |
return NULL;
|
|
1388 |
}
|
|
1389 |
|
|
1390 |
// SYM_REF0(XORN_operator_c)
|
|
1391 |
void *visit_expression_type_c::visit(XORN_operator_c *symbol) {
|
|
1392 |
verify_null(symbol);
|
257
|
1393 |
il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_BIT_compatible);
|
204
|
1394 |
return NULL;
|
|
1395 |
}
|
|
1396 |
|
|
1397 |
// SYM_REF0(ADD_operator_c)
|
|
1398 |
void *visit_expression_type_c::visit(ADD_operator_c *symbol) {
|
|
1399 |
verify_null(symbol);
|
|
1400 |
symbol_c *left_type = il_default_variable_type;
|
|
1401 |
symbol_c *right_type = il_operand_type;
|
257
|
1402 |
|
|
1403 |
/* The following is not required, it is already handled by compute_expression() ... */
|
|
1404 |
/*
|
|
1405 |
if (is_type(left_type, time_type_name_c) && is_type(right_type, time_type_name_c))
|
204
|
1406 |
il_default_variable_type = &time_type_name;
|
257
|
1407 |
*/
|
|
1408 |
|
|
1409 |
if (is_type(left_type, tod_type_name_c) && is_type(right_type, time_type_name_c))
|
204
|
1410 |
il_default_variable_type = &tod_type_name;
|
257
|
1411 |
else if (is_type(left_type, safetod_type_name_c) && is_type(right_type, time_type_name_c))
|
|
1412 |
il_default_variable_type = &tod_type_name;
|
|
1413 |
else if (is_type(left_type, tod_type_name_c) && is_type(right_type, safetime_type_name_c))
|
|
1414 |
il_default_variable_type = &tod_type_name;
|
|
1415 |
else if (is_type(left_type, safetod_type_name_c) && is_type(right_type, safetime_type_name_c))
|
|
1416 |
il_default_variable_type = &safetod_type_name;
|
|
1417 |
|
|
1418 |
else if (is_type(left_type, dt_type_name_c) && is_type(right_type, time_type_name_c))
|
204
|
1419 |
il_default_variable_type = &dt_type_name;
|
257
|
1420 |
else if (is_type(left_type, safedt_type_name_c) && is_type(right_type, time_type_name_c))
|
|
1421 |
il_default_variable_type = &dt_type_name;
|
|
1422 |
else if (is_type(left_type, dt_type_name_c) && is_type(right_type, safetime_type_name_c))
|
|
1423 |
il_default_variable_type = &dt_type_name;
|
|
1424 |
else if (is_type(left_type, safedt_type_name_c) && is_type(right_type, safetime_type_name_c))
|
|
1425 |
il_default_variable_type = &safedt_type_name;
|
|
1426 |
|
|
1427 |
else il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_MAGNITUDE_compatible);
|
204
|
1428 |
return NULL;
|
|
1429 |
}
|
|
1430 |
|
|
1431 |
// SYM_REF0(SUB_operator_c)
|
|
1432 |
void *visit_expression_type_c::visit(SUB_operator_c *symbol) {
|
|
1433 |
verify_null(symbol);
|
|
1434 |
symbol_c *left_type = il_default_variable_type;
|
|
1435 |
symbol_c *right_type = il_operand_type;;
|
257
|
1436 |
|
|
1437 |
/* The following is not required, it is already handled by compute_expression() ... */
|
|
1438 |
/*
|
204
|
1439 |
if (typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c))
|
|
1440 |
il_default_variable_type = &time_type_name;
|
257
|
1441 |
*/
|
|
1442 |
|
|
1443 |
if (is_type(left_type, tod_type_name_c) && is_type(right_type, time_type_name_c))
|
|
1444 |
il_default_variable_type = &tod_type_name;
|
|
1445 |
else if (is_type(left_type, safetod_type_name_c) && is_type(right_type, time_type_name_c))
|
|
1446 |
il_default_variable_type = &tod_type_name;
|
|
1447 |
else if (is_type(left_type, tod_type_name_c) && is_type(right_type, safetime_type_name_c))
|
|
1448 |
il_default_variable_type = &tod_type_name;
|
|
1449 |
else if (is_type(left_type, safetod_type_name_c) && is_type(right_type, safetime_type_name_c))
|
|
1450 |
il_default_variable_type = &safetod_type_name;
|
|
1451 |
|
|
1452 |
else if (is_type(left_type, dt_type_name_c) && is_type(right_type, time_type_name_c))
|
|
1453 |
il_default_variable_type = &dt_type_name;
|
|
1454 |
else if (is_type(left_type, safedt_type_name_c) && is_type(right_type, time_type_name_c))
|
|
1455 |
il_default_variable_type = &dt_type_name;
|
|
1456 |
else if (is_type(left_type, dt_type_name_c) && is_type(right_type, safetime_type_name_c))
|
|
1457 |
il_default_variable_type = &dt_type_name;
|
|
1458 |
else if (is_type(left_type, safedt_type_name_c) && is_type(right_type, safetime_type_name_c))
|
|
1459 |
il_default_variable_type = &safedt_type_name;
|
|
1460 |
|
|
1461 |
else if (is_type(left_type, date_type_name_c) && is_type(right_type, date_type_name_c))
|
204
|
1462 |
il_default_variable_type = &time_type_name;
|
257
|
1463 |
else if (is_type(left_type, safedate_type_name_c) && is_type(right_type, date_type_name_c))
|
204
|
1464 |
il_default_variable_type = &time_type_name;
|
257
|
1465 |
else if (is_type(left_type, date_type_name_c) && is_type(right_type, safedate_type_name_c))
|
204
|
1466 |
il_default_variable_type = &time_type_name;
|
257
|
1467 |
else if (is_type(left_type, safedate_type_name_c) && is_type(right_type, safedate_type_name_c))
|
|
1468 |
il_default_variable_type = &safetime_type_name;
|
|
1469 |
|
|
1470 |
else if (is_type(left_type, tod_type_name_c) && is_type(right_type, tod_type_name_c))
|
|
1471 |
il_default_variable_type = &time_type_name;
|
|
1472 |
else if (is_type(left_type, safetod_type_name_c) && is_type(right_type, tod_type_name_c))
|
|
1473 |
il_default_variable_type = &time_type_name;
|
|
1474 |
else if (is_type(left_type, tod_type_name_c) && is_type(right_type, safetod_type_name_c))
|
|
1475 |
il_default_variable_type = &time_type_name;
|
|
1476 |
else if (is_type(left_type, safetod_type_name_c) && is_type(right_type, safetod_type_name_c))
|
|
1477 |
il_default_variable_type = &safetime_type_name;
|
|
1478 |
|
|
1479 |
else if (is_type(left_type, dt_type_name_c) && is_type(right_type, dt_type_name_c))
|
|
1480 |
il_default_variable_type = &time_type_name;
|
|
1481 |
else if (is_type(left_type, safedt_type_name_c) && is_type(right_type, dt_type_name_c))
|
|
1482 |
il_default_variable_type = &time_type_name;
|
|
1483 |
else if (is_type(left_type, dt_type_name_c) && is_type(right_type, safedt_type_name_c))
|
|
1484 |
il_default_variable_type = &time_type_name;
|
|
1485 |
else if (is_type(left_type, safedt_type_name_c) && is_type(right_type, safedt_type_name_c))
|
|
1486 |
il_default_variable_type = &safetime_type_name;
|
|
1487 |
|
|
1488 |
else il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_MAGNITUDE_compatible);
|
204
|
1489 |
return NULL;
|
|
1490 |
}
|
|
1491 |
|
|
1492 |
// SYM_REF0(MUL_operator_c)
|
|
1493 |
void *visit_expression_type_c::visit(MUL_operator_c *symbol) {
|
|
1494 |
verify_null(symbol);
|
|
1495 |
symbol_c *left_type = il_default_variable_type;
|
|
1496 |
symbol_c *right_type = il_operand_type;
|
257
|
1497 |
|
|
1498 |
if (is_type(left_type, time_type_name_c) && is_ANY_NUM_compatible(right_type))
|
204
|
1499 |
il_default_variable_type = &time_type_name;
|
257
|
1500 |
else if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_type(right_type))
|
|
1501 |
il_default_variable_type = &time_type_name;
|
|
1502 |
else if (is_type(left_type, safetime_type_name_c) && is_ANY_SAFENUM_type(right_type))
|
|
1503 |
il_default_variable_type = &safetime_type_name;
|
|
1504 |
/* Since we have already checked for ANY_NUM_type and ANY_SAFENUM_type in the previous lines,
|
|
1505 |
* this next line is really only to check for integers/reals of undefined type on 'right_type'...
|
|
1506 |
*/
|
|
1507 |
else if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_compatible(right_type))
|
|
1508 |
il_default_variable_type = &safetime_type_name;
|
|
1509 |
|
|
1510 |
else il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_NUM_compatible);
|
204
|
1511 |
return NULL;
|
|
1512 |
}
|
|
1513 |
|
|
1514 |
// SYM_REF0(DIV_operator_c)
|
|
1515 |
void *visit_expression_type_c::visit(DIV_operator_c *symbol) {
|
|
1516 |
verify_null(symbol);
|
|
1517 |
symbol_c *left_type = il_default_variable_type;
|
|
1518 |
symbol_c *right_type = il_operand_type;
|
257
|
1519 |
|
|
1520 |
if (is_type(left_type, time_type_name_c) && is_ANY_NUM_compatible(right_type))
|
204
|
1521 |
il_default_variable_type = &time_type_name;
|
257
|
1522 |
else if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_type(right_type))
|
|
1523 |
il_default_variable_type = &time_type_name;
|
|
1524 |
else if (is_type(left_type, safetime_type_name_c) && is_ANY_SAFENUM_type(right_type))
|
|
1525 |
il_default_variable_type = &safetime_type_name;
|
|
1526 |
/* Since we have already checked for ANY_NUM_type and ANY_SAFENUM_type in the previous lines,
|
|
1527 |
* this next line is really only to check for integers/reals of undefined type on 'right_type'...
|
|
1528 |
*/
|
|
1529 |
else if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_compatible(right_type))
|
|
1530 |
il_default_variable_type = &safetime_type_name;
|
|
1531 |
|
|
1532 |
else il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_NUM_compatible);
|
204
|
1533 |
return NULL;
|
|
1534 |
}
|
|
1535 |
|
|
1536 |
// SYM_REF0(MOD_operator_c)
|
|
1537 |
void *visit_expression_type_c::visit(MOD_operator_c *symbol) {
|
|
1538 |
verify_null(symbol);
|
257
|
1539 |
il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_INT_compatible);
|
204
|
1540 |
return NULL;
|
|
1541 |
}
|
|
1542 |
|
|
1543 |
// SYM_REF0(GT_operator_c)
|
|
1544 |
void *visit_expression_type_c::visit(GT_operator_c *symbol) {
|
|
1545 |
verify_null(symbol);
|
257
|
1546 |
compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
|
204
|
1547 |
il_default_variable_type = &search_expression_type_c::bool_type_name;
|
|
1548 |
return NULL;
|
|
1549 |
}
|
|
1550 |
|
|
1551 |
//SYM_REF0(GE_operator_c)
|
|
1552 |
void *visit_expression_type_c::visit(GE_operator_c *symbol) {
|
|
1553 |
verify_null(symbol);
|
257
|
1554 |
compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
|
204
|
1555 |
il_default_variable_type = &search_expression_type_c::bool_type_name;
|
|
1556 |
return NULL;
|
|
1557 |
}
|
|
1558 |
|
|
1559 |
//SYM_REF0(EQ_operator_c)
|
|
1560 |
void *visit_expression_type_c::visit(EQ_operator_c *symbol) {
|
|
1561 |
verify_null(symbol);
|
257
|
1562 |
compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
|
204
|
1563 |
il_default_variable_type = &search_expression_type_c::bool_type_name;
|
|
1564 |
return NULL;
|
|
1565 |
}
|
|
1566 |
|
|
1567 |
//SYM_REF0(LT_operator_c)
|
|
1568 |
void *visit_expression_type_c::visit(LT_operator_c *symbol) {
|
|
1569 |
verify_null(symbol);
|
257
|
1570 |
compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
|
204
|
1571 |
il_default_variable_type = &search_expression_type_c::bool_type_name;
|
|
1572 |
return NULL;
|
|
1573 |
}
|
|
1574 |
|
|
1575 |
//SYM_REF0(LE_operator_c)
|
|
1576 |
void *visit_expression_type_c::visit(LE_operator_c *symbol) {
|
|
1577 |
verify_null(symbol);
|
257
|
1578 |
compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
|
204
|
1579 |
il_default_variable_type = &search_expression_type_c::bool_type_name;
|
|
1580 |
return NULL;
|
|
1581 |
}
|
|
1582 |
|
|
1583 |
//SYM_REF0(NE_operator_c)
|
|
1584 |
void *visit_expression_type_c::visit(NE_operator_c *symbol) {
|
|
1585 |
verify_null(symbol);
|
257
|
1586 |
compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
|
204
|
1587 |
il_default_variable_type = &search_expression_type_c::bool_type_name;
|
|
1588 |
return NULL;
|
|
1589 |
}
|
|
1590 |
|
|
1591 |
// SYM_REF0(CAL_operator_c)
|
|
1592 |
void *visit_expression_type_c::visit(CAL_operator_c *symbol) {
|
|
1593 |
return NULL;
|
|
1594 |
}
|
|
1595 |
|
|
1596 |
// SYM_REF0(CALC_operator_c)
|
|
1597 |
void *visit_expression_type_c::visit(CALC_operator_c *symbol) {
|
|
1598 |
if(il_default_variable_type == NULL)
|
|
1599 |
STAGE3_ERROR(symbol, symbol, "CALC: il default variable should not be NULL.");
|
|
1600 |
if (!is_BOOL_type(il_default_variable_type))
|
|
1601 |
STAGE3_ERROR(symbol, symbol, "CALC operator requires il_default_variable to be of type BOOL.");
|
|
1602 |
return NULL;
|
|
1603 |
}
|
|
1604 |
|
|
1605 |
// SYM_REF0(CALCN_operator_c)
|
|
1606 |
void *visit_expression_type_c::visit(CALCN_operator_c *symbol) {
|
|
1607 |
if(il_default_variable_type == NULL)
|
|
1608 |
STAGE3_ERROR(symbol, symbol, "CALCN: il_default_variable should not be NULL.");
|
|
1609 |
if (!is_BOOL_type(il_default_variable_type))
|
|
1610 |
STAGE3_ERROR(symbol, symbol, "CALCN operator requires il_default_variable to be of type BOOL.");
|
|
1611 |
return NULL;
|
|
1612 |
}
|
|
1613 |
|
|
1614 |
// SYM_REF0(RET_operator_c)
|
|
1615 |
void *visit_expression_type_c::visit(RET_operator_c *symbol) {
|
|
1616 |
return NULL;
|
|
1617 |
}
|
|
1618 |
|
|
1619 |
// SYM_REF0(RETC_operator_c)
|
|
1620 |
void *visit_expression_type_c::visit(RETC_operator_c *symbol) {
|
|
1621 |
if(il_default_variable_type == NULL)
|
|
1622 |
STAGE3_ERROR(symbol, symbol, "RETC: il default variable should not be NULL.");
|
|
1623 |
if (!is_BOOL_type(il_default_variable_type))
|
|
1624 |
STAGE3_ERROR(symbol, symbol, "RETC operator requires il_default_variable to be of type BOOL.");
|
|
1625 |
return NULL;
|
|
1626 |
}
|
|
1627 |
|
|
1628 |
// SYM_REF0(RETCN_operator_c)
|
|
1629 |
void *visit_expression_type_c::visit(RETCN_operator_c *symbol) {
|
|
1630 |
if(il_default_variable_type == NULL)
|
|
1631 |
STAGE3_ERROR(symbol, symbol, "RETCN: il_default_variable should not be NULL.");
|
|
1632 |
if (!is_BOOL_type(il_default_variable_type))
|
|
1633 |
STAGE3_ERROR(symbol, symbol, "RETCN operator requires il_default_variable to be of type BOOL.");
|
|
1634 |
return NULL;
|
|
1635 |
}
|
|
1636 |
|
|
1637 |
// SYM_REF0(JMP_operator_c)
|
|
1638 |
void *visit_expression_type_c::visit(JMP_operator_c *symbol){
|
|
1639 |
return NULL;
|
|
1640 |
}
|
|
1641 |
|
|
1642 |
// SYM_REF0(JMPC_operator_c)
|
|
1643 |
void *visit_expression_type_c::visit(JMPC_operator_c *symbol) {
|
|
1644 |
if(il_default_variable_type == NULL)
|
|
1645 |
STAGE3_ERROR(symbol, symbol, "JMPC: il default variable should not be NULL.");
|
|
1646 |
if (!is_BOOL_type(il_default_variable_type))
|
|
1647 |
STAGE3_ERROR(symbol, symbol, "JMPC operator requires il_default_variable to be of type BOOL.");
|
|
1648 |
return NULL;
|
|
1649 |
}
|
|
1650 |
|
|
1651 |
// SYM_REF0(JMPCN_operator_c)
|
|
1652 |
void *visit_expression_type_c::visit(JMPCN_operator_c *symbol) {
|
|
1653 |
if(il_default_variable_type == NULL)
|
|
1654 |
STAGE3_ERROR(symbol, symbol, "JMPCN: il_default_variable should not be NULL.");
|
|
1655 |
if (!is_BOOL_type(il_default_variable_type))
|
|
1656 |
STAGE3_ERROR(symbol, symbol, "JMPCN operator requires il_default_variable to be of type BOOL.");
|
|
1657 |
return NULL;
|
|
1658 |
}
|
|
1659 |
|
|
1660 |
/* Symbol class handled together with function call checks */
|
|
1661 |
/* any_identifier ASSIGN */
|
|
1662 |
// SYM_REF1(il_assign_operator_c, variable_name)
|
|
1663 |
// void *visit_expression_type_c::visit(il_assign_operator_c *symbol, variable_name);
|
|
1664 |
|
|
1665 |
/* Symbol class handled together with function call checks */
|
|
1666 |
/*| [NOT] any_identifier SENDTO */
|
|
1667 |
// SYM_REF2(il_assign_out_operator_c, option, variable_name)
|
|
1668 |
// void *visit_expression_type_c::visit(il_assign_operator_c *symbol, option, variable_name);
|
|
1669 |
|
|
1670 |
|
|
1671 |
|
|
1672 |
|
|
1673 |
|
|
1674 |
/***************************************/
|
|
1675 |
/* B.3 - Language ST (Structured Text) */
|
|
1676 |
/***************************************/
|
|
1677 |
/***********************/
|
|
1678 |
/* B 3.1 - Expressions */
|
|
1679 |
/***********************/
|
|
1680 |
|
|
1681 |
void *visit_expression_type_c::visit(or_expression_c *symbol) {
|
|
1682 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1683 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
257
|
1684 |
return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_BIT_compatible);
|
204
|
1685 |
}
|
|
1686 |
|
|
1687 |
|
|
1688 |
void *visit_expression_type_c::visit(xor_expression_c *symbol) {
|
|
1689 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1690 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
257
|
1691 |
return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_BIT_compatible);
|
204
|
1692 |
}
|
|
1693 |
|
|
1694 |
|
|
1695 |
void *visit_expression_type_c::visit(and_expression_c *symbol) {
|
|
1696 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1697 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
257
|
1698 |
return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_BIT_compatible);
|
204
|
1699 |
}
|
|
1700 |
|
|
1701 |
|
|
1702 |
void *visit_expression_type_c::visit(equ_expression_c *symbol) {
|
|
1703 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1704 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
257
|
1705 |
compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
|
204
|
1706 |
return &search_expression_type_c::bool_type_name;
|
|
1707 |
}
|
|
1708 |
|
|
1709 |
|
|
1710 |
void *visit_expression_type_c::visit(notequ_expression_c *symbol) {
|
|
1711 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1712 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
257
|
1713 |
compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
|
204
|
1714 |
return &search_expression_type_c::bool_type_name;
|
|
1715 |
}
|
|
1716 |
|
|
1717 |
|
|
1718 |
void *visit_expression_type_c::visit(lt_expression_c *symbol) {
|
|
1719 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1720 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
257
|
1721 |
compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
|
204
|
1722 |
return &search_expression_type_c::bool_type_name;
|
|
1723 |
}
|
|
1724 |
|
|
1725 |
|
|
1726 |
void *visit_expression_type_c::visit(gt_expression_c *symbol) {
|
|
1727 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1728 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
257
|
1729 |
compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
|
204
|
1730 |
return &search_expression_type_c::bool_type_name;
|
|
1731 |
}
|
|
1732 |
|
|
1733 |
|
|
1734 |
void *visit_expression_type_c::visit(le_expression_c *symbol) {
|
|
1735 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1736 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
257
|
1737 |
compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
|
204
|
1738 |
return &search_expression_type_c::bool_type_name;
|
|
1739 |
}
|
|
1740 |
|
|
1741 |
|
|
1742 |
void *visit_expression_type_c::visit(ge_expression_c *symbol) {
|
|
1743 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1744 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
257
|
1745 |
compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
|
204
|
1746 |
return &search_expression_type_c::bool_type_name;
|
|
1747 |
}
|
|
1748 |
|
|
1749 |
|
|
1750 |
void *visit_expression_type_c::visit(add_expression_c *symbol) {
|
|
1751 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1752 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
257
|
1753 |
|
|
1754 |
/* The following is already checked in compute_expression */
|
|
1755 |
/*
|
|
1756 |
if (is_type(left_type, time_type_name_c) && is_type(right_type, time_type_name_c))
|
|
1757 |
return (void *)&time_type_name;
|
|
1758 |
*/
|
|
1759 |
|
|
1760 |
if (is_type(left_type, tod_type_name_c) && is_type(right_type, time_type_name_c))
|
|
1761 |
return (void *)&tod_type_name;
|
|
1762 |
if (is_type(left_type, safetod_type_name_c) && is_type(right_type, time_type_name_c))
|
|
1763 |
return (void *)&tod_type_name;
|
|
1764 |
if (is_type(left_type, tod_type_name_c) && is_type(right_type, safetime_type_name_c))
|
|
1765 |
return (void *)&tod_type_name;
|
|
1766 |
if (is_type(left_type, safetod_type_name_c) && is_type(right_type, safetime_type_name_c))
|
|
1767 |
return (void *)&safetod_type_name;
|
|
1768 |
|
|
1769 |
if (is_type(left_type, dt_type_name_c) && is_type(right_type, time_type_name_c))
|
|
1770 |
return (void *)&dt_type_name;
|
|
1771 |
if (is_type(left_type, safedt_type_name_c) && is_type(right_type, time_type_name_c))
|
|
1772 |
return (void *)&dt_type_name;
|
|
1773 |
if (is_type(left_type, dt_type_name_c) && is_type(right_type, safetime_type_name_c))
|
|
1774 |
return (void *)&dt_type_name;
|
|
1775 |
if (is_type(left_type, safedt_type_name_c) && is_type(right_type, safetime_type_name_c))
|
|
1776 |
return (void *)&safedt_type_name;
|
|
1777 |
|
|
1778 |
return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_MAGNITUDE_compatible);
|
204
|
1779 |
}
|
|
1780 |
|
|
1781 |
|
|
1782 |
void *visit_expression_type_c::visit(sub_expression_c *symbol) {
|
|
1783 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1784 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
257
|
1785 |
|
|
1786 |
/* The following is already checked in compute_expression */
|
|
1787 |
/*
|
|
1788 |
if (is_type(left_type, time_type_name_c) && is_type(right_type, time_type_name_c))
|
|
1789 |
return (void *)&time_type_name;
|
|
1790 |
*/
|
|
1791 |
|
|
1792 |
if (is_type(left_type, tod_type_name_c) && is_type(right_type, time_type_name_c))
|
|
1793 |
return (void *)&tod_type_name;
|
|
1794 |
if (is_type(left_type, safetod_type_name_c) && is_type(right_type, time_type_name_c))
|
|
1795 |
return (void *)&tod_type_name;
|
|
1796 |
if (is_type(left_type, tod_type_name_c) && is_type(right_type, safetime_type_name_c))
|
|
1797 |
return (void *)&tod_type_name;
|
|
1798 |
if (is_type(left_type, safetod_type_name_c) && is_type(right_type, safetime_type_name_c))
|
|
1799 |
return (void *)&safetod_type_name;
|
|
1800 |
|
|
1801 |
if (is_type(left_type, dt_type_name_c) && is_type(right_type, time_type_name_c))
|
|
1802 |
return (void *)&dt_type_name;
|
|
1803 |
if (is_type(left_type, safedt_type_name_c) && is_type(right_type, time_type_name_c))
|
|
1804 |
return (void *)&dt_type_name;
|
|
1805 |
if (is_type(left_type, dt_type_name_c) && is_type(right_type, safetime_type_name_c))
|
|
1806 |
return (void *)&dt_type_name;
|
|
1807 |
if (is_type(left_type, safedt_type_name_c) && is_type(right_type, safetime_type_name_c))
|
|
1808 |
return (void *)&safedt_type_name;
|
|
1809 |
|
|
1810 |
if (is_type(left_type, tod_type_name_c) && is_type(right_type, tod_type_name_c))
|
|
1811 |
return (void *)&time_type_name;
|
|
1812 |
if (is_type(left_type, safetod_type_name_c) && is_type(right_type, tod_type_name_c))
|
|
1813 |
return (void *)&time_type_name;
|
|
1814 |
if (is_type(left_type, tod_type_name_c) && is_type(right_type, safetod_type_name_c))
|
|
1815 |
return (void *)&time_type_name;
|
|
1816 |
if (is_type(left_type, safetod_type_name_c) && is_type(right_type, safetod_type_name_c))
|
|
1817 |
return (void *)&safetime_type_name;
|
|
1818 |
|
|
1819 |
if (is_type(left_type, date_type_name_c) && is_type(right_type, date_type_name_c))
|
|
1820 |
return (void *)&time_type_name;
|
|
1821 |
if (is_type(left_type, safedate_type_name_c) && is_type(right_type, date_type_name_c))
|
|
1822 |
return (void *)&time_type_name;
|
|
1823 |
if (is_type(left_type, date_type_name_c) && is_type(right_type, safedate_type_name_c))
|
|
1824 |
return (void *)&time_type_name;
|
|
1825 |
if (is_type(left_type, safedate_type_name_c) && is_type(right_type, safedate_type_name_c))
|
|
1826 |
return (void *)&safetime_type_name;
|
|
1827 |
|
|
1828 |
if (is_type(left_type, dt_type_name_c) && is_type(right_type, dt_type_name_c))
|
|
1829 |
return (void *)&time_type_name;
|
|
1830 |
if (is_type(left_type, safedt_type_name_c) && is_type(right_type, dt_type_name_c))
|
|
1831 |
return (void *)&time_type_name;
|
|
1832 |
if (is_type(left_type, dt_type_name_c) && is_type(right_type, safedt_type_name_c))
|
|
1833 |
return (void *)&time_type_name;
|
|
1834 |
if (is_type(left_type, safedt_type_name_c) && is_type(right_type, safedt_type_name_c))
|
|
1835 |
return (void *)&safetime_type_name;
|
|
1836 |
|
|
1837 |
return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_MAGNITUDE_compatible);
|
204
|
1838 |
}
|
|
1839 |
|
|
1840 |
|
|
1841 |
void *visit_expression_type_c::visit(mul_expression_c *symbol) {
|
|
1842 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1843 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
257
|
1844 |
|
|
1845 |
if (is_type(left_type, time_type_name_c) && is_ANY_NUM_compatible(right_type))
|
|
1846 |
return (void *)&time_type_name;
|
|
1847 |
if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_type(right_type))
|
|
1848 |
return (void *)&time_type_name;
|
|
1849 |
if (is_type(left_type, safetime_type_name_c) && is_ANY_SAFENUM_type(right_type))
|
|
1850 |
return (void *)&safetime_type_name;
|
|
1851 |
/* Since we have already checked for ANY_NUM_type and ANY_SAFENUM_type in the previous lines,
|
|
1852 |
* this next line is really only to check for integers/reals of undefined type on 'right_type'...
|
|
1853 |
*/
|
|
1854 |
if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_compatible(right_type))
|
|
1855 |
return (void *)&safetime_type_name;
|
|
1856 |
|
|
1857 |
return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_NUM_compatible);
|
204
|
1858 |
}
|
|
1859 |
|
|
1860 |
|
|
1861 |
void *visit_expression_type_c::visit(div_expression_c *symbol) {
|
|
1862 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1863 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
257
|
1864 |
|
|
1865 |
if (is_type(left_type, time_type_name_c) && is_ANY_NUM_compatible(right_type))
|
|
1866 |
return (void *)&time_type_name;
|
|
1867 |
if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_type(right_type))
|
|
1868 |
return (void *)&time_type_name;
|
|
1869 |
if (is_type(left_type, safetime_type_name_c) && is_ANY_SAFENUM_type(right_type))
|
|
1870 |
return (void *)&safetime_type_name;
|
|
1871 |
/* Since we have already checked for ANY_NUM_type and ANY_SAFENUM_type in the previous lines,
|
|
1872 |
* this next line is really only to check for integers/reals of undefined type on 'right_type'...
|
|
1873 |
*/
|
|
1874 |
if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_compatible(right_type))
|
|
1875 |
return (void *)&safetime_type_name;
|
|
1876 |
|
|
1877 |
return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_NUM_compatible);
|
204
|
1878 |
}
|
|
1879 |
|
|
1880 |
|
|
1881 |
void *visit_expression_type_c::visit(mod_expression_c *symbol) {
|
|
1882 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1883 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
257
|
1884 |
return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_INT_compatible);
|
204
|
1885 |
}
|
|
1886 |
|
|
1887 |
|
|
1888 |
void *visit_expression_type_c::visit(power_expression_c *symbol) {
|
|
1889 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1890 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
257
|
1891 |
if (!is_ANY_REAL_compatible(left_type))
|
204
|
1892 |
STAGE3_ERROR(symbol->l_exp, symbol->l_exp, "first operand of ** operator has invalid data type, should be of type ANY_REAL.");
|
257
|
1893 |
if (!is_ANY_NUM_compatible(right_type))
|
204
|
1894 |
STAGE3_ERROR(symbol->r_exp, symbol->r_exp, "second operand of ** operator has invalid data type, should be of type ANY_NUM.");
|
|
1895 |
|
|
1896 |
return (void *)left_type;
|
|
1897 |
}
|
|
1898 |
|
|
1899 |
|
|
1900 |
void *visit_expression_type_c::visit(neg_expression_c *symbol) {
|
|
1901 |
symbol_c *exp_type = base_type((symbol_c *)symbol->exp->accept(*this));
|
257
|
1902 |
if (!is_ANY_MAGNITUDE_compatible(exp_type))
|
204
|
1903 |
STAGE3_ERROR(symbol, symbol, "operand of negate expression '-' has invalid data type, should be of type ANY_MAGNITUDE.");
|
|
1904 |
|
|
1905 |
return exp_type;
|
|
1906 |
}
|
|
1907 |
|
|
1908 |
|
|
1909 |
void *visit_expression_type_c::visit(not_expression_c *symbol) {
|
|
1910 |
symbol_c *type = base_type((symbol_c *)symbol->exp->accept(*this));
|
257
|
1911 |
return compute_expression(type, type, &visit_expression_type_c::is_ANY_BIT_compatible);
|
204
|
1912 |
}
|
|
1913 |
|
|
1914 |
|
|
1915 |
void *visit_expression_type_c::visit(function_invocation_c *symbol) {
|
|
1916 |
function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name);
|
|
1917 |
if (f_decl == function_symtable.end_value()) {
|
|
1918 |
/* TODO: the following code is for standard library functions. We do not yet support this... */
|
|
1919 |
void *res = compute_standard_function_default(symbol);
|
|
1920 |
if (res != NULL) return res;
|
|
1921 |
ERROR;
|
|
1922 |
}
|
|
1923 |
|
|
1924 |
/* now check the semantics of the function call... */
|
|
1925 |
/* If the syntax parser is working correctly, exactly one of the
|
|
1926 |
* following two symbols will be NULL, while the other is != NULL.
|
|
1927 |
*/
|
|
1928 |
if (symbol-> formal_param_list != NULL) check_formal_call (symbol, f_decl);
|
|
1929 |
if (symbol->nonformal_param_list != NULL) check_nonformal_call(symbol, f_decl);
|
|
1930 |
|
|
1931 |
return base_type(f_decl->type_name);
|
|
1932 |
}
|
|
1933 |
|
|
1934 |
/********************/
|
|
1935 |
/* B 3.2 Statements */
|
|
1936 |
/********************/
|
|
1937 |
// SYM_LIST(statement_list_c)
|
|
1938 |
/* The visitor of the base class search_visitor_c will handle calling each instruction in the list.
|
|
1939 |
* We do not need to do anything here...
|
|
1940 |
*/
|
|
1941 |
// void *visit_expression_type_c::visit(statement_list_c *symbol)
|
|
1942 |
|
|
1943 |
|
|
1944 |
/*********************************/
|
|
1945 |
/* B 3.2.1 Assignment Statements */
|
|
1946 |
/*********************************/
|
|
1947 |
|
|
1948 |
void *visit_expression_type_c::visit(assignment_statement_c *symbol) {
|
|
1949 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
|
|
1950 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
|
|
1951 |
|
257
|
1952 |
if (!is_valid_assignment(left_type, right_type)) {
|
204
|
1953 |
STAGE3_ERROR(symbol, symbol, "data type mismatch in assignment statement!\n");
|
|
1954 |
}
|
|
1955 |
return NULL;
|
|
1956 |
}
|
|
1957 |
|
|
1958 |
|
|
1959 |
|
|
1960 |
/*****************************************/
|
|
1961 |
/* B 3.2.2 Subprogram Control Statements */
|
|
1962 |
/*****************************************/
|
|
1963 |
|
|
1964 |
/* RETURN */
|
|
1965 |
// SYM_REF0(return_statement_c)
|
|
1966 |
|
|
1967 |
|
|
1968 |
/* fb_name '(' [param_assignment_list] ')' */
|
|
1969 |
/* param_assignment_list -> may be NULL ! */
|
|
1970 |
// SYM_REF3(fb_invocation_c, fb_name, formal_param_list, nonformal_param_list)
|
|
1971 |
void *visit_expression_type_c::visit(fb_invocation_c *symbol) {
|
|
1972 |
symbol_c *fb_decl = search_varfb_instance_type->get_type(symbol->fb_name);
|
|
1973 |
/* The following should never occur. The function block must be defined,
|
|
1974 |
* and the FB type being called MUST be in the symtable...
|
|
1975 |
* This was all already checked at stage 2!
|
|
1976 |
*/
|
|
1977 |
if (NULL == fb_decl) ERROR;
|
|
1978 |
|
|
1979 |
/* now check the semantics of the fb call... */
|
|
1980 |
/* If the syntax parser is working correctly, exactly one of the
|
|
1981 |
* following two symbols will be NULL, while the other is != NULL.
|
|
1982 |
*/
|
|
1983 |
if (symbol-> formal_param_list != NULL) check_formal_call (symbol, fb_decl);
|
|
1984 |
if (symbol->nonformal_param_list != NULL) check_nonformal_call(symbol, fb_decl);
|
|
1985 |
|
|
1986 |
return NULL;
|
|
1987 |
}
|
|
1988 |
|
|
1989 |
|
|
1990 |
#if 0
|
|
1991 |
/* helper symbol for fb_invocation */
|
|
1992 |
/* param_assignment_list ',' param_assignment */
|
|
1993 |
SYM_LIST(param_assignment_list_c)
|
|
1994 |
|
|
1995 |
/* variable_name ASSIGN expression */
|
|
1996 |
SYM_REF2(input_variable_param_assignment_c, variable_name, expression)
|
|
1997 |
|
|
1998 |
/* [NOT] variable_name '=>' variable */
|
|
1999 |
SYM_REF3(output_variable_param_assignment_c, not_param, variable_name, variable)
|
|
2000 |
|
|
2001 |
/* helper CLASS for output_variable_param_assignment */
|
|
2002 |
SYM_REF0(not_paramassign_c)
|
|
2003 |
#endif
|
|
2004 |
|
|
2005 |
/********************************/
|
|
2006 |
/* B 3.2.3 Selection Statements */
|
|
2007 |
/********************************/
|
|
2008 |
|
|
2009 |
/* IF expression THEN statement_list elseif_statement_list ELSE statement_list END_IF */
|
|
2010 |
// SYM_REF4(if_statement_c, expression, statement_list, elseif_statement_list, else_statement_list)
|
|
2011 |
void *visit_expression_type_c::visit(if_statement_c *symbol) {
|
|
2012 |
symbol_c *expr_type = base_type((symbol_c*)symbol->expression->accept(*this));
|
|
2013 |
if (!is_BOOL_type(expr_type)) STAGE3_ERROR(symbol,symbol,"IF conditional expression is not of boolean type.");
|
|
2014 |
if (NULL != symbol->statement_list)
|
|
2015 |
symbol->statement_list->accept(*this);
|
|
2016 |
if (NULL != symbol->elseif_statement_list)
|
|
2017 |
symbol->elseif_statement_list->accept(*this);
|
|
2018 |
if (NULL != symbol->else_statement_list)
|
|
2019 |
symbol->else_statement_list->accept(*this);
|
|
2020 |
return NULL;
|
|
2021 |
}
|
|
2022 |
|
|
2023 |
/* helper symbol for if_statement */
|
|
2024 |
// SYM_LIST(elseif_statement_list_c)
|
|
2025 |
// void *visit_expression_type_c::visit(elseif_statement_list_c *symbol) { }
|
|
2026 |
|
|
2027 |
/* helper symbol for elseif_statement_list */
|
|
2028 |
/* ELSIF expression THEN statement_list */
|
|
2029 |
// SYM_REF2(elseif_statement_c, expression, statement_list)
|
|
2030 |
void *visit_expression_type_c::visit(elseif_statement_c *symbol) {
|
|
2031 |
symbol_c *elseif_expr_type = base_type((symbol_c*)symbol->expression->accept(*this));
|
|
2032 |
if(!is_BOOL_type(elseif_expr_type)) STAGE3_ERROR(symbol,symbol,"ELSIF conditional expression is not of boolean type.");
|
|
2033 |
if (NULL != symbol->statement_list)
|
|
2034 |
symbol->statement_list->accept(*this);
|
|
2035 |
return NULL;
|
|
2036 |
}
|
|
2037 |
|
|
2038 |
|
|
2039 |
/* CASE expression OF case_element_list ELSE statement_list END_CASE */
|
|
2040 |
// SYM_REF3(case_statement_c, expression, case_element_list, statement_list)
|
|
2041 |
void *visit_expression_type_c::visit(case_statement_c *symbol) {
|
|
2042 |
case_expression_type = base_type((symbol_c*)symbol->expression->accept(*this));
|
|
2043 |
if (NULL != case_expression_type) {
|
|
2044 |
if (NULL != symbol->case_element_list)
|
|
2045 |
symbol->case_element_list->accept(*this);
|
|
2046 |
}
|
|
2047 |
if (NULL != symbol->statement_list)
|
|
2048 |
symbol->statement_list->accept(*this);
|
|
2049 |
return NULL;
|
|
2050 |
}
|
|
2051 |
|
|
2052 |
#if 0
|
|
2053 |
/* helper symbol for case_statement */
|
|
2054 |
// SYM_LIST(case_element_list_c)
|
|
2055 |
// void *visit_expression_type_c::visit(case_element_list_c *symbol);
|
|
2056 |
|
|
2057 |
/* case_list ':' statement_list */
|
|
2058 |
// SYM_REF2(case_element_c, case_list, statement_list)
|
|
2059 |
void *visit_expression_type_c::visit(case_element_c *symbol);
|
|
2060 |
#endif
|
|
2061 |
|
|
2062 |
// SYM_LIST(case_list_c)
|
|
2063 |
void *visit_expression_type_c::visit(case_list_c *symbol) {
|
|
2064 |
symbol_c *element_type;
|
|
2065 |
for(int i = 0; i < symbol->n; i++) {
|
|
2066 |
element_type = (symbol_c *)symbol->elements[i]->accept(*this);
|
|
2067 |
if (NULL == element_type) {
|
|
2068 |
STAGE3_ERROR(symbol->elements[i], symbol->elements[i], "Case list element has undefined data type.");
|
|
2069 |
} else {
|
|
2070 |
element_type = base_type(element_type);
|
|
2071 |
if (NULL != element_type){
|
257
|
2072 |
/* The CASE value is only used for comparison (and not assingment), so we only check for compatibility! */
|
204
|
2073 |
if (!is_compatible_type(case_expression_type, element_type))
|
|
2074 |
STAGE3_ERROR(symbol->elements[i], symbol->elements[i], "Invalid data type of case list element.");
|
|
2075 |
}
|
|
2076 |
}
|
|
2077 |
}
|
|
2078 |
return NULL;
|
|
2079 |
}
|
|
2080 |
|
|
2081 |
/********************************/
|
|
2082 |
/* B 3.2.4 Iteration Statements */
|
|
2083 |
/********************************/
|
|
2084 |
|
|
2085 |
/* FOR control_variable ASSIGN expression TO expression [BY expression] DO statement_list END_FOR */
|
|
2086 |
// SYM_REF5(for_statement_c, control_variable, beg_expression, end_expression, by_expression, statement_list)
|
|
2087 |
void *visit_expression_type_c::visit(for_statement_c *symbol) {
|
|
2088 |
symbol_c *var_type = (symbol_c*)symbol->control_variable->accept(*this);
|
|
2089 |
if (NULL == var_type) ERROR;
|
|
2090 |
var_type = base_type(var_type);
|
|
2091 |
if (NULL == var_type) ERROR;
|
|
2092 |
// ASSIGN
|
|
2093 |
symbol_c *beg_expr_type = base_type((symbol_c*)symbol->beg_expression->accept(*this));
|
257
|
2094 |
if (NULL != beg_expr_type) {
|
|
2095 |
/* The BEG value is assigned to the variable, so we check for assignment validity! */
|
|
2096 |
if(!is_valid_assignment(var_type, beg_expr_type))
|
204
|
2097 |
STAGE3_ERROR(symbol, symbol, "Data type mismatch between control variable and initial value.");
|
|
2098 |
}
|
|
2099 |
// TO
|
|
2100 |
symbol_c *end_expr_type = base_type((symbol_c*)symbol->end_expression->accept(*this));
|
|
2101 |
if (NULL != end_expr_type) {
|
257
|
2102 |
/* The TO value is only used for comparison, so we only check for compatibility! */
|
|
2103 |
if(!is_compatible_type(var_type, end_expr_type))
|
204
|
2104 |
STAGE3_ERROR(symbol, symbol, "Data type mismatch between control variable and final value.");
|
|
2105 |
}
|
|
2106 |
// BY
|
|
2107 |
if(symbol->by_expression != NULL) {
|
|
2108 |
symbol_c *by_expr_type = base_type((symbol_c*)symbol->by_expression->accept(*this));
|
|
2109 |
if (NULL != end_expr_type) {
|
257
|
2110 |
/* The BY value is used in an expression (add, sub, ...), so we only check for compatibility! */
|
|
2111 |
if(!is_compatible_type(var_type, by_expr_type))
|
204
|
2112 |
STAGE3_ERROR(symbol, symbol, "Data type mismatch between control variable and BY value.");
|
|
2113 |
}
|
|
2114 |
}
|
|
2115 |
// DO
|
|
2116 |
if (NULL != symbol->statement_list)
|
|
2117 |
symbol->statement_list->accept(*this);
|
|
2118 |
return NULL;
|
|
2119 |
}
|
|
2120 |
|
|
2121 |
|
|
2122 |
/* WHILE expression DO statement_list END_WHILE */
|
|
2123 |
// SYM_REF2(while_statement_c, expression, statement_list)
|
|
2124 |
void *visit_expression_type_c::visit(while_statement_c *symbol) {
|
|
2125 |
symbol_c *expr_type = base_type((symbol_c*)symbol->expression->accept(*this));
|
|
2126 |
if (NULL != expr_type) {
|
|
2127 |
if(!is_BOOL_type(expr_type))
|
|
2128 |
STAGE3_ERROR(symbol,symbol,"WHILE conditional expression is not of boolean type.");
|
|
2129 |
}
|
|
2130 |
|
|
2131 |
if (NULL != symbol->statement_list)
|
|
2132 |
symbol->statement_list->accept(*this);
|
|
2133 |
return NULL;
|
|
2134 |
}
|
|
2135 |
|
|
2136 |
/* REPEAT statement_list UNTIL expression END_REPEAT */
|
|
2137 |
// SYM_REF2(repeat_statement_c, statement_list, expression)
|
|
2138 |
void *visit_expression_type_c::visit(repeat_statement_c *symbol) {
|
|
2139 |
if (NULL != symbol->statement_list)
|
|
2140 |
symbol->statement_list->accept(*this);
|
|
2141 |
|
|
2142 |
symbol_c *expr_type = base_type((symbol_c*)symbol->expression->accept(*this));
|
|
2143 |
if (NULL != expr_type) {
|
|
2144 |
if(!is_BOOL_type(expr_type))
|
|
2145 |
STAGE3_ERROR(symbol,symbol,"REPEAT conditional expression is not of boolean type.");
|
|
2146 |
}
|
|
2147 |
return NULL;
|
|
2148 |
}
|
|
2149 |
|
|
2150 |
/* EXIT */
|
|
2151 |
// SYM_REF0(exit_statement_c)
|
|
2152 |
|
|
2153 |
|
|
2154 |
|