90 #include "absyntax_utils.hh" |
90 #include "absyntax_utils.hh" |
91 |
91 |
92 |
92 |
93 |
93 |
94 |
94 |
95 /**********************************************/ |
|
96 /* A small helper visitor class, that will */ |
|
97 /* return the name of a variable, as it will */ |
|
98 /* appear in the variable declaration. */ |
|
99 /**********************************************/ |
|
100 /* For ex.: |
|
101 * VAR |
|
102 * A : int; |
|
103 * B : ARRAY [1..9] of int; |
|
104 * C : some_struct_t; |
|
105 * END_VAR |
|
106 * |
|
107 * A := 56; |
|
108 * B[8] := 99; |
|
109 * C.e := 77; |
|
110 * |
|
111 * Calling this visitor class with symbolic_variable_c instance referencing 'A' in |
|
112 * the line 'A := 56', will return the string "A". |
|
113 * |
|
114 * Calling this visitor class with array_variable_c instance referencing 'B[8]' in |
|
115 * the line 'B[8] := 99', will return the string "B". |
|
116 * |
|
117 * Calling this visitor class with array_variable_c instance referencing 'C.e' in |
|
118 * the line 'C.e := 77', will return the string "C". |
|
119 */ |
|
120 class get_var_name_c : public search_visitor_c { |
|
121 private: |
|
122 static get_var_name_c *singleton_instance_; |
|
123 public: |
|
124 get_var_name_c(void) {}; |
|
125 ~get_var_name_c(void) {}; |
|
126 |
|
127 static token_c *get_name(symbol_c *symbol) { |
|
128 if (NULL == singleton_instance_) singleton_instance_ = new get_var_name_c(); |
|
129 if (NULL == singleton_instance_) ERROR; |
|
130 |
|
131 return (token_c *)(symbol->accept(*singleton_instance_)); |
|
132 } |
|
133 |
|
134 private: |
|
135 /*************************/ |
|
136 /* B.1 - Common elements */ |
|
137 /*************************/ |
|
138 /*******************************************/ |
|
139 /* B 1.1 - Letters, digits and identifiers */ |
|
140 /*******************************************/ |
|
141 // SYM_TOKEN(identifier_c) |
|
142 void *visit(identifier_c *symbol); |
|
143 |
|
144 /*********************/ |
|
145 /* B 1.4 - Variables */ |
|
146 /*********************/ |
|
147 // SYM_REF2(symbolic_variable_c, var_name, unused) |
|
148 void *visit(symbolic_variable_c *symbol); |
|
149 |
|
150 /********************************************/ |
|
151 /* B.1.4.1 Directly Represented Variables */ |
|
152 /********************************************/ |
|
153 // SYM_TOKEN(direct_variable_c) |
|
154 // void *visit(direct_variable_c *symbol); |
|
155 |
|
156 /*************************************/ |
|
157 /* B.1.4.2 Multi-element Variables */ |
|
158 /*************************************/ |
|
159 /* subscripted_variable '[' subscript_list ']' */ |
|
160 // SYM_REF2(array_variable_c, subscripted_variable, subscript_list) |
|
161 void *visit(array_variable_c *symbol); |
|
162 |
|
163 /* subscript_list ',' subscript */ |
|
164 // SYM_LIST(subscript_list_c) |
|
165 // void *visit(subscript_list_c *symbol); |
|
166 |
|
167 /* record_variable '.' field_selector */ |
|
168 /* WARNING: input and/or output variables of function blocks |
|
169 * may be accessed as fields of a tructured variable! |
|
170 * Code handling a structured_variable_c must take |
|
171 * this into account! |
|
172 */ |
|
173 // SYM_REF2(structured_variable_c, record_variable, field_selector) |
|
174 void *visit(structured_variable_c *symbol); |
|
175 }; |
|
176 |
|
177 get_var_name_c *get_var_name_c::singleton_instance_ = NULL; |
|
178 |
|
179 |
|
180 |
|
181 /*************************/ |
|
182 /* B.1 - Common elements */ |
|
183 /*************************/ |
|
184 /*******************************************/ |
|
185 /* B 1.1 - Letters, digits and identifiers */ |
|
186 /*******************************************/ |
|
187 // SYM_TOKEN(identifier_c) |
|
188 void *get_var_name_c::visit(identifier_c *symbol) {return (void *)symbol;} |
|
189 |
|
190 /*********************/ |
|
191 /* B 1.4 - Variables */ |
|
192 /*********************/ |
|
193 // SYM_REF2(symbolic_variable_c, var_name, unused) |
|
194 void *get_var_name_c::visit(symbolic_variable_c *symbol) {return symbol->var_name->accept(*this);} |
|
195 |
|
196 /********************************************/ |
|
197 /* B.1.4.1 Directly Represented Variables */ |
|
198 /********************************************/ |
|
199 // SYM_TOKEN(direct_variable_c) |
|
200 |
|
201 /*************************************/ |
|
202 /* B.1.4.2 Multi-element Variables */ |
|
203 /*************************************/ |
|
204 /* subscripted_variable '[' subscript_list ']' */ |
|
205 // SYM_REF2(array_variable_c, subscripted_variable, subscript_list) |
|
206 void *get_var_name_c::visit(array_variable_c *symbol) {return symbol->subscripted_variable->accept(*this);} |
|
207 |
|
208 /* subscript_list ',' subscript */ |
|
209 // SYM_LIST(subscript_list_c) |
|
210 |
|
211 /* record_variable '.' field_selector */ |
|
212 /* WARNING: input and/or output variables of function blocks |
|
213 * may be accessed as fields of a tructured variable! |
|
214 * Code handling a structured_variable_c must take |
|
215 * this into account! |
|
216 */ |
|
217 // SYM_REF2(structured_variable_c, record_variable, field_selector) |
|
218 void *get_var_name_c::visit(structured_variable_c *symbol) {return symbol->record_variable->accept(*this);} |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
95 |
230 search_var_instance_decl_c::search_var_instance_decl_c(symbol_c *search_scope) { |
96 search_var_instance_decl_c::search_var_instance_decl_c(symbol_c *search_scope) { |
231 this->current_vartype = none_vt; |
97 this->current_vartype = none_vt; |
232 this->search_scope = search_scope; |
98 this->search_scope = search_scope; |
233 this->search_name = NULL; |
99 this->search_name = NULL; |