93 |
93 |
94 search_varfb_instance_type_c::search_varfb_instance_type_c(symbol_c *search_scope): search_var_instance_decl(search_scope) { |
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; |
95 this->decompose_var_instance_name = NULL; |
96 this->current_structelement_name = NULL; |
96 this->current_structelement_name = NULL; |
97 this->current_typeid = NULL; |
97 this->current_typeid = NULL; |
98 } |
98 this->current_basetypeid = NULL; |
99 |
99 } |
100 symbol_c *search_varfb_instance_type_c::get_basetype_decl(symbol_c *variable_name) { |
100 |
|
101 symbol_c *search_varfb_instance_type_c::get_type_decl(symbol_c *variable_name) { |
101 this->current_structelement_name = NULL; |
102 this->current_structelement_name = NULL; |
102 this->current_typeid = NULL; |
103 this->current_typeid = NULL; |
|
104 this->current_basetypeid = NULL; |
103 this->decompose_var_instance_name = new decompose_var_instance_name_c(variable_name); |
105 this->decompose_var_instance_name = new decompose_var_instance_name_c(variable_name); |
104 if (NULL == decompose_var_instance_name) ERROR; |
106 if (NULL == decompose_var_instance_name) ERROR; |
105 |
107 |
106 /* find the part of the variable name that will appear in the |
108 /* 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 |
109 * variable declaration, for e.g., in window.point.x, this would be |
110 symbol_c *var_name_part = decompose_var_instance_name->next_part(); |
112 symbol_c *var_name_part = decompose_var_instance_name->next_part(); |
111 if (NULL == var_name_part) ERROR; |
113 if (NULL == var_name_part) ERROR; |
112 |
114 |
113 /* Now we try to find the variable instance declaration, to determine its type... */ |
115 /* 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); |
116 symbol_c *var_decl = search_var_instance_decl.get_decl(var_name_part); |
115 if (NULL == var_decl) { |
117 if (NULL == var_decl) ERROR; |
116 /* variable instance declaration not found! */ |
|
117 ERROR; |
|
118 } |
|
119 |
118 |
120 /* if it is a struct or function block, we must search the type |
119 /* if it is a struct or function block, we must search the type |
121 * of the struct or function block member. |
120 * of the struct or function block member. |
122 * This is done by this class visiting the var_decl. |
121 * This is done by this class visiting the var_decl. |
123 * This class, while visiting, will recursively call |
122 * This class, while visiting, will recursively call |
142 if (NULL != var_name) return NULL; |
141 if (NULL != var_name) return NULL; |
143 |
142 |
144 return res; |
143 return res; |
145 } |
144 } |
146 |
145 |
|
146 |
|
147 symbol_c *search_varfb_instance_type_c::get_basetype_decl(symbol_c *variable_name) { |
|
148 symbol_c *res = get_type_decl(variable_name); |
|
149 if (NULL == res) return NULL; |
|
150 return (symbol_c *)base_type(res); |
|
151 } |
|
152 |
|
153 |
147 unsigned int search_varfb_instance_type_c::get_vartype(symbol_c *variable_name) { |
154 unsigned int search_varfb_instance_type_c::get_vartype(symbol_c *variable_name) { |
148 this->current_structelement_name = NULL; |
155 this->current_structelement_name = NULL; |
149 this->current_typeid = NULL; |
156 this->current_typeid = NULL; |
|
157 this->current_basetypeid = NULL; |
150 this->is_complex = false; |
158 this->is_complex = false; |
151 this->decompose_var_instance_name = new decompose_var_instance_name_c(variable_name); |
159 this->decompose_var_instance_name = new decompose_var_instance_name_c(variable_name); |
152 if (NULL == decompose_var_instance_name) ERROR; |
160 if (NULL == decompose_var_instance_name) ERROR; |
153 |
161 |
154 /* find the part of the variable name that will appear in the |
162 /* find the part of the variable name that will appear in the |
181 return res; |
189 return res; |
182 } |
190 } |
183 |
191 |
184 symbol_c *search_varfb_instance_type_c::get_type_id(symbol_c *variable_name) { |
192 symbol_c *search_varfb_instance_type_c::get_type_id(symbol_c *variable_name) { |
185 this->current_typeid = NULL; |
193 this->current_typeid = NULL; |
186 symbol_c *vartype = this->get_basetype_decl(variable_name); |
194 symbol_c *vartype = this->get_type_decl(variable_name); |
187 if (this->current_typeid != NULL) |
195 if (this->current_typeid != NULL) |
188 return this->current_typeid; |
196 return this->current_typeid; |
189 else |
197 else |
190 return vartype; |
198 return vartype; |
191 } |
199 } |
217 * This is so because the base class does not consider a function block |
225 * This is so because the base class does not consider a function block |
218 * to be a type, unlike this class that allows a variable instance |
226 * to be a type, unlike this class that allows a variable instance |
219 * of a function block type... |
227 * of a function block type... |
220 */ |
228 */ |
221 void *search_varfb_instance_type_c::visit(identifier_c *type_name) { |
229 void *search_varfb_instance_type_c::visit(identifier_c *type_name) { |
222 this->current_typeid = type_name; |
230 /* we only store the new type id if none had been found yet. |
|
231 * Since we will recursively carry on looking at the base type |
|
232 * to determine the base type declaration and id, we must only set this variable |
|
233 * the first time. |
|
234 * e.g. TYPE myint1_t : int := 1; |
|
235 * myint2_t : int1_t := 2; |
|
236 * myint3_t : int2_t := 3; |
|
237 * END_TYPE; |
|
238 * VAR |
|
239 * myint1 : myint1_t; |
|
240 * myint2 : myint2_t; |
|
241 * myint3 : myint3_t; |
|
242 * END_VAR |
|
243 * |
|
244 * If we ask for typeid of myint3, it must return myint3_t |
|
245 * If we ask for basetypeid of myint3, it must return int |
|
246 * |
|
247 * When determining the data type of myint3, we will recursively go all the way |
|
248 * down to int, but we must still only store myint3_t as the base type id. |
|
249 */ |
|
250 if (NULL == this->current_typeid) |
|
251 this->current_typeid = type_name; |
|
252 this->current_basetypeid = type_name; |
223 |
253 |
224 /* look up the type declaration... */ |
254 /* look up the type declaration... */ |
225 symbol_c *fb_decl = function_block_type_symtable.find_value(type_name); |
255 symbol_c *fb_decl = function_block_type_symtable.find_value(type_name); |
226 if (fb_decl != function_block_type_symtable.end_value()) |
256 if (fb_decl != function_block_type_symtable.end_value()) |
227 /* Type declaration found!! */ |
257 /* Type declaration found!! */ |