|
1 /* |
|
2 * (c) 2003 Mario de Sousa |
|
3 * |
|
4 * Offered to the public under the terms of the GNU General Public License |
|
5 * as published by the Free Software Foundation; either version 2 of the |
|
6 * License, or (at your option) any later version. |
|
7 * |
|
8 * This program is distributed in the hope that it will be useful, but |
|
9 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
11 * Public License for more details. |
|
12 * |
|
13 * This code is made available on the understanding that it will not be |
|
14 * used in safety-critical situations without a full and competent review. |
|
15 */ |
|
16 |
|
17 /* |
|
18 * An IEC 61131-3 IL and ST compiler. |
|
19 * |
|
20 * Based on the |
|
21 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
22 * |
|
23 */ |
|
24 |
|
25 |
|
26 /* Determine the data type of a specific variable instance, including |
|
27 * function block instances. |
|
28 * A reference to the relevant variable declaration is returned. |
|
29 * The variable instance may NOT be a member of a structure of a memeber |
|
30 * of a structure of an element of an array of ... |
|
31 * |
|
32 * example: |
|
33 * window.points[1].coordinate.x |
|
34 * window.points[1].colour |
|
35 * etc... ARE NOT ALLOWED! |
|
36 * |
|
37 * This class must only be passed the name of the variable that will appear |
|
38 * in the variable declaration. In the above examples, this would be |
|
39 * 'window' !! |
|
40 * |
|
41 * |
|
42 * If you need to pass a complete name of a variable instance (such as |
|
43 * 'window.points[1].coordinate.x') use the search_varfb_instance_type_c instead! |
|
44 */ |
|
45 /* Note that current_type_decl that this class returns may reference the |
|
46 * name of a type, or the type declaration itself! |
|
47 * For an example of the first, consider a variable declared as ... |
|
48 * x : AAA; |
|
49 * where the AAA type is previously declared as whatever. |
|
50 * For an example of the second, consider a variable declared as ... |
|
51 * x : array of int [10]; ----> is allowed |
|
52 * |
|
53 * If it is the first, we will return a reference to the name, if the second |
|
54 * we return a reference to the declaration!! |
|
55 */ |
|
56 |
|
57 |
|
58 class search_var_instance_decl_c: public search_visitor_c { |
|
59 |
|
60 private: |
|
61 symbol_c *search_scope; |
|
62 symbol_c *search_name; |
|
63 symbol_c *current_type_decl; |
|
64 |
|
65 /* variable used to store the type of variable currently being processed... */ |
|
66 /* Will contain a single value of generate_c_vardecl_c::XXXX_vt */ |
|
67 unsigned int current_vartype; |
|
68 |
|
69 public: |
|
70 search_var_instance_decl_c(symbol_c *search_scope); |
|
71 symbol_c *get_decl(symbol_c *variable_instance_name); |
|
72 unsigned int get_vartype(); |
|
73 |
|
74 public: |
|
75 |
|
76 /* the types of variables that need to be processed... */ |
|
77 static const unsigned int none_vt = 0x0000; |
|
78 static const unsigned int input_vt = 0x0001; // VAR_INPUT |
|
79 static const unsigned int output_vt = 0x0002; // VAR_OUTPUT |
|
80 static const unsigned int inoutput_vt = 0x0004; // VAR_IN_OUT |
|
81 static const unsigned int private_vt = 0x0008; // VAR |
|
82 static const unsigned int temp_vt = 0x0010; // VAR_TEMP |
|
83 static const unsigned int external_vt = 0x0020; // VAR_EXTERNAL |
|
84 static const unsigned int global_vt = 0x0040; // VAR_GLOBAL |
|
85 static const unsigned int located_vt = 0x0080; // VAR <var_name> AT <location> |
|
86 |
|
87 private: |
|
88 /***************************/ |
|
89 /* B 0 - Programming Model */ |
|
90 /***************************/ |
|
91 void *visit(library_c *symbol); |
|
92 |
|
93 /******************************************/ |
|
94 /* B 1.4.3 - Declaration & Initialisation */ |
|
95 /******************************************/ |
|
96 /* edge -> The F_EDGE or R_EDGE directive */ |
|
97 // SYM_REF2(edge_declaration_c, edge, var1_list) |
|
98 // TODO |
|
99 void *visit(input_declarations_c *symbol); |
|
100 /* VAR_OUTPUT [RETAIN | NON_RETAIN] var_init_decl_list END_VAR */ |
|
101 /* option -> may be NULL ! */ |
|
102 void *visit(output_declarations_c *symbol); |
|
103 /* VAR_IN_OUT var_declaration_list END_VAR */ |
|
104 void *visit(input_output_declarations_c *symbol); |
|
105 /* VAR [CONSTANT] var_init_decl_list END_VAR */ |
|
106 /* option -> may be NULL ! */ |
|
107 /* helper symbol for input_declarations */ |
|
108 void *visit(var_declarations_c *symbol); |
|
109 /* VAR RETAIN var_init_decl_list END_VAR */ |
|
110 void *visit(retentive_var_declarations_c *symbol); |
|
111 /* VAR [CONSTANT|RETAIN|NON_RETAIN] located_var_decl_list END_VAR */ |
|
112 /* option -> may be NULL ! */ |
|
113 //SYM_REF2(located_var_declarations_c, option, located_var_decl_list) |
|
114 void *visit(located_var_declarations_c *symbol); |
|
115 /*| VAR_EXTERNAL [CONSTANT] external_declaration_list END_VAR */ |
|
116 /* option -> may be NULL ! */ |
|
117 //SYM_REF2(external_var_declarations_c, option, external_declaration_list) |
|
118 void *visit(external_var_declarations_c *symbol); |
|
119 /*| VAR_GLOBAL [CONSTANT|RETAIN] global_var_decl_list END_VAR */ |
|
120 /* option -> may be NULL ! */ |
|
121 //SYM_REF2(global_var_declarations_c, option, global_var_decl_list) |
|
122 void *visit(global_var_declarations_c *symbol); |
|
123 /* var1_list is one of the following... |
|
124 * simple_spec_init_c * |
|
125 * subrange_spec_init_c * |
|
126 * enumerated_spec_init_c * |
|
127 */ |
|
128 // SYM_REF2(var1_init_decl_c, var1_list, spec_init) |
|
129 void *visit(var1_init_decl_c *symbol); |
|
130 /* var1_list ',' variable_name */ |
|
131 // SYM_LIST(var1_list_c) |
|
132 void *visit(var1_list_c *symbol); |
|
133 /* name_list ':' function_block_type_name ASSIGN structure_initialization */ |
|
134 /* structure_initialization -> may be NULL ! */ |
|
135 void *visit(fb_name_decl_c *symbol); |
|
136 /* name_list ',' fb_name */ |
|
137 void *visit(fb_name_list_c *symbol); |
|
138 /* var1_list ':' array_spec_init */ |
|
139 // SYM_REF2(array_var_init_decl_c, var1_list, array_spec_init) |
|
140 void *visit(array_var_init_decl_c *symbol); |
|
141 /* var1_list ':' initialized_structure */ |
|
142 // SYM_REF2(structured_var_init_decl_c, var1_list, initialized_structure) |
|
143 void *visit(structured_var_init_decl_c *symbol); |
|
144 /* var1_list ':' array_specification */ |
|
145 // SYM_REF2(array_var_declaration_c, var1_list, array_specification) |
|
146 void *visit(array_var_declaration_c *symbol); |
|
147 /* var1_list ':' structure_type_name */ |
|
148 // SYM_REF2(structured_var_declaration_c, var1_list, structure_type_name) |
|
149 void *visit(structured_var_declaration_c *symbol); |
|
150 /* [variable_name] location ':' located_var_spec_init */ |
|
151 /* variable_name -> may be NULL ! */ |
|
152 // SYM_REF4(located_var_decl_c, variable_name, location, located_var_spec_init, unused) |
|
153 // TODO!! |
|
154 |
|
155 /* global_var_name ':' (simple_specification|subrange_specification|enumerated_specification|array_specification|prev_declared_structure_type_name|function_block_type_name */ |
|
156 // SYM_REF2(external_declaration_c, global_var_name, specification) |
|
157 void *visit(external_declaration_c *symbol); |
|
158 /*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */ |
|
159 /* type_specification ->may be NULL ! */ |
|
160 // SYM_REF2(global_var_decl_c, global_var_spec, type_specification) |
|
161 void *visit(global_var_decl_c *symbol); |
|
162 /*| global_var_name location */ |
|
163 //SYM_REF2(global_var_spec_c, global_var_name, location) |
|
164 void *visit(global_var_spec_c *symbol); |
|
165 /*| global_var_list ',' global_var_name */ |
|
166 //SYM_LIST(global_var_list_c) |
|
167 void *visit(global_var_list_c *symbol); |
|
168 /* [variable_name] location ':' located_var_spec_init */ |
|
169 /* variable_name -> may be NULL ! */ |
|
170 //SYM_REF4(located_var_decl_c, variable_name, location, located_var_spec_init, unused) |
|
171 void *visit(located_var_decl_c *symbol); |
|
172 /*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */ |
|
173 /* type_specification ->may be NULL ! */ |
|
174 // SYM_REF2(global_var_decl_c, global_var_spec, type_specification) |
|
175 // TODO!! |
|
176 /* AT direct_variable */ |
|
177 // SYM_REF2(location_c, direct_variable, unused) |
|
178 void *visit(location_c *symbol); |
|
179 /*| global_var_list ',' global_var_name */ |
|
180 // SYM_LIST(global_var_list_c) |
|
181 // TODO!! |
|
182 /* var1_list ':' single_byte_string_spec */ |
|
183 // SYM_REF2(single_byte_string_var_declaration_c, var1_list, single_byte_string_spec) |
|
184 void *visit(single_byte_string_var_declaration_c *symbol); |
|
185 /* STRING ['[' integer ']'] [ASSIGN single_byte_character_string] */ |
|
186 /* integer ->may be NULL ! */ |
|
187 /* single_byte_character_string ->may be NULL ! */ |
|
188 // SYM_REF2(single_byte_string_spec_c, integer, single_byte_character_string) |
|
189 // TODO!! |
|
190 |
|
191 /* var1_list ':' double_byte_string_spec */ |
|
192 // SYM_REF2(double_byte_string_var_declaration_c, var1_list, double_byte_string_spec) |
|
193 void *visit(double_byte_string_var_declaration_c *symbol); |
|
194 /* WSTRING ['[' integer ']'] [ASSIGN double_byte_character_string] */ |
|
195 /* integer ->may be NULL ! */ |
|
196 /* double_byte_character_string ->may be NULL ! */ |
|
197 // SYM_REF2(double_byte_string_spec_c, integer, double_byte_character_string) |
|
198 // TODO!! |
|
199 |
|
200 /* variable_name incompl_location ':' var_spec */ |
|
201 // SYM_REF4(incompl_located_var_decl_c, variable_name, incompl_location, var_spec, unused) |
|
202 // TODO!! |
|
203 |
|
204 /* AT incompl_location_token */ |
|
205 // SYM_TOKEN(incompl_location_c) |
|
206 // TODO!! |
|
207 |
|
208 |
|
209 /**************************************/ |
|
210 /* B.1.5 - Program organization units */ |
|
211 /**************************************/ |
|
212 /***********************/ |
|
213 /* B 1.5.1 - Functions */ |
|
214 /***********************/ |
|
215 // SYM_REF4(function_declaration_c, derived_function_name, type_name, var_declarations_list, function_body) |
|
216 void *visit(function_declaration_c *symbol); |
|
217 |
|
218 /*****************************/ |
|
219 /* B 1.5.2 - Function Blocks */ |
|
220 /*****************************/ |
|
221 void *visit(function_block_declaration_c *symbol); |
|
222 |
|
223 /**********************/ |
|
224 /* B 1.5.3 - Programs */ |
|
225 /**********************/ |
|
226 void *visit(program_declaration_c *symbol); |
|
227 |
|
228 /********************************/ |
|
229 /* B 1.7 Configuration elements */ |
|
230 /********************************/ |
|
231 |
|
232 /* |
|
233 CONFIGURATION configuration_name |
|
234 optional_global_var_declarations |
|
235 (resource_declaration_list | single_resource_declaration) |
|
236 optional_access_declarations |
|
237 optional_instance_specific_initializations |
|
238 END_CONFIGURATION |
|
239 */ |
|
240 /* |
|
241 SYM_REF6(configuration_declaration_c, configuration_name, global_var_declarations, resource_declarations, access_declarations, instance_specific_initializations, unused) |
|
242 */ |
|
243 void *visit(configuration_declaration_c *symbol); |
|
244 /* |
|
245 RESOURCE resource_name ON resource_type_name |
|
246 optional_global_var_declarations |
|
247 single_resource_declaration |
|
248 END_RESOURCE |
|
249 */ |
|
250 // SYM_REF4(resource_declaration_c, resource_name, resource_type_name, global_var_declarations, resource_declaration) |
|
251 void *visit(resource_declaration_c *symbol); |
|
252 |
|
253 /* task_configuration_list program_configuration_list */ |
|
254 // SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list) |
|
255 void *visit(single_resource_declaration_c *symbol); |
|
256 |
|
257 #if 0 |
|
258 /*********************/ |
|
259 /* B 1.4 - Variables */ |
|
260 /*********************/ |
|
261 SYM_REF2(symbolic_variable_c, var_name, unused) |
|
262 |
|
263 /********************************************/ |
|
264 /* B.1.4.1 Directly Represented Variables */ |
|
265 /********************************************/ |
|
266 SYM_TOKEN(direct_variable_c) |
|
267 |
|
268 /*************************************/ |
|
269 /* B.1.4.2 Multi-element Variables */ |
|
270 /*************************************/ |
|
271 /* subscripted_variable '[' subscript_list ']' */ |
|
272 SYM_REF2(array_variable_c, subscripted_variable, subscript_list) |
|
273 |
|
274 /* subscript_list ',' subscript */ |
|
275 SYM_LIST(subscript_list_c) |
|
276 |
|
277 /* record_variable '.' field_selector */ |
|
278 /* WARNING: input and/or output variables of function blocks |
|
279 * may be accessed as fields of a tructured variable! |
|
280 * Code handling a structured_variable_c must take |
|
281 * this into account! |
|
282 */ |
|
283 SYM_REF2(structured_variable_c, record_variable, field_selector) |
|
284 #endif |
|
285 |
|
286 }; // search_var_instance_decl_c |
|
287 |