author | Mario de Sousa <msousa@fe.up.pt> |
Fri, 01 Apr 2011 10:06:19 +0100 | |
changeset 264 | 6facabd9c2cd |
parent 258 | d7d92b2f87e9 |
child 265 | 4d222f46f8cc |
permissions | -rwxr-xr-x |
181 | 1 |
/* |
2 |
* (c) 2003 Mario de Sousa |
|
3 |
* |
|
4 |
* Offered to the public under the terms of the GNU General Public License |
|
5 |
* as published by the Free Software Foundation; either version 2 of the |
|
6 |
* License, or (at your option) any later version. |
|
7 |
* |
|
8 |
* This program is distributed in the hope that it will be useful, but |
|
9 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
11 |
* Public License for more details. |
|
12 |
* |
|
13 |
* This code is made available on the understanding that it will not be |
|
14 |
* used in safety-critical situations without a full and competent review. |
|
15 |
*/ |
|
16 |
||
17 |
/* |
|
18 |
* An IEC 61131-3 IL and ST compiler. |
|
19 |
* |
|
20 |
* Based on the |
|
21 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
||
26 |
/* Determine the data type of an ST expression. |
|
27 |
* A reference to the relevant type definition is returned. |
|
28 |
* |
|
29 |
* For example: |
|
30 |
* 2 + 3 -> returns reference to a int_type_name_c object. |
|
31 |
* 22.2 - 5 -> returns reference to a real_type_name_c object. |
|
32 |
* etc... |
|
33 |
*/ |
|
34 |
||
35 |
||
36 |
||
37 |
#include "absyntax_utils.hh" |
|
38 |
#include <typeinfo> |
|
39 |
||
40 |
search_expression_type_c::search_expression_type_c(symbol_c *search_scope) { |
|
41 |
search_varfb_instance_type = new search_varfb_instance_type_c(search_scope); |
|
42 |
} |
|
43 |
||
44 |
search_expression_type_c::~search_expression_type_c(void) { |
|
45 |
delete search_varfb_instance_type; |
|
46 |
} |
|
47 |
||
48 |
/* A helper function... */ |
|
49 |
bool search_expression_type_c::is_bool_type(symbol_c *type_symbol) { |
|
50 |
bool_type_name_c tt; |
|
51 |
if (type_symbol == NULL) {return true;} |
|
257 | 52 |
if (typeid(*type_symbol) == typeid(safebool_type_name_c)) {return true;} |
53 |
if (typeid(*type_symbol) == typeid(bool_type_name_c)) {return true;} |
|
54 |
if (typeid(*type_symbol) == typeid(boolean_true_c)) {return true;} |
|
55 |
if (typeid(*type_symbol) == typeid(boolean_false_c)) {return true;} |
|
56 |
return false; |
|
181 | 57 |
} |
58 |
||
59 |
/* A helper function... */ |
|
60 |
bool search_expression_type_c::is_time_type(symbol_c *type_symbol) { |
|
61 |
if (type_symbol == NULL) {return true;} |
|
257 | 62 |
if (typeid(*type_symbol) == typeid(time_type_name_c)) {return true;} |
63 |
if (typeid(*type_symbol) == typeid(date_type_name_c)) {return true;} |
|
64 |
if (typeid(*type_symbol) == typeid(tod_type_name_c)) {return true;} |
|
65 |
if (typeid(*type_symbol) == typeid(dt_type_name_c)) {return true;} |
|
66 |
if (typeid(*type_symbol) == typeid(safetime_type_name_c)) {return true;} |
|
67 |
if (typeid(*type_symbol) == typeid(safedate_type_name_c)) {return true;} |
|
68 |
if (typeid(*type_symbol) == typeid(safetod_type_name_c)) {return true;} |
|
69 |
if (typeid(*type_symbol) == typeid(safedt_type_name_c)) {return true;} |
|
181 | 70 |
return false; |
71 |
} |
|
72 |
||
73 |
/* A helper function... */ |
|
74 |
bool search_expression_type_c::is_string_type(symbol_c *type_symbol) { |
|
75 |
if (type_symbol == NULL) {return true;} |
|
257 | 76 |
if (typeid(*type_symbol) == typeid(string_type_name_c)) {return true;} |
77 |
if (typeid(*type_symbol) == typeid(wstring_type_name_c)) {return true;} |
|
78 |
if (typeid(*type_symbol) == typeid(safestring_type_name_c)) {return true;} |
|
79 |
if (typeid(*type_symbol) == typeid(safewstring_type_name_c)) {return true;} |
|
181 | 80 |
return false; |
81 |
} |
|
82 |
||
83 |
/* A helper function... */ |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
84 |
bool search_expression_type_c::is_literal_integer_type(symbol_c *type_symbol) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
85 |
if (type_symbol == NULL) {return true;} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
86 |
if (typeid(*type_symbol) == typeid(integer_c)) {return true;} |
257 | 87 |
if (typeid(*type_symbol) == typeid(neg_integer_c)) {return true;} |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
88 |
if (typeid(*type_symbol) == typeid(binary_integer_c)) {return true;} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
89 |
if (typeid(*type_symbol) == typeid(octal_integer_c)) {return true;} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
90 |
if (typeid(*type_symbol) == typeid(hex_integer_c)) {return true;} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
91 |
return false; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
92 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
93 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
94 |
/* A helper function... */ |
181 | 95 |
bool search_expression_type_c::is_integer_type(symbol_c *type_symbol) { |
96 |
if (type_symbol == NULL) {return true;} |
|
257 | 97 |
if (typeid(*type_symbol) == typeid(sint_type_name_c)) {return true;} |
98 |
if (typeid(*type_symbol) == typeid(int_type_name_c)) {return true;} |
|
99 |
if (typeid(*type_symbol) == typeid(dint_type_name_c)) {return true;} |
|
100 |
if (typeid(*type_symbol) == typeid(lint_type_name_c)) {return true;} |
|
101 |
if (typeid(*type_symbol) == typeid(usint_type_name_c)) {return true;} |
|
102 |
if (typeid(*type_symbol) == typeid(uint_type_name_c)) {return true;} |
|
103 |
if (typeid(*type_symbol) == typeid(udint_type_name_c)) {return true;} |
|
104 |
if (typeid(*type_symbol) == typeid(ulint_type_name_c)) {return true;} |
|
105 |
if (typeid(*type_symbol) == typeid(safesint_type_name_c)) {return true;} |
|
106 |
if (typeid(*type_symbol) == typeid(safeint_type_name_c)) {return true;} |
|
107 |
if (typeid(*type_symbol) == typeid(safedint_type_name_c)) {return true;} |
|
108 |
if (typeid(*type_symbol) == typeid(safelint_type_name_c)) {return true;} |
|
109 |
if (typeid(*type_symbol) == typeid(safeusint_type_name_c)) {return true;} |
|
110 |
if (typeid(*type_symbol) == typeid(safeuint_type_name_c)) {return true;} |
|
111 |
if (typeid(*type_symbol) == typeid(safeudint_type_name_c)) {return true;} |
|
112 |
if (typeid(*type_symbol) == typeid(safeulint_type_name_c)) {return true;} |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
113 |
return is_literal_integer_type(type_symbol); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
114 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
115 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
116 |
/* A helper function... */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
117 |
bool search_expression_type_c::is_literal_real_type(symbol_c *type_symbol) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
118 |
if (type_symbol == NULL) {return true;} |
257 | 119 |
if (typeid(*type_symbol) == typeid(real_c)) {return true;} |
120 |
if (typeid(*type_symbol) == typeid(neg_real_c)) {return true;} |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
121 |
return false; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
122 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
123 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
124 |
/* A helper function... */ |
181 | 125 |
bool search_expression_type_c::is_real_type(symbol_c *type_symbol) { |
126 |
if (type_symbol == NULL) {return true;} |
|
257 | 127 |
if (typeid(*type_symbol) == typeid(real_type_name_c)) {return true;} |
128 |
if (typeid(*type_symbol) == typeid(lreal_type_name_c)) {return true;} |
|
129 |
if (typeid(*type_symbol) == typeid(safereal_type_name_c)) {return true;} |
|
130 |
if (typeid(*type_symbol) == typeid(safelreal_type_name_c)) {return true;} |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
131 |
return is_literal_real_type(type_symbol); |
181 | 132 |
} |
133 |
||
134 |
bool search_expression_type_c::is_num_type(symbol_c *type_symbol) { |
|
135 |
if (type_symbol == NULL) {return true;} |
|
136 |
return is_real_type(type_symbol) || is_integer_type(type_symbol); |
|
137 |
} |
|
138 |
||
139 |
bool search_expression_type_c::is_nbinary_type(symbol_c *type_symbol) { |
|
140 |
if (type_symbol == NULL) {return true;} |
|
257 | 141 |
if (typeid(*type_symbol) == typeid(byte_type_name_c)) {return true;} |
142 |
if (typeid(*type_symbol) == typeid(word_type_name_c)) {return true;} |
|
143 |
if (typeid(*type_symbol) == typeid(dword_type_name_c)) {return true;} |
|
144 |
if (typeid(*type_symbol) == typeid(lword_type_name_c)) {return true;} |
|
145 |
if (typeid(*type_symbol) == typeid(safebyte_type_name_c)) {return true;} |
|
146 |
if (typeid(*type_symbol) == typeid(safeword_type_name_c)) {return true;} |
|
147 |
if (typeid(*type_symbol) == typeid(safedword_type_name_c)) {return true;} |
|
148 |
if (typeid(*type_symbol) == typeid(safelword_type_name_c)) {return true;} |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
149 |
return is_literal_integer_type(type_symbol); |
181 | 150 |
} |
151 |
||
152 |
bool search_expression_type_c::is_binary_type(symbol_c *type_symbol) { |
|
153 |
if (type_symbol == NULL) {return true;} |
|
257 | 154 |
// if (typeid(*type_symbol) == typeid(bool_type_name_c)) {return true;} |
155 |
// if (typeid(*type_symbol) == typeid(safebool_type_name_c)) {return true;} |
|
156 |
return (is_nbinary_type(type_symbol) || is_bool_type(type_symbol)); |
|
181 | 157 |
} |
158 |
||
159 |
bool search_expression_type_c::is_same_type(symbol_c *first_type, symbol_c *second_type) { |
|
160 |
if (first_type == NULL || second_type == NULL) {return true;} |
|
161 |
if (typeid(*first_type) == typeid(*second_type)) {return true;} |
|
257 | 162 |
if (is_bool_type(first_type) && is_bool_type(second_type)) {return true;} |
163 |
if (is_integer_type(first_type) && is_literal_integer_type(second_type)) {return true;} |
|
164 |
if (is_literal_integer_type(first_type) && is_integer_type(second_type)) {return true;} |
|
165 |
if (is_binary_type(first_type) && is_literal_integer_type(second_type)) {return true;} |
|
166 |
if (is_literal_integer_type(first_type) && is_binary_type(second_type)) {return true;} |
|
167 |
if (is_real_type(first_type) && is_literal_real_type(second_type)) {return true;} |
|
168 |
if (is_literal_real_type(first_type) && is_real_type(second_type)) {return true;} |
|
181 | 169 |
return false; |
170 |
} |
|
171 |
||
172 |
symbol_c* search_expression_type_c::common_type(symbol_c *first_type, symbol_c *second_type) { |
|
173 |
if (first_type == NULL && second_type == NULL) {return NULL;} |
|
174 |
if (first_type == NULL) {return second_type;} |
|
175 |
if (second_type == NULL) {return first_type;} |
|
176 |
if (typeid(*first_type) == typeid(*second_type)) {return first_type;} |
|
257 | 177 |
if (is_integer_type(first_type) && is_literal_integer_type(second_type)) {return first_type;} |
178 |
if (is_literal_integer_type(first_type) && is_integer_type(second_type)) {return second_type;} |
|
179 |
if (is_binary_type(first_type) && is_literal_integer_type(second_type)) {return first_type;} |
|
180 |
if (is_literal_integer_type(first_type) && is_binary_type(second_type)) {return second_type;} |
|
181 |
if (is_real_type(first_type) && is_literal_real_type(second_type)) {return first_type;} |
|
182 |
if (is_literal_real_type(first_type) && is_real_type(second_type)) {return second_type;} |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
183 |
return NULL; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
184 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
185 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
186 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
187 |
integer_c search_expression_type_c::integer("1"); // what default value should we use here ??? |
181 | 188 |
#include "search_type_code.c" |
189 |
||
190 |
/*static bool_type_name_c bool_type_name;*/ |
|
191 |
||
192 |
/* A helper function... */ |
|
193 |
void *search_expression_type_c::compute_boolean_expression(symbol_c *left_type, symbol_c *right_type) { |
|
194 |
if (!is_same_type(left_type, right_type)) |
|
195 |
ERROR; |
|
196 |
if (!is_bool_type(left_type) && !is_binary_type(left_type)) |
|
197 |
ERROR; |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
198 |
if (is_literal_integer_type(left_type)) {return (void *)right_type;} |
181 | 199 |
else {return (void *)left_type;} |
200 |
} |
|
201 |
||
202 |
/* A helper function... */ |
|
203 |
void *search_expression_type_c::compute_numeric_expression(symbol_c *left_type, symbol_c *right_type) { |
|
204 |
if (!is_same_type(left_type, right_type)) |
|
205 |
ERROR; |
|
206 |
if (!is_integer_type(left_type) && !is_real_type(left_type)) |
|
207 |
ERROR; |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
208 |
if (is_literal_integer_type(left_type) || is_literal_real_type(left_type)) {return (void *)right_type;} |
181 | 209 |
else {return (void *)left_type;} |
210 |
return NULL; |
|
211 |
} |
|
212 |
||
213 |
/* a helper function... */ |
|
214 |
symbol_c *search_expression_type_c::base_type(symbol_c *symbol) { |
|
215 |
return (symbol_c *)symbol->accept(search_base_type); |
|
216 |
} |
|
217 |
||
218 |
/*********************/ |
|
219 |
/* B 1.4 - Variables */ |
|
220 |
/*********************/ |
|
221 |
||
222 |
void *search_expression_type_c::visit(symbolic_variable_c *symbol) { |
|
223 |
symbol_c *res; |
|
224 |
||
225 |
/* Nope, now we assume it is a variable, and determine its type... */ |
|
226 |
res = search_varfb_instance_type->get_type(symbol); |
|
227 |
if (NULL != res) return res; |
|
228 |
||
229 |
return NULL; |
|
230 |
} |
|
231 |
||
232 |
/********************************************/ |
|
233 |
/* B 1.4.1 - Directly Represented Variables */ |
|
234 |
/********************************************/ |
|
235 |
void *search_expression_type_c::visit(direct_variable_c *symbol) { |
|
196
1c0c7a664fc2
Fix problems with direct variables in expression while compiling resulting expression type
lbessard
parents:
194
diff
changeset
|
236 |
symbol_c *res; |
1c0c7a664fc2
Fix problems with direct variables in expression while compiling resulting expression type
lbessard
parents:
194
diff
changeset
|
237 |
|
1c0c7a664fc2
Fix problems with direct variables in expression while compiling resulting expression type
lbessard
parents:
194
diff
changeset
|
238 |
/* Nope, now we assume it is a variable, and determine its type... */ |
1c0c7a664fc2
Fix problems with direct variables in expression while compiling resulting expression type
lbessard
parents:
194
diff
changeset
|
239 |
res = search_varfb_instance_type->get_type(symbol); |
1c0c7a664fc2
Fix problems with direct variables in expression while compiling resulting expression type
lbessard
parents:
194
diff
changeset
|
240 |
if (NULL != res) return res; |
1c0c7a664fc2
Fix problems with direct variables in expression while compiling resulting expression type
lbessard
parents:
194
diff
changeset
|
241 |
|
1c0c7a664fc2
Fix problems with direct variables in expression while compiling resulting expression type
lbessard
parents:
194
diff
changeset
|
242 |
return NULL; |
181 | 243 |
} |
244 |
||
245 |
/*************************************/ |
|
246 |
/* B 1.4.2 - Multi-element variables */ |
|
247 |
/*************************************/ |
|
248 |
||
249 |
void *search_expression_type_c::visit(array_variable_c *symbol) { |
|
250 |
symbol_c *res; |
|
251 |
||
252 |
/* Nope, now we assume it is a variable, and determine its type... */ |
|
253 |
res = search_varfb_instance_type->get_type(symbol); |
|
254 |
if (NULL != res) return res; |
|
255 |
||
256 |
return NULL; |
|
257 |
} |
|
258 |
||
259 |
void *search_expression_type_c::visit(structured_variable_c *symbol) { |
|
260 |
symbol_c *res; |
|
261 |
||
262 |
/* Nope, now we assume it is a variable, and determine its type... */ |
|
263 |
res = search_varfb_instance_type->get_type(symbol); |
|
264 |
if (NULL != res) return res; |
|
265 |
||
266 |
return NULL; |
|
267 |
} |
|
268 |
||
269 |
/***************************************/ |
|
270 |
/* B.3 - Language ST (Structured Text) */ |
|
271 |
/***************************************/ |
|
272 |
/***********************/ |
|
273 |
/* B 3.1 - Expressions */ |
|
274 |
/***********************/ |
|
275 |
void *search_expression_type_c::visit(or_expression_c *symbol) { |
|
276 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this)); |
|
277 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this)); |
|
278 |
return compute_boolean_expression(left_type, right_type); |
|
279 |
} |
|
280 |
||
281 |
void *search_expression_type_c::visit(xor_expression_c *symbol) { |
|
282 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this)); |
|
283 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this)); |
|
284 |
return compute_boolean_expression(left_type, right_type); |
|
285 |
} |
|
286 |
||
287 |
void *search_expression_type_c::visit(and_expression_c *symbol) { |
|
288 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this)); |
|
289 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this)); |
|
290 |
return compute_boolean_expression(left_type, right_type); |
|
291 |
} |
|
292 |
||
293 |
void *search_expression_type_c::visit(equ_expression_c *symbol) {return (void *)&bool_type_name;} |
|
294 |
void *search_expression_type_c::visit(notequ_expression_c *symbol) {return (void *)&bool_type_name;} |
|
295 |
void *search_expression_type_c::visit(lt_expression_c *symbol) {return (void *)&bool_type_name;} |
|
296 |
void *search_expression_type_c::visit(gt_expression_c *symbol) {return (void *)&bool_type_name;} |
|
297 |
void *search_expression_type_c::visit(le_expression_c *symbol) {return (void *)&bool_type_name;} |
|
298 |
void *search_expression_type_c::visit(ge_expression_c *symbol) {return (void *)&bool_type_name;} |
|
299 |
||
300 |
void *search_expression_type_c::visit(add_expression_c *symbol) { |
|
301 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this)); |
|
302 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this)); |
|
303 |
if (typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&time_type_name;} |
|
304 |
if (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&tod_type_name;} |
|
305 |
if (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&dt_type_name;} |
|
306 |
return compute_numeric_expression(left_type, right_type); |
|
307 |
} |
|
308 |
||
309 |
void *search_expression_type_c::visit(sub_expression_c *symbol) { |
|
310 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this)); |
|
311 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this)); |
|
312 |
if (typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&time_type_name;} |
|
313 |
if (typeid(*left_type) == typeid(date_type_name_c) && typeid(*right_type) == typeid(date_type_name_c)) {return (void *)&time_type_name;} |
|
314 |
if (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&tod_type_name;} |
|
315 |
if (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(tod_type_name_c)) {return (void *)&time_type_name;} |
|
316 |
if (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&dt_type_name;} |
|
317 |
if (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(dt_type_name_c)) {return (void *)&time_type_name;} |
|
318 |
return compute_numeric_expression(left_type, right_type); |
|
319 |
} |
|
320 |
||
321 |
void *search_expression_type_c::visit(mul_expression_c *symbol) { |
|
322 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this)); |
|
323 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this)); |
|
324 |
if (typeid(*left_type) == typeid(time_type_name_c) && is_num_type(right_type)) { |
|
325 |
return (void *)&time_type_name; |
|
326 |
} |
|
327 |
return compute_numeric_expression(left_type, right_type); |
|
328 |
} |
|
329 |
||
330 |
void *search_expression_type_c::visit(div_expression_c *symbol) { |
|
331 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this)); |
|
332 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this)); |
|
333 |
if (typeid(*left_type) == typeid(time_type_name_c) && is_num_type(right_type)){ |
|
334 |
return (void *)&time_type_name; |
|
335 |
} |
|
336 |
return compute_numeric_expression(left_type, right_type); |
|
337 |
} |
|
338 |
||
339 |
void *search_expression_type_c::visit(mod_expression_c *symbol) { |
|
340 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this)); |
|
341 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this)); |
|
342 |
return compute_numeric_expression(left_type, right_type); |
|
343 |
} |
|
344 |
||
345 |
void *search_expression_type_c::visit(power_expression_c *symbol) { |
|
346 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this)); |
|
347 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this)); |
|
348 |
if (is_real_type(left_type) && is_num_type(right_type)) { |
|
349 |
return (void *)left_type; |
|
350 |
} |
|
351 |
ERROR; |
|
352 |
return NULL; |
|
353 |
} |
|
354 |
||
355 |
void *search_expression_type_c::visit(neg_expression_c *symbol) { |
|
356 |
symbol_c *exp_type = base_type((symbol_c *)symbol->exp->accept(*this)); |
|
357 |
if (is_num_type(exp_type) || typeid(*exp_type) == typeid(time_type_name_c)){ |
|
358 |
return (void *)exp_type; |
|
359 |
} |
|
360 |
ERROR; |
|
361 |
return NULL; |
|
362 |
} |
|
363 |
||
364 |
void *search_expression_type_c::visit(not_expression_c *symbol) { |
|
365 |
symbol_c *exp_type = base_type((symbol_c *)symbol->exp->accept(*this)); |
|
366 |
return compute_boolean_expression(exp_type, exp_type); |
|
367 |
} |
|
368 |
||
369 |
void *search_expression_type_c::visit(function_invocation_c *symbol) { |
|
370 |
function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
|
371 |
if (f_decl == function_symtable.end_value()) { |
|
372 |
void *res = compute_standard_function_default(symbol); |
|
373 |
if (res == NULL) |
|
374 |
ERROR; |
|
375 |
return res; |
|
376 |
} |
|
377 |
return base_type(f_decl->type_name); |
|
378 |
} |
|
379 |
||
380 |
/*bool_type_name_c search_expression_type_c::bool_type_name;*/ |
|
381 |