author | laurent |
Tue, 15 Dec 2009 08:51:44 +0100 | |
changeset 235 | ed66dc50f31a |
parent 233 | 3d23a68183d3 |
child 236 | c55b02ca2342 |
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) { |
235 | 211 |
if (vartype == search_var_instance_decl_c::inoutput_vt) |
212 |
generate_c_base_c::visit(symbol); |
|
213 |
else { |
|
214 |
s4o.print("&("); |
|
215 |
generate_c_base_c::visit(symbol); |
|
216 |
s4o.print(")"); |
|
217 |
} |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
218 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
219 |
else { |
235 | 220 |
if (vartype == search_var_instance_decl_c::inoutput_vt) { |
221 |
s4o.print("(*"); |
|
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
|
222 |
generate_c_base_c::visit(symbol); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
223 |
s4o.print(")"); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
224 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
225 |
else |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
226 |
generate_c_base_c::visit(symbol); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
227 |
} |
145 | 228 |
} |
235 | 229 |
else |
230 |
print_getter(symbol); |
|
70 | 231 |
return NULL; |
232 |
} |
|
233 |
||
234 |
/********************************************/ |
|
235 |
/* B.1.4.1 Directly Represented Variables */ |
|
236 |
/********************************************/ |
|
237 |
// direct_variable: direct_variable_token {$$ = new direct_variable_c($1);}; |
|
238 |
void *visit(direct_variable_c *symbol) { |
|
239 |
TRACE("direct_variable_c"); |
|
240 |
/* Do not use print_token() as it will change everything into uppercase */ |
|
241 |
if (strlen(symbol->value) == 0) ERROR; |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
242 |
if (this->is_variable_prefix_null()) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
243 |
if (wanted_variablegeneration != fparam_output_vg) |
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 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
246 |
else { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
247 |
switch (wanted_variablegeneration) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
248 |
case expression_vg: |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
249 |
s4o.print(GET_LOCATED); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
250 |
s4o.print("("); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
251 |
break; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
252 |
case fparam_output_vg: |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
253 |
s4o.print(GET_LOCATED_BY_REF); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
254 |
s4o.print("("); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
255 |
break; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
256 |
default: |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
257 |
break; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
258 |
} |
145 | 259 |
} |
70 | 260 |
this->print_variable_prefix(); |
261 |
s4o.printlocation(symbol->value + 1); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
262 |
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
|
263 |
wanted_variablegeneration != assignment_vg) |
145 | 264 |
s4o.print(")"); |
70 | 265 |
return NULL; |
266 |
} |
|
267 |
||
98 | 268 |
/*************************************/ |
269 |
/* B.1.4.2 Multi-element Variables */ |
|
270 |
/*************************************/ |
|
271 |
||
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
|
272 |
// 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
|
273 |
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
|
274 |
TRACE("structured_variable_c"); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
275 |
switch (wanted_variablegeneration) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
276 |
case complextype_base_vg: |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
277 |
symbol->record_variable->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
278 |
break; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
279 |
case complextype_suffix_vg: |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
280 |
symbol->record_variable->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
281 |
s4o.print("."); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
282 |
symbol->field_selector->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
283 |
break; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
284 |
default: |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
285 |
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
|
286 |
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
|
287 |
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
|
288 |
symbol->field_selector->accept(*this); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
289 |
} |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
290 |
else |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
291 |
print_getter(symbol); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
292 |
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
|
293 |
} |
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
|
294 |
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
|
295 |
} |
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
|
296 |
|
98 | 297 |
/* subscripted_variable '[' subscript_list ']' */ |
298 |
//SYM_REF2(array_variable_c, subscripted_variable, subscript_list) |
|
299 |
void *visit(array_variable_c *symbol) { |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
300 |
switch (wanted_variablegeneration) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
301 |
case complextype_base_vg: |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
302 |
symbol->subscripted_variable->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
303 |
break; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
304 |
case complextype_suffix_vg: |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
305 |
current_array_type = search_varfb_instance_type->get_rawtype(symbol->subscripted_variable); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
306 |
symbol->subscripted_variable->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
307 |
if (current_array_type != NULL) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
308 |
symbol->subscript_list->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
309 |
current_array_type = NULL; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
310 |
} |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
311 |
break; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
312 |
default: |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
313 |
if (this->is_variable_prefix_null()) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
314 |
current_array_type = search_varfb_instance_type->get_rawtype(symbol->subscripted_variable); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
315 |
symbol->subscripted_variable->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
316 |
if (current_array_type != NULL) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
317 |
symbol->subscript_list->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
318 |
current_array_type = NULL; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
319 |
} |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
320 |
} |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
321 |
else |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
322 |
print_getter(symbol); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
323 |
break; |
98 | 324 |
} |
325 |
return NULL; |
|
326 |
} |
|
327 |
||
328 |
/* subscript_list ',' subscript */ |
|
329 |
void *visit(subscript_list_c *symbol) { |
|
330 |
for (int i = 0; i < symbol->n; i++) { |
|
331 |
s4o.print("[__"); |
|
332 |
current_array_type->accept(*this); |
|
333 |
s4o.print("_TRANSIDX"); |
|
334 |
print_integer(i); |
|
335 |
s4o.print("("); |
|
336 |
symbol->elements[i]->accept(*this); |
|
337 |
s4o.print(")]"); |
|
338 |
} |
|
339 |
return NULL; |
|
340 |
} |
|
341 |
||
235 | 342 |
/******************************************/ |
343 |
/* B 1.4.3 - Declaration & Initialisation */ |
|
344 |
/******************************************/ |
|
345 |
void *visit(structure_element_initialization_list_c *symbol) { |
|
346 |
generate_c_structure_initialization_c *structure_initialization = new generate_c_structure_initialization_c(&s4o); |
|
347 |
structure_initialization->init_structure_default(this->current_param_type); |
|
348 |
structure_initialization->current_mode = generate_c_structure_initialization_c::initializationvalue_sm; |
|
349 |
symbol->accept(*structure_initialization); |
|
350 |
delete structure_initialization; |
|
351 |
return NULL; |
|
352 |
} |
|
98 | 353 |
|
70 | 354 |
/***************************************/ |
355 |
/* B.3 - Language ST (Structured Text) */ |
|
356 |
/***************************************/ |
|
357 |
/***********************/ |
|
358 |
/* B 3.1 - Expressions */ |
|
359 |
/***********************/ |
|
360 |
void *visit(or_expression_c *symbol) { |
|
361 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
362 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
363 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
364 |
ERROR; |
|
365 |
if (search_expression_type->is_bool_type(left_type)) |
|
366 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " || "); |
|
367 |
if (search_expression_type->is_binary_type(left_type)) |
|
368 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " | "); |
|
369 |
ERROR; |
|
370 |
return NULL; |
|
371 |
} |
|
372 |
||
373 |
void *visit(xor_expression_c *symbol) { |
|
374 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
375 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
376 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
377 |
ERROR; |
|
378 |
if (search_expression_type->is_bool_type(left_type)) { |
|
379 |
s4o.print("("); |
|
380 |
symbol->l_exp->accept(*this); |
|
381 |
s4o.print(" && !"); |
|
382 |
symbol->r_exp->accept(*this); |
|
383 |
s4o.print(") || (!"); |
|
384 |
symbol->l_exp->accept(*this); |
|
385 |
s4o.print(" && "); |
|
386 |
symbol->r_exp->accept(*this); |
|
387 |
s4o.print(")"); |
|
130 | 388 |
return NULL; |
70 | 389 |
} |
390 |
if (search_expression_type->is_binary_type(left_type)) |
|
391 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " ^ "); |
|
392 |
ERROR; |
|
393 |
return NULL; |
|
394 |
} |
|
395 |
||
396 |
void *visit(and_expression_c *symbol) { |
|
397 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
398 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
399 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
400 |
ERROR; |
|
401 |
if (search_expression_type->is_bool_type(left_type)) |
|
402 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " && "); |
|
403 |
if (search_expression_type->is_binary_type(left_type)) |
|
404 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " & "); |
|
405 |
ERROR; |
|
406 |
return NULL; |
|
407 |
} |
|
408 |
||
409 |
void *visit(equ_expression_c *symbol) { |
|
410 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
411 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
412 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
413 |
ERROR; |
|
123 | 414 |
if (search_expression_type->is_time_type(left_type) || |
415 |
search_expression_type->is_string_type(left_type)) |
|
70 | 416 |
return print_compare_function("__eq_", left_type, symbol->l_exp, symbol->r_exp); |
417 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " == "); |
|
418 |
} |
|
419 |
||
420 |
void *visit(notequ_expression_c *symbol) { |
|
421 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
422 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
423 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
424 |
ERROR; |
|
123 | 425 |
if (search_expression_type->is_time_type(left_type) || |
426 |
search_expression_type->is_string_type(left_type)) |
|
70 | 427 |
return print_compare_function("__ne_", left_type, symbol->l_exp, symbol->r_exp); |
428 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " != "); |
|
429 |
} |
|
430 |
||
431 |
void *visit(lt_expression_c *symbol) { |
|
432 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
433 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
434 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
435 |
ERROR; |
|
123 | 436 |
if (search_expression_type->is_time_type(left_type) || |
437 |
search_expression_type->is_string_type(left_type)) |
|
70 | 438 |
return print_compare_function("__lt_", left_type, symbol->l_exp, symbol->r_exp); |
123 | 439 |
if (!search_base_type.type_is_enumerated(left_type)) |
440 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " < "); |
|
441 |
ERROR; |
|
442 |
return NULL; |
|
70 | 443 |
} |
444 |
||
445 |
void *visit(gt_expression_c *symbol) { |
|
446 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
447 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
448 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
449 |
ERROR; |
|
123 | 450 |
if (search_expression_type->is_time_type(left_type) || |
451 |
search_expression_type->is_string_type(left_type)) |
|
70 | 452 |
return print_compare_function("__gt_", left_type, symbol->l_exp, symbol->r_exp); |
123 | 453 |
if (!search_base_type.type_is_enumerated(left_type)) |
454 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " > "); |
|
455 |
ERROR; |
|
456 |
return NULL; |
|
70 | 457 |
} |
458 |
||
459 |
void *visit(le_expression_c *symbol) { |
|
460 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
461 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
462 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
463 |
ERROR; |
|
123 | 464 |
if (search_expression_type->is_time_type(left_type) || |
465 |
search_expression_type->is_string_type(left_type)) |
|
70 | 466 |
return print_compare_function("__le_", left_type, symbol->l_exp, symbol->r_exp); |
123 | 467 |
if (!search_base_type.type_is_enumerated(left_type)) |
468 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " <= "); |
|
469 |
ERROR; |
|
470 |
return NULL; |
|
70 | 471 |
} |
472 |
||
473 |
void *visit(ge_expression_c *symbol) { |
|
474 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
475 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
476 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
477 |
ERROR; |
|
123 | 478 |
if (search_expression_type->is_time_type(left_type) || |
479 |
search_expression_type->is_string_type(left_type)) |
|
70 | 480 |
return print_compare_function("__ge_", left_type, symbol->l_exp, symbol->r_exp); |
123 | 481 |
if (!search_base_type.type_is_enumerated(left_type)) |
482 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " >= "); |
|
483 |
ERROR; |
|
484 |
return NULL; |
|
70 | 485 |
} |
486 |
||
487 |
void *visit(add_expression_c *symbol) { |
|
488 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
489 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
490 |
if ((typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
|
491 |
(typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
|
492 |
(typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c))) |
|
149 | 493 |
return print_binary_function("__TIME_ADD", symbol->l_exp, symbol->r_exp); |
70 | 494 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
495 |
ERROR; |
|
496 |
if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) |
|
497 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " + "); |
|
498 |
ERROR; |
|
499 |
return NULL; |
|
500 |
} |
|
501 |
||
502 |
void *visit(sub_expression_c *symbol) { |
|
503 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
504 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
505 |
if ((typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
|
506 |
(typeid(*left_type) == typeid(date_type_name_c) && typeid(*right_type) == typeid(date_type_name_c)) || |
|
507 |
(typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
|
508 |
(typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(tod_type_name_c)) || |
|
509 |
(typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
|
510 |
(typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(dt_type_name_c))) |
|
149 | 511 |
return print_binary_function("__TIME_SUB", symbol->l_exp, symbol->r_exp); |
70 | 512 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
513 |
ERROR; |
|
514 |
if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) |
|
515 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " - "); |
|
516 |
ERROR; |
|
517 |
return NULL; |
|
518 |
} |
|
519 |
||
520 |
void *visit(mul_expression_c *symbol) { |
|
521 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
522 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
523 |
if ((typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_integer_type(right_type)) || |
|
524 |
(typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_real_type(right_type))) |
|
149 | 525 |
return print_binary_function("__TIME_MUL", symbol->l_exp, symbol->r_exp); |
70 | 526 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
527 |
ERROR; |
|
528 |
if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) |
|
529 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " * "); |
|
530 |
ERROR; |
|
531 |
return NULL; |
|
532 |
} |
|
533 |
||
534 |
void *visit(div_expression_c *symbol) { |
|
535 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
536 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
149 | 537 |
if ((typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_integer_type(right_type)) || |
538 |
(typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_real_type(right_type))) |
|
539 |
return print_binary_function("__TIME_DIV", symbol->l_exp, symbol->r_exp); |
|
70 | 540 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
541 |
ERROR; |
|
542 |
if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) |
|
543 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " / "); |
|
544 |
ERROR; |
|
545 |
return NULL; |
|
546 |
} |
|
547 |
||
548 |
void *visit(mod_expression_c *symbol) { |
|
549 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
550 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
551 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
552 |
ERROR; |
|
553 |
if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) { |
|
554 |
s4o.print("(("); |
|
555 |
symbol->r_exp->accept(*this); |
|
556 |
s4o.print(" == 0)?0:"); |
|
557 |
print_binary_expression(symbol->l_exp, symbol->r_exp, " % "); |
|
558 |
s4o.print(")"); |
|
559 |
return NULL; |
|
560 |
} |
|
561 |
ERROR; |
|
562 |
return NULL; |
|
563 |
} |
|
564 |
||
565 |
/* TODO: power expression... */ |
|
566 |
void *visit(power_expression_c *symbol) {ERROR; return print_binary_expression(symbol->l_exp, symbol->r_exp, " ** ");} |
|
123 | 567 |
void *visit(neg_expression_c *symbol) { |
568 |
symbol_c *exp_type = search_expression_type->get_type(symbol->exp); |
|
569 |
if (search_expression_type->is_integer_type(exp_type) || search_expression_type->is_real_type(exp_type)) |
|
570 |
return print_unary_expression(symbol->exp, " -"); |
|
571 |
ERROR; |
|
572 |
return NULL; |
|
573 |
} |
|
70 | 574 |
|
575 |
void *visit(not_expression_c *symbol) { |
|
576 |
symbol_c *exp_type = search_expression_type->get_type(symbol->exp); |
|
123 | 577 |
if (search_expression_type->is_binary_type(exp_type)) |
578 |
return print_unary_expression(symbol->exp, search_expression_type->is_bool_type(exp_type)?"!":"~"); |
|
579 |
ERROR; |
|
580 |
return NULL; |
|
70 | 581 |
} |
582 |
||
583 |
void *visit(function_invocation_c *symbol) { |
|
149 | 584 |
symbol_c* function_type_prefix = NULL; |
585 |
symbol_c* function_name = NULL; |
|
586 |
symbol_c* function_type_suffix = NULL; |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
587 |
DECLARE_PARAM_LIST() |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
588 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
589 |
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
|
590 |
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
|
591 |
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
|
592 |
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
|
593 |
|
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
594 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
595 |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
596 |
function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
70 | 597 |
if (f_decl == function_symtable.end_value()) { |
598 |
/* The function called is not in the symtable, so we test if it is a |
|
599 |
* 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
|
600 |
|
70 | 601 |
function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
602 |
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
|
603 |
|
70 | 604 |
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
|
605 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
606 |
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
|
607 |
|
235 | 608 |
symbol_c *en_param_name = (symbol_c *)(new identifier_c("EN")); |
149 | 609 |
/* Get the value from EN param */ |
235 | 610 |
symbol_c *EN_param_value = function_call_param_iterator.search_f(en_param_name); |
149 | 611 |
if (EN_param_value == NULL) |
612 |
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
|
613 |
else |
ae423926bc84
Fixed parameter count error on variadic functions with EN/ENO
etisserant
parents:
162
diff
changeset
|
614 |
nb_param --; |
235 | 615 |
ADD_PARAM_LIST(en_param_name, EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in) |
616 |
||
617 |
symbol_c *eno_param_name = (symbol_c *)(new identifier_c("ENO")); |
|
149 | 618 |
/* Get the value from ENO param */ |
235 | 619 |
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
|
620 |
if (ENO_param_value != NULL) |
ae423926bc84
Fixed parameter count error on variadic functions with EN/ENO
etisserant
parents:
162
diff
changeset
|
621 |
nb_param --; |
235 | 622 |
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
|
623 |
|
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
624 |
#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
|
625 |
|
70 | 626 |
} |
627 |
else { |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
628 |
function_name = symbol->function_name; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
629 |
|
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
630 |
/* loop through each function parameter, find the value we should pass |
70 | 631 |
* to it, and then output the c equivalent... |
632 |
*/ |
|
633 |
function_param_iterator_c fp_iterator(f_decl); |
|
634 |
identifier_c *param_name; |
|
635 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
149 | 636 |
|
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
637 |
symbol_c *param_type = fp_iterator.param_type(); |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
638 |
if (param_type == NULL) ERROR; |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
639 |
|
70 | 640 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
149 | 641 |
|
70 | 642 |
/* 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
|
643 |
symbol_c *param_value = function_call_param_iterator.search_f(param_name); |
70 | 644 |
|
645 |
/* 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
|
646 |
if (param_value == NULL) { |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
647 |
param_value = function_call_param_iterator.next_nf(); |
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
648 |
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
|
649 |
} |
149 | 650 |
|
651 |
if (param_value == NULL && param_direction == function_param_iterator_c::direction_in) { |
|
652 |
/* No value given for parameter, so we must use the default... */ |
|
653 |
/* First check whether default value specified in function declaration...*/ |
|
654 |
param_value = fp_iterator.default_value(); |
|
655 |
} |
|
656 |
||
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
657 |
ADD_PARAM_LIST(param_name, param_value, param_type, param_direction) |
70 | 658 |
} /* for(...) */ |
659 |
// symbol->parameter_assignment->accept(*this); |
|
149 | 660 |
} |
661 |
||
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
662 |
if (function_call_param_iterator.next_nf() != NULL) ERROR; |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
663 |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
664 |
bool has_output_params = false; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
665 |
|
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
666 |
if (!this->is_variable_prefix_null()) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
667 |
PARAM_LIST_ITERATOR() { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
668 |
if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
669 |
PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
670 |
PARAM_VALUE != NULL) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
671 |
if (!has_output_params) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
672 |
has_output_params = true; |
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 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
675 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
676 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
677 |
|
149 | 678 |
if (function_type_prefix != NULL) { |
679 |
s4o.print("("); |
|
680 |
function_type_prefix->accept(*this); |
|
70 | 681 |
s4o.print(")"); |
149 | 682 |
} |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
683 |
if (has_output_params) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
684 |
fcall_number++; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
685 |
s4o.print("__"); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
686 |
fbname->accept(*this); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
687 |
s4o.print("_"); |
149 | 688 |
function_name->accept(*this); |
235 | 689 |
if (function_type_suffix != NULL) |
690 |
function_type_suffix->accept(*this); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
691 |
s4o.print_integer(fcall_number); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
692 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
693 |
else { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
694 |
function_name->accept(*this); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
695 |
if (function_type_suffix != NULL) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
696 |
function_type_suffix->accept(*this); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
697 |
} |
149 | 698 |
s4o.print("("); |
699 |
s4o.indent_right(); |
|
700 |
||
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
701 |
int nb_param = 0; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
702 |
PARAM_LIST_ITERATOR() { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
703 |
symbol_c *param_value = PARAM_VALUE; |
235 | 704 |
current_param_type = PARAM_TYPE; |
149 | 705 |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
706 |
switch (PARAM_DIRECTION) { |
149 | 707 |
case function_param_iterator_c::direction_in: |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
708 |
if (nb_param > 0) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
709 |
s4o.print(",\n"+s4o.indent_spaces); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
710 |
if (param_value == NULL) { |
149 | 711 |
/* If not, get the default value of this variable's type */ |
235 | 712 |
param_value = (symbol_c *)current_param_type->accept(*type_initial_value_c::instance()); |
149 | 713 |
} |
714 |
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
|
715 |
s4o.print("("); |
235 | 716 |
if (search_expression_type->is_literal_integer_type(current_param_type)) |
220 | 717 |
search_expression_type->lint_type_name.accept(*this); |
235 | 718 |
else if (search_expression_type->is_literal_real_type(current_param_type)) |
220 | 719 |
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
|
720 |
else |
235 | 721 |
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
|
722 |
s4o.print(")"); |
235 | 723 |
print_check_function(current_param_type, param_value); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
724 |
nb_param++; |
149 | 725 |
break; |
726 |
case function_param_iterator_c::direction_out: |
|
727 |
case function_param_iterator_c::direction_inout: |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
728 |
if (!has_output_params) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
729 |
if (nb_param > 0) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
730 |
s4o.print(",\n"+s4o.indent_spaces); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
731 |
if (param_value == NULL) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
732 |
s4o.print("NULL"); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
733 |
else { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
734 |
wanted_variablegeneration = fparam_output_vg; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
735 |
param_value->accept(*this); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
736 |
wanted_variablegeneration = expression_vg; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
737 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
738 |
nb_param++; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
739 |
} |
149 | 740 |
break; |
741 |
case function_param_iterator_c::direction_extref: |
|
742 |
/* TODO! */ |
|
743 |
ERROR; |
|
744 |
break; |
|
745 |
} /* switch */ |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
746 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
747 |
if (has_output_params) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
748 |
if (nb_param > 0) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
749 |
s4o.print(",\n"+s4o.indent_spaces); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
750 |
s4o.print(FB_FUNCTION_PARAM); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
751 |
} |
149 | 752 |
s4o.print(")"); |
753 |
s4o.indent_left(); |
|
70 | 754 |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
755 |
CLEAR_PARAM_LIST() |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
756 |
|
70 | 757 |
return NULL; |
758 |
} |
|
759 |
||
760 |
/********************/ |
|
761 |
/* B 3.2 Statements */ |
|
762 |
/********************/ |
|
763 |
void *visit(statement_list_c *symbol) { |
|
764 |
return print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); |
|
765 |
} |
|
766 |
||
767 |
/*********************************/ |
|
768 |
/* B 3.2.1 Assignment Statements */ |
|
769 |
/*********************************/ |
|
770 |
void *visit(assignment_statement_c *symbol) { |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
771 |
symbol_c *left_type = search_varfb_instance_type->get_rawtype(symbol->l_exp); |
98 | 772 |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
773 |
if (this->is_variable_prefix_null()) { |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
774 |
symbol->l_exp->accept(*this); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
775 |
s4o.print(" = "); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
776 |
print_check_function(left_type, symbol->r_exp); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
777 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
778 |
else { |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
779 |
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
|
780 |
} |
70 | 781 |
return NULL; |
782 |
} |
|
783 |
||
784 |
/*****************************************/ |
|
785 |
/* B 3.2.2 Subprogram Control Statements */ |
|
786 |
/*****************************************/ |
|
787 |
||
788 |
/* fb_name '(' [param_assignment_list] ')' */ |
|
789 |
/* param_assignment_list -> may be NULL ! */ |
|
790 |
//SYM_REF2(fb_invocation_c, fb_name, param_assignment_list) |
|
791 |
void *visit(fb_invocation_c *symbol) { |
|
792 |
TRACE("fb_invocation_c"); |
|
793 |
/* first figure out what is the name of the function block type of the function block being called... */ |
|
794 |
symbol_c *function_block_type_name = this->search_fb_instance_decl->get_type_name(symbol->fb_name); |
|
795 |
/* should never occur. The function block instance MUST have been declared... */ |
|
796 |
if (function_block_type_name == NULL) ERROR; |
|
797 |
||
798 |
/* Now find the declaration of the function block type being called... */ |
|
799 |
function_block_declaration_c *fb_decl = function_block_type_symtable.find_value(function_block_type_name); |
|
800 |
/* should never occur. The function block type being called MUST be in the symtable... */ |
|
801 |
if (fb_decl == function_block_type_symtable.end_value()) ERROR; |
|
802 |
||
803 |
/* loop through each function block parameter, find the value we should pass |
|
804 |
* to it, and then output the c equivalent... |
|
805 |
*/ |
|
806 |
function_param_iterator_c fp_iterator(fb_decl); |
|
807 |
identifier_c *param_name; |
|
808 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
809 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
810 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
160 | 811 |
|
162
60a124678842
Fixed typo in EN/ENO parameters handling for std library functions
etisserant
parents:
160
diff
changeset
|
812 |
/*fprintf(stderr, "param : %s\n", param_name->value);*/ |
160 | 813 |
|
70 | 814 |
/* 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
|
815 |
symbol_c *param_value = function_call_param_iterator.search_f(param_name); |
70 | 816 |
|
817 |
/* Get the value from a foo(<param_value>) style call */ |
|
818 |
if (param_value == NULL) |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
819 |
param_value = function_call_param_iterator.next_nf(); |
70 | 820 |
|
98 | 821 |
symbol_c *param_type = fp_iterator.param_type(); |
822 |
if (param_type == NULL) ERROR; |
|
823 |
||
70 | 824 |
/* now output the value assignment */ |
825 |
if (param_value != NULL) |
|
826 |
if ((param_direction == function_param_iterator_c::direction_in) || |
|
827 |
(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
|
828 |
if (this->is_variable_prefix_null()) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
829 |
symbol->fb_name->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
830 |
s4o.print("."); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
831 |
param_name->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
832 |
s4o.print(" = "); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
833 |
print_check_function(param_type, param_value); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
834 |
} |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
835 |
else { |
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
226
diff
changeset
|
836 |
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
|
837 |
} |
70 | 838 |
s4o.print(";\n" + s4o.indent_spaces); |
839 |
} |
|
840 |
} /* for(...) */ |
|
841 |
||
842 |
/* now call the function... */ |
|
843 |
function_block_type_name->accept(*this); |
|
844 |
s4o.print(FB_FUNCTION_SUFFIX); |
|
845 |
s4o.print("(&"); |
|
846 |
print_variable_prefix(); |
|
847 |
symbol->fb_name->accept(*this); |
|
848 |
s4o.print(")"); |
|
849 |
||
850 |
/* loop through each function parameter, find the variable to which |
|
851 |
* we should atribute the value of all output or inoutput parameters. |
|
852 |
*/ |
|
853 |
fp_iterator.reset(); |
|
854 |
function_call_param_iterator.reset(); |
|
855 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
856 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
857 |
||
858 |
/* 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
|
859 |
symbol_c *param_value = function_call_param_iterator.search_f(param_name); |
70 | 860 |
|
861 |
/* Get the value from a foo(<param_value>) style call */ |
|
862 |
if (param_value == NULL) |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
863 |
param_value = function_call_param_iterator.next_nf(); |
70 | 864 |
|
865 |
/* now output the value assignment */ |
|
866 |
if (param_value != NULL) |
|
867 |
if ((param_direction == function_param_iterator_c::direction_out) || |
|
868 |
(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
|
869 |
symbol_c *param_type = search_varfb_instance_type->get_rawtype(param_value); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
870 |
if (this->is_variable_prefix_null()) { |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
871 |
param_value->accept(*this); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
872 |
s4o.print(" = "); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
873 |
print_check_function(param_type, param_name, symbol->fb_name); |
98 | 874 |
} |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
875 |
else { |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
876 |
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
|
877 |
} |
70 | 878 |
} |
879 |
} /* for(...) */ |
|
880 |
||
881 |
return NULL; |
|
882 |
} |
|
883 |
||
884 |
||
885 |
||
886 |
||
887 |
/* helper symbol for fb_invocation */ |
|
888 |
/* param_assignment_list ',' param_assignment */ |
|
889 |
void *visit(param_assignment_list_c *symbol) { |
|
890 |
TRACE("param_assignment_list_c"); |
|
891 |
/* this should never be called... */ |
|
892 |
ERROR; |
|
893 |
return NULL; |
|
894 |
// return print_list(symbol, "", ", "); |
|
895 |
} |
|
896 |
||
897 |
||
898 |
void *visit(input_variable_param_assignment_c *symbol) { |
|
899 |
TRACE("input_variable_param_assignment_c"); |
|
900 |
/* this should never be called... */ |
|
901 |
ERROR; |
|
902 |
return NULL; |
|
903 |
/* |
|
904 |
symbol->variable_name->accept(*this); |
|
905 |
s4o.print(" = "); |
|
906 |
symbol->expression->accept(*this); |
|
907 |
return NULL; |
|
908 |
*/ |
|
909 |
} |
|
910 |
||
911 |
void *visit(output_variable_param_assignment_c *symbol) { |
|
912 |
TRACE("output_variable_param_assignment_c"); |
|
913 |
/* this should never be called... */ |
|
914 |
ERROR; |
|
915 |
return NULL; |
|
916 |
/* |
|
917 |
s4o.print(s4o.indent_spaces); |
|
918 |
if (symbol->not_param != NULL) |
|
919 |
symbol->not_param->accept(*this); |
|
920 |
symbol->variable_name->accept(*this); |
|
921 |
s4o.print(" => "); |
|
922 |
symbol->variable->accept(*this); |
|
923 |
return NULL; |
|
924 |
*/ |
|
925 |
} |
|
926 |
||
927 |
// TODO: the NOT symbol in function (block) calls... |
|
928 |
void *visit(not_paramassign_c *symbol) { |
|
929 |
TRACE("not_paramassign_c"); |
|
930 |
/* this should never be called... */ |
|
931 |
ERROR; |
|
932 |
return NULL; |
|
933 |
/* |
|
934 |
s4o.print("NOT "); |
|
935 |
return NULL; |
|
936 |
*/ |
|
937 |
} |
|
938 |
||
939 |
||
940 |
/********************************/ |
|
941 |
/* B 3.2.3 Selection Statements */ |
|
942 |
/********************************/ |
|
943 |
void *visit(if_statement_c *symbol) { |
|
944 |
s4o.print("if ("); |
|
945 |
symbol->expression->accept(*this); |
|
946 |
s4o.print(") {\n"); |
|
947 |
s4o.indent_right(); |
|
948 |
symbol->statement_list->accept(*this); |
|
949 |
s4o.indent_left(); |
|
950 |
symbol->elseif_statement_list->accept(*this); |
|
951 |
||
952 |
if (symbol->else_statement_list != NULL) { |
|
953 |
s4o.print(s4o.indent_spaces); s4o.print("} else {\n"); |
|
954 |
s4o.indent_right(); |
|
955 |
symbol->else_statement_list->accept(*this); |
|
956 |
s4o.indent_left(); |
|
957 |
} |
|
958 |
s4o.print(s4o.indent_spaces); s4o.print("}"); |
|
959 |
return NULL; |
|
960 |
} |
|
961 |
||
962 |
/* helper symbol for if_statement */ |
|
963 |
void *visit(elseif_statement_list_c *symbol) {return print_list(symbol);} |
|
964 |
||
965 |
/* helper symbol for elseif_statement_list */ |
|
966 |
void *visit(elseif_statement_c *symbol) { |
|
967 |
s4o.print(s4o.indent_spaces); s4o.print("} else if ("); |
|
968 |
symbol->expression->accept(*this); |
|
969 |
s4o.print(") {\n"); |
|
970 |
s4o.indent_right(); |
|
971 |
symbol->statement_list->accept(*this); |
|
972 |
s4o.indent_left(); |
|
973 |
return NULL; |
|
974 |
} |
|
975 |
||
976 |
void *visit(case_statement_c *symbol) { |
|
977 |
s4o.print("switch("); |
|
978 |
symbol->expression->accept(*this); |
|
979 |
s4o.print(") {\n"); |
|
980 |
s4o.indent_right(); |
|
981 |
symbol->case_element_list->accept(*this); |
|
982 |
if (symbol->statement_list != NULL) { |
|
983 |
s4o.print(s4o.indent_spaces + "default:\n"); |
|
984 |
s4o.indent_right(); |
|
985 |
symbol->statement_list->accept(*this); |
|
986 |
s4o.print(s4o.indent_spaces + "break;\n"); |
|
987 |
s4o.indent_left(); |
|
988 |
} |
|
989 |
s4o.indent_left(); |
|
990 |
s4o.print(s4o.indent_spaces + "}"); |
|
991 |
return NULL; |
|
992 |
} |
|
993 |
||
994 |
/* helper symbol for case_statement */ |
|
995 |
void *visit(case_element_list_c *symbol) {return print_list(symbol);} |
|
996 |
||
997 |
void *visit(case_element_c *symbol) { |
|
998 |
s4o.print(s4o.indent_spaces + "case "); |
|
999 |
symbol->case_list->accept(*this); |
|
1000 |
s4o.print(" :\n"); |
|
1001 |
s4o.indent_right(); |
|
1002 |
symbol->statement_list->accept(*this); |
|
1003 |
s4o.print(s4o.indent_spaces + "break;\n"); |
|
1004 |
s4o.indent_left(); |
|
1005 |
return NULL; |
|
1006 |
} |
|
1007 |
||
1008 |
void *visit(case_list_c *symbol) {return print_list(symbol, "", ", ");} |
|
1009 |
||
1010 |
/********************************/ |
|
1011 |
/* B 3.2.4 Iteration Statements */ |
|
1012 |
/********************************/ |
|
1013 |
void *visit(for_statement_c *symbol) { |
|
1014 |
s4o.print("for("); |
|
1015 |
symbol->control_variable->accept(*this); |
|
1016 |
s4o.print(" = "); |
|
1017 |
symbol->beg_expression->accept(*this); |
|
1018 |
s4o.print("; "); |
|
1019 |
symbol->control_variable->accept(*this); |
|
1020 |
s4o.print(" != "); |
|
1021 |
symbol->end_expression->accept(*this); |
|
1022 |
s4o.print("; "); |
|
1023 |
symbol->control_variable->accept(*this); |
|
1024 |
if (symbol->by_expression != NULL) { |
|
1025 |
s4o.print(" += "); |
|
1026 |
symbol->by_expression->accept(*this); |
|
1027 |
} else { |
|
1028 |
s4o.print("++"); |
|
1029 |
} |
|
1030 |
s4o.print(") {\n"); |
|
1031 |
s4o.indent_right(); |
|
1032 |
symbol->statement_list->accept(*this); |
|
1033 |
s4o.indent_left(); |
|
1034 |
s4o.print(s4o.indent_spaces); s4o.print("}"); |
|
1035 |
return NULL; |
|
1036 |
} |
|
1037 |
void *visit(while_statement_c *symbol) { |
|
1038 |
s4o.print("while ("); |
|
1039 |
symbol->expression->accept(*this); |
|
1040 |
s4o.print(") {\n"); |
|
1041 |
s4o.indent_right(); |
|
1042 |
symbol->statement_list->accept(*this); |
|
1043 |
s4o.indent_left(); |
|
1044 |
s4o.print(s4o.indent_spaces); s4o.print("}"); |
|
1045 |
return NULL; |
|
1046 |
} |
|
1047 |
void *visit(repeat_statement_c *symbol) { |
|
1048 |
s4o.print("do {\n"); |
|
1049 |
s4o.indent_right(); |
|
1050 |
symbol->statement_list->accept(*this); |
|
1051 |
s4o.indent_left(); |
|
1052 |
s4o.print(s4o.indent_spaces); s4o.print("} while("); |
|
1053 |
symbol->expression->accept(*this); |
|
1054 |
s4o.print(")"); |
|
1055 |
return NULL; |
|
1056 |
} |
|
1057 |
void *visit(exit_statement_c *symbol) { |
|
1058 |
s4o.print("exit(0)"); |
|
1059 |
return NULL; |
|
1060 |
} |
|
1061 |
||
1062 |
||
1063 |
||
1064 |
}; /* generate_c_st_c */ |
|
1065 |
||
1066 |
||
1067 |
||
1068 |
||
1069 |
||
1070 |
||
1071 |
||
1072 |
||
1073 |