author | Edouard Tisserant |
Wed, 28 Nov 2012 12:00:38 +0900 | |
changeset 710 | e9bb0ed80471 |
parent 706 | 31553c22f318 |
child 793 | 268bf4ca5fa1 |
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" |
|
380
b78e59ed4269
Fix bug in generate_c_inlinefcall.cc that prevent to use extendible standard functions
laurent
parents:
355
diff
changeset
|
27 |
#define INLINE_PARAM_COUNT "__PARAM_COUNT" |
219 | 28 |
|
234
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
29 |
class generate_c_inlinefcall_c: public generate_c_typedecl_c { |
219 | 30 |
|
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
|
31 |
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
|
32 |
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
|
33 |
expression_vg, |
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
34 |
assignment_vg, |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
35 |
complextype_base_vg, |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
36 |
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
|
37 |
} 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
|
38 |
|
219 | 39 |
private: |
40 |
||
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
41 |
/* The initial value that should be given to the IL default variable |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
42 |
* imediately after a parenthesis is opened. |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
43 |
* This variable is only used to pass data from the |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
44 |
* il_expression_c visitor to the simple_instr_list_c visitor. |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
45 |
* |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
46 |
* e.g.: |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
47 |
* LD var1 |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
48 |
* AND ( var2 |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
49 |
* OR var3 |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
50 |
* ) |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
51 |
* |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
52 |
* In the above code sample, the line 'AND ( var2' constitutes |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
53 |
* an il_expression_c, where var2 should be loaded into the |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
54 |
* il default variable before continuing with the expression |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
55 |
* inside the parenthesis. |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
56 |
* Unfortunately, only the simple_instr_list_c may do the |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
57 |
* initial laoding of the var2 bariable following the parenthesis, |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
58 |
* so the il_expression_c visitor will have to pass 'var2' as a |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
59 |
* parameter to the simple_instr_list_c visitor. |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
60 |
* Ergo, the existance of the following parameter...! |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
61 |
*/ |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
62 |
symbol_c *il_default_variable_init_value; |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
63 |
|
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
64 |
/* Operand to the IL operation currently being processed... */ |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
65 |
/* These variables are used to pass data from the |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
66 |
* il_simple_operation_c and il_expression_c visitors |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
67 |
* to the il operator visitors (i.e. LD_operator_c, |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
68 |
* LDN_operator_c, ST_operator_c, STN_operator_c, ...) |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
69 |
*/ |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
70 |
symbol_c *current_operand; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
71 |
symbol_c *current_operand_type; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
72 |
|
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
73 |
/* The result of the comparison IL operations (GT, EQ, LT, ...) |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
74 |
* is a boolean variable. |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
75 |
* This class keeps track of the current data type stored in the |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
76 |
* il default variable. This is usually done by keeping a reference |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
77 |
* to the data type of the last operand. Nevertheless, in the case of |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
78 |
* the comparison IL operators, the data type of the result (a boolean) |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
79 |
* is not the data type of the operand. We therefore need an object |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
80 |
* of the boolean data type to keep as a reference of the current |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
81 |
* data type. |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
82 |
* The following object is it... |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
83 |
*/ |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
84 |
bool_type_name_c bool_type; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
85 |
lint_type_name_c lint_type; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
86 |
lword_type_name_c lword_type; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
87 |
lreal_type_name_c lreal_type; |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
88 |
|
219 | 89 |
/* The name of the IL default variable... */ |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
90 |
#define IL_DEFVAR VAR_LEADER "IL_DEFVAR" |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
91 |
|
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
92 |
/* The name of the variable used to pass the result of a |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
93 |
* parenthesised instruction list to the immediately preceding |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
94 |
* scope ... |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
95 |
*/ |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
96 |
#define IL_DEFVAR_BACK VAR_LEADER "IL_DEFVAR_BACK" |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
97 |
il_default_variable_c default_variable_name; |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
98 |
il_default_variable_c default_variable_back_name; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
99 |
|
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
100 |
symbol_c* current_array_type; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
101 |
|
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
102 |
int fcall_number; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
103 |
bool generating_inlinefunction; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
104 |
symbol_c *fbname; |
219 | 105 |
|
106 |
search_expression_type_c *search_expression_type; |
|
107 |
||
108 |
search_varfb_instance_type_c *search_varfb_instance_type; |
|
505
21be0f2f242d
Removing code from search_varfb_instance_type_c (use search_var_instance_decl_c instead).
Mario de Sousa <msousa@fe.up.pt>
parents:
500
diff
changeset
|
109 |
search_var_instance_decl_c *search_var_instance_decl; |
219 | 110 |
|
111 |
search_base_type_c search_base_type; |
|
112 |
||
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
|
113 |
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
|
114 |
|
219 | 115 |
public: |
234
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
116 |
generate_c_inlinefcall_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL) |
219 | 117 |
: generate_c_typedecl_c(s4o_ptr), |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
118 |
default_variable_name(IL_DEFVAR, NULL), |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
119 |
default_variable_back_name(IL_DEFVAR_BACK, NULL) |
219 | 120 |
{ |
121 |
search_expression_type = new search_expression_type_c(scope); |
|
122 |
search_varfb_instance_type = new search_varfb_instance_type_c(scope); |
|
505
21be0f2f242d
Removing code from search_varfb_instance_type_c (use search_var_instance_decl_c instead).
Mario de Sousa <msousa@fe.up.pt>
parents:
500
diff
changeset
|
123 |
search_var_instance_decl = new search_var_instance_decl_c(scope); |
21be0f2f242d
Removing code from search_varfb_instance_type_c (use search_var_instance_decl_c instead).
Mario de Sousa <msousa@fe.up.pt>
parents:
500
diff
changeset
|
124 |
|
219 | 125 |
this->set_variable_prefix(variable_prefix); |
392
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
388
diff
changeset
|
126 |
current_operand = NULL; |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
388
diff
changeset
|
127 |
current_operand_type = NULL; |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
388
diff
changeset
|
128 |
il_default_variable_init_value = NULL; |
219 | 129 |
fcall_number = 0; |
130 |
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
|
131 |
wanted_variablegeneration = expression_vg; |
388
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
132 |
generating_inlinefunction = false; |
219 | 133 |
} |
134 |
||
234
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
135 |
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
|
136 |
delete search_expression_type; |
219 | 137 |
delete search_varfb_instance_type; |
505
21be0f2f242d
Removing code from search_varfb_instance_type_c (use search_var_instance_decl_c instead).
Mario de Sousa <msousa@fe.up.pt>
parents:
500
diff
changeset
|
138 |
delete search_var_instance_decl; |
219 | 139 |
} |
140 |
||
234
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
141 |
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
|
142 |
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
|
143 |
symbol_c* function_call; |
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
144 |
while ((function_call = fc_iterator.next()) != NULL) { |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
145 |
function_call->accept(*this); |
234
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
146 |
} |
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
147 |
} |
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
148 |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
149 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
150 |
|
234
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
151 |
void generate_inline(symbol_c *function_name, |
235 | 152 |
symbol_c *function_type_prefix, |
153 |
symbol_c *function_type_suffix, |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
154 |
std::list<FUNCTION_PARAM*> param_list, |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
155 |
function_declaration_c *f_decl = NULL) { |
388
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
156 |
|
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
157 |
std::list<FUNCTION_PARAM*>::iterator pt; |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
158 |
generating_inlinefunction = true; |
219 | 159 |
|
160 |
fcall_number++; |
|
336 | 161 |
function_type_prefix = search_expression_type->default_literal_type(function_type_prefix); |
162 |
if (function_type_suffix) { |
|
163 |
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
|
164 |
} |
219 | 165 |
|
166 |
s4o.print(s4o.indent_spaces); |
|
167 |
s4o.print("inline "); |
|
235 | 168 |
function_type_prefix->accept(*this); |
219 | 169 |
s4o.print(" __"); |
170 |
fbname->accept(*this); |
|
171 |
s4o.print("_"); |
|
172 |
function_name->accept(*this); |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
173 |
if (f_decl != NULL) { |
383
0b81b59f333b
Fix bug generate_c_inlinefcall in inline function name generated
laurent
parents:
380
diff
changeset
|
174 |
/* function being called is overloaded! */ |
0b81b59f333b
Fix bug generate_c_inlinefcall in inline function name generated
laurent
parents:
380
diff
changeset
|
175 |
s4o.print("__"); |
406
6381589697ff
Fix bug with overloaded function due to literal input values
laurent
parents:
399
diff
changeset
|
176 |
print_function_parameter_data_types_c overloaded_func_suf(&s4o); |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
177 |
f_decl->accept(overloaded_func_suf); |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
178 |
} |
336 | 179 |
if (function_type_suffix) { |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
180 |
function_type_suffix->accept(*this); |
336 | 181 |
} |
594
c8092e909886
Clean up code (remove parsing of integers in stage 4).
Mario de Sousa <msousa@fe.up.pt>
parents:
531
diff
changeset
|
182 |
s4o.print(fcall_number); |
219 | 183 |
s4o.print("("); |
184 |
s4o.indent_right(); |
|
185 |
||
186 |
PARAM_LIST_ITERATOR() { |
|
187 |
if (PARAM_DIRECTION == function_param_iterator_c::direction_in) { |
|
336 | 188 |
search_expression_type->default_literal_type(PARAM_TYPE)->accept(*this); |
219 | 189 |
s4o.print(" "); |
190 |
PARAM_NAME->accept(*this); |
|
191 |
s4o.print(",\n" + s4o.indent_spaces); |
|
192 |
} |
|
193 |
} |
|
194 |
fbname->accept(*this); |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
195 |
s4o.print(" *"); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
196 |
s4o.print(FB_FUNCTION_PARAM); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
197 |
s4o.indent_left(); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
198 |
s4o.print(")\n" + s4o.indent_spaces); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
199 |
s4o.print("{\n"); |
219 | 200 |
s4o.indent_right(); |
201 |
||
202 |
s4o.print(s4o.indent_spaces); |
|
235 | 203 |
function_type_prefix->accept(*this); |
219 | 204 |
s4o.print(" "), |
205 |
s4o.print(INLINE_RESULT_TEMP_VAR); |
|
206 |
s4o.print(";\n"); |
|
207 |
||
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
208 |
PARAM_LIST_ITERATOR() { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
209 |
if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
210 |
PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
211 |
PARAM_VALUE != NULL) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
212 |
s4o.print(s4o.indent_spaces); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
213 |
PARAM_TYPE->accept(*this); |
219 | 214 |
s4o.print(" "); |
215 |
s4o.print(TEMP_VAR); |
|
216 |
PARAM_NAME->accept(*this); |
|
217 |
s4o.print(" = "); |
|
218 |
print_check_function(PARAM_TYPE, PARAM_VALUE); |
|
219 |
s4o.print(";\n"); |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
220 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
221 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
222 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
223 |
s4o.print(s4o.indent_spaces + INLINE_RESULT_TEMP_VAR), |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
224 |
s4o.print(" = "); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
225 |
function_name->accept(*this); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
226 |
if (f_decl != NULL) { |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
227 |
/* function being called is overloaded! */ |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
228 |
s4o.print("__"); |
406
6381589697ff
Fix bug with overloaded function due to literal input values
laurent
parents:
399
diff
changeset
|
229 |
print_function_parameter_data_types_c overloaded_func_suf(&s4o); |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
230 |
f_decl->accept(overloaded_func_suf); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
231 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
232 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
233 |
if (function_type_suffix) |
235 | 234 |
function_type_suffix->accept(*this); |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
235 |
s4o.print("("); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
236 |
s4o.indent_right(); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
237 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
238 |
PARAM_LIST_ITERATOR() { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
239 |
if (pt != param_list.begin()) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
240 |
s4o.print(",\n" + s4o.indent_spaces); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
241 |
if (PARAM_DIRECTION == function_param_iterator_c::direction_in) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
242 |
PARAM_NAME->accept(*this); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
243 |
else if (PARAM_VALUE != NULL){ |
219 | 244 |
s4o.print("&"); |
245 |
s4o.print(TEMP_VAR); |
|
246 |
PARAM_NAME->accept(*this); |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
247 |
} else { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
248 |
s4o.print("NULL"); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
249 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
250 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
251 |
s4o.print(");\n"); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
252 |
s4o.indent_left(); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
253 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
254 |
PARAM_LIST_ITERATOR() { |
219 | 255 |
if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
256 |
PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
257 |
PARAM_VALUE != NULL) { |
219 | 258 |
s4o.print(s4o.indent_spaces); |
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
259 |
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
|
260 |
s4o.print(";\n"); |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
261 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
262 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
263 |
s4o.print(s4o.indent_spaces + "return "); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
264 |
s4o.print(INLINE_RESULT_TEMP_VAR); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
265 |
s4o.print(";\n"); |
219 | 266 |
|
267 |
s4o.indent_left(); |
|
268 |
s4o.print(s4o.indent_spaces + "}\n\n"); |
|
388
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
269 |
|
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
270 |
generating_inlinefunction = false; |
219 | 271 |
} |
272 |
||
273 |
private: |
|
274 |
||
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
275 |
/* A helper function... */ |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
276 |
void CMP_operator_result_type() { |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
277 |
/* the data type resulting from this operation... */ |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
278 |
this->default_variable_name.current_type = &(this->bool_type); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
279 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
280 |
|
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
281 |
/* A helper function... */ |
345
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
282 |
void BYTE_operator_result_type(void) { |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
283 |
if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type)) { |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
284 |
if (search_expression_type->is_literal_integer_type(this->current_operand_type)) |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
285 |
this->default_variable_name.current_type = &(this->lword_type); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
286 |
else |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
287 |
this->default_variable_name.current_type = this->current_operand_type; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
288 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
289 |
else if (search_expression_type->is_literal_integer_type(this->current_operand_type)) |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
290 |
this->current_operand_type = this->default_variable_name.current_type; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
291 |
} |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
292 |
|
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
293 |
/* A helper function... */ |
345
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
294 |
void NUM_operator_result_type(void) { |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
295 |
if (search_expression_type->is_literal_real_type(this->default_variable_name.current_type)) { |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
296 |
if (search_expression_type->is_literal_integer_type(this->current_operand_type) || |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
297 |
search_expression_type->is_literal_real_type(this->current_operand_type)) |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
298 |
this->default_variable_name.current_type = &(this->lreal_type); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
299 |
else |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
300 |
this->default_variable_name.current_type = this->current_operand_type; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
301 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
302 |
else if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type)) { |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
303 |
if (search_expression_type->is_literal_integer_type(this->current_operand_type)) |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
304 |
this->default_variable_name.current_type = &(this->lint_type); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
305 |
else if (search_expression_type->is_literal_real_type(this->current_operand_type)) |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
306 |
this->default_variable_name.current_type = &(this->lreal_type); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
307 |
else |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
308 |
this->default_variable_name.current_type = this->current_operand_type; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
309 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
310 |
else if (search_expression_type->is_literal_integer_type(this->current_operand_type) || |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
311 |
search_expression_type->is_literal_real_type(this->current_operand_type)) |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
312 |
this->current_operand_type = this->default_variable_name.current_type; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
313 |
} |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
314 |
|
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
315 |
void *print_getter(symbol_c *symbol) { |
505
21be0f2f242d
Removing code from search_varfb_instance_type_c (use search_var_instance_decl_c instead).
Mario de Sousa <msousa@fe.up.pt>
parents:
500
diff
changeset
|
316 |
unsigned int vartype = search_var_instance_decl->get_vartype(symbol); |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
317 |
if (vartype == search_var_instance_decl_c::external_vt) { |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
318 |
if (search_var_instance_decl->type_is_fb(symbol)) |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
319 |
s4o.print(GET_EXTERNAL_FB); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
320 |
else |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
321 |
s4o.print(GET_EXTERNAL); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
322 |
} |
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
323 |
else if (vartype == search_var_instance_decl_c::located_vt) |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
324 |
s4o.print(GET_LOCATED); |
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
325 |
else |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
326 |
s4o.print(GET_VAR); |
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
327 |
s4o.print("("); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
328 |
|
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
329 |
wanted_variablegeneration = complextype_base_vg; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
330 |
symbol->accept(*this); |
531
e7d6f28fc882
Make temporary fix to is_complex() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
505
diff
changeset
|
331 |
if (search_var_instance_decl->type_is_complex(symbol)) |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
332 |
s4o.print(","); |
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
333 |
wanted_variablegeneration = complextype_suffix_vg; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
334 |
symbol->accept(*this); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
335 |
s4o.print(")"); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
336 |
wanted_variablegeneration = expression_vg; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
337 |
return NULL; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
338 |
} |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
339 |
|
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
340 |
void *print_setter(symbol_c* symbol, |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
341 |
symbol_c* type, |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
342 |
symbol_c* value) { |
505
21be0f2f242d
Removing code from search_varfb_instance_type_c (use search_var_instance_decl_c instead).
Mario de Sousa <msousa@fe.up.pt>
parents:
500
diff
changeset
|
343 |
unsigned int vartype = search_var_instance_decl->get_vartype(symbol); |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
344 |
if (vartype == search_var_instance_decl_c::external_vt) { |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
345 |
if (search_var_instance_decl->type_is_fb(symbol)) |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
346 |
s4o.print(SET_EXTERNAL_FB); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
347 |
else |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
348 |
s4o.print(SET_EXTERNAL); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
349 |
} |
392
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
388
diff
changeset
|
350 |
else if (vartype == search_var_instance_decl_c::located_vt) |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
388
diff
changeset
|
351 |
s4o.print(SET_LOCATED); |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
388
diff
changeset
|
352 |
else |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
388
diff
changeset
|
353 |
s4o.print(SET_VAR); |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
388
diff
changeset
|
354 |
s4o.print("(,"); |
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
355 |
|
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
356 |
wanted_variablegeneration = complextype_base_vg; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
357 |
symbol->accept(*this); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
358 |
s4o.print(","); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
359 |
wanted_variablegeneration = expression_vg; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
360 |
print_check_function(type, value, NULL, true); |
531
e7d6f28fc882
Make temporary fix to is_complex() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
505
diff
changeset
|
361 |
if (search_var_instance_decl->type_is_complex(symbol)) { |
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
362 |
s4o.print(","); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
363 |
wanted_variablegeneration = complextype_suffix_vg; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
364 |
symbol->accept(*this); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
365 |
} |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
366 |
s4o.print(")"); |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
367 |
wanted_variablegeneration = expression_vg; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
368 |
return NULL; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
369 |
} |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
370 |
|
219 | 371 |
/*********************/ |
372 |
/* B 1.4 - Variables */ |
|
373 |
/*********************/ |
|
374 |
void *visit(symbolic_variable_c *symbol) { |
|
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
375 |
unsigned int vartype; |
388
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
376 |
if (generating_inlinefunction) { |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
377 |
if (wanted_variablegeneration == complextype_base_vg) |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
378 |
generate_c_base_c::visit(symbol); |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
379 |
else if (wanted_variablegeneration == complextype_suffix_vg) |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
380 |
return NULL; |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
381 |
else |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
382 |
print_getter(symbol); |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
383 |
} |
219 | 384 |
return NULL; |
385 |
} |
|
386 |
||
387 |
/********************************************/ |
|
388 |
/* B.1.4.1 Directly Represented Variables */ |
|
389 |
/********************************************/ |
|
390 |
// direct_variable: direct_variable_token {$$ = new direct_variable_c($1);}; |
|
391 |
void *visit(direct_variable_c *symbol) { |
|
392 |
TRACE("direct_variable_c"); |
|
388
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
393 |
if (generating_inlinefunction) { |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
394 |
/* Do not use print_token() as it will change everything into uppercase */ |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
395 |
if (strlen(symbol->value) == 0) ERROR; |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
396 |
s4o.print(GET_LOCATED); |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
397 |
s4o.print("("); |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
398 |
this->print_variable_prefix(); |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
399 |
s4o.printlocation(symbol->value + 1); |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
400 |
s4o.print(")"); |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
401 |
} |
219 | 402 |
return NULL; |
403 |
} |
|
404 |
||
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
405 |
/*************************************/ |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
406 |
/* B.1.4.2 Multi-element Variables */ |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
407 |
/*************************************/ |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
408 |
|
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
409 |
// 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
|
410 |
void *visit(structured_variable_c *symbol) { |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
411 |
TRACE("structured_variable_c"); |
625 | 412 |
bool type_is_complex = search_var_instance_decl->type_is_complex(symbol->record_variable); |
388
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
413 |
if (generating_inlinefunction) { |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
414 |
switch (wanted_variablegeneration) { |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
415 |
case complextype_base_vg: |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
416 |
symbol->record_variable->accept(*this); |
410
c6486bd97392
Fix bug while using complex type variables in Function and FunctionBlock interface
Laurent Bessard
parents:
408
diff
changeset
|
417 |
if (!type_is_complex) { |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
418 |
s4o.print("."); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
419 |
symbol->field_selector->accept(*this); |
410
c6486bd97392
Fix bug while using complex type variables in Function and FunctionBlock interface
Laurent Bessard
parents:
408
diff
changeset
|
420 |
} |
388
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
421 |
break; |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
422 |
case complextype_suffix_vg: |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
423 |
symbol->record_variable->accept(*this); |
410
c6486bd97392
Fix bug while using complex type variables in Function and FunctionBlock interface
Laurent Bessard
parents:
408
diff
changeset
|
424 |
if (type_is_complex) { |
c6486bd97392
Fix bug while using complex type variables in Function and FunctionBlock interface
Laurent Bessard
parents:
408
diff
changeset
|
425 |
s4o.print("."); |
c6486bd97392
Fix bug while using complex type variables in Function and FunctionBlock interface
Laurent Bessard
parents:
408
diff
changeset
|
426 |
symbol->field_selector->accept(*this); |
c6486bd97392
Fix bug while using complex type variables in Function and FunctionBlock interface
Laurent Bessard
parents:
408
diff
changeset
|
427 |
} |
388
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
428 |
break; |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
429 |
default: |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
430 |
print_getter(symbol); |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
431 |
break; |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
432 |
} |
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
433 |
} |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
434 |
return NULL; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
435 |
} |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
436 |
|
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
437 |
/* subscripted_variable '[' subscript_list ']' */ |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
438 |
//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
|
439 |
void *visit(array_variable_c *symbol) { |
388
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
440 |
if (generating_inlinefunction) { |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
441 |
switch (wanted_variablegeneration) { |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
442 |
case complextype_base_vg: |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
443 |
symbol->subscripted_variable->accept(*this); |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
444 |
break; |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
445 |
case complextype_suffix_vg: |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
446 |
symbol->subscripted_variable->accept(*this); |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
447 |
|
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
448 |
current_array_type = search_varfb_instance_type->get_type_id(symbol->subscripted_variable); |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
449 |
if (current_array_type == NULL) ERROR; |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
450 |
|
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
451 |
s4o.print(".table"); |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
452 |
symbol->subscript_list->accept(*this); |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
453 |
|
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
454 |
current_array_type = NULL; |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
455 |
break; |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
456 |
default: |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
457 |
print_getter(symbol); |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
458 |
break; |
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
459 |
} |
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
460 |
} |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
461 |
return NULL; |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
462 |
} |
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
221
diff
changeset
|
463 |
|
219 | 464 |
/****************************************/ |
465 |
/* B.2 - Language IL (Instruction List) */ |
|
466 |
/****************************************/ |
|
467 |
||
468 |
/***********************************/ |
|
469 |
/* B 2.1 Instructions and Operands */ |
|
470 |
/***********************************/ |
|
471 |
||
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
472 |
/* | label ':' [il_incomplete_instruction] eol_list */ |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
473 |
// SYM_REF2(il_instruction_c, label, il_instruction) |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
474 |
void *visit(il_instruction_c *symbol) { |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
475 |
if (NULL != symbol->il_instruction) { |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
476 |
symbol->il_instruction->accept(*this); |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
477 |
} |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
478 |
return NULL; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
479 |
} |
392
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
388
diff
changeset
|
480 |
|
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
481 |
/* | il_simple_operator [il_operand] */ |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
482 |
//SYM_REF2(il_simple_operation_c, il_simple_operator, il_operand) |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
483 |
void *visit(il_simple_operation_c *symbol) { |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
484 |
this->current_operand = symbol->il_operand; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
485 |
if (NULL == this->current_operand) { |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
486 |
this->current_operand_type = NULL; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
487 |
} else { |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
488 |
this->current_operand_type = search_expression_type->get_type(this->current_operand); |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
489 |
if (NULL == this->current_operand_type) ERROR; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
490 |
} |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
491 |
|
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
492 |
symbol->il_simple_operator->accept(*this); |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
493 |
|
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
494 |
this->current_operand = NULL; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
495 |
this->current_operand_type = NULL; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
496 |
return NULL; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
497 |
} |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
498 |
|
219 | 499 |
void *visit(il_function_call_c *symbol) { |
235 | 500 |
symbol_c* function_type_prefix = NULL; |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
501 |
symbol_c* function_name = NULL; |
235 | 502 |
symbol_c* function_type_suffix = NULL; |
503 |
DECLARE_PARAM_LIST() |
|
504 |
||
505 |
symbol_c *param_data_type = default_variable_name.current_type; |
|
506 |
||
507 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
508 |
||
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
509 |
function_declaration_c *f_decl = (function_declaration_c *)symbol->called_function_declaration; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
510 |
if (f_decl == NULL) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
511 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
512 |
/* determine the base data type returned by the function being called... */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
513 |
search_base_type_c search_base_type; |
406
6381589697ff
Fix bug with overloaded function due to literal input values
laurent
parents:
399
diff
changeset
|
514 |
function_type_prefix = (symbol_c *)f_decl->type_name->accept(search_base_type); |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
515 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
516 |
function_name = symbol->function_name; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
517 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
518 |
/* loop through each function parameter, find the value we should pass |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
519 |
* to it, and then output the c equivalent... |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
520 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
521 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
522 |
function_param_iterator_c fp_iterator(f_decl); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
523 |
identifier_c *param_name; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
524 |
/* flag to remember whether we have already used the value stored in the default variable to pass to the first parameter */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
525 |
bool used_defvar = false; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
526 |
/* flag to cirreclty handle calls to extensible standard functions (i.e. functions with variable number of input parameters) */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
527 |
bool found_first_extensible_parameter = false; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
528 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
529 |
if (fp_iterator.is_extensible_param() && (!found_first_extensible_parameter)) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
530 |
/* We are calling an extensible function. Before passing the extensible |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
531 |
* parameters, we must add a dummy paramater value to tell the called |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
532 |
* function how many extensible parameters we will be passing. |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
533 |
* |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
534 |
* Note that stage 3 has already determined the number of extensible |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
535 |
* paramters, and stored that info in the abstract syntax tree. We simply |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
536 |
* re-use that value. |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
537 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
538 |
/* NOTE: we are not freeing the malloc'd memory. This is not really a bug. |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
539 |
* Since we are writing a compiler, which runs to termination quickly, |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
540 |
* we can consider this as just memory required for the compilation process |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
541 |
* that will be free'd when the program terminates. |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
542 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
543 |
char *tmp = (char *)malloc(32); /* enough space for a call with 10^31 (larger than 2^64) input parameters! */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
544 |
if (tmp == NULL) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
545 |
int res = snprintf(tmp, 32, "%d", symbol->extensible_param_count); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
546 |
if ((res >= 32) || (res < 0)) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
547 |
identifier_c *param_value = new identifier_c(tmp); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
548 |
uint_type_name_c *param_type = new uint_type_name_c(); |
380
b78e59ed4269
Fix bug in generate_c_inlinefcall.cc that prevent to use extendible standard functions
laurent
parents:
355
diff
changeset
|
549 |
identifier_c *param_name = new identifier_c(INLINE_PARAM_COUNT); |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
550 |
ADD_PARAM_LIST(param_name, param_value, param_type, function_param_iterator_c::direction_in) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
551 |
found_first_extensible_parameter = true; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
552 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
553 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
554 |
symbol_c *param_type = fp_iterator.param_type(); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
555 |
if (param_type == NULL) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
556 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
557 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
558 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
559 |
symbol_c *param_value = NULL; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
560 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
561 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
562 |
/* NOTE: the following line of code is not required in this case, but it doesn't |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
563 |
* harm to leave it in, as in the case of a non-formal syntax function call, |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
564 |
* it will always return NULL. |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
565 |
* We leave it in in case we later decide to merge this part of the code together |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
566 |
* with the function calling code in generate_c_st_c, which does require |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
567 |
* the following line... |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
568 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
569 |
if (param_value == NULL) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
570 |
param_value = function_call_param_iterator.search_f(param_name); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
571 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
572 |
/* if it is the first parameter in a non-formal function call (which is the |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
573 |
* case being handled!), semantics specifies that we should |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
574 |
* get the value off the IL default variable! |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
575 |
* |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
576 |
* However, if the parameter is an implicitly defined EN or ENO parameter, we should not |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
577 |
* use the default variable as a source of data to pass to those parameters! |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
578 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
579 |
if ((param_value == NULL) && (!used_defvar) && !fp_iterator.is_en_eno_param_implicit()) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
580 |
param_value = &this->default_variable_name; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
581 |
used_defvar = true; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
582 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
583 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
584 |
/* Get the value from a foo(<param_value>) style call */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
585 |
if ((param_value == NULL) && !fp_iterator.is_en_eno_param_implicit()) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
586 |
param_value = function_call_param_iterator.next_nf(); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
587 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
588 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
589 |
/* if no more parameter values in function call, and the current parameter |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
590 |
* of the function declaration is an extensible parameter, we |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
591 |
* have reached the end, and should simply jump out of the for loop. |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
592 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
593 |
if ((param_value == NULL) && (fp_iterator.is_extensible_param())) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
594 |
break; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
595 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
596 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
597 |
if ((param_value == NULL) && (param_direction == function_param_iterator_c::direction_in)) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
598 |
/* No value given for parameter, so we must use the default... */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
599 |
/* First check whether default value specified in function declaration...*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
600 |
param_value = fp_iterator.default_value(); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
601 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
602 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
603 |
ADD_PARAM_LIST(param_name, param_value, param_type, fp_iterator.param_direction()) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
604 |
} /* for(...) */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
605 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
606 |
if (function_call_param_iterator.next_nf() != NULL) ERROR; |
235 | 607 |
if (NULL == function_type_prefix) ERROR; |
608 |
||
609 |
bool has_output_params = false; |
|
610 |
||
611 |
PARAM_LIST_ITERATOR() { |
|
612 |
if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
|
613 |
PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
|
614 |
PARAM_VALUE != NULL) { |
|
615 |
has_output_params = true; |
|
616 |
} |
|
617 |
} |
|
618 |
||
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
619 |
/* Check whether we are calling an overloaded function! */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
620 |
/* (fdecl_mutiplicity==2) => calling overloaded function */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
621 |
int fdecl_mutiplicity = function_symtable.multiplicity(symbol->function_name); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
622 |
if (fdecl_mutiplicity == 0) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
623 |
if (fdecl_mutiplicity == 1) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
624 |
/* function being called is NOT overloaded! */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
625 |
f_decl = NULL; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
626 |
|
235 | 627 |
if (has_output_params) |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
628 |
generate_inline(function_name, function_type_prefix, function_type_suffix, param_list, f_decl); |
235 | 629 |
|
630 |
CLEAR_PARAM_LIST() |
|
631 |
||
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
632 |
/* the data type resulting from this operation... */ |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
633 |
default_variable_name.current_type = function_type_prefix; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
634 |
return NULL; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
635 |
} |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
636 |
|
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
637 |
/* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */ |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
638 |
//SYM_REF4(il_expression_c, il_expr_operator, il_operand, simple_instr_list, unused) |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
639 |
void *visit(il_expression_c *symbol) { |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
640 |
/* We will be recursevely interpreting an instruction list, |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
641 |
* so we store a backup of the data type of the value currently stored |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
642 |
* in the default variable, and set the current data type to NULL |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
643 |
*/ |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
644 |
symbol_c *old_current_default_variable_data_type = this->default_variable_name.current_type; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
645 |
this->default_variable_name.current_type = NULL; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
646 |
|
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
647 |
/* Pass the symbol->il_operand to the simple_instr_list visitor |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
648 |
* using the il_default_variable_init_value parameter... |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
649 |
* Note that the simple_instr_list_c visitor will set this parameter |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
650 |
* to NULL as soon as it does not require it any longer, |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
651 |
* so we don't do it here again after the |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
652 |
* symbol->simple_instr_list->accept(*this); |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
653 |
* returns... |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
654 |
*/ |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
655 |
this->il_default_variable_init_value = symbol->il_operand; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
656 |
|
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
657 |
/* Now do the parenthesised instructions... */ |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
658 |
/* NOTE: the following code line will get the variable |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
659 |
* this->default_variable_name.current_type updated! |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
660 |
*/ |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
661 |
symbol->simple_instr_list->accept(*this); |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
662 |
|
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
663 |
/* Now do the operation, using the previous result! */ |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
664 |
/* NOTE: The result of the previous instruction list will be stored |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
665 |
* in a variable named IL_DEFVAR_BACK. This is done in the visitor |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
666 |
* to instruction_list_c objects... |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
667 |
*/ |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
668 |
this->current_operand = &(this->default_variable_back_name); |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
669 |
this->current_operand_type = this->default_variable_back_name.current_type; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
670 |
|
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
671 |
this->default_variable_name.current_type = old_current_default_variable_data_type; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
672 |
if (NULL == this->current_operand_type) ERROR; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
673 |
|
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
674 |
symbol->il_expr_operator->accept(*this); |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
675 |
|
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
676 |
this->current_operand = NULL; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
677 |
this->current_operand_type = NULL; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
678 |
this->default_variable_back_name.current_type = NULL; |
235 | 679 |
return NULL; |
680 |
} |
|
681 |
||
682 |
/* | function_name '(' eol_list [il_param_list] ')' */ |
|
683 |
// SYM_REF2(il_formal_funct_call_c, function_name, il_param_list) |
|
219 | 684 |
void *visit(il_formal_funct_call_c *symbol) { |
235 | 685 |
symbol_c* function_type_prefix = NULL; |
686 |
symbol_c* function_name = NULL; |
|
687 |
symbol_c* function_type_suffix = NULL; |
|
688 |
DECLARE_PARAM_LIST() |
|
689 |
||
690 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
691 |
||
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
692 |
function_declaration_c *f_decl = (function_declaration_c *)symbol->called_function_declaration; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
693 |
if (f_decl == NULL) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
694 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
695 |
/* determine the base data type returned by the function being called... */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
696 |
search_base_type_c search_base_type; |
406
6381589697ff
Fix bug with overloaded function due to literal input values
laurent
parents:
399
diff
changeset
|
697 |
function_type_prefix = (symbol_c *)f_decl->type_name->accept(search_base_type); |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
698 |
if (NULL == function_type_prefix) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
699 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
700 |
function_name = symbol->function_name; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
701 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
702 |
/* loop through each function parameter, find the value we should pass |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
703 |
* to it, and then output the c equivalent... |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
704 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
705 |
function_param_iterator_c fp_iterator(f_decl); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
706 |
identifier_c *param_name; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
707 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
708 |
/* flag to cirreclty handle calls to extensible standard functions (i.e. functions with variable number of input parameters) */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
709 |
bool found_first_extensible_parameter = false; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
710 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
711 |
if (fp_iterator.is_extensible_param() && (!found_first_extensible_parameter)) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
712 |
/* We are calling an extensible function. Before passing the extensible |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
713 |
* parameters, we must add a dummy paramater value to tell the called |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
714 |
* function how many extensible parameters we will be passing. |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
715 |
* |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
716 |
* Note that stage 3 has already determined the number of extensible |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
717 |
* paramters, and stored that info in the abstract syntax tree. We simply |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
718 |
* re-use that value. |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
719 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
720 |
/* NOTE: we are not freeing the malloc'd memory. This is not really a bug. |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
721 |
* Since we are writing a compiler, which runs to termination quickly, |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
722 |
* we can consider this as just memory required for the compilation process |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
723 |
* that will be free'd when the program terminates. |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
724 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
725 |
char *tmp = (char *)malloc(32); /* enough space for a call with 10^31 (larger than 2^64) input parameters! */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
726 |
if (tmp == NULL) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
727 |
int res = snprintf(tmp, 32, "%d", symbol->extensible_param_count); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
728 |
if ((res >= 32) || (res < 0)) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
729 |
identifier_c *param_value = new identifier_c(tmp); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
730 |
uint_type_name_c *param_type = new uint_type_name_c(); |
380
b78e59ed4269
Fix bug in generate_c_inlinefcall.cc that prevent to use extendible standard functions
laurent
parents:
355
diff
changeset
|
731 |
identifier_c *param_name = new identifier_c(INLINE_PARAM_COUNT); |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
732 |
ADD_PARAM_LIST(param_name, param_value, param_type, function_param_iterator_c::direction_in) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
733 |
found_first_extensible_parameter = true; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
734 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
735 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
736 |
if (fp_iterator.is_extensible_param()) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
737 |
/* since we are handling an extensible parameter, we must add the index to the |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
738 |
* parameter name so we can go looking for the value passed to the correct |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
739 |
* extended parameter (e.g. IN1, IN2, IN3, IN4, ...) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
740 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
741 |
char *tmp = (char *)malloc(32); /* enough space for a call with 10^31 (larger than 2^64) input parameters! */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
742 |
int res = snprintf(tmp, 32, "%d", fp_iterator.extensible_param_index()); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
743 |
if ((res >= 32) || (res < 0)) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
744 |
param_name = new identifier_c(strdup2(param_name->value, tmp)); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
745 |
if (param_name->value == NULL) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
746 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
747 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
748 |
symbol_c *param_type = fp_iterator.param_type(); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
749 |
if (param_type == NULL) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
750 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
751 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
752 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
753 |
symbol_c *param_value = NULL; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
754 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
755 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
756 |
if (param_value == NULL) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
757 |
param_value = function_call_param_iterator.search_f(param_name); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
758 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
759 |
/* Get the value from a foo(<param_value>) style call */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
760 |
/* NOTE: the following line of code is not required in this case, but it doesn't |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
761 |
* harm to leave it in, as in the case of a formal syntax function call, |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
762 |
* it will always return NULL. |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
763 |
* We leave it in in case we later decide to merge this part of the code together |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
764 |
* with the function calling code in generate_c_st_c, which does require |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
765 |
* the following line... |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
766 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
767 |
if ((param_value == NULL) && !fp_iterator.is_en_eno_param_implicit()) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
768 |
param_value = function_call_param_iterator.next_nf(); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
769 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
770 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
771 |
/* if no more parameter values in function call, and the current parameter |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
772 |
* of the function declaration is an extensible parameter, we |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
773 |
* have reached the end, and should simply jump out of the for loop. |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
774 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
775 |
if ((param_value == NULL) && (fp_iterator.is_extensible_param())) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
776 |
break; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
777 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
778 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
779 |
if ((param_value == NULL) && (param_direction == function_param_iterator_c::direction_in)) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
780 |
/* No value given for parameter, so we must use the default... */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
781 |
/* First check whether default value specified in function declaration...*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
782 |
param_value = fp_iterator.default_value(); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
783 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
784 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
785 |
ADD_PARAM_LIST(param_name, param_value, param_type, fp_iterator.param_direction()) |
235 | 786 |
} |
787 |
||
788 |
if (function_call_param_iterator.next_nf() != NULL) ERROR; |
|
789 |
||
790 |
bool has_output_params = false; |
|
791 |
||
792 |
PARAM_LIST_ITERATOR() { |
|
793 |
if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
|
794 |
PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
|
795 |
PARAM_VALUE != NULL) { |
|
796 |
has_output_params = true; |
|
219 | 797 |
} |
235 | 798 |
} |
799 |
||
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
800 |
/* Check whether we are calling an overloaded function! */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
801 |
/* (fdecl_mutiplicity==2) => calling overloaded function */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
802 |
int fdecl_mutiplicity = function_symtable.multiplicity(symbol->function_name); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
803 |
if (fdecl_mutiplicity == 0) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
804 |
if (fdecl_mutiplicity == 1) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
805 |
/* function being called is NOT overloaded! */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
806 |
f_decl = NULL; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
807 |
|
235 | 808 |
if (has_output_params) |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
809 |
generate_inline(function_name, function_type_prefix, function_type_suffix, param_list, f_decl); |
235 | 810 |
|
811 |
CLEAR_PARAM_LIST() |
|
812 |
||
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
813 |
/* the data type resulting from this operation... */ |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
814 |
default_variable_name.current_type = function_type_prefix; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
815 |
return NULL; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
816 |
} |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
817 |
|
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
818 |
/* | simple_instr_list il_simple_instruction */ |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
819 |
// SYM_LIST(simple_instr_list_c) |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
820 |
void *visit(simple_instr_list_c *symbol) { |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
821 |
/* Check whether we should initiliase the il default variable... */ |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
822 |
if (NULL != this->il_default_variable_init_value) { |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
823 |
/* Yes, we must... */ |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
824 |
/* We will do it by instatiating a LD operator, and having this |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
825 |
* same generate_c_il_c class visiting it! |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
826 |
*/ |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
827 |
LD_operator_c ld_oper; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
828 |
il_simple_operation_c il_simple_oper(&ld_oper, this->il_default_variable_init_value); |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
829 |
|
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
830 |
il_simple_oper.accept(*this); |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
831 |
} |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
832 |
|
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
833 |
/* this parameter no longer required... */ |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
834 |
this->il_default_variable_init_value = NULL; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
835 |
|
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
836 |
iterator_visitor_c::visit(symbol); |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
837 |
|
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
838 |
/* copy the result in the default variable to the variable |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
839 |
* used to pass the data out to the scope enclosing |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
840 |
* the current scope! |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
841 |
* |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
842 |
* We also need to update the data type currently stored within |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
843 |
* the variable used to pass the data to the outside scope... |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
844 |
*/ |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
845 |
this->default_variable_back_name.current_type = this->default_variable_name.current_type; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
846 |
return NULL; |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
847 |
} |
453
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
392
diff
changeset
|
848 |
|
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
392
diff
changeset
|
849 |
// SYM_REF1(il_simple_instruction_c, il_simple_instruction, symbol_c *prev_il_instruction;) |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
850 |
void *visit(il_simple_instruction_c *symbol) { |
453
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
392
diff
changeset
|
851 |
return symbol->il_simple_instruction->accept(*this); |
4733f662362a
More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
392
diff
changeset
|
852 |
} |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
853 |
|
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
854 |
void *visit(LD_operator_c *symbol) { |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
855 |
/* the data type resulting from this operation... */ |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
856 |
this->default_variable_name.current_type = this->current_operand_type; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
857 |
return NULL; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
858 |
} |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
859 |
|
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
860 |
void *visit(LDN_operator_c *symbol) { |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
861 |
/* the data type resulting from this operation... */ |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
862 |
this->default_variable_name.current_type = this->current_operand_type; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
863 |
return NULL; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
864 |
} |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
865 |
|
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
866 |
void *visit(AND_operator_c *symbol) { |
346
620fd98a021d
Adding BYTE operators visit functions in inlinefcall
laurent
parents:
345
diff
changeset
|
867 |
if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
620fd98a021d
Adding BYTE operators visit functions in inlinefcall
laurent
parents:
345
diff
changeset
|
868 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
869 |
BYTE_operator_result_type(); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
870 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
871 |
else {ERROR;} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
872 |
return NULL; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
873 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
874 |
|
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
875 |
void *visit(OR_operator_c *symbol) { |
346
620fd98a021d
Adding BYTE operators visit functions in inlinefcall
laurent
parents:
345
diff
changeset
|
876 |
if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
620fd98a021d
Adding BYTE operators visit functions in inlinefcall
laurent
parents:
345
diff
changeset
|
877 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
878 |
BYTE_operator_result_type(); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
879 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
880 |
else {ERROR;} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
881 |
return NULL; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
882 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
883 |
|
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
884 |
void *visit(XOR_operator_c *symbol) { |
346
620fd98a021d
Adding BYTE operators visit functions in inlinefcall
laurent
parents:
345
diff
changeset
|
885 |
if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
620fd98a021d
Adding BYTE operators visit functions in inlinefcall
laurent
parents:
345
diff
changeset
|
886 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
887 |
BYTE_operator_result_type(); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
888 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
889 |
else {ERROR;} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
890 |
return NULL; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
891 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
892 |
|
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
893 |
void *visit(ANDN_operator_c *symbol) { |
346
620fd98a021d
Adding BYTE operators visit functions in inlinefcall
laurent
parents:
345
diff
changeset
|
894 |
if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
620fd98a021d
Adding BYTE operators visit functions in inlinefcall
laurent
parents:
345
diff
changeset
|
895 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
896 |
BYTE_operator_result_type(); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
897 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
898 |
else {ERROR;} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
899 |
return NULL; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
900 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
901 |
|
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
902 |
void *visit(ORN_operator_c *symbol) { |
346
620fd98a021d
Adding BYTE operators visit functions in inlinefcall
laurent
parents:
345
diff
changeset
|
903 |
if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
620fd98a021d
Adding BYTE operators visit functions in inlinefcall
laurent
parents:
345
diff
changeset
|
904 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
905 |
BYTE_operator_result_type(); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
906 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
907 |
else {ERROR;} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
908 |
return NULL; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
909 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
910 |
|
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
911 |
void *visit(XORN_operator_c *symbol) { |
346
620fd98a021d
Adding BYTE operators visit functions in inlinefcall
laurent
parents:
345
diff
changeset
|
912 |
if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
620fd98a021d
Adding BYTE operators visit functions in inlinefcall
laurent
parents:
345
diff
changeset
|
913 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
914 |
BYTE_operator_result_type(); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
915 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
916 |
else {ERROR;} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
917 |
return NULL; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
918 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
919 |
|
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
920 |
void *visit(ADD_operator_c *symbol) { |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
921 |
if (search_expression_type->is_time_type(this->default_variable_name.current_type) && |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
922 |
search_expression_type->is_time_type(this->current_operand_type)) { |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
923 |
/* the data type resulting from this operation... */ |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
924 |
this->default_variable_name.current_type = this->current_operand_type; |
345
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
925 |
} |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
926 |
else if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
927 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
345
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
928 |
NUM_operator_result_type(); |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
929 |
} |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
930 |
else {ERROR;} |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
931 |
return NULL; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
932 |
} |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
933 |
|
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
934 |
void *visit(SUB_operator_c *symbol) { |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
935 |
if (search_expression_type->is_time_type(this->default_variable_name.current_type) && |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
936 |
search_expression_type->is_time_type(this->current_operand_type)) { |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
937 |
/* the data type resulting from this operation... */ |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
938 |
this->default_variable_name.current_type = this->current_operand_type; |
345
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
939 |
} |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
940 |
else if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
941 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
942 |
NUM_operator_result_type(); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
943 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
944 |
else {ERROR;} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
945 |
return NULL; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
946 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
947 |
|
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
948 |
void *visit(MUL_operator_c *symbol) { |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
949 |
if (search_expression_type->is_time_type(this->default_variable_name.current_type) && |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
950 |
search_expression_type->is_integer_type(this->current_operand_type)) { |
345
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
951 |
/* the data type resulting from this operation is unchanged! */ |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
952 |
} |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
953 |
else if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
954 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
955 |
NUM_operator_result_type(); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
956 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
957 |
else {ERROR;} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
958 |
return NULL; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
959 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
960 |
|
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
961 |
void *visit(DIV_operator_c *symbol) { |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
962 |
if (search_expression_type->is_time_type(this->default_variable_name.current_type) && |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
963 |
search_expression_type->is_integer_type(this->current_operand_type)) { |
345
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
964 |
/* the data type resulting from this operation is unchanged! */ |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
965 |
} |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
966 |
else if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
967 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
345
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
968 |
NUM_operator_result_type(); |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
969 |
} |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
970 |
else {ERROR;} |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
971 |
return NULL; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
972 |
} |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
973 |
|
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
974 |
void *visit(MOD_operator_c *symbol) { |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
975 |
if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
976 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
345
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
977 |
NUM_operator_result_type(); |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
978 |
} |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
979 |
else {ERROR;} |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
980 |
return NULL; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
981 |
} |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
982 |
|
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
983 |
void *visit(GT_operator_c *symbol) { |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
984 |
if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) && |
345
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
985 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
986 |
CMP_operator_result_type(); |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
987 |
} |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
988 |
else {ERROR;} |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
989 |
return NULL; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
990 |
} |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
991 |
|
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
992 |
void *visit(GE_operator_c *symbol) { |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
993 |
if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) && |
345
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
994 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
995 |
CMP_operator_result_type(); |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
996 |
} |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
997 |
else {ERROR;} |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
998 |
return NULL; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
999 |
} |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
1000 |
|
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1001 |
void *visit(EQ_operator_c *symbol) { |
345
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
1002 |
if (search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
1003 |
CMP_operator_result_type(); |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
1004 |
} |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
1005 |
else {ERROR;} |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
1006 |
return NULL; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
1007 |
} |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
1008 |
|
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1009 |
void *visit(LT_operator_c *symbol) { |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
1010 |
if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) && |
345
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
1011 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
1012 |
CMP_operator_result_type(); |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
1013 |
} |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
1014 |
else {ERROR;} |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
1015 |
return NULL; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
1016 |
} |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
1017 |
|
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1018 |
void *visit(LE_operator_c *symbol) { |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
1019 |
if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) && |
345
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
1020 |
search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
1021 |
CMP_operator_result_type(); |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
1022 |
} |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
1023 |
else {ERROR;} |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
1024 |
return NULL; |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
1025 |
} |
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
1026 |
|
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1027 |
void *visit(NE_operator_c *symbol) { |
345
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
1028 |
if (search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
1029 |
CMP_operator_result_type(); |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
1030 |
} |
894c0e6d951c
Fix bug with DIV and MOD operator in IL code generator
laurent
parents:
337
diff
changeset
|
1031 |
else {ERROR;} |
219 | 1032 |
return NULL; |
1033 |
} |
|
1034 |
||
1035 |
/***************************************/ |
|
1036 |
/* B.3 - Language ST (Structured Text) */ |
|
1037 |
/***************************************/ |
|
1038 |
/***********************/ |
|
1039 |
/* B 3.1 - Expressions */ |
|
1040 |
/***********************/ |
|
1041 |
||
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
1042 |
void *visit(statement_list_c *symbol) { |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1043 |
function_call_iterator_c fc_iterator(symbol); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1044 |
symbol_c* function_call; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1045 |
while ((function_call = fc_iterator.next()) != NULL) { |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1046 |
function_call->accept(*this); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1047 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1048 |
return NULL; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1049 |
} |
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
1050 |
|
219 | 1051 |
void *visit(function_invocation_c *symbol) { |
235 | 1052 |
symbol_c* function_type_prefix = NULL; |
1053 |
symbol_c* function_name = NULL; |
|
1054 |
symbol_c* function_type_suffix = NULL; |
|
1055 |
DECLARE_PARAM_LIST() |
|
1056 |
||
1057 |
symbol_c *parameter_assignment_list = NULL; |
|
1058 |
if (NULL != symbol-> formal_param_list) parameter_assignment_list = symbol-> formal_param_list; |
|
1059 |
if (NULL != symbol->nonformal_param_list) parameter_assignment_list = symbol->nonformal_param_list; |
|
1060 |
if (NULL == parameter_assignment_list) ERROR; |
|
1061 |
||
1062 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
1063 |
||
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1064 |
function_declaration_c *f_decl = (function_declaration_c *)symbol->called_function_declaration; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1065 |
if (f_decl == NULL) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1066 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1067 |
function_name = symbol->function_name; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1068 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1069 |
/* determine the base data type returned by the function being called... */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1070 |
search_base_type_c search_base_type; |
406
6381589697ff
Fix bug with overloaded function due to literal input values
laurent
parents:
399
diff
changeset
|
1071 |
function_type_prefix = (symbol_c *)f_decl->type_name->accept(search_base_type); |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1072 |
if (NULL == function_type_prefix) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1073 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1074 |
/* loop through each function parameter, find the value we should pass |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1075 |
* to it, and then output the c equivalent... |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1076 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1077 |
function_param_iterator_c fp_iterator(f_decl); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1078 |
identifier_c *param_name; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1079 |
/* flag to cirreclty handle calls to extensible standard functions (i.e. functions with variable number of input parameters) */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1080 |
bool found_first_extensible_parameter = false; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1081 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1082 |
if (fp_iterator.is_extensible_param() && (!found_first_extensible_parameter)) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1083 |
/* We are calling an extensible function. Before passing the extensible |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1084 |
* parameters, we must add a dummy paramater value to tell the called |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1085 |
* function how many extensible parameters we will be passing. |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1086 |
* |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1087 |
* Note that stage 3 has already determined the number of extensible |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1088 |
* paramters, and stored that info in the abstract syntax tree. We simply |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1089 |
* re-use that value. |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1090 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1091 |
/* NOTE: we are not freeing the malloc'd memory. This is not really a bug. |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1092 |
* Since we are writing a compiler, which runs to termination quickly, |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1093 |
* we can consider this as just memory required for the compilation process |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1094 |
* that will be free'd when the program terminates. |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1095 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1096 |
char *tmp = (char *)malloc(32); /* enough space for a call with 10^31 (larger than 2^64) input parameters! */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1097 |
if (tmp == NULL) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1098 |
int res = snprintf(tmp, 32, "%d", symbol->extensible_param_count); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1099 |
if ((res >= 32) || (res < 0)) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1100 |
identifier_c *param_value = new identifier_c(tmp); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1101 |
uint_type_name_c *param_type = new uint_type_name_c(); |
380
b78e59ed4269
Fix bug in generate_c_inlinefcall.cc that prevent to use extendible standard functions
laurent
parents:
355
diff
changeset
|
1102 |
identifier_c *param_name = new identifier_c(INLINE_PARAM_COUNT); |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1103 |
ADD_PARAM_LIST(param_name, param_value, param_type, function_param_iterator_c::direction_in) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1104 |
found_first_extensible_parameter = true; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1105 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1106 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1107 |
if (fp_iterator.is_extensible_param()) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1108 |
/* since we are handling an extensible parameter, we must add the index to the |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1109 |
* parameter name so we can go looking for the value passed to the correct |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1110 |
* extended parameter (e.g. IN1, IN2, IN3, IN4, ...) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1111 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1112 |
char *tmp = (char *)malloc(32); /* enough space for a call with 10^31 (larger than 2^64) input parameters! */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1113 |
int res = snprintf(tmp, 32, "%d", fp_iterator.extensible_param_index()); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1114 |
if ((res >= 32) || (res < 0)) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1115 |
param_name = new identifier_c(strdup2(param_name->value, tmp)); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1116 |
if (param_name->value == NULL) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1117 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1118 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1119 |
symbol_c *param_type = fp_iterator.param_type(); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1120 |
if (param_type == NULL) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1121 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1122 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1123 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1124 |
symbol_c *param_value = NULL; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1125 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1126 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1127 |
if (param_value == NULL) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1128 |
param_value = function_call_param_iterator.search_f(param_name); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1129 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1130 |
/* Get the value from a foo(<param_value>) style call */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1131 |
if ((param_value == NULL) && !fp_iterator.is_en_eno_param_implicit()) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1132 |
param_value = function_call_param_iterator.next_nf(); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1133 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1134 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1135 |
/* if no more parameter values in function call, and the current parameter |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1136 |
* of the function declaration is an extensible parameter, we |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1137 |
* have reached the end, and should simply jump out of the for loop. |
219 | 1138 |
*/ |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1139 |
if ((param_value == NULL) && (fp_iterator.is_extensible_param())) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1140 |
break; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1141 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1142 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1143 |
if ((param_value == NULL) && (param_direction == function_param_iterator_c::direction_in)) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1144 |
/* No value given for parameter, so we must use the default... */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1145 |
/* First check whether default value specified in function declaration...*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1146 |
param_value = fp_iterator.default_value(); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1147 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1148 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1149 |
ADD_PARAM_LIST(param_name, param_value, param_type, param_direction) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1150 |
} /* for(...) */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1151 |
// symbol->parameter_assignment->accept(*this); |
235 | 1152 |
|
1153 |
if (function_call_param_iterator.next_nf() != NULL) ERROR; |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1154 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1155 |
bool has_output_params = false; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1156 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1157 |
PARAM_LIST_ITERATOR() { |
235 | 1158 |
if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
1159 |
PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
|
1160 |
PARAM_VALUE != NULL) { |
|
1161 |
has_output_params = true; |
|
219 | 1162 |
} |
235 | 1163 |
} |
1164 |
||
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1165 |
/* Check whether we are calling an overloaded function! */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1166 |
/* (fdecl_mutiplicity==2) => calling overloaded function */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1167 |
int fdecl_mutiplicity = function_symtable.multiplicity(symbol->function_name); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1168 |
if (fdecl_mutiplicity == 0) ERROR; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1169 |
if (fdecl_mutiplicity == 1) |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1170 |
/* function being called is NOT overloaded! */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1171 |
f_decl = NULL; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1172 |
|
235 | 1173 |
if (has_output_params) |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
1174 |
generate_inline(function_name, function_type_prefix, function_type_suffix, param_list, f_decl); |
235 | 1175 |
|
1176 |
CLEAR_PARAM_LIST() |
|
1177 |
||
337
9a2262fb7994
Fix bug with inline function call in POU programmed in IL
laurent
parents:
336
diff
changeset
|
1178 |
return NULL; |
219 | 1179 |
} |
1180 |
||
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1181 |
/*********************************************/ |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1182 |
/* B.1.6 Sequential function chart elements */ |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1183 |
/*********************************************/ |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1184 |
|
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1185 |
void *visit(initial_step_c *symbol) { |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1186 |
return NULL; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1187 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1188 |
|
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1189 |
void *visit(step_c *symbol) { |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1190 |
return NULL; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1191 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1192 |
|
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1193 |
void *visit(transition_c *symbol) { |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1194 |
return symbol->transition_condition->accept(*this); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1195 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1196 |
|
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1197 |
void *visit(transition_condition_c *symbol) { |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1198 |
// Transition condition is in IL |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1199 |
if (symbol->transition_condition_il != NULL) { |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1200 |
symbol->transition_condition_il->accept(*this); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1201 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1202 |
|
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1203 |
// Transition condition is in ST |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1204 |
if (symbol->transition_condition_st != NULL) { |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1205 |
function_call_iterator_c fc_iterator(symbol->transition_condition_st); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1206 |
symbol_c* function_call; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1207 |
while ((function_call = fc_iterator.next()) != NULL) { |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1208 |
function_call->accept(*this); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1209 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1210 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1211 |
|
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1212 |
return NULL; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1213 |
} |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1214 |
|
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1215 |
void *visit(action_c *symbol) { |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1216 |
return symbol->function_block_body->accept(*this); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1217 |
} |
388
17eaad42ba88
Fix bug in generate_c_inlinefcall. Was not handling textual SFC elements
laurent
parents:
383
diff
changeset
|
1218 |
|
234
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
1219 |
}; /* generate_c_inlinefcall_c */ |
e4d31cd0e6d8
Using function_call_iterator in generate_c_inlinefcall instead of creating a new visitor
laurent
parents:
233
diff
changeset
|
1220 |