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