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