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