author | laurent |
Wed, 02 Sep 2009 17:35:56 +0200 | |
changeset 207 | 56ee922d0112 |
parent 202 | da1a8186f86f |
child 233 | 3d23a68183d3 |
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 |
/* |
|
27 |
* Function parameter iterator. |
|
28 |
* Iterate through the in/out parameters of a function declaration. |
|
29 |
* Function blocks are also suported. |
|
30 |
* |
|
31 |
* This is part of the 4th stage that generates |
|
32 |
* a c++ source program equivalent to the IL and ST |
|
33 |
* code. |
|
34 |
*/ |
|
35 |
||
36 |
/* Given a function_declaration_c, iterate through each |
|
37 |
* function in/out/inout parameter, returning the name |
|
38 |
* of each parameter...function_param_iterator_c |
|
39 |
*/ |
|
40 |
||
41 |
||
42 |
||
43 |
#include "function_param_iterator.hh" |
|
44 |
#include "spec_init_separator.hh" |
|
45 |
#include <strings.h> |
|
46 |
||
47 |
||
48 |
//#define DEBUG |
|
49 |
#ifdef DEBUG |
|
50 |
#define TRACE(classname) printf("\n____%s____\n",classname); |
|
51 |
#else |
|
52 |
#define TRACE(classname) |
|
53 |
#endif |
|
54 |
||
55 |
||
56 |
#define ERROR error_exit(__FILE__,__LINE__) |
|
57 |
/* function defined in main.cc */ |
|
58 |
extern void error_exit(const char *file_name, int line_no); |
|
59 |
||
60 |
||
61 |
||
62 |
void* function_param_iterator_c::handle_param_list(list_c *list) { |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
63 |
switch (current_operation) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
64 |
case iterate_op: |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
65 |
if (next_param <= param_count + list->n) |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
66 |
return list->elements[next_param - param_count - 1]; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
67 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
68 |
/* the desired param is not on this list... */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
69 |
param_count += list->n; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
70 |
break; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
71 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
72 |
case search_op: |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
73 |
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
|
74 |
identifier_c *variable_name = dynamic_cast<identifier_c *>(list->elements[i]); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
75 |
if (variable_name == NULL) ERROR; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
76 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
77 |
if (strcasecmp(search_param_name->value, variable_name->value) == 0) |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
78 |
/* FOUND! This is the same parameter!! */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
79 |
return (void *)variable_name; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
80 |
} |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
81 |
break; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
82 |
} /* switch */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
83 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
84 |
/* Not found! */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
85 |
return NULL; |
181 | 86 |
} |
87 |
||
88 |
void* function_param_iterator_c::handle_single_param(symbol_c *var_name) { |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
89 |
switch (current_operation) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
90 |
case iterate_op: |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
91 |
param_count++; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
92 |
if (next_param == param_count) |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
93 |
return var_name; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
94 |
break; |
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 |
case search_op: |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
97 |
identifier_c *variable_name = dynamic_cast<identifier_c *>(var_name); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
98 |
if (variable_name == NULL) ERROR; |
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 |
if (strcasecmp(search_param_name->value, variable_name->value) == 0) |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
101 |
/* FOUND! This is the same parameter!! */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
102 |
return (void *)variable_name; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
103 |
break; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
104 |
} /* switch */ |
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 |
/* Not found! */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
107 |
return NULL; |
181 | 108 |
} |
109 |
||
110 |
void* function_param_iterator_c::iterate_list(list_c *list) { |
|
111 |
void *res; |
|
112 |
for (int i = 0; i < list->n; i++) { |
|
113 |
res = list->elements[i]->accept(*this); |
|
114 |
if (res != NULL) |
|
115 |
return res; |
|
116 |
} |
|
117 |
return NULL; |
|
118 |
} |
|
119 |
||
120 |
/* start off at the first parameter once again... */ |
|
121 |
void function_param_iterator_c::reset(void) { |
|
122 |
next_param = param_count = 0; |
|
123 |
current_param_name = NULL; |
|
124 |
current_param_type = current_param_default_value = NULL; |
|
202
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 |
|
181 | 127 |
|
128 |
/* initialise the iterator object. |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
129 |
* We must be given a reference to one of the following |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
130 |
* - function_declaration_c |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
131 |
* - function_block_declaration_c |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
132 |
* - program_declaration_c |
181 | 133 |
* that will be analysed... |
134 |
*/ |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
135 |
function_param_iterator_c::function_param_iterator_c(symbol_c *pou_decl) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
136 |
/* do some consistency checks... */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
137 |
function_declaration_c * f_decl = dynamic_cast<function_declaration_c *>(pou_decl); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
138 |
function_block_declaration_c *fb_decl = dynamic_cast<function_block_declaration_c *>(pou_decl); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
139 |
program_declaration_c * p_decl = dynamic_cast<program_declaration_c *>(pou_decl); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
140 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
141 |
if ((NULL == f_decl) && (NULL == fb_decl) && (NULL == p_decl)) ERROR; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
142 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
143 |
/* OK. Now initialise this object... */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
144 |
this->f_decl = pou_decl; |
181 | 145 |
reset(); |
146 |
} |
|
147 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
148 |
|
181 | 149 |
|
150 |
/* Skip to the next parameter. After object creation, |
|
151 |
* the object references on parameter _before_ the first, so |
|
152 |
* this function must be called once to get the object to |
|
153 |
* reference the first parameter... |
|
154 |
* |
|
155 |
* Returns the parameter's name! |
|
156 |
*/ |
|
157 |
identifier_c *function_param_iterator_c::next(void) { |
|
158 |
void *res; |
|
159 |
identifier_c *identifier; |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
160 |
|
181 | 161 |
param_count = 0; |
162 |
next_param++; |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
163 |
current_operation = function_param_iterator_c::iterate_op; |
181 | 164 |
res = f_decl->accept(*this); |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
165 |
if (res == NULL) |
181 | 166 |
return NULL; |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
167 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
168 |
symbol_c *sym = (symbol_c *)res; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
169 |
identifier = dynamic_cast<identifier_c *>(sym); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
170 |
if (identifier == NULL) |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
171 |
ERROR; |
181 | 172 |
current_param_name = identifier; |
173 |
return current_param_name; |
|
174 |
} |
|
175 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
176 |
/* Search for the value passed to the parameter named <param_name>... */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
177 |
identifier_c *function_param_iterator_c::search(symbol_c *param_name) { |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
178 |
if (NULL == param_name) ERROR; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
179 |
search_param_name = dynamic_cast<identifier_c *>(param_name); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
180 |
if (NULL == search_param_name) ERROR; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
181 |
current_operation = function_param_iterator_c::search_op; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
182 |
void *res = f_decl->accept(*this); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
183 |
identifier_c *res_param_name = dynamic_cast<identifier_c *>((symbol_c *)res); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
184 |
return res_param_name; |
181 | 185 |
} |
186 |
||
187 |
/* Returns the currently referenced parameter's default value, |
|
188 |
* or NULL if none is specified in the function declrataion itself. |
|
189 |
*/ |
|
190 |
symbol_c *function_param_iterator_c::default_value(void) { |
|
191 |
return current_param_default_value; |
|
192 |
} |
|
193 |
||
194 |
/* Returns the currently referenced parameter's type name. */ |
|
195 |
symbol_c *function_param_iterator_c::param_type(void) { |
|
196 |
return current_param_type; |
|
197 |
} |
|
198 |
||
199 |
/* Returns the currently referenced parameter's data passing direction. |
|
200 |
* i.e. VAR_INPUT, VAR_OUTPUT or VAR_INOUT |
|
201 |
*/ |
|
202 |
function_param_iterator_c::param_direction_t function_param_iterator_c::param_direction(void) { |
|
203 |
return current_param_direction; |
|
204 |
} |
|
205 |
||
206 |
/****************************************/ |
|
207 |
/* 1.4.3 - Declaration & Initialisation */ |
|
208 |
/****************************************/ |
|
209 |
void *function_param_iterator_c::visit(input_declarations_c *symbol) { |
|
210 |
TRACE("input_declarations_c"); |
|
211 |
current_param_direction = direction_in; |
|
212 |
return symbol->input_declaration_list->accept(*this); |
|
213 |
} |
|
214 |
||
215 |
void *function_param_iterator_c::visit(input_declaration_list_c *symbol) {TRACE("input_declaration_list_c"); return iterate_list(symbol);} |
|
216 |
||
217 |
void *function_param_iterator_c::visit(edge_declaration_c *symbol) {TRACE("edge_declaration_c"); return symbol->var1_list->accept(*this);} |
|
218 |
||
219 |
void *function_param_iterator_c::visit(en_param_declaration_c *symbol) { |
|
220 |
TRACE("en_param_declaration_c"); |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
221 |
/* It is OK to store these values in the current_param_XXX |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
222 |
* variables, because if the desired parameter is not in the |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
223 |
* variable list we will be analysing, the current_param_XXXX |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
224 |
* variables will get overwritten when we visit the next |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
225 |
* var1_init_decl_c list! |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
226 |
*/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
227 |
current_param_default_value = symbol->value; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
228 |
current_param_type = symbol->type; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
229 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
230 |
return handle_single_param(symbol->name); |
181 | 231 |
} |
232 |
||
233 |
/* var1_list ':' array_spec_init */ |
|
234 |
//SYM_REF2(array_var_init_decl_c, var1_list, array_spec_init) |
|
235 |
void *function_param_iterator_c::visit(array_var_init_decl_c *symbol) {TRACE("array_var_init_decl_c"); return symbol->var1_list->accept(*this);} |
|
236 |
||
237 |
/* var1_list ':' initialized_structure */ |
|
238 |
//SYM_REF2(structured_var_init_decl_c, var1_list, initialized_structure) |
|
239 |
void *function_param_iterator_c::visit(structured_var_init_decl_c *symbol) {TRACE("structured_var_init_decl_c"); return symbol->var1_list->accept(*this);} |
|
240 |
||
241 |
void *function_param_iterator_c::visit(output_declarations_c *symbol) { |
|
242 |
TRACE("output_declarations_c"); |
|
243 |
current_param_direction = direction_out; |
|
244 |
return symbol->var_init_decl_list->accept(*this); |
|
245 |
} |
|
246 |
void *function_param_iterator_c::visit(eno_param_declaration_c *symbol) { |
|
247 |
TRACE("eno_param_declaration_c"); |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
248 |
/* It is OK to store these values in the current_param_XXX |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
249 |
* variables, because if the desired parameter is not in the |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
250 |
* variable list we will be analysing, the current_param_XXXX |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
251 |
* variables will get overwritten when we visit the next |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
252 |
* var1_init_decl_c list! |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
253 |
*/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
254 |
current_param_default_value = NULL; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
255 |
current_param_type = symbol->type; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
256 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
257 |
return handle_single_param(symbol->name); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
258 |
#if 0 |
181 | 259 |
if (eno_declared) ERROR; |
260 |
return (void *)declare_eno_param(); |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
261 |
#endif |
181 | 262 |
} |
263 |
void *function_param_iterator_c::visit(input_output_declarations_c *symbol) { |
|
264 |
TRACE("input_output_declarations_c"); |
|
265 |
current_param_direction = direction_inout; |
|
266 |
return symbol->var_declaration_list->accept(*this); |
|
267 |
} |
|
268 |
void *function_param_iterator_c::visit(var_declaration_list_c *symbol) {TRACE("var_declaration_list_c"); return iterate_list(symbol);} |
|
269 |
||
270 |
/* var1_list ':' array_specification */ |
|
271 |
//SYM_REF2(array_var_declaration_c, var1_list, array_specification) |
|
272 |
void *function_param_iterator_c::visit(array_var_declaration_c *symbol) {TRACE("array_var_declaration_c"); return symbol->var1_list->accept(*this);} |
|
273 |
||
274 |
/* var1_list ':' structure_type_name */ |
|
275 |
//SYM_REF2(structured_var_declaration_c, var1_list, structure_type_name) |
|
276 |
void *function_param_iterator_c::visit(structured_var_declaration_c *symbol) {TRACE("structured_var_declaration_c"); return symbol->var1_list->accept(*this);} |
|
277 |
||
278 |
/* VAR [CONSTANT] var_init_decl_list END_VAR */ |
|
279 |
void *function_param_iterator_c::visit(var_declarations_c *symbol) {TRACE("var_declarations_c"); return NULL;} |
|
280 |
||
281 |
/*| VAR_EXTERNAL [CONSTANT] external_declaration_list END_VAR */ |
|
282 |
/* option -> may be NULL ! */ |
|
283 |
// SYM_REF2(external_var_declarations_c, option, external_declaration_list) |
|
284 |
void *function_param_iterator_c::visit(external_var_declarations_c *symbol) { |
|
285 |
TRACE("external_var_declarations_c"); |
|
286 |
current_param_direction = direction_extref; |
|
287 |
return symbol->external_declaration_list->accept(*this); |
|
288 |
} |
|
289 |
||
290 |
/* helper symbol for external_var_declarations */ |
|
291 |
/*| external_declaration_list external_declaration';' */ |
|
292 |
// SYM_LIST(external_declaration_list_c) |
|
293 |
void *function_param_iterator_c::visit(external_declaration_list_c *symbol) {TRACE("external_declaration_list_c"); return iterate_list(symbol);} |
|
294 |
||
295 |
/* global_var_name ':' (simple_specification|subrange_specification|enumerated_specification|array_specification|prev_declared_structure_type_name|function_block_type_name */ |
|
296 |
//SYM_REF2(external_declaration_c, global_var_name, specification) |
|
297 |
void *function_param_iterator_c::visit(external_declaration_c *symbol) { |
|
298 |
TRACE("external_declaration_c"); |
|
299 |
/* It is OK to store these values in the current_param_XXX |
|
300 |
* variables, because if the desired parameter is not in the |
|
301 |
* variable list we will be analysing, the current_param_XXXX |
|
302 |
* variables will get overwritten when we visit the next |
|
303 |
* var1_init_decl_c list! |
|
304 |
*/ |
|
305 |
current_param_default_value = spec_init_sperator_c::get_init(symbol->specification); |
|
306 |
current_param_type = spec_init_sperator_c::get_spec(symbol->specification); |
|
307 |
||
308 |
return handle_single_param(symbol->global_var_name); |
|
309 |
} |
|
310 |
||
311 |
||
312 |
#if 0 |
|
313 |
/*| VAR_GLOBAL [CONSTANT|RETAIN] global_var_decl_list END_VAR */ |
|
314 |
/* option -> may be NULL ! */ |
|
315 |
SYM_REF2(global_var_declarations_c, option, global_var_decl_list) |
|
316 |
||
317 |
/* helper symbol for global_var_declarations */ |
|
318 |
/*| global_var_decl_list global_var_decl ';' */ |
|
319 |
SYM_LIST(global_var_decl_list_c) |
|
320 |
||
321 |
/*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */ |
|
322 |
/* type_specification ->may be NULL ! */ |
|
323 |
SYM_REF2(global_var_decl_c, global_var_spec, type_specification) |
|
324 |
||
325 |
/*| global_var_name location */ |
|
326 |
SYM_REF2(global_var_spec_c, global_var_name, location) |
|
327 |
||
328 |
/* AT direct_variable */ |
|
329 |
SYM_REF2(location_c, direct_variable, unused) |
|
330 |
||
331 |
/*| global_var_list ',' global_var_name */ |
|
332 |
SYM_LIST(global_var_list_c) |
|
333 |
||
334 |
/* var1_list ':' single_byte_string_spec */ |
|
335 |
SYM_REF2(single_byte_string_var_declaration_c, var1_list, single_byte_string_spec) |
|
336 |
||
337 |
/* STRING ['[' integer ']'] [ASSIGN single_byte_character_string] */ |
|
338 |
/* integer ->may be NULL ! */ |
|
339 |
/* single_byte_character_string ->may be NULL ! */ |
|
340 |
SYM_REF2(single_byte_string_spec_c, integer, single_byte_character_string) |
|
341 |
||
342 |
/* var1_list ':' double_byte_string_spec */ |
|
343 |
SYM_REF2(double_byte_string_var_declaration_c, var1_list, double_byte_string_spec) |
|
344 |
||
345 |
/* WSTRING ['[' integer ']'] [ASSIGN double_byte_character_string] */ |
|
346 |
/* integer ->may be NULL ! */ |
|
347 |
/* double_byte_character_string ->may be NULL ! */ |
|
348 |
SYM_REF2(double_byte_string_spec_c, integer, double_byte_character_string) |
|
349 |
||
350 |
/*| VAR [RETAIN|NON_RETAIN] incompl_located_var_decl_list END_VAR */ |
|
351 |
/* option ->may be NULL ! */ |
|
352 |
SYM_REF2(incompl_located_var_declarations_c, option, incompl_located_var_decl_list) |
|
353 |
||
354 |
/* helper symbol for incompl_located_var_declarations */ |
|
355 |
/*| incompl_located_var_decl_list incompl_located_var_decl ';' */ |
|
356 |
SYM_LIST(incompl_located_var_decl_list_c) |
|
357 |
||
358 |
/* variable_name incompl_location ':' var_spec */ |
|
359 |
SYM_REF4(incompl_located_var_decl_c, variable_name, incompl_location, var_spec, unused) |
|
360 |
||
361 |
/* AT incompl_location_token */ |
|
362 |
SYM_TOKEN(incompl_location_c) |
|
363 |
#endif |
|
364 |
||
365 |
||
366 |
void *function_param_iterator_c::visit(var1_init_decl_c *symbol) { |
|
367 |
TRACE("var1_init_decl_c"); |
|
368 |
/* It is OK to store these values in the current_param_XXX |
|
369 |
* variables, because if the desired parameter is not in the |
|
370 |
* variable list we will be analysing, the current_param_XXXX |
|
371 |
* variables will get overwritten when we visit the next |
|
372 |
* var1_init_decl_c list! |
|
373 |
*/ |
|
374 |
current_param_default_value = spec_init_sperator_c::get_init(symbol->spec_init); |
|
375 |
current_param_type = spec_init_sperator_c::get_spec(symbol->spec_init); |
|
376 |
||
377 |
return symbol->var1_list->accept(*this); |
|
378 |
} |
|
379 |
||
380 |
||
381 |
||
382 |
void *function_param_iterator_c::visit(var1_list_c *symbol) { |
|
383 |
TRACE("var1_list_c"); |
|
384 |
return handle_param_list(symbol); |
|
385 |
} |
|
386 |
||
387 |
void *function_param_iterator_c::visit(var_init_decl_list_c *symbol) {TRACE("var_init_decl_list_c"); return iterate_list(symbol);} |
|
388 |
||
389 |
||
390 |
/***********************/ |
|
391 |
/* B 1.5.1 - Functions */ |
|
392 |
/***********************/ |
|
393 |
void *function_param_iterator_c::visit(function_declaration_c *symbol) {TRACE("function_declaration_c"); return symbol->var_declarations_list->accept(*this);} |
|
394 |
/* intermediate helper symbol for function_declaration */ |
|
395 |
void *function_param_iterator_c::visit(var_declarations_list_c *symbol) {TRACE("var_declarations_list_c"); return iterate_list(symbol);} |
|
396 |
void *function_param_iterator_c::visit(function_var_decls_c *symbol) {TRACE("function_var_decls_c"); /* ignore */ return NULL;} |
|
397 |
||
398 |
||
399 |
/*****************************/ |
|
400 |
/* B 1.5.2 - Function Blocks */ |
|
401 |
/*****************************/ |
|
402 |
/* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ |
|
403 |
void *function_param_iterator_c::visit(function_block_declaration_c *symbol) {TRACE("function_block_declaration_c"); return symbol->var_declarations->accept(*this);} |
|
404 |
||
405 |
/* intermediate helper symbol for function_declaration */ |
|
406 |
/* { io_var_declarations | other_var_declarations } */ |
|
407 |
/* |
|
408 |
* NOTE: we re-use the var_declarations_list_c |
|
409 |
*/ |
|
410 |
||
411 |
/* VAR_TEMP temp_var_decl_list END_VAR */ |
|
412 |
void *function_param_iterator_c::visit(temp_var_decls_c *symbol) {TRACE("temp_var_decls_c"); /* ignore */ return NULL;} |
|
413 |
void *function_param_iterator_c::visit(temp_var_decls_list_c *symbol) {TRACE("temp_var_decls_list_c"); /* ignore */ return NULL;} |
|
414 |
||
415 |
/* VAR NON_RETAIN var_init_decl_list END_VAR */ |
|
416 |
void *function_param_iterator_c::visit(non_retentive_var_decls_c *symbol) {TRACE("non_retentive_var_decls_c"); /* ignore */ return NULL;} |
|
417 |
||
418 |
||
419 |
/**********************/ |
|
420 |
/* B 1.5.3 - Programs */ |
|
421 |
/**********************/ |
|
422 |
/* PROGRAM program_type_name program_var_declarations_list function_block_body END_PROGRAM */ |
|
423 |
// SYM_REF4(program_declaration_c, program_type_name, var_declarations, function_block_body, unused) |
|
424 |
void *function_param_iterator_c::visit(program_declaration_c *symbol) {TRACE("program_declaration_c"); return symbol->var_declarations->accept(*this);} |
|
425 |
||
426 |
/* intermediate helper symbol for program_declaration_c */ |
|
427 |
/* { io_var_declarations | other_var_declarations } */ |
|
428 |
/* |
|
429 |
* NOTE: we re-use the var_declarations_list_c |
|
430 |
*/ |
|
431 |
||
432 |
||
433 |
||
434 |
||
435 |
||
436 |