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