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