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