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