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