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