author | Catarina Boucinha <ccb@fe.up.pt> |
Thu, 27 Aug 2009 16:29:23 +0100 | |
changeset 204 | 8ffa211b7f9a |
parent 202 | da1a8186f86f |
child 208 | c72748a12ae3 |
child 257 | 90782e241346 |
permissions | -rw-r--r-- |
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;} |
|
52 |
return (typeid(*type_symbol) == typeid(bool_type_name_c)); |
|
53 |
} |
|
54 |
||
55 |
/* A helper function... */ |
|
56 |
bool search_expression_type_c::is_time_type(symbol_c *type_symbol) { |
|
57 |
if (type_symbol == NULL) {return true;} |
|
58 |
if (typeid(*type_symbol) == typeid(time_type_name_c)) {return true;} |
|
59 |
if (typeid(*type_symbol) == typeid(date_type_name_c)) {return true;} |
|
60 |
if (typeid(*type_symbol) == typeid(tod_type_name_c)) {return true;} |
|
61 |
if (typeid(*type_symbol) == typeid(dt_type_name_c)) {return true;} |
|
62 |
return false; |
|
63 |
} |
|
64 |
||
65 |
/* A helper function... */ |
|
66 |
bool search_expression_type_c::is_string_type(symbol_c *type_symbol) { |
|
67 |
if (type_symbol == NULL) {return true;} |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
68 |
if (typeid(*type_symbol) == typeid(string_type_name_c)) {return true;} |
181 | 69 |
if (typeid(*type_symbol) == typeid(wstring_type_name_c)) {return true;} |
70 |
return false; |
|
71 |
} |
|
72 |
||
73 |
/* A helper function... */ |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
74 |
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
|
75 |
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
|
76 |
if (typeid(*type_symbol) == typeid(integer_c)) {return true;} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
return false; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
81 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
82 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
83 |
/* A helper function... */ |
181 | 84 |
bool search_expression_type_c::is_integer_type(symbol_c *type_symbol) { |
85 |
if (type_symbol == NULL) {return true;} |
|
202
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(sint_type_name_c)) {return true;} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
87 |
if (typeid(*type_symbol) == typeid(int_type_name_c)) {return true;} |
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(dint_type_name_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(lint_type_name_c)) {return true;} |
181 | 90 |
if (typeid(*type_symbol) == typeid(usint_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
|
91 |
if (typeid(*type_symbol) == typeid(uint_type_name_c)) {return true;} |
181 | 92 |
if (typeid(*type_symbol) == typeid(udint_type_name_c)) {return true;} |
93 |
if (typeid(*type_symbol) == typeid(ulint_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
|
94 |
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
|
95 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
96 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
97 |
/* A helper function... */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
98 |
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
|
99 |
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
|
100 |
if (typeid(*type_symbol) == typeid(real_c)) {return true;} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
101 |
return false; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
102 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
103 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
104 |
/* A helper function... */ |
181 | 105 |
bool search_expression_type_c::is_real_type(symbol_c *type_symbol) { |
106 |
if (type_symbol == NULL) {return true;} |
|
107 |
if (typeid(*type_symbol) == typeid(real_type_name_c)) {return true;} |
|
108 |
if (typeid(*type_symbol) == typeid(lreal_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
|
109 |
return is_literal_real_type(type_symbol); |
181 | 110 |
} |
111 |
||
112 |
bool search_expression_type_c::is_num_type(symbol_c *type_symbol) { |
|
113 |
if (type_symbol == NULL) {return true;} |
|
114 |
return is_real_type(type_symbol) || is_integer_type(type_symbol); |
|
115 |
} |
|
116 |
||
117 |
bool search_expression_type_c::is_nbinary_type(symbol_c *type_symbol) { |
|
118 |
if (type_symbol == NULL) {return true;} |
|
119 |
if (typeid(*type_symbol) == typeid(byte_type_name_c)) {return true;} |
|
120 |
if (typeid(*type_symbol) == typeid(word_type_name_c)) {return true;} |
|
121 |
if (typeid(*type_symbol) == typeid(dword_type_name_c)) {return true;} |
|
122 |
if (typeid(*type_symbol) == typeid(lword_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
|
123 |
return is_literal_integer_type(type_symbol); |
181 | 124 |
} |
125 |
||
126 |
bool search_expression_type_c::is_binary_type(symbol_c *type_symbol) { |
|
127 |
if (type_symbol == NULL) {return true;} |
|
128 |
if (typeid(*type_symbol) == typeid(bool_type_name_c)) {return true;} |
|
129 |
return is_nbinary_type(type_symbol); |
|
130 |
} |
|
131 |
||
132 |
bool search_expression_type_c::is_same_type(symbol_c *first_type, symbol_c *second_type) { |
|
133 |
if (first_type == NULL || second_type == NULL) {return true;} |
|
134 |
if (typeid(*first_type) == typeid(*second_type)) {return true;} |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
135 |
if (is_integer_type(first_type) && is_literal_integer_type(second_type)) {return true;} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
136 |
if (is_literal_integer_type(first_type) && is_integer_type(second_type)) {return true;} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
137 |
if (is_binary_type(first_type) && is_literal_integer_type(second_type)) {return true;} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
138 |
if (is_literal_integer_type(first_type) && is_binary_type(second_type)) {return true;} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
139 |
if (is_real_type(first_type) && is_literal_real_type(second_type)) {return true;} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
140 |
if (is_literal_real_type(first_type) && is_real_type(second_type)) {return true;} |
181 | 141 |
return false; |
142 |
} |
|
143 |
||
144 |
symbol_c* search_expression_type_c::common_type(symbol_c *first_type, symbol_c *second_type) { |
|
145 |
if (first_type == NULL && second_type == NULL) {return NULL;} |
|
146 |
if (first_type == NULL) {return second_type;} |
|
147 |
if (second_type == NULL) {return first_type;} |
|
148 |
if (typeid(*first_type) == typeid(*second_type)) {return first_type;} |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
149 |
if (is_integer_type(first_type) && is_literal_integer_type(second_type)) {return first_type;} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
150 |
if (is_literal_integer_type(first_type) && is_integer_type(second_type)) {return second_type;} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
151 |
if (is_binary_type(first_type) && is_literal_integer_type(second_type)) {return first_type;} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
152 |
if (is_literal_integer_type(first_type) && is_binary_type(second_type)) {return second_type;} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
153 |
if (is_real_type(first_type) && is_literal_real_type(second_type)) {return first_type;} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
154 |
if (is_literal_real_type(first_type) && is_real_type(second_type)) {return second_type;} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
155 |
return NULL; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
156 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
157 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
158 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
159 |
integer_c search_expression_type_c::integer("1"); // what default value should we use here ??? |
181 | 160 |
#define compute_standard_function_default search_expression_type_c::compute_standard_function_default |
161 |
#define compute_standard_function_il search_expression_type_c::compute_standard_function_il |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
162 |
#define search(x) search_f(x) |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
163 |
#define next() next_nf() |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
164 |
// #define search_constant_type_c::constant_int_type_name search_expression_type_c::integer |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
165 |
#define constant_int_type_name integer |
181 | 166 |
#include "search_type_code.c" |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
167 |
#undef constant_int_type_name |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
168 |
// #undef search_constant_type_c::constant_int_type_name |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
169 |
#undef next |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
170 |
#undef search |
181 | 171 |
#undef compute_standard_function_default |
172 |
#undef compute_standard_function_il |
|
173 |
||
174 |
/*static bool_type_name_c bool_type_name;*/ |
|
175 |
||
176 |
/* A helper function... */ |
|
177 |
void *search_expression_type_c::compute_boolean_expression(symbol_c *left_type, symbol_c *right_type) { |
|
178 |
if (!is_same_type(left_type, right_type)) |
|
179 |
ERROR; |
|
180 |
if (!is_bool_type(left_type) && !is_binary_type(left_type)) |
|
181 |
ERROR; |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
182 |
if (is_literal_integer_type(left_type)) {return (void *)right_type;} |
181 | 183 |
else {return (void *)left_type;} |
184 |
} |
|
185 |
||
186 |
/* A helper function... */ |
|
187 |
void *search_expression_type_c::compute_numeric_expression(symbol_c *left_type, symbol_c *right_type) { |
|
188 |
if (!is_same_type(left_type, right_type)) |
|
189 |
ERROR; |
|
190 |
if (!is_integer_type(left_type) && !is_real_type(left_type)) |
|
191 |
ERROR; |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
196
diff
changeset
|
192 |
if (is_literal_integer_type(left_type) || is_literal_real_type(left_type)) {return (void *)right_type;} |
181 | 193 |
else {return (void *)left_type;} |
194 |
return NULL; |
|
195 |
} |
|
196 |
||
197 |
/* a helper function... */ |
|
198 |
symbol_c *search_expression_type_c::base_type(symbol_c *symbol) { |
|
199 |
return (symbol_c *)symbol->accept(search_base_type); |
|
200 |
} |
|
201 |
||
202 |
/*********************/ |
|
203 |
/* B 1.4 - Variables */ |
|
204 |
/*********************/ |
|
205 |
||
206 |
void *search_expression_type_c::visit(symbolic_variable_c *symbol) { |
|
207 |
symbol_c *res; |
|
208 |
||
209 |
/* Nope, now we assume it is a variable, and determine its type... */ |
|
210 |
res = search_varfb_instance_type->get_type(symbol); |
|
211 |
if (NULL != res) return res; |
|
212 |
||
213 |
return NULL; |
|
214 |
} |
|
215 |
||
216 |
/********************************************/ |
|
217 |
/* B 1.4.1 - Directly Represented Variables */ |
|
218 |
/********************************************/ |
|
219 |
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
|
220 |
symbol_c *res; |
1c0c7a664fc2
Fix problems with direct variables in expression while compiling resulting expression type
lbessard
parents:
194
diff
changeset
|
221 |
|
1c0c7a664fc2
Fix problems with direct variables in expression while compiling resulting expression type
lbessard
parents:
194
diff
changeset
|
222 |
/* 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
|
223 |
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
|
224 |
if (NULL != res) return res; |
1c0c7a664fc2
Fix problems with direct variables in expression while compiling resulting expression type
lbessard
parents:
194
diff
changeset
|
225 |
|
1c0c7a664fc2
Fix problems with direct variables in expression while compiling resulting expression type
lbessard
parents:
194
diff
changeset
|
226 |
return NULL; |
181 | 227 |
} |
228 |
||
229 |
/*************************************/ |
|
230 |
/* B 1.4.2 - Multi-element variables */ |
|
231 |
/*************************************/ |
|
232 |
||
233 |
void *search_expression_type_c::visit(array_variable_c *symbol) { |
|
234 |
symbol_c *res; |
|
235 |
||
236 |
/* Nope, now we assume it is a variable, and determine its type... */ |
|
237 |
res = search_varfb_instance_type->get_type(symbol); |
|
238 |
if (NULL != res) return res; |
|
239 |
||
240 |
return NULL; |
|
241 |
} |
|
242 |
||
243 |
void *search_expression_type_c::visit(structured_variable_c *symbol) { |
|
244 |
symbol_c *res; |
|
245 |
||
246 |
/* Nope, now we assume it is a variable, and determine its type... */ |
|
247 |
res = search_varfb_instance_type->get_type(symbol); |
|
248 |
if (NULL != res) return res; |
|
249 |
||
250 |
return NULL; |
|
251 |
} |
|
252 |
||
253 |
/***************************************/ |
|
254 |
/* B.3 - Language ST (Structured Text) */ |
|
255 |
/***************************************/ |
|
256 |
/***********************/ |
|
257 |
/* B 3.1 - Expressions */ |
|
258 |
/***********************/ |
|
259 |
void *search_expression_type_c::visit(or_expression_c *symbol) { |
|
260 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this)); |
|
261 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this)); |
|
262 |
return compute_boolean_expression(left_type, right_type); |
|
263 |
} |
|
264 |
||
265 |
void *search_expression_type_c::visit(xor_expression_c *symbol) { |
|
266 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this)); |
|
267 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this)); |
|
268 |
return compute_boolean_expression(left_type, right_type); |
|
269 |
} |
|
270 |
||
271 |
void *search_expression_type_c::visit(and_expression_c *symbol) { |
|
272 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this)); |
|
273 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this)); |
|
274 |
return compute_boolean_expression(left_type, right_type); |
|
275 |
} |
|
276 |
||
277 |
void *search_expression_type_c::visit(equ_expression_c *symbol) {return (void *)&bool_type_name;} |
|
278 |
void *search_expression_type_c::visit(notequ_expression_c *symbol) {return (void *)&bool_type_name;} |
|
279 |
void *search_expression_type_c::visit(lt_expression_c *symbol) {return (void *)&bool_type_name;} |
|
280 |
void *search_expression_type_c::visit(gt_expression_c *symbol) {return (void *)&bool_type_name;} |
|
281 |
void *search_expression_type_c::visit(le_expression_c *symbol) {return (void *)&bool_type_name;} |
|
282 |
void *search_expression_type_c::visit(ge_expression_c *symbol) {return (void *)&bool_type_name;} |
|
283 |
||
284 |
void *search_expression_type_c::visit(add_expression_c *symbol) { |
|
285 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this)); |
|
286 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this)); |
|
287 |
if (typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&time_type_name;} |
|
288 |
if (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&tod_type_name;} |
|
289 |
if (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&dt_type_name;} |
|
290 |
return compute_numeric_expression(left_type, right_type); |
|
291 |
} |
|
292 |
||
293 |
void *search_expression_type_c::visit(sub_expression_c *symbol) { |
|
294 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this)); |
|
295 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this)); |
|
296 |
if (typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&time_type_name;} |
|
297 |
if (typeid(*left_type) == typeid(date_type_name_c) && typeid(*right_type) == typeid(date_type_name_c)) {return (void *)&time_type_name;} |
|
298 |
if (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&tod_type_name;} |
|
299 |
if (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(tod_type_name_c)) {return (void *)&time_type_name;} |
|
300 |
if (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) {return (void *)&dt_type_name;} |
|
301 |
if (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(dt_type_name_c)) {return (void *)&time_type_name;} |
|
302 |
return compute_numeric_expression(left_type, right_type); |
|
303 |
} |
|
304 |
||
305 |
void *search_expression_type_c::visit(mul_expression_c *symbol) { |
|
306 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this)); |
|
307 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this)); |
|
308 |
if (typeid(*left_type) == typeid(time_type_name_c) && is_num_type(right_type)) { |
|
309 |
return (void *)&time_type_name; |
|
310 |
} |
|
311 |
return compute_numeric_expression(left_type, right_type); |
|
312 |
} |
|
313 |
||
314 |
void *search_expression_type_c::visit(div_expression_c *symbol) { |
|
315 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this)); |
|
316 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this)); |
|
317 |
if (typeid(*left_type) == typeid(time_type_name_c) && is_num_type(right_type)){ |
|
318 |
return (void *)&time_type_name; |
|
319 |
} |
|
320 |
return compute_numeric_expression(left_type, right_type); |
|
321 |
} |
|
322 |
||
323 |
void *search_expression_type_c::visit(mod_expression_c *symbol) { |
|
324 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this)); |
|
325 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this)); |
|
326 |
return compute_numeric_expression(left_type, right_type); |
|
327 |
} |
|
328 |
||
329 |
void *search_expression_type_c::visit(power_expression_c *symbol) { |
|
330 |
symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this)); |
|
331 |
symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this)); |
|
332 |
if (is_real_type(left_type) && is_num_type(right_type)) { |
|
333 |
return (void *)left_type; |
|
334 |
} |
|
335 |
ERROR; |
|
336 |
return NULL; |
|
337 |
} |
|
338 |
||
339 |
void *search_expression_type_c::visit(neg_expression_c *symbol) { |
|
340 |
symbol_c *exp_type = base_type((symbol_c *)symbol->exp->accept(*this)); |
|
341 |
if (is_num_type(exp_type) || typeid(*exp_type) == typeid(time_type_name_c)){ |
|
342 |
return (void *)exp_type; |
|
343 |
} |
|
344 |
ERROR; |
|
345 |
return NULL; |
|
346 |
} |
|
347 |
||
348 |
void *search_expression_type_c::visit(not_expression_c *symbol) { |
|
349 |
symbol_c *exp_type = base_type((symbol_c *)symbol->exp->accept(*this)); |
|
350 |
return compute_boolean_expression(exp_type, exp_type); |
|
351 |
} |
|
352 |
||
353 |
void *search_expression_type_c::visit(function_invocation_c *symbol) { |
|
354 |
function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
|
355 |
if (f_decl == function_symtable.end_value()) { |
|
356 |
void *res = compute_standard_function_default(symbol); |
|
357 |
if (res == NULL) |
|
358 |
ERROR; |
|
359 |
return res; |
|
360 |
} |
|
361 |
return base_type(f_decl->type_name); |
|
362 |
} |
|
363 |
||
364 |
/*bool_type_name_c search_expression_type_c::bool_type_name;*/ |
|
365 |