author | laurent |
Mon, 21 Sep 2009 12:04:15 +0200 | |
changeset 210 | 8387cac2aba6 |
parent 208 | c72748a12ae3 |
child 216 | 136d6ae70745 |
permissions | -rwxr-xr-x |
70 | 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 |
* Conversion of st statements (i.e. ST code). |
|
28 |
* |
|
29 |
* This is part of the 4th stage that generates |
|
30 |
* a c++ source program equivalent to the IL and ST |
|
31 |
* code. |
|
32 |
*/ |
|
33 |
||
34 |
||
35 |
/***********************************************************************/ |
|
36 |
/***********************************************************************/ |
|
37 |
/***********************************************************************/ |
|
38 |
/***********************************************************************/ |
|
39 |
||
40 |
||
41 |
class generate_c_st_c: public generate_c_typedecl_c { |
|
42 |
||
43 |
private: |
|
44 |
/* When calling a function block, we must first find it's type, |
|
45 |
* by searching through the declarations of the variables currently |
|
46 |
* in scope. |
|
47 |
* This class does just that... |
|
48 |
* A new class is instantiated whenever we begin generating the code |
|
49 |
* for a function block type declaration, or a program declaration. |
|
50 |
* This object instance will then later be called while the |
|
51 |
* function block's or the program's body is being handled. |
|
52 |
* |
|
53 |
* Note that functions cannot contain calls to function blocks, |
|
54 |
* so we do not create an object instance when handling |
|
55 |
* a function declaration. |
|
56 |
*/ |
|
57 |
search_fb_instance_decl_c *search_fb_instance_decl; |
|
58 |
||
59 |
/* When compiling st code, it becomes necessary to determine the |
|
60 |
* data type of st expressions. To do this, we must first find the |
|
61 |
* st operand's declaration, within the scope of the function block |
|
62 |
* or function currently being processed. |
|
63 |
* The following object does just that... |
|
64 |
* This object instance will then later be called while the |
|
65 |
* remaining st code is being handled. |
|
66 |
*/ |
|
67 |
search_expression_type_c *search_expression_type; |
|
68 |
||
69 |
search_varfb_instance_type_c *search_varfb_instance_type; |
|
70 |
||
98 | 71 |
search_base_type_c search_base_type; |
72 |
||
73 |
symbol_c* current_array_type; |
|
74 |
||
145 | 75 |
bool current_param_is_pointer; |
76 |
||
70 | 77 |
public: |
78 |
generate_c_st_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) |
|
79 |
: generate_c_typedecl_c(s4o_ptr) { |
|
80 |
search_fb_instance_decl = new search_fb_instance_decl_c(scope); |
|
81 |
search_expression_type = new search_expression_type_c(scope); |
|
82 |
search_varfb_instance_type = new search_varfb_instance_type_c(scope); |
|
83 |
this->set_variable_prefix(variable_prefix); |
|
98 | 84 |
current_array_type = NULL; |
145 | 85 |
current_param_is_pointer = false; |
70 | 86 |
} |
87 |
||
88 |
virtual ~generate_c_st_c(void) { |
|
89 |
delete search_fb_instance_decl; |
|
90 |
delete search_expression_type; |
|
91 |
delete search_varfb_instance_type; |
|
92 |
} |
|
93 |
||
94 |
||
95 |
public: |
|
96 |
void generate(statement_list_c *stl) { |
|
97 |
stl->accept(*this); |
|
98 |
} |
|
99 |
||
100 |
private: |
|
101 |
||
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
102 |
|
70 | 103 |
/*********************/ |
104 |
/* B 1.4 - Variables */ |
|
105 |
/*********************/ |
|
106 |
void *visit(symbolic_variable_c *symbol) { |
|
107 |
unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); |
|
145 | 108 |
if (!current_param_is_pointer && (vartype == search_var_instance_decl_c::external_vt || vartype == search_var_instance_decl_c::located_vt)) { |
70 | 109 |
s4o.print("*("); |
110 |
generate_c_base_c::visit(symbol); |
|
111 |
s4o.print(")"); |
|
112 |
} |
|
145 | 113 |
else if (current_param_is_pointer && vartype != search_var_instance_decl_c::external_vt && vartype != search_var_instance_decl_c::located_vt) { |
114 |
s4o.print("&("); |
|
115 |
generate_c_base_c::visit(symbol); |
|
116 |
s4o.print(")"); |
|
117 |
} |
|
70 | 118 |
else { |
119 |
generate_c_base_c::visit(symbol); |
|
120 |
} |
|
121 |
return NULL; |
|
122 |
} |
|
123 |
||
124 |
/********************************************/ |
|
125 |
/* B.1.4.1 Directly Represented Variables */ |
|
126 |
/********************************************/ |
|
127 |
// direct_variable: direct_variable_token {$$ = new direct_variable_c($1);}; |
|
128 |
void *visit(direct_variable_c *symbol) { |
|
129 |
TRACE("direct_variable_c"); |
|
130 |
/* Do not use print_token() as it will change everything into uppercase */ |
|
131 |
if (strlen(symbol->value) == 0) ERROR; |
|
145 | 132 |
if (!current_param_is_pointer) { |
133 |
s4o.print("*("); |
|
134 |
} |
|
70 | 135 |
this->print_variable_prefix(); |
136 |
s4o.printlocation(symbol->value + 1); |
|
145 | 137 |
if (!current_param_is_pointer) { |
138 |
s4o.print(")"); |
|
139 |
} |
|
70 | 140 |
return NULL; |
141 |
} |
|
142 |
||
98 | 143 |
/*************************************/ |
144 |
/* B.1.4.2 Multi-element Variables */ |
|
145 |
/*************************************/ |
|
146 |
||
147 |
/* subscripted_variable '[' subscript_list ']' */ |
|
148 |
//SYM_REF2(array_variable_c, subscripted_variable, subscript_list) |
|
149 |
void *visit(array_variable_c *symbol) { |
|
150 |
current_array_type = search_varfb_instance_type->get_type(symbol->subscripted_variable, false); |
|
151 |
symbol->subscripted_variable->accept(*this); |
|
152 |
if (current_array_type != NULL) { |
|
153 |
symbol->subscript_list->accept(*this); |
|
154 |
current_array_type = NULL; |
|
155 |
} |
|
156 |
return NULL; |
|
157 |
} |
|
158 |
||
159 |
/* subscript_list ',' subscript */ |
|
160 |
void *visit(subscript_list_c *symbol) { |
|
161 |
for (int i = 0; i < symbol->n; i++) { |
|
162 |
s4o.print("[__"); |
|
163 |
current_array_type->accept(*this); |
|
164 |
s4o.print("_TRANSIDX"); |
|
165 |
print_integer(i); |
|
166 |
s4o.print("("); |
|
167 |
symbol->elements[i]->accept(*this); |
|
168 |
s4o.print(")]"); |
|
169 |
} |
|
170 |
return NULL; |
|
171 |
} |
|
172 |
||
173 |
||
70 | 174 |
/***************************************/ |
175 |
/* B.3 - Language ST (Structured Text) */ |
|
176 |
/***************************************/ |
|
177 |
/***********************/ |
|
178 |
/* B 3.1 - Expressions */ |
|
179 |
/***********************/ |
|
180 |
void *visit(or_expression_c *symbol) { |
|
181 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
182 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
183 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
184 |
ERROR; |
|
185 |
if (search_expression_type->is_bool_type(left_type)) |
|
186 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " || "); |
|
187 |
if (search_expression_type->is_binary_type(left_type)) |
|
188 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " | "); |
|
189 |
ERROR; |
|
190 |
return NULL; |
|
191 |
} |
|
192 |
||
193 |
void *visit(xor_expression_c *symbol) { |
|
194 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
195 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
196 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
197 |
ERROR; |
|
198 |
if (search_expression_type->is_bool_type(left_type)) { |
|
199 |
s4o.print("("); |
|
200 |
symbol->l_exp->accept(*this); |
|
201 |
s4o.print(" && !"); |
|
202 |
symbol->r_exp->accept(*this); |
|
203 |
s4o.print(") || (!"); |
|
204 |
symbol->l_exp->accept(*this); |
|
205 |
s4o.print(" && "); |
|
206 |
symbol->r_exp->accept(*this); |
|
207 |
s4o.print(")"); |
|
130 | 208 |
return NULL; |
70 | 209 |
} |
210 |
if (search_expression_type->is_binary_type(left_type)) |
|
211 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " ^ "); |
|
212 |
ERROR; |
|
213 |
return NULL; |
|
214 |
} |
|
215 |
||
216 |
void *visit(and_expression_c *symbol) { |
|
217 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
218 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
219 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
220 |
ERROR; |
|
221 |
if (search_expression_type->is_bool_type(left_type)) |
|
222 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " && "); |
|
223 |
if (search_expression_type->is_binary_type(left_type)) |
|
224 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " & "); |
|
225 |
ERROR; |
|
226 |
return NULL; |
|
227 |
} |
|
228 |
||
229 |
void *visit(equ_expression_c *symbol) { |
|
230 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
231 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
232 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
233 |
ERROR; |
|
123 | 234 |
if (search_expression_type->is_time_type(left_type) || |
235 |
search_expression_type->is_string_type(left_type)) |
|
70 | 236 |
return print_compare_function("__eq_", left_type, symbol->l_exp, symbol->r_exp); |
237 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " == "); |
|
238 |
} |
|
239 |
||
240 |
void *visit(notequ_expression_c *symbol) { |
|
241 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
242 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
243 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
244 |
ERROR; |
|
123 | 245 |
if (search_expression_type->is_time_type(left_type) || |
246 |
search_expression_type->is_string_type(left_type)) |
|
70 | 247 |
return print_compare_function("__ne_", left_type, symbol->l_exp, symbol->r_exp); |
248 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " != "); |
|
249 |
} |
|
250 |
||
251 |
void *visit(lt_expression_c *symbol) { |
|
252 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
253 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
254 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
255 |
ERROR; |
|
123 | 256 |
if (search_expression_type->is_time_type(left_type) || |
257 |
search_expression_type->is_string_type(left_type)) |
|
70 | 258 |
return print_compare_function("__lt_", left_type, symbol->l_exp, symbol->r_exp); |
123 | 259 |
if (!search_base_type.type_is_enumerated(left_type)) |
260 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " < "); |
|
261 |
ERROR; |
|
262 |
return NULL; |
|
70 | 263 |
} |
264 |
||
265 |
void *visit(gt_expression_c *symbol) { |
|
266 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
267 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
268 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
269 |
ERROR; |
|
123 | 270 |
if (search_expression_type->is_time_type(left_type) || |
271 |
search_expression_type->is_string_type(left_type)) |
|
70 | 272 |
return print_compare_function("__gt_", left_type, symbol->l_exp, symbol->r_exp); |
123 | 273 |
if (!search_base_type.type_is_enumerated(left_type)) |
274 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " > "); |
|
275 |
ERROR; |
|
276 |
return NULL; |
|
70 | 277 |
} |
278 |
||
279 |
void *visit(le_expression_c *symbol) { |
|
280 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
281 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
282 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
283 |
ERROR; |
|
123 | 284 |
if (search_expression_type->is_time_type(left_type) || |
285 |
search_expression_type->is_string_type(left_type)) |
|
70 | 286 |
return print_compare_function("__le_", left_type, symbol->l_exp, symbol->r_exp); |
123 | 287 |
if (!search_base_type.type_is_enumerated(left_type)) |
288 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " <= "); |
|
289 |
ERROR; |
|
290 |
return NULL; |
|
70 | 291 |
} |
292 |
||
293 |
void *visit(ge_expression_c *symbol) { |
|
294 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
295 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
296 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
297 |
ERROR; |
|
123 | 298 |
if (search_expression_type->is_time_type(left_type) || |
299 |
search_expression_type->is_string_type(left_type)) |
|
70 | 300 |
return print_compare_function("__ge_", left_type, symbol->l_exp, symbol->r_exp); |
123 | 301 |
if (!search_base_type.type_is_enumerated(left_type)) |
302 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " >= "); |
|
303 |
ERROR; |
|
304 |
return NULL; |
|
70 | 305 |
} |
306 |
||
307 |
void *visit(add_expression_c *symbol) { |
|
308 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
309 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
310 |
if ((typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
|
311 |
(typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
|
312 |
(typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c))) |
|
149 | 313 |
return print_binary_function("__TIME_ADD", symbol->l_exp, symbol->r_exp); |
70 | 314 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
315 |
ERROR; |
|
316 |
if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) |
|
317 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " + "); |
|
318 |
ERROR; |
|
319 |
return NULL; |
|
320 |
} |
|
321 |
||
322 |
void *visit(sub_expression_c *symbol) { |
|
323 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
324 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
325 |
if ((typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
|
326 |
(typeid(*left_type) == typeid(date_type_name_c) && typeid(*right_type) == typeid(date_type_name_c)) || |
|
327 |
(typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
|
328 |
(typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(tod_type_name_c)) || |
|
329 |
(typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
|
330 |
(typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(dt_type_name_c))) |
|
149 | 331 |
return print_binary_function("__TIME_SUB", symbol->l_exp, symbol->r_exp); |
70 | 332 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
333 |
ERROR; |
|
334 |
if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) |
|
335 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " - "); |
|
336 |
ERROR; |
|
337 |
return NULL; |
|
338 |
} |
|
339 |
||
340 |
void *visit(mul_expression_c *symbol) { |
|
341 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
342 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
343 |
if ((typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_integer_type(right_type)) || |
|
344 |
(typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_real_type(right_type))) |
|
149 | 345 |
return print_binary_function("__TIME_MUL", symbol->l_exp, symbol->r_exp); |
70 | 346 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
347 |
ERROR; |
|
348 |
if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) |
|
349 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " * "); |
|
350 |
ERROR; |
|
351 |
return NULL; |
|
352 |
} |
|
353 |
||
354 |
void *visit(div_expression_c *symbol) { |
|
355 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
356 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
149 | 357 |
if ((typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_integer_type(right_type)) || |
358 |
(typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_real_type(right_type))) |
|
359 |
return print_binary_function("__TIME_DIV", symbol->l_exp, symbol->r_exp); |
|
70 | 360 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
361 |
ERROR; |
|
362 |
if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) |
|
363 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " / "); |
|
364 |
ERROR; |
|
365 |
return NULL; |
|
366 |
} |
|
367 |
||
368 |
void *visit(mod_expression_c *symbol) { |
|
369 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
370 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
371 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
372 |
ERROR; |
|
373 |
if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) { |
|
374 |
s4o.print("(("); |
|
375 |
symbol->r_exp->accept(*this); |
|
376 |
s4o.print(" == 0)?0:"); |
|
377 |
print_binary_expression(symbol->l_exp, symbol->r_exp, " % "); |
|
378 |
s4o.print(")"); |
|
379 |
return NULL; |
|
380 |
} |
|
381 |
ERROR; |
|
382 |
return NULL; |
|
383 |
} |
|
384 |
||
385 |
/* TODO: power expression... */ |
|
386 |
void *visit(power_expression_c *symbol) {ERROR; return print_binary_expression(symbol->l_exp, symbol->r_exp, " ** ");} |
|
123 | 387 |
void *visit(neg_expression_c *symbol) { |
388 |
symbol_c *exp_type = search_expression_type->get_type(symbol->exp); |
|
389 |
if (search_expression_type->is_integer_type(exp_type) || search_expression_type->is_real_type(exp_type)) |
|
390 |
return print_unary_expression(symbol->exp, " -"); |
|
391 |
ERROR; |
|
392 |
return NULL; |
|
393 |
} |
|
70 | 394 |
|
395 |
void *visit(not_expression_c *symbol) { |
|
396 |
symbol_c *exp_type = search_expression_type->get_type(symbol->exp); |
|
123 | 397 |
if (search_expression_type->is_binary_type(exp_type)) |
398 |
return print_unary_expression(symbol->exp, search_expression_type->is_bool_type(exp_type)?"!":"~"); |
|
399 |
ERROR; |
|
400 |
return NULL; |
|
70 | 401 |
} |
402 |
||
403 |
void *visit(function_invocation_c *symbol) { |
|
149 | 404 |
symbol_c* function_type_prefix = NULL; |
405 |
symbol_c* function_name = NULL; |
|
406 |
symbol_c* function_type_suffix = NULL; |
|
407 |
std::list<FUNCTION_PARAM> param_list; |
|
408 |
FUNCTION_PARAM *param; |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
409 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
410 |
symbol_c *parameter_assignment_list = NULL; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
411 |
if (NULL != symbol-> formal_param_list) parameter_assignment_list = symbol-> formal_param_list; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
412 |
if (NULL != symbol->nonformal_param_list) parameter_assignment_list = symbol->nonformal_param_list; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
413 |
if (NULL == parameter_assignment_list) ERROR; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
414 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
415 |
function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
70 | 416 |
if (f_decl == function_symtable.end_value()) { |
417 |
/* The function called is not in the symtable, so we test if it is a |
|
418 |
* standard function defined in standard */ |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
419 |
|
70 | 420 |
function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
421 |
if (current_function_type == function_none) ERROR; |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
422 |
|
70 | 423 |
symbol_c *function_return_type = search_expression_type->get_type(symbol); |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
424 |
|
70 | 425 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
167
ae423926bc84
Fixed parameter count error on variadic functions with EN/ENO
etisserant
parents:
162
diff
changeset
|
426 |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
427 |
int nb_param = ((list_c *)parameter_assignment_list)->n; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
428 |
|
149 | 429 |
identifier_c en_param_name("EN"); |
430 |
/* Get the value from EN param */ |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
431 |
symbol_c *EN_param_value = function_call_param_iterator.search_f(&en_param_name); |
149 | 432 |
if (EN_param_value == NULL) |
433 |
EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())); |
|
167
ae423926bc84
Fixed parameter count error on variadic functions with EN/ENO
etisserant
parents:
162
diff
changeset
|
434 |
else |
ae423926bc84
Fixed parameter count error on variadic functions with EN/ENO
etisserant
parents:
162
diff
changeset
|
435 |
nb_param --; |
149 | 436 |
ADD_PARAM_LIST(EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in) |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
437 |
|
162
60a124678842
Fixed typo in EN/ENO parameters handling for std library functions
etisserant
parents:
160
diff
changeset
|
438 |
identifier_c eno_param_name("ENO"); |
149 | 439 |
/* Get the value from ENO param */ |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
440 |
symbol_c *ENO_param_value = function_call_param_iterator.search_f(&eno_param_name); |
167
ae423926bc84
Fixed parameter count error on variadic functions with EN/ENO
etisserant
parents:
162
diff
changeset
|
441 |
if (ENO_param_value != NULL) |
ae423926bc84
Fixed parameter count error on variadic functions with EN/ENO
etisserant
parents:
162
diff
changeset
|
442 |
nb_param --; |
149 | 443 |
ADD_PARAM_LIST(ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
444 |
|
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
445 |
#include "st_code_gen.c" |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
446 |
|
70 | 447 |
} |
448 |
else { |
|
449 |
/* loop through each function parameter, find the value we should pass |
|
450 |
* to it, and then output the c equivalent... |
|
451 |
*/ |
|
452 |
function_param_iterator_c fp_iterator(f_decl); |
|
453 |
||
149 | 454 |
function_name = symbol->function_name; |
70 | 455 |
|
456 |
identifier_c *param_name; |
|
457 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
458 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
149 | 459 |
|
70 | 460 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
149 | 461 |
|
70 | 462 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
463 |
symbol_c *param_value = function_call_param_iterator.search_f(param_name); |
70 | 464 |
|
465 |
/* Get the value from a foo(<param_value>) style call */ |
|
466 |
if (param_value == NULL) |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
467 |
param_value = function_call_param_iterator.next_nf(); |
149 | 468 |
|
469 |
if (param_value == NULL && param_direction == function_param_iterator_c::direction_in) { |
|
470 |
/* No value given for parameter, so we must use the default... */ |
|
471 |
/* First check whether default value specified in function declaration...*/ |
|
472 |
param_value = fp_iterator.default_value(); |
|
473 |
} |
|
474 |
||
70 | 475 |
symbol_c *param_type = fp_iterator.param_type(); |
476 |
if (param_type == NULL) ERROR; |
|
149 | 477 |
|
478 |
ADD_PARAM_LIST(param_value, param_type, param_direction) |
|
70 | 479 |
} /* for(...) */ |
480 |
// symbol->parameter_assignment->accept(*this); |
|
149 | 481 |
} |
482 |
||
483 |
if (function_type_prefix != NULL) { |
|
484 |
s4o.print("("); |
|
485 |
function_type_prefix->accept(*this); |
|
70 | 486 |
s4o.print(")"); |
149 | 487 |
} |
488 |
if (function_name != NULL) |
|
489 |
function_name->accept(*this); |
|
490 |
if (function_type_suffix != NULL) |
|
491 |
function_type_suffix->accept(*this); |
|
492 |
s4o.print("("); |
|
493 |
s4o.indent_right(); |
|
494 |
||
495 |
std::list<FUNCTION_PARAM>::iterator pt; |
|
496 |
for(pt = param_list.begin(); pt != param_list.end(); pt++) { |
|
497 |
if (pt != param_list.begin()) |
|
498 |
s4o.print(",\n"+s4o.indent_spaces); |
|
499 |
symbol_c *param_value = pt->param_value; |
|
500 |
symbol_c *param_type = pt->param_type; |
|
501 |
||
502 |
switch (pt->param_direction) { |
|
503 |
case function_param_iterator_c::direction_in: |
|
504 |
if (param_value == NULL) { |
|
505 |
/* If not, get the default value of this variable's type */ |
|
506 |
param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance()); |
|
507 |
} |
|
508 |
if (param_value == NULL) ERROR; |
|
509 |
if (search_base_type.type_is_subrange(param_type)) { |
|
510 |
s4o.print("__CHECK_"); |
|
511 |
param_type->accept(*this); |
|
512 |
s4o.print("("); |
|
513 |
} |
|
514 |
param_value->accept(*this); |
|
515 |
if (search_base_type.type_is_subrange(param_type)) |
|
516 |
s4o.print(")"); |
|
517 |
break; |
|
518 |
case function_param_iterator_c::direction_out: |
|
519 |
case function_param_iterator_c::direction_inout: |
|
520 |
current_param_is_pointer = true; |
|
521 |
if (param_value == NULL) { |
|
522 |
s4o.print("NULL"); |
|
523 |
} else { |
|
524 |
param_value->accept(*this); |
|
525 |
} |
|
526 |
current_param_is_pointer = false; |
|
527 |
break; |
|
528 |
case function_param_iterator_c::direction_extref: |
|
529 |
/* TODO! */ |
|
530 |
ERROR; |
|
531 |
break; |
|
532 |
} /* switch */ |
|
533 |
} |
|
169 | 534 |
|
149 | 535 |
s4o.print(")"); |
536 |
s4o.indent_left(); |
|
70 | 537 |
|
538 |
return NULL; |
|
539 |
} |
|
540 |
||
541 |
/********************/ |
|
542 |
/* B 3.2 Statements */ |
|
543 |
/********************/ |
|
544 |
void *visit(statement_list_c *symbol) { |
|
545 |
return print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); |
|
546 |
} |
|
547 |
||
548 |
/*********************************/ |
|
549 |
/* B 3.2.1 Assignment Statements */ |
|
550 |
/*********************************/ |
|
551 |
void *visit(assignment_statement_c *symbol) { |
|
98 | 552 |
symbol_c *left_type = search_varfb_instance_type->get_type(symbol->l_exp, false); |
553 |
||
70 | 554 |
symbol->l_exp->accept(*this); |
555 |
s4o.print(" = "); |
|
123 | 556 |
if (search_base_type.type_is_subrange(left_type)) { |
98 | 557 |
s4o.print("__CHECK_"); |
558 |
left_type->accept(*this); |
|
559 |
s4o.print("("); |
|
560 |
} |
|
70 | 561 |
symbol->r_exp->accept(*this); |
123 | 562 |
if (search_base_type.type_is_subrange(left_type)) |
98 | 563 |
s4o.print(")"); |
70 | 564 |
return NULL; |
565 |
} |
|
566 |
||
567 |
/*****************************************/ |
|
568 |
/* B 3.2.2 Subprogram Control Statements */ |
|
569 |
/*****************************************/ |
|
570 |
||
571 |
/* fb_name '(' [param_assignment_list] ')' */ |
|
572 |
/* param_assignment_list -> may be NULL ! */ |
|
573 |
//SYM_REF2(fb_invocation_c, fb_name, param_assignment_list) |
|
574 |
void *visit(fb_invocation_c *symbol) { |
|
575 |
TRACE("fb_invocation_c"); |
|
576 |
/* first figure out what is the name of the function block type of the function block being called... */ |
|
577 |
symbol_c *function_block_type_name = this->search_fb_instance_decl->get_type_name(symbol->fb_name); |
|
578 |
/* should never occur. The function block instance MUST have been declared... */ |
|
579 |
if (function_block_type_name == NULL) ERROR; |
|
580 |
||
581 |
/* Now find the declaration of the function block type being called... */ |
|
582 |
function_block_declaration_c *fb_decl = function_block_type_symtable.find_value(function_block_type_name); |
|
583 |
/* should never occur. The function block type being called MUST be in the symtable... */ |
|
584 |
if (fb_decl == function_block_type_symtable.end_value()) ERROR; |
|
585 |
||
586 |
/* loop through each function block parameter, find the value we should pass |
|
587 |
* to it, and then output the c equivalent... |
|
588 |
*/ |
|
589 |
function_param_iterator_c fp_iterator(fb_decl); |
|
590 |
identifier_c *param_name; |
|
591 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
592 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
593 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
160 | 594 |
|
162
60a124678842
Fixed typo in EN/ENO parameters handling for std library functions
etisserant
parents:
160
diff
changeset
|
595 |
/*fprintf(stderr, "param : %s\n", param_name->value);*/ |
160 | 596 |
|
70 | 597 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
598 |
symbol_c *param_value = function_call_param_iterator.search_f(param_name); |
70 | 599 |
|
600 |
/* Get the value from a foo(<param_value>) style call */ |
|
601 |
if (param_value == NULL) |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
602 |
param_value = function_call_param_iterator.next_nf(); |
70 | 603 |
|
98 | 604 |
symbol_c *param_type = fp_iterator.param_type(); |
605 |
if (param_type == NULL) ERROR; |
|
606 |
||
70 | 607 |
/* now output the value assignment */ |
608 |
if (param_value != NULL) |
|
609 |
if ((param_direction == function_param_iterator_c::direction_in) || |
|
610 |
(param_direction == function_param_iterator_c::direction_inout)) { |
|
611 |
print_variable_prefix(); |
|
612 |
symbol->fb_name->accept(*this); |
|
613 |
s4o.print("."); |
|
614 |
param_name->accept(*this); |
|
615 |
s4o.print(" = "); |
|
123 | 616 |
if (search_base_type.type_is_subrange(param_type)) { |
98 | 617 |
s4o.print("__CHECK_"); |
618 |
param_type->accept(*this); |
|
619 |
s4o.print("("); |
|
620 |
} |
|
70 | 621 |
param_value->accept(*this); |
123 | 622 |
if (search_base_type.type_is_subrange(param_type)) |
98 | 623 |
s4o.print(")"); |
70 | 624 |
s4o.print(";\n" + s4o.indent_spaces); |
625 |
} |
|
626 |
} /* for(...) */ |
|
627 |
||
628 |
/* now call the function... */ |
|
629 |
function_block_type_name->accept(*this); |
|
630 |
s4o.print(FB_FUNCTION_SUFFIX); |
|
631 |
s4o.print("(&"); |
|
632 |
print_variable_prefix(); |
|
633 |
symbol->fb_name->accept(*this); |
|
634 |
s4o.print(")"); |
|
635 |
||
636 |
/* loop through each function parameter, find the variable to which |
|
637 |
* we should atribute the value of all output or inoutput parameters. |
|
638 |
*/ |
|
639 |
fp_iterator.reset(); |
|
640 |
function_call_param_iterator.reset(); |
|
641 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
642 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
643 |
||
644 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
645 |
symbol_c *param_value = function_call_param_iterator.search_f(param_name); |
70 | 646 |
|
647 |
/* Get the value from a foo(<param_value>) style call */ |
|
648 |
if (param_value == NULL) |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
649 |
param_value = function_call_param_iterator.next_nf(); |
70 | 650 |
|
651 |
/* now output the value assignment */ |
|
652 |
if (param_value != NULL) |
|
653 |
if ((param_direction == function_param_iterator_c::direction_out) || |
|
654 |
(param_direction == function_param_iterator_c::direction_inout)) { |
|
98 | 655 |
symbol_c *param_type = search_varfb_instance_type->get_type(param_value, false); |
656 |
||
70 | 657 |
s4o.print(";\n"+ s4o.indent_spaces); |
658 |
param_value->accept(*this); |
|
659 |
s4o.print(" = "); |
|
123 | 660 |
if (search_base_type.type_is_subrange(param_type)) { |
98 | 661 |
s4o.print("__CHECK_"); |
662 |
param_type->accept(*this); |
|
663 |
s4o.print("("); |
|
664 |
} |
|
70 | 665 |
print_variable_prefix(); |
666 |
symbol->fb_name->accept(*this); |
|
667 |
s4o.print("."); |
|
668 |
param_name->accept(*this); |
|
123 | 669 |
if (search_base_type.type_is_subrange(param_type)) |
98 | 670 |
s4o.print(")"); |
70 | 671 |
} |
672 |
} /* for(...) */ |
|
673 |
||
674 |
return NULL; |
|
675 |
} |
|
676 |
||
677 |
||
678 |
||
679 |
||
680 |
/* helper symbol for fb_invocation */ |
|
681 |
/* param_assignment_list ',' param_assignment */ |
|
682 |
void *visit(param_assignment_list_c *symbol) { |
|
683 |
TRACE("param_assignment_list_c"); |
|
684 |
/* this should never be called... */ |
|
685 |
ERROR; |
|
686 |
return NULL; |
|
687 |
// return print_list(symbol, "", ", "); |
|
688 |
} |
|
689 |
||
690 |
||
691 |
void *visit(input_variable_param_assignment_c *symbol) { |
|
692 |
TRACE("input_variable_param_assignment_c"); |
|
693 |
/* this should never be called... */ |
|
694 |
ERROR; |
|
695 |
return NULL; |
|
696 |
/* |
|
697 |
symbol->variable_name->accept(*this); |
|
698 |
s4o.print(" = "); |
|
699 |
symbol->expression->accept(*this); |
|
700 |
return NULL; |
|
701 |
*/ |
|
702 |
} |
|
703 |
||
704 |
void *visit(output_variable_param_assignment_c *symbol) { |
|
705 |
TRACE("output_variable_param_assignment_c"); |
|
706 |
/* this should never be called... */ |
|
707 |
ERROR; |
|
708 |
return NULL; |
|
709 |
/* |
|
710 |
s4o.print(s4o.indent_spaces); |
|
711 |
if (symbol->not_param != NULL) |
|
712 |
symbol->not_param->accept(*this); |
|
713 |
symbol->variable_name->accept(*this); |
|
714 |
s4o.print(" => "); |
|
715 |
symbol->variable->accept(*this); |
|
716 |
return NULL; |
|
717 |
*/ |
|
718 |
} |
|
719 |
||
720 |
// TODO: the NOT symbol in function (block) calls... |
|
721 |
void *visit(not_paramassign_c *symbol) { |
|
722 |
TRACE("not_paramassign_c"); |
|
723 |
/* this should never be called... */ |
|
724 |
ERROR; |
|
725 |
return NULL; |
|
726 |
/* |
|
727 |
s4o.print("NOT "); |
|
728 |
return NULL; |
|
729 |
*/ |
|
730 |
} |
|
731 |
||
732 |
||
733 |
/********************************/ |
|
734 |
/* B 3.2.3 Selection Statements */ |
|
735 |
/********************************/ |
|
736 |
void *visit(if_statement_c *symbol) { |
|
737 |
s4o.print("if ("); |
|
738 |
symbol->expression->accept(*this); |
|
739 |
s4o.print(") {\n"); |
|
740 |
s4o.indent_right(); |
|
741 |
symbol->statement_list->accept(*this); |
|
742 |
s4o.indent_left(); |
|
743 |
symbol->elseif_statement_list->accept(*this); |
|
744 |
||
745 |
if (symbol->else_statement_list != NULL) { |
|
746 |
s4o.print(s4o.indent_spaces); s4o.print("} else {\n"); |
|
747 |
s4o.indent_right(); |
|
748 |
symbol->else_statement_list->accept(*this); |
|
749 |
s4o.indent_left(); |
|
750 |
} |
|
751 |
s4o.print(s4o.indent_spaces); s4o.print("}"); |
|
752 |
return NULL; |
|
753 |
} |
|
754 |
||
755 |
/* helper symbol for if_statement */ |
|
756 |
void *visit(elseif_statement_list_c *symbol) {return print_list(symbol);} |
|
757 |
||
758 |
/* helper symbol for elseif_statement_list */ |
|
759 |
void *visit(elseif_statement_c *symbol) { |
|
760 |
s4o.print(s4o.indent_spaces); s4o.print("} else if ("); |
|
761 |
symbol->expression->accept(*this); |
|
762 |
s4o.print(") {\n"); |
|
763 |
s4o.indent_right(); |
|
764 |
symbol->statement_list->accept(*this); |
|
765 |
s4o.indent_left(); |
|
766 |
return NULL; |
|
767 |
} |
|
768 |
||
769 |
void *visit(case_statement_c *symbol) { |
|
770 |
s4o.print("switch("); |
|
771 |
symbol->expression->accept(*this); |
|
772 |
s4o.print(") {\n"); |
|
773 |
s4o.indent_right(); |
|
774 |
symbol->case_element_list->accept(*this); |
|
775 |
if (symbol->statement_list != NULL) { |
|
776 |
s4o.print(s4o.indent_spaces + "default:\n"); |
|
777 |
s4o.indent_right(); |
|
778 |
symbol->statement_list->accept(*this); |
|
779 |
s4o.print(s4o.indent_spaces + "break;\n"); |
|
780 |
s4o.indent_left(); |
|
781 |
} |
|
782 |
s4o.indent_left(); |
|
783 |
s4o.print(s4o.indent_spaces + "}"); |
|
784 |
return NULL; |
|
785 |
} |
|
786 |
||
787 |
/* helper symbol for case_statement */ |
|
788 |
void *visit(case_element_list_c *symbol) {return print_list(symbol);} |
|
789 |
||
790 |
void *visit(case_element_c *symbol) { |
|
791 |
s4o.print(s4o.indent_spaces + "case "); |
|
792 |
symbol->case_list->accept(*this); |
|
793 |
s4o.print(" :\n"); |
|
794 |
s4o.indent_right(); |
|
795 |
symbol->statement_list->accept(*this); |
|
796 |
s4o.print(s4o.indent_spaces + "break;\n"); |
|
797 |
s4o.indent_left(); |
|
798 |
return NULL; |
|
799 |
} |
|
800 |
||
801 |
void *visit(case_list_c *symbol) {return print_list(symbol, "", ", ");} |
|
802 |
||
803 |
/********************************/ |
|
804 |
/* B 3.2.4 Iteration Statements */ |
|
805 |
/********************************/ |
|
806 |
void *visit(for_statement_c *symbol) { |
|
807 |
s4o.print("for("); |
|
808 |
symbol->control_variable->accept(*this); |
|
809 |
s4o.print(" = "); |
|
810 |
symbol->beg_expression->accept(*this); |
|
811 |
s4o.print("; "); |
|
812 |
symbol->control_variable->accept(*this); |
|
813 |
s4o.print(" != "); |
|
814 |
symbol->end_expression->accept(*this); |
|
815 |
s4o.print("; "); |
|
816 |
symbol->control_variable->accept(*this); |
|
817 |
if (symbol->by_expression != NULL) { |
|
818 |
s4o.print(" += "); |
|
819 |
symbol->by_expression->accept(*this); |
|
820 |
} else { |
|
821 |
s4o.print("++"); |
|
822 |
} |
|
823 |
s4o.print(") {\n"); |
|
824 |
s4o.indent_right(); |
|
825 |
symbol->statement_list->accept(*this); |
|
826 |
s4o.indent_left(); |
|
827 |
s4o.print(s4o.indent_spaces); s4o.print("}"); |
|
828 |
return NULL; |
|
829 |
} |
|
830 |
void *visit(while_statement_c *symbol) { |
|
831 |
s4o.print("while ("); |
|
832 |
symbol->expression->accept(*this); |
|
833 |
s4o.print(") {\n"); |
|
834 |
s4o.indent_right(); |
|
835 |
symbol->statement_list->accept(*this); |
|
836 |
s4o.indent_left(); |
|
837 |
s4o.print(s4o.indent_spaces); s4o.print("}"); |
|
838 |
return NULL; |
|
839 |
} |
|
840 |
void *visit(repeat_statement_c *symbol) { |
|
841 |
s4o.print("do {\n"); |
|
842 |
s4o.indent_right(); |
|
843 |
symbol->statement_list->accept(*this); |
|
844 |
s4o.indent_left(); |
|
845 |
s4o.print(s4o.indent_spaces); s4o.print("} while("); |
|
846 |
symbol->expression->accept(*this); |
|
847 |
s4o.print(")"); |
|
848 |
return NULL; |
|
849 |
} |
|
850 |
void *visit(exit_statement_c *symbol) { |
|
851 |
s4o.print("exit(0)"); |
|
852 |
return NULL; |
|
853 |
} |
|
854 |
||
855 |
||
856 |
||
857 |
}; /* generate_c_st_c */ |
|
858 |
||
859 |
||
860 |
||
861 |
||
862 |
||
863 |
||
864 |
||
865 |
||
866 |