author | Mario de Sousa <msousa@fe.up.pt> |
Thu, 31 Mar 2011 21:06:36 +0100 | |
changeset 262 | 197ba42d78b2 |
parent 247 | 560075ece524 |
child 265 | 4d222f46f8cc |
permissions | -rwxr-xr-x |
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 |
||
41 |
#include "function_call_param_iterator.hh" |
|
42 |
#include <strings.h> |
|
43 |
||
44 |
||
45 |
//#define DEBUG |
|
46 |
#ifdef DEBUG |
|
47 |
#define TRACE(classname) printf("\n____%s____\n",classname); |
|
48 |
#else |
|
49 |
#define TRACE(classname) |
|
50 |
#endif |
|
51 |
||
52 |
#define ERROR error_exit(__FILE__,__LINE__) |
|
53 |
/* function defined in main.cc */ |
|
54 |
extern void error_exit(const char *file_name, int line_no); |
|
55 |
||
56 |
||
57 |
||
58 |
||
59 |
||
60 |
void *function_call_param_iterator_c::search_list(list_c *list) { |
|
61 |
switch (current_operation) { |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
62 |
case iterate_nf_op: |
181 | 63 |
for(int i = 0; i < list->n; i++) { |
64 |
void *res = list->elements[i]->accept(*this); |
|
65 |
if (NULL != res) { |
|
66 |
/* It went through the handle_parameter_assignment() function, |
|
67 |
* and is therefore a parameter assignment (<param> = <value>), |
|
68 |
* and not a simple expression (<value>). |
|
69 |
*/ |
|
70 |
/* we do nothing... */ |
|
71 |
} else { |
|
72 |
param_count++; |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
73 |
if (param_count == iterate_nf_next_param) { |
181 | 74 |
return list->elements[i]; |
75 |
} |
|
76 |
} |
|
77 |
} |
|
78 |
return NULL; |
|
79 |
break; |
|
80 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
81 |
case iterate_f_op: |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
82 |
for(int i = 0; i < list->n; i++) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
83 |
void *res = list->elements[i]->accept(*this); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
84 |
if (NULL != res) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
85 |
/* It went through the handle_parameter_assignment() function, |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
86 |
* and is therefore a parameter assignment (<param> = <value>), |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
87 |
* and not a simple expression (<value>). |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
88 |
*/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
89 |
param_count++; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
90 |
if (param_count == iterate_f_next_param) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
91 |
return res; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
92 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
93 |
} else { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
94 |
/* we do nothing... */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
95 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
96 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
97 |
return NULL; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
98 |
break; |
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 |
case search_f_op: |
181 | 101 |
for(int i = 0; i < list->n; i++) { |
102 |
void *res = list->elements[i]->accept(*this); |
|
103 |
if (res != NULL) |
|
104 |
return res; |
|
105 |
} |
|
106 |
return NULL; |
|
107 |
break; |
|
108 |
} /* switch */ |
|
109 |
return NULL; |
|
110 |
} |
|
111 |
||
112 |
||
113 |
||
114 |
void *function_call_param_iterator_c::handle_parameter_assignment(symbol_c *variable_name, symbol_c *expression) { |
|
115 |
switch (current_operation) { |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
116 |
case iterate_nf_op: |
181 | 117 |
/* UGLY HACK -> this will be detected in the search_list() function */ |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
118 |
return (void *)variable_name; /* anything, as long as it is not NULL!! */ |
181 | 119 |
break; |
120 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
121 |
case iterate_f_op: |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
122 |
current_value = expression; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
123 |
return (void *)variable_name; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
124 |
break; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
125 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
126 |
case search_f_op: |
181 | 127 |
identifier_c *variable_name2 = dynamic_cast<identifier_c *>(variable_name); |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
128 |
|
181 | 129 |
if (variable_name2 == NULL) ERROR; |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
130 |
|
181 | 131 |
if (strcasecmp(search_param_name->value, variable_name2->value) == 0) |
132 |
/* FOUND! This is the same parameter!! */ |
|
133 |
return (void *)expression; |
|
134 |
return NULL; |
|
135 |
break; |
|
136 |
} |
|
137 |
||
138 |
ERROR; |
|
139 |
return NULL; |
|
140 |
} |
|
141 |
||
142 |
||
143 |
/* start off at the first parameter once again... */ |
|
144 |
void function_call_param_iterator_c::reset(void) { |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
145 |
iterate_nf_next_param = 0; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
146 |
iterate_f_next_param = 0; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
147 |
param_count = 0; |
181 | 148 |
} |
149 |
||
150 |
/* initialise the iterator object. |
|
151 |
* We must be given a reference to the function/program/function block call |
|
152 |
* that will be analysed... |
|
153 |
*/ |
|
154 |
function_call_param_iterator_c::function_call_param_iterator_c(symbol_c *f_call) { |
|
155 |
/* It is expected that f_call will reference one of the following: |
|
156 |
* program_configuration_c |
|
157 |
* function_invocation_c |
|
158 |
* fb_invocation_c |
|
159 |
* il_function_call_c |
|
160 |
* il_formal_funct_call_c |
|
161 |
* ... (have I missed any?) |
|
162 |
*/ |
|
163 |
this->f_call = f_call; |
|
164 |
search_param_name = NULL; |
|
165 |
reset(); |
|
166 |
} |
|
167 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
168 |
/* Skip to the next formal parameter. After object creation, |
181 | 169 |
* the object references on parameter _before_ the first, so |
170 |
* this function must be called once to get the object to |
|
171 |
* reference the first parameter... |
|
172 |
* |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
173 |
* 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
|
174 |
* 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
|
175 |
* 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
|
176 |
*/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
177 |
symbol_c *function_call_param_iterator_c::next_f(void) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
178 |
current_value = NULL; |
181 | 179 |
param_count = 0; |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
180 |
iterate_f_next_param++; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
181 |
current_operation = function_call_param_iterator_c::iterate_f_op; |
181 | 182 |
void *res = f_call->accept(*this); |
183 |
return (symbol_c *)res; |
|
184 |
} |
|
185 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
186 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
187 |
/* Skip to the next non-formal parameter. After object creation, |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
188 |
* 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
|
189 |
* 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
|
190 |
* reference the first parameter... |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
191 |
* |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
192 |
* Returns whatever is being passed to the parameter! |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
193 |
*/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
194 |
symbol_c *function_call_param_iterator_c::next_nf(void) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
195 |
current_value = NULL; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
196 |
param_count = 0; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
197 |
iterate_nf_next_param++; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
198 |
current_operation = function_call_param_iterator_c::iterate_nf_op; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
199 |
void *res = f_call->accept(*this); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
200 |
current_value = (symbol_c *)res; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
201 |
return (symbol_c *)res; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
202 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
203 |
|
181 | 204 |
/* 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
|
205 |
symbol_c *function_call_param_iterator_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
|
206 |
current_value = NULL; |
181 | 207 |
if (NULL == param_name) ERROR; |
208 |
search_param_name = dynamic_cast<identifier_c *>(param_name); |
|
209 |
if (NULL == search_param_name) ERROR; |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
210 |
current_operation = function_call_param_iterator_c::search_f_op; |
181 | 211 |
void *res = f_call->accept(*this); |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
212 |
current_value = (symbol_c *)res; |
181 | 213 |
return (symbol_c *)res; |
214 |
} |
|
215 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
216 |
/* 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
|
217 |
symbol_c *function_call_param_iterator_c::get_current_value(void) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
218 |
return current_value; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
219 |
} |
181 | 220 |
|
221 |
/********************************/ |
|
222 |
/* B 1.7 Configuration elements */ |
|
223 |
/********************************/ |
|
224 |
||
225 |
/* |
|
226 |
CONFIGURATION configuration_name |
|
227 |
optional_global_var_declarations |
|
228 |
(resource_declaration_list | single_resource_declaration) |
|
229 |
optional_access_declarations |
|
230 |
optional_instance_specific_initializations |
|
231 |
END_CONFIGURATION |
|
232 |
*/ |
|
233 |
/* |
|
234 |
SYM_REF6(configuration_declaration_c, configuration_name, global_var_declarations, resource_declarations, access_declarations, instance_specific_initializations, unused) |
|
235 |
*/ |
|
236 |
||
237 |
/* helper symbol for configuration_declaration */ |
|
238 |
/* |
|
239 |
SYM_LIST(resource_declaration_list_c) |
|
240 |
*/ |
|
241 |
||
242 |
/* |
|
243 |
RESOURCE resource_name ON resource_type_name |
|
244 |
optional_global_var_declarations |
|
245 |
single_resource_declaration |
|
246 |
END_RESOURCE |
|
247 |
*/ |
|
248 |
/* |
|
249 |
SYM_REF4(resource_declaration_c, resource_name, resource_type_name, global_var_declarations, resource_declaration) |
|
250 |
*/ |
|
251 |
||
252 |
/* task_configuration_list program_configuration_list */ |
|
253 |
/* |
|
254 |
SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list) |
|
255 |
*/ |
|
256 |
||
257 |
/* helper symbol for single_resource_declaration */ |
|
258 |
/* |
|
259 |
SYM_LIST(task_configuration_list_c) |
|
260 |
*/ |
|
261 |
||
262 |
/* helper symbol for single_resource_declaration */ |
|
263 |
/* |
|
264 |
SYM_LIST(program_configuration_list_c) |
|
265 |
*/ |
|
266 |
||
267 |
/* helper symbol for |
|
268 |
* - access_path |
|
269 |
* - instance_specific_init |
|
270 |
*/ |
|
271 |
/* |
|
272 |
SYM_LIST(any_fb_name_list_c) |
|
273 |
*/ |
|
274 |
||
275 |
/* [resource_name '.'] global_var_name ['.' structure_element_name] */ |
|
276 |
/* |
|
277 |
SYM_REF4(global_var_reference_c, resource_name, global_var_name, structure_element_name, unused) |
|
278 |
*/ |
|
279 |
||
280 |
/* prev_declared_program_name '.' symbolic_variable */ |
|
281 |
/* |
|
282 |
SYM_REF2(program_output_reference_c, program_name, symbolic_variable) |
|
283 |
*/ |
|
284 |
||
285 |
/* TASK task_name task_initialization */ |
|
286 |
/* |
|
287 |
SYM_REF2(task_configuration_c, task_name, task_initialization) |
|
288 |
*/ |
|
289 |
||
290 |
/* '(' [SINGLE ASSIGN data_source ','] [INTERVAL ASSIGN data_source ','] PRIORITY ASSIGN integer ')' */ |
|
291 |
/* |
|
292 |
SYM_REF4(task_initialization_c, single_data_source, interval_data_source, priority_data_source, unused) |
|
293 |
*/ |
|
294 |
||
295 |
/* PROGRAM [RETAIN | NON_RETAIN] program_name [WITH task_name] ':' program_type_name ['(' prog_conf_elements ')'] */ |
|
296 |
// SYM_REF6(program_configuration_c, retain_option, program_name, task_name, program_type_name, prog_conf_elements, unused) |
|
297 |
void *function_call_param_iterator_c::visit(program_configuration_c *symbol) { |
|
298 |
TRACE("program_configuration_c"); |
|
299 |
return symbol->prog_conf_elements->accept(*this); |
|
300 |
} |
|
301 |
||
302 |
/* prog_conf_elements ',' prog_conf_element */ |
|
303 |
// SYM_LIST(prog_conf_elements_c) |
|
304 |
void *function_call_param_iterator_c::visit(prog_conf_elements_c *symbol) { |
|
305 |
TRACE("prog_conf_elements_c"); |
|
306 |
return search_list(symbol); |
|
307 |
} |
|
308 |
||
309 |
/* fb_name WITH task_name */ |
|
310 |
/* |
|
311 |
SYM_REF2(fb_task_c, fb_name, task_name) |
|
312 |
*/ |
|
313 |
||
314 |
/* any_symbolic_variable ASSIGN prog_data_source */ |
|
315 |
// SYM_REF2(prog_cnxn_assign_c, symbolic_variable, prog_data_source) |
|
316 |
void *function_call_param_iterator_c::visit(prog_cnxn_assign_c *symbol) { |
|
317 |
TRACE("prog_cnxn_assign_c"); |
|
318 |
||
319 |
/* NOTE: symbolic_variable may be something other than a symbolic_variable_c, but I (Mario) |
|
320 |
* do not understand the semantics that should be implmeneted if it is not a |
|
321 |
* symbolic_variable, so for the moment we simply give up! |
|
322 |
*/ |
|
323 |
symbolic_variable_c *symb_var = dynamic_cast<symbolic_variable_c *>(symbol->symbolic_variable); |
|
324 |
if (NULL == symb_var) |
|
325 |
ERROR; |
|
326 |
||
327 |
return handle_parameter_assignment(symb_var->var_name, symbol->prog_data_source); |
|
328 |
} |
|
329 |
||
330 |
/* any_symbolic_variable SENDTO data_sink */ |
|
331 |
// SYM_REF2(prog_cnxn_sendto_c, symbolic_variable, prog_data_source) |
|
332 |
void *function_call_param_iterator_c::visit(prog_cnxn_sendto_c *symbol) { |
|
333 |
TRACE("prog_cnxn_sendto_c"); |
|
334 |
||
335 |
/* NOTE: symbolic_variable may be something other than a symbolic_variable_c, but I (Mario) |
|
336 |
* do not understand the semantics that should be implmeneted if it is not a |
|
337 |
* symbolic_variable, so for the moment we simply give up! |
|
338 |
*/ |
|
339 |
symbolic_variable_c *symb_var = dynamic_cast<symbolic_variable_c *>(symbol->symbolic_variable); |
|
340 |
if (NULL == symb_var) |
|
341 |
ERROR; |
|
342 |
||
343 |
return handle_parameter_assignment(symb_var->var_name, symbol->data_sink); |
|
344 |
} |
|
345 |
||
346 |
/* VAR_CONFIG instance_specific_init_list END_VAR */ |
|
347 |
/* |
|
348 |
SYM_REF2(instance_specific_initializations_c, instance_specific_init_list, unused) |
|
349 |
*/ |
|
350 |
||
351 |
/* helper symbol for instance_specific_initializations */ |
|
352 |
/* |
|
353 |
SYM_LIST(instance_specific_init_list_c) |
|
354 |
*/ |
|
355 |
||
356 |
/* resource_name '.' program_name '.' {fb_name '.'} |
|
357 |
((variable_name [location] ':' located_var_spec_init) | (fb_name ':' fb_initialization)) |
|
358 |
*/ |
|
359 |
/* |
|
360 |
SYM_REF6(instance_specific_init_c, resource_name, program_name, any_fb_name_list, variable_name, location, initialization) |
|
361 |
*/ |
|
362 |
||
363 |
/* helper symbol for instance_specific_init */ |
|
364 |
/* function_block_type_name ':=' structure_initialization */ |
|
365 |
/* |
|
366 |
SYM_REF2(fb_initialization_c, function_block_type_name, structure_initialization) |
|
367 |
*/ |
|
368 |
||
369 |
||
370 |
||
371 |
/****************************************/ |
|
372 |
/* B.2 - Language IL (Instruction List) */ |
|
373 |
/****************************************/ |
|
374 |
/***********************************/ |
|
375 |
/* B 2.1 Instructions and Operands */ |
|
376 |
/***********************************/ |
|
377 |
||
378 |
/* | function_name [il_operand_list] */ |
|
379 |
// SYM_REF2(il_function_call_c, function_name, il_operand_list) |
|
380 |
void *function_call_param_iterator_c::visit(il_function_call_c *symbol) { |
|
381 |
TRACE("il_function_call_c"); |
|
382 |
if (NULL != symbol->il_operand_list) |
|
383 |
return symbol->il_operand_list->accept(*this); |
|
384 |
return NULL; |
|
385 |
} |
|
386 |
||
387 |
||
388 |
/* | function_name '(' eol_list [il_param_list] ')' */ |
|
389 |
// SYM_REF2(il_formal_funct_call_c, function_name, il_param_list) |
|
390 |
void *function_call_param_iterator_c::visit(il_formal_funct_call_c *symbol) { |
|
391 |
TRACE("il_formal_funct_call_c"); |
|
392 |
if (NULL != symbol->il_param_list) |
|
393 |
return symbol->il_param_list->accept(*this); |
|
394 |
return NULL; |
|
395 |
} |
|
396 |
||
397 |
||
398 |
/* il_call_operator prev_declared_fb_name |
|
399 |
* | il_call_operator prev_declared_fb_name '(' ')' |
|
400 |
* | il_call_operator prev_declared_fb_name '(' eol_list ')' |
|
401 |
* | il_call_operator prev_declared_fb_name '(' il_operand_list ')' |
|
402 |
* | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')' |
|
403 |
*/ |
|
404 |
// SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list) |
|
405 |
void *function_call_param_iterator_c::visit(il_fb_call_c *symbol) { |
|
406 |
TRACE("il_fb_call_c"); |
|
407 |
/* the following should never occur. In reality the syntax parser |
|
408 |
* will guarantee that they never occur, but it makes it easier to |
|
409 |
* understand the remaining code :-) |
|
410 |
*/ |
|
411 |
//if ((NULL == symbol->il_operand_list) && (NULL == symbol->il_param_list)) ERROR; |
|
412 |
//if ((NULL != symbol->il_operand_list) && (NULL != symbol->il_param_list)) ERROR; |
|
413 |
||
414 |
if (NULL != symbol->il_operand_list) |
|
415 |
return symbol->il_operand_list->accept(*this); |
|
416 |
if (NULL != symbol->il_param_list) |
|
417 |
return symbol->il_param_list->accept(*this); |
|
418 |
return NULL; |
|
419 |
} |
|
420 |
||
421 |
/* | il_operand_list ',' il_operand */ |
|
422 |
// SYM_LIST(il_operand_list_c) |
|
423 |
void *function_call_param_iterator_c::visit(il_operand_list_c *symbol) { |
|
424 |
TRACE("il_operand_list_c"); |
|
425 |
return search_list(symbol); |
|
426 |
} |
|
427 |
||
428 |
||
429 |
/* | il_initial_param_list il_param_instruction */ |
|
430 |
// SYM_LIST(il_param_list_c) |
|
431 |
void *function_call_param_iterator_c::visit(il_param_list_c *symbol) { |
|
432 |
TRACE("il_param_list_c"); |
|
433 |
return search_list(symbol); |
|
434 |
} |
|
435 |
||
436 |
/* il_assign_operator il_operand |
|
437 |
* | il_assign_operator '(' eol_list simple_instr_list ')' |
|
438 |
*/ |
|
439 |
// SYM_REF4(il_param_assignment_c, il_assign_operator, il_operand, simple_instr_list, unused) |
|
440 |
void *function_call_param_iterator_c::visit(il_param_assignment_c *symbol) { |
|
441 |
TRACE("il_param_assignment_c"); |
|
442 |
||
443 |
// TODO : We do not yet handle a instruction list passed as parameter !!! |
|
444 |
// since we do not yet support it, it is best to simply stop than to fail silently... |
|
445 |
if (NULL != symbol->simple_instr_list) ERROR; |
|
446 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
447 |
return handle_parameter_assignment((symbol_c *)symbol->il_assign_operator->accept(*this), symbol->il_operand); |
181 | 448 |
} |
449 |
||
450 |
/* il_assign_out_operator variable */ |
|
451 |
// SYM_REF2(il_param_out_assignment_c, il_assign_out_operator, variable); |
|
452 |
void *function_call_param_iterator_c::visit(il_param_out_assignment_c *symbol) { |
|
453 |
TRACE("il_param_out_assignment_c"); |
|
454 |
return handle_parameter_assignment((symbol_c *)symbol->il_assign_out_operator->accept(*this), symbol->variable); |
|
455 |
} |
|
456 |
||
457 |
||
458 |
/*******************/ |
|
459 |
/* B 2.2 Operators */ |
|
460 |
/*******************/ |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
461 |
/* any_identifier ASSIGN */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
462 |
// 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
|
463 |
void *function_call_param_iterator_c::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
|
464 |
TRACE("il_assign_operator_c"); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
465 |
return (void *)symbol->variable_name; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
466 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
467 |
|
181 | 468 |
/*| [NOT] any_identifier SENDTO */ |
469 |
// SYM_REF2(il_assign_out_operator_c, option, variable_name) |
|
470 |
void *function_call_param_iterator_c::visit(il_assign_out_operator_c *symbol) { |
|
471 |
TRACE("il_assign_out_operator_c"); |
|
472 |
||
473 |
// TODO : Handle not_param !!! |
|
474 |
// we do not yet support it, so it is best to simply stop than to fail silently... |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
475 |
// if (NULL != symbol->option) ERROR; |
181 | 476 |
|
477 |
return (void *)symbol->variable_name; |
|
478 |
} |
|
479 |
||
480 |
||
481 |
||
482 |
||
483 |
/***************************************/ |
|
484 |
/* B.3 - Language ST (Structured Text) */ |
|
485 |
/***************************************/ |
|
486 |
/***********************/ |
|
487 |
/* B 3.1 - Expressions */ |
|
488 |
/***********************/ |
|
489 |
||
490 |
/* |
|
491 |
SYM_REF2(function_invocation_c, function_name, parameter_assignment_list) |
|
492 |
*/ |
|
493 |
void *function_call_param_iterator_c::visit(function_invocation_c *symbol) { |
|
494 |
TRACE("function_invocation_c"); |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
495 |
/* If the syntax parser is working correctly, exactly one of the |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
496 |
* following two symbols will be NULL, while the other is != NULL. |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
497 |
*/ |
247
560075ece524
Bug when function call result is a parameter of another function call fixed.
laurent
parents:
202
diff
changeset
|
498 |
if (symbol == (function_invocation_c *)f_call) { |
560075ece524
Bug when function call result is a parameter of another function call fixed.
laurent
parents:
202
diff
changeset
|
499 |
if (symbol-> formal_param_list != NULL) return symbol-> formal_param_list->accept(*this); |
560075ece524
Bug when function call result is a parameter of another function call fixed.
laurent
parents:
202
diff
changeset
|
500 |
if (symbol->nonformal_param_list != NULL) return symbol->nonformal_param_list->accept(*this); |
560075ece524
Bug when function call result is a parameter of another function call fixed.
laurent
parents:
202
diff
changeset
|
501 |
} |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
502 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
503 |
return NULL; |
181 | 504 |
} |
505 |
||
506 |
||
507 |
/********************/ |
|
508 |
/* B 3.2 Statements */ |
|
509 |
/********************/ |
|
510 |
||
511 |
/*********************************/ |
|
512 |
/* B 3.2.1 Assignment Statements */ |
|
513 |
/*********************************/ |
|
514 |
/* |
|
515 |
SYM_REF2(assignment_statement_c, l_exp, r_exp) |
|
516 |
*/ |
|
517 |
||
518 |
/*****************************************/ |
|
519 |
/* B 3.2.2 Subprogram Control Statements */ |
|
520 |
/*****************************************/ |
|
521 |
/* RETURN */ |
|
522 |
// SYM_REF0(return_statement_c) |
|
523 |
||
524 |
||
525 |
/* fb_name '(' [param_assignment_list] ')' */ |
|
526 |
/* param_assignment_list -> may be NULL ! */ |
|
527 |
// SYM_REF2(fb_invocation_c, fb_name, param_assignment_list) |
|
528 |
void *function_call_param_iterator_c::visit(fb_invocation_c *symbol) { |
|
529 |
TRACE("fb_invocation_c"); |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
530 |
/* If the syntax parser is working correctly, only one of the |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
531 |
* following two symbols will be != NULL. |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
532 |
* However, both may be NULL simultaneously! |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
533 |
*/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
534 |
if (symbol-> formal_param_list != NULL) return symbol-> formal_param_list->accept(*this); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
535 |
if (symbol->nonformal_param_list != NULL) return symbol->nonformal_param_list->accept(*this); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
536 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
537 |
return NULL; |
181 | 538 |
} |
539 |
||
540 |
/* helper symbol for fb_invocation */ |
|
541 |
/* param_assignment_list ',' param_assignment */ |
|
542 |
// SYM_LIST(param_assignment_list_c) |
|
543 |
void *function_call_param_iterator_c::visit(param_assignment_list_c *symbol) { |
|
544 |
TRACE("param_assignment_list_c"); |
|
545 |
return search_list(symbol); |
|
546 |
} |
|
547 |
||
548 |
/* variable_name ASSIGN expression */ |
|
549 |
// SYM_REF2(input_variable_param_assignment_c, variable_name, expression) |
|
550 |
void *function_call_param_iterator_c::visit(input_variable_param_assignment_c *symbol) { |
|
551 |
TRACE("input_variable_param_assignment_c"); |
|
552 |
return handle_parameter_assignment(symbol->variable_name, symbol->expression); |
|
553 |
} |
|
554 |
||
555 |
/* [NOT] variable_name '=>' variable */ |
|
556 |
// SYM_REF4(output_variable_param_assignment_c, not_param, variable_name, variable, unused) |
|
557 |
void *function_call_param_iterator_c::visit(output_variable_param_assignment_c *symbol) { |
|
558 |
TRACE("output_variable_param_assignment_c"); |
|
559 |
// TODO : Handle not_param !!! |
|
560 |
if (NULL != symbol->not_param) ERROR; // we do not yet support it, so it is best to simply stop than to fail silently... |
|
561 |
||
562 |
return handle_parameter_assignment(symbol->variable_name, symbol->variable); |
|
563 |
} |
|
564 |
||
565 |
/* helper CLASS for output_variable_param_assignment */ |
|
566 |
// SYM_REF0(not_paramassign_c) |
|
567 |
// TODO... ??? |
|
568 |
||
569 |