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