author | laurent |
Wed, 14 Sep 2011 22:58:39 +0200 | |
changeset 377 | 60b012b7793f |
parent 376 | 7dcbd8418771 |
child 382 | ac6dfec701c9 |
permissions | -rwxr-xr-x |
70 | 1 |
/* |
279
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
2 |
* matiec - a compiler for the programming languages defined in IEC 61131-3 |
70 | 3 |
* |
279
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
4 |
* Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt) |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
5 |
* Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant |
70 | 6 |
* |
279
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
7 |
* This program is free software: you can redistribute it and/or modify |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
8 |
* it under the terms of the GNU General Public License as published by |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
9 |
* the Free Software Foundation, either version 3 of the License, or |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
10 |
* (at your option) any later version. |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
11 |
* |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
12 |
* This program is distributed in the hope that it will be useful, |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
15 |
* GNU General Public License for more details. |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
16 |
* |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
18 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
70 | 19 |
* |
20 |
* This code is made available on the understanding that it will not be |
|
21 |
* used in safety-critical situations without a full and competent review. |
|
22 |
* |
|
23 |
* Based on the |
|
24 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
25 |
* |
|
26 |
*/ |
|
27 |
||
28 |
||
29 |
/* |
|
30 |
* Conversion of st statements (i.e. ST code). |
|
31 |
* |
|
32 |
* This is part of the 4th stage that generates |
|
279
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
33 |
* a C source program equivalent to the IL and ST, or SFC |
70 | 34 |
* code. |
35 |
*/ |
|
36 |
||
37 |
||
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
38 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
39 |
#include "../../util/strdup.hh" |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
40 |
|
70 | 41 |
/***********************************************************************/ |
42 |
/***********************************************************************/ |
|
43 |
/***********************************************************************/ |
|
44 |
/***********************************************************************/ |
|
45 |
||
46 |
||
47 |
class generate_c_st_c: public generate_c_typedecl_c { |
|
48 |
||
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
49 |
public: |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
50 |
typedef enum { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
51 |
expression_vg, |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
52 |
assignment_vg, |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
53 |
complextype_base_vg, |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
54 |
complextype_suffix_vg, |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
55 |
fparam_output_vg |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
56 |
} variablegeneration_t; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
57 |
|
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
58 |
typedef enum { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
59 |
single_cg, |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
60 |
subrange_cg, |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
61 |
none_cg |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
62 |
} casegeneration_t; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
63 |
|
70 | 64 |
private: |
65 |
/* When calling a function block, we must first find it's type, |
|
66 |
* by searching through the declarations of the variables currently |
|
67 |
* in scope. |
|
68 |
* This class does just that... |
|
69 |
* A new class is instantiated whenever we begin generating the code |
|
70 |
* for a function block type declaration, or a program declaration. |
|
71 |
* This object instance will then later be called while the |
|
72 |
* function block's or the program's body is being handled. |
|
73 |
* |
|
74 |
* Note that functions cannot contain calls to function blocks, |
|
75 |
* so we do not create an object instance when handling |
|
76 |
* a function declaration. |
|
77 |
*/ |
|
78 |
search_fb_instance_decl_c *search_fb_instance_decl; |
|
79 |
||
80 |
/* When compiling st code, it becomes necessary to determine the |
|
81 |
* data type of st expressions. To do this, we must first find the |
|
82 |
* st operand's declaration, within the scope of the function block |
|
83 |
* or function currently being processed. |
|
84 |
* The following object does just that... |
|
85 |
* This object instance will then later be called while the |
|
86 |
* remaining st code is being handled. |
|
87 |
*/ |
|
88 |
search_expression_type_c *search_expression_type; |
|
89 |
||
90 |
search_varfb_instance_type_c *search_varfb_instance_type; |
|
91 |
||
98 | 92 |
search_base_type_c search_base_type; |
93 |
||
94 |
symbol_c* current_array_type; |
|
235 | 95 |
symbol_c* current_param_type; |
98 | 96 |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
97 |
int fcall_number; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
98 |
symbol_c *fbname; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
99 |
|
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
100 |
bool first_subrange_case_list; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
101 |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
102 |
variablegeneration_t wanted_variablegeneration; |
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
103 |
casegeneration_t wanted_casegeneration; |
145 | 104 |
|
70 | 105 |
public: |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
106 |
generate_c_st_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL) |
70 | 107 |
: generate_c_typedecl_c(s4o_ptr) { |
108 |
search_fb_instance_decl = new search_fb_instance_decl_c(scope); |
|
109 |
search_expression_type = new search_expression_type_c(scope); |
|
110 |
search_varfb_instance_type = new search_varfb_instance_type_c(scope); |
|
111 |
this->set_variable_prefix(variable_prefix); |
|
98 | 112 |
current_array_type = NULL; |
235 | 113 |
current_param_type = NULL; |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
114 |
fcall_number = 0; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
115 |
fbname = name; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
116 |
wanted_variablegeneration = expression_vg; |
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
117 |
wanted_casegeneration = none_cg; |
70 | 118 |
} |
119 |
||
120 |
virtual ~generate_c_st_c(void) { |
|
121 |
delete search_fb_instance_decl; |
|
122 |
delete search_expression_type; |
|
123 |
delete search_varfb_instance_type; |
|
124 |
} |
|
125 |
||
126 |
||
127 |
public: |
|
128 |
void generate(statement_list_c *stl) { |
|
129 |
stl->accept(*this); |
|
130 |
} |
|
131 |
||
132 |
private: |
|
133 |
||
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
134 |
void *print_getter(symbol_c *symbol) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
135 |
unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); |
235 | 136 |
if (wanted_variablegeneration == fparam_output_vg) { |
137 |
if (vartype == search_var_instance_decl_c::external_vt) |
|
138 |
s4o.print(GET_EXTERNAL_BY_REF); |
|
139 |
else if (vartype == search_var_instance_decl_c::located_vt) |
|
140 |
s4o.print(GET_LOCATED_BY_REF); |
|
141 |
else |
|
142 |
s4o.print(GET_VAR_BY_REF); |
|
143 |
} |
|
144 |
else { |
|
145 |
if (vartype == search_var_instance_decl_c::external_vt) |
|
146 |
s4o.print(GET_EXTERNAL); |
|
147 |
else if (vartype == search_var_instance_decl_c::located_vt) |
|
148 |
s4o.print(GET_LOCATED); |
|
149 |
else |
|
150 |
s4o.print(GET_VAR); |
|
151 |
} |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
152 |
s4o.print("("); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
153 |
|
235 | 154 |
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
|
155 |
wanted_variablegeneration = complextype_base_vg; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
156 |
symbol->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
157 |
if (search_varfb_instance_type->type_is_complex()) |
235 | 158 |
s4o.print(","); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
159 |
wanted_variablegeneration = complextype_suffix_vg; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
160 |
symbol->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
161 |
s4o.print(")"); |
235 | 162 |
wanted_variablegeneration = old_wanted_variablegeneration; |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
163 |
return NULL; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
164 |
} |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
165 |
|
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
166 |
void *print_setter(symbol_c* symbol, |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
167 |
symbol_c* type, |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
168 |
symbol_c* value, |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
169 |
symbol_c* fb_symbol = NULL, |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
170 |
symbol_c* fb_value = NULL) { |
302
d120740a6b58
Fixing bug related to setting array variables with values coming from other variables
Mario de Sousa <msousa@fe.up.pt>
parents:
298
diff
changeset
|
171 |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
172 |
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
|
173 |
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
|
174 |
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
|
175 |
/* 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
|
176 |
if (variable != NULL) { |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
177 |
s4o.print(SET_EXTERNAL); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
178 |
s4o.print("("); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
179 |
variable->var_name->accept(*this); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
180 |
s4o.print(","); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
181 |
} |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
182 |
else { |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
183 |
s4o.print(SET_COMPLEX_EXTERNAL); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
184 |
s4o.print("("); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
185 |
} |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
186 |
} |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
187 |
else { |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
188 |
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
|
189 |
s4o.print(SET_LOCATED); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
190 |
else |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
191 |
s4o.print(SET_VAR); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
192 |
s4o.print("("); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
193 |
} |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
194 |
|
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
195 |
if (fb_symbol != NULL) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
196 |
print_variable_prefix(); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
197 |
fb_symbol->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
198 |
s4o.print("."); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
199 |
} |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
200 |
else |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
201 |
wanted_variablegeneration = complextype_base_vg; |
302
d120740a6b58
Fixing bug related to setting array variables with values coming from other variables
Mario de Sousa <msousa@fe.up.pt>
parents:
298
diff
changeset
|
202 |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
203 |
symbol->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
204 |
s4o.print(","); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
205 |
wanted_variablegeneration = expression_vg; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
206 |
print_check_function(type, value, fb_value); |
302
d120740a6b58
Fixing bug related to setting array variables with values coming from other variables
Mario de Sousa <msousa@fe.up.pt>
parents:
298
diff
changeset
|
207 |
/* We need to call search_varfb_instance_type->get_vartype() again, as it may have been called |
d120740a6b58
Fixing bug related to setting array variables with values coming from other variables
Mario de Sousa <msousa@fe.up.pt>
parents:
298
diff
changeset
|
208 |
* again since we called it in the beginning of this print_setter() function. |
d120740a6b58
Fixing bug related to setting array variables with values coming from other variables
Mario de Sousa <msousa@fe.up.pt>
parents:
298
diff
changeset
|
209 |
* This make sure the call to search_varfb_instance_type->type_is_complex() will return |
d120740a6b58
Fixing bug related to setting array variables with values coming from other variables
Mario de Sousa <msousa@fe.up.pt>
parents:
298
diff
changeset
|
210 |
* the correct value regarding our 'symbol'. |
d120740a6b58
Fixing bug related to setting array variables with values coming from other variables
Mario de Sousa <msousa@fe.up.pt>
parents:
298
diff
changeset
|
211 |
*/ |
d120740a6b58
Fixing bug related to setting array variables with values coming from other variables
Mario de Sousa <msousa@fe.up.pt>
parents:
298
diff
changeset
|
212 |
search_varfb_instance_type->get_vartype(symbol); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
213 |
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
|
214 |
s4o.print(","); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
215 |
wanted_variablegeneration = complextype_suffix_vg; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
216 |
symbol->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
217 |
} |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
218 |
s4o.print(")"); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
219 |
wanted_variablegeneration = expression_vg; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
220 |
return NULL; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
221 |
} |
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
222 |
|
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
223 |
/********************************/ |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
224 |
/* B 1.3.3 - Derived data types */ |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
225 |
/********************************/ |
377
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
226 |
|
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
227 |
/* signed_integer DOTDOT signed_integer */ |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
228 |
void *visit(subrange_c *symbol) { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
229 |
switch (wanted_casegeneration) { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
230 |
case subrange_cg: |
376 | 231 |
s4o.print("__case_expression >= "); |
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
232 |
symbol->lower_limit->accept(*this); |
376 | 233 |
s4o.print(" && __case_expression <= "); |
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
234 |
symbol->upper_limit->accept(*this); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
235 |
break; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
236 |
default: |
377
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
237 |
symbol->lower_limit->accept(*this); |
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
238 |
break; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
239 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
240 |
return NULL; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
241 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
242 |
|
377
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
243 |
/* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */ |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
244 |
void *visit(array_specification_c *symbol) { |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
245 |
symbol->non_generic_type_name->accept(*this); |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
246 |
return NULL; |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
247 |
} |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
248 |
|
70 | 249 |
/*********************/ |
250 |
/* B 1.4 - Variables */ |
|
251 |
/*********************/ |
|
252 |
void *visit(symbolic_variable_c *symbol) { |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
253 |
unsigned int vartype; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
254 |
if (wanted_variablegeneration == complextype_base_vg) |
298
022a874149ce
Fixing code generation of array indexes in Function Blocks.
Mario de Sousa <msousa@fe.up.pt>
parents:
283
diff
changeset
|
255 |
generate_c_base_c::visit(symbol); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
256 |
else if (wanted_variablegeneration == complextype_suffix_vg) |
298
022a874149ce
Fixing code generation of array indexes in Function Blocks.
Mario de Sousa <msousa@fe.up.pt>
parents:
283
diff
changeset
|
257 |
return NULL; |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
258 |
else if (this->is_variable_prefix_null()) { |
298
022a874149ce
Fixing code generation of array indexes in Function Blocks.
Mario de Sousa <msousa@fe.up.pt>
parents:
283
diff
changeset
|
259 |
vartype = search_varfb_instance_type->get_vartype(symbol); |
022a874149ce
Fixing code generation of array indexes in Function Blocks.
Mario de Sousa <msousa@fe.up.pt>
parents:
283
diff
changeset
|
260 |
if (wanted_variablegeneration == fparam_output_vg) { |
022a874149ce
Fixing code generation of array indexes in Function Blocks.
Mario de Sousa <msousa@fe.up.pt>
parents:
283
diff
changeset
|
261 |
s4o.print("&("); |
022a874149ce
Fixing code generation of array indexes in Function Blocks.
Mario de Sousa <msousa@fe.up.pt>
parents:
283
diff
changeset
|
262 |
generate_c_base_c::visit(symbol); |
022a874149ce
Fixing code generation of array indexes in Function Blocks.
Mario de Sousa <msousa@fe.up.pt>
parents:
283
diff
changeset
|
263 |
s4o.print(")"); |
022a874149ce
Fixing code generation of array indexes in Function Blocks.
Mario de Sousa <msousa@fe.up.pt>
parents:
283
diff
changeset
|
264 |
} |
022a874149ce
Fixing code generation of array indexes in Function Blocks.
Mario de Sousa <msousa@fe.up.pt>
parents:
283
diff
changeset
|
265 |
else { |
022a874149ce
Fixing code generation of array indexes in Function Blocks.
Mario de Sousa <msousa@fe.up.pt>
parents:
283
diff
changeset
|
266 |
generate_c_base_c::visit(symbol); |
022a874149ce
Fixing code generation of array indexes in Function Blocks.
Mario de Sousa <msousa@fe.up.pt>
parents:
283
diff
changeset
|
267 |
} |
145 | 268 |
} |
235 | 269 |
else |
298
022a874149ce
Fixing code generation of array indexes in Function Blocks.
Mario de Sousa <msousa@fe.up.pt>
parents:
283
diff
changeset
|
270 |
print_getter(symbol); |
70 | 271 |
return NULL; |
272 |
} |
|
273 |
||
274 |
/********************************************/ |
|
275 |
/* B.1.4.1 Directly Represented Variables */ |
|
276 |
/********************************************/ |
|
277 |
// direct_variable: direct_variable_token {$$ = new direct_variable_c($1);}; |
|
278 |
void *visit(direct_variable_c *symbol) { |
|
279 |
TRACE("direct_variable_c"); |
|
280 |
/* Do not use print_token() as it will change everything into uppercase */ |
|
281 |
if (strlen(symbol->value) == 0) ERROR; |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
282 |
if (this->is_variable_prefix_null()) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
283 |
if (wanted_variablegeneration != fparam_output_vg) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
284 |
s4o.print("*("); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
285 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
286 |
else { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
287 |
switch (wanted_variablegeneration) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
288 |
case expression_vg: |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
289 |
s4o.print(GET_LOCATED); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
290 |
s4o.print("("); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
291 |
break; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
292 |
case fparam_output_vg: |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
293 |
s4o.print(GET_LOCATED_BY_REF); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
294 |
s4o.print("("); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
295 |
break; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
296 |
default: |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
297 |
break; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
298 |
} |
145 | 299 |
} |
70 | 300 |
this->print_variable_prefix(); |
301 |
s4o.printlocation(symbol->value + 1); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
302 |
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
|
303 |
wanted_variablegeneration != assignment_vg) |
145 | 304 |
s4o.print(")"); |
70 | 305 |
return NULL; |
306 |
} |
|
307 |
||
98 | 308 |
/*************************************/ |
309 |
/* B.1.4.2 Multi-element Variables */ |
|
310 |
/*************************************/ |
|
311 |
||
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
|
312 |
// 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
|
313 |
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
|
314 |
TRACE("structured_variable_c"); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
315 |
switch (wanted_variablegeneration) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
316 |
case complextype_base_vg: |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
317 |
symbol->record_variable->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
318 |
break; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
319 |
case complextype_suffix_vg: |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
320 |
symbol->record_variable->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
321 |
s4o.print("."); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
322 |
symbol->field_selector->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
323 |
break; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
324 |
default: |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
325 |
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
|
326 |
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
|
327 |
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
|
328 |
symbol->field_selector->accept(*this); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
329 |
} |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
330 |
else |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
331 |
print_getter(symbol); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
332 |
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
|
333 |
} |
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
|
334 |
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
|
335 |
} |
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
|
336 |
|
98 | 337 |
/* subscripted_variable '[' subscript_list ']' */ |
338 |
//SYM_REF2(array_variable_c, subscripted_variable, subscript_list) |
|
339 |
void *visit(array_variable_c *symbol) { |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
340 |
switch (wanted_variablegeneration) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
341 |
case complextype_base_vg: |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
342 |
symbol->subscripted_variable->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
343 |
break; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
344 |
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
|
345 |
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
|
346 |
|
321
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
309
diff
changeset
|
347 |
current_array_type = search_varfb_instance_type->get_type_id(symbol->subscripted_variable); |
238
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
348 |
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
|
349 |
|
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
350 |
s4o.print(".table"); |
298
022a874149ce
Fixing code generation of array indexes in Function Blocks.
Mario de Sousa <msousa@fe.up.pt>
parents:
283
diff
changeset
|
351 |
wanted_variablegeneration = expression_vg; |
238
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
352 |
symbol->subscript_list->accept(*this); |
298
022a874149ce
Fixing code generation of array indexes in Function Blocks.
Mario de Sousa <msousa@fe.up.pt>
parents:
283
diff
changeset
|
353 |
wanted_variablegeneration = complextype_suffix_vg; |
238
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
354 |
|
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
355 |
current_array_type = NULL; |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
356 |
break; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
357 |
default: |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
358 |
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
|
359 |
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
|
360 |
|
321
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
309
diff
changeset
|
361 |
current_array_type = search_varfb_instance_type->get_type_id(symbol->subscripted_variable); |
238
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
362 |
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
|
363 |
|
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
364 |
s4o.print(".table"); |
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
365 |
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
|
366 |
|
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
367 |
current_array_type = NULL; |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
368 |
} |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
369 |
else |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
370 |
print_getter(symbol); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
371 |
break; |
98 | 372 |
} |
373 |
return NULL; |
|
374 |
} |
|
375 |
||
376 |
/* subscript_list ',' subscript */ |
|
377 |
void *visit(subscript_list_c *symbol) { |
|
377
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
378 |
array_dimension_iterator_c* array_dimension_iterator = new array_dimension_iterator_c(current_array_type); |
98 | 379 |
for (int i = 0; i < symbol->n; i++) { |
377
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
380 |
symbol_c* dimension = array_dimension_iterator->next(); |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
381 |
if (dimension == NULL) ERROR; |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
382 |
|
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
383 |
s4o.print("[("); |
98 | 384 |
symbol->elements[i]->accept(*this); |
377
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
385 |
s4o.print(") - ("); |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
386 |
dimension->accept(*this); |
98 | 387 |
s4o.print(")]"); |
388 |
} |
|
377
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
389 |
delete array_dimension_iterator; |
98 | 390 |
return NULL; |
391 |
} |
|
392 |
||
235 | 393 |
/******************************************/ |
394 |
/* B 1.4.3 - Declaration & Initialisation */ |
|
395 |
/******************************************/ |
|
237 | 396 |
|
397 |
/* helper symbol for structure_initialization */ |
|
398 |
/* structure_element_initialization_list ',' structure_element_initialization */ |
|
235 | 399 |
void *visit(structure_element_initialization_list_c *symbol) { |
400 |
generate_c_structure_initialization_c *structure_initialization = new generate_c_structure_initialization_c(&s4o); |
|
401 |
structure_initialization->init_structure_default(this->current_param_type); |
|
237 | 402 |
structure_initialization->init_structure_values(symbol); |
235 | 403 |
delete structure_initialization; |
404 |
return NULL; |
|
405 |
} |
|
98 | 406 |
|
237 | 407 |
/* helper symbol for array_initialization */ |
408 |
/* array_initial_elements_list ',' array_initial_elements */ |
|
409 |
void *visit(array_initial_elements_list_c *symbol) { |
|
410 |
generate_c_array_initialization_c *array_initialization = new generate_c_array_initialization_c(&s4o); |
|
411 |
array_initialization->init_array_size(this->current_param_type); |
|
412 |
array_initialization->init_array_values(symbol); |
|
413 |
delete array_initialization; |
|
414 |
return NULL; |
|
415 |
} |
|
416 |
||
70 | 417 |
/***************************************/ |
418 |
/* B.3 - Language ST (Structured Text) */ |
|
419 |
/***************************************/ |
|
420 |
/***********************/ |
|
421 |
/* B 3.1 - Expressions */ |
|
422 |
/***********************/ |
|
423 |
void *visit(or_expression_c *symbol) { |
|
424 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
425 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
426 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
427 |
ERROR; |
|
428 |
if (search_expression_type->is_bool_type(left_type)) |
|
429 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " || "); |
|
430 |
if (search_expression_type->is_binary_type(left_type)) |
|
431 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " | "); |
|
432 |
ERROR; |
|
433 |
return NULL; |
|
434 |
} |
|
435 |
||
436 |
void *visit(xor_expression_c *symbol) { |
|
437 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
438 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
439 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
440 |
ERROR; |
|
441 |
if (search_expression_type->is_bool_type(left_type)) { |
|
442 |
s4o.print("("); |
|
443 |
symbol->l_exp->accept(*this); |
|
444 |
s4o.print(" && !"); |
|
445 |
symbol->r_exp->accept(*this); |
|
446 |
s4o.print(") || (!"); |
|
447 |
symbol->l_exp->accept(*this); |
|
448 |
s4o.print(" && "); |
|
449 |
symbol->r_exp->accept(*this); |
|
450 |
s4o.print(")"); |
|
130 | 451 |
return NULL; |
70 | 452 |
} |
453 |
if (search_expression_type->is_binary_type(left_type)) |
|
454 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " ^ "); |
|
455 |
ERROR; |
|
456 |
return NULL; |
|
457 |
} |
|
458 |
||
459 |
void *visit(and_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; |
|
464 |
if (search_expression_type->is_bool_type(left_type)) |
|
465 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " && "); |
|
466 |
if (search_expression_type->is_binary_type(left_type)) |
|
467 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " & "); |
|
468 |
ERROR; |
|
469 |
return NULL; |
|
470 |
} |
|
471 |
||
472 |
void *visit(equ_expression_c *symbol) { |
|
473 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
474 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
475 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
476 |
ERROR; |
|
123 | 477 |
if (search_expression_type->is_time_type(left_type) || |
478 |
search_expression_type->is_string_type(left_type)) |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
479 |
return print_compare_function("EQ_", left_type, symbol->l_exp, symbol->r_exp); |
70 | 480 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " == "); |
481 |
} |
|
482 |
||
483 |
void *visit(notequ_expression_c *symbol) { |
|
484 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
485 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
486 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
487 |
ERROR; |
|
123 | 488 |
if (search_expression_type->is_time_type(left_type) || |
489 |
search_expression_type->is_string_type(left_type)) |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
490 |
return print_compare_function("NE_", left_type, symbol->l_exp, symbol->r_exp); |
70 | 491 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " != "); |
492 |
} |
|
493 |
||
494 |
void *visit(lt_expression_c *symbol) { |
|
495 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
496 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
497 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
498 |
ERROR; |
|
123 | 499 |
if (search_expression_type->is_time_type(left_type) || |
500 |
search_expression_type->is_string_type(left_type)) |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
501 |
return print_compare_function("LT_", left_type, symbol->l_exp, symbol->r_exp); |
123 | 502 |
if (!search_base_type.type_is_enumerated(left_type)) |
503 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " < "); |
|
504 |
ERROR; |
|
505 |
return NULL; |
|
70 | 506 |
} |
507 |
||
508 |
void *visit(gt_expression_c *symbol) { |
|
509 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
510 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
511 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
512 |
ERROR; |
|
123 | 513 |
if (search_expression_type->is_time_type(left_type) || |
514 |
search_expression_type->is_string_type(left_type)) |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
515 |
return print_compare_function("GT_", left_type, symbol->l_exp, symbol->r_exp); |
123 | 516 |
if (!search_base_type.type_is_enumerated(left_type)) |
517 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " > "); |
|
518 |
ERROR; |
|
519 |
return NULL; |
|
70 | 520 |
} |
521 |
||
522 |
void *visit(le_expression_c *symbol) { |
|
523 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
524 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
525 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
526 |
ERROR; |
|
123 | 527 |
if (search_expression_type->is_time_type(left_type) || |
528 |
search_expression_type->is_string_type(left_type)) |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
529 |
return print_compare_function("LE_", left_type, symbol->l_exp, symbol->r_exp); |
123 | 530 |
if (!search_base_type.type_is_enumerated(left_type)) |
531 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " <= "); |
|
532 |
ERROR; |
|
533 |
return NULL; |
|
70 | 534 |
} |
535 |
||
536 |
void *visit(ge_expression_c *symbol) { |
|
537 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
538 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
539 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
540 |
ERROR; |
|
123 | 541 |
if (search_expression_type->is_time_type(left_type) || |
542 |
search_expression_type->is_string_type(left_type)) |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
543 |
return print_compare_function("GE_", left_type, symbol->l_exp, symbol->r_exp); |
123 | 544 |
if (!search_base_type.type_is_enumerated(left_type)) |
545 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " >= "); |
|
546 |
ERROR; |
|
547 |
return NULL; |
|
70 | 548 |
} |
549 |
||
550 |
void *visit(add_expression_c *symbol) { |
|
551 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
552 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
553 |
if ((typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
|
554 |
(typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
|
555 |
(typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c))) |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
556 |
return print_binary_function("__time_add", symbol->l_exp, symbol->r_exp); |
70 | 557 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
558 |
ERROR; |
|
559 |
if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) |
|
560 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " + "); |
|
561 |
ERROR; |
|
562 |
return NULL; |
|
563 |
} |
|
564 |
||
565 |
void *visit(sub_expression_c *symbol) { |
|
566 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
567 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
568 |
if ((typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
|
569 |
(typeid(*left_type) == typeid(date_type_name_c) && typeid(*right_type) == typeid(date_type_name_c)) || |
|
570 |
(typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
|
571 |
(typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(tod_type_name_c)) || |
|
572 |
(typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
|
573 |
(typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(dt_type_name_c))) |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
574 |
return print_binary_function("__time_sub", symbol->l_exp, symbol->r_exp); |
70 | 575 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
576 |
ERROR; |
|
577 |
if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) |
|
578 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " - "); |
|
579 |
ERROR; |
|
580 |
return NULL; |
|
581 |
} |
|
582 |
||
583 |
void *visit(mul_expression_c *symbol) { |
|
584 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
585 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
586 |
if ((typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_integer_type(right_type)) || |
|
587 |
(typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_real_type(right_type))) |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
588 |
return print_binary_function("__time_mul", symbol->l_exp, symbol->r_exp); |
70 | 589 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
590 |
ERROR; |
|
591 |
if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) |
|
592 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " * "); |
|
593 |
ERROR; |
|
594 |
return NULL; |
|
595 |
} |
|
596 |
||
597 |
void *visit(div_expression_c *symbol) { |
|
598 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
599 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
149 | 600 |
if ((typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_integer_type(right_type)) || |
601 |
(typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_real_type(right_type))) |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
602 |
return print_binary_function("__time_div", symbol->l_exp, symbol->r_exp); |
70 | 603 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
604 |
ERROR; |
|
605 |
if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) |
|
606 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " / "); |
|
607 |
ERROR; |
|
608 |
return NULL; |
|
609 |
} |
|
610 |
||
611 |
void *visit(mod_expression_c *symbol) { |
|
612 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
|
613 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
614 |
if (!search_expression_type->is_same_type(left_type, right_type)) |
|
615 |
ERROR; |
|
616 |
if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) { |
|
617 |
s4o.print("(("); |
|
618 |
symbol->r_exp->accept(*this); |
|
619 |
s4o.print(" == 0)?0:"); |
|
620 |
print_binary_expression(symbol->l_exp, symbol->r_exp, " % "); |
|
621 |
s4o.print(")"); |
|
622 |
return NULL; |
|
623 |
} |
|
624 |
ERROR; |
|
625 |
return NULL; |
|
626 |
} |
|
627 |
||
257 | 628 |
void *visit(power_expression_c *symbol) { |
349 | 629 |
symbol_c *left_type = search_expression_type->get_type(symbol->l_exp); |
630 |
symbol_c *right_type = search_expression_type->get_type(symbol->r_exp); |
|
631 |
if (search_expression_type->is_real_type(left_type) && search_expression_type->is_num_type(right_type)) { |
|
375 | 632 |
s4o.print("EXPT__LREAL__LREAL__LREAL((BOOL)__BOOL_LITERAL(TRUE),\n"); |
349 | 633 |
s4o.indent_right(); |
634 |
s4o.print(s4o.indent_spaces + "NULL,\n"); |
|
635 |
s4o.print(s4o.indent_spaces + "(LREAL)("); |
|
636 |
symbol->l_exp->accept(*this); |
|
637 |
s4o.print("),\n"); |
|
638 |
s4o.print(s4o.indent_spaces + "(LREAL)("); |
|
639 |
symbol->r_exp->accept(*this); |
|
640 |
s4o.print("))"); |
|
641 |
return NULL; |
|
642 |
} |
|
643 |
ERROR; |
|
358
a2c4af8f0c18
Add support for '**' (power) operator in ST expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
355
diff
changeset
|
644 |
return NULL; |
257 | 645 |
} |
646 |
||
123 | 647 |
void *visit(neg_expression_c *symbol) { |
257 | 648 |
return print_unary_expression(symbol->exp, " -"); |
123 | 649 |
} |
70 | 650 |
|
651 |
void *visit(not_expression_c *symbol) { |
|
652 |
symbol_c *exp_type = search_expression_type->get_type(symbol->exp); |
|
123 | 653 |
if (search_expression_type->is_binary_type(exp_type)) |
654 |
return print_unary_expression(symbol->exp, search_expression_type->is_bool_type(exp_type)?"!":"~"); |
|
655 |
ERROR; |
|
656 |
return NULL; |
|
70 | 657 |
} |
658 |
||
659 |
void *visit(function_invocation_c *symbol) { |
|
149 | 660 |
symbol_c* function_name = NULL; |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
661 |
DECLARE_PARAM_LIST() |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
662 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
663 |
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
|
664 |
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
|
665 |
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
|
666 |
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
|
667 |
|
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
668 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
669 |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
670 |
function_declaration_c *f_decl = (function_declaration_c *)symbol->called_function_declaration; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
671 |
if (f_decl == NULL) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
672 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
673 |
function_name = symbol->function_name; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
674 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
675 |
/* loop through each function parameter, find the value we should pass |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
676 |
* to it, and then output the c equivalent... |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
677 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
678 |
function_param_iterator_c fp_iterator(f_decl); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
679 |
identifier_c *param_name; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
680 |
/* flag to cirreclty handle calls to extensible standard functions (i.e. functions with variable number of input parameters) */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
681 |
bool found_first_extensible_parameter = false; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
682 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
683 |
if (fp_iterator.is_extensible_param() && (!found_first_extensible_parameter)) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
684 |
/* We are calling an extensible function. Before passing the extensible |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
685 |
* parameters, we must add a dummy paramater value to tell the called |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
686 |
* function how many extensible parameters we will be passing. |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
687 |
* |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
688 |
* Note that stage 3 has already determined the number of extensible |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
689 |
* paramters, and stored that info in the abstract syntax tree. We simply |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
690 |
* re-use that value. |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
691 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
692 |
/* NOTE: we are not freeing the malloc'd memory. This is not really a bug. |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
693 |
* Since we are writing a compiler, which runs to termination quickly, |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
694 |
* we can consider this as just memory required for the compilation process |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
695 |
* that will be free'd when the program terminates. |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
696 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
697 |
char *tmp = (char *)malloc(32); /* enough space for a call with 10^31 (larger than 2^64) input parameters! */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
698 |
if (tmp == NULL) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
699 |
int res = snprintf(tmp, 32, "%d", symbol->extensible_param_count); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
700 |
if ((res >= 32) || (res < 0)) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
701 |
identifier_c *param_value = new identifier_c(tmp); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
702 |
uint_type_name_c *param_type = new uint_type_name_c(); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
703 |
identifier_c *param_name = new identifier_c(""); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
704 |
ADD_PARAM_LIST(param_name, param_value, param_type, function_param_iterator_c::direction_in) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
705 |
found_first_extensible_parameter = true; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
706 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
707 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
708 |
if (fp_iterator.is_extensible_param()) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
709 |
/* since we are handling an extensible parameter, we must add the index to the |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
710 |
* parameter name so we can go looking for the value passed to the correct |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
711 |
* extended parameter (e.g. IN1, IN2, IN3, IN4, ...) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
712 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
713 |
char *tmp = (char *)malloc(32); /* enough space for a call with 10^31 (larger than 2^64) input parameters! */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
714 |
int res = snprintf(tmp, 32, "%d", fp_iterator.extensible_param_index()); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
715 |
if ((res >= 32) || (res < 0)) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
716 |
param_name = new identifier_c(strdup2(param_name->value, tmp)); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
717 |
if (param_name->value == NULL) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
718 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
719 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
720 |
symbol_c *param_type = fp_iterator.param_type(); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
721 |
if (param_type == NULL) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
722 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
723 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
724 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
725 |
symbol_c *param_value = NULL; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
726 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
727 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
728 |
if (param_value == NULL) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
729 |
param_value = function_call_param_iterator.search_f(param_name); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
730 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
731 |
/* Get the value from a foo(<param_value>) style call */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
732 |
if ((param_value == NULL) && !fp_iterator.is_en_eno_param_implicit()) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
733 |
param_value = function_call_param_iterator.next_nf(); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
734 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
735 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
736 |
/* if no more parameter values in function call, and the current parameter |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
737 |
* of the function declaration is an extensible parameter, we |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
738 |
* have reached the end, and should simply jump out of the for loop. |
70 | 739 |
*/ |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
740 |
if ((param_value == NULL) && (fp_iterator.is_extensible_param())) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
741 |
break; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
742 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
743 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
744 |
if ((param_value == NULL) && (param_direction == function_param_iterator_c::direction_in)) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
745 |
/* No value given for parameter, so we must use the default... */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
746 |
/* First check whether default value specified in function declaration...*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
747 |
param_value = fp_iterator.default_value(); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
748 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
749 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
750 |
ADD_PARAM_LIST(param_name, param_value, param_type, param_direction) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
751 |
} /* for(...) */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
752 |
// symbol->parameter_assignment->accept(*this); |
149 | 753 |
|
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
754 |
if (function_call_param_iterator.next_nf() != NULL) ERROR; |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
755 |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
756 |
bool has_output_params = false; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
757 |
|
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
758 |
if (!this->is_variable_prefix_null()) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
759 |
PARAM_LIST_ITERATOR() { |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
760 |
if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
761 |
PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
762 |
PARAM_VALUE != NULL) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
763 |
has_output_params = true; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
764 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
765 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
766 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
767 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
768 |
/* Check whether we are calling an overloaded function! */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
769 |
/* (fdecl_mutiplicity==2) => calling overloaded function */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
770 |
int fdecl_mutiplicity = function_symtable.multiplicity(symbol->function_name); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
771 |
if (fdecl_mutiplicity == 0) ERROR; |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
772 |
|
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
773 |
if (has_output_params) { |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
774 |
fcall_number++; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
775 |
s4o.print("__"); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
776 |
fbname->accept(*this); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
777 |
s4o.print("_"); |
149 | 778 |
function_name->accept(*this); |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
779 |
if (fdecl_mutiplicity == 2) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
780 |
/* function being called is overloaded! */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
781 |
s4o.print("__"); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
782 |
print_function_parameter_data_types_c overloaded_func_suf(&s4o); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
783 |
f_decl->accept(overloaded_func_suf); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
784 |
} |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
785 |
s4o.print_integer(fcall_number); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
786 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
787 |
else { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
788 |
function_name->accept(*this); |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
789 |
if (fdecl_mutiplicity == 2) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
790 |
/* function being called is overloaded! */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
791 |
s4o.print("__"); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
792 |
print_function_parameter_data_types_c overloaded_func_suf(&s4o); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
793 |
f_decl->accept(overloaded_func_suf); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
794 |
} |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
795 |
} |
149 | 796 |
s4o.print("("); |
797 |
s4o.indent_right(); |
|
798 |
||
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
799 |
int nb_param = 0; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
800 |
PARAM_LIST_ITERATOR() { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
801 |
symbol_c *param_value = PARAM_VALUE; |
235 | 802 |
current_param_type = PARAM_TYPE; |
149 | 803 |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
804 |
switch (PARAM_DIRECTION) { |
149 | 805 |
case function_param_iterator_c::direction_in: |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
806 |
if (nb_param > 0) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
807 |
s4o.print(",\n"+s4o.indent_spaces); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
808 |
if (param_value == NULL) { |
149 | 809 |
/* If not, get the default value of this variable's type */ |
235 | 810 |
param_value = (symbol_c *)current_param_type->accept(*type_initial_value_c::instance()); |
149 | 811 |
} |
812 |
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
|
813 |
s4o.print("("); |
235 | 814 |
if (search_expression_type->is_literal_integer_type(current_param_type)) |
220 | 815 |
search_expression_type->lint_type_name.accept(*this); |
235 | 816 |
else if (search_expression_type->is_literal_real_type(current_param_type)) |
220 | 817 |
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
|
818 |
else |
235 | 819 |
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
|
820 |
s4o.print(")"); |
235 | 821 |
print_check_function(current_param_type, param_value); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
822 |
nb_param++; |
149 | 823 |
break; |
824 |
case function_param_iterator_c::direction_out: |
|
825 |
case function_param_iterator_c::direction_inout: |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
826 |
if (!has_output_params) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
827 |
if (nb_param > 0) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
828 |
s4o.print(",\n"+s4o.indent_spaces); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
829 |
if (param_value == NULL) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
830 |
s4o.print("NULL"); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
831 |
else { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
832 |
wanted_variablegeneration = fparam_output_vg; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
833 |
param_value->accept(*this); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
834 |
wanted_variablegeneration = expression_vg; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
835 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
836 |
nb_param++; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
837 |
} |
149 | 838 |
break; |
839 |
case function_param_iterator_c::direction_extref: |
|
840 |
/* TODO! */ |
|
841 |
ERROR; |
|
842 |
break; |
|
843 |
} /* switch */ |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
844 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
845 |
if (has_output_params) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
846 |
if (nb_param > 0) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
847 |
s4o.print(",\n"+s4o.indent_spaces); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
848 |
s4o.print(FB_FUNCTION_PARAM); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
849 |
} |
149 | 850 |
s4o.print(")"); |
851 |
s4o.indent_left(); |
|
70 | 852 |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
853 |
CLEAR_PARAM_LIST() |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
854 |
|
70 | 855 |
return NULL; |
856 |
} |
|
857 |
||
858 |
/********************/ |
|
859 |
/* B 3.2 Statements */ |
|
860 |
/********************/ |
|
861 |
void *visit(statement_list_c *symbol) { |
|
862 |
return print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); |
|
863 |
} |
|
864 |
||
865 |
/*********************************/ |
|
866 |
/* B 3.2.1 Assignment Statements */ |
|
867 |
/*********************************/ |
|
868 |
void *visit(assignment_statement_c *symbol) { |
|
321
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
309
diff
changeset
|
869 |
symbol_c *left_type = search_varfb_instance_type->get_type_id(symbol->l_exp); |
98 | 870 |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
871 |
if (this->is_variable_prefix_null()) { |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
872 |
symbol->l_exp->accept(*this); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
873 |
s4o.print(" = "); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
874 |
print_check_function(left_type, symbol->r_exp); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
875 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
876 |
else { |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
877 |
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
|
878 |
} |
70 | 879 |
return NULL; |
880 |
} |
|
881 |
||
882 |
/*****************************************/ |
|
883 |
/* B 3.2.2 Subprogram Control Statements */ |
|
884 |
/*****************************************/ |
|
885 |
||
283
214d3fdee596
fixing C code generation of return_statement_c and exit_statement_c
Mario de Sousa <msousa@fe.up.pt>
parents:
282
diff
changeset
|
886 |
void *visit(return_statement_c *symbol) { |
214d3fdee596
fixing C code generation of return_statement_c and exit_statement_c
Mario de Sousa <msousa@fe.up.pt>
parents:
282
diff
changeset
|
887 |
s4o.print("goto "); s4o.print(END_LABEL); |
214d3fdee596
fixing C code generation of return_statement_c and exit_statement_c
Mario de Sousa <msousa@fe.up.pt>
parents:
282
diff
changeset
|
888 |
return NULL; |
214d3fdee596
fixing C code generation of return_statement_c and exit_statement_c
Mario de Sousa <msousa@fe.up.pt>
parents:
282
diff
changeset
|
889 |
} |
214d3fdee596
fixing C code generation of return_statement_c and exit_statement_c
Mario de Sousa <msousa@fe.up.pt>
parents:
282
diff
changeset
|
890 |
|
214d3fdee596
fixing C code generation of return_statement_c and exit_statement_c
Mario de Sousa <msousa@fe.up.pt>
parents:
282
diff
changeset
|
891 |
|
70 | 892 |
/* fb_name '(' [param_assignment_list] ')' */ |
893 |
/* param_assignment_list -> may be NULL ! */ |
|
894 |
//SYM_REF2(fb_invocation_c, fb_name, param_assignment_list) |
|
895 |
void *visit(fb_invocation_c *symbol) { |
|
896 |
TRACE("fb_invocation_c"); |
|
897 |
/* first figure out what is the name of the function block type of the function block being called... */ |
|
898 |
symbol_c *function_block_type_name = this->search_fb_instance_decl->get_type_name(symbol->fb_name); |
|
899 |
/* should never occur. The function block instance MUST have been declared... */ |
|
900 |
if (function_block_type_name == NULL) ERROR; |
|
901 |
||
902 |
/* Now find the declaration of the function block type being called... */ |
|
903 |
function_block_declaration_c *fb_decl = function_block_type_symtable.find_value(function_block_type_name); |
|
904 |
/* should never occur. The function block type being called MUST be in the symtable... */ |
|
905 |
if (fb_decl == function_block_type_symtable.end_value()) ERROR; |
|
906 |
||
907 |
/* loop through each function block parameter, find the value we should pass |
|
908 |
* to it, and then output the c equivalent... |
|
909 |
*/ |
|
910 |
function_param_iterator_c fp_iterator(fb_decl); |
|
911 |
identifier_c *param_name; |
|
912 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
913 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
914 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
160 | 915 |
|
162
60a124678842
Fixed typo in EN/ENO parameters handling for std library functions
etisserant
parents:
160
diff
changeset
|
916 |
/*fprintf(stderr, "param : %s\n", param_name->value);*/ |
160 | 917 |
|
70 | 918 |
/* 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
|
919 |
symbol_c *param_value = function_call_param_iterator.search_f(param_name); |
70 | 920 |
|
921 |
/* Get the value from a foo(<param_value>) style call */ |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
922 |
/* When using the informal invocation style, user can not pass values to EN or ENO parameters if these |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
923 |
* were implicitly defined! |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
924 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
925 |
if ((param_value == NULL) && !fp_iterator.is_en_eno_param_implicit()) |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
926 |
param_value = function_call_param_iterator.next_nf(); |
70 | 927 |
|
98 | 928 |
symbol_c *param_type = fp_iterator.param_type(); |
929 |
if (param_type == NULL) ERROR; |
|
930 |
||
70 | 931 |
/* now output the value assignment */ |
932 |
if (param_value != NULL) |
|
933 |
if ((param_direction == function_param_iterator_c::direction_in) || |
|
934 |
(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
|
935 |
if (this->is_variable_prefix_null()) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
936 |
symbol->fb_name->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
937 |
s4o.print("."); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
938 |
param_name->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
939 |
s4o.print(" = "); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
940 |
print_check_function(param_type, param_value); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
941 |
} |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
942 |
else { |
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
226
diff
changeset
|
943 |
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
|
944 |
} |
70 | 945 |
s4o.print(";\n" + s4o.indent_spaces); |
946 |
} |
|
947 |
} /* for(...) */ |
|
948 |
||
949 |
/* now call the function... */ |
|
950 |
function_block_type_name->accept(*this); |
|
951 |
s4o.print(FB_FUNCTION_SUFFIX); |
|
952 |
s4o.print("(&"); |
|
953 |
print_variable_prefix(); |
|
954 |
symbol->fb_name->accept(*this); |
|
955 |
s4o.print(")"); |
|
956 |
||
957 |
/* loop through each function parameter, find the variable to which |
|
958 |
* we should atribute the value of all output or inoutput parameters. |
|
959 |
*/ |
|
960 |
fp_iterator.reset(); |
|
961 |
function_call_param_iterator.reset(); |
|
962 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
963 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
964 |
||
965 |
/* 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
|
966 |
symbol_c *param_value = function_call_param_iterator.search_f(param_name); |
70 | 967 |
|
968 |
/* Get the value from a foo(<param_value>) style call */ |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
969 |
/* When using the informal invocation style, user can not pass values to EN or ENO parameters if these |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
970 |
* were implicitly defined! |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
971 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
972 |
if ((param_value == NULL) && !fp_iterator.is_en_eno_param_implicit()) |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
973 |
param_value = function_call_param_iterator.next_nf(); |
70 | 974 |
|
975 |
/* now output the value assignment */ |
|
976 |
if (param_value != NULL) |
|
977 |
if ((param_direction == function_param_iterator_c::direction_out) || |
|
978 |
(param_direction == function_param_iterator_c::direction_inout)) { |
|
321
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
309
diff
changeset
|
979 |
symbol_c *param_type = search_varfb_instance_type->get_type_id(param_value); |
240 | 980 |
s4o.print(";\n" + s4o.indent_spaces); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
981 |
if (this->is_variable_prefix_null()) { |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
982 |
param_value->accept(*this); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
983 |
s4o.print(" = "); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
984 |
print_check_function(param_type, param_name, symbol->fb_name); |
98 | 985 |
} |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
986 |
else { |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
987 |
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
|
988 |
} |
70 | 989 |
} |
990 |
} /* for(...) */ |
|
991 |
||
992 |
return NULL; |
|
993 |
} |
|
994 |
||
995 |
||
996 |
||
997 |
||
998 |
/* helper symbol for fb_invocation */ |
|
999 |
/* param_assignment_list ',' param_assignment */ |
|
1000 |
void *visit(param_assignment_list_c *symbol) { |
|
1001 |
TRACE("param_assignment_list_c"); |
|
1002 |
/* this should never be called... */ |
|
1003 |
ERROR; |
|
1004 |
return NULL; |
|
1005 |
// return print_list(symbol, "", ", "); |
|
1006 |
} |
|
1007 |
||
1008 |
||
1009 |
void *visit(input_variable_param_assignment_c *symbol) { |
|
1010 |
TRACE("input_variable_param_assignment_c"); |
|
1011 |
/* this should never be called... */ |
|
1012 |
ERROR; |
|
1013 |
return NULL; |
|
1014 |
/* |
|
1015 |
symbol->variable_name->accept(*this); |
|
1016 |
s4o.print(" = "); |
|
1017 |
symbol->expression->accept(*this); |
|
1018 |
return NULL; |
|
1019 |
*/ |
|
1020 |
} |
|
1021 |
||
1022 |
void *visit(output_variable_param_assignment_c *symbol) { |
|
1023 |
TRACE("output_variable_param_assignment_c"); |
|
1024 |
/* this should never be called... */ |
|
1025 |
ERROR; |
|
1026 |
return NULL; |
|
1027 |
/* |
|
1028 |
s4o.print(s4o.indent_spaces); |
|
1029 |
if (symbol->not_param != NULL) |
|
1030 |
symbol->not_param->accept(*this); |
|
1031 |
symbol->variable_name->accept(*this); |
|
1032 |
s4o.print(" => "); |
|
1033 |
symbol->variable->accept(*this); |
|
1034 |
return NULL; |
|
1035 |
*/ |
|
1036 |
} |
|
1037 |
||
1038 |
// TODO: the NOT symbol in function (block) calls... |
|
1039 |
void *visit(not_paramassign_c *symbol) { |
|
1040 |
TRACE("not_paramassign_c"); |
|
1041 |
/* this should never be called... */ |
|
1042 |
ERROR; |
|
1043 |
return NULL; |
|
1044 |
/* |
|
1045 |
s4o.print("NOT "); |
|
1046 |
return NULL; |
|
1047 |
*/ |
|
1048 |
} |
|
1049 |
||
1050 |
||
1051 |
/********************************/ |
|
1052 |
/* B 3.2.3 Selection Statements */ |
|
1053 |
/********************************/ |
|
1054 |
void *visit(if_statement_c *symbol) { |
|
1055 |
s4o.print("if ("); |
|
1056 |
symbol->expression->accept(*this); |
|
1057 |
s4o.print(") {\n"); |
|
1058 |
s4o.indent_right(); |
|
1059 |
symbol->statement_list->accept(*this); |
|
1060 |
s4o.indent_left(); |
|
1061 |
symbol->elseif_statement_list->accept(*this); |
|
1062 |
||
1063 |
if (symbol->else_statement_list != NULL) { |
|
1064 |
s4o.print(s4o.indent_spaces); s4o.print("} else {\n"); |
|
1065 |
s4o.indent_right(); |
|
1066 |
symbol->else_statement_list->accept(*this); |
|
1067 |
s4o.indent_left(); |
|
1068 |
} |
|
1069 |
s4o.print(s4o.indent_spaces); s4o.print("}"); |
|
1070 |
return NULL; |
|
1071 |
} |
|
1072 |
||
1073 |
/* helper symbol for if_statement */ |
|
1074 |
void *visit(elseif_statement_list_c *symbol) {return print_list(symbol);} |
|
1075 |
||
1076 |
/* helper symbol for elseif_statement_list */ |
|
1077 |
void *visit(elseif_statement_c *symbol) { |
|
1078 |
s4o.print(s4o.indent_spaces); s4o.print("} else if ("); |
|
1079 |
symbol->expression->accept(*this); |
|
1080 |
s4o.print(") {\n"); |
|
1081 |
s4o.indent_right(); |
|
1082 |
symbol->statement_list->accept(*this); |
|
1083 |
s4o.indent_left(); |
|
1084 |
return NULL; |
|
1085 |
} |
|
1086 |
||
1087 |
void *visit(case_statement_c *symbol) { |
|
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1088 |
symbol_c *expression_type = search_expression_type->get_type(symbol->expression); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1089 |
s4o.print("{\n"); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1090 |
s4o.indent_right(); |
376 | 1091 |
s4o.print(s4o.indent_spaces); |
1092 |
if (search_expression_type->is_literal_integer_type(expression_type)) |
|
1093 |
search_expression_type->lint_type_name.accept(*this); |
|
1094 |
else if (search_expression_type->is_literal_real_type(expression_type)) |
|
1095 |
search_expression_type->lreal_type_name.accept(*this); |
|
1096 |
else |
|
1097 |
expression_type->accept(*this); |
|
1098 |
s4o.print(" __case_expression = "); |
|
70 | 1099 |
symbol->expression->accept(*this); |
376 | 1100 |
s4o.print(";\n" + s4o.indent_spaces + "switch (__case_expression) {\n"); |
70 | 1101 |
s4o.indent_right(); |
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1102 |
wanted_casegeneration = single_cg; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1103 |
symbol->case_element_list->accept(*this); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1104 |
wanted_casegeneration = subrange_cg; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1105 |
s4o.print(s4o.indent_spaces + "default:\n"); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1106 |
s4o.indent_right(); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1107 |
first_subrange_case_list = true; |
70 | 1108 |
symbol->case_element_list->accept(*this); |
1109 |
if (symbol->statement_list != NULL) { |
|
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1110 |
if (!first_subrange_case_list) { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1111 |
s4o.print(s4o.indent_spaces + "else {\n"); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1112 |
s4o.indent_right(); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1113 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1114 |
symbol->statement_list->accept(*this); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1115 |
if (!first_subrange_case_list) { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1116 |
s4o.indent_left(); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1117 |
s4o.print(s4o.indent_spaces + "}\n"); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1118 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1119 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1120 |
s4o.print(s4o.indent_spaces + "break;\n"); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1121 |
s4o.indent_left(); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1122 |
wanted_casegeneration = none_cg; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1123 |
s4o.indent_left(); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1124 |
s4o.print(s4o.indent_spaces + "}\n"); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1125 |
s4o.indent_left(); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1126 |
s4o.print(s4o.indent_spaces + "}"); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1127 |
return NULL; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1128 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1129 |
|
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1130 |
/* helper symbol for case_statement */ |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1131 |
void *visit(case_element_list_c *symbol) {return print_list(symbol);} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1132 |
|
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1133 |
void *visit(case_element_c *symbol) { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1134 |
case_element_iterator_c *case_element_iterator; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1135 |
symbol_c* element = NULL; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1136 |
bool first_element = true; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1137 |
|
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1138 |
switch (wanted_casegeneration) { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1139 |
case single_cg: |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1140 |
case_element_iterator = new case_element_iterator_c(symbol->case_list, case_element_iterator_c::element_single); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1141 |
for (element = case_element_iterator->next(); element != NULL; element = case_element_iterator->next()) { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1142 |
if (first_element) first_element = false; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1143 |
s4o.print(s4o.indent_spaces + "case "); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1144 |
element->accept(*this); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1145 |
s4o.print(":\n"); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1146 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1147 |
delete case_element_iterator; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1148 |
break; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1149 |
|
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1150 |
case subrange_cg: |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1151 |
case_element_iterator = new case_element_iterator_c(symbol->case_list, case_element_iterator_c::element_subrange); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1152 |
for (element = case_element_iterator->next(); element != NULL; element = case_element_iterator->next()) { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1153 |
if (first_element) { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1154 |
if (first_subrange_case_list) { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1155 |
s4o.print(s4o.indent_spaces + "if ("); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1156 |
first_subrange_case_list = false; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1157 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1158 |
else { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1159 |
s4o.print(s4o.indent_spaces + "else if ("); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1160 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1161 |
first_element = false; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1162 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1163 |
else { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1164 |
s4o.print(" && "); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1165 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1166 |
element->accept(*this); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1167 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1168 |
delete case_element_iterator; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1169 |
if (!first_element) { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1170 |
s4o.print(") {\n"); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1171 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1172 |
break; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1173 |
|
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1174 |
default: |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1175 |
break; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1176 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1177 |
|
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1178 |
if (!first_element) { |
70 | 1179 |
s4o.indent_right(); |
1180 |
symbol->statement_list->accept(*this); |
|
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1181 |
switch (wanted_casegeneration) { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1182 |
case single_cg: |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1183 |
s4o.print(s4o.indent_spaces + "break;\n"); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1184 |
s4o.indent_left(); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1185 |
break; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1186 |
case subrange_cg: |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1187 |
s4o.indent_left(); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1188 |
s4o.print(s4o.indent_spaces + "}\n"); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1189 |
break; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1190 |
default: |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1191 |
break; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1192 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1193 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1194 |
return NULL; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1195 |
} |
70 | 1196 |
|
1197 |
/********************************/ |
|
1198 |
/* B 3.2.4 Iteration Statements */ |
|
1199 |
/********************************/ |
|
1200 |
void *visit(for_statement_c *symbol) { |
|
1201 |
s4o.print("for("); |
|
1202 |
symbol->control_variable->accept(*this); |
|
1203 |
s4o.print(" = "); |
|
1204 |
symbol->beg_expression->accept(*this); |
|
1205 |
s4o.print("; "); |
|
1206 |
symbol->control_variable->accept(*this); |
|
1207 |
s4o.print(" != "); |
|
1208 |
symbol->end_expression->accept(*this); |
|
1209 |
s4o.print("; "); |
|
1210 |
symbol->control_variable->accept(*this); |
|
1211 |
if (symbol->by_expression != NULL) { |
|
1212 |
s4o.print(" += "); |
|
1213 |
symbol->by_expression->accept(*this); |
|
1214 |
} else { |
|
1215 |
s4o.print("++"); |
|
1216 |
} |
|
1217 |
s4o.print(") {\n"); |
|
1218 |
s4o.indent_right(); |
|
1219 |
symbol->statement_list->accept(*this); |
|
1220 |
s4o.indent_left(); |
|
1221 |
s4o.print(s4o.indent_spaces); s4o.print("}"); |
|
1222 |
return NULL; |
|
1223 |
} |
|
1224 |
void *visit(while_statement_c *symbol) { |
|
1225 |
s4o.print("while ("); |
|
1226 |
symbol->expression->accept(*this); |
|
1227 |
s4o.print(") {\n"); |
|
1228 |
s4o.indent_right(); |
|
1229 |
symbol->statement_list->accept(*this); |
|
1230 |
s4o.indent_left(); |
|
1231 |
s4o.print(s4o.indent_spaces); s4o.print("}"); |
|
1232 |
return NULL; |
|
1233 |
} |
|
1234 |
void *visit(repeat_statement_c *symbol) { |
|
1235 |
s4o.print("do {\n"); |
|
1236 |
s4o.indent_right(); |
|
1237 |
symbol->statement_list->accept(*this); |
|
1238 |
s4o.indent_left(); |
|
1239 |
s4o.print(s4o.indent_spaces); s4o.print("} while("); |
|
1240 |
symbol->expression->accept(*this); |
|
1241 |
s4o.print(")"); |
|
1242 |
return NULL; |
|
1243 |
} |
|
1244 |
void *visit(exit_statement_c *symbol) { |
|
281
686fa44e3832
fixing exit_statement_c: produce 'break' instead of 'exit(0); (Thanks to Manuele)
Mario de Sousa <msousa@fe.up.pt>
parents:
258
diff
changeset
|
1245 |
s4o.print("break"); |
70 | 1246 |
return NULL; |
1247 |
} |
|
1248 |
||
1249 |
||
1250 |
||
1251 |
}; /* generate_c_st_c */ |
|
1252 |
||
1253 |
||
1254 |
||
1255 |
||
1256 |
||
1257 |
||
1258 |
||
1259 |
||
1260 |