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