author | laurent |
Wed, 16 Mar 2011 10:31:50 +0100 | |
changeset 250 | 5d2927300e2c |
parent 237 | cece842c7417 |
child 265 | 4d222f46f8cc |
permissions | -rwxr-xr-x |
181 | 1 |
/* |
2 |
* (c) 2003 Mario de Sousa |
|
3 |
* |
|
4 |
* Offered to the public under the terms of the GNU General Public License |
|
5 |
* as published by the Free Software Foundation; either version 2 of the |
|
6 |
* License, or (at your option) any later version. |
|
7 |
* |
|
8 |
* This program is distributed in the hope that it will be useful, but |
|
9 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
11 |
* Public License for more details. |
|
12 |
* |
|
13 |
* This code is made available on the understanding that it will not be |
|
14 |
* used in safety-critical situations without a full and competent review. |
|
15 |
*/ |
|
16 |
||
17 |
/* |
|
18 |
* An IEC 61131-3 IL and ST compiler. |
|
19 |
* |
|
20 |
* Based on the |
|
21 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
||
26 |
/* |
|
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; |
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
162 |
en_eno_param_implicit = false; |
181 | 163 |
next_param++; |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
164 |
current_operation = function_param_iterator_c::iterate_op; |
181 | 165 |
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
|
166 |
if (res == NULL) |
181 | 167 |
return NULL; |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
168 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
169 |
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
|
170 |
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
|
171 |
if (identifier == NULL) |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
172 |
ERROR; |
181 | 173 |
current_param_name = identifier; |
174 |
return current_param_name; |
|
175 |
} |
|
176 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
177 |
/* 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
|
178 |
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
|
179 |
if (NULL == param_name) ERROR; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
180 |
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
|
181 |
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
|
182 |
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
|
183 |
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
|
184 |
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
|
185 |
return res_param_name; |
181 | 186 |
} |
187 |
||
188 |
/* Returns the currently referenced parameter's default value, |
|
189 |
* or NULL if none is specified in the function declrataion itself. |
|
190 |
*/ |
|
191 |
symbol_c *function_param_iterator_c::default_value(void) { |
|
192 |
return current_param_default_value; |
|
193 |
} |
|
194 |
||
195 |
/* Returns the currently referenced parameter's type name. */ |
|
196 |
symbol_c *function_param_iterator_c::param_type(void) { |
|
197 |
return current_param_type; |
|
198 |
} |
|
199 |
||
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
200 |
/* Returns if currently referenced parameter is an implicit defined EN/ENO parameter. */ |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
201 |
bool function_param_iterator_c::is_en_eno_param_implicit(void) { |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
202 |
return en_eno_param_implicit; |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
203 |
} |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
204 |
|
181 | 205 |
/* Returns the currently referenced parameter's data passing direction. |
206 |
* i.e. VAR_INPUT, VAR_OUTPUT or VAR_INOUT |
|
207 |
*/ |
|
208 |
function_param_iterator_c::param_direction_t function_param_iterator_c::param_direction(void) { |
|
209 |
return current_param_direction; |
|
210 |
} |
|
211 |
||
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
212 |
void *function_param_iterator_c::visit(implicit_definition_c *symbol) { |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
213 |
en_eno_param_implicit = current_operation == function_param_iterator_c::iterate_op; |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
214 |
return NULL; |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
215 |
} |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
216 |
|
181 | 217 |
/****************************************/ |
218 |
/* 1.4.3 - Declaration & Initialisation */ |
|
219 |
/****************************************/ |
|
220 |
void *function_param_iterator_c::visit(input_declarations_c *symbol) { |
|
221 |
TRACE("input_declarations_c"); |
|
222 |
current_param_direction = direction_in; |
|
223 |
return symbol->input_declaration_list->accept(*this); |
|
224 |
} |
|
225 |
||
226 |
void *function_param_iterator_c::visit(input_declaration_list_c *symbol) {TRACE("input_declaration_list_c"); return iterate_list(symbol);} |
|
227 |
||
228 |
void *function_param_iterator_c::visit(edge_declaration_c *symbol) {TRACE("edge_declaration_c"); return symbol->var1_list->accept(*this);} |
|
229 |
||
230 |
void *function_param_iterator_c::visit(en_param_declaration_c *symbol) { |
|
231 |
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
|
232 |
/* 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
|
233 |
* 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
|
234 |
* 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
|
235 |
* 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
|
236 |
* var1_init_decl_c list! |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
237 |
*/ |
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
238 |
symbol->method->accept(*this); |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
239 |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
240 |
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
|
241 |
current_param_type = symbol->type; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
242 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
243 |
return handle_single_param(symbol->name); |
181 | 244 |
} |
245 |
||
246 |
/* var1_list ':' array_spec_init */ |
|
247 |
//SYM_REF2(array_var_init_decl_c, var1_list, array_spec_init) |
|
235 | 248 |
void *function_param_iterator_c::visit(array_var_init_decl_c *symbol) { |
249 |
TRACE("array_var_init_decl_c"); |
|
250 |
||
251 |
current_param_default_value = spec_init_sperator_c::get_init(symbol->array_spec_init); |
|
252 |
current_param_type = spec_init_sperator_c::get_spec(symbol->array_spec_init); |
|
253 |
||
254 |
return symbol->var1_list->accept(*this); |
|
255 |
} |
|
181 | 256 |
|
257 |
/* var1_list ':' initialized_structure */ |
|
258 |
//SYM_REF2(structured_var_init_decl_c, var1_list, initialized_structure) |
|
235 | 259 |
void *function_param_iterator_c::visit(structured_var_init_decl_c *symbol) { |
260 |
TRACE("structured_var_init_decl_c"); |
|
261 |
||
262 |
current_param_default_value = spec_init_sperator_c::get_init(symbol->initialized_structure); |
|
263 |
current_param_type = spec_init_sperator_c::get_spec(symbol->initialized_structure); |
|
264 |
||
265 |
return symbol->var1_list->accept(*this); |
|
266 |
} |
|
181 | 267 |
|
268 |
void *function_param_iterator_c::visit(output_declarations_c *symbol) { |
|
269 |
TRACE("output_declarations_c"); |
|
270 |
current_param_direction = direction_out; |
|
271 |
return symbol->var_init_decl_list->accept(*this); |
|
272 |
} |
|
273 |
void *function_param_iterator_c::visit(eno_param_declaration_c *symbol) { |
|
274 |
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
|
275 |
/* 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
|
276 |
* 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
|
277 |
* 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
|
278 |
* 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
|
279 |
* var1_init_decl_c list! |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
280 |
*/ |
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
281 |
symbol->method->accept(*this); |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
202
diff
changeset
|
282 |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
283 |
current_param_default_value = NULL; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
284 |
current_param_type = symbol->type; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
285 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
286 |
return handle_single_param(symbol->name); |
181 | 287 |
} |
288 |
void *function_param_iterator_c::visit(input_output_declarations_c *symbol) { |
|
289 |
TRACE("input_output_declarations_c"); |
|
290 |
current_param_direction = direction_inout; |
|
291 |
return symbol->var_declaration_list->accept(*this); |
|
292 |
} |
|
293 |
void *function_param_iterator_c::visit(var_declaration_list_c *symbol) {TRACE("var_declaration_list_c"); return iterate_list(symbol);} |
|
294 |
||
295 |
/* var1_list ':' array_specification */ |
|
296 |
//SYM_REF2(array_var_declaration_c, var1_list, array_specification) |
|
237 | 297 |
void *function_param_iterator_c::visit(array_var_declaration_c *symbol) { |
298 |
TRACE("array_var_declaration_c"); |
|
299 |
||
300 |
current_param_default_value = NULL; |
|
301 |
current_param_type = symbol->array_specification; |
|
302 |
||
303 |
return symbol->var1_list->accept(*this); |
|
304 |
} |
|
181 | 305 |
|
306 |
/* var1_list ':' structure_type_name */ |
|
307 |
//SYM_REF2(structured_var_declaration_c, var1_list, structure_type_name) |
|
235 | 308 |
void *function_param_iterator_c::visit(structured_var_declaration_c *symbol) { |
309 |
TRACE("structured_var_declaration_c"); |
|
310 |
||
311 |
current_param_default_value = NULL; |
|
312 |
current_param_type = symbol->structure_type_name; |
|
313 |
||
314 |
return symbol->var1_list->accept(*this); |
|
315 |
} |
|
181 | 316 |
|
317 |
/* VAR [CONSTANT] var_init_decl_list END_VAR */ |
|
318 |
void *function_param_iterator_c::visit(var_declarations_c *symbol) {TRACE("var_declarations_c"); return NULL;} |
|
319 |
||
320 |
/*| VAR_EXTERNAL [CONSTANT] external_declaration_list END_VAR */ |
|
321 |
/* option -> may be NULL ! */ |
|
322 |
// SYM_REF2(external_var_declarations_c, option, external_declaration_list) |
|
323 |
void *function_param_iterator_c::visit(external_var_declarations_c *symbol) { |
|
324 |
TRACE("external_var_declarations_c"); |
|
325 |
current_param_direction = direction_extref; |
|
326 |
return symbol->external_declaration_list->accept(*this); |
|
327 |
} |
|
328 |
||
329 |
/* helper symbol for external_var_declarations */ |
|
330 |
/*| external_declaration_list external_declaration';' */ |
|
331 |
// SYM_LIST(external_declaration_list_c) |
|
332 |
void *function_param_iterator_c::visit(external_declaration_list_c *symbol) {TRACE("external_declaration_list_c"); return iterate_list(symbol);} |
|
333 |
||
334 |
/* global_var_name ':' (simple_specification|subrange_specification|enumerated_specification|array_specification|prev_declared_structure_type_name|function_block_type_name */ |
|
335 |
//SYM_REF2(external_declaration_c, global_var_name, specification) |
|
336 |
void *function_param_iterator_c::visit(external_declaration_c *symbol) { |
|
337 |
TRACE("external_declaration_c"); |
|
338 |
/* It is OK to store these values in the current_param_XXX |
|
339 |
* variables, because if the desired parameter is not in the |
|
340 |
* variable list we will be analysing, the current_param_XXXX |
|
341 |
* variables will get overwritten when we visit the next |
|
342 |
* var1_init_decl_c list! |
|
343 |
*/ |
|
344 |
current_param_default_value = spec_init_sperator_c::get_init(symbol->specification); |
|
345 |
current_param_type = spec_init_sperator_c::get_spec(symbol->specification); |
|
346 |
||
347 |
return handle_single_param(symbol->global_var_name); |
|
348 |
} |
|
349 |
||
350 |
||
351 |
#if 0 |
|
352 |
/*| VAR_GLOBAL [CONSTANT|RETAIN] global_var_decl_list END_VAR */ |
|
353 |
/* option -> may be NULL ! */ |
|
354 |
SYM_REF2(global_var_declarations_c, option, global_var_decl_list) |
|
355 |
||
356 |
/* helper symbol for global_var_declarations */ |
|
357 |
/*| global_var_decl_list global_var_decl ';' */ |
|
358 |
SYM_LIST(global_var_decl_list_c) |
|
359 |
||
360 |
/*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */ |
|
361 |
/* type_specification ->may be NULL ! */ |
|
362 |
SYM_REF2(global_var_decl_c, global_var_spec, type_specification) |
|
363 |
||
364 |
/*| global_var_name location */ |
|
365 |
SYM_REF2(global_var_spec_c, global_var_name, location) |
|
366 |
||
367 |
/* AT direct_variable */ |
|
368 |
SYM_REF2(location_c, direct_variable, unused) |
|
369 |
||
370 |
/*| global_var_list ',' global_var_name */ |
|
371 |
SYM_LIST(global_var_list_c) |
|
372 |
||
373 |
/* var1_list ':' single_byte_string_spec */ |
|
374 |
SYM_REF2(single_byte_string_var_declaration_c, var1_list, single_byte_string_spec) |
|
375 |
||
376 |
/* STRING ['[' integer ']'] [ASSIGN single_byte_character_string] */ |
|
377 |
/* integer ->may be NULL ! */ |
|
378 |
/* single_byte_character_string ->may be NULL ! */ |
|
379 |
SYM_REF2(single_byte_string_spec_c, integer, single_byte_character_string) |
|
380 |
||
381 |
/* var1_list ':' double_byte_string_spec */ |
|
382 |
SYM_REF2(double_byte_string_var_declaration_c, var1_list, double_byte_string_spec) |
|
383 |
||
384 |
/* WSTRING ['[' integer ']'] [ASSIGN double_byte_character_string] */ |
|
385 |
/* integer ->may be NULL ! */ |
|
386 |
/* double_byte_character_string ->may be NULL ! */ |
|
387 |
SYM_REF2(double_byte_string_spec_c, integer, double_byte_character_string) |
|
388 |
||
389 |
/*| VAR [RETAIN|NON_RETAIN] incompl_located_var_decl_list END_VAR */ |
|
390 |
/* option ->may be NULL ! */ |
|
391 |
SYM_REF2(incompl_located_var_declarations_c, option, incompl_located_var_decl_list) |
|
392 |
||
393 |
/* helper symbol for incompl_located_var_declarations */ |
|
394 |
/*| incompl_located_var_decl_list incompl_located_var_decl ';' */ |
|
395 |
SYM_LIST(incompl_located_var_decl_list_c) |
|
396 |
||
397 |
/* variable_name incompl_location ':' var_spec */ |
|
398 |
SYM_REF4(incompl_located_var_decl_c, variable_name, incompl_location, var_spec, unused) |
|
399 |
||
400 |
/* AT incompl_location_token */ |
|
401 |
SYM_TOKEN(incompl_location_c) |
|
402 |
#endif |
|
403 |
||
404 |
||
405 |
void *function_param_iterator_c::visit(var1_init_decl_c *symbol) { |
|
406 |
TRACE("var1_init_decl_c"); |
|
407 |
/* It is OK to store these values in the current_param_XXX |
|
408 |
* variables, because if the desired parameter is not in the |
|
409 |
* variable list we will be analysing, the current_param_XXXX |
|
410 |
* variables will get overwritten when we visit the next |
|
411 |
* var1_init_decl_c list! |
|
412 |
*/ |
|
413 |
current_param_default_value = spec_init_sperator_c::get_init(symbol->spec_init); |
|
414 |
current_param_type = spec_init_sperator_c::get_spec(symbol->spec_init); |
|
415 |
||
416 |
return symbol->var1_list->accept(*this); |
|
417 |
} |
|
418 |
||
419 |
||
420 |
||
421 |
void *function_param_iterator_c::visit(var1_list_c *symbol) { |
|
422 |
TRACE("var1_list_c"); |
|
423 |
return handle_param_list(symbol); |
|
424 |
} |
|
425 |
||
426 |
void *function_param_iterator_c::visit(var_init_decl_list_c *symbol) {TRACE("var_init_decl_list_c"); return iterate_list(symbol);} |
|
427 |
||
428 |
||
429 |
/***********************/ |
|
430 |
/* B 1.5.1 - Functions */ |
|
431 |
/***********************/ |
|
432 |
void *function_param_iterator_c::visit(function_declaration_c *symbol) {TRACE("function_declaration_c"); return symbol->var_declarations_list->accept(*this);} |
|
433 |
/* intermediate helper symbol for function_declaration */ |
|
434 |
void *function_param_iterator_c::visit(var_declarations_list_c *symbol) {TRACE("var_declarations_list_c"); return iterate_list(symbol);} |
|
435 |
void *function_param_iterator_c::visit(function_var_decls_c *symbol) {TRACE("function_var_decls_c"); /* ignore */ return NULL;} |
|
436 |
||
437 |
||
438 |
/*****************************/ |
|
439 |
/* B 1.5.2 - Function Blocks */ |
|
440 |
/*****************************/ |
|
441 |
/* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ |
|
442 |
void *function_param_iterator_c::visit(function_block_declaration_c *symbol) {TRACE("function_block_declaration_c"); return symbol->var_declarations->accept(*this);} |
|
443 |
||
444 |
/* intermediate helper symbol for function_declaration */ |
|
445 |
/* { io_var_declarations | other_var_declarations } */ |
|
446 |
/* |
|
447 |
* NOTE: we re-use the var_declarations_list_c |
|
448 |
*/ |
|
449 |
||
450 |
/* VAR_TEMP temp_var_decl_list END_VAR */ |
|
451 |
void *function_param_iterator_c::visit(temp_var_decls_c *symbol) {TRACE("temp_var_decls_c"); /* ignore */ return NULL;} |
|
452 |
void *function_param_iterator_c::visit(temp_var_decls_list_c *symbol) {TRACE("temp_var_decls_list_c"); /* ignore */ return NULL;} |
|
453 |
||
454 |
/* VAR NON_RETAIN var_init_decl_list END_VAR */ |
|
455 |
void *function_param_iterator_c::visit(non_retentive_var_decls_c *symbol) {TRACE("non_retentive_var_decls_c"); /* ignore */ return NULL;} |
|
456 |
||
457 |
||
458 |
/**********************/ |
|
459 |
/* B 1.5.3 - Programs */ |
|
460 |
/**********************/ |
|
461 |
/* PROGRAM program_type_name program_var_declarations_list function_block_body END_PROGRAM */ |
|
462 |
// SYM_REF4(program_declaration_c, program_type_name, var_declarations, function_block_body, unused) |
|
463 |
void *function_param_iterator_c::visit(program_declaration_c *symbol) {TRACE("program_declaration_c"); return symbol->var_declarations->accept(*this);} |
|
464 |
||
465 |
/* intermediate helper symbol for program_declaration_c */ |
|
466 |
/* { io_var_declarations | other_var_declarations } */ |
|
467 |
/* |
|
468 |
* NOTE: we re-use the var_declarations_list_c |
|
469 |
*/ |
|
470 |
||
471 |
||
472 |
||
473 |
||
474 |
||
475 |