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