author | laurent |
Sat, 12 Mar 2011 18:43:02 +0100 | |
changeset 249 | d58a45824531 |
parent 240 | f78fa87bb4cb |
child 258 | d7d92b2f87e9 |
permissions | -rwxr-xr-x |
70 | 1 |
/* |
2 |
* (c) 2003 Mario de Sousa |
|
3 |
* |
|
4 |
* Offered to the public under the terms of the GNU General Public License |
|
5 |
* as published by the Free Software Foundation; either version 2 of the |
|
6 |
* License, or (at your option) any later version. |
|
7 |
* |
|
8 |
* This program is distributed in the hope that it will be useful, but |
|
9 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
11 |
* Public License for more details. |
|
12 |
* |
|
13 |
* This code is made available on the understanding that it will not be |
|
14 |
* used in safety-critical situations without a full and competent review. |
|
15 |
*/ |
|
16 |
||
17 |
/* |
|
18 |
* An IEC 61131-3 IL and ST compiler. |
|
19 |
* |
|
20 |
* Based on the |
|
21 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
||
26 |
/* |
|
27 |
* Conversion of st statements (i.e. ST code). |
|
28 |
* |
|
29 |
* This is part of the 4th stage that generates |
|
30 |
* a c++ source program equivalent to the IL and ST |
|
31 |
* code. |
|
32 |
*/ |
|
33 |
||
34 |
||
35 |
/***********************************************************************/ |
|
36 |
/***********************************************************************/ |
|
37 |
/***********************************************************************/ |
|
38 |
/***********************************************************************/ |
|
39 |
||
40 |
||
41 |
class generate_c_st_c: public generate_c_typedecl_c { |
|
42 |
||
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
43 |
public: |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
44 |
typedef enum { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
45 |
expression_vg, |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
46 |
assignment_vg, |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
47 |
complextype_base_vg, |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
48 |
complextype_suffix_vg, |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
49 |
fparam_output_vg |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
50 |
} variablegeneration_t; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
51 |
|
70 | 52 |
private: |
53 |
/* When calling a function block, we must first find it's type, |
|
54 |
* by searching through the declarations of the variables currently |
|
55 |
* in scope. |
|
56 |
* This class does just that... |
|
57 |
* A new class is instantiated whenever we begin generating the code |
|
58 |
* for a function block type declaration, or a program declaration. |
|
59 |
* This object instance will then later be called while the |
|
60 |
* function block's or the program's body is being handled. |
|
61 |
* |
|
62 |
* Note that functions cannot contain calls to function blocks, |
|
63 |
* so we do not create an object instance when handling |
|
64 |
* a function declaration. |
|
65 |
*/ |
|
66 |
search_fb_instance_decl_c *search_fb_instance_decl; |
|
67 |
||
68 |
/* When compiling st code, it becomes necessary to determine the |
|
69 |
* data type of st expressions. To do this, we must first find the |
|
70 |
* st operand's declaration, within the scope of the function block |
|
71 |
* or function currently being processed. |
|
72 |
* The following object does just that... |
|
73 |
* This object instance will then later be called while the |
|
74 |
* remaining st code is being handled. |
|
75 |
*/ |
|
76 |
search_expression_type_c *search_expression_type; |
|
77 |
||
78 |
search_varfb_instance_type_c *search_varfb_instance_type; |
|
79 |
||
98 | 80 |
search_base_type_c search_base_type; |
81 |
||
82 |
symbol_c* current_array_type; |
|
235 | 83 |
symbol_c* current_param_type; |
98 | 84 |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
85 |
int fcall_number; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
86 |
symbol_c *fbname; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
87 |
|
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
88 |
variablegeneration_t wanted_variablegeneration; |
145 | 89 |
|
70 | 90 |
public: |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
91 |
generate_c_st_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL) |
70 | 92 |
: generate_c_typedecl_c(s4o_ptr) { |
93 |
search_fb_instance_decl = new search_fb_instance_decl_c(scope); |
|
94 |
search_expression_type = new search_expression_type_c(scope); |
|
95 |
search_varfb_instance_type = new search_varfb_instance_type_c(scope); |
|
96 |
this->set_variable_prefix(variable_prefix); |
|
98 | 97 |
current_array_type = NULL; |
235 | 98 |
current_param_type = NULL; |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
99 |
fcall_number = 0; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
100 |
fbname = name; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
101 |
wanted_variablegeneration = expression_vg; |
70 | 102 |
} |
103 |
||
104 |
virtual ~generate_c_st_c(void) { |
|
105 |
delete search_fb_instance_decl; |
|
106 |
delete search_expression_type; |
|
107 |
delete search_varfb_instance_type; |
|
108 |
} |
|
109 |
||
110 |
||
111 |
public: |
|
112 |
void generate(statement_list_c *stl) { |
|
113 |
stl->accept(*this); |
|
114 |
} |
|
115 |
||
116 |
private: |
|
117 |
||
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
118 |
void *print_getter(symbol_c *symbol) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
119 |
unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); |
235 | 120 |
if (wanted_variablegeneration == fparam_output_vg) { |
121 |
if (vartype == search_var_instance_decl_c::external_vt) |
|
122 |
s4o.print(GET_EXTERNAL_BY_REF); |
|
123 |
else if (vartype == search_var_instance_decl_c::located_vt) |
|
124 |
s4o.print(GET_LOCATED_BY_REF); |
|
125 |
else |
|
126 |
s4o.print(GET_VAR_BY_REF); |
|
127 |
} |
|
128 |
else { |
|
129 |
if (vartype == search_var_instance_decl_c::external_vt) |
|
130 |
s4o.print(GET_EXTERNAL); |
|
131 |
else if (vartype == search_var_instance_decl_c::located_vt) |
|
132 |
s4o.print(GET_LOCATED); |
|
133 |
else |
|
134 |
s4o.print(GET_VAR); |
|
135 |
} |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
136 |
s4o.print("("); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
137 |
|
235 | 138 |
variablegeneration_t old_wanted_variablegeneration = wanted_variablegeneration; |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
139 |
wanted_variablegeneration = complextype_base_vg; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
140 |
symbol->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
141 |
if (search_varfb_instance_type->type_is_complex()) |
235 | 142 |
s4o.print(","); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
143 |
wanted_variablegeneration = complextype_suffix_vg; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
144 |
symbol->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
145 |
s4o.print(")"); |
235 | 146 |
wanted_variablegeneration = old_wanted_variablegeneration; |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
147 |
return NULL; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
148 |
} |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
149 |
|
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
150 |
void *print_setter(symbol_c* symbol, |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
151 |
symbol_c* type, |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
152 |
symbol_c* value, |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
153 |
symbol_c* fb_symbol = NULL, |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
154 |
symbol_c* fb_value = NULL) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
155 |
unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); |
231
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
156 |
if (vartype == search_var_instance_decl_c::external_vt) { |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
157 |
symbolic_variable_c *variable = dynamic_cast<symbolic_variable_c *>(symbol); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
158 |
/* TODO Find a solution for forcing global complex variables */ |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
159 |
if (variable != NULL) { |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
160 |
s4o.print(SET_EXTERNAL); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
161 |
s4o.print("("); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
162 |
variable->var_name->accept(*this); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
163 |
s4o.print(","); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
164 |
} |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
165 |
else { |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
166 |
s4o.print(SET_COMPLEX_EXTERNAL); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
167 |
s4o.print("("); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
168 |
} |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
169 |
} |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
170 |
else { |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
171 |
if (vartype == search_var_instance_decl_c::located_vt) |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
172 |
s4o.print(SET_LOCATED); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
173 |
else |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
174 |
s4o.print(SET_VAR); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
175 |
s4o.print("("); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
176 |
} |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
177 |
|
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
178 |
if (fb_symbol != NULL) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
179 |
print_variable_prefix(); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
180 |
fb_symbol->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
181 |
s4o.print("."); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
182 |
} |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
183 |
else |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
184 |
wanted_variablegeneration = complextype_base_vg; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
185 |
symbol->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
186 |
s4o.print(","); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
187 |
wanted_variablegeneration = expression_vg; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
188 |
print_check_function(type, value, fb_value); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
189 |
if (search_varfb_instance_type->type_is_complex()) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
190 |
s4o.print(","); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
191 |
wanted_variablegeneration = complextype_suffix_vg; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
192 |
symbol->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
193 |
} |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
194 |
s4o.print(")"); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
195 |
wanted_variablegeneration = expression_vg; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
196 |
return NULL; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
197 |
} |
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
198 |
|
70 | 199 |
/*********************/ |
200 |
/* B 1.4 - Variables */ |
|
201 |
/*********************/ |
|
202 |
void *visit(symbolic_variable_c *symbol) { |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
203 |
unsigned int vartype; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
204 |
if (wanted_variablegeneration == complextype_base_vg) |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
205 |
generate_c_base_c::visit(symbol); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
206 |
else if (wanted_variablegeneration == complextype_suffix_vg) |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
207 |
return NULL; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
208 |
else if (this->is_variable_prefix_null()) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
209 |
vartype = search_varfb_instance_type->get_vartype(symbol); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
210 |
if (wanted_variablegeneration == fparam_output_vg) { |
236 | 211 |
s4o.print("&("); |
212 |
generate_c_base_c::visit(symbol); |
|
213 |
s4o.print(")"); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
214 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
215 |
else { |
236 | 216 |
generate_c_base_c::visit(symbol); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
217 |
} |
145 | 218 |
} |
235 | 219 |
else |
220 |
print_getter(symbol); |
|
70 | 221 |
return NULL; |
222 |
} |
|
223 |
||
224 |
/********************************************/ |
|
225 |
/* B.1.4.1 Directly Represented Variables */ |
|
226 |
/********************************************/ |
|
227 |
// direct_variable: direct_variable_token {$$ = new direct_variable_c($1);}; |
|
228 |
void *visit(direct_variable_c *symbol) { |
|
229 |
TRACE("direct_variable_c"); |
|
230 |
/* Do not use print_token() as it will change everything into uppercase */ |
|
231 |
if (strlen(symbol->value) == 0) ERROR; |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
232 |
if (this->is_variable_prefix_null()) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
233 |
if (wanted_variablegeneration != fparam_output_vg) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
234 |
s4o.print("*("); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
235 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
236 |
else { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
237 |
switch (wanted_variablegeneration) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
238 |
case expression_vg: |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
239 |
s4o.print(GET_LOCATED); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
240 |
s4o.print("("); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
241 |
break; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
242 |
case fparam_output_vg: |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
243 |
s4o.print(GET_LOCATED_BY_REF); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
244 |
s4o.print("("); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
245 |
break; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
246 |
default: |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
247 |
break; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
248 |
} |
145 | 249 |
} |
70 | 250 |
this->print_variable_prefix(); |
251 |
s4o.printlocation(symbol->value + 1); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
252 |
if ((this->is_variable_prefix_null() && wanted_variablegeneration != fparam_output_vg) || |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
253 |
wanted_variablegeneration != assignment_vg) |
145 | 254 |
s4o.print(")"); |
70 | 255 |
return NULL; |
256 |
} |
|
257 |
||
98 | 258 |
/*************************************/ |
259 |
/* B.1.4.2 Multi-element Variables */ |
|
260 |
/*************************************/ |
|
261 |
||
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
220
diff
changeset
|
262 |
// SYM_REF2(structured_variable_c, record_variable, field_selector) |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
220
diff
changeset
|
263 |
void *visit(structured_variable_c *symbol) { |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
220
diff
changeset
|
264 |
TRACE("structured_variable_c"); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
265 |
switch (wanted_variablegeneration) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
266 |
case complextype_base_vg: |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
267 |
symbol->record_variable->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
268 |
break; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
269 |
case complextype_suffix_vg: |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
270 |
symbol->record_variable->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
271 |
s4o.print("."); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
272 |
symbol->field_selector->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
273 |
break; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
274 |
default: |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
275 |
if (this->is_variable_prefix_null()) { |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
220
diff
changeset
|
276 |
symbol->record_variable->accept(*this); |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
220
diff
changeset
|
277 |
s4o.print("."); |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
220
diff
changeset
|
278 |
symbol->field_selector->accept(*this); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
279 |
} |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
280 |
else |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
281 |
print_getter(symbol); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
282 |
break; |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
220
diff
changeset
|
283 |
} |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
220
diff
changeset
|
284 |
return NULL; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
220
diff
changeset
|
285 |
} |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
220
diff
changeset
|
286 |
|
98 | 287 |
/* subscripted_variable '[' subscript_list ']' */ |
288 |
//SYM_REF2(array_variable_c, subscripted_variable, subscript_list) |
|
289 |
void *visit(array_variable_c *symbol) { |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
290 |
switch (wanted_variablegeneration) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
291 |
case complextype_base_vg: |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
292 |
symbol->subscripted_variable->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
293 |
break; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
294 |
case complextype_suffix_vg: |
238
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
295 |
symbol->subscripted_variable->accept(*this); |
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
296 |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
297 |
current_array_type = search_varfb_instance_type->get_rawtype(symbol->subscripted_variable); |
238
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
298 |
if (current_array_type == NULL) ERROR; |
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
299 |
|
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
300 |
s4o.print(".table"); |
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
301 |
symbol->subscript_list->accept(*this); |
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
302 |
|
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
303 |
current_array_type = NULL; |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
304 |
break; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
305 |
default: |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
306 |
if (this->is_variable_prefix_null()) { |
238
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
307 |
symbol->subscripted_variable->accept(*this); |
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
308 |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
309 |
current_array_type = search_varfb_instance_type->get_rawtype(symbol->subscripted_variable); |
238
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
310 |
if (current_array_type == NULL) ERROR; |
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
311 |
|
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
312 |
s4o.print(".table"); |
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
313 |
symbol->subscript_list->accept(*this); |
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
314 |
|
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
315 |
current_array_type = NULL; |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
316 |
} |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
317 |
else |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
318 |
print_getter(symbol); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
319 |
break; |
98 | 320 |
} |
321 |
return NULL; |
|
322 |
} |
|
323 |
||
324 |
/* subscript_list ',' subscript */ |
|
325 |
void *visit(subscript_list_c *symbol) { |
|
326 |
for (int i = 0; i < symbol->n; i++) { |
|
327 |
s4o.print("[__"); |
|
328 |
current_array_type->accept(*this); |
|
329 |
s4o.print("_TRANSIDX"); |
|
330 |
print_integer(i); |
|
331 |
s4o.print("("); |
|
332 |
symbol->elements[i]->accept(*this); |
|
333 |
s4o.print(")]"); |
|
334 |
} |
|
335 |
return NULL; |
|
336 |
} |
|
337 |
||
235 | 338 |
/******************************************/ |
339 |
/* B 1.4.3 - Declaration & Initialisation */ |
|
340 |
/******************************************/ |
|
237 | 341 |
|
342 |
/* helper symbol for structure_initialization */ |
|
343 |
/* structure_element_initialization_list ',' structure_element_initialization */ |
|
235 | 344 |
void *visit(structure_element_initialization_list_c *symbol) { |
345 |
generate_c_structure_initialization_c *structure_initialization = new generate_c_structure_initialization_c(&s4o); |
|
346 |
structure_initialization->init_structure_default(this->current_param_type); |
|
237 | 347 |
structure_initialization->init_structure_values(symbol); |
235 | 348 |
delete structure_initialization; |
349 |
return NULL; |
|
350 |
} |
|
98 | 351 |
|
237 | 352 |
/* helper symbol for array_initialization */ |
353 |
/* array_initial_elements_list ',' array_initial_elements */ |
|
354 |
void *visit(array_initial_elements_list_c *symbol) { |
|
355 |
generate_c_array_initialization_c *array_initialization = new generate_c_array_initialization_c(&s4o); |
|
356 |
array_initialization->init_array_size(this->current_param_type); |
|
357 |
array_initialization->init_array_values(symbol); |
|
358 |
delete array_initialization; |
|
359 |
return NULL; |
|
360 |
} |
|
361 |
||
70 | 362 |
/***************************************/ |
363 |
/* B.3 - Language ST (Structured Text) */ |
|
364 |
/***************************************/ |
|
365 |
/***********************/ |
|
366 |
/* B 3.1 - Expressions */ |
|
367 |
/***********************/ |
|
368 |
void *visit(or_expression_c *symbol) { |
|
369 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
370 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
371 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
372 |
ERROR; |
|
373 |
if (search_expression_type->is_bool_type(left_type)) |
|
374 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " || "); |
|
375 |
if (search_expression_type->is_binary_type(left_type)) |
|
376 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " | "); |
|
377 |
ERROR; |
|
378 |
return NULL; |
|
379 |
} |
|
380 |
||
381 |
void *visit(xor_expression_c *symbol) { |
|
382 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
383 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
384 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
385 |
ERROR; |
|
386 |
if (search_expression_type->is_bool_type(left_type)) { |
|
387 |
s4o.print("("); |
|
388 |
symbol->l_exp->accept(*this); |
|
389 |
s4o.print(" && !"); |
|
390 |
symbol->r_exp->accept(*this); |
|
391 |
s4o.print(") || (!"); |
|
392 |
symbol->l_exp->accept(*this); |
|
393 |
s4o.print(" && "); |
|
394 |
symbol->r_exp->accept(*this); |
|
395 |
s4o.print(")"); |
|
130 | 396 |
return NULL; |
70 | 397 |
} |
398 |
if (search_expression_type->is_binary_type(left_type)) |
|
399 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " ^ "); |
|
400 |
ERROR; |
|
401 |
return NULL; |
|
402 |
} |
|
403 |
||
404 |
void *visit(and_expression_c *symbol) { |
|
405 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
406 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
407 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
408 |
ERROR; |
|
409 |
if (search_expression_type->is_bool_type(left_type)) |
|
410 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " && "); |
|
411 |
if (search_expression_type->is_binary_type(left_type)) |
|
412 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " & "); |
|
413 |
ERROR; |
|
414 |
return NULL; |
|
415 |
} |
|
416 |
||
417 |
void *visit(equ_expression_c *symbol) { |
|
418 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
419 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
420 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
421 |
ERROR; |
|
123 | 422 |
if (search_expression_type->is_time_type(left_type) || |
423 |
search_expression_type->is_string_type(left_type)) |
|
70 | 424 |
return print_compare_function("__eq_", left_type, symbol->l_exp, symbol->r_exp); |
425 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " == "); |
|
426 |
} |
|
427 |
||
428 |
void *visit(notequ_expression_c *symbol) { |
|
429 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
430 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
431 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
432 |
ERROR; |
|
123 | 433 |
if (search_expression_type->is_time_type(left_type) || |
434 |
search_expression_type->is_string_type(left_type)) |
|
70 | 435 |
return print_compare_function("__ne_", left_type, symbol->l_exp, symbol->r_exp); |
436 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " != "); |
|
437 |
} |
|
438 |
||
439 |
void *visit(lt_expression_c *symbol) { |
|
440 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
441 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
442 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
443 |
ERROR; |
|
123 | 444 |
if (search_expression_type->is_time_type(left_type) || |
445 |
search_expression_type->is_string_type(left_type)) |
|
70 | 446 |
return print_compare_function("__lt_", left_type, symbol->l_exp, symbol->r_exp); |
123 | 447 |
if (!search_base_type.type_is_enumerated(left_type)) |
448 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " < "); |
|
449 |
ERROR; |
|
450 |
return NULL; |
|
70 | 451 |
} |
452 |
||
453 |
void *visit(gt_expression_c *symbol) { |
|
454 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
455 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
456 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
457 |
ERROR; |
|
123 | 458 |
if (search_expression_type->is_time_type(left_type) || |
459 |
search_expression_type->is_string_type(left_type)) |
|
70 | 460 |
return print_compare_function("__gt_", left_type, symbol->l_exp, symbol->r_exp); |
123 | 461 |
if (!search_base_type.type_is_enumerated(left_type)) |
462 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " > "); |
|
463 |
ERROR; |
|
464 |
return NULL; |
|
70 | 465 |
} |
466 |
||
467 |
void *visit(le_expression_c *symbol) { |
|
468 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
469 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
470 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
471 |
ERROR; |
|
123 | 472 |
if (search_expression_type->is_time_type(left_type) || |
473 |
search_expression_type->is_string_type(left_type)) |
|
70 | 474 |
return print_compare_function("__le_", left_type, symbol->l_exp, symbol->r_exp); |
123 | 475 |
if (!search_base_type.type_is_enumerated(left_type)) |
476 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " <= "); |
|
477 |
ERROR; |
|
478 |
return NULL; |
|
70 | 479 |
} |
480 |
||
481 |
void *visit(ge_expression_c *symbol) { |
|
482 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
483 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
484 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
485 |
ERROR; |
|
123 | 486 |
if (search_expression_type->is_time_type(left_type) || |
487 |
search_expression_type->is_string_type(left_type)) |
|
70 | 488 |
return print_compare_function("__ge_", left_type, symbol->l_exp, symbol->r_exp); |
123 | 489 |
if (!search_base_type.type_is_enumerated(left_type)) |
490 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " >= "); |
|
491 |
ERROR; |
|
492 |
return NULL; |
|
70 | 493 |
} |
494 |
||
495 |
void *visit(add_expression_c *symbol) { |
|
496 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
497 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
498 |
if ((typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
|
499 |
(typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
|
500 |
(typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c))) |
|
149 | 501 |
return print_binary_function("__TIME_ADD", symbol->l_exp, symbol->r_exp); |
70 | 502 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
503 |
ERROR; |
|
504 |
if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) |
|
505 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " + "); |
|
506 |
ERROR; |
|
507 |
return NULL; |
|
508 |
} |
|
509 |
||
510 |
void *visit(sub_expression_c *symbol) { |
|
511 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
512 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
513 |
if ((typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
|
514 |
(typeid(*left_type) == typeid(date_type_name_c) && typeid(*right_type) == typeid(date_type_name_c)) || |
|
515 |
(typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
|
516 |
(typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(tod_type_name_c)) || |
|
517 |
(typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
|
518 |
(typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(dt_type_name_c))) |
|
149 | 519 |
return print_binary_function("__TIME_SUB", symbol->l_exp, symbol->r_exp); |
70 | 520 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
521 |
ERROR; |
|
522 |
if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) |
|
523 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " - "); |
|
524 |
ERROR; |
|
525 |
return NULL; |
|
526 |
} |
|
527 |
||
528 |
void *visit(mul_expression_c *symbol) { |
|
529 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
530 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
531 |
if ((typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_integer_type(right_type)) || |
|
532 |
(typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_real_type(right_type))) |
|
149 | 533 |
return print_binary_function("__TIME_MUL", symbol->l_exp, symbol->r_exp); |
70 | 534 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
535 |
ERROR; |
|
536 |
if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) |
|
537 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " * "); |
|
538 |
ERROR; |
|
539 |
return NULL; |
|
540 |
} |
|
541 |
||
542 |
void *visit(div_expression_c *symbol) { |
|
543 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
544 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
149 | 545 |
if ((typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_integer_type(right_type)) || |
546 |
(typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_real_type(right_type))) |
|
547 |
return print_binary_function("__TIME_DIV", symbol->l_exp, symbol->r_exp); |
|
70 | 548 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
549 |
ERROR; |
|
550 |
if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) |
|
551 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " / "); |
|
552 |
ERROR; |
|
553 |
return NULL; |
|
554 |
} |
|
555 |
||
556 |
void *visit(mod_expression_c *symbol) { |
|
557 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
558 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
559 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
560 |
ERROR; |
|
561 |
if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) { |
|
562 |
s4o.print("(("); |
|
563 |
symbol->r_exp->accept(*this); |
|
564 |
s4o.print(" == 0)?0:"); |
|
565 |
print_binary_expression(symbol->l_exp, symbol->r_exp, " % "); |
|
566 |
s4o.print(")"); |
|
567 |
return NULL; |
|
568 |
} |
|
569 |
ERROR; |
|
570 |
return NULL; |
|
571 |
} |
|
572 |
||
573 |
/* TODO: power expression... */ |
|
574 |
void *visit(power_expression_c *symbol) {ERROR; return print_binary_expression(symbol->l_exp, symbol->r_exp, " ** ");} |
|
123 | 575 |
void *visit(neg_expression_c *symbol) { |
576 |
symbol_c *exp_type = search_expression_type->get_type(symbol->exp); |
|
577 |
if (search_expression_type->is_integer_type(exp_type) || search_expression_type->is_real_type(exp_type)) |
|
578 |
return print_unary_expression(symbol->exp, " -"); |
|
579 |
ERROR; |
|
580 |
return NULL; |
|
581 |
} |
|
70 | 582 |
|
583 |
void *visit(not_expression_c *symbol) { |
|
584 |
symbol_c *exp_type = search_expression_type->get_type(symbol->exp); |
|
123 | 585 |
if (search_expression_type->is_binary_type(exp_type)) |
586 |
return print_unary_expression(symbol->exp, search_expression_type->is_bool_type(exp_type)?"!":"~"); |
|
587 |
ERROR; |
|
588 |
return NULL; |
|
70 | 589 |
} |
590 |
||
591 |
void *visit(function_invocation_c *symbol) { |
|
149 | 592 |
symbol_c* function_type_prefix = NULL; |
593 |
symbol_c* function_name = NULL; |
|
594 |
symbol_c* function_type_suffix = NULL; |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
595 |
DECLARE_PARAM_LIST() |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
596 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
597 |
symbol_c *parameter_assignment_list = NULL; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
598 |
if (NULL != symbol-> formal_param_list) parameter_assignment_list = symbol-> formal_param_list; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
599 |
if (NULL != symbol->nonformal_param_list) parameter_assignment_list = symbol->nonformal_param_list; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
600 |
if (NULL == parameter_assignment_list) ERROR; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
601 |
|
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
602 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
603 |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
604 |
function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
70 | 605 |
if (f_decl == function_symtable.end_value()) { |
606 |
/* The function called is not in the symtable, so we test if it is a |
|
607 |
* standard function defined in standard */ |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
608 |
|
70 | 609 |
function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
610 |
if (current_function_type == function_none) ERROR; |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
611 |
|
70 | 612 |
symbol_c *function_return_type = search_expression_type->get_type(symbol); |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
613 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
614 |
int nb_param = ((list_c *)parameter_assignment_list)->n; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
615 |
|
235 | 616 |
symbol_c *en_param_name = (symbol_c *)(new identifier_c("EN")); |
149 | 617 |
/* Get the value from EN param */ |
235 | 618 |
symbol_c *EN_param_value = function_call_param_iterator.search_f(en_param_name); |
149 | 619 |
if (EN_param_value == NULL) |
620 |
EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())); |
|
167
ae423926bc84
Fixed parameter count error on variadic functions with EN/ENO
etisserant
parents:
162
diff
changeset
|
621 |
else |
ae423926bc84
Fixed parameter count error on variadic functions with EN/ENO
etisserant
parents:
162
diff
changeset
|
622 |
nb_param --; |
235 | 623 |
ADD_PARAM_LIST(en_param_name, EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in) |
624 |
||
625 |
symbol_c *eno_param_name = (symbol_c *)(new identifier_c("ENO")); |
|
149 | 626 |
/* Get the value from ENO param */ |
235 | 627 |
symbol_c *ENO_param_value = function_call_param_iterator.search_f(eno_param_name); |
167
ae423926bc84
Fixed parameter count error on variadic functions with EN/ENO
etisserant
parents:
162
diff
changeset
|
628 |
if (ENO_param_value != NULL) |
ae423926bc84
Fixed parameter count error on variadic functions with EN/ENO
etisserant
parents:
162
diff
changeset
|
629 |
nb_param --; |
235 | 630 |
ADD_PARAM_LIST(eno_param_name, ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
631 |
|
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
632 |
#include "st_code_gen.c" |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
633 |
|
70 | 634 |
} |
635 |
else { |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
636 |
function_name = symbol->function_name; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
637 |
|
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
638 |
/* loop through each function parameter, find the value we should pass |
70 | 639 |
* to it, and then output the c equivalent... |
640 |
*/ |
|
641 |
function_param_iterator_c fp_iterator(f_decl); |
|
642 |
identifier_c *param_name; |
|
643 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
149 | 644 |
|
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
645 |
symbol_c *param_type = fp_iterator.param_type(); |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
646 |
if (param_type == NULL) ERROR; |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
647 |
|
70 | 648 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
149 | 649 |
|
70 | 650 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
651 |
symbol_c *param_value = function_call_param_iterator.search_f(param_name); |
70 | 652 |
|
653 |
/* Get the value from a foo(<param_value>) style call */ |
|
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
654 |
if (param_value == NULL) { |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
655 |
param_value = function_call_param_iterator.next_nf(); |
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
656 |
if (param_value != NULL && fp_iterator.is_en_eno_param_implicit()) ERROR; |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
657 |
} |
149 | 658 |
|
659 |
if (param_value == NULL && param_direction == function_param_iterator_c::direction_in) { |
|
660 |
/* No value given for parameter, so we must use the default... */ |
|
661 |
/* First check whether default value specified in function declaration...*/ |
|
662 |
param_value = fp_iterator.default_value(); |
|
663 |
} |
|
664 |
||
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
665 |
ADD_PARAM_LIST(param_name, param_value, param_type, param_direction) |
70 | 666 |
} /* for(...) */ |
667 |
// symbol->parameter_assignment->accept(*this); |
|
149 | 668 |
} |
669 |
||
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
670 |
if (function_call_param_iterator.next_nf() != NULL) ERROR; |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
671 |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
672 |
bool has_output_params = false; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
673 |
|
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
674 |
if (!this->is_variable_prefix_null()) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
675 |
PARAM_LIST_ITERATOR() { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
676 |
if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
677 |
PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
678 |
PARAM_VALUE != NULL) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
679 |
if (!has_output_params) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
680 |
has_output_params = true; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
681 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
682 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
683 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
684 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
685 |
|
149 | 686 |
if (function_type_prefix != NULL) { |
687 |
s4o.print("("); |
|
688 |
function_type_prefix->accept(*this); |
|
70 | 689 |
s4o.print(")"); |
149 | 690 |
} |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
691 |
if (has_output_params) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
692 |
fcall_number++; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
693 |
s4o.print("__"); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
694 |
fbname->accept(*this); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
695 |
s4o.print("_"); |
149 | 696 |
function_name->accept(*this); |
235 | 697 |
if (function_type_suffix != NULL) |
698 |
function_type_suffix->accept(*this); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
699 |
s4o.print_integer(fcall_number); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
700 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
701 |
else { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
702 |
function_name->accept(*this); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
703 |
if (function_type_suffix != NULL) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
704 |
function_type_suffix->accept(*this); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
705 |
} |
149 | 706 |
s4o.print("("); |
707 |
s4o.indent_right(); |
|
708 |
||
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
709 |
int nb_param = 0; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
710 |
PARAM_LIST_ITERATOR() { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
711 |
symbol_c *param_value = PARAM_VALUE; |
235 | 712 |
current_param_type = PARAM_TYPE; |
149 | 713 |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
714 |
switch (PARAM_DIRECTION) { |
149 | 715 |
case function_param_iterator_c::direction_in: |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
716 |
if (nb_param > 0) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
717 |
s4o.print(",\n"+s4o.indent_spaces); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
718 |
if (param_value == NULL) { |
149 | 719 |
/* If not, get the default value of this variable's type */ |
235 | 720 |
param_value = (symbol_c *)current_param_type->accept(*type_initial_value_c::instance()); |
149 | 721 |
} |
722 |
if (param_value == NULL) ERROR; |
|
216
136d6ae70745
Bug with using non explicit literals as standard library functions input parameters fixed
laurent
parents:
208
diff
changeset
|
723 |
s4o.print("("); |
235 | 724 |
if (search_expression_type->is_literal_integer_type(current_param_type)) |
220 | 725 |
search_expression_type->lint_type_name.accept(*this); |
235 | 726 |
else if (search_expression_type->is_literal_real_type(current_param_type)) |
220 | 727 |
search_expression_type->lreal_type_name.accept(*this); |
216
136d6ae70745
Bug with using non explicit literals as standard library functions input parameters fixed
laurent
parents:
208
diff
changeset
|
728 |
else |
235 | 729 |
current_param_type->accept(*this); |
216
136d6ae70745
Bug with using non explicit literals as standard library functions input parameters fixed
laurent
parents:
208
diff
changeset
|
730 |
s4o.print(")"); |
235 | 731 |
print_check_function(current_param_type, param_value); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
732 |
nb_param++; |
149 | 733 |
break; |
734 |
case function_param_iterator_c::direction_out: |
|
735 |
case function_param_iterator_c::direction_inout: |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
736 |
if (!has_output_params) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
737 |
if (nb_param > 0) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
738 |
s4o.print(",\n"+s4o.indent_spaces); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
739 |
if (param_value == NULL) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
740 |
s4o.print("NULL"); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
741 |
else { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
742 |
wanted_variablegeneration = fparam_output_vg; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
743 |
param_value->accept(*this); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
744 |
wanted_variablegeneration = expression_vg; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
745 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
746 |
nb_param++; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
747 |
} |
149 | 748 |
break; |
749 |
case function_param_iterator_c::direction_extref: |
|
750 |
/* TODO! */ |
|
751 |
ERROR; |
|
752 |
break; |
|
753 |
} /* switch */ |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
754 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
755 |
if (has_output_params) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
756 |
if (nb_param > 0) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
757 |
s4o.print(",\n"+s4o.indent_spaces); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
758 |
s4o.print(FB_FUNCTION_PARAM); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
759 |
} |
149 | 760 |
s4o.print(")"); |
761 |
s4o.indent_left(); |
|
70 | 762 |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
763 |
CLEAR_PARAM_LIST() |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
764 |
|
70 | 765 |
return NULL; |
766 |
} |
|
767 |
||
768 |
/********************/ |
|
769 |
/* B 3.2 Statements */ |
|
770 |
/********************/ |
|
771 |
void *visit(statement_list_c *symbol) { |
|
772 |
return print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); |
|
773 |
} |
|
774 |
||
775 |
/*********************************/ |
|
776 |
/* B 3.2.1 Assignment Statements */ |
|
777 |
/*********************************/ |
|
778 |
void *visit(assignment_statement_c *symbol) { |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
779 |
symbol_c *left_type = search_varfb_instance_type->get_rawtype(symbol->l_exp); |
98 | 780 |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
781 |
if (this->is_variable_prefix_null()) { |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
782 |
symbol->l_exp->accept(*this); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
783 |
s4o.print(" = "); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
784 |
print_check_function(left_type, symbol->r_exp); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
785 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
786 |
else { |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
787 |
print_setter(symbol->l_exp, left_type, symbol->r_exp); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
788 |
} |
70 | 789 |
return NULL; |
790 |
} |
|
791 |
||
792 |
/*****************************************/ |
|
793 |
/* B 3.2.2 Subprogram Control Statements */ |
|
794 |
/*****************************************/ |
|
795 |
||
796 |
/* fb_name '(' [param_assignment_list] ')' */ |
|
797 |
/* param_assignment_list -> may be NULL ! */ |
|
798 |
//SYM_REF2(fb_invocation_c, fb_name, param_assignment_list) |
|
799 |
void *visit(fb_invocation_c *symbol) { |
|
800 |
TRACE("fb_invocation_c"); |
|
801 |
/* first figure out what is the name of the function block type of the function block being called... */ |
|
802 |
symbol_c *function_block_type_name = this->search_fb_instance_decl->get_type_name(symbol->fb_name); |
|
803 |
/* should never occur. The function block instance MUST have been declared... */ |
|
804 |
if (function_block_type_name == NULL) ERROR; |
|
805 |
||
806 |
/* Now find the declaration of the function block type being called... */ |
|
807 |
function_block_declaration_c *fb_decl = function_block_type_symtable.find_value(function_block_type_name); |
|
808 |
/* should never occur. The function block type being called MUST be in the symtable... */ |
|
809 |
if (fb_decl == function_block_type_symtable.end_value()) ERROR; |
|
810 |
||
811 |
/* loop through each function block parameter, find the value we should pass |
|
812 |
* to it, and then output the c equivalent... |
|
813 |
*/ |
|
814 |
function_param_iterator_c fp_iterator(fb_decl); |
|
815 |
identifier_c *param_name; |
|
816 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
817 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
818 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
160 | 819 |
|
162
60a124678842
Fixed typo in EN/ENO parameters handling for std library functions
etisserant
parents:
160
diff
changeset
|
820 |
/*fprintf(stderr, "param : %s\n", param_name->value);*/ |
160 | 821 |
|
70 | 822 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
823 |
symbol_c *param_value = function_call_param_iterator.search_f(param_name); |
70 | 824 |
|
825 |
/* Get the value from a foo(<param_value>) style call */ |
|
826 |
if (param_value == NULL) |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
827 |
param_value = function_call_param_iterator.next_nf(); |
70 | 828 |
|
98 | 829 |
symbol_c *param_type = fp_iterator.param_type(); |
830 |
if (param_type == NULL) ERROR; |
|
831 |
||
70 | 832 |
/* now output the value assignment */ |
833 |
if (param_value != NULL) |
|
834 |
if ((param_direction == function_param_iterator_c::direction_in) || |
|
835 |
(param_direction == function_param_iterator_c::direction_inout)) { |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
836 |
if (this->is_variable_prefix_null()) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
837 |
symbol->fb_name->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
838 |
s4o.print("."); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
839 |
param_name->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
840 |
s4o.print(" = "); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
841 |
print_check_function(param_type, param_value); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
842 |
} |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
843 |
else { |
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
226
diff
changeset
|
844 |
print_setter(param_name, param_type, param_value, symbol->fb_name); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
845 |
} |
70 | 846 |
s4o.print(";\n" + s4o.indent_spaces); |
847 |
} |
|
848 |
} /* for(...) */ |
|
849 |
||
850 |
/* now call the function... */ |
|
851 |
function_block_type_name->accept(*this); |
|
852 |
s4o.print(FB_FUNCTION_SUFFIX); |
|
853 |
s4o.print("(&"); |
|
854 |
print_variable_prefix(); |
|
855 |
symbol->fb_name->accept(*this); |
|
856 |
s4o.print(")"); |
|
857 |
||
858 |
/* loop through each function parameter, find the variable to which |
|
859 |
* we should atribute the value of all output or inoutput parameters. |
|
860 |
*/ |
|
861 |
fp_iterator.reset(); |
|
862 |
function_call_param_iterator.reset(); |
|
863 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
864 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
865 |
||
866 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
867 |
symbol_c *param_value = function_call_param_iterator.search_f(param_name); |
70 | 868 |
|
869 |
/* Get the value from a foo(<param_value>) style call */ |
|
870 |
if (param_value == NULL) |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
871 |
param_value = function_call_param_iterator.next_nf(); |
70 | 872 |
|
873 |
/* now output the value assignment */ |
|
874 |
if (param_value != NULL) |
|
875 |
if ((param_direction == function_param_iterator_c::direction_out) || |
|
876 |
(param_direction == function_param_iterator_c::direction_inout)) { |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
877 |
symbol_c *param_type = search_varfb_instance_type->get_rawtype(param_value); |
240 | 878 |
s4o.print(";\n" + s4o.indent_spaces); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
879 |
if (this->is_variable_prefix_null()) { |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
880 |
param_value->accept(*this); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
881 |
s4o.print(" = "); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
882 |
print_check_function(param_type, param_name, symbol->fb_name); |
98 | 883 |
} |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
884 |
else { |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
885 |
print_setter(param_value, param_type, param_name, NULL, symbol->fb_name); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
886 |
} |
70 | 887 |
} |
888 |
} /* for(...) */ |
|
889 |
||
890 |
return NULL; |
|
891 |
} |
|
892 |
||
893 |
||
894 |
||
895 |
||
896 |
/* helper symbol for fb_invocation */ |
|
897 |
/* param_assignment_list ',' param_assignment */ |
|
898 |
void *visit(param_assignment_list_c *symbol) { |
|
899 |
TRACE("param_assignment_list_c"); |
|
900 |
/* this should never be called... */ |
|
901 |
ERROR; |
|
902 |
return NULL; |
|
903 |
// return print_list(symbol, "", ", "); |
|
904 |
} |
|
905 |
||
906 |
||
907 |
void *visit(input_variable_param_assignment_c *symbol) { |
|
908 |
TRACE("input_variable_param_assignment_c"); |
|
909 |
/* this should never be called... */ |
|
910 |
ERROR; |
|
911 |
return NULL; |
|
912 |
/* |
|
913 |
symbol->variable_name->accept(*this); |
|
914 |
s4o.print(" = "); |
|
915 |
symbol->expression->accept(*this); |
|
916 |
return NULL; |
|
917 |
*/ |
|
918 |
} |
|
919 |
||
920 |
void *visit(output_variable_param_assignment_c *symbol) { |
|
921 |
TRACE("output_variable_param_assignment_c"); |
|
922 |
/* this should never be called... */ |
|
923 |
ERROR; |
|
924 |
return NULL; |
|
925 |
/* |
|
926 |
s4o.print(s4o.indent_spaces); |
|
927 |
if (symbol->not_param != NULL) |
|
928 |
symbol->not_param->accept(*this); |
|
929 |
symbol->variable_name->accept(*this); |
|
930 |
s4o.print(" => "); |
|
931 |
symbol->variable->accept(*this); |
|
932 |
return NULL; |
|
933 |
*/ |
|
934 |
} |
|
935 |
||
936 |
// TODO: the NOT symbol in function (block) calls... |
|
937 |
void *visit(not_paramassign_c *symbol) { |
|
938 |
TRACE("not_paramassign_c"); |
|
939 |
/* this should never be called... */ |
|
940 |
ERROR; |
|
941 |
return NULL; |
|
942 |
/* |
|
943 |
s4o.print("NOT "); |
|
944 |
return NULL; |
|
945 |
*/ |
|
946 |
} |
|
947 |
||
948 |
||
949 |
/********************************/ |
|
950 |
/* B 3.2.3 Selection Statements */ |
|
951 |
/********************************/ |
|
952 |
void *visit(if_statement_c *symbol) { |
|
953 |
s4o.print("if ("); |
|
954 |
symbol->expression->accept(*this); |
|
955 |
s4o.print(") {\n"); |
|
956 |
s4o.indent_right(); |
|
957 |
symbol->statement_list->accept(*this); |
|
958 |
s4o.indent_left(); |
|
959 |
symbol->elseif_statement_list->accept(*this); |
|
960 |
||
961 |
if (symbol->else_statement_list != NULL) { |
|
962 |
s4o.print(s4o.indent_spaces); s4o.print("} else {\n"); |
|
963 |
s4o.indent_right(); |
|
964 |
symbol->else_statement_list->accept(*this); |
|
965 |
s4o.indent_left(); |
|
966 |
} |
|
967 |
s4o.print(s4o.indent_spaces); s4o.print("}"); |
|
968 |
return NULL; |
|
969 |
} |
|
970 |
||
971 |
/* helper symbol for if_statement */ |
|
972 |
void *visit(elseif_statement_list_c *symbol) {return print_list(symbol);} |
|
973 |
||
974 |
/* helper symbol for elseif_statement_list */ |
|
975 |
void *visit(elseif_statement_c *symbol) { |
|
976 |
s4o.print(s4o.indent_spaces); s4o.print("} else if ("); |
|
977 |
symbol->expression->accept(*this); |
|
978 |
s4o.print(") {\n"); |
|
979 |
s4o.indent_right(); |
|
980 |
symbol->statement_list->accept(*this); |
|
981 |
s4o.indent_left(); |
|
982 |
return NULL; |
|
983 |
} |
|
984 |
||
985 |
void *visit(case_statement_c *symbol) { |
|
986 |
s4o.print("switch("); |
|
987 |
symbol->expression->accept(*this); |
|
988 |
s4o.print(") {\n"); |
|
989 |
s4o.indent_right(); |
|
990 |
symbol->case_element_list->accept(*this); |
|
991 |
if (symbol->statement_list != NULL) { |
|
992 |
s4o.print(s4o.indent_spaces + "default:\n"); |
|
993 |
s4o.indent_right(); |
|
994 |
symbol->statement_list->accept(*this); |
|
995 |
s4o.print(s4o.indent_spaces + "break;\n"); |
|
996 |
s4o.indent_left(); |
|
997 |
} |
|
998 |
s4o.indent_left(); |
|
999 |
s4o.print(s4o.indent_spaces + "}"); |
|
1000 |
return NULL; |
|
1001 |
} |
|
1002 |
||
1003 |
/* helper symbol for case_statement */ |
|
1004 |
void *visit(case_element_list_c *symbol) {return print_list(symbol);} |
|
1005 |
||
1006 |
void *visit(case_element_c *symbol) { |
|
1007 |
s4o.print(s4o.indent_spaces + "case "); |
|
1008 |
symbol->case_list->accept(*this); |
|
1009 |
s4o.print(" :\n"); |
|
1010 |
s4o.indent_right(); |
|
1011 |
symbol->statement_list->accept(*this); |
|
1012 |
s4o.print(s4o.indent_spaces + "break;\n"); |
|
1013 |
s4o.indent_left(); |
|
1014 |
return NULL; |
|
1015 |
} |
|
1016 |
||
1017 |
void *visit(case_list_c *symbol) {return print_list(symbol, "", ", ");} |
|
1018 |
||
1019 |
/********************************/ |
|
1020 |
/* B 3.2.4 Iteration Statements */ |
|
1021 |
/********************************/ |
|
1022 |
void *visit(for_statement_c *symbol) { |
|
1023 |
s4o.print("for("); |
|
1024 |
symbol->control_variable->accept(*this); |
|
1025 |
s4o.print(" = "); |
|
1026 |
symbol->beg_expression->accept(*this); |
|
1027 |
s4o.print("; "); |
|
1028 |
symbol->control_variable->accept(*this); |
|
1029 |
s4o.print(" != "); |
|
1030 |
symbol->end_expression->accept(*this); |
|
1031 |
s4o.print("; "); |
|
1032 |
symbol->control_variable->accept(*this); |
|
1033 |
if (symbol->by_expression != NULL) { |
|
1034 |
s4o.print(" += "); |
|
1035 |
symbol->by_expression->accept(*this); |
|
1036 |
} else { |
|
1037 |
s4o.print("++"); |
|
1038 |
} |
|
1039 |
s4o.print(") {\n"); |
|
1040 |
s4o.indent_right(); |
|
1041 |
symbol->statement_list->accept(*this); |
|
1042 |
s4o.indent_left(); |
|
1043 |
s4o.print(s4o.indent_spaces); s4o.print("}"); |
|
1044 |
return NULL; |
|
1045 |
} |
|
1046 |
void *visit(while_statement_c *symbol) { |
|
1047 |
s4o.print("while ("); |
|
1048 |
symbol->expression->accept(*this); |
|
1049 |
s4o.print(") {\n"); |
|
1050 |
s4o.indent_right(); |
|
1051 |
symbol->statement_list->accept(*this); |
|
1052 |
s4o.indent_left(); |
|
1053 |
s4o.print(s4o.indent_spaces); s4o.print("}"); |
|
1054 |
return NULL; |
|
1055 |
} |
|
1056 |
void *visit(repeat_statement_c *symbol) { |
|
1057 |
s4o.print("do {\n"); |
|
1058 |
s4o.indent_right(); |
|
1059 |
symbol->statement_list->accept(*this); |
|
1060 |
s4o.indent_left(); |
|
1061 |
s4o.print(s4o.indent_spaces); s4o.print("} while("); |
|
1062 |
symbol->expression->accept(*this); |
|
1063 |
s4o.print(")"); |
|
1064 |
return NULL; |
|
1065 |
} |
|
1066 |
void *visit(exit_statement_c *symbol) { |
|
1067 |
s4o.print("exit(0)"); |
|
1068 |
return NULL; |
|
1069 |
} |
|
1070 |
||
1071 |
||
1072 |
||
1073 |
}; /* generate_c_st_c */ |
|
1074 |
||
1075 |
||
1076 |
||
1077 |
||
1078 |
||
1079 |
||
1080 |
||
1081 |
||
1082 |