29 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
29 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
30 * |
30 * |
31 */ |
31 */ |
32 |
32 |
33 |
33 |
34 /* Determine the data type of a specific variable instance, including |
34 /* Search in a VAR* END_VAR declaration for the delcration of the specified variable instance. |
35 * function block instances. |
35 * Will return: |
36 * A reference to the relevant variable declaration is returned. |
36 * - the declaration itself (get_decl() ) |
|
37 * - the type of declaration in which the variable was declared (get_vartype() ) |
|
38 * |
37 * The variable instance may NOT be a member of a structure of a memeber |
39 * The variable instance may NOT be a member of a structure of a memeber |
38 * of a structure of an element of an array of ... |
40 * of a structure of an element of an array of ... |
39 * |
41 * |
40 * example: |
42 * For example, considering the following 'variables': |
41 * window.points[1].coordinate.x |
43 * window.points[1].coordinate.x |
42 * window.points[1].colour |
44 * window.points[1].colour |
43 * etc... ARE NOT ALLOWED! |
45 * offset[99] |
|
46 * |
|
47 * passing a reference to 'points', 'points[1]', 'points[1].colour', 'colour' |
|
48 * ARE NOT ALLOWED! |
44 * |
49 * |
45 * This class must only be passed the name of the variable that will appear |
50 * This class must only be passed the name of the variable that will appear |
46 * in the variable declaration. In the above examples, this would be |
51 * in the variable declaration. In the above examples, this would be |
47 * 'window' !! |
52 * 'window.points[1].coordinate.x' |
48 * |
53 * 'window.points[1].coordinate' |
49 * |
54 * 'window.points[1]' |
50 * If you need to pass a complete name of a variable instance (such as |
55 * 'window' |
51 * 'window.points[1].coordinate.x') use the search_varfb_instance_type_c instead! |
56 * 'window.points[1].colour' |
52 */ |
57 * 'offset' |
53 /* Note that current_type_decl that this class returns may reference the |
58 * 'offset[99]' |
|
59 * |
|
60 * |
|
61 */ |
|
62 |
|
63 /* Note: |
|
64 * Determining the declaration type of a specific variable instance (including |
|
65 * function block instances) really means determining whether the variable was declared in a |
|
66 * VAR_INPUT |
|
67 * VAR_OUTPUT |
|
68 * VAR_IN_OUT |
|
69 * VAR |
|
70 * VAR_TEMP |
|
71 * VAR_EXTERNAL |
|
72 * VAR_GLOBAL |
|
73 * VAR <var_name> AT <location> -> Located variable! |
|
74 * |
|
75 */ |
|
76 |
|
77 /* Note: |
|
78 * The current_type_decl that this class returns may reference the |
54 * name of a type, or the type declaration itself! |
79 * name of a type, or the type declaration itself! |
55 * For an example of the first, consider a variable declared as ... |
80 * For an example of the first, consider a variable declared as ... |
56 * x : AAA; |
81 * x : AAA; |
57 * where the AAA type is previously declared as whatever. |
82 * where the AAA type is previously declared as whatever. |
58 * For an example of the second, consider a variable declared as ... |
83 * For an example of the second, consider a variable declared as ... |
63 */ |
88 */ |
64 |
89 |
65 |
90 |
66 class search_var_instance_decl_c: public search_visitor_c { |
91 class search_var_instance_decl_c: public search_visitor_c { |
67 |
92 |
68 private: |
|
69 symbol_c *search_scope; |
|
70 symbol_c *search_name; |
|
71 symbol_c *current_type_decl; |
|
72 |
|
73 /* variable used to store the type of variable currently being processed... */ |
|
74 /* Will contain a single value of generate_c_vardecl_c::XXXX_vt */ |
|
75 unsigned int current_vartype; |
|
76 |
|
77 public: |
93 public: |
78 search_var_instance_decl_c(symbol_c *search_scope); |
94 search_var_instance_decl_c(symbol_c *search_scope); |
79 symbol_c *get_decl(symbol_c *variable_instance_name); |
|
80 unsigned int get_vartype(void); |
|
81 |
95 |
82 public: |
96 public: |
83 |
97 typedef enum { |
|
98 input_vt , // VAR_INPUT |
|
99 output_vt , // VAR_OUTPUT |
|
100 inoutput_vt, // VAR_IN_OUT |
|
101 private_vt , // VAR |
|
102 temp_vt , // VAR_TEMP |
|
103 external_vt, // VAR_EXTERNAL |
|
104 global_vt , // VAR_GLOBAL |
|
105 located_vt , // VAR <var_name> AT <location> |
|
106 none_vt |
|
107 } vt_t; |
|
108 |
|
109 typedef enum { |
|
110 constant_opt , |
|
111 retain_opt , |
|
112 non_retain_opt, |
|
113 none_opt |
|
114 } opt_t; |
|
115 #if 0 |
84 /* the types of variables that need to be processed... */ |
116 /* the types of variables that need to be processed... */ |
85 static const unsigned int none_vt = 0x0000; |
117 static const unsigned int none_vt = 0x0000; |
86 static const unsigned int input_vt = 0x0001; // VAR_INPUT |
118 static const unsigned int input_vt = 0x0001; // VAR_INPUT |
87 static const unsigned int output_vt = 0x0002; // VAR_OUTPUT |
119 static const unsigned int output_vt = 0x0002; // VAR_OUTPUT |
88 static const unsigned int inoutput_vt = 0x0004; // VAR_IN_OUT |
120 static const unsigned int inoutput_vt = 0x0004; // VAR_IN_OUT |
90 static const unsigned int temp_vt = 0x0010; // VAR_TEMP |
122 static const unsigned int temp_vt = 0x0010; // VAR_TEMP |
91 static const unsigned int external_vt = 0x0020; // VAR_EXTERNAL |
123 static const unsigned int external_vt = 0x0020; // VAR_EXTERNAL |
92 static const unsigned int global_vt = 0x0040; // VAR_GLOBAL |
124 static const unsigned int global_vt = 0x0040; // VAR_GLOBAL |
93 static const unsigned int located_vt = 0x0080; // VAR <var_name> AT <location> |
125 static const unsigned int located_vt = 0x0080; // VAR <var_name> AT <location> |
94 |
126 |
|
127 static const unsigned int none_opt = 0x0000; |
|
128 static const unsigned int constant_opt = 0x0001; |
|
129 static const unsigned int retain_opt = 0x0002; |
|
130 static const unsigned int non_retain_opt = 0x0003; |
|
131 #endif |
|
132 |
|
133 symbol_c * get_decl (symbol_c *variable_instance_name); |
|
134 vt_t get_vartype(symbol_c *variable_instance_name); |
|
135 opt_t get_option (symbol_c *variable_instance_name); |
|
136 |
|
137 /* NOTE: The following function will be completely deleted in the (hopefully near) future. */ |
|
138 /* Returns true if the variable is an ARRAY or a STRUCT, otherwise returns false. |
|
139 * Note that for FB, also returns false! |
|
140 */ |
|
141 bool type_is_complex(symbol_c *variable_name); |
|
142 |
|
143 |
|
144 |
|
145 private: |
|
146 symbol_c *search_scope; |
|
147 symbol_c *search_name; |
|
148 symbol_c *current_type_decl; |
|
149 /* variable used to store the type of variable currently being processed... */ |
|
150 /* Will contain a single value of generate_c_vardecl_c::XXXX_vt */ |
|
151 vt_t current_vartype; |
|
152 opt_t current_option; |
|
153 |
|
154 |
95 private: |
155 private: |
96 /***************************/ |
156 /***************************/ |
97 /* B 0 - Programming Model */ |
157 /* B 0 - Programming Model */ |
98 /***************************/ |
158 /***************************/ |
99 void *visit(library_c *symbol); |
159 void *visit(library_c *symbol); |
103 /******************************************/ |
163 /******************************************/ |
104 |
164 |
105 /* edge -> The F_EDGE or R_EDGE directive */ |
165 /* edge -> The F_EDGE or R_EDGE directive */ |
106 // SYM_REF2(edge_declaration_c, edge, var1_list) |
166 // SYM_REF2(edge_declaration_c, edge, var1_list) |
107 // TODO |
167 // TODO |
|
168 void *visit(constant_option_c *symbol); |
|
169 void *visit(retain_option_c *symbol); |
|
170 void *visit(non_retain_option_c *symbol); |
|
171 |
|
172 |
108 void *visit(input_declarations_c *symbol); |
173 void *visit(input_declarations_c *symbol); |
109 /* VAR_OUTPUT [RETAIN | NON_RETAIN] var_init_decl_list END_VAR */ |
174 /* VAR_OUTPUT [RETAIN | NON_RETAIN] var_init_decl_list END_VAR */ |
110 /* option -> may be NULL ! */ |
175 /* option -> may be NULL ! */ |
111 void *visit(output_declarations_c *symbol); |
176 void *visit(output_declarations_c *symbol); |
112 /* VAR_IN_OUT var_declaration_list END_VAR */ |
177 /* VAR_IN_OUT var_declaration_list END_VAR */ |
234 /**********************/ |
299 /**********************/ |
235 /* B 1.5.3 - Programs */ |
300 /* B 1.5.3 - Programs */ |
236 /**********************/ |
301 /**********************/ |
237 void *visit(program_declaration_c *symbol); |
302 void *visit(program_declaration_c *symbol); |
238 |
303 |
|
304 /*********************************************/ |
|
305 /* B.1.6 Sequential function chart elements */ |
|
306 /*********************************************/ |
|
307 /* | sequential_function_chart sfc_network */ |
|
308 // SYM_LIST(sequential_function_chart_c) |
|
309 /* search_var_instance_decl_c inherits from serach_visitor_c, so no need to implement the following method. */ |
|
310 // void *visit(sequential_function_chart_c *symbol); |
|
311 |
|
312 /* initial_step {step | transition | action} */ |
|
313 // SYM_LIST(sfc_network_c) |
|
314 /* search_var_instance_decl_c inherits from serach_visitor_c, so no need to implement the following method. */ |
|
315 // void *visit(sfc_network_c *symbol); |
|
316 |
|
317 |
|
318 /* INITIAL_STEP step_name ':' action_association_list END_STEP */ |
|
319 // SYM_REF2(initial_step_c, step_name, action_association_list) |
|
320 void *visit(initial_step_c *symbol); |
|
321 |
|
322 /* STEP step_name ':' action_association_list END_STEP */ |
|
323 // SYM_REF2(step_c, step_name, action_association_list) |
|
324 void *visit(step_c *symbol); |
|
325 |
239 /********************************/ |
326 /********************************/ |
240 /* B 1.7 Configuration elements */ |
327 /* B 1.7 Configuration elements */ |
241 /********************************/ |
328 /********************************/ |
242 |
329 |
243 /* |
330 /* |
263 |
350 |
264 /* task_configuration_list program_configuration_list */ |
351 /* task_configuration_list program_configuration_list */ |
265 // SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list) |
352 // SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list) |
266 void *visit(single_resource_declaration_c *symbol); |
353 void *visit(single_resource_declaration_c *symbol); |
267 |
354 |
268 #if 0 |
355 |
269 /*********************/ |
356 /****************************************/ |
270 /* B 1.4 - Variables */ |
357 /* B.2 - Language IL (Instruction List) */ |
271 /*********************/ |
358 /****************************************/ |
272 SYM_REF2(symbolic_variable_c, var_name, unused) |
359 /***********************************/ |
273 |
360 /* B 2.1 Instructions and Operands */ |
274 /********************************************/ |
361 /***********************************/ |
275 /* B.1.4.1 Directly Represented Variables */ |
362 /*| instruction_list il_instruction */ |
276 /********************************************/ |
363 // SYM_LIST(instruction_list_c) |
277 SYM_TOKEN(direct_variable_c) |
364 void *visit(instruction_list_c *symbol); |
278 |
365 |
279 /*************************************/ |
366 |
280 /* B.1.4.2 Multi-element Variables */ |
367 /***************************************/ |
281 /*************************************/ |
368 /* B.3 - Language ST (Structured Text) */ |
282 /* subscripted_variable '[' subscript_list ']' */ |
369 /***************************************/ |
283 SYM_REF2(array_variable_c, subscripted_variable, subscript_list) |
370 /********************/ |
284 |
371 /* B 3.2 Statements */ |
285 /* subscript_list ',' subscript */ |
372 /********************/ |
286 SYM_LIST(subscript_list_c) |
373 // SYM_LIST(statement_list_c) |
287 |
374 void *visit(statement_list_c *symbol); |
288 /* record_variable '.' field_selector */ |
|
289 /* WARNING: input and/or output variables of function blocks |
|
290 * may be accessed as fields of a tructured variable! |
|
291 * Code handling a structured_variable_c must take |
|
292 * this into account! |
|
293 */ |
|
294 SYM_REF2(structured_variable_c, record_variable, field_selector) |
|
295 #endif |
|
296 |
375 |
297 }; // search_var_instance_decl_c |
376 }; // search_var_instance_decl_c |
298 |
377 |