author | Mario de Sousa <msousa@fe.up.pt> |
Sat, 09 Jul 2011 14:17:52 +0100 | |
changeset 339 | 06b561479e46 |
parent 326 | e3fbf97d2021 |
child 367 | 6d94128ba5ad |
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:
238
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:
238
diff
changeset
|
3 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
238
diff
changeset
|
4 |
* Copyright (C) 2003-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:
265
diff
changeset
|
5 |
* Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant |
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
238
diff
changeset
|
6 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
238
diff
changeset
|
7 |
* 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:
238
diff
changeset
|
8 |
* 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:
238
diff
changeset
|
9 |
* 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:
238
diff
changeset
|
10 |
* (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:
238
diff
changeset
|
11 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
238
diff
changeset
|
12 |
* 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:
238
diff
changeset
|
13 |
* 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:
238
diff
changeset
|
14 |
* 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:
238
diff
changeset
|
15 |
* 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:
238
diff
changeset
|
16 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
238
diff
changeset
|
17 |
* 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:
238
diff
changeset
|
18 |
* 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:
238
diff
changeset
|
19 |
* |
181 | 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 |
/* |
|
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
238
diff
changeset
|
26 |
* An IEC 61131-3 compiler. |
181 | 27 |
* |
28 |
* Based on the |
|
29 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
30 |
* |
|
31 |
*/ |
|
32 |
||
33 |
/* Determine the data type of a variable. |
|
34 |
* The variable may be a simple variable, a function block instance, a |
|
35 |
* struture element within a data structured type (a struct or a fb), or |
|
36 |
* an array element. |
|
37 |
* A mixture of array element of a structure element of a structure element |
|
38 |
* of a .... is also suported! |
|
39 |
* |
|
40 |
* example: |
|
41 |
* window.points[1].coordinate.x |
|
42 |
* window.points[1].colour |
|
43 |
* etc... ARE ALLOWED! |
|
44 |
* |
|
45 |
* This class must be passed the scope within which the |
|
46 |
* variable was declared, and the variable name... |
|
321
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
47 |
* |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
48 |
* |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
49 |
* |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
50 |
* |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
51 |
* |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
52 |
* This class has several members, depending on the exact data the caller |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
53 |
* is looking for... |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
54 |
* |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
55 |
* - item i: we can get either the name of the data type(A), |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
56 |
* or it's declaration (B) |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
57 |
* (notice however that some variables belong to a data type that does |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
58 |
* not have a name, only a declaration as in |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
59 |
* VAR a: ARRAY [1..3] of INT; END_VAR |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
60 |
* ) |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
61 |
* - item ii: we can get either the direct data type (1), |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
62 |
* or the base type (2) |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
63 |
* |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
64 |
* By direct type, I mean the data type of the variable. By base type, I |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
65 |
* mean the data type on which the direct type is based on. For example, in |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
66 |
* a subrange on INT, the direct type is the subrange itself, while the |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
67 |
* base type is INT. |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
68 |
* e.g. |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
69 |
* This means that if we find that the variable is of type MY_INT, |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
70 |
* which was previously declared to be |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
71 |
* TYPE MY_INT: INT := 9; |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
72 |
* option (1) will return MY_INT |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
73 |
* option (2) will return INT |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
74 |
* |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
75 |
* |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
76 |
* Member functions: |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
77 |
* ================ |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
78 |
* get_basetype_decl() ---> returns 2B |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
79 |
* get_type_id() ---> returns 1A |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
80 |
* |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
81 |
* Since we haven't yet needed them, we don't yet implement |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
82 |
* get_basetype_id() ----> would return 2A |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
83 |
* get_type_decl() ----> would return 1B |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
84 |
*/ |
181 | 85 |
|
86 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
87 |
/* |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
88 |
* TODO: this code has a memory leak... |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
89 |
* We call 'new' in several locations, but bever get to 'delete' the object instances... |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
90 |
*/ |
181 | 91 |
#include "absyntax_utils.hh" |
92 |
||
93 |
||
94 |
search_varfb_instance_type_c::search_varfb_instance_type_c(symbol_c *search_scope): search_var_instance_decl(search_scope) { |
|
95 |
this->decompose_var_instance_name = NULL; |
|
96 |
this->current_structelement_name = NULL; |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
202
diff
changeset
|
97 |
this->current_rawtype = NULL; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
202
diff
changeset
|
98 |
} |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
202
diff
changeset
|
99 |
|
321
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
100 |
symbol_c *search_varfb_instance_type_c::get_basetype_decl(symbol_c *variable_name) { |
181 | 101 |
this->current_structelement_name = NULL; |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
202
diff
changeset
|
102 |
this->current_rawtype = NULL; |
181 | 103 |
this->decompose_var_instance_name = new decompose_var_instance_name_c(variable_name); |
104 |
if (NULL == decompose_var_instance_name) ERROR; |
|
105 |
||
106 |
/* find the part of the variable name that will appear in the |
|
107 |
* variable declaration, for e.g., in window.point.x, this would be |
|
108 |
* window! |
|
109 |
*/ |
|
110 |
symbol_c *var_name_part = decompose_var_instance_name->next_part(); |
|
111 |
if (NULL == var_name_part) ERROR; |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
112 |
|
181 | 113 |
/* Now we try to find the variable instance declaration, to determine its type... */ |
114 |
symbol_c *var_decl = search_var_instance_decl.get_decl(var_name_part); |
|
115 |
if (NULL == var_decl) { |
|
116 |
/* variable instance declaration not found! */ |
|
117 |
ERROR; |
|
118 |
} |
|
119 |
||
120 |
/* if it is a struct or function block, we must search the type |
|
121 |
* of the struct or function block member. |
|
122 |
* This is done by this class visiting the var_decl. |
|
123 |
* This class, while visiting, will recursively call |
|
124 |
* decompose_var_instance_name->get_next() when and if required... |
|
125 |
*/ |
|
126 |
symbol_c *res = (symbol_c *)var_decl->accept(*this); |
|
127 |
if (NULL == res) ERROR; |
|
128 |
||
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
202
diff
changeset
|
129 |
/* make sure that we have decomposed all structure elements of the variable name */ |
181 | 130 |
symbol_c *var_name = decompose_var_instance_name->next_part(); |
131 |
if (NULL != var_name) ERROR; |
|
132 |
||
133 |
return res; |
|
134 |
} |
|
135 |
||
136 |
unsigned int search_varfb_instance_type_c::get_vartype(symbol_c *variable_name) { |
|
137 |
this->current_structelement_name = NULL; |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
202
diff
changeset
|
138 |
this->current_rawtype = NULL; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
202
diff
changeset
|
139 |
this->is_complex = false; |
181 | 140 |
this->decompose_var_instance_name = new decompose_var_instance_name_c(variable_name); |
141 |
if (NULL == decompose_var_instance_name) ERROR; |
|
142 |
||
143 |
/* find the part of the variable name that will appear in the |
|
144 |
* variable declaration, for e.g., in window.point.x, this would be |
|
145 |
* window! |
|
146 |
*/ |
|
147 |
symbol_c *var_name_part = decompose_var_instance_name->next_part(); |
|
148 |
if (NULL == var_name_part) ERROR; |
|
149 |
||
150 |
/* Now we try to find the variable instance declaration, to determine its type... */ |
|
151 |
symbol_c *var_decl = search_var_instance_decl.get_decl(var_name_part); |
|
152 |
if (NULL == var_decl) { |
|
153 |
/* variable instance declaration not found! */ |
|
154 |
return 0; |
|
155 |
} |
|
156 |
||
157 |
/* if it is a struct or function block, we must search the type |
|
158 |
* of the struct or function block member. |
|
159 |
* This is done by this class visiting the var_decl. |
|
160 |
* This class, while visiting, will recursively call |
|
161 |
* decompose_var_instance_name->get_next() when and if required... |
|
162 |
*/ |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
202
diff
changeset
|
163 |
var_decl->accept(*this); |
181 | 164 |
unsigned int res = search_var_instance_decl.get_vartype(); |
165 |
||
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
202
diff
changeset
|
166 |
/* make sure that we have decomposed all structure elements of the variable name */ |
181 | 167 |
symbol_c *var_name = decompose_var_instance_name->next_part(); |
168 |
if (NULL != var_name) ERROR; |
|
169 |
||
170 |
return res; |
|
171 |
} |
|
172 |
||
321
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
173 |
symbol_c *search_varfb_instance_type_c::get_type_id(symbol_c *variable_name) { |
326
e3fbf97d2021
Fix what I think is a bug (has not yet manifested itself).
Mario de Sousa <msousa@fe.up.pt>
parents:
321
diff
changeset
|
174 |
this->current_rawtype = NULL; |
321
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
175 |
symbol_c *rawtype = this->get_basetype_decl(variable_name); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
202
diff
changeset
|
176 |
if (this->current_rawtype != NULL) |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
202
diff
changeset
|
177 |
return this->current_rawtype; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
202
diff
changeset
|
178 |
else |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
202
diff
changeset
|
179 |
return rawtype; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
202
diff
changeset
|
180 |
} |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
202
diff
changeset
|
181 |
|
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
202
diff
changeset
|
182 |
bool search_varfb_instance_type_c::type_is_complex(void) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
202
diff
changeset
|
183 |
return this->is_complex; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
202
diff
changeset
|
184 |
} |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
202
diff
changeset
|
185 |
|
181 | 186 |
/* a helper function... */ |
187 |
void *search_varfb_instance_type_c::visit_list(list_c *list) { |
|
188 |
if (NULL == current_structelement_name) ERROR; |
|
189 |
||
190 |
for(int i = 0; i < list->n; i++) { |
|
191 |
void *res = list->elements[i]->accept(*this); |
|
192 |
if (res != NULL) |
|
193 |
return res; |
|
194 |
} |
|
195 |
/* not found! */ |
|
196 |
return NULL; |
|
197 |
} |
|
198 |
||
199 |
/* a helper function... */ |
|
200 |
void *search_varfb_instance_type_c::base_type(symbol_c *symbol) { |
|
201 |
search_base_type_c search_base_type; |
|
202 |
return symbol->accept(search_base_type); |
|
203 |
} |
|
204 |
||
205 |
/* We override the base class' visitor to identifier_c. |
|
206 |
* This is so because the base class does not consider a function block |
|
207 |
* to be a type, unlike this class that allows a variable instance |
|
208 |
* of a function block type... |
|
209 |
*/ |
|
210 |
void *search_varfb_instance_type_c::visit(identifier_c *type_name) { |
|
211 |
/* look up the type declaration... */ |
|
212 |
symbol_c *fb_decl = function_block_type_symtable.find_value(type_name); |
|
213 |
if (fb_decl != function_block_type_symtable.end_value()) |
|
214 |
/* Type declaration found!! */ |
|
215 |
return fb_decl->accept(*this); |
|
216 |
||
235 | 217 |
this->current_rawtype = type_name; |
218 |
||
181 | 219 |
/* No. It is not a function block, so we let |
220 |
* the base class take care of it... |
|
221 |
*/ |
|
238
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
235
diff
changeset
|
222 |
if (NULL == decompose_var_instance_name->next_part(false)) { |
235 | 223 |
return base_type(type_name); |
224 |
} |
|
238
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
235
diff
changeset
|
225 |
else { |
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
235
diff
changeset
|
226 |
return search_base_type_c::visit(type_name); |
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
235
diff
changeset
|
227 |
} |
181 | 228 |
} |
229 |
||
230 |
/********************************/ |
|
231 |
/* B 1.3.3 - Derived data types */ |
|
232 |
/********************************/ |
|
233 |
||
234 |
/* identifier ':' array_spec_init */ |
|
235 |
void *search_varfb_instance_type_c::visit(array_type_declaration_c *symbol) { |
|
238
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
235
diff
changeset
|
236 |
this->is_complex = true; |
181 | 237 |
return symbol->array_spec_init->accept(*this); |
238 |
} |
|
239 |
||
238
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
235
diff
changeset
|
240 |
/* array_specification [ASSIGN array_initialization] */ |
181 | 241 |
/* array_initialization may be NULL ! */ |
242 |
void *search_varfb_instance_type_c::visit(array_spec_init_c *symbol) { |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
202
diff
changeset
|
243 |
this->is_complex = true; |
181 | 244 |
return symbol->array_specification->accept(*this); |
245 |
} |
|
238
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
235
diff
changeset
|
246 |
|
181 | 247 |
/* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */ |
248 |
void *search_varfb_instance_type_c::visit(array_specification_c *symbol) { |
|
235 | 249 |
this->is_complex = true; |
181 | 250 |
return symbol->non_generic_type_name->accept(*this); |
251 |
} |
|
252 |
||
253 |
/* structure_type_name ':' structure_specification */ |
|
254 |
void *search_varfb_instance_type_c::visit(structure_type_declaration_c *symbol) { |
|
235 | 255 |
this->is_complex = true; |
181 | 256 |
return symbol->structure_specification->accept(*this); |
257 |
/* NOTE: structure_specification will point to either a |
|
258 |
* initialized_structure_c |
|
259 |
* OR A |
|
260 |
* structure_element_declaration_list_c |
|
261 |
*/ |
|
262 |
} |
|
263 |
||
264 |
/* structure_type_name ASSIGN structure_initialization */ |
|
265 |
/* structure_initialization may be NULL ! */ |
|
266 |
// SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization) |
|
267 |
void *search_varfb_instance_type_c::visit(initialized_structure_c *symbol) { |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
202
diff
changeset
|
268 |
this->is_complex = true; |
181 | 269 |
/* recursively find out the data type of var_name... */ |
270 |
return symbol->structure_type_name->accept(*this); |
|
271 |
} |
|
272 |
||
273 |
/* helper symbol for structure_declaration */ |
|
274 |
/* structure_declaration: STRUCT structure_element_declaration_list END_STRUCT */ |
|
275 |
/* structure_element_declaration_list structure_element_declaration ';' */ |
|
276 |
void *search_varfb_instance_type_c::visit(structure_element_declaration_list_c *symbol) { |
|
238
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
235
diff
changeset
|
277 |
/* make sure that we have decomposed all structure elements of the variable name */ |
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
235
diff
changeset
|
278 |
current_structelement_name = decompose_var_instance_name->next_part(); |
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
235
diff
changeset
|
279 |
/* now search the structure declaration */ |
181 | 280 |
return visit_list(symbol); |
281 |
} |
|
282 |
||
283 |
/* structure_element_name ':' spec_init */ |
|
284 |
void *search_varfb_instance_type_c::visit(structure_element_declaration_c *symbol) { |
|
285 |
if (NULL == current_structelement_name) ERROR; |
|
286 |
||
287 |
if (compare_identifiers(symbol->structure_element_name, current_structelement_name) == 0) |
|
288 |
return symbol->spec_init->accept(*this); |
|
289 |
||
290 |
return NULL; |
|
291 |
} |
|
292 |
||
293 |
/* helper symbol for structure_initialization */ |
|
294 |
/* structure_initialization: '(' structure_element_initialization_list ')' */ |
|
295 |
/* structure_element_initialization_list ',' structure_element_initialization */ |
|
296 |
void *search_varfb_instance_type_c::visit(structure_element_initialization_list_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
|
297 |
/* structure_element_name ASSIGN value */ |
|
298 |
void *search_varfb_instance_type_c::visit(structure_element_initialization_c *symbol) {ERROR; return NULL;} /* should never get called... */ |
|
299 |
||
300 |
||
301 |
||
302 |
/**************************************/ |
|
303 |
/* B.1.5 - Program organization units */ |
|
304 |
/**************************************/ |
|
305 |
/*****************************/ |
|
306 |
/* B 1.5.2 - Function Blocks */ |
|
307 |
/*****************************/ |
|
308 |
/* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ |
|
309 |
// SYM_REF4(function_block_declaration_c, fblock_name, var_declarations, fblock_body, unused) |
|
310 |
void *search_varfb_instance_type_c::visit(function_block_declaration_c *symbol) { |
|
311 |
/* make sure that we have decomposed all strcuture elements of the variable name */ |
|
312 |
||
313 |
symbol_c *var_name = decompose_var_instance_name->next_part(); |
|
314 |
if (NULL == var_name) { |
|
315 |
/* this is it... ! |
|
316 |
* No need to look any further... |
|
317 |
* Note also that, unlike for the struct types, a function block may |
|
318 |
* not be defined based on another (i.e. no inheritance is allowed), |
|
319 |
* so this function block is already the most base type. |
|
320 |
* We simply return it. |
|
321 |
*/ |
|
322 |
return (void *)symbol; |
|
323 |
} |
|
324 |
||
325 |
/* now search the function block declaration for the variable... */ |
|
326 |
search_var_instance_decl_c search_decl(symbol); |
|
327 |
symbol_c *var_decl = search_decl.get_decl(var_name); |
|
328 |
if (NULL == var_decl) { |
|
329 |
/* variable instance declaration not found! */ |
|
330 |
return NULL; |
|
331 |
} |
|
332 |
||
333 |
/* We have found the declaration. |
|
334 |
* Should we look any further? |
|
335 |
*/ |
|
336 |
var_name = decompose_var_instance_name->next_part(); |
|
337 |
if (NULL == var_name) { |
|
338 |
/* this is it... ! */ |
|
339 |
return base_type(var_decl); |
|
340 |
} |
|
341 |
||
342 |
current_structelement_name = var_name; |
|
343 |
/* recursively find out the data type of var_name... */ |
|
344 |
return symbol->var_declarations->accept(*this); |
|
345 |
} |