author | laurent |
Fri, 08 Jul 2011 11:06:27 +0200 | |
changeset 336 | 229eb3e29216 |
parent 332 | 0f1d91a37506 |
child 337 | 9a2262fb7994 |
child 350 | 2c3c4dc34979 |
permissions | -rwxr-xr-x |
219 | 1 |
/* |
279
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
238
diff
changeset
|
2 |
* matiec - a compiler for the programming languages defined in IEC 61131-3 |
219 | 3 |
* |
279
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
238
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:
238
diff
changeset
|
5 |
* Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant |
219 | 6 |
* |
279
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
238
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:
238
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:
238
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:
238
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:
238
diff
changeset
|
11 |
* |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
238
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:
238
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:
238
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:
238
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:
238
diff
changeset
|
16 |
* |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
238
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:
238
diff
changeset
|
18 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
238
diff
changeset
|
19 |
* |
219 | 20 |
* |
21 |
* This code is made available on the understanding that it will not be |
|
22 |
* used in safety-critical situations without a full and competent review. |
|
23 |
*/ |
|
24 |
||
25 |
||
26 |
#define INLINE_RESULT_TEMP_VAR "__res" |
|
27 |
||
234
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
28 |
class generate_c_inlinefcall_c: public generate_c_typedecl_c { |
219 | 29 |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
30 |
public: |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
31 |
typedef enum { |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
32 |
expression_vg, |
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
33 |
assignment_vg, |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
34 |
complextype_base_vg, |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
35 |
complextype_suffix_vg |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
36 |
} variablegeneration_t; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
37 |
|
219 | 38 |
private: |
39 |
||
40 |
/* The name of the IL default variable... */ |
|
41 |
#define IL_DEFVAR VAR_LEADER "IL_DEFVAR" |
|
42 |
/* The name of the variable used to pass the result of a |
|
43 |
* parenthesised instruction list to the immediately preceding |
|
44 |
* scope ... |
|
45 |
*/ |
|
46 |
il_default_variable_c default_variable_name; |
|
47 |
||
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
48 |
symbol_c* current_array_type; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
49 |
|
219 | 50 |
int fcall_number; |
51 |
symbol_c *fbname; |
|
52 |
||
53 |
search_expression_type_c *search_expression_type; |
|
54 |
||
55 |
search_varfb_instance_type_c *search_varfb_instance_type; |
|
56 |
||
57 |
search_base_type_c search_base_type; |
|
58 |
||
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
59 |
variablegeneration_t wanted_variablegeneration; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
60 |
|
219 | 61 |
public: |
234
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
62 |
generate_c_inlinefcall_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL) |
219 | 63 |
: generate_c_typedecl_c(s4o_ptr), |
64 |
default_variable_name(IL_DEFVAR, NULL) |
|
65 |
{ |
|
66 |
search_expression_type = new search_expression_type_c(scope); |
|
67 |
search_varfb_instance_type = new search_varfb_instance_type_c(scope); |
|
68 |
this->set_variable_prefix(variable_prefix); |
|
69 |
fcall_number = 0; |
|
70 |
fbname = name; |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
71 |
wanted_variablegeneration = expression_vg; |
219 | 72 |
} |
73 |
||
234
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
74 |
virtual ~generate_c_inlinefcall_c(void) { |
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
75 |
delete search_expression_type; |
219 | 76 |
delete search_varfb_instance_type; |
77 |
} |
|
78 |
||
234
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
79 |
void print(symbol_c* symbol) { |
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
80 |
function_call_iterator_c fc_iterator(symbol); |
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
81 |
symbol_c* function_call; |
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
82 |
while ((function_call = fc_iterator.next()) != NULL) { |
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
83 |
function_call->accept(*this); |
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
84 |
} |
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
85 |
} |
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
86 |
|
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
87 |
void generate_inline(symbol_c *function_name, |
235 | 88 |
symbol_c *function_type_prefix, |
89 |
symbol_c *function_type_suffix, |
|
234
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
90 |
std::list<FUNCTION_PARAM*> param_list) { |
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
91 |
std::list<FUNCTION_PARAM*>::iterator pt; |
219 | 92 |
|
93 |
fcall_number++; |
|
336 | 94 |
function_type_prefix = search_expression_type->default_literal_type(function_type_prefix); |
95 |
if (function_type_suffix) { |
|
96 |
function_type_suffix = search_expression_type->default_literal_type(function_type_suffix); |
|
332
0f1d91a37506
Fix bug in inline function calls when using function with undetermined type interface with literals as input
laurent
parents:
321
diff
changeset
|
97 |
} |
219 | 98 |
|
99 |
s4o.print(s4o.indent_spaces); |
|
100 |
s4o.print("inline "); |
|
235 | 101 |
function_type_prefix->accept(*this); |
219 | 102 |
s4o.print(" __"); |
103 |
fbname->accept(*this); |
|
104 |
s4o.print("_"); |
|
105 |
function_name->accept(*this); |
|
336 | 106 |
if (function_type_suffix) { |
107 |
function_type_suffix->accept(*this); |
|
108 |
} |
|
219 | 109 |
s4o.print_integer(fcall_number); |
110 |
s4o.print("("); |
|
111 |
s4o.indent_right(); |
|
112 |
||
113 |
PARAM_LIST_ITERATOR() { |
|
114 |
if (PARAM_DIRECTION == function_param_iterator_c::direction_in) { |
|
336 | 115 |
search_expression_type->default_literal_type(PARAM_TYPE)->accept(*this); |
219 | 116 |
s4o.print(" "); |
117 |
PARAM_NAME->accept(*this); |
|
118 |
s4o.print(",\n" + s4o.indent_spaces); |
|
119 |
} |
|
120 |
} |
|
121 |
fbname->accept(*this); |
|
122 |
s4o.print(" *"); |
|
123 |
s4o.print(FB_FUNCTION_PARAM); |
|
124 |
s4o.indent_left(); |
|
125 |
s4o.print(")\n" + s4o.indent_spaces); |
|
126 |
s4o.print("{\n"); |
|
127 |
s4o.indent_right(); |
|
128 |
||
129 |
s4o.print(s4o.indent_spaces); |
|
235 | 130 |
function_type_prefix->accept(*this); |
219 | 131 |
s4o.print(" "), |
132 |
s4o.print(INLINE_RESULT_TEMP_VAR); |
|
133 |
s4o.print(";\n"); |
|
134 |
||
135 |
PARAM_LIST_ITERATOR() { |
|
136 |
if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
|
137 |
PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
|
138 |
PARAM_VALUE != NULL) { |
|
139 |
s4o.print(s4o.indent_spaces); |
|
140 |
PARAM_TYPE->accept(*this); |
|
141 |
s4o.print(" "); |
|
142 |
s4o.print(TEMP_VAR); |
|
143 |
PARAM_NAME->accept(*this); |
|
144 |
s4o.print(" = "); |
|
145 |
print_check_function(PARAM_TYPE, PARAM_VALUE); |
|
146 |
s4o.print(";\n"); |
|
147 |
} |
|
148 |
} |
|
149 |
||
150 |
s4o.print(s4o.indent_spaces + INLINE_RESULT_TEMP_VAR), |
|
151 |
s4o.print(" = "); |
|
152 |
function_name->accept(*this); |
|
235 | 153 |
if (function_type_suffix) |
154 |
function_type_suffix->accept(*this); |
|
219 | 155 |
s4o.print("("); |
156 |
s4o.indent_right(); |
|
157 |
||
158 |
PARAM_LIST_ITERATOR() { |
|
159 |
if (pt != param_list.begin()) |
|
160 |
s4o.print(",\n" + s4o.indent_spaces); |
|
161 |
if (PARAM_DIRECTION == function_param_iterator_c::direction_in) |
|
162 |
PARAM_NAME->accept(*this); |
|
163 |
else if (PARAM_VALUE != NULL){ |
|
164 |
s4o.print("&"); |
|
165 |
s4o.print(TEMP_VAR); |
|
166 |
PARAM_NAME->accept(*this); |
|
167 |
} |
|
168 |
else { |
|
169 |
s4o.print("NULL"); |
|
170 |
} |
|
171 |
} |
|
172 |
s4o.print(");\n"); |
|
173 |
s4o.indent_left(); |
|
174 |
||
175 |
PARAM_LIST_ITERATOR() { |
|
176 |
if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
|
177 |
PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
|
178 |
PARAM_VALUE != NULL) { |
|
179 |
||
180 |
s4o.print(s4o.indent_spaces); |
|
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
181 |
print_setter(PARAM_VALUE, PARAM_TYPE, PARAM_NAME); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
182 |
s4o.print(";\n"); |
219 | 183 |
} |
184 |
} |
|
185 |
s4o.print(s4o.indent_spaces + "return "); |
|
186 |
s4o.print(INLINE_RESULT_TEMP_VAR); |
|
187 |
s4o.print(";\n"); |
|
188 |
||
189 |
s4o.indent_left(); |
|
190 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
|
191 |
} |
|
192 |
||
193 |
private: |
|
194 |
||
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
195 |
void *print_getter(symbol_c *symbol) { |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
196 |
unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
197 |
if (vartype == search_var_instance_decl_c::external_vt) |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
198 |
s4o.print(GET_EXTERNAL); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
199 |
else if (vartype == search_var_instance_decl_c::located_vt) |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
200 |
s4o.print(GET_LOCATED); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
201 |
else |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
202 |
s4o.print(GET_VAR); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
203 |
s4o.print("("); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
204 |
|
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
205 |
wanted_variablegeneration = complextype_base_vg; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
206 |
symbol->accept(*this); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
207 |
if (search_varfb_instance_type->type_is_complex()) |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
208 |
s4o.print(","); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
209 |
wanted_variablegeneration = complextype_suffix_vg; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
210 |
symbol->accept(*this); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
211 |
s4o.print(")"); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
212 |
wanted_variablegeneration = expression_vg; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
213 |
return NULL; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
214 |
} |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
215 |
|
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
216 |
void *print_setter(symbol_c* symbol, |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
217 |
symbol_c* type, |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
218 |
symbol_c* value) { |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
219 |
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
|
220 |
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
|
221 |
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
|
222 |
/* 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
|
223 |
if (variable != NULL) { |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
224 |
s4o.print(SET_EXTERNAL); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
225 |
s4o.print("("); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
226 |
variable->var_name->accept(*this); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
227 |
s4o.print(","); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
228 |
} |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
229 |
else { |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
230 |
s4o.print(SET_COMPLEX_EXTERNAL); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
231 |
s4o.print("("); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
232 |
} |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
233 |
} |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
234 |
else { |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
235 |
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
|
236 |
s4o.print(SET_LOCATED); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
237 |
else |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
238 |
s4o.print(SET_VAR); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
239 |
s4o.print("("); |
b8527b0abe75
Adding support for forcing global without perturbation from setting external
laurent
parents:
228
diff
changeset
|
240 |
} |
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
241 |
|
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
242 |
wanted_variablegeneration = complextype_base_vg; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
243 |
symbol->accept(*this); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
244 |
s4o.print(","); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
245 |
wanted_variablegeneration = expression_vg; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
246 |
print_check_function(type, value, NULL, true); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
247 |
if (search_varfb_instance_type->type_is_complex()) { |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
248 |
s4o.print(","); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
249 |
wanted_variablegeneration = complextype_suffix_vg; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
250 |
symbol->accept(*this); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
251 |
} |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
252 |
s4o.print(")"); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
253 |
wanted_variablegeneration = expression_vg; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
254 |
return NULL; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
255 |
} |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
256 |
|
219 | 257 |
/*********************/ |
258 |
/* B 1.4 - Variables */ |
|
259 |
/*********************/ |
|
260 |
void *visit(symbolic_variable_c *symbol) { |
|
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
261 |
unsigned int vartype; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
262 |
if (wanted_variablegeneration == complextype_base_vg) |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
263 |
generate_c_base_c::visit(symbol); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
264 |
else if (wanted_variablegeneration == complextype_suffix_vg) |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
265 |
return NULL; |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
266 |
else |
235 | 267 |
print_getter(symbol); |
219 | 268 |
return NULL; |
269 |
} |
|
270 |
||
271 |
/********************************************/ |
|
272 |
/* B.1.4.1 Directly Represented Variables */ |
|
273 |
/********************************************/ |
|
274 |
// direct_variable: direct_variable_token {$$ = new direct_variable_c($1);}; |
|
275 |
void *visit(direct_variable_c *symbol) { |
|
276 |
TRACE("direct_variable_c"); |
|
277 |
/* Do not use print_token() as it will change everything into uppercase */ |
|
278 |
if (strlen(symbol->value) == 0) ERROR; |
|
279 |
s4o.print(GET_LOCATED); |
|
280 |
s4o.print("("); |
|
281 |
this->print_variable_prefix(); |
|
282 |
s4o.printlocation(symbol->value + 1); |
|
283 |
s4o.print(")"); |
|
284 |
return NULL; |
|
285 |
} |
|
286 |
||
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
287 |
/*************************************/ |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
288 |
/* B.1.4.2 Multi-element Variables */ |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
289 |
/*************************************/ |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
290 |
|
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
291 |
// SYM_REF2(structured_variable_c, record_variable, field_selector) |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
292 |
void *visit(structured_variable_c *symbol) { |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
293 |
TRACE("structured_variable_c"); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
294 |
switch (wanted_variablegeneration) { |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
295 |
case complextype_base_vg: |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
296 |
symbol->record_variable->accept(*this); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
297 |
break; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
298 |
case complextype_suffix_vg: |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
299 |
symbol->record_variable->accept(*this); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
300 |
s4o.print("."); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
301 |
symbol->field_selector->accept(*this); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
302 |
break; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
303 |
default: |
237 | 304 |
print_getter(symbol); |
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
305 |
break; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
306 |
} |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
307 |
return NULL; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
308 |
} |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
309 |
|
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
310 |
/* subscripted_variable '[' subscript_list ']' */ |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
311 |
//SYM_REF2(array_variable_c, subscripted_variable, subscript_list) |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
312 |
void *visit(array_variable_c *symbol) { |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
313 |
switch (wanted_variablegeneration) { |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
314 |
case complextype_base_vg: |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
315 |
symbol->subscripted_variable->accept(*this); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
316 |
break; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
317 |
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
|
318 |
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
|
319 |
|
321
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
320 |
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
|
321 |
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
|
322 |
|
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
323 |
s4o.print(".table"); |
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
324 |
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
|
325 |
|
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
326 |
current_array_type = NULL; |
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
327 |
break; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
328 |
default: |
237 | 329 |
print_getter(symbol); |
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
330 |
break; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
331 |
} |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
332 |
return NULL; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
333 |
} |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
334 |
|
219 | 335 |
/****************************************/ |
336 |
/* B.2 - Language IL (Instruction List) */ |
|
337 |
/****************************************/ |
|
338 |
||
339 |
/***********************************/ |
|
340 |
/* B 2.1 Instructions and Operands */ |
|
341 |
/***********************************/ |
|
342 |
||
343 |
void *visit(il_function_call_c *symbol) { |
|
235 | 344 |
symbol_c* function_type_prefix = NULL; |
345 |
symbol_c* function_name = NULL; |
|
346 |
symbol_c* function_type_suffix = NULL; |
|
347 |
DECLARE_PARAM_LIST() |
|
348 |
||
349 |
symbol_c *param_data_type = default_variable_name.current_type; |
|
350 |
||
351 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
352 |
||
353 |
function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
|
354 |
if (f_decl == function_symtable.end_value()) { |
|
355 |
function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
|
356 |
if (current_function_type == function_none) ERROR; |
|
357 |
||
358 |
function_type_prefix = (symbol_c *)search_expression_type->compute_standard_function_il(symbol, param_data_type); |
|
359 |
||
360 |
symbol_c *en_param_name = (symbol_c *)(new identifier_c("EN")); |
|
361 |
/* Add the value from EN param */ |
|
362 |
ADD_PARAM_LIST(en_param_name, |
|
363 |
(symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())), |
|
364 |
(symbol_c*)(new bool_type_name_c()), |
|
365 |
function_param_iterator_c::direction_in) |
|
366 |
||
367 |
symbol_c *eno_param_name = (symbol_c *)(new identifier_c("ENO")); |
|
368 |
/* Add the value from ENO param */ |
|
369 |
ADD_PARAM_LIST(eno_param_name, NULL, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
|
370 |
||
371 |
int nb_param = 1; |
|
372 |
if (symbol->il_operand_list != NULL) |
|
373 |
nb_param += ((list_c *)symbol->il_operand_list)->n; |
|
374 |
||
375 |
#include "il_code_gen.c" |
|
376 |
||
377 |
} |
|
378 |
else { |
|
379 |
function_name = symbol->function_name; |
|
219 | 380 |
|
381 |
/* determine the base data type returned by the function being called... */ |
|
382 |
search_base_type_c search_base_type; |
|
235 | 383 |
function_type_prefix = (symbol_c *)f_decl->type_name->accept(search_base_type); |
219 | 384 |
|
385 |
/* loop through each function parameter, find the value we should pass |
|
386 |
* to it, and then output the c equivalent... |
|
387 |
*/ |
|
388 |
||
389 |
function_param_iterator_c fp_iterator(f_decl); |
|
390 |
identifier_c *param_name; |
|
391 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
392 |
symbol_c *param_type = fp_iterator.param_type(); |
|
393 |
if (param_type == NULL) ERROR; |
|
394 |
||
395 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
396 |
||
397 |
symbol_c *param_value = NULL; |
|
398 |
||
399 |
/* if it is the first parameter, semantics specifies that we should |
|
400 |
* get the value off the IL default variable! |
|
401 |
*/ |
|
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
402 |
if (1 == i) |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
403 |
param_value = &this->default_variable_name; |
219 | 404 |
|
405 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
|
406 |
/* NOTE: the following line of code is not required in this case, but it doesn't |
|
407 |
* harm to leave it in, as in the case of a non-formal syntax function call, |
|
408 |
* it will always return NULL. |
|
409 |
* We leave it in in case we later decide to merge this part of the code together |
|
410 |
* with the function calling code in generate_c_st_c, which does require |
|
411 |
* the following line... |
|
412 |
*/ |
|
413 |
if (param_value == NULL) |
|
414 |
param_value = function_call_param_iterator.search_f(param_name); |
|
415 |
||
416 |
/* Get the value from a foo(<param_value>) style call */ |
|
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
417 |
if (param_value == NULL) { |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
418 |
param_value = function_call_param_iterator.next_nf(); |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
419 |
if (param_value != NULL && fp_iterator.is_en_eno_param_implicit()) ERROR; |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
420 |
} |
219 | 421 |
|
422 |
if (param_value == NULL && param_direction == function_param_iterator_c::direction_in) { |
|
423 |
/* No value given for parameter, so we must use the default... */ |
|
424 |
/* First check whether default value specified in function declaration...*/ |
|
425 |
param_value = fp_iterator.default_value(); |
|
426 |
} |
|
427 |
||
428 |
ADD_PARAM_LIST(param_name, param_value, param_type, fp_iterator.param_direction()) |
|
429 |
} /* for(...) */ |
|
430 |
} |
|
235 | 431 |
|
432 |
if (function_call_param_iterator.next_nf() != NULL) ERROR; |
|
433 |
if (NULL == function_type_prefix) ERROR; |
|
434 |
||
435 |
bool has_output_params = false; |
|
436 |
||
437 |
PARAM_LIST_ITERATOR() { |
|
438 |
if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
|
439 |
PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
|
440 |
PARAM_VALUE != NULL) { |
|
441 |
has_output_params = true; |
|
442 |
} |
|
443 |
} |
|
444 |
||
445 |
if (has_output_params) |
|
446 |
generate_inline(function_name, function_type_prefix, function_type_suffix, param_list); |
|
447 |
||
448 |
CLEAR_PARAM_LIST() |
|
449 |
||
450 |
return NULL; |
|
451 |
} |
|
452 |
||
453 |
/* | function_name '(' eol_list [il_param_list] ')' */ |
|
454 |
// SYM_REF2(il_formal_funct_call_c, function_name, il_param_list) |
|
219 | 455 |
void *visit(il_formal_funct_call_c *symbol) { |
235 | 456 |
symbol_c* function_type_prefix = NULL; |
457 |
symbol_c* function_name = NULL; |
|
458 |
symbol_c* function_type_suffix = NULL; |
|
459 |
DECLARE_PARAM_LIST() |
|
460 |
||
461 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
462 |
||
463 |
function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
|
464 |
if (f_decl == function_symtable.end_value()) { |
|
465 |
function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
|
466 |
if (current_function_type == function_none) ERROR; |
|
467 |
||
468 |
function_type_prefix = (symbol_c *)search_expression_type->compute_standard_function_default(NULL, symbol); |
|
469 |
||
470 |
int nb_param = 0; |
|
471 |
if (symbol->il_param_list != NULL) |
|
472 |
nb_param += ((list_c *)symbol->il_param_list)->n; |
|
473 |
||
474 |
symbol_c *en_param_name = (symbol_c *)(new identifier_c("EN")); |
|
475 |
/* Get the value from EN param */ |
|
476 |
symbol_c *EN_param_value = function_call_param_iterator.search_f(en_param_name); |
|
477 |
if (EN_param_value == NULL) |
|
478 |
EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())); |
|
479 |
else |
|
480 |
nb_param --; |
|
481 |
ADD_PARAM_LIST(en_param_name, EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in) |
|
482 |
||
483 |
symbol_c *eno_param_name = (symbol_c *)(new identifier_c("ENO")); |
|
484 |
/* Get the value from ENO param */ |
|
485 |
symbol_c *ENO_param_value = function_call_param_iterator.search_f(eno_param_name); |
|
486 |
if (ENO_param_value != NULL) |
|
487 |
nb_param --; |
|
488 |
ADD_PARAM_LIST(eno_param_name, ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
|
489 |
||
490 |
#include "st_code_gen.c" |
|
491 |
||
492 |
} |
|
493 |
else { |
|
494 |
function_name = symbol->function_name; |
|
219 | 495 |
|
496 |
/* determine the base data type returned by the function being called... */ |
|
497 |
search_base_type_c search_base_type; |
|
235 | 498 |
function_type_prefix = (symbol_c *)f_decl->type_name->accept(search_base_type); |
219 | 499 |
|
500 |
/* loop through each function parameter, find the value we should pass |
|
501 |
* to it, and then output the c equivalent... |
|
502 |
*/ |
|
503 |
||
504 |
function_param_iterator_c fp_iterator(f_decl); |
|
505 |
identifier_c *param_name; |
|
506 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
507 |
symbol_c *param_type = fp_iterator.param_type(); |
|
508 |
if (param_type == NULL) ERROR; |
|
509 |
||
510 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
511 |
||
512 |
||
513 |
symbol_c *param_value = NULL; |
|
514 |
||
515 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
|
516 |
if (param_value == NULL) |
|
517 |
param_value = function_call_param_iterator.search_f(param_name); |
|
518 |
||
519 |
/* Get the value from a foo(<param_value>) style call */ |
|
520 |
/* NOTE: the following line of code is not required in this case, but it doesn't |
|
521 |
* harm to leave it in, as in the case of a formal syntax function call, |
|
522 |
* it will always return NULL. |
|
523 |
* We leave it in in case we later decide to merge this part of the code together |
|
524 |
* with the function calling code in generate_c_st_c, which does require |
|
525 |
* the following line... |
|
526 |
*/ |
|
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
527 |
if (param_value == NULL) { |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
528 |
param_value = function_call_param_iterator.next_nf(); |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
529 |
if (param_value != NULL && fp_iterator.is_en_eno_param_implicit()) ERROR; |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
530 |
} |
219 | 531 |
|
532 |
if (param_value == NULL) { |
|
533 |
/* No value given for parameter, so we must use the default... */ |
|
534 |
/* First check whether default value specified in function declaration...*/ |
|
535 |
param_value = fp_iterator.default_value(); |
|
536 |
} |
|
537 |
||
538 |
ADD_PARAM_LIST(param_name, param_value, param_type, fp_iterator.param_direction()) |
|
539 |
} |
|
235 | 540 |
} |
541 |
||
542 |
if (function_call_param_iterator.next_nf() != NULL) ERROR; |
|
543 |
if (NULL == function_type_prefix) ERROR; |
|
544 |
||
545 |
bool has_output_params = false; |
|
546 |
||
547 |
PARAM_LIST_ITERATOR() { |
|
548 |
if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
|
549 |
PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
|
550 |
PARAM_VALUE != NULL) { |
|
551 |
has_output_params = true; |
|
219 | 552 |
} |
235 | 553 |
} |
554 |
||
555 |
if (has_output_params) |
|
556 |
generate_inline(function_name, function_type_prefix, function_type_suffix, param_list); |
|
557 |
||
558 |
CLEAR_PARAM_LIST() |
|
559 |
||
219 | 560 |
return NULL; |
561 |
} |
|
562 |
||
563 |
/***************************************/ |
|
564 |
/* B.3 - Language ST (Structured Text) */ |
|
565 |
/***************************************/ |
|
566 |
/***********************/ |
|
567 |
/* B 3.1 - Expressions */ |
|
568 |
/***********************/ |
|
569 |
||
570 |
void *visit(function_invocation_c *symbol) { |
|
235 | 571 |
symbol_c* function_type_prefix = NULL; |
572 |
symbol_c* function_name = NULL; |
|
573 |
symbol_c* function_type_suffix = NULL; |
|
574 |
DECLARE_PARAM_LIST() |
|
575 |
||
576 |
symbol_c *parameter_assignment_list = NULL; |
|
577 |
if (NULL != symbol-> formal_param_list) parameter_assignment_list = symbol-> formal_param_list; |
|
578 |
if (NULL != symbol->nonformal_param_list) parameter_assignment_list = symbol->nonformal_param_list; |
|
579 |
if (NULL == parameter_assignment_list) ERROR; |
|
580 |
||
581 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
582 |
||
219 | 583 |
function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
235 | 584 |
if (f_decl == function_symtable.end_value()) { |
585 |
/* The function called is not in the symtable, so we test if it is a |
|
586 |
* standard function defined in standard */ |
|
587 |
||
588 |
function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
|
589 |
if (current_function_type == function_none) ERROR; |
|
590 |
||
591 |
function_type_prefix = search_expression_type->get_type(symbol); |
|
592 |
||
593 |
int nb_param = ((list_c *)parameter_assignment_list)->n; |
|
594 |
||
595 |
symbol_c *en_param_name = (symbol_c *)(new identifier_c("EN")); |
|
596 |
/* Get the value from EN param */ |
|
597 |
symbol_c *EN_param_value = function_call_param_iterator.search_f(en_param_name); |
|
598 |
if (EN_param_value == NULL) |
|
599 |
EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())); |
|
600 |
else |
|
601 |
nb_param --; |
|
602 |
ADD_PARAM_LIST(en_param_name, EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in) |
|
603 |
||
604 |
symbol_c *eno_param_name = (symbol_c *)(new identifier_c("ENO")); |
|
605 |
/* Get the value from ENO param */ |
|
606 |
symbol_c *ENO_param_value = function_call_param_iterator.search_f(eno_param_name); |
|
607 |
if (ENO_param_value != NULL) |
|
608 |
nb_param --; |
|
609 |
ADD_PARAM_LIST(eno_param_name, ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
|
610 |
||
611 |
#include "st_code_gen.c" |
|
612 |
||
613 |
} |
|
614 |
else { |
|
615 |
function_name = symbol->function_name; |
|
219 | 616 |
|
617 |
/* determine the base data type returned by the function being called... */ |
|
618 |
search_base_type_c search_base_type; |
|
235 | 619 |
function_type_prefix = (symbol_c *)f_decl->type_name->accept(search_base_type); |
219 | 620 |
|
621 |
/* loop through each function parameter, find the value we should pass |
|
622 |
* to it, and then output the c equivalent... |
|
623 |
*/ |
|
624 |
function_param_iterator_c fp_iterator(f_decl); |
|
625 |
identifier_c *param_name; |
|
626 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
627 |
symbol_c *param_type = fp_iterator.param_type(); |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
628 |
if (param_type == NULL) ERROR; |
219 | 629 |
|
630 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
631 |
||
632 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
|
633 |
symbol_c *param_value = function_call_param_iterator.search_f(param_name); |
|
634 |
||
635 |
/* Get the value from a foo(<param_value>) style call */ |
|
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
636 |
if (param_value == NULL) { |
219 | 637 |
param_value = function_call_param_iterator.next_nf(); |
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
638 |
if (param_value != NULL && fp_iterator.is_en_eno_param_implicit()) ERROR; |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
639 |
} |
219 | 640 |
|
641 |
if (param_value == NULL && param_direction == function_param_iterator_c::direction_in) { |
|
642 |
/* No value given for parameter, so we must use the default... */ |
|
643 |
/* First check whether default value specified in function declaration...*/ |
|
644 |
param_value = fp_iterator.default_value(); |
|
645 |
} |
|
646 |
||
647 |
ADD_PARAM_LIST(param_name, param_value, param_type, param_direction) |
|
648 |
} /* for(...) */ |
|
649 |
// symbol->parameter_assignment->accept(*this); |
|
235 | 650 |
} |
651 |
||
652 |
if (function_call_param_iterator.next_nf() != NULL) ERROR; |
|
653 |
if (NULL == function_type_prefix) ERROR; |
|
654 |
||
655 |
bool has_output_params = false; |
|
656 |
||
657 |
PARAM_LIST_ITERATOR() { |
|
658 |
if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
|
659 |
PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
|
660 |
PARAM_VALUE != NULL) { |
|
661 |
has_output_params = true; |
|
219 | 662 |
} |
235 | 663 |
} |
664 |
||
665 |
if (has_output_params) |
|
666 |
generate_inline(function_name, function_type_prefix, function_type_suffix, param_list); |
|
667 |
||
668 |
CLEAR_PARAM_LIST() |
|
669 |
||
219 | 670 |
return NULL; |
671 |
} |
|
672 |
||
234
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
673 |
}; /* generate_c_inlinefcall_c */ |
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
674 |
|
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
675 |