author | laurent |
Wed, 02 Dec 2009 16:11:01 +0100 | |
changeset 221 | c6aed7e5f070 |
parent 219 | 9bb38736f126 |
child 228 | 43831b683764 |
permissions | -rwxr-xr-x |
219 | 1 |
/* |
2 |
* (c) 2007 Mario de Sousa and Laurent Bessard |
|
3 |
* |
|
4 |
* Offered to the public under the terms of the GNU General Public License |
|
5 |
* as published by the Free Software Foundation; either version 2 of the |
|
6 |
* License, or (at your option) any later version. |
|
7 |
* |
|
8 |
* This program is distributed in the hope that it will be useful, but |
|
9 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
11 |
* Public License for more details. |
|
12 |
* |
|
13 |
* This code is made available on the understanding that it will not be |
|
14 |
* used in safety-critical situations without a full and competent review. |
|
15 |
*/ |
|
16 |
||
17 |
/* |
|
18 |
* An IEC 61131-3 IL and ST compiler. |
|
19 |
* |
|
20 |
* Based on the |
|
21 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
/* |
|
26 |
* This is one of the versions available for the 4th stage. |
|
27 |
* |
|
28 |
* This 4th stage generates a c++ source program equivalent |
|
29 |
* to the IL and ST code. |
|
30 |
*/ |
|
31 |
||
32 |
||
33 |
#define INLINE_RESULT_TEMP_VAR "__res" |
|
34 |
||
35 |
class generate_c_inline_c: public generate_c_typedecl_c { |
|
36 |
||
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
|
37 |
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
|
38 |
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
|
39 |
expression_vg, |
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
|
40 |
assignment_vg |
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
|
41 |
} 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
|
42 |
|
219 | 43 |
private: |
44 |
||
45 |
/* The name of the IL default variable... */ |
|
46 |
#define IL_DEFVAR VAR_LEADER "IL_DEFVAR" |
|
47 |
/* The name of the variable used to pass the result of a |
|
48 |
* parenthesised instruction list to the immediately preceding |
|
49 |
* scope ... |
|
50 |
*/ |
|
51 |
il_default_variable_c default_variable_name; |
|
52 |
||
53 |
int fcall_number; |
|
54 |
symbol_c *fbname; |
|
55 |
||
56 |
search_expression_type_c *search_expression_type; |
|
57 |
||
58 |
search_varfb_instance_type_c *search_varfb_instance_type; |
|
59 |
||
60 |
search_base_type_c search_base_type; |
|
61 |
||
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
|
62 |
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
|
63 |
|
219 | 64 |
public: |
65 |
generate_c_inline_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL) |
|
66 |
: generate_c_typedecl_c(s4o_ptr), |
|
67 |
default_variable_name(IL_DEFVAR, NULL) |
|
68 |
{ |
|
69 |
search_expression_type = new search_expression_type_c(scope); |
|
70 |
search_varfb_instance_type = new search_varfb_instance_type_c(scope); |
|
71 |
this->set_variable_prefix(variable_prefix); |
|
72 |
fcall_number = 0; |
|
73 |
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
|
74 |
wanted_variablegeneration = expression_vg; |
219 | 75 |
} |
76 |
||
77 |
virtual ~generate_c_inline_c(void) { |
|
78 |
delete search_varfb_instance_type; |
|
79 |
} |
|
80 |
||
81 |
void *generate_inline(symbol_c *function_name, |
|
82 |
symbol_c *return_data_type, |
|
83 |
std::list<FUNCTION_PARAM*> param_list) { |
|
84 |
std::list<FUNCTION_PARAM*>::iterator pt; |
|
85 |
||
86 |
fcall_number++; |
|
87 |
||
88 |
s4o.print(s4o.indent_spaces); |
|
89 |
s4o.print("inline "); |
|
90 |
return_data_type->accept(*this); |
|
91 |
s4o.print(" __"); |
|
92 |
fbname->accept(*this); |
|
93 |
s4o.print("_"); |
|
94 |
function_name->accept(*this); |
|
95 |
s4o.print_integer(fcall_number); |
|
96 |
s4o.print("("); |
|
97 |
s4o.indent_right(); |
|
98 |
||
99 |
PARAM_LIST_ITERATOR() { |
|
100 |
if (PARAM_DIRECTION == function_param_iterator_c::direction_in) { |
|
101 |
PARAM_TYPE->accept(*this); |
|
102 |
s4o.print(" "); |
|
103 |
PARAM_NAME->accept(*this); |
|
104 |
s4o.print(",\n" + s4o.indent_spaces); |
|
105 |
} |
|
106 |
} |
|
107 |
fbname->accept(*this); |
|
108 |
s4o.print(" *"); |
|
109 |
s4o.print(FB_FUNCTION_PARAM); |
|
110 |
s4o.indent_left(); |
|
111 |
s4o.print(")\n" + s4o.indent_spaces); |
|
112 |
s4o.print("{\n"); |
|
113 |
s4o.indent_right(); |
|
114 |
||
115 |
s4o.print(s4o.indent_spaces); |
|
116 |
return_data_type->accept(*this); |
|
117 |
s4o.print(" "), |
|
118 |
s4o.print(INLINE_RESULT_TEMP_VAR); |
|
119 |
s4o.print(";\n"); |
|
120 |
||
121 |
PARAM_LIST_ITERATOR() { |
|
122 |
if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
|
123 |
PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
|
124 |
PARAM_VALUE != NULL) { |
|
125 |
s4o.print(s4o.indent_spaces); |
|
126 |
PARAM_TYPE->accept(*this); |
|
127 |
s4o.print(" "); |
|
128 |
s4o.print(TEMP_VAR); |
|
129 |
PARAM_NAME->accept(*this); |
|
130 |
s4o.print(" = "); |
|
131 |
print_check_function(PARAM_TYPE, PARAM_VALUE); |
|
132 |
s4o.print(";\n"); |
|
133 |
} |
|
134 |
} |
|
135 |
||
136 |
s4o.print(s4o.indent_spaces + INLINE_RESULT_TEMP_VAR), |
|
137 |
s4o.print(" = "); |
|
138 |
function_name->accept(*this); |
|
139 |
s4o.print("("); |
|
140 |
s4o.indent_right(); |
|
141 |
||
142 |
PARAM_LIST_ITERATOR() { |
|
143 |
if (pt != param_list.begin()) |
|
144 |
s4o.print(",\n" + s4o.indent_spaces); |
|
145 |
if (PARAM_DIRECTION == function_param_iterator_c::direction_in) |
|
146 |
PARAM_NAME->accept(*this); |
|
147 |
else if (PARAM_VALUE != NULL){ |
|
148 |
s4o.print("&"); |
|
149 |
s4o.print(TEMP_VAR); |
|
150 |
PARAM_NAME->accept(*this); |
|
151 |
} |
|
152 |
else { |
|
153 |
s4o.print("NULL"); |
|
154 |
} |
|
155 |
} |
|
156 |
s4o.print(");\n"); |
|
157 |
s4o.indent_left(); |
|
158 |
||
159 |
PARAM_LIST_ITERATOR() { |
|
160 |
if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
|
161 |
PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
|
162 |
PARAM_VALUE != NULL) { |
|
163 |
||
164 |
s4o.print(s4o.indent_spaces); |
|
165 |
||
166 |
unsigned int vartype = search_varfb_instance_type->get_vartype(PARAM_VALUE); |
|
167 |
if (vartype == search_var_instance_decl_c::external_vt) |
|
168 |
s4o.print(SET_EXTERNAL); |
|
169 |
else if (vartype == search_var_instance_decl_c::located_vt) |
|
170 |
s4o.print(SET_LOCATED); |
|
171 |
else |
|
172 |
s4o.print(SET_VAR); |
|
173 |
s4o.print("("); |
|
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
219
diff
changeset
|
174 |
wanted_variablegeneration = assignment_vg; |
219 | 175 |
PARAM_VALUE->accept(*this); |
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
|
176 |
wanted_variablegeneration = expression_vg; |
219 | 177 |
s4o.print(", "); |
178 |
print_check_function(PARAM_TYPE, PARAM_NAME, NULL, true); |
|
179 |
s4o.print(");\n"); |
|
180 |
} |
|
181 |
} |
|
182 |
s4o.print(s4o.indent_spaces + "return "); |
|
183 |
s4o.print(INLINE_RESULT_TEMP_VAR); |
|
184 |
s4o.print(";\n"); |
|
185 |
||
186 |
s4o.indent_left(); |
|
187 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
|
188 |
||
189 |
return NULL; |
|
190 |
} |
|
191 |
||
192 |
private: |
|
193 |
||
194 |
/*********************/ |
|
195 |
/* B 1.4 - Variables */ |
|
196 |
/*********************/ |
|
197 |
void *visit(symbolic_variable_c *symbol) { |
|
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
|
198 |
if (wanted_variablegeneration == expression_vg) { |
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
|
199 |
unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); |
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
|
200 |
if (vartype == search_var_instance_decl_c::external_vt) { |
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
|
201 |
s4o.print(GET_EXTERNAL); |
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
|
202 |
s4o.print("("); |
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
|
203 |
symbol->var_name->accept(*this); |
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
|
204 |
} |
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
|
205 |
else { |
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
|
206 |
if (vartype == search_var_instance_decl_c::located_vt) |
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
|
207 |
s4o.print(GET_LOCATED); |
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
|
208 |
else |
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
|
209 |
s4o.print(GET_VAR); |
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
|
210 |
s4o.print("("); |
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
|
211 |
generate_c_base_c::visit(symbol); |
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
|
212 |
} |
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
|
213 |
s4o.print(")"); |
219 | 214 |
} |
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
|
215 |
else |
219 | 216 |
generate_c_base_c::visit(symbol); |
217 |
return NULL; |
|
218 |
} |
|
219 |
||
220 |
/********************************************/ |
|
221 |
/* B.1.4.1 Directly Represented Variables */ |
|
222 |
/********************************************/ |
|
223 |
// direct_variable: direct_variable_token {$$ = new direct_variable_c($1);}; |
|
224 |
void *visit(direct_variable_c *symbol) { |
|
225 |
TRACE("direct_variable_c"); |
|
226 |
/* Do not use print_token() as it will change everything into uppercase */ |
|
227 |
if (strlen(symbol->value) == 0) ERROR; |
|
228 |
s4o.print(GET_LOCATED); |
|
229 |
s4o.print("("); |
|
230 |
this->print_variable_prefix(); |
|
231 |
s4o.printlocation(symbol->value + 1); |
|
232 |
s4o.print(")"); |
|
233 |
return NULL; |
|
234 |
} |
|
235 |
||
236 |
/****************************************/ |
|
237 |
/* B.2 - Language IL (Instruction List) */ |
|
238 |
/****************************************/ |
|
239 |
||
240 |
/***********************************/ |
|
241 |
/* B 2.1 Instructions and Operands */ |
|
242 |
/***********************************/ |
|
243 |
||
244 |
void *visit(il_function_call_c *symbol) { |
|
245 |
function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
|
246 |
||
247 |
if (f_decl != function_symtable.end_value()) { |
|
248 |
DECLARE_PARAM_LIST() |
|
249 |
bool has_output_params = false; |
|
250 |
||
251 |
/* determine the base data type returned by the function being called... */ |
|
252 |
search_base_type_c search_base_type; |
|
253 |
symbol_c *return_data_type = (symbol_c *)f_decl->type_name->accept(search_base_type); |
|
254 |
if (NULL == return_data_type) ERROR; |
|
255 |
||
256 |
/* loop through each function parameter, find the value we should pass |
|
257 |
* to it, and then output the c equivalent... |
|
258 |
*/ |
|
259 |
||
260 |
function_param_iterator_c fp_iterator(f_decl); |
|
261 |
identifier_c *param_name; |
|
262 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
263 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
264 |
symbol_c *param_type = fp_iterator.param_type(); |
|
265 |
if (param_type == NULL) ERROR; |
|
266 |
||
267 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
268 |
||
269 |
symbol_c *param_value = NULL; |
|
270 |
||
271 |
/* if it is the first parameter, semantics specifies that we should |
|
272 |
* get the value off the IL default variable! |
|
273 |
*/ |
|
274 |
if (1 == i) |
|
275 |
param_value = &this->default_variable_name; |
|
276 |
||
277 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
|
278 |
/* NOTE: the following line of code is not required in this case, but it doesn't |
|
279 |
* harm to leave it in, as in the case of a non-formal syntax function call, |
|
280 |
* it will always return NULL. |
|
281 |
* We leave it in in case we later decide to merge this part of the code together |
|
282 |
* with the function calling code in generate_c_st_c, which does require |
|
283 |
* the following line... |
|
284 |
*/ |
|
285 |
if (param_value == NULL) |
|
286 |
param_value = function_call_param_iterator.search_f(param_name); |
|
287 |
||
288 |
/* Get the value from a foo(<param_value>) style call */ |
|
289 |
if (param_value == NULL) |
|
290 |
param_value = function_call_param_iterator.next_nf(); |
|
291 |
||
292 |
if (param_value == NULL && param_direction == function_param_iterator_c::direction_in) { |
|
293 |
/* No value given for parameter, so we must use the default... */ |
|
294 |
/* First check whether default value specified in function declaration...*/ |
|
295 |
param_value = fp_iterator.default_value(); |
|
296 |
} |
|
297 |
||
298 |
ADD_PARAM_LIST(param_name, param_value, param_type, fp_iterator.param_direction()) |
|
299 |
} /* for(...) */ |
|
300 |
||
301 |
PARAM_LIST_ITERATOR() { |
|
302 |
if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
|
303 |
PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
|
304 |
PARAM_VALUE != NULL) { |
|
305 |
has_output_params = true; |
|
306 |
} |
|
307 |
} |
|
308 |
||
309 |
if (has_output_params) |
|
310 |
generate_inline(symbol->function_name, return_data_type, param_list); |
|
311 |
||
312 |
CLEAR_PARAM_LIST() |
|
313 |
} |
|
314 |
return NULL; |
|
315 |
} |
|
316 |
||
317 |
void *visit(il_formal_funct_call_c *symbol) { |
|
318 |
function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
|
319 |
||
320 |
if (f_decl != function_symtable.end_value()) { |
|
321 |
DECLARE_PARAM_LIST() |
|
322 |
bool has_output_params = false; |
|
323 |
||
324 |
/* determine the base data type returned by the function being called... */ |
|
325 |
search_base_type_c search_base_type; |
|
326 |
symbol_c *return_data_type = (symbol_c *)f_decl->type_name->accept(search_base_type); |
|
327 |
if (NULL == return_data_type) ERROR; |
|
328 |
||
329 |
/* loop through each function parameter, find the value we should pass |
|
330 |
* to it, and then output the c equivalent... |
|
331 |
*/ |
|
332 |
||
333 |
function_param_iterator_c fp_iterator(f_decl); |
|
334 |
identifier_c *param_name; |
|
335 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
336 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
337 |
symbol_c *param_type = fp_iterator.param_type(); |
|
338 |
if (param_type == NULL) ERROR; |
|
339 |
||
340 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
341 |
||
342 |
||
343 |
symbol_c *param_value = NULL; |
|
344 |
||
345 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
|
346 |
if (param_value == NULL) |
|
347 |
param_value = function_call_param_iterator.search_f(param_name); |
|
348 |
||
349 |
/* Get the value from a foo(<param_value>) style call */ |
|
350 |
/* NOTE: the following line of code is not required in this case, but it doesn't |
|
351 |
* harm to leave it in, as in the case of a formal syntax function call, |
|
352 |
* it will always return NULL. |
|
353 |
* We leave it in in case we later decide to merge this part of the code together |
|
354 |
* with the function calling code in generate_c_st_c, which does require |
|
355 |
* the following line... |
|
356 |
*/ |
|
357 |
if (param_value == NULL) |
|
358 |
param_value = function_call_param_iterator.next_nf(); |
|
359 |
||
360 |
if (param_value == NULL) { |
|
361 |
/* No value given for parameter, so we must use the default... */ |
|
362 |
/* First check whether default value specified in function declaration...*/ |
|
363 |
param_value = fp_iterator.default_value(); |
|
364 |
} |
|
365 |
||
366 |
ADD_PARAM_LIST(param_name, param_value, param_type, fp_iterator.param_direction()) |
|
367 |
} |
|
368 |
||
369 |
PARAM_LIST_ITERATOR() { |
|
370 |
if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
|
371 |
PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
|
372 |
PARAM_VALUE != NULL) { |
|
373 |
has_output_params = true; |
|
374 |
} |
|
375 |
} |
|
376 |
||
377 |
if (has_output_params) |
|
378 |
generate_inline(symbol->function_name, return_data_type, param_list); |
|
379 |
||
380 |
CLEAR_PARAM_LIST() |
|
381 |
} |
|
382 |
return NULL; |
|
383 |
} |
|
384 |
||
385 |
/***************************************/ |
|
386 |
/* B.3 - Language ST (Structured Text) */ |
|
387 |
/***************************************/ |
|
388 |
/***********************/ |
|
389 |
/* B 3.1 - Expressions */ |
|
390 |
/***********************/ |
|
391 |
||
392 |
void *visit(function_invocation_c *symbol) { |
|
393 |
function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
|
394 |
||
395 |
if (f_decl != function_symtable.end_value()) { |
|
396 |
DECLARE_PARAM_LIST() |
|
397 |
bool has_output_params = false; |
|
398 |
||
399 |
symbol_c *parameter_assignment_list = NULL; |
|
400 |
if (NULL != symbol-> formal_param_list) parameter_assignment_list = symbol-> formal_param_list; |
|
401 |
if (NULL != symbol->nonformal_param_list) parameter_assignment_list = symbol->nonformal_param_list; |
|
402 |
if (NULL == parameter_assignment_list) ERROR; |
|
403 |
||
404 |
/* determine the base data type returned by the function being called... */ |
|
405 |
search_base_type_c search_base_type; |
|
406 |
symbol_c *return_data_type = (symbol_c *)f_decl->type_name->accept(search_base_type); |
|
407 |
if (NULL == return_data_type) ERROR; |
|
408 |
||
409 |
/* loop through each function parameter, find the value we should pass |
|
410 |
* to it, and then output the c equivalent... |
|
411 |
*/ |
|
412 |
function_param_iterator_c fp_iterator(f_decl); |
|
413 |
identifier_c *param_name; |
|
414 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
415 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
416 |
||
417 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
418 |
||
419 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
|
420 |
symbol_c *param_value = function_call_param_iterator.search_f(param_name); |
|
421 |
||
422 |
/* Get the value from a foo(<param_value>) style call */ |
|
423 |
if (param_value == NULL) |
|
424 |
param_value = function_call_param_iterator.next_nf(); |
|
425 |
||
426 |
if (param_value == NULL && param_direction == function_param_iterator_c::direction_in) { |
|
427 |
/* No value given for parameter, so we must use the default... */ |
|
428 |
/* First check whether default value specified in function declaration...*/ |
|
429 |
param_value = fp_iterator.default_value(); |
|
430 |
} |
|
431 |
||
432 |
symbol_c *param_type = fp_iterator.param_type(); |
|
433 |
if (param_type == NULL) ERROR; |
|
434 |
||
435 |
ADD_PARAM_LIST(param_name, param_value, param_type, param_direction) |
|
436 |
} /* for(...) */ |
|
437 |
// symbol->parameter_assignment->accept(*this); |
|
438 |
||
439 |
PARAM_LIST_ITERATOR() { |
|
440 |
if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
|
441 |
PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
|
442 |
PARAM_VALUE != NULL) { |
|
443 |
has_output_params = true; |
|
444 |
} |
|
445 |
} |
|
446 |
||
447 |
if (has_output_params) |
|
448 |
generate_inline(symbol->function_name, return_data_type, param_list); |
|
449 |
||
450 |
CLEAR_PARAM_LIST() |
|
451 |
} |
|
452 |
return NULL; |
|
453 |
} |
|
454 |
||
455 |
}; /* generate_c_inline_c */ |
|
456 |
||
457 |
||
458 |
/***********************************************************************/ |
|
459 |
/***********************************************************************/ |
|
460 |
/***********************************************************************/ |
|
461 |
/***********************************************************************/ |
|
462 |
||
463 |
||
464 |
class generate_c_inlinefcall_c: public iterator_visitor_c { |
|
465 |
||
466 |
private: |
|
467 |
generate_c_inline_c *generate_c_inline; |
|
468 |
||
469 |
public: |
|
470 |
generate_c_inlinefcall_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL) { |
|
471 |
generate_c_inline = new generate_c_inline_c(s4o_ptr, name, scope, variable_prefix); |
|
472 |
} |
|
473 |
||
474 |
virtual ~generate_c_inlinefcall_c(void) { |
|
475 |
delete generate_c_inline; |
|
476 |
} |
|
477 |
||
478 |
private: |
|
479 |
||
480 |
void *visit(function_invocation_c *symbol) { |
|
481 |
return symbol->accept(*generate_c_inline); |
|
482 |
} |
|
483 |
||
484 |
void *visit(il_function_call_c *symbol) { |
|
485 |
return symbol->accept(*generate_c_inline); |
|
486 |
} |
|
487 |
||
488 |
void *visit(il_formal_funct_call_c *symbol) { |
|
489 |
return symbol->accept(*generate_c_inline); |
|
490 |
} |
|
491 |
}; /* generate_c_inlinefcall_c */ |
|
492 |
||
493 |
||
494 |