54 |
54 |
55 |
55 |
56 search_varfb_instance_type_c::search_varfb_instance_type_c(symbol_c *search_scope): search_var_instance_decl(search_scope) { |
56 search_varfb_instance_type_c::search_varfb_instance_type_c(symbol_c *search_scope): search_var_instance_decl(search_scope) { |
57 this->decompose_var_instance_name = NULL; |
57 this->decompose_var_instance_name = NULL; |
58 this->current_structelement_name = NULL; |
58 this->current_structelement_name = NULL; |
59 this->search_base_type = false; |
59 this->current_rawtype = NULL; |
60 } |
60 } |
61 |
61 |
62 symbol_c *search_varfb_instance_type_c::get_type(symbol_c *variable_name, bool base_type) { |
62 symbol_c *search_varfb_instance_type_c::get_type(symbol_c *variable_name) { |
63 this->current_structelement_name = NULL; |
63 this->current_structelement_name = NULL; |
|
64 this->current_rawtype = NULL; |
64 this->decompose_var_instance_name = new decompose_var_instance_name_c(variable_name); |
65 this->decompose_var_instance_name = new decompose_var_instance_name_c(variable_name); |
65 this->search_base_type = base_type; |
|
66 if (NULL == decompose_var_instance_name) ERROR; |
66 if (NULL == decompose_var_instance_name) ERROR; |
67 |
67 |
68 /* find the part of the variable name that will appear in the |
68 /* find the part of the variable name that will appear in the |
69 * variable declaration, for e.g., in window.point.x, this would be |
69 * variable declaration, for e.g., in window.point.x, this would be |
70 * window! |
70 * window! |
86 * decompose_var_instance_name->get_next() when and if required... |
86 * decompose_var_instance_name->get_next() when and if required... |
87 */ |
87 */ |
88 symbol_c *res = (symbol_c *)var_decl->accept(*this); |
88 symbol_c *res = (symbol_c *)var_decl->accept(*this); |
89 if (NULL == res) ERROR; |
89 if (NULL == res) ERROR; |
90 |
90 |
91 /* make sure that we have decomposed all strcuture elements of the variable name */ |
91 /* make sure that we have decomposed all structure elements of the variable name */ |
92 symbol_c *var_name = decompose_var_instance_name->next_part(); |
92 symbol_c *var_name = decompose_var_instance_name->next_part(); |
93 if (NULL != var_name) ERROR; |
93 if (NULL != var_name) ERROR; |
94 |
94 |
95 return res; |
95 return res; |
96 } |
96 } |
97 |
97 |
98 unsigned int search_varfb_instance_type_c::get_vartype(symbol_c *variable_name) { |
98 unsigned int search_varfb_instance_type_c::get_vartype(symbol_c *variable_name) { |
99 this->current_structelement_name = NULL; |
99 this->current_structelement_name = NULL; |
|
100 this->current_rawtype = NULL; |
|
101 this->is_complex = false; |
100 this->decompose_var_instance_name = new decompose_var_instance_name_c(variable_name); |
102 this->decompose_var_instance_name = new decompose_var_instance_name_c(variable_name); |
101 if (NULL == decompose_var_instance_name) ERROR; |
103 if (NULL == decompose_var_instance_name) ERROR; |
102 |
104 |
103 /* find the part of the variable name that will appear in the |
105 /* find the part of the variable name that will appear in the |
104 * variable declaration, for e.g., in window.point.x, this would be |
106 * variable declaration, for e.g., in window.point.x, this would be |
118 * of the struct or function block member. |
120 * of the struct or function block member. |
119 * This is done by this class visiting the var_decl. |
121 * This is done by this class visiting the var_decl. |
120 * This class, while visiting, will recursively call |
122 * This class, while visiting, will recursively call |
121 * decompose_var_instance_name->get_next() when and if required... |
123 * decompose_var_instance_name->get_next() when and if required... |
122 */ |
124 */ |
|
125 var_decl->accept(*this); |
123 unsigned int res = search_var_instance_decl.get_vartype(); |
126 unsigned int res = search_var_instance_decl.get_vartype(); |
124 |
127 |
125 /* make sure that we have decomposed all strcuture elements of the variable name */ |
128 /* make sure that we have decomposed all structure elements of the variable name */ |
126 symbol_c *var_name = decompose_var_instance_name->next_part(); |
129 symbol_c *var_name = decompose_var_instance_name->next_part(); |
127 if (NULL != var_name) ERROR; |
130 if (NULL != var_name) ERROR; |
128 |
131 |
129 return res; |
132 return res; |
|
133 } |
|
134 |
|
135 symbol_c *search_varfb_instance_type_c::get_rawtype(symbol_c *variable_name) { |
|
136 symbol_c *rawtype = this->get_type(variable_name); |
|
137 if (this->current_rawtype != NULL) |
|
138 return this->current_rawtype; |
|
139 else |
|
140 return rawtype; |
|
141 } |
|
142 |
|
143 bool search_varfb_instance_type_c::type_is_complex(void) { |
|
144 return this->is_complex; |
130 } |
145 } |
131 |
146 |
132 /* a helper function... */ |
147 /* a helper function... */ |
133 void *search_varfb_instance_type_c::visit_list(list_c *list) { |
148 void *search_varfb_instance_type_c::visit_list(list_c *list) { |
134 if (NULL == current_structelement_name) ERROR; |
149 if (NULL == current_structelement_name) ERROR; |
161 return fb_decl->accept(*this); |
176 return fb_decl->accept(*this); |
162 |
177 |
163 /* No. It is not a function block, so we let |
178 /* No. It is not a function block, so we let |
164 * the base class take care of it... |
179 * the base class take care of it... |
165 */ |
180 */ |
166 if (this->search_base_type) |
181 this->current_rawtype = type_name; |
|
182 if (current_structelement_name == NULL) |
|
183 return base_type(type_name); |
|
184 else |
167 return search_base_type_c::visit(type_name); |
185 return search_base_type_c::visit(type_name); |
168 else |
|
169 return type_name; |
|
170 } |
186 } |
171 |
187 |
172 /********************************/ |
188 /********************************/ |
173 /* B 1.3.3 - Derived data types */ |
189 /* B 1.3.3 - Derived data types */ |
174 /********************************/ |
190 /********************************/ |
179 } |
195 } |
180 |
196 |
181 /* array_specification [ASSIGN array_initialization} */ |
197 /* array_specification [ASSIGN array_initialization} */ |
182 /* array_initialization may be NULL ! */ |
198 /* array_initialization may be NULL ! */ |
183 void *search_varfb_instance_type_c::visit(array_spec_init_c *symbol) { |
199 void *search_varfb_instance_type_c::visit(array_spec_init_c *symbol) { |
|
200 this->is_complex = true; |
184 symbol_c *var_name = decompose_var_instance_name->next_part(); |
201 symbol_c *var_name = decompose_var_instance_name->next_part(); |
185 if (NULL != var_name) |
202 if (NULL != var_name) |
186 current_structelement_name = var_name; |
203 current_structelement_name = var_name; |
187 return symbol->array_specification->accept(*this); |
204 return symbol->array_specification->accept(*this); |
188 } |
205 } |
207 |
224 |
208 /* structure_type_name ASSIGN structure_initialization */ |
225 /* structure_type_name ASSIGN structure_initialization */ |
209 /* structure_initialization may be NULL ! */ |
226 /* structure_initialization may be NULL ! */ |
210 // SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization) |
227 // SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization) |
211 void *search_varfb_instance_type_c::visit(initialized_structure_c *symbol) { |
228 void *search_varfb_instance_type_c::visit(initialized_structure_c *symbol) { |
212 /* make sure that we have decomposed all strcuture elements of the variable name */ |
229 this->is_complex = true; |
|
230 /* make sure that we have decomposed all structure elements of the variable name */ |
213 symbol_c *var_name = decompose_var_instance_name->next_part(); |
231 symbol_c *var_name = decompose_var_instance_name->next_part(); |
214 if (NULL == var_name) { |
232 if (NULL == var_name) { |
215 /* this is it... ! |
233 /* this is it... ! |
216 * No need to look any further... |
234 * No need to look any further... |
217 */ |
235 */ |