author | laurent |
Mon, 19 Oct 2009 18:12:44 +0200 | |
changeset 211 | 5249d313ff7c |
parent 210 | 8387cac2aba6 |
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 il statements (i.e. IL 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 |
||
42 |
/* Returns the data type of an il_operand. |
|
43 |
* |
|
44 |
* Note that the il_operand may be a variable, in which case |
|
45 |
* we return the type of the variable instance. |
|
46 |
* The il_operand may also be a constant, in which case |
|
47 |
* we return the data type of that constant. |
|
48 |
* |
|
49 |
* The variable instance may be a member of a structured variable, |
|
50 |
* or an element in an array, or any combination of the two. |
|
51 |
* |
|
52 |
* The class constructor must be given the search scope |
|
53 |
* (function, function block or program within which |
|
54 |
* the possible il_operand variable instance was declared). |
|
55 |
*/ |
|
56 |
||
57 |
/***********************************************************************/ |
|
58 |
/***********************************************************************/ |
|
59 |
/***********************************************************************/ |
|
60 |
/***********************************************************************/ |
|
61 |
||
62 |
||
63 |
/* A new class to ouput the il default variable to c++ code |
|
64 |
* We use this class, inheriting from symbol_c, so it may be used |
|
65 |
* as any other symbol_c object in the intermediate parse tree, |
|
66 |
* more specifically, so it can be used as any other il operand. |
|
67 |
* This makes the rest of the code much easier... |
|
68 |
* |
|
69 |
* Nevertheless, the basic visitor class visitor_c does not know |
|
70 |
* how to visit this new il_default_variable_c class, so we have |
|
71 |
* to extend that too. |
|
72 |
* In reality extending the basic symbols doesn't quite work out |
|
73 |
* as cleanly as desired (we need to use dynamic_cast in the |
|
74 |
* accept method of the il_default_variable_c), but it is cleaner |
|
75 |
* than the alternative... |
|
76 |
*/ |
|
77 |
class il_default_variable_c; |
|
78 |
||
79 |
/* This visitor class is not really required, we could place the |
|
80 |
* visit() method directly in genertae_cc_il_c, but doing it in |
|
81 |
* a seperate class makes the architecture more evident... |
|
82 |
*/ |
|
83 |
class il_default_variable_visitor_c { |
|
84 |
public: |
|
85 |
virtual void *visit(il_default_variable_c *symbol) = 0; |
|
86 |
||
87 |
virtual ~il_default_variable_visitor_c(void) {return;} |
|
88 |
}; |
|
89 |
||
90 |
||
91 |
/* A class to print out to the resulting C++ code |
|
92 |
* the IL default variable name. |
|
93 |
* |
|
94 |
* It includes a reference to its name, |
|
95 |
* and the data type of the data currently stored |
|
96 |
* in this C++ variable... This is required because the |
|
97 |
* C++ variable is a union, and we must know which member |
|
98 |
* of the union top reference!! |
|
99 |
* |
|
100 |
* Note that we also need to keep track of the data type of |
|
101 |
* the value currently being stored in the default variable. |
|
102 |
* This is required so we can process parenthesis, |
|
103 |
* |
|
104 |
* e.g. : |
|
105 |
* LD var1 |
|
106 |
* AND ( |
|
107 |
* LD var2 |
|
108 |
* OR var3 |
|
109 |
* ) |
|
110 |
* |
|
111 |
* Note that we only execute the 'AND (' operation when we come across |
|
112 |
* the ')', i.e. once we have evaluated the result of the |
|
113 |
* instructions inside the parenthesis. |
|
114 |
* When we do execute the 'AND (' operation, we need to know the data type |
|
115 |
* of the operand, which in this case is the result of the evaluation of the |
|
116 |
* instruction list inside the parenthesis. We can only know this if we |
|
117 |
* keep track of the data type currently stored in the default variable! |
|
118 |
* |
|
119 |
* We use the current_type inside the generate_c_il::default_variable_name variable |
|
120 |
* to track this! |
|
121 |
*/ |
|
122 |
class il_default_variable_c: public symbol_c { |
|
123 |
public: |
|
124 |
symbol_c *var_name; /* in principle, this should point to an indentifier_c */ |
|
125 |
symbol_c *current_type; |
|
126 |
||
127 |
public: |
|
128 |
il_default_variable_c(const char *var_name_str, symbol_c *current_type); |
|
129 |
virtual void *accept(visitor_c &visitor); |
|
130 |
}; |
|
131 |
||
132 |
||
133 |
/***********************************************************************/ |
|
134 |
/***********************************************************************/ |
|
135 |
/***********************************************************************/ |
|
136 |
/***********************************************************************/ |
|
137 |
||
138 |
||
139 |
||
140 |
class generate_c_il_c: public generate_c_typedecl_c, il_default_variable_visitor_c { |
|
141 |
||
142 |
private: |
|
143 |
/* When compiling il code, it becomes necessary to determine the |
|
144 |
* data type of il operands. To do this, we must first find the |
|
145 |
* il operand's declaration, within the scope of the function block |
|
146 |
* or function currently being processed. |
|
147 |
* The following object does just that... |
|
148 |
* This object instance will then later be called while the |
|
149 |
* remaining il code is being handled. |
|
150 |
*/ |
|
151 |
search_expression_type_c *search_expression_type; |
|
152 |
||
153 |
/* The initial value that should be given to the IL default variable |
|
154 |
* imediately after a parenthesis is opened. |
|
155 |
* This variable is only used to pass data from the |
|
156 |
* il_expression_c visitor to the simple_instr_list_c visitor. |
|
157 |
* |
|
158 |
* e.g.: |
|
159 |
* LD var1 |
|
160 |
* AND ( var2 |
|
161 |
* OR var3 |
|
162 |
* ) |
|
163 |
* |
|
164 |
* In the above code sample, the line 'AND ( var2' constitutes |
|
165 |
* an il_expression_c, where var2 should be loaded into the |
|
166 |
* il default variable before continuing with the expression |
|
167 |
* inside the parenthesis. |
|
168 |
* Unfortunately, only the simple_instr_list_c may do the |
|
169 |
* initial laoding of the var2 bariable following the parenthesis, |
|
170 |
* so the il_expression_c visitor will have to pass 'var2' as a |
|
171 |
* parameter to the simple_instr_list_c visitor. |
|
172 |
* Ergo, the existance of the following parameter...! |
|
173 |
*/ |
|
174 |
symbol_c *il_default_variable_init_value; |
|
175 |
||
176 |
/* Operand to the IL operation currently being processed... */ |
|
177 |
/* These variables are used to pass data from the |
|
178 |
* il_simple_operation_c and il_expression_c visitors |
|
179 |
* to the il operator visitors (i.e. LD_operator_c, |
|
180 |
* LDN_operator_c, ST_operator_c, STN_operator_c, ...) |
|
181 |
*/ |
|
182 |
symbol_c *current_operand; |
|
183 |
symbol_c *current_operand_type; |
|
184 |
||
185 |
/* Label to which the current IL jump operation should jump to... */ |
|
186 |
/* This variable is used to pass data from the |
|
187 |
* il_jump_operation_c visitor |
|
188 |
* to the il jump operator visitors (i.e. JMP_operator_c, |
|
189 |
* JMPC_operator_c, JMPCN_operator_c, ...) |
|
190 |
*/ |
|
191 |
symbol_c *jump_label; |
|
192 |
||
193 |
/* The result of the comparison IL operations (GT, EQ, LT, ...) |
|
194 |
* is a boolean variable. |
|
195 |
* This class keeps track of the current data type stored in the |
|
196 |
* il default variable. This is usually done by keeping a reference |
|
197 |
* to the data type of the last operand. Nevertheless, in the case of |
|
198 |
* the comparison IL operators, the data type of the result (a boolean) |
|
199 |
* is not the data type of the operand. We therefore need an object |
|
200 |
* of the boolean data type to keep as a reference of the current |
|
201 |
* data type. |
|
202 |
* The following object is it... |
|
203 |
*/ |
|
204 |
bool_type_name_c bool_type; |
|
210
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
205 |
lint_type_name_c lint_type; |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
206 |
lword_type_name_c lword_type; |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
207 |
lreal_type_name_c lreal_type; |
70 | 208 |
|
209 |
/* the data type of the IL default variable... */ |
|
210 |
#define IL_DEFVAR_T VAR_LEADER "IL_DEFVAR_T" |
|
211 |
/* The name of the IL default variable... */ |
|
212 |
#define IL_DEFVAR VAR_LEADER "IL_DEFVAR" |
|
213 |
/* The name of the variable used to pass the result of a |
|
214 |
* parenthesised instruction list to the immediately preceding |
|
215 |
* scope ... |
|
216 |
*/ |
|
217 |
#define IL_DEFVAR_BACK VAR_LEADER "IL_DEFVAR_BACK" |
|
218 |
il_default_variable_c default_variable_name; |
|
219 |
il_default_variable_c default_variable_back_name; |
|
220 |
||
221 |
/* When calling a function block, we must first find it's type, |
|
222 |
* by searching through the declarations of the variables currently |
|
223 |
* in scope. |
|
224 |
* This class does just that... |
|
225 |
* A new class is instantiated whenever we begin generating the code |
|
226 |
* for a function block type declaration, or a program declaration. |
|
227 |
* This object instance will then later be called while the |
|
228 |
* function block's or the program's body is being handled. |
|
229 |
* |
|
230 |
* Note that functions cannot contain calls to function blocks, |
|
231 |
* so we do not create an object instance when handling |
|
232 |
* a function declaration. |
|
233 |
*/ |
|
234 |
search_fb_instance_decl_c *search_fb_instance_decl; |
|
235 |
||
98 | 236 |
search_varfb_instance_type_c *search_varfb_instance_type; |
237 |
||
238 |
search_base_type_c search_base_type; |
|
70 | 239 |
|
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
240 |
bool current_param_is_pointer; |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
241 |
|
70 | 242 |
public: |
243 |
generate_c_il_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) |
|
244 |
: generate_c_typedecl_c(s4o_ptr), |
|
245 |
default_variable_name(IL_DEFVAR, NULL), |
|
246 |
default_variable_back_name(IL_DEFVAR_BACK, NULL) |
|
247 |
{ |
|
248 |
search_expression_type = new search_expression_type_c(scope); |
|
249 |
search_fb_instance_decl = new search_fb_instance_decl_c(scope); |
|
98 | 250 |
search_varfb_instance_type = new search_varfb_instance_type_c(scope); |
70 | 251 |
current_operand = NULL; |
252 |
current_operand_type = NULL; |
|
253 |
il_default_variable_init_value = NULL; |
|
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
254 |
current_param_is_pointer = false; |
70 | 255 |
this->set_variable_prefix(variable_prefix); |
256 |
} |
|
257 |
||
258 |
virtual ~generate_c_il_c(void) { |
|
259 |
delete search_fb_instance_decl; |
|
260 |
delete search_expression_type; |
|
98 | 261 |
delete search_varfb_instance_type; |
70 | 262 |
} |
263 |
||
264 |
void generate(instruction_list_c *il) { |
|
265 |
il->accept(*this); |
|
266 |
} |
|
267 |
||
268 |
/* Declare the backup to the default variable, that will store the result |
|
269 |
* of the IL operations executed inside a parenthesis... |
|
270 |
*/ |
|
271 |
void declare_backup_variable(void) { |
|
272 |
s4o.print(s4o.indent_spaces); |
|
273 |
s4o.print(IL_DEFVAR_T); |
|
274 |
s4o.print(" "); |
|
275 |
print_backup_variable(); |
|
276 |
s4o.print(";\n"); |
|
277 |
} |
|
278 |
||
279 |
void print_backup_variable(void) { |
|
280 |
this->default_variable_back_name.accept(*this); |
|
281 |
} |
|
282 |
||
283 |
private: |
|
284 |
/* A helper function... */ |
|
285 |
/* |
|
286 |
bool is_bool_type(symbol_c *type_symbol) { |
|
287 |
return (NULL != dynamic_cast<bool_type_name_c *>(type_symbol)); |
|
288 |
} |
|
289 |
*/ |
|
290 |
||
291 |
/* A helper function... */ |
|
292 |
void *XXX_operator(symbol_c *lo, const char *op, symbol_c *ro) { |
|
293 |
if ((NULL == lo) || (NULL == ro)) ERROR; |
|
294 |
if (NULL == op) ERROR; |
|
295 |
||
296 |
lo->accept(*this); |
|
297 |
s4o.print(op); |
|
298 |
ro->accept(*this); |
|
299 |
return NULL; |
|
300 |
} |
|
301 |
||
302 |
/* A helper function... */ |
|
303 |
void *XXX_function(const char *func, symbol_c *lo, symbol_c *ro) { |
|
304 |
if ((NULL == lo) || (NULL == ro)) ERROR; |
|
305 |
if (NULL == func) ERROR; |
|
306 |
||
307 |
lo->accept(*this); |
|
308 |
s4o.print(" = "); |
|
309 |
s4o.print(func); |
|
310 |
s4o.print("("); |
|
311 |
lo->accept(*this); |
|
312 |
s4o.print(", "); |
|
313 |
ro->accept(*this); |
|
314 |
s4o.print(")"); |
|
315 |
return NULL; |
|
316 |
} |
|
317 |
||
318 |
/* A helper function... */ |
|
319 |
void *XXX_CAL_operator(const char *param_name, symbol_c *fb_name) { |
|
320 |
if (NULL == fb_name) ERROR; |
|
321 |
symbolic_variable_c *sv = dynamic_cast<symbolic_variable_c *>(fb_name); |
|
322 |
if (NULL == sv) ERROR; |
|
323 |
identifier_c *id = dynamic_cast<identifier_c *>(sv->var_name); |
|
324 |
if (NULL == id) ERROR; |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
201
diff
changeset
|
325 |
|
70 | 326 |
identifier_c param(param_name); |
327 |
||
328 |
//SYM_REF3(il_param_assignment_c, il_assign_operator, il_operand, simple_instr_list) |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
201
diff
changeset
|
329 |
il_assign_operator_c il_assign_operator(¶m); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
201
diff
changeset
|
330 |
il_param_assignment_c il_param_assignment(&il_assign_operator, &this->default_variable_name, NULL); |
70 | 331 |
// SYM_LIST(il_param_list_c) |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
201
diff
changeset
|
332 |
il_param_list_c il_param_list; |
70 | 333 |
il_param_list.add_element(&il_param_assignment); |
334 |
CAL_operator_c CAL_operator; |
|
335 |
// SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list) |
|
336 |
il_fb_call_c il_fb_call(&CAL_operator, id, NULL, &il_param_list); |
|
337 |
||
338 |
il_fb_call.accept(*this); |
|
339 |
return NULL; |
|
340 |
} |
|
341 |
||
342 |
/* A helper function... */ |
|
343 |
void *CMP_operator(symbol_c *o, const char *operation) { |
|
344 |
if (NULL == o) ERROR; |
|
345 |
if (NULL == this->default_variable_name.current_type) ERROR; |
|
346 |
||
347 |
symbol_c *backup = this->default_variable_name.current_type; |
|
348 |
this->default_variable_name.current_type = &(this->bool_type); |
|
349 |
this->default_variable_name.accept(*this); |
|
350 |
this->default_variable_name.current_type = backup; |
|
351 |
||
352 |
s4o.print(" = "); |
|
353 |
s4o.print(operation); |
|
354 |
this->default_variable_name.current_type->accept(*this); |
|
149 | 355 |
s4o.print("(__BOOL_LITERAL(TRUE), NULL, 2, "); |
70 | 356 |
this->default_variable_name.accept(*this); |
357 |
s4o.print(", "); |
|
358 |
o->accept(*this); |
|
359 |
s4o.print(")"); |
|
360 |
||
361 |
/* the data type resulting from this operation... */ |
|
362 |
this->default_variable_name.current_type = &(this->bool_type); |
|
363 |
return NULL; |
|
364 |
} |
|
365 |
||
366 |
||
367 |
/* A helper function... */ |
|
368 |
void C_modifier(void) { |
|
369 |
if (search_expression_type->is_bool_type(default_variable_name.current_type)) { |
|
370 |
s4o.print("if ("); |
|
371 |
this->default_variable_name.accept(*this); |
|
372 |
s4o.print(") "); |
|
373 |
} |
|
374 |
else {ERROR;} |
|
375 |
} |
|
376 |
||
377 |
/* A helper function... */ |
|
378 |
void CN_modifier(void) { |
|
379 |
if (search_expression_type->is_bool_type(default_variable_name.current_type)) { |
|
380 |
s4o.print("if (!"); |
|
381 |
this->default_variable_name.accept(*this); |
|
382 |
s4o.print(") "); |
|
383 |
} |
|
384 |
else {ERROR;} |
|
385 |
} |
|
386 |
||
210
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
387 |
void BYTE_operator_result_type(void) { |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
388 |
if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type)) { |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
389 |
if (search_expression_type->is_literal_integer_type(this->current_operand_type)) |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
390 |
this->default_variable_name.current_type = &(this->lword_type); |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
391 |
else |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
392 |
this->default_variable_name.current_type = this->current_operand_type; |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
393 |
} |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
394 |
else if (search_expression_type->is_literal_integer_type(this->current_operand_type)) |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
395 |
this->current_operand_type = this->default_variable_name.current_type; |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
396 |
} |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
397 |
|
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
398 |
void NUM_operator_result_type(void) { |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
399 |
if (search_expression_type->is_literal_real_type(this->default_variable_name.current_type)) { |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
400 |
if (search_expression_type->is_literal_integer_type(this->current_operand_type) || |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
401 |
search_expression_type->is_literal_real_type(this->current_operand_type)) |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
402 |
this->default_variable_name.current_type = &(this->lreal_type); |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
403 |
else |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
404 |
this->default_variable_name.current_type = this->current_operand_type; |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
405 |
} |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
406 |
else if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type)) { |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
407 |
if (search_expression_type->is_literal_integer_type(this->current_operand_type)) |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
408 |
this->default_variable_name.current_type = &(this->lint_type); |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
409 |
else if (search_expression_type->is_literal_real_type(this->current_operand_type)) |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
410 |
this->default_variable_name.current_type = &(this->lreal_type); |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
411 |
else |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
412 |
this->default_variable_name.current_type = this->current_operand_type; |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
413 |
} |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
414 |
else if (search_expression_type->is_literal_integer_type(this->current_operand_type) || |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
415 |
search_expression_type->is_literal_real_type(this->current_operand_type)) |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
416 |
this->current_operand_type = this->default_variable_name.current_type; |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
417 |
} |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
418 |
|
70 | 419 |
|
420 |
public: |
|
421 |
void *visit(il_default_variable_c *symbol) { |
|
422 |
//s4o.print("il_default_variable_c VISITOR!!\n"); |
|
423 |
symbol->var_name->accept(*this); |
|
424 |
if (NULL != symbol->current_type) { |
|
425 |
s4o.print("."); |
|
426 |
symbol->current_type->accept(*this); |
|
427 |
s4o.print("var"); |
|
428 |
} |
|
429 |
return NULL; |
|
430 |
} |
|
431 |
||
432 |
||
433 |
private: |
|
434 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
201
diff
changeset
|
435 |
#if 0 |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
201
diff
changeset
|
436 |
I NEED TO FIX THIS!!! |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
201
diff
changeset
|
437 |
TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO |
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
438 |
void *visit(eno_param_c *symbol) { |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
439 |
if (this->is_variable_prefix_null()) { |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
440 |
s4o.print("*"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
441 |
} |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
442 |
else { |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
443 |
this->print_variable_prefix(); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
444 |
} |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
445 |
s4o.print("ENO"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
446 |
return NULL; |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
447 |
} |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
201
diff
changeset
|
448 |
TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
201
diff
changeset
|
449 |
#endif |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
201
diff
changeset
|
450 |
|
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
451 |
|
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
452 |
/*********************/ |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
453 |
/* B 1.4 - Variables */ |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
454 |
/*********************/ |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
455 |
void *visit(symbolic_variable_c *symbol) { |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
456 |
unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
457 |
if (!current_param_is_pointer && (vartype == search_var_instance_decl_c::external_vt || vartype == search_var_instance_decl_c::located_vt)) { |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
458 |
s4o.print("*("); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
459 |
generate_c_base_c::visit(symbol); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
460 |
s4o.print(")"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
461 |
} |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
462 |
else if (current_param_is_pointer && vartype != search_var_instance_decl_c::external_vt && vartype != search_var_instance_decl_c::located_vt) { |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
463 |
s4o.print("&("); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
464 |
generate_c_base_c::visit(symbol); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
465 |
s4o.print(")"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
466 |
} |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
467 |
else { |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
468 |
generate_c_base_c::visit(symbol); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
469 |
} |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
470 |
return NULL; |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
471 |
} |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
472 |
|
70 | 473 |
/********************************************/ |
474 |
/* B.1.4.1 Directly Represented Variables */ |
|
475 |
/********************************************/ |
|
476 |
// direct_variable: direct_variable_token {$$ = new direct_variable_c($1);}; |
|
477 |
void *visit(direct_variable_c *symbol) { |
|
478 |
TRACE("direct_variable_c"); |
|
479 |
/* Do not use print_token() as it will change everything into uppercase */ |
|
480 |
if (strlen(symbol->value) == 0) ERROR; |
|
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
481 |
if (!current_param_is_pointer) { |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
482 |
s4o.print("*("); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
483 |
} |
70 | 484 |
this->print_variable_prefix(); |
485 |
s4o.printlocation(symbol->value + 1); |
|
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
486 |
if (!current_param_is_pointer) { |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
487 |
s4o.print(")"); |
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
488 |
} |
70 | 489 |
return NULL; |
490 |
} |
|
491 |
||
492 |
/****************************************/ |
|
493 |
/* B.2 - Language IL (Instruction List) */ |
|
494 |
/****************************************/ |
|
495 |
||
496 |
/***********************************/ |
|
497 |
/* B 2.1 Instructions and Operands */ |
|
498 |
/***********************************/ |
|
499 |
||
500 |
/* please see the comment before the RET_operator_c visitor for details... */ |
|
501 |
#define END_LABEL VAR_LEADER "end" |
|
502 |
||
503 |
/*| instruction_list il_instruction */ |
|
504 |
void *visit(instruction_list_c *symbol) { |
|
505 |
||
506 |
/* Declare the backup to the default variable, that will store the result |
|
507 |
* of the IL operations executed inside a parenthesis... |
|
508 |
*/ |
|
509 |
declare_backup_variable(); |
|
510 |
||
511 |
/* Declare the default variable, that will store the result of the IL operations... */ |
|
512 |
s4o.print(s4o.indent_spaces); |
|
513 |
s4o.print(IL_DEFVAR_T); |
|
514 |
s4o.print(" "); |
|
515 |
this->default_variable_name.accept(*this); |
|
211 | 516 |
s4o.print(";\n"); |
517 |
s4o.print(s4o.indent_spaces); |
|
518 |
print_backup_variable(); |
|
519 |
s4o.print(".INTvar = 0;\n\n"); |
|
70 | 520 |
|
521 |
print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); |
|
522 |
||
211 | 523 |
/* label not used by at least one goto result in a warning. |
524 |
* To work around this we introduce the useless goto |
|
525 |
* to humour the compiler... |
|
526 |
*/ |
|
527 |
s4o.print("\n"); |
|
528 |
s4o.print(s4o.indent_spaces); |
|
529 |
s4o.print("/* to humour the compiler, we insert a goto */\n"); |
|
530 |
s4o.print(s4o.indent_spaces); |
|
531 |
s4o.print("goto "); |
|
532 |
s4o.print(END_LABEL); |
|
533 |
s4o.print(";\n"); |
|
534 |
||
70 | 535 |
/* write the label marking the end of the code block */ |
536 |
/* please see the comment before the RET_operator_c visitor for details... */ |
|
537 |
s4o.print("\n"); |
|
538 |
s4o.print(s4o.indent_spaces); |
|
539 |
s4o.print(END_LABEL); |
|
540 |
s4o.print(":\n"); |
|
541 |
s4o.indent_right(); |
|
542 |
/* since every label must be followed by at least one statement, and |
|
543 |
* only the functions will introduce the return statement after this label, |
|
544 |
* function blocks written in IL would result in invalid C++ code. |
|
545 |
* To work around this we introduce the equivalent of a 'nop' operation |
|
546 |
* to humour the compiler... |
|
547 |
*/ |
|
548 |
s4o.print(s4o.indent_spaces); |
|
549 |
s4o.print("/* to humour the compiler, we insert a nop */\n"); |
|
550 |
s4o.print(s4o.indent_spaces); |
|
551 |
this->default_variable_name.accept(*this); |
|
552 |
s4o.print(" = "); |
|
553 |
this->default_variable_name.accept(*this); |
|
554 |
s4o.print(";\n"); |
|
555 |
s4o.indent_left(); |
|
556 |
||
557 |
return NULL; |
|
558 |
} |
|
559 |
||
560 |
||
561 |
/* | label ':' [il_incomplete_instruction] eol_list */ |
|
562 |
// SYM_REF2(il_instruction_c, label, il_instruction) |
|
563 |
void *visit(il_instruction_c *symbol) { |
|
564 |
if (NULL != symbol->label) { |
|
565 |
symbol->label->accept(*this); |
|
566 |
s4o.print(":\n"); |
|
567 |
s4o.print(s4o.indent_spaces); |
|
568 |
} |
|
569 |
symbol->il_instruction->accept(*this); |
|
570 |
return NULL; |
|
571 |
} |
|
572 |
||
573 |
/* | il_simple_operator [il_operand] */ |
|
574 |
//SYM_REF2(il_simple_operation_c, il_simple_operator, il_operand) |
|
575 |
void *visit(il_simple_operation_c *symbol) { |
|
576 |
this->current_operand = symbol->il_operand; |
|
577 |
if (NULL == this->current_operand) { |
|
578 |
this->current_operand_type = NULL; |
|
579 |
} else { |
|
580 |
this->current_operand_type = search_expression_type->get_type(this->current_operand); |
|
581 |
if (NULL == this->current_operand_type) ERROR; |
|
582 |
} |
|
583 |
||
584 |
symbol->il_simple_operator->accept(*this); |
|
585 |
||
586 |
this->current_operand = NULL; |
|
587 |
this->current_operand_type = NULL; |
|
588 |
return NULL; |
|
589 |
} |
|
590 |
||
591 |
||
592 |
/* | function_name [il_operand_list] */ |
|
593 |
// SYM_REF2(il_function_call_c, function_name, il_operand_list) |
|
594 |
void *visit(il_function_call_c *symbol) { |
|
595 |
function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
|
596 |
||
149 | 597 |
symbol_c* function_type_prefix = NULL; |
598 |
symbol_c* function_name = NULL; |
|
599 |
symbol_c* function_type_suffix = NULL; |
|
600 |
std::list<FUNCTION_PARAM> param_list; |
|
601 |
FUNCTION_PARAM *param; |
|
602 |
||
603 |
symbol_c *param_data_type = default_variable_name.current_type; |
|
604 |
symbol_c *return_data_type = NULL; |
|
605 |
||
70 | 606 |
if (f_decl == function_symtable.end_value()) { |
607 |
function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
|
608 |
if (current_function_type == function_none) ERROR; |
|
609 |
||
149 | 610 |
return_data_type = (symbol_c *)search_expression_type->compute_standard_function_il(symbol, param_data_type); |
70 | 611 |
if (NULL == return_data_type) ERROR; |
612 |
||
613 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
614 |
||
149 | 615 |
/* Add the value from EN param */ |
616 |
ADD_PARAM_LIST((symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())), |
|
617 |
(symbol_c*)(new bool_type_name_c()), |
|
618 |
function_param_iterator_c::direction_in) |
|
619 |
||
620 |
/* Add the value from ENO param */ |
|
621 |
ADD_PARAM_LIST(NULL, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
|
622 |
||
70 | 623 |
int nb_param = 1; |
624 |
if (symbol->il_operand_list != NULL) |
|
625 |
nb_param += ((list_c *)symbol->il_operand_list)->n; |
|
626 |
||
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
123
diff
changeset
|
627 |
#include "il_code_gen.c" |
70 | 628 |
|
629 |
} |
|
630 |
else { |
|
631 |
/* determine the base data type returned by the function being called... */ |
|
632 |
search_base_type_c search_base_type; |
|
149 | 633 |
return_data_type = (symbol_c *)f_decl->type_name->accept(search_base_type); |
70 | 634 |
if (NULL == return_data_type) ERROR; |
635 |
||
149 | 636 |
function_name = symbol->function_name; |
637 |
||
70 | 638 |
/* loop through each function parameter, find the value we should pass |
639 |
* to it, and then output the c equivalent... |
|
640 |
*/ |
|
641 |
||
642 |
function_param_iterator_c fp_iterator(f_decl); |
|
643 |
identifier_c *param_name; |
|
644 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
645 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
646 |
symbol_c *param_type = fp_iterator.param_type(); |
|
647 |
if (param_type == NULL) ERROR; |
|
149 | 648 |
|
70 | 649 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
149 | 650 |
|
70 | 651 |
symbol_c *param_value = NULL; |
652 |
||
653 |
/* if it is the first parameter, semantics specifies that we should |
|
654 |
* get the value off the IL default variable! |
|
655 |
*/ |
|
656 |
if (1 == i) |
|
657 |
param_value = &this->default_variable_name; |
|
658 |
||
659 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
|
660 |
/* NOTE: the following line of code is not required in this case, but it doesn't |
|
661 |
* harm to leave it in, as in the case of a non-formal syntax function call, |
|
662 |
* it will always return NULL. |
|
663 |
* We leave it in in case we later decide to merge this part of the code together |
|
664 |
* with the function calling code in generate_c_st_c, which does require |
|
665 |
* the following line... |
|
666 |
*/ |
|
667 |
if (param_value == NULL) |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
201
diff
changeset
|
668 |
param_value = function_call_param_iterator.search_f(param_name); |
70 | 669 |
|
670 |
/* Get the value from a foo(<param_value>) style call */ |
|
671 |
if (param_value == NULL) |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
201
diff
changeset
|
672 |
param_value = function_call_param_iterator.next_nf(); |
149 | 673 |
|
674 |
if (param_value == NULL && param_direction == function_param_iterator_c::direction_in) { |
|
675 |
/* No value given for parameter, so we must use the default... */ |
|
676 |
/* First check whether default value specified in function declaration...*/ |
|
677 |
param_value = fp_iterator.default_value(); |
|
678 |
} |
|
679 |
||
680 |
ADD_PARAM_LIST(param_value, param_type, fp_iterator.param_direction()) |
|
681 |
} /* for(...) */ |
|
682 |
} |
|
683 |
||
684 |
default_variable_name.current_type = return_data_type; |
|
685 |
this->default_variable_name.accept(*this); |
|
686 |
default_variable_name.current_type = param_data_type; |
|
687 |
s4o.print(" = "); |
|
688 |
||
689 |
if (function_type_prefix != NULL) { |
|
690 |
s4o.print("("); |
|
691 |
function_type_prefix->accept(*this); |
|
692 |
s4o.print(")"); |
|
693 |
} |
|
694 |
if (function_name != NULL) |
|
695 |
function_name->accept(*this); |
|
696 |
if (function_type_suffix != NULL) |
|
697 |
function_type_suffix->accept(*this); |
|
698 |
s4o.print("("); |
|
699 |
s4o.indent_right(); |
|
700 |
||
701 |
std::list<FUNCTION_PARAM>::iterator pt; |
|
702 |
for(pt = param_list.begin(); pt != param_list.end(); pt++) { |
|
703 |
if (pt != param_list.begin()) |
|
704 |
s4o.print(",\n"+s4o.indent_spaces); |
|
705 |
symbol_c *param_value = pt->param_value; |
|
706 |
symbol_c *param_type = pt->param_type; |
|
707 |
||
708 |
switch (pt->param_direction) { |
|
709 |
case function_param_iterator_c::direction_in: |
|
710 |
if (param_value == NULL) { |
|
711 |
/* If not, get the default value of this variable's type */ |
|
712 |
param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance()); |
|
713 |
} |
|
714 |
if (param_value == NULL) ERROR; |
|
715 |
if (search_base_type.type_is_subrange(param_type)) { |
|
716 |
s4o.print("__CHECK_"); |
|
717 |
param_type->accept(*this); |
|
718 |
s4o.print("("); |
|
719 |
} |
|
720 |
param_value->accept(*this); |
|
721 |
if (search_base_type.type_is_subrange(param_type)) |
|
722 |
s4o.print(")"); |
|
723 |
break; |
|
724 |
case function_param_iterator_c::direction_out: |
|
725 |
case function_param_iterator_c::direction_inout: |
|
726 |
current_param_is_pointer = true; |
|
727 |
if (param_value == NULL) { |
|
728 |
s4o.print("NULL"); |
|
729 |
} else { |
|
70 | 730 |
param_value->accept(*this); |
149 | 731 |
} |
732 |
current_param_is_pointer = false; |
|
733 |
break; |
|
734 |
case function_param_iterator_c::direction_extref: |
|
735 |
/* TODO! */ |
|
736 |
ERROR; |
|
737 |
break; |
|
738 |
} /* switch */ |
|
739 |
} |
|
740 |
||
741 |
s4o.print(")"); |
|
742 |
/* the data type returned by the function, and stored in the il default variable... */ |
|
743 |
default_variable_name.current_type = return_data_type; |
|
70 | 744 |
return NULL; |
745 |
} |
|
746 |
||
747 |
||
748 |
/* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */ |
|
749 |
//SYM_REF4(il_expression_c, il_expr_operator, il_operand, simple_instr_list, unused) |
|
750 |
void *visit(il_expression_c *symbol) { |
|
751 |
/* We will be recursevely interpreting an instruction list, |
|
752 |
* so we store a backup of the data type of the value currently stored |
|
753 |
* in the default variable, and set the current data type to NULL |
|
754 |
*/ |
|
755 |
symbol_c *old_current_default_variable_data_type = this->default_variable_name.current_type; |
|
756 |
this->default_variable_name.current_type = NULL; |
|
757 |
||
758 |
/* Pass the symbol->il_operand to the simple_instr_list visitor |
|
759 |
* using the il_default_variable_init_value parameter... |
|
760 |
* Note that the simple_instr_list_c visitor will set this parameter |
|
761 |
* to NULL as soon as it does not require it any longer, |
|
762 |
* so we don't do it here again after the |
|
763 |
* symbol->simple_instr_list->accept(*this); |
|
764 |
* returns... |
|
765 |
*/ |
|
766 |
this->il_default_variable_init_value = symbol->il_operand; |
|
767 |
||
768 |
/* Now do the parenthesised instructions... */ |
|
769 |
/* NOTE: the following code line will get the variable |
|
770 |
* this->default_variable_name.current_type updated! |
|
771 |
*/ |
|
772 |
symbol->simple_instr_list->accept(*this); |
|
773 |
||
774 |
/* Now do the operation, using the previous result! */ |
|
775 |
/* NOTE: The result of the previous instruction list will be stored |
|
776 |
* in a variable named IL_DEFVAR_BACK. This is done in the visitor |
|
777 |
* to instruction_list_c objects... |
|
778 |
*/ |
|
779 |
this->current_operand = &(this->default_variable_back_name); |
|
780 |
this->current_operand_type = this->default_variable_back_name.current_type; |
|
781 |
||
782 |
this->default_variable_name.current_type = old_current_default_variable_data_type; |
|
783 |
if (NULL == this->current_operand_type) ERROR; |
|
784 |
||
785 |
symbol->il_expr_operator->accept(*this); |
|
786 |
||
787 |
this->current_operand = NULL; |
|
788 |
this->current_operand_type = NULL; |
|
789 |
this->default_variable_back_name.current_type = NULL; |
|
790 |
return NULL; |
|
791 |
} |
|
792 |
||
793 |
/* il_jump_operator label */ |
|
794 |
// SYM_REF2(il_jump_operation_c, il_jump_operator, label) |
|
795 |
void *visit(il_jump_operation_c *symbol) { |
|
796 |
/* Pass the symbol->label to the il_jump_operation visitor |
|
797 |
* using the jump_label parameter... |
|
798 |
*/ |
|
799 |
this->jump_label = symbol->label; |
|
800 |
symbol->il_jump_operator->accept(*this); |
|
801 |
this->jump_label = NULL; |
|
802 |
||
803 |
return NULL; |
|
804 |
} |
|
805 |
||
806 |
/* il_call_operator prev_declared_fb_name |
|
807 |
* | il_call_operator prev_declared_fb_name '(' ')' |
|
808 |
* | il_call_operator prev_declared_fb_name '(' eol_list ')' |
|
809 |
* | il_call_operator prev_declared_fb_name '(' il_operand_list ')' |
|
810 |
* | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')' |
|
811 |
*/ |
|
812 |
// SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list) |
|
813 |
void *visit(il_fb_call_c *symbol) { |
|
814 |
symbol->il_call_operator->accept(*this); |
|
815 |
s4o.print("{\n"); |
|
816 |
s4o.indent_right(); |
|
817 |
s4o.print(s4o.indent_spaces); |
|
818 |
||
819 |
/* first figure out what is the name of the function block type of the function block being called... */ |
|
820 |
symbol_c *function_block_type_name = this->search_fb_instance_decl->get_type_name(symbol->fb_name); |
|
821 |
/* should never occur. The function block instance MUST have been declared... */ |
|
822 |
if (function_block_type_name == NULL) ERROR; |
|
823 |
||
824 |
/* Now find the declaration of the function block type being called... */ |
|
825 |
function_block_declaration_c *fb_decl = function_block_type_symtable.find_value(function_block_type_name); |
|
826 |
/* should never occur. The function block type being called MUST be in the symtable... */ |
|
827 |
if (fb_decl == function_block_type_symtable.end_value()) ERROR; |
|
828 |
||
829 |
/* loop through each function block parameter, find the value we should pass |
|
830 |
* to it, and then output the c equivalent... |
|
831 |
*/ |
|
832 |
function_param_iterator_c fp_iterator(fb_decl); |
|
833 |
identifier_c *param_name; |
|
834 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
835 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
836 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
837 |
||
838 |
/* 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:
201
diff
changeset
|
839 |
symbol_c *param_value = function_call_param_iterator.search_f(param_name); |
70 | 840 |
|
841 |
/* Get the value from a foo(<param_value>) style call */ |
|
842 |
if (param_value == NULL) |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
201
diff
changeset
|
843 |
param_value = function_call_param_iterator.next_nf(); |
70 | 844 |
|
98 | 845 |
symbol_c *param_type = fp_iterator.param_type(); |
846 |
if (param_type == NULL) ERROR; |
|
847 |
||
123 | 848 |
/* now output the value assignment */ |
70 | 849 |
if (param_value != NULL) |
850 |
if ((param_direction == function_param_iterator_c::direction_in) || |
|
851 |
(param_direction == function_param_iterator_c::direction_inout)) { |
|
852 |
symbol->fb_name->accept(*this); |
|
853 |
s4o.print("."); |
|
854 |
param_name->accept(*this); |
|
855 |
s4o.print(" = "); |
|
123 | 856 |
if (search_base_type.type_is_subrange(param_type)) { |
98 | 857 |
s4o.print("__CHECK_"); |
858 |
param_type->accept(*this); |
|
859 |
s4o.print("("); |
|
860 |
} |
|
70 | 861 |
param_value->accept(*this); |
123 | 862 |
if (search_base_type.type_is_subrange(param_type)) |
98 | 863 |
s4o.print(")"); |
70 | 864 |
s4o.print(";\n" + s4o.indent_spaces); |
865 |
} |
|
866 |
} /* for(...) */ |
|
867 |
||
868 |
/* now call the function... */ |
|
869 |
function_block_type_name->accept(*this); |
|
870 |
s4o.print(FB_FUNCTION_SUFFIX); |
|
871 |
s4o.print("(&"); |
|
872 |
symbol->fb_name->accept(*this); |
|
873 |
s4o.print(")"); |
|
874 |
||
875 |
/* loop through each function parameter, find the variable to which |
|
876 |
* we should atribute the value of all output or inoutput parameters. |
|
877 |
*/ |
|
878 |
fp_iterator.reset(); |
|
879 |
function_call_param_iterator.reset(); |
|
880 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
881 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
882 |
||
883 |
/* 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:
201
diff
changeset
|
884 |
symbol_c *param_value = function_call_param_iterator.search_f(param_name); |
70 | 885 |
|
886 |
/* Get the value from a foo(<param_value>) style call */ |
|
887 |
if (param_value == NULL) |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
201
diff
changeset
|
888 |
param_value = function_call_param_iterator.next_nf(); |
70 | 889 |
|
890 |
/* now output the value assignment */ |
|
891 |
if (param_value != NULL) |
|
892 |
if ((param_direction == function_param_iterator_c::direction_out) || |
|
893 |
(param_direction == function_param_iterator_c::direction_inout)) { |
|
98 | 894 |
symbol_c *param_type = search_varfb_instance_type->get_type(param_value, false); |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
201
diff
changeset
|
895 |
|
70 | 896 |
s4o.print(";\n"+ s4o.indent_spaces); |
897 |
param_value->accept(*this); |
|
898 |
s4o.print(" = "); |
|
123 | 899 |
if (search_base_type.type_is_subrange(param_type)) { |
98 | 900 |
s4o.print("__CHECK_"); |
901 |
param_type->accept(*this); |
|
902 |
s4o.print("("); |
|
903 |
} |
|
70 | 904 |
symbol->fb_name->accept(*this); |
905 |
s4o.print("."); |
|
906 |
param_name->accept(*this); |
|
123 | 907 |
if (search_base_type.type_is_subrange(param_type)) |
98 | 908 |
s4o.print(")"); |
70 | 909 |
} |
910 |
} /* for(...) */ |
|
911 |
||
912 |
s4o.print(";\n"); |
|
913 |
s4o.indent_left(); |
|
914 |
s4o.print(s4o.indent_spaces); |
|
915 |
s4o.print("}"); |
|
916 |
||
917 |
return NULL; |
|
918 |
} |
|
919 |
||
920 |
||
921 |
||
922 |
/* | function_name '(' eol_list [il_param_list] ')' */ |
|
923 |
// SYM_REF2(il_formal_funct_call_c, function_name, il_param_list) |
|
924 |
void *visit(il_formal_funct_call_c *symbol) { |
|
925 |
function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
|
926 |
||
149 | 927 |
symbol_c* function_type_prefix = NULL; |
928 |
symbol_c* function_name = NULL; |
|
929 |
symbol_c* function_type_suffix = NULL; |
|
930 |
std::list<FUNCTION_PARAM> param_list; |
|
931 |
FUNCTION_PARAM *param; |
|
932 |
||
933 |
symbol_c *return_data_type = NULL; |
|
934 |
||
935 |
if (f_decl == function_symtable.end_value()) { |
|
936 |
function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
|
937 |
if (current_function_type == function_none) ERROR; |
|
938 |
||
939 |
return_data_type = (symbol_c *)search_expression_type->compute_standard_function_default(NULL, symbol); |
|
940 |
if (NULL == return_data_type) ERROR; |
|
941 |
||
942 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
943 |
||
169 | 944 |
int nb_param = 0; |
945 |
if (symbol->il_param_list != NULL) |
|
946 |
nb_param += ((list_c *)symbol->il_param_list)->n; |
|
947 |
||
149 | 948 |
identifier_c en_param_name("EN"); |
949 |
/* Get the value from EN param */ |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
201
diff
changeset
|
950 |
symbol_c *EN_param_value = function_call_param_iterator.search_f(&en_param_name); |
149 | 951 |
if (EN_param_value == NULL) |
952 |
EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())); |
|
169 | 953 |
else |
954 |
nb_param --; |
|
149 | 955 |
ADD_PARAM_LIST(EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in) |
956 |
||
957 |
identifier_c eno_param_name("EN0"); |
|
958 |
/* Get the value from ENO param */ |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
201
diff
changeset
|
959 |
symbol_c *ENO_param_value = function_call_param_iterator.search_f(&eno_param_name); |
169 | 960 |
if (ENO_param_value != NULL) |
961 |
nb_param --; |
|
149 | 962 |
ADD_PARAM_LIST(ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
963 |
||
964 |
#include "st_code_gen.c" |
|
965 |
||
966 |
} |
|
967 |
else { |
|
968 |
/* determine the base data type returned by the function being called... */ |
|
969 |
search_base_type_c search_base_type; |
|
970 |
return_data_type = (symbol_c *)f_decl->type_name->accept(search_base_type); |
|
971 |
if (NULL == return_data_type) ERROR; |
|
972 |
||
973 |
function_name = symbol->function_name; |
|
974 |
||
975 |
/* loop through each function parameter, find the value we should pass |
|
976 |
* to it, and then output the c equivalent... |
|
977 |
*/ |
|
978 |
||
979 |
function_param_iterator_c fp_iterator(f_decl); |
|
980 |
identifier_c *param_name; |
|
981 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
982 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
983 |
symbol_c *param_type = fp_iterator.param_type(); |
|
984 |
if (param_type == NULL) ERROR; |
|
985 |
||
986 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
987 |
||
988 |
||
989 |
symbol_c *param_value = NULL; |
|
990 |
||
991 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
|
992 |
if (param_value == NULL) |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
201
diff
changeset
|
993 |
param_value = function_call_param_iterator.search_f(param_name); |
149 | 994 |
|
995 |
/* Get the value from a foo(<param_value>) style call */ |
|
996 |
/* NOTE: the following line of code is not required in this case, but it doesn't |
|
997 |
* harm to leave it in, as in the case of a formal syntax function call, |
|
998 |
* it will always return NULL. |
|
999 |
* We leave it in in case we later decide to merge this part of the code together |
|
1000 |
* with the function calling code in generate_c_st_c, which does require |
|
1001 |
* the following line... |
|
1002 |
*/ |
|
1003 |
if (param_value == NULL) |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
201
diff
changeset
|
1004 |
param_value = function_call_param_iterator.next_nf(); |
149 | 1005 |
|
1006 |
if (param_value == NULL) { |
|
1007 |
/* No value given for parameter, so we must use the default... */ |
|
1008 |
/* First check whether default value specified in function declaration...*/ |
|
1009 |
param_value = fp_iterator.default_value(); |
|
1010 |
} |
|
1011 |
||
1012 |
ADD_PARAM_LIST(param_value, param_type, fp_iterator.param_direction()) |
|
1013 |
} |
|
1014 |
} |
|
1015 |
||
1016 |
default_variable_name.current_type = return_data_type; |
|
1017 |
this->default_variable_name.accept(*this); |
|
1018 |
s4o.print(" = "); |
|
1019 |
||
1020 |
if (function_type_prefix != NULL) { |
|
1021 |
s4o.print("("); |
|
1022 |
function_type_prefix->accept(*this); |
|
1023 |
s4o.print(")"); |
|
1024 |
} |
|
1025 |
if (function_name != NULL) |
|
1026 |
function_name->accept(*this); |
|
1027 |
if (function_type_suffix != NULL) |
|
1028 |
function_type_suffix->accept(*this); |
|
70 | 1029 |
s4o.print("("); |
149 | 1030 |
s4o.indent_right(); |
1031 |
||
1032 |
std::list<FUNCTION_PARAM>::iterator pt; |
|
1033 |
for(pt = param_list.begin(); pt != param_list.end(); pt++) { |
|
1034 |
if (pt != param_list.begin()) |
|
1035 |
s4o.print(",\n"+s4o.indent_spaces); |
|
1036 |
symbol_c *param_value = pt->param_value; |
|
1037 |
symbol_c *param_type = pt->param_type; |
|
1038 |
||
1039 |
switch (pt->param_direction) { |
|
70 | 1040 |
case function_param_iterator_c::direction_in: |
1041 |
if (param_value == NULL) { |
|
1042 |
/* If not, get the default value of this variable's type */ |
|
1043 |
param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance()); |
|
1044 |
} |
|
1045 |
if (param_value == NULL) ERROR; |
|
123 | 1046 |
if (search_base_type.type_is_subrange(param_type)) { |
98 | 1047 |
s4o.print("__CHECK_"); |
1048 |
param_type->accept(*this); |
|
1049 |
s4o.print("("); |
|
1050 |
} |
|
70 | 1051 |
param_value->accept(*this); |
123 | 1052 |
if (search_base_type.type_is_subrange(param_type)) |
98 | 1053 |
s4o.print(")"); |
149 | 1054 |
break; |
70 | 1055 |
case function_param_iterator_c::direction_out: |
1056 |
case function_param_iterator_c::direction_inout: |
|
149 | 1057 |
current_param_is_pointer = true; |
70 | 1058 |
if (param_value == NULL) { |
149 | 1059 |
s4o.print("NULL"); |
1060 |
} else { |
|
70 | 1061 |
param_value->accept(*this); |
149 | 1062 |
} |
1063 |
current_param_is_pointer = false; |
|
1064 |
break; |
|
70 | 1065 |
case function_param_iterator_c::direction_extref: |
1066 |
/* TODO! */ |
|
1067 |
ERROR; |
|
149 | 1068 |
break; |
70 | 1069 |
} /* switch */ |
1070 |
} /* for(...) */ |
|
1071 |
||
1072 |
// symbol->parameter_assignment->accept(*this); |
|
1073 |
s4o.print(")"); |
|
149 | 1074 |
/* the data type returned by the function, and stored in the il default variable... */ |
70 | 1075 |
return NULL; |
1076 |
} |
|
1077 |
||
1078 |
||
1079 |
/* | il_operand_list ',' il_operand */ |
|
1080 |
// SYM_LIST(il_operand_list_c) |
|
1081 |
void *visit(il_operand_list_c *symbol) {ERROR; return NULL;} // should never get called! |
|
1082 |
||
1083 |
||
1084 |
/* | simple_instr_list il_simple_instruction */ |
|
1085 |
// SYM_LIST(simple_instr_list_c) |
|
1086 |
void *visit(simple_instr_list_c *symbol) { |
|
1087 |
/* A simple_instr_list_c is used to store a list of il operations |
|
1088 |
* being done within parenthesis... |
|
1089 |
* |
|
1090 |
* e.g.: |
|
1091 |
* LD var1 |
|
1092 |
* AND ( var2 |
|
1093 |
* OR var3 |
|
1094 |
* OR var4 |
|
1095 |
* ) |
|
1096 |
* |
|
1097 |
* This will be converted to C++ by defining a new scope |
|
1098 |
* with a new il default variable, and executing the il operands |
|
1099 |
* within this new scope. |
|
1100 |
* At the end of the scope the result, i.e. the value currently stored |
|
1101 |
* in the il default variable is copied to the variable used to take this |
|
1102 |
* value to the outside scope... |
|
1103 |
* |
|
1104 |
* The above example will result in the following C++ code: |
|
1105 |
* {__IL_DEFVAR_T __IL_DEFVAR_BACK; |
|
1106 |
* __IL_DEFVAR_T __IL_DEFVAR; |
|
1107 |
* |
|
1108 |
* __IL_DEFVAR.INTvar = var1; |
|
1109 |
* { |
|
1110 |
* __IL_DEFVAR_T __IL_DEFVAR; |
|
1111 |
* |
|
1112 |
* __IL_DEFVAR.INTvar = var2; |
|
1113 |
* __IL_DEFVAR.INTvar |= var3; |
|
1114 |
* __IL_DEFVAR.INTvar |= var4; |
|
1115 |
* |
|
1116 |
* __IL_DEFVAR_BACK = __IL_DEFVAR; |
|
1117 |
* } |
|
1118 |
* __IL_DEFVAR.INTvar &= __IL_DEFVAR_BACK.INTvar; |
|
1119 |
* |
|
1120 |
* } |
|
1121 |
* |
|
1122 |
* The intial value of the il default variable (in the above |
|
1123 |
* example 'var2') is passed to this simple_instr_list_c visitor |
|
1124 |
* using the il_default_variable_init_value parameter. |
|
1125 |
* Since it is possible to have parenthesis inside other parenthesis |
|
1126 |
* recursively, we reset the il_default_variable_init_value to NULL |
|
1127 |
* as soon as we no longer require it, as it may be used once again |
|
1128 |
* in the line |
|
1129 |
* print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); |
|
1130 |
* |
|
1131 |
*/ |
|
1132 |
||
1133 |
/* Declare the default variable, that will store the result of the IL operations... */ |
|
1134 |
s4o.print("{\n"); |
|
1135 |
s4o.indent_right(); |
|
1136 |
||
1137 |
s4o.print(s4o.indent_spaces); |
|
1138 |
s4o.print(IL_DEFVAR_T); |
|
1139 |
s4o.print(" "); |
|
1140 |
this->default_variable_name.accept(*this); |
|
1141 |
s4o.print(";\n\n"); |
|
1142 |
||
1143 |
/* Check whether we should initiliase the il default variable... */ |
|
1144 |
if (NULL != this->il_default_variable_init_value) { |
|
1145 |
/* Yes, we must... */ |
|
1146 |
/* We will do it by instatiating a LD operator, and having this |
|
1147 |
* same generate_c_il_c class visiting it! |
|
1148 |
*/ |
|
1149 |
LD_operator_c ld_oper; |
|
1150 |
il_simple_operation_c il_simple_oper(&ld_oper, this->il_default_variable_init_value); |
|
1151 |
||
1152 |
s4o.print(s4o.indent_spaces); |
|
1153 |
il_simple_oper.accept(*this); |
|
1154 |
s4o.print(";\n"); |
|
1155 |
} |
|
1156 |
||
1157 |
/* this parameter no longer required... */ |
|
1158 |
this->il_default_variable_init_value = NULL; |
|
1159 |
||
1160 |
print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); |
|
1161 |
||
1162 |
/* copy the result in the default variable to the variable |
|
1163 |
* used to pass the data out to the scope enclosing |
|
1164 |
* the current scope! |
|
1165 |
* |
|
1166 |
* We also need to update the data type currently stored within |
|
1167 |
* the variable used to pass the data to the outside scope... |
|
1168 |
*/ |
|
1169 |
this->default_variable_back_name.current_type = this->default_variable_name.current_type; |
|
1170 |
s4o.print("\n"); |
|
1171 |
s4o.print(s4o.indent_spaces); |
|
1172 |
this->default_variable_back_name.accept(*this); |
|
1173 |
s4o.print(" = "); |
|
1174 |
this->default_variable_name.accept(*this); |
|
1175 |
s4o.print(";\n"); |
|
1176 |
||
1177 |
s4o.indent_left(); |
|
1178 |
s4o.print(s4o.indent_spaces); |
|
1179 |
s4o.print("}\n"); |
|
1180 |
s4o.print(s4o.indent_spaces); |
|
1181 |
return NULL; |
|
1182 |
} |
|
1183 |
||
1184 |
/* | il_initial_param_list il_param_instruction */ |
|
1185 |
// SYM_LIST(il_param_list_c) |
|
1186 |
void *visit(il_param_list_c *symbol) {ERROR; return NULL;} // should never get called! |
|
1187 |
||
1188 |
/* il_assign_operator il_operand |
|
1189 |
* | il_assign_operator '(' eol_list simple_instr_list ')' |
|
1190 |
*/ |
|
1191 |
// SYM_REF4(il_param_assignment_c, il_assign_operator, il_operand, simple_instr_list, unused) |
|
1192 |
void *visit(il_param_assignment_c *symbol) {ERROR; return NULL;} // should never get called! |
|
1193 |
||
1194 |
/* il_assign_out_operator variable */ |
|
1195 |
// SYM_REF2(il_param_out_assignment_c, il_assign_out_operator, variable); |
|
1196 |
void *visit(il_param_out_assignment_c *symbol) {ERROR; return NULL;} // should never get called! |
|
1197 |
||
1198 |
/*******************/ |
|
1199 |
/* B 2.2 Operators */ |
|
1200 |
/*******************/ |
|
1201 |
||
1202 |
void *visit(LD_operator_c *symbol) { |
|
1203 |
/* the data type resulting from this operation... */ |
|
210
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1204 |
if (search_expression_type->is_literal_integer_type(this->current_operand_type)) |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1205 |
this->default_variable_name.current_type = &(this->lint_type); |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1206 |
else if (search_expression_type->is_literal_real_type(this->current_operand_type)) |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1207 |
this->default_variable_name.current_type = &(this->lreal_type); |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1208 |
else |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1209 |
this->default_variable_name.current_type = this->current_operand_type; |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1210 |
XXX_operator(&(this->default_variable_name), " = ", this->current_operand); |
70 | 1211 |
this->default_variable_name.current_type = this->current_operand_type; |
1212 |
return NULL; |
|
1213 |
} |
|
1214 |
||
1215 |
void *visit(LDN_operator_c *symbol) { |
|
1216 |
/* the data type resulting from this operation... */ |
|
210
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1217 |
if (search_expression_type->is_literal_integer_type(this->current_operand_type)) |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1218 |
this->default_variable_name.current_type = &(this->lword_type); |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1219 |
else |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1220 |
this->default_variable_name.current_type = this->current_operand_type; |
70 | 1221 |
XXX_operator(&(this->default_variable_name), |
1222 |
search_expression_type->is_bool_type(this->current_operand_type)?" = !":" = ~", |
|
1223 |
this->current_operand); |
|
1224 |
return NULL; |
|
1225 |
} |
|
1226 |
||
1227 |
void *visit(ST_operator_c *symbol) { |
|
98 | 1228 |
symbol_c *operand_type = search_varfb_instance_type->get_type(this->current_operand, false); |
123 | 1229 |
|
98 | 1230 |
this->current_operand->accept(*this); |
1231 |
s4o.print(" = "); |
|
123 | 1232 |
if (search_base_type.type_is_subrange(operand_type)) { |
98 | 1233 |
s4o.print("__CHECK_"); |
1234 |
operand_type->accept(*this); |
|
1235 |
s4o.print("("); |
|
1236 |
} |
|
210
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1237 |
if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type) || |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1238 |
search_expression_type->is_literal_real_type(this->default_variable_name.current_type)) |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1239 |
this->default_variable_name.current_type = this->current_operand_type; |
98 | 1240 |
this->default_variable_name.accept(*this); |
123 | 1241 |
if (search_base_type.type_is_subrange(operand_type)) |
98 | 1242 |
s4o.print(")"); |
70 | 1243 |
/* the data type resulting from this operation is unchamged. */ |
1244 |
return NULL; |
|
1245 |
} |
|
1246 |
||
1247 |
void *visit(STN_operator_c *symbol) { |
|
98 | 1248 |
symbol_c *operand_type = search_varfb_instance_type->get_type(this->current_operand, false); |
123 | 1249 |
|
98 | 1250 |
this->current_operand->accept(*this); |
1251 |
s4o.print(" = "); |
|
123 | 1252 |
if (search_base_type.type_is_subrange(operand_type)) { |
98 | 1253 |
s4o.print("__CHECK_"); |
1254 |
operand_type->accept(*this); |
|
1255 |
s4o.print("("); |
|
1256 |
} |
|
1257 |
if (search_expression_type->is_bool_type(this->current_operand_type)) |
|
1258 |
s4o.print("!"); |
|
1259 |
else |
|
1260 |
s4o.print("~"); |
|
210
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1261 |
if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type)) |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1262 |
this->default_variable_name.current_type = this->current_operand_type; |
98 | 1263 |
this->default_variable_name.accept(*this); |
123 | 1264 |
if (search_base_type.type_is_subrange(operand_type)) |
98 | 1265 |
s4o.print(")"); |
70 | 1266 |
/* the data type resulting from this operation is unchamged. */ |
1267 |
return NULL; |
|
1268 |
} |
|
1269 |
||
1270 |
void *visit(NOT_operator_c *symbol) { |
|
1271 |
if ((NULL != this->current_operand) || (NULL != this->current_operand_type)) ERROR; |
|
1272 |
XXX_operator(&(this->default_variable_name), |
|
1273 |
search_expression_type->is_bool_type(this->default_variable_name.current_type)?" = !":" = ~", |
|
1274 |
&(this->default_variable_name)); |
|
1275 |
/* the data type resulting from this operation is unchanged. */ |
|
1276 |
return NULL; |
|
1277 |
} |
|
1278 |
||
1279 |
void *visit(S_operator_c *symbol) { |
|
1280 |
if ((NULL == this->current_operand) || (NULL == this->current_operand_type)) ERROR; |
|
1281 |
||
1282 |
C_modifier(); |
|
1283 |
this->current_operand->accept(*this); |
|
1284 |
s4o.print(search_expression_type->is_bool_type(this->current_operand_type)?" = true":" = 1"); |
|
1285 |
/* the data type resulting from this operation is unchanged! */ |
|
1286 |
return NULL; |
|
1287 |
} |
|
1288 |
||
1289 |
void *visit(R_operator_c *symbol) { |
|
1290 |
if ((NULL == this->current_operand) || (NULL == this->current_operand_type)) ERROR; |
|
1291 |
||
1292 |
C_modifier(); |
|
1293 |
this->current_operand->accept(*this); |
|
1294 |
s4o.print(search_expression_type->is_bool_type(this->current_operand_type)?" = false":" = 0"); |
|
1295 |
/* the data type resulting from this operation is unchanged! */ |
|
1296 |
return NULL; |
|
1297 |
} |
|
1298 |
||
1299 |
void *visit(S1_operator_c *symbol) {return XXX_CAL_operator("S1", this->current_operand);} |
|
1300 |
void *visit(R1_operator_c *symbol) {return XXX_CAL_operator("R1", this->current_operand);} |
|
1301 |
void *visit(CLK_operator_c *symbol) {return XXX_CAL_operator("CLK", this->current_operand);} |
|
1302 |
void *visit(CU_operator_c *symbol) {return XXX_CAL_operator("CU", this->current_operand);} |
|
1303 |
void *visit(CD_operator_c *symbol) {return XXX_CAL_operator("CD", this->current_operand);} |
|
1304 |
void *visit(PV_operator_c *symbol) {return XXX_CAL_operator("PV", this->current_operand);} |
|
1305 |
void *visit(IN_operator_c *symbol) {return XXX_CAL_operator("IN", this->current_operand);} |
|
1306 |
void *visit(PT_operator_c *symbol) {return XXX_CAL_operator("PT", this->current_operand);} |
|
1307 |
||
1308 |
void *visit(AND_operator_c *symbol) { |
|
1309 |
if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
|
1310 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
|
210
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1311 |
BYTE_operator_result_type(); |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1312 |
XXX_operator(&(this->default_variable_name), " &= ", this->current_operand); |
70 | 1313 |
/* the data type resulting from this operation... */ |
1314 |
this->default_variable_name.current_type = this->current_operand_type; |
|
1315 |
} |
|
1316 |
else {ERROR;} |
|
1317 |
return NULL; |
|
1318 |
} |
|
1319 |
||
1320 |
void *visit(OR_operator_c *symbol) { |
|
1321 |
if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
|
1322 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
|
210
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1323 |
BYTE_operator_result_type(); |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1324 |
XXX_operator(&(this->default_variable_name), " |= ", this->current_operand); |
70 | 1325 |
/* the data type resulting from this operation... */ |
1326 |
this->default_variable_name.current_type = this->current_operand_type; |
|
1327 |
} |
|
1328 |
else {ERROR;} |
|
1329 |
return NULL; |
|
1330 |
} |
|
1331 |
||
1332 |
void *visit(XOR_operator_c *symbol) { |
|
1333 |
if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
|
1334 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
|
210
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1335 |
BYTE_operator_result_type(); |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1336 |
// '^' is a bit by bit exclusive OR !! Also seems to work with boolean types! |
70 | 1337 |
XXX_operator(&(this->default_variable_name), " ^= ", this->current_operand); |
1338 |
/* the data type resulting from this operation... */ |
|
1339 |
this->default_variable_name.current_type = this->current_operand_type; |
|
1340 |
} |
|
1341 |
else {ERROR;} |
|
1342 |
return NULL; |
|
1343 |
} |
|
1344 |
||
1345 |
void *visit(ANDN_operator_c *symbol) { |
|
1346 |
if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
|
1347 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
|
210
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1348 |
BYTE_operator_result_type(); |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1349 |
XXX_operator(&(this->default_variable_name), |
70 | 1350 |
search_expression_type->is_bool_type(this->current_operand_type)?" &= !":" &= ~", |
1351 |
this->current_operand); |
|
1352 |
/* the data type resulting from this operation... */ |
|
1353 |
this->default_variable_name.current_type = this->current_operand_type; |
|
1354 |
} |
|
1355 |
else {ERROR;} |
|
1356 |
return NULL; |
|
1357 |
} |
|
1358 |
||
1359 |
void *visit(ORN_operator_c *symbol) { |
|
1360 |
if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
|
1361 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
|
210
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1362 |
BYTE_operator_result_type(); |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1363 |
XXX_operator(&(this->default_variable_name), |
70 | 1364 |
search_expression_type->is_bool_type(this->current_operand_type)?" |= !":" |= ~", |
1365 |
this->current_operand); |
|
1366 |
/* the data type resulting from this operation... */ |
|
1367 |
this->default_variable_name.current_type = this->current_operand_type; |
|
1368 |
} |
|
1369 |
else {ERROR;} |
|
1370 |
return NULL; |
|
1371 |
} |
|
1372 |
||
1373 |
void *visit(XORN_operator_c *symbol) { |
|
1374 |
if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
|
1375 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
|
210
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1376 |
BYTE_operator_result_type(); |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1377 |
XXX_operator(&(this->default_variable_name), |
70 | 1378 |
// bit by bit exclusive OR !! Also seems to work with boolean types! |
1379 |
search_expression_type->is_bool_type(this->current_operand_type)?" ^= !":" ^= ~", |
|
1380 |
this->current_operand); |
|
1381 |
/* the data type resulting from this operation... */ |
|
1382 |
this->default_variable_name.current_type = this->current_operand_type; |
|
1383 |
} |
|
1384 |
else {ERROR;} |
|
1385 |
return NULL; |
|
1386 |
} |
|
1387 |
||
1388 |
void *visit(ADD_operator_c *symbol) { |
|
1389 |
if (search_expression_type->is_time_type(this->default_variable_name.current_type) && |
|
1390 |
search_expression_type->is_time_type(this->current_operand_type)) { |
|
149 | 1391 |
XXX_function("__TIME_ADD", &(this->default_variable_name), this->current_operand); |
70 | 1392 |
/* the data type resulting from this operation... */ |
1393 |
this->default_variable_name.current_type = this->current_operand_type; |
|
1394 |
return NULL; |
|
1395 |
} |
|
1396 |
if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
|
1397 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
|
210
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1398 |
NUM_operator_result_type(); |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1399 |
XXX_operator(&(this->default_variable_name), " += ", this->current_operand); |
70 | 1400 |
/* the data type resulting from this operation... */ |
1401 |
this->default_variable_name.current_type = this->current_operand_type; |
|
1402 |
return NULL; |
|
1403 |
} |
|
1404 |
ERROR; |
|
1405 |
return NULL; |
|
1406 |
} |
|
1407 |
||
1408 |
void *visit(SUB_operator_c *symbol) { |
|
1409 |
if (search_expression_type->is_time_type(this->default_variable_name.current_type) && |
|
1410 |
search_expression_type->is_time_type(this->current_operand_type)) { |
|
149 | 1411 |
XXX_function("__TIME_SUB", &(this->default_variable_name), this->current_operand); |
70 | 1412 |
/* the data type resulting from this operation... */ |
1413 |
this->default_variable_name.current_type = this->current_operand_type; |
|
1414 |
return NULL; |
|
1415 |
} |
|
1416 |
if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
|
1417 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
|
210
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1418 |
NUM_operator_result_type(); |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1419 |
XXX_operator(&(this->default_variable_name), " -= ", this->current_operand); |
70 | 1420 |
/* the data type resulting from this operation... */ |
1421 |
this->default_variable_name.current_type = this->current_operand_type; |
|
1422 |
return NULL; |
|
1423 |
} |
|
1424 |
ERROR; |
|
1425 |
return NULL; |
|
1426 |
} |
|
1427 |
||
1428 |
void *visit(MUL_operator_c *symbol) { |
|
1429 |
if (search_expression_type->is_time_type(this->default_variable_name.current_type) && |
|
1430 |
search_expression_type->is_integer_type(this->current_operand_type)) { |
|
149 | 1431 |
XXX_function("__TIME_MUL", &(this->default_variable_name), this->current_operand); |
70 | 1432 |
/* the data type resulting from this operation... */ |
1433 |
return NULL; |
|
1434 |
} |
|
1435 |
if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
|
1436 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
|
210
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1437 |
NUM_operator_result_type(); |
70 | 1438 |
XXX_operator(&(this->default_variable_name), " *= ", this->current_operand); |
1439 |
/* the data type resulting from this operation... */ |
|
1440 |
this->default_variable_name.current_type = this->current_operand_type; |
|
1441 |
return NULL; |
|
1442 |
} |
|
1443 |
ERROR; |
|
1444 |
return NULL; |
|
1445 |
} |
|
1446 |
||
1447 |
void *visit(DIV_operator_c *symbol) { |
|
149 | 1448 |
if (search_expression_type->is_time_type(this->default_variable_name.current_type) && |
1449 |
search_expression_type->is_integer_type(this->current_operand_type)) { |
|
1450 |
XXX_function("__TIME_DIV", &(this->default_variable_name), this->current_operand); |
|
1451 |
/* the data type resulting from this operation... */ |
|
1452 |
return NULL; |
|
1453 |
} |
|
70 | 1454 |
if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
1455 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
|
210
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1456 |
NUM_operator_result_type(); |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1457 |
XXX_operator(&(this->default_variable_name), " /= ", this->current_operand); |
70 | 1458 |
/* the data type resulting from this operation... */ |
1459 |
this->default_variable_name.current_type = this->current_operand_type; |
|
1460 |
} |
|
149 | 1461 |
ERROR; |
70 | 1462 |
return NULL; |
1463 |
} |
|
1464 |
||
1465 |
void *visit(MOD_operator_c *symbol) { |
|
1466 |
if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
|
1467 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
|
210
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1468 |
NUM_operator_result_type(); |
8387cac2aba6
Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents:
208
diff
changeset
|
1469 |
XXX_operator(&(this->default_variable_name), " %= ", this->current_operand); |
70 | 1470 |
/* the data type resulting from this operation... */ |
1471 |
this->default_variable_name.current_type = this->current_operand_type; |
|
1472 |
} |
|
149 | 1473 |
ERROR; |
70 | 1474 |
return NULL; |
1475 |
} |
|
1476 |
||
1477 |
void *visit(GT_operator_c *symbol) { |
|
123 | 1478 |
if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) && |
1479 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) |
|
1480 |
return CMP_operator(this->current_operand, "__gt_"); |
|
1481 |
ERROR; |
|
1482 |
return NULL; |
|
70 | 1483 |
} |
1484 |
||
1485 |
void *visit(GE_operator_c *symbol) { |
|
123 | 1486 |
if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) && |
1487 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) |
|
1488 |
return CMP_operator(this->current_operand, "__ge_"); |
|
1489 |
ERROR; |
|
1490 |
return NULL; |
|
70 | 1491 |
} |
1492 |
||
1493 |
void *visit(EQ_operator_c *symbol) { |
|
123 | 1494 |
if (search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) |
1495 |
return CMP_operator(this->current_operand, "__eq_"); |
|
1496 |
ERROR; |
|
1497 |
return NULL; |
|
70 | 1498 |
} |
1499 |
||
1500 |
void *visit(LT_operator_c *symbol) { |
|
123 | 1501 |
if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) && |
1502 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) |
|
1503 |
return CMP_operator(this->current_operand, "__lt_"); |
|
1504 |
ERROR; |
|
1505 |
return NULL; |
|
70 | 1506 |
} |
1507 |
||
1508 |
void *visit(LE_operator_c *symbol) { |
|
123 | 1509 |
if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) && |
1510 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) |
|
1511 |
return CMP_operator(this->current_operand, "__le_"); |
|
1512 |
ERROR; |
|
1513 |
return NULL; |
|
70 | 1514 |
} |
1515 |
||
1516 |
void *visit(NE_operator_c *symbol) { |
|
123 | 1517 |
if (search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) |
1518 |
return CMP_operator(this->current_operand, "__ne_"); |
|
1519 |
ERROR; |
|
1520 |
return NULL; |
|
70 | 1521 |
} |
1522 |
||
1523 |
||
1524 |
//SYM_REF0(CAL_operator_c) |
|
1525 |
// This method will be called from within the il_fb_call_c visitor method |
|
1526 |
void *visit(CAL_operator_c *symbol) {return NULL;} |
|
1527 |
||
1528 |
//SYM_REF0(CALC_operator_c) |
|
1529 |
// This method will be called from within the il_fb_call_c visitor method |
|
1530 |
void *visit(CALC_operator_c *symbol) {C_modifier(); return NULL;} |
|
1531 |
||
1532 |
//SYM_REF0(CALCN_operator_c) |
|
1533 |
// This method will be called from within the il_fb_call_c visitor method |
|
1534 |
void *visit(CALCN_operator_c *symbol) {CN_modifier(); return NULL;} |
|
1535 |
||
1536 |
/* NOTE: The semantics of the RET operator requires us to return a value |
|
1537 |
* if the IL code is inside a function, but simply return no value if |
|
1538 |
* the IL code is inside a function block or program! |
|
1539 |
* Nevertheless, it is the generate_c_c class itself that |
|
1540 |
* introduces the 'reaturn <value>' into the c++ code at the end |
|
1541 |
* of every function. This class does not know whether the IL code |
|
1542 |
* is inside a function or a function block. |
|
1543 |
* We work around this by jumping to the end of the code, |
|
1544 |
* that will be marked by the END_LABEL label in the |
|
1545 |
* instruction_list_c visitor... |
|
1546 |
*/ |
|
1547 |
// SYM_REF0(RET_operator_c) |
|
1548 |
void *visit(RET_operator_c *symbol) { |
|
1549 |
s4o.print("goto ");s4o.print(END_LABEL); |
|
1550 |
return NULL; |
|
1551 |
} |
|
1552 |
||
1553 |
// SYM_REF0(RETC_operator_c) |
|
1554 |
void *visit(RETC_operator_c *symbol) { |
|
1555 |
C_modifier(); |
|
1556 |
s4o.print("goto ");s4o.print(END_LABEL); |
|
1557 |
return NULL; |
|
1558 |
} |
|
1559 |
||
1560 |
// SYM_REF0(RETCN_operator_c) |
|
1561 |
void *visit(RETCN_operator_c *symbol) { |
|
1562 |
CN_modifier(); |
|
1563 |
s4o.print("goto ");s4o.print(END_LABEL); |
|
1564 |
return NULL; |
|
1565 |
} |
|
1566 |
||
1567 |
//SYM_REF0(JMP_operator_c) |
|
1568 |
void *visit(JMP_operator_c *symbol) { |
|
1569 |
if (NULL == this->jump_label) ERROR; |
|
1570 |
||
1571 |
s4o.print("goto "); |
|
1572 |
this->jump_label->accept(*this); |
|
1573 |
/* the data type resulting from this operation is unchanged! */ |
|
1574 |
return NULL; |
|
1575 |
} |
|
1576 |
||
1577 |
// SYM_REF0(JMPC_operator_c) |
|
1578 |
void *visit(JMPC_operator_c *symbol) { |
|
1579 |
if (NULL == this->jump_label) ERROR; |
|
1580 |
||
1581 |
C_modifier(); |
|
1582 |
s4o.print("goto "); |
|
1583 |
this->jump_label->accept(*this); |
|
1584 |
/* the data type resulting from this operation is unchanged! */ |
|
1585 |
return NULL; |
|
1586 |
} |
|
1587 |
||
1588 |
// SYM_REF0(JMPCN_operator_c) |
|
1589 |
void *visit(JMPCN_operator_c *symbol) { |
|
1590 |
if (NULL == this->jump_label) ERROR; |
|
1591 |
||
1592 |
CN_modifier(); |
|
1593 |
s4o.print("goto "); |
|
1594 |
this->jump_label->accept(*this); |
|
1595 |
/* the data type resulting from this operation is unchanged! */ |
|
1596 |
return NULL; |
|
1597 |
} |
|
1598 |
||
1599 |
#if 0 |
|
1600 |
/*| [NOT] any_identifier SENDTO */ |
|
1601 |
SYM_REF2(il_assign_out_operator_c, option, variable_name) |
|
1602 |
#endif |
|
1603 |
||
1604 |
}; /* generate_c_il_c */ |
|
1605 |
||
1606 |
||
1607 |
||
1608 |
||
1609 |
||
1610 |
||
1611 |
||
1612 |
||
1613 |
||
1614 |
/* The implementation of the single visit() member function |
|
1615 |
* of il_default_variable_c. |
|
1616 |
* It can only come after the full declaration of |
|
1617 |
* generate_c_il_c. Since we define and declare |
|
1618 |
* generate_c_il_c simultaneously, it can only come |
|
1619 |
* after the definition... |
|
1620 |
*/ |
|
1621 |
void *il_default_variable_c::accept(visitor_c &visitor) { |
|
1622 |
/* An ugly hack!! */ |
|
1623 |
/* This is required because we need to over-ride the base |
|
1624 |
* accept(visitor_c &) method of the class symbol_c, |
|
1625 |
* so this method may be called through a symbol_c * |
|
1626 |
* reference! |
|
1627 |
* |
|
1628 |
* But, the visitor_c does not include a visitor to |
|
1629 |
* an il_default_variable_c, which means that we couldn't |
|
1630 |
* simply call visitor.visit(this); |
|
1631 |
* |
|
1632 |
* We therefore need to use the dynamic_cast hack!! |
|
1633 |
* |
|
1634 |
* Note too that we can't cast a visitor_c to a |
|
1635 |
* il_default_variable_visitor_c, since they are not related. |
|
1636 |
* Nor may the il_default_variable_visitor_c inherit from |
|
1637 |
* visitor_c, because then generate_c_il_c would contain |
|
1638 |
* two visitor_c base classes, one each through |
|
1639 |
* il_default_variable_visitor_c and generate_c_type_c |
|
1640 |
* |
|
1641 |
* We could use virtual inheritance of the visitor_c, but it |
|
1642 |
* would probably create more problems than it is worth! |
|
1643 |
*/ |
|
1644 |
generate_c_il_c *v; |
|
1645 |
v = dynamic_cast<generate_c_il_c *>(&visitor); |
|
1646 |
if (v == NULL) ERROR; |
|
1647 |
||
1648 |
return v->visit(this); |
|
1649 |
} |
|
1650 |
||
1651 |
||
1652 |
||
1653 |
||
1654 |
il_default_variable_c::il_default_variable_c(const char *var_name_str, symbol_c *current_type) { |
|
1655 |
if (NULL == var_name_str) ERROR; |
|
1656 |
/* Note: current_type may start off with NULL */ |
|
1657 |
||
1658 |
this->var_name = new identifier_c(var_name_str); |
|
1659 |
if (NULL == this->var_name) ERROR; |
|
1660 |
||
1661 |
this->current_type = current_type; |
|
1662 |
} |