181
|
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 |
* Function call parameter iterator.
|
|
27 |
* It will iterate through the formal parameters of a function call
|
|
28 |
* (i.e. function calls using the foo(<param1>, <param2>, ...) syntax).
|
|
29 |
* and/or search through the non-formal parameters of a function call
|
|
30 |
* (i.e. function calls using the foo(<name1> = <param1>, <name2> = <param2>, ...) syntax).
|
|
31 |
*
|
|
32 |
* Calls to function blocks and programs are also supported.
|
|
33 |
*
|
|
34 |
* Note that calls to next() will only iterate through formal parameters,
|
|
35 |
* and calls to search() will only serach through non-formal parameters.
|
|
36 |
*/
|
|
37 |
|
|
38 |
|
|
39 |
#include "../absyntax/visitor.hh"
|
|
40 |
|
|
41 |
|
|
42 |
class function_call_param_iterator_c : public null_visitor_c {
|
|
43 |
|
|
44 |
private:
|
|
45 |
/* a pointer to the function call
|
|
46 |
* (or function block or program call!)
|
|
47 |
*/
|
|
48 |
symbol_c *f_call;
|
|
49 |
int next_param, param_count;
|
|
50 |
identifier_c *search_param_name;
|
|
51 |
|
|
52 |
/* Which operation of the class was called...
|
|
53 |
* Search a parameter, or iterate to the next parameter.
|
|
54 |
*/
|
|
55 |
typedef enum {iterate_op, search_op} operation_t;
|
|
56 |
operation_t current_operation;
|
|
57 |
|
|
58 |
private:
|
|
59 |
void *search_list(list_c *list);
|
|
60 |
void *handle_parameter_assignment(symbol_c *variable_name, symbol_c *expression) ;
|
|
61 |
|
|
62 |
|
|
63 |
public:
|
|
64 |
/* start off at the first parameter once again... */
|
|
65 |
void reset(void);
|
|
66 |
|
|
67 |
/* initialise the iterator object.
|
|
68 |
* We must be given a reference to the function/program/function block call
|
|
69 |
* that will be analysed...
|
|
70 |
*/
|
|
71 |
function_call_param_iterator_c(symbol_c *f_call);
|
|
72 |
|
|
73 |
/* Skip to the next parameter. After object creation,
|
|
74 |
* the object references on parameter _before_ the first, so
|
|
75 |
* this function must be called once to get the object to
|
|
76 |
* reference the first parameter...
|
|
77 |
*
|
|
78 |
* Returns whatever is being passed to the parameter!
|
|
79 |
*/
|
|
80 |
symbol_c *next(void);
|
|
81 |
|
|
82 |
/* Search for the value passed to the parameter named <param_name>... */
|
|
83 |
symbol_c *search(symbol_c *param_name);
|
|
84 |
|
|
85 |
|
|
86 |
private:
|
|
87 |
/********************************/
|
|
88 |
/* B 1.7 Configuration elements */
|
|
89 |
/********************************/
|
|
90 |
|
|
91 |
/*
|
|
92 |
CONFIGURATION configuration_name
|
|
93 |
optional_global_var_declarations
|
|
94 |
(resource_declaration_list | single_resource_declaration)
|
|
95 |
optional_access_declarations
|
|
96 |
optional_instance_specific_initializations
|
|
97 |
END_CONFIGURATION
|
|
98 |
*/
|
|
99 |
/*
|
|
100 |
SYM_REF6(configuration_declaration_c, configuration_name, global_var_declarations, resource_declarations, access_declarations, instance_specific_initializations, unused)
|
|
101 |
*/
|
|
102 |
|
|
103 |
/* helper symbol for configuration_declaration */
|
|
104 |
/*
|
|
105 |
SYM_LIST(resource_declaration_list_c)
|
|
106 |
*/
|
|
107 |
|
|
108 |
/*
|
|
109 |
RESOURCE resource_name ON resource_type_name
|
|
110 |
optional_global_var_declarations
|
|
111 |
single_resource_declaration
|
|
112 |
END_RESOURCE
|
|
113 |
*/
|
|
114 |
/*
|
|
115 |
SYM_REF4(resource_declaration_c, resource_name, resource_type_name, global_var_declarations, resource_declaration)
|
|
116 |
*/
|
|
117 |
|
|
118 |
/* task_configuration_list program_configuration_list */
|
|
119 |
/*
|
|
120 |
SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list)
|
|
121 |
*/
|
|
122 |
|
|
123 |
/* helper symbol for single_resource_declaration */
|
|
124 |
/*
|
|
125 |
SYM_LIST(task_configuration_list_c)
|
|
126 |
*/
|
|
127 |
|
|
128 |
/* helper symbol for single_resource_declaration */
|
|
129 |
/*
|
|
130 |
SYM_LIST(program_configuration_list_c)
|
|
131 |
*/
|
|
132 |
|
|
133 |
/* helper symbol for
|
|
134 |
* - access_path
|
|
135 |
* - instance_specific_init
|
|
136 |
*/
|
|
137 |
/*
|
|
138 |
SYM_LIST(any_fb_name_list_c)
|
|
139 |
*/
|
|
140 |
|
|
141 |
/* [resource_name '.'] global_var_name ['.' structure_element_name] */
|
|
142 |
/*
|
|
143 |
SYM_REF4(global_var_reference_c, resource_name, global_var_name, structure_element_name, unused)
|
|
144 |
*/
|
|
145 |
|
|
146 |
/* prev_declared_program_name '.' symbolic_variable */
|
|
147 |
/*
|
|
148 |
SYM_REF2(program_output_reference_c, program_name, symbolic_variable)
|
|
149 |
*/
|
|
150 |
|
|
151 |
/* TASK task_name task_initialization */
|
|
152 |
/*
|
|
153 |
SYM_REF2(task_configuration_c, task_name, task_initialization)
|
|
154 |
*/
|
|
155 |
|
|
156 |
/* '(' [SINGLE ASSIGN data_source ','] [INTERVAL ASSIGN data_source ','] PRIORITY ASSIGN integer ')' */
|
|
157 |
/*
|
|
158 |
SYM_REF4(task_initialization_c, single_data_source, interval_data_source, priority_data_source, unused)
|
|
159 |
*/
|
|
160 |
|
|
161 |
/* PROGRAM [RETAIN | NON_RETAIN] program_name [WITH task_name] ':' program_type_name ['(' prog_conf_elements ')'] */
|
|
162 |
// SYM_REF6(program_configuration_c, retain_option, program_name, task_name, program_type_name, prog_conf_elements, unused)
|
|
163 |
void *visit(program_configuration_c *symbol);
|
|
164 |
|
|
165 |
/* prog_conf_elements ',' prog_conf_element */
|
|
166 |
// SYM_LIST(prog_conf_elements_c)
|
|
167 |
void *visit(prog_conf_elements_c *symbol);
|
|
168 |
|
|
169 |
/* fb_name WITH task_name */
|
|
170 |
/*
|
|
171 |
SYM_REF2(fb_task_c, fb_name, task_name)
|
|
172 |
*/
|
|
173 |
|
|
174 |
/* any_symbolic_variable ASSIGN prog_data_source */
|
|
175 |
// SYM_REF2(prog_cnxn_assign_c, symbolic_variable, prog_data_source)
|
|
176 |
void *visit(prog_cnxn_assign_c *symbol);
|
|
177 |
|
|
178 |
/* any_symbolic_variable SENDTO data_sink */
|
|
179 |
// SYM_REF2(prog_cnxn_sendto_c, symbolic_variable, prog_data_source)
|
|
180 |
void *visit(prog_cnxn_sendto_c *symbol);
|
|
181 |
|
|
182 |
/* VAR_CONFIG instance_specific_init_list END_VAR */
|
|
183 |
/*
|
|
184 |
SYM_REF2(instance_specific_initializations_c, instance_specific_init_list, unused)
|
|
185 |
*/
|
|
186 |
|
|
187 |
/* helper symbol for instance_specific_initializations */
|
|
188 |
/*
|
|
189 |
SYM_LIST(instance_specific_init_list_c)
|
|
190 |
*/
|
|
191 |
|
|
192 |
/* resource_name '.' program_name '.' {fb_name '.'}
|
|
193 |
((variable_name [location] ':' located_var_spec_init) | (fb_name ':' fb_initialization))
|
|
194 |
*/
|
|
195 |
/*
|
|
196 |
SYM_REF6(instance_specific_init_c, resource_name, program_name, any_fb_name_list, variable_name, location, initialization)
|
|
197 |
*/
|
|
198 |
|
|
199 |
/* helper symbol for instance_specific_init */
|
|
200 |
/* function_block_type_name ':=' structure_initialization */
|
|
201 |
/*
|
|
202 |
SYM_REF2(fb_initialization_c, function_block_type_name, structure_initialization)
|
|
203 |
*/
|
|
204 |
|
|
205 |
|
|
206 |
/****************************************/
|
|
207 |
/* B.2 - Language IL (Instruction List) */
|
|
208 |
/****************************************/
|
|
209 |
/***********************************/
|
|
210 |
/* B 2.1 Instructions and Operands */
|
|
211 |
/***********************************/
|
|
212 |
|
|
213 |
/* | function_name [il_operand_list] */
|
|
214 |
// SYM_REF2(il_function_call_c, function_name, il_operand_list)
|
|
215 |
void *visit(il_function_call_c *symbol);
|
|
216 |
|
|
217 |
|
|
218 |
/* | function_name '(' eol_list [il_param_list] ')' */
|
|
219 |
// SYM_REF2(il_formal_funct_call_c, function_name, il_param_list)
|
|
220 |
void *visit(il_formal_funct_call_c *symbol);
|
|
221 |
|
|
222 |
|
|
223 |
/* il_call_operator prev_declared_fb_name
|
|
224 |
* | il_call_operator prev_declared_fb_name '(' ')'
|
|
225 |
* | il_call_operator prev_declared_fb_name '(' eol_list ')'
|
|
226 |
* | il_call_operator prev_declared_fb_name '(' il_operand_list ')'
|
|
227 |
* | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')'
|
|
228 |
*/
|
|
229 |
// SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list)
|
|
230 |
void *visit(il_fb_call_c *symbol);
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
/* | il_operand_list ',' il_operand */
|
|
235 |
// SYM_LIST(il_operand_list_c)
|
|
236 |
void *visit(il_operand_list_c *symbol);
|
|
237 |
|
|
238 |
|
|
239 |
/* | il_initial_param_list il_param_instruction */
|
|
240 |
// SYM_LIST(il_param_list_c)
|
|
241 |
void *visit(il_param_list_c *symbol);
|
|
242 |
|
|
243 |
/* il_assign_operator il_operand
|
|
244 |
* | il_assign_operator '(' eol_list simple_instr_list ')'
|
|
245 |
*/
|
|
246 |
// SYM_REF4(il_param_assignment_c, il_assign_operator, il_operand, simple_instr_list, unused)
|
|
247 |
void *visit(il_param_assignment_c *symbol);
|
|
248 |
|
|
249 |
/* il_assign_out_operator variable */
|
|
250 |
// SYM_REF2(il_param_out_assignment_c, il_assign_out_operator, variable);
|
|
251 |
void *visit(il_param_out_assignment_c *symbol);
|
|
252 |
|
|
253 |
|
|
254 |
/*******************/
|
|
255 |
/* B 2.2 Operators */
|
|
256 |
/*******************/
|
|
257 |
/*| [NOT] any_identifier SENDTO */
|
|
258 |
// SYM_REF2(il_assign_out_operator_c, option, variable_name)
|
|
259 |
void *visit(il_assign_out_operator_c *symbol);
|
|
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
|
264 |
/***************************************/
|
|
265 |
/* B.3 - Language ST (Structured Text) */
|
|
266 |
/***************************************/
|
|
267 |
/***********************/
|
|
268 |
/* B 3.1 - Expressions */
|
|
269 |
/***********************/
|
|
270 |
|
|
271 |
/*
|
|
272 |
SYM_REF2(function_invocation_c, function_name, parameter_assignment_list)
|
|
273 |
*/
|
|
274 |
void *visit(function_invocation_c *symbol);
|
|
275 |
|
|
276 |
|
|
277 |
/********************/
|
|
278 |
/* B 3.2 Statements */
|
|
279 |
/********************/
|
|
280 |
|
|
281 |
/*********************************/
|
|
282 |
/* B 3.2.1 Assignment Statements */
|
|
283 |
/*********************************/
|
|
284 |
/*
|
|
285 |
SYM_REF2(assignment_statement_c, l_exp, r_exp)
|
|
286 |
*/
|
|
287 |
|
|
288 |
/*****************************************/
|
|
289 |
/* B 3.2.2 Subprogram Control Statements */
|
|
290 |
/*****************************************/
|
|
291 |
/* RETURN */
|
|
292 |
// SYM_REF0(return_statement_c)
|
|
293 |
|
|
294 |
|
|
295 |
/* fb_name '(' [param_assignment_list] ')' */
|
|
296 |
/* param_assignment_list -> may be NULL ! */
|
|
297 |
// SYM_REF2(fb_invocation_c, fb_name, param_assignment_list)
|
|
298 |
void *visit(fb_invocation_c *symbol);
|
|
299 |
|
|
300 |
/* helper symbol for fb_invocation */
|
|
301 |
/* param_assignment_list ',' param_assignment */
|
|
302 |
// SYM_LIST(param_assignment_list_c)
|
|
303 |
void *visit(param_assignment_list_c *symbol);
|
|
304 |
|
|
305 |
/* variable_name ASSIGN expression */
|
|
306 |
// SYM_REF2(input_variable_param_assignment_c, variable_name, expression)
|
|
307 |
void *visit(input_variable_param_assignment_c *symbol);
|
|
308 |
|
|
309 |
/* [NOT] variable_name '=>' variable */
|
|
310 |
// SYM_REF4(output_variable_param_assignment_c, not_param, variable_name, variable, unused)
|
|
311 |
void *visit(output_variable_param_assignment_c *symbol);
|
|
312 |
|
|
313 |
/* helper CLASS for output_variable_param_assignment */
|
|
314 |
// SYM_REF0(not_paramassign_c)
|
|
315 |
// TODO... ???
|
|
316 |
|
|
317 |
}; // function_call_param_iterator_c
|
|
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|