author | mjsousa |
Sun, 09 Feb 2014 07:23:30 +0000 | |
changeset 861 | 443e8243f289 |
parent 855 | a3109442e166 |
child 864 | 300c27c08753 |
permissions | -rwxr-xr-x |
70 | 1 |
/* |
279
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
2 |
* matiec - a compiler for the programming languages defined in IEC 61131-3 |
70 | 3 |
* |
279
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
4 |
* Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt) |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
5 |
* Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant |
70 | 6 |
* |
279
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
7 |
* This program is free software: you can redistribute it and/or modify |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
8 |
* it under the terms of the GNU General Public License as published by |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
9 |
* the Free Software Foundation, either version 3 of the License, or |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
10 |
* (at your option) any later version. |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
11 |
* |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
12 |
* This program is distributed in the hope that it will be useful, |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
15 |
* GNU General Public License for more details. |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
16 |
* |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License |
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
18 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
70 | 19 |
* |
20 |
* This code is made available on the understanding that it will not be |
|
21 |
* used in safety-critical situations without a full and competent review. |
|
22 |
* |
|
23 |
* Based on the |
|
24 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
25 |
* |
|
26 |
*/ |
|
27 |
||
28 |
||
29 |
/* |
|
30 |
* Conversion of st statements (i.e. ST code). |
|
31 |
* |
|
32 |
* This is part of the 4th stage that generates |
|
279
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
258
diff
changeset
|
33 |
* a C source program equivalent to the IL and ST, or SFC |
70 | 34 |
* code. |
35 |
*/ |
|
36 |
||
37 |
||
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
38 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
39 |
#include "../../util/strdup.hh" |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
40 |
|
70 | 41 |
/***********************************************************************/ |
42 |
/***********************************************************************/ |
|
43 |
/***********************************************************************/ |
|
44 |
/***********************************************************************/ |
|
45 |
||
46 |
||
861
443e8243f289
Code cleanup (part 3): generate_c_typedecl_c is no longer needed for code generation in POUS.c It is now only needed for datatype declaration in POUS.h
mjsousa
parents:
855
diff
changeset
|
47 |
class generate_c_st_c: public generate_c_base_c { |
70 | 48 |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
49 |
public: |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
50 |
typedef enum { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
51 |
expression_vg, |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
52 |
assignment_vg, |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
53 |
complextype_base_vg, |
392
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
387
diff
changeset
|
54 |
complextype_base_assignment_vg, |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
55 |
complextype_suffix_vg, |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
56 |
fparam_output_vg |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
57 |
} variablegeneration_t; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
58 |
|
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
59 |
typedef enum { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
60 |
single_cg, |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
61 |
subrange_cg, |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
62 |
none_cg |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
63 |
} casegeneration_t; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
64 |
|
70 | 65 |
private: |
66 |
/* When calling a function block, we must first find it's type, |
|
67 |
* by searching through the declarations of the variables currently |
|
68 |
* in scope. |
|
69 |
* This class does just that... |
|
70 |
* A new class is instantiated whenever we begin generating the code |
|
71 |
* for a function block type declaration, or a program declaration. |
|
72 |
* This object instance will then later be called while the |
|
73 |
* function block's or the program's body is being handled. |
|
74 |
* |
|
75 |
* Note that functions cannot contain calls to function blocks, |
|
76 |
* so we do not create an object instance when handling |
|
77 |
* a function declaration. |
|
78 |
*/ |
|
79 |
search_fb_instance_decl_c *search_fb_instance_decl; |
|
80 |
||
81 |
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:
503
diff
changeset
|
82 |
search_var_instance_decl_c *search_var_instance_decl; |
70 | 83 |
|
98 | 84 |
symbol_c* current_array_type; |
235 | 85 |
symbol_c* current_param_type; |
98 | 86 |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
87 |
int fcall_number; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
88 |
symbol_c *fbname; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
89 |
|
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
90 |
bool first_subrange_case_list; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
91 |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
92 |
variablegeneration_t wanted_variablegeneration; |
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
93 |
casegeneration_t wanted_casegeneration; |
145 | 94 |
|
70 | 95 |
public: |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
96 |
generate_c_st_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL) |
861
443e8243f289
Code cleanup (part 3): generate_c_typedecl_c is no longer needed for code generation in POUS.c It is now only needed for datatype declaration in POUS.h
mjsousa
parents:
855
diff
changeset
|
97 |
: generate_c_base_c(s4o_ptr) { |
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
98 |
search_fb_instance_decl = new search_fb_instance_decl_c (scope); |
70 | 99 |
search_varfb_instance_type = new search_varfb_instance_type_c(scope); |
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
100 |
search_var_instance_decl = new search_var_instance_decl_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:
503
diff
changeset
|
101 |
|
70 | 102 |
this->set_variable_prefix(variable_prefix); |
98 | 103 |
current_array_type = NULL; |
235 | 104 |
current_param_type = NULL; |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
105 |
fcall_number = 0; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
106 |
fbname = name; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
107 |
wanted_variablegeneration = expression_vg; |
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
108 |
wanted_casegeneration = none_cg; |
70 | 109 |
} |
110 |
||
111 |
virtual ~generate_c_st_c(void) { |
|
112 |
delete search_fb_instance_decl; |
|
113 |
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:
503
diff
changeset
|
114 |
delete search_var_instance_decl; |
70 | 115 |
} |
116 |
||
117 |
||
118 |
public: |
|
119 |
void generate(statement_list_c *stl) { |
|
120 |
stl->accept(*this); |
|
121 |
} |
|
122 |
||
123 |
private: |
|
531
e7d6f28fc882
Make temporary fix to is_complex() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
505
diff
changeset
|
124 |
|
e7d6f28fc882
Make temporary fix to is_complex() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
505
diff
changeset
|
125 |
|
e7d6f28fc882
Make temporary fix to is_complex() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
505
diff
changeset
|
126 |
|
e7d6f28fc882
Make temporary fix to is_complex() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
505
diff
changeset
|
127 |
|
e7d6f28fc882
Make temporary fix to is_complex() method.
Mario de Sousa <msousa@fe.up.pt>
parents:
505
diff
changeset
|
128 |
|
70 | 129 |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
130 |
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:
503
diff
changeset
|
131 |
unsigned int vartype = search_var_instance_decl->get_vartype(symbol); |
235 | 132 |
if (wanted_variablegeneration == fparam_output_vg) { |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
133 |
if (vartype == search_var_instance_decl_c::external_vt) { |
854
13d0b67de111
Code cleanup: move datatype analysis to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
852
diff
changeset
|
134 |
if (!get_datatype_info_c::is_type_valid (symbol->datatype)) ERROR; |
13d0b67de111
Code cleanup: move datatype analysis to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
852
diff
changeset
|
135 |
if ( get_datatype_info_c::is_function_block(symbol->datatype)) |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
136 |
s4o.print(GET_EXTERNAL_FB_BY_REF); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
137 |
else |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
138 |
s4o.print(GET_EXTERNAL_BY_REF); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
139 |
} |
235 | 140 |
else if (vartype == search_var_instance_decl_c::located_vt) |
141 |
s4o.print(GET_LOCATED_BY_REF); |
|
142 |
else |
|
143 |
s4o.print(GET_VAR_BY_REF); |
|
144 |
} |
|
145 |
else { |
|
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
146 |
if (vartype == search_var_instance_decl_c::external_vt) { |
854
13d0b67de111
Code cleanup: move datatype analysis to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
852
diff
changeset
|
147 |
if (!get_datatype_info_c::is_type_valid (symbol->datatype)) ERROR; |
13d0b67de111
Code cleanup: move datatype analysis to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
852
diff
changeset
|
148 |
if ( get_datatype_info_c::is_function_block(symbol->datatype)) |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
149 |
s4o.print(GET_EXTERNAL_FB); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
150 |
else |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
151 |
s4o.print(GET_EXTERNAL); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
152 |
} |
503
e1e7c7678c44
Edit formating and delete unused code.
Mario de Sousa <msousa@fe.up.pt>
parents:
498
diff
changeset
|
153 |
else if (vartype == search_var_instance_decl_c::located_vt) |
e1e7c7678c44
Edit formating and delete unused code.
Mario de Sousa <msousa@fe.up.pt>
parents:
498
diff
changeset
|
154 |
s4o.print(GET_LOCATED); |
e1e7c7678c44
Edit formating and delete unused code.
Mario de Sousa <msousa@fe.up.pt>
parents:
498
diff
changeset
|
155 |
else |
e1e7c7678c44
Edit formating and delete unused code.
Mario de Sousa <msousa@fe.up.pt>
parents:
498
diff
changeset
|
156 |
s4o.print(GET_VAR); |
235 | 157 |
} |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
158 |
s4o.print("("); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
159 |
|
235 | 160 |
variablegeneration_t old_wanted_variablegeneration = wanted_variablegeneration; |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
161 |
wanted_variablegeneration = complextype_base_vg; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
162 |
symbol->accept(*this); |
851
2c59c2b8fca4
Fix bug/issue #33 (correctly access struct/array variables declared inside a FB -> r:=FB1.FB2.struct1.array1[3] )
Mario de Sousa <msousa@fe.up.pt>
parents:
800
diff
changeset
|
163 |
s4o.print(","); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
164 |
wanted_variablegeneration = complextype_suffix_vg; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
165 |
symbol->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
166 |
s4o.print(")"); |
235 | 167 |
wanted_variablegeneration = old_wanted_variablegeneration; |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
168 |
return NULL; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
169 |
} |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
170 |
|
852
efb44e892582
Fix bug: allow use, as lvalues, structures/arrays inside FBs (e.g. fb1.struct1.r := 33.3).
Mario de Sousa <msousa@fe.up.pt>
parents:
851
diff
changeset
|
171 |
|
efb44e892582
Fix bug: allow use, as lvalues, structures/arrays inside FBs (e.g. fb1.struct1.r := 33.3).
Mario de Sousa <msousa@fe.up.pt>
parents:
851
diff
changeset
|
172 |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
173 |
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
|
174 |
symbol_c* type, |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
175 |
symbol_c* value, |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
176 |
symbol_c* fb_symbol = NULL, |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
177 |
symbol_c* fb_value = NULL) { |
302
d120740a6b58
Fixing bug related to setting array variables with values coming from other variables
Mario de Sousa <msousa@fe.up.pt>
parents:
298
diff
changeset
|
178 |
|
405
7b5d67d1aeef
Fix bug wrong code generated when, in a pou, a located variable has the same name than a function block instance input variable
laurent
parents:
399
diff
changeset
|
179 |
bool type_is_complex = false; |
7b5d67d1aeef
Fix bug wrong code generated when, in a pou, a located variable has the same name than a function block instance input variable
laurent
parents:
399
diff
changeset
|
180 |
if (fb_symbol == NULL) { |
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:
503
diff
changeset
|
181 |
unsigned int vartype = search_var_instance_decl->get_vartype(symbol); |
852
efb44e892582
Fix bug: allow use, as lvalues, structures/arrays inside FBs (e.g. fb1.struct1.r := 33.3).
Mario de Sousa <msousa@fe.up.pt>
parents:
851
diff
changeset
|
182 |
type_is_complex = analyse_variable_c::contains_complex_type(symbol); |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
183 |
if (vartype == search_var_instance_decl_c::external_vt) { |
854
13d0b67de111
Code cleanup: move datatype analysis to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
852
diff
changeset
|
184 |
if (!get_datatype_info_c::is_type_valid (symbol->datatype)) ERROR; |
13d0b67de111
Code cleanup: move datatype analysis to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
852
diff
changeset
|
185 |
if ( get_datatype_info_c::is_function_block(symbol->datatype)) |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
186 |
s4o.print(SET_EXTERNAL_FB); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
187 |
else |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
188 |
s4o.print(SET_EXTERNAL); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
189 |
} |
405
7b5d67d1aeef
Fix bug wrong code generated when, in a pou, a located variable has the same name than a function block instance input variable
laurent
parents:
399
diff
changeset
|
190 |
else if (vartype == search_var_instance_decl_c::located_vt) |
7b5d67d1aeef
Fix bug wrong code generated when, in a pou, a located variable has the same name than a function block instance input variable
laurent
parents:
399
diff
changeset
|
191 |
s4o.print(SET_LOCATED); |
7b5d67d1aeef
Fix bug wrong code generated when, in a pou, a located variable has the same name than a function block instance input variable
laurent
parents:
399
diff
changeset
|
192 |
else |
7b5d67d1aeef
Fix bug wrong code generated when, in a pou, a located variable has the same name than a function block instance input variable
laurent
parents:
399
diff
changeset
|
193 |
s4o.print(SET_VAR); |
7b5d67d1aeef
Fix bug wrong code generated when, in a pou, a located variable has the same name than a function block instance input variable
laurent
parents:
399
diff
changeset
|
194 |
} |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
195 |
else { |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
196 |
unsigned int vartype = search_var_instance_decl->get_vartype(fb_symbol); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
197 |
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
|
198 |
s4o.print(SET_EXTERNAL_FB); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
199 |
else |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
200 |
s4o.print(SET_VAR); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
201 |
} |
392
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
387
diff
changeset
|
202 |
s4o.print("("); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
203 |
|
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
204 |
if (fb_symbol != NULL) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
205 |
print_variable_prefix(); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
206 |
fb_symbol->accept(*this); |
392
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
387
diff
changeset
|
207 |
s4o.print(".,"); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
208 |
} |
382
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
209 |
else if (type_is_complex) |
392
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
387
diff
changeset
|
210 |
wanted_variablegeneration = complextype_base_assignment_vg; |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
211 |
else |
382
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
212 |
wanted_variablegeneration = assignment_vg; |
302
d120740a6b58
Fixing bug related to setting array variables with values coming from other variables
Mario de Sousa <msousa@fe.up.pt>
parents:
298
diff
changeset
|
213 |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
214 |
symbol->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
215 |
s4o.print(","); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
216 |
wanted_variablegeneration = expression_vg; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
217 |
print_check_function(type, value, fb_value); |
382
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
218 |
if (type_is_complex) { |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
219 |
s4o.print(","); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
220 |
wanted_variablegeneration = complextype_suffix_vg; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
221 |
symbol->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
222 |
} |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
223 |
s4o.print(")"); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
224 |
wanted_variablegeneration = expression_vg; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
225 |
return NULL; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
226 |
} |
146
eef5e62048c7
Adding support for EN/ENO params in function and function blocks (standard function not supported yet)
lbessard
parents:
145
diff
changeset
|
227 |
|
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
228 |
/********************************/ |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
229 |
/* B 1.3.3 - Derived data types */ |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
230 |
/********************************/ |
377
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
231 |
|
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
232 |
/* signed_integer DOTDOT signed_integer */ |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
233 |
void *visit(subrange_c *symbol) { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
234 |
switch (wanted_casegeneration) { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
235 |
case subrange_cg: |
376 | 236 |
s4o.print("__case_expression >= "); |
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
237 |
symbol->lower_limit->accept(*this); |
376 | 238 |
s4o.print(" && __case_expression <= "); |
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
239 |
symbol->upper_limit->accept(*this); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
240 |
break; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
241 |
default: |
377
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
242 |
symbol->lower_limit->accept(*this); |
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
243 |
break; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
244 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
245 |
return NULL; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
246 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
247 |
|
377
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
248 |
/* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */ |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
249 |
void *visit(array_specification_c *symbol) { |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
250 |
symbol->non_generic_type_name->accept(*this); |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
251 |
return NULL; |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
252 |
} |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
253 |
|
800
2481fffe6e58
Fixed bug in case statement with enumerated type variable as case expression
Laurent Bessard
parents:
793
diff
changeset
|
254 |
/* enumerated_type_name ':' enumerated_spec_init */ |
2481fffe6e58
Fixed bug in case statement with enumerated type variable as case expression
Laurent Bessard
parents:
793
diff
changeset
|
255 |
void *visit(enumerated_type_declaration_c *symbol) { |
2481fffe6e58
Fixed bug in case statement with enumerated type variable as case expression
Laurent Bessard
parents:
793
diff
changeset
|
256 |
symbol->enumerated_type_name->accept(*this); |
2481fffe6e58
Fixed bug in case statement with enumerated type variable as case expression
Laurent Bessard
parents:
793
diff
changeset
|
257 |
return NULL; |
2481fffe6e58
Fixed bug in case statement with enumerated type variable as case expression
Laurent Bessard
parents:
793
diff
changeset
|
258 |
} |
2481fffe6e58
Fixed bug in case statement with enumerated type variable as case expression
Laurent Bessard
parents:
793
diff
changeset
|
259 |
|
70 | 260 |
/*********************/ |
261 |
/* B 1.4 - Variables */ |
|
262 |
/*********************/ |
|
263 |
void *visit(symbolic_variable_c *symbol) { |
|
382
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
264 |
switch (wanted_variablegeneration) { |
392
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
387
diff
changeset
|
265 |
case complextype_base_assignment_vg: |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
387
diff
changeset
|
266 |
case assignment_vg: |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
387
diff
changeset
|
267 |
this->print_variable_prefix(); |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
387
diff
changeset
|
268 |
s4o.print(","); |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
387
diff
changeset
|
269 |
symbol->var_name->accept(*this); |
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
387
diff
changeset
|
270 |
break; |
382
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
271 |
case complextype_base_vg: |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
272 |
generate_c_base_c::visit(symbol); |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
273 |
break; |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
274 |
case complextype_suffix_vg: |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
275 |
break; |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
276 |
default: |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
277 |
if (this->is_variable_prefix_null()) { |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
278 |
if (wanted_variablegeneration == fparam_output_vg) { |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
279 |
s4o.print("&("); |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
280 |
generate_c_base_c::visit(symbol); |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
281 |
s4o.print(")"); |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
282 |
} |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
283 |
else { |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
284 |
generate_c_base_c::visit(symbol); |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
285 |
} |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
286 |
} |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
287 |
else |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
288 |
print_getter(symbol); |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
289 |
break; |
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
290 |
} |
70 | 291 |
return NULL; |
292 |
} |
|
293 |
||
294 |
/********************************************/ |
|
295 |
/* B.1.4.1 Directly Represented Variables */ |
|
296 |
/********************************************/ |
|
297 |
// direct_variable: direct_variable_token {$$ = new direct_variable_c($1);}; |
|
298 |
void *visit(direct_variable_c *symbol) { |
|
299 |
TRACE("direct_variable_c"); |
|
300 |
/* Do not use print_token() as it will change everything into uppercase */ |
|
301 |
if (strlen(symbol->value) == 0) ERROR; |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
302 |
if (this->is_variable_prefix_null()) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
303 |
if (wanted_variablegeneration != fparam_output_vg) |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
304 |
s4o.print("*("); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
305 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
306 |
else { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
307 |
switch (wanted_variablegeneration) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
308 |
case expression_vg: |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
309 |
s4o.print(GET_LOCATED); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
310 |
s4o.print("("); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
311 |
break; |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
312 |
case fparam_output_vg: |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
313 |
s4o.print(GET_LOCATED_BY_REF); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
314 |
s4o.print("("); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
315 |
break; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
316 |
default: |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
317 |
break; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
318 |
} |
145 | 319 |
} |
70 | 320 |
this->print_variable_prefix(); |
321 |
s4o.printlocation(symbol->value + 1); |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
322 |
if ((this->is_variable_prefix_null() && wanted_variablegeneration != fparam_output_vg) || |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
323 |
wanted_variablegeneration != assignment_vg) |
145 | 324 |
s4o.print(")"); |
70 | 325 |
return NULL; |
326 |
} |
|
327 |
||
98 | 328 |
/*************************************/ |
329 |
/* B.1.4.2 Multi-element Variables */ |
|
330 |
/*************************************/ |
|
331 |
||
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
220
diff
changeset
|
332 |
// SYM_REF2(structured_variable_c, record_variable, field_selector) |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
220
diff
changeset
|
333 |
void *visit(structured_variable_c *symbol) { |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
220
diff
changeset
|
334 |
TRACE("structured_variable_c"); |
854
13d0b67de111
Code cleanup: move datatype analysis to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
852
diff
changeset
|
335 |
bool type_is_complex = analyse_variable_c::is_complex_type(symbol->record_variable); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
336 |
switch (wanted_variablegeneration) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
337 |
case complextype_base_vg: |
392
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
387
diff
changeset
|
338 |
case complextype_base_assignment_vg: |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
339 |
symbol->record_variable->accept(*this); |
410
c6486bd97392
Fix bug while using complex type variables in Function and FunctionBlock interface
Laurent Bessard
parents:
406
diff
changeset
|
340 |
if (!type_is_complex) { |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
341 |
s4o.print("."); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
342 |
symbol->field_selector->accept(*this); |
410
c6486bd97392
Fix bug while using complex type variables in Function and FunctionBlock interface
Laurent Bessard
parents:
406
diff
changeset
|
343 |
} |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
344 |
break; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
345 |
case complextype_suffix_vg: |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
346 |
symbol->record_variable->accept(*this); |
410
c6486bd97392
Fix bug while using complex type variables in Function and FunctionBlock interface
Laurent Bessard
parents:
406
diff
changeset
|
347 |
if (type_is_complex) { |
c6486bd97392
Fix bug while using complex type variables in Function and FunctionBlock interface
Laurent Bessard
parents:
406
diff
changeset
|
348 |
s4o.print("."); |
c6486bd97392
Fix bug while using complex type variables in Function and FunctionBlock interface
Laurent Bessard
parents:
406
diff
changeset
|
349 |
symbol->field_selector->accept(*this); |
c6486bd97392
Fix bug while using complex type variables in Function and FunctionBlock interface
Laurent Bessard
parents:
406
diff
changeset
|
350 |
} |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
351 |
break; |
382
ac6dfec701c9
Fix bug in parser while trying to use IL operator like S1, R1, etc... as standard function block interface variable in structured_variable syntax and bug in code generator while generating code for assignment of function block interface variable using structured_variable syntax
laurent
parents:
377
diff
changeset
|
352 |
case assignment_vg: |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
353 |
symbol->record_variable->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
354 |
s4o.print("."); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
355 |
symbol->field_selector->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
356 |
break; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
357 |
default: |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
358 |
if (this->is_variable_prefix_null()) { |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
359 |
symbol->record_variable->accept(*this); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
360 |
s4o.print("."); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
361 |
symbol->field_selector->accept(*this); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
362 |
} |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
363 |
else |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
364 |
print_getter(symbol); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
365 |
break; |
221
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
220
diff
changeset
|
366 |
} |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
220
diff
changeset
|
367 |
return NULL; |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
220
diff
changeset
|
368 |
} |
c6aed7e5f070
Adding support for flags on Function Block variables for marking which variable must be debugged, retained or is forced
laurent
parents:
220
diff
changeset
|
369 |
|
98 | 370 |
/* subscripted_variable '[' subscript_list ']' */ |
371 |
//SYM_REF2(array_variable_c, subscripted_variable, subscript_list) |
|
372 |
void *visit(array_variable_c *symbol) { |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
373 |
switch (wanted_variablegeneration) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
374 |
case complextype_base_vg: |
392
9b88b8b6bccd
Fixing generated code for global variables. Adding support for defining global variables with complex type
laurent
parents:
387
diff
changeset
|
375 |
case complextype_base_assignment_vg: |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
376 |
symbol->subscripted_variable->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
377 |
break; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
378 |
case complextype_suffix_vg: |
238
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
379 |
symbol->subscripted_variable->accept(*this); |
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
380 |
|
417
d48f53715f77
Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
392
diff
changeset
|
381 |
current_array_type = search_varfb_instance_type->get_basetype_decl(symbol->subscripted_variable); |
238
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
382 |
if (current_array_type == NULL) ERROR; |
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
383 |
|
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
384 |
s4o.print(".table"); |
298
022a874149ce
Fixing code generation of array indexes in Function Blocks.
Mario de Sousa <msousa@fe.up.pt>
parents:
283
diff
changeset
|
385 |
wanted_variablegeneration = expression_vg; |
238
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
386 |
symbol->subscript_list->accept(*this); |
298
022a874149ce
Fixing code generation of array indexes in Function Blocks.
Mario de Sousa <msousa@fe.up.pt>
parents:
283
diff
changeset
|
387 |
wanted_variablegeneration = complextype_suffix_vg; |
238
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
388 |
|
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
389 |
current_array_type = NULL; |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
390 |
break; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
391 |
default: |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
392 |
if (this->is_variable_prefix_null()) { |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
393 |
symbol->subscripted_variable->accept(*this); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
394 |
|
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
395 |
current_array_type = search_varfb_instance_type->get_basetype_decl(symbol->subscripted_variable); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
396 |
if (current_array_type == NULL) ERROR; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
397 |
|
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
398 |
s4o.print(".table"); |
238
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
399 |
symbol->subscript_list->accept(*this); |
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
400 |
|
0919986a5c98
Bug when trying to get type of elements in a big complex structure fixed
laurent
parents:
237
diff
changeset
|
401 |
current_array_type = NULL; |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
402 |
} |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
403 |
else |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
404 |
print_getter(symbol); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
405 |
break; |
98 | 406 |
} |
407 |
return NULL; |
|
408 |
} |
|
409 |
||
410 |
/* subscript_list ',' subscript */ |
|
411 |
void *visit(subscript_list_c *symbol) { |
|
377
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
412 |
array_dimension_iterator_c* array_dimension_iterator = new array_dimension_iterator_c(current_array_type); |
98 | 413 |
for (int i = 0; i < symbol->n; i++) { |
377
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
414 |
symbol_c* dimension = array_dimension_iterator->next(); |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
415 |
if (dimension == NULL) ERROR; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
416 |
|
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
417 |
s4o.print("[("); |
98 | 418 |
symbol->elements[i]->accept(*this); |
377
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
419 |
s4o.print(") - ("); |
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
420 |
dimension->accept(*this); |
98 | 421 |
s4o.print(")]"); |
422 |
} |
|
377
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
376
diff
changeset
|
423 |
delete array_dimension_iterator; |
98 | 424 |
return NULL; |
425 |
} |
|
426 |
||
235 | 427 |
/******************************************/ |
428 |
/* B 1.4.3 - Declaration & Initialisation */ |
|
429 |
/******************************************/ |
|
237 | 430 |
|
431 |
/* helper symbol for structure_initialization */ |
|
432 |
/* structure_element_initialization_list ',' structure_element_initialization */ |
|
235 | 433 |
void *visit(structure_element_initialization_list_c *symbol) { |
434 |
generate_c_structure_initialization_c *structure_initialization = new generate_c_structure_initialization_c(&s4o); |
|
435 |
structure_initialization->init_structure_default(this->current_param_type); |
|
237 | 436 |
structure_initialization->init_structure_values(symbol); |
235 | 437 |
delete structure_initialization; |
438 |
return NULL; |
|
439 |
} |
|
98 | 440 |
|
237 | 441 |
/* helper symbol for array_initialization */ |
442 |
/* array_initial_elements_list ',' array_initial_elements */ |
|
443 |
void *visit(array_initial_elements_list_c *symbol) { |
|
444 |
generate_c_array_initialization_c *array_initialization = new generate_c_array_initialization_c(&s4o); |
|
445 |
array_initialization->init_array_size(this->current_param_type); |
|
446 |
array_initialization->init_array_values(symbol); |
|
447 |
delete array_initialization; |
|
448 |
return NULL; |
|
449 |
} |
|
450 |
||
70 | 451 |
/***************************************/ |
452 |
/* B.3 - Language ST (Structured Text) */ |
|
453 |
/***************************************/ |
|
454 |
/***********************/ |
|
455 |
/* B 3.1 - Expressions */ |
|
456 |
/***********************/ |
|
457 |
void *visit(or_expression_c *symbol) { |
|
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
458 |
if (get_datatype_info_c::is_BOOL_compatible(symbol->datatype)) |
70 | 459 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " || "); |
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
460 |
if (get_datatype_info_c::is_ANY_nBIT_compatible(symbol->datatype)) |
70 | 461 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " | "); |
462 |
ERROR; |
|
463 |
return NULL; |
|
464 |
} |
|
465 |
||
466 |
void *visit(xor_expression_c *symbol) { |
|
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
467 |
if (get_datatype_info_c::is_BOOL_compatible(symbol->datatype)) { |
70 | 468 |
s4o.print("("); |
469 |
symbol->l_exp->accept(*this); |
|
470 |
s4o.print(" && !"); |
|
471 |
symbol->r_exp->accept(*this); |
|
472 |
s4o.print(") || (!"); |
|
473 |
symbol->l_exp->accept(*this); |
|
474 |
s4o.print(" && "); |
|
475 |
symbol->r_exp->accept(*this); |
|
476 |
s4o.print(")"); |
|
130 | 477 |
return NULL; |
70 | 478 |
} |
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
479 |
if (get_datatype_info_c::is_ANY_nBIT_compatible(symbol->datatype)) |
70 | 480 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " ^ "); |
481 |
ERROR; |
|
482 |
return NULL; |
|
483 |
} |
|
484 |
||
485 |
void *visit(and_expression_c *symbol) { |
|
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
486 |
if (get_datatype_info_c::is_BOOL_compatible(symbol->datatype)) |
70 | 487 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " && "); |
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
488 |
if (get_datatype_info_c::is_ANY_nBIT_compatible(symbol->datatype)) |
70 | 489 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " & "); |
490 |
ERROR; |
|
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
491 |
return NULL; |
70 | 492 |
} |
493 |
||
494 |
void *visit(equ_expression_c *symbol) { |
|
694
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
495 |
if (get_datatype_info_c::is_TIME_compatible (symbol->l_exp->datatype) || |
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
496 |
get_datatype_info_c::is_ANY_DATE_compatible (symbol->l_exp->datatype) || |
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
497 |
get_datatype_info_c::is_ANY_STRING_compatible(symbol->l_exp->datatype)) |
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
498 |
return print_compare_function("EQ_", symbol->l_exp->datatype, symbol->l_exp, symbol->r_exp); |
70 | 499 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " == "); |
500 |
} |
|
501 |
||
502 |
void *visit(notequ_expression_c *symbol) { |
|
694
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
503 |
if (get_datatype_info_c::is_TIME_compatible (symbol->l_exp->datatype) || |
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
504 |
get_datatype_info_c::is_ANY_DATE_compatible (symbol->l_exp->datatype) || |
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
505 |
get_datatype_info_c::is_ANY_STRING_compatible(symbol->l_exp->datatype)) |
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
506 |
return print_compare_function("NE_", symbol->l_exp->datatype, symbol->l_exp, symbol->r_exp); |
70 | 507 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " != "); |
508 |
} |
|
509 |
||
510 |
void *visit(lt_expression_c *symbol) { |
|
694
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
511 |
if (get_datatype_info_c::is_TIME_compatible (symbol->l_exp->datatype) || |
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
512 |
get_datatype_info_c::is_ANY_DATE_compatible (symbol->l_exp->datatype) || |
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
513 |
get_datatype_info_c::is_ANY_STRING_compatible(symbol->l_exp->datatype)) |
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
514 |
return print_compare_function("LT_", symbol->l_exp->datatype, symbol->l_exp, symbol->r_exp); |
653
ea78924a1f60
Deleting datatype checks no longer needed (with a view of making search_expression_type_c redundant).
Mario de Sousa <msousa@fe.up.pt>
parents:
594
diff
changeset
|
515 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " < "); |
70 | 516 |
} |
517 |
||
518 |
void *visit(gt_expression_c *symbol) { |
|
694
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
519 |
if (get_datatype_info_c::is_TIME_compatible (symbol->l_exp->datatype) || |
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
520 |
get_datatype_info_c::is_ANY_DATE_compatible (symbol->l_exp->datatype) || |
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
521 |
get_datatype_info_c::is_ANY_STRING_compatible(symbol->l_exp->datatype)) |
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
522 |
return print_compare_function("GT_", symbol->l_exp->datatype, symbol->l_exp, symbol->r_exp); |
653
ea78924a1f60
Deleting datatype checks no longer needed (with a view of making search_expression_type_c redundant).
Mario de Sousa <msousa@fe.up.pt>
parents:
594
diff
changeset
|
523 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " > "); |
70 | 524 |
} |
525 |
||
526 |
void *visit(le_expression_c *symbol) { |
|
694
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
527 |
if (get_datatype_info_c::is_TIME_compatible (symbol->l_exp->datatype) || |
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
528 |
get_datatype_info_c::is_ANY_DATE_compatible (symbol->l_exp->datatype) || |
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
529 |
get_datatype_info_c::is_ANY_STRING_compatible(symbol->l_exp->datatype)) |
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
530 |
return print_compare_function("LE_", symbol->l_exp->datatype, symbol->l_exp, symbol->r_exp); |
653
ea78924a1f60
Deleting datatype checks no longer needed (with a view of making search_expression_type_c redundant).
Mario de Sousa <msousa@fe.up.pt>
parents:
594
diff
changeset
|
531 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " <= "); |
70 | 532 |
} |
533 |
||
534 |
void *visit(ge_expression_c *symbol) { |
|
694
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
535 |
if (get_datatype_info_c::is_TIME_compatible (symbol->l_exp->datatype) || |
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
536 |
get_datatype_info_c::is_ANY_DATE_compatible (symbol->l_exp->datatype) || |
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
537 |
get_datatype_info_c::is_ANY_STRING_compatible(symbol->l_exp->datatype)) |
a010763dd4cb
Fix stage4 for compare expressions.
Manuele Conti <conti.ma@alice.it>
parents:
693
diff
changeset
|
538 |
return print_compare_function("GE_", symbol->l_exp->datatype, symbol->l_exp, symbol->r_exp); |
653
ea78924a1f60
Deleting datatype checks no longer needed (with a view of making search_expression_type_c redundant).
Mario de Sousa <msousa@fe.up.pt>
parents:
594
diff
changeset
|
539 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " >= "); |
70 | 540 |
} |
541 |
||
542 |
void *visit(add_expression_c *symbol) { |
|
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
543 |
/* |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
544 |
symbol_c *left_type = symbol->l_exp->datatype; |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
545 |
symbol_c *right_type = symbol->r_exp->datatype; |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
546 |
if ((typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
547 |
(typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
548 |
(typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c))) |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
549 |
return print_binary_function("__time_add", symbol->l_exp, symbol->r_exp); |
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
550 |
*/ |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
551 |
if (get_datatype_info_c::is_TIME_compatible (symbol->datatype) || |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
552 |
get_datatype_info_c::is_ANY_DATE_compatible (symbol->datatype)) |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
553 |
return print_binary_function("__time_add", symbol->l_exp, symbol->r_exp); |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
554 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " + "); |
70 | 555 |
} |
556 |
||
557 |
void *visit(sub_expression_c *symbol) { |
|
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
558 |
/* |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
559 |
symbol_c *left_type = symbol->l_exp->datatype; |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
560 |
symbol_c *right_type = symbol->r_exp->datatype; |
70 | 561 |
if ((typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
562 |
(typeid(*left_type) == typeid(date_type_name_c) && typeid(*right_type) == typeid(date_type_name_c)) || |
|
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
563 |
(typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
564 |
(typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(tod_type_name_c)) || |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
565 |
(typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) || |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
566 |
(typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(dt_type_name_c))) |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
567 |
return print_binary_function("__time_sub", symbol->l_exp, symbol->r_exp); |
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
568 |
*/ |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
569 |
if (get_datatype_info_c::is_TIME_compatible (symbol->datatype) || |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
570 |
get_datatype_info_c::is_ANY_DATE_compatible (symbol->datatype)) |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
571 |
return print_binary_function("__time_sub", symbol->l_exp, symbol->r_exp); |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
572 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " - "); |
70 | 573 |
} |
574 |
||
575 |
void *visit(mul_expression_c *symbol) { |
|
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
576 |
/* |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
577 |
symbol_c *left_type = symbol->l_exp->datatype; |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
578 |
symbol_c *right_type = symbol->r_exp->datatype; |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
579 |
if ((typeid(*left_type) == typeid(time_type_name_c) && get_datatype_info_c::is_ANY_INT_compatible (right_type)) || |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
580 |
(typeid(*left_type) == typeid(time_type_name_c) && get_datatype_info_c::is_ANY_REAL_compatible(right_type))) |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
581 |
return print_binary_function("__time_mul", symbol->l_exp, symbol->r_exp); |
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
582 |
*/ |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
583 |
if (get_datatype_info_c::is_TIME_compatible (symbol->datatype)) |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
584 |
return print_binary_function("__time_mul", symbol->l_exp, symbol->r_exp); |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
585 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " * "); |
70 | 586 |
} |
587 |
||
588 |
void *visit(div_expression_c *symbol) { |
|
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
589 |
/* |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
590 |
symbol_c *left_type = symbol->l_exp->datatype; |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
591 |
symbol_c *right_type = symbol->r_exp->datatype; |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
592 |
if ((typeid(*left_type) == typeid(time_type_name_c) && get_datatype_info_c::is_ANY_INT_compatible (right_type)) || |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
593 |
(typeid(*left_type) == typeid(time_type_name_c) && get_datatype_info_c::is_ANY_REAL_compatible(right_type))) |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
594 |
return print_binary_function("__time_div", symbol->l_exp, symbol->r_exp); |
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
595 |
*/ |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
596 |
if (get_datatype_info_c::is_TIME_compatible (symbol->datatype)) |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
597 |
return print_binary_function("__time_div", symbol->l_exp, symbol->r_exp); |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
598 |
return print_binary_expression(symbol->l_exp, symbol->r_exp, " / "); |
70 | 599 |
} |
600 |
||
601 |
void *visit(mod_expression_c *symbol) { |
|
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
602 |
s4o.print("(("); |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
603 |
symbol->r_exp->accept(*this); |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
604 |
s4o.print(" == 0)?0:"); |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
605 |
print_binary_expression(symbol->l_exp, symbol->r_exp, " % "); |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
606 |
s4o.print(")"); |
70 | 607 |
return NULL; |
608 |
} |
|
609 |
||
257 | 610 |
void *visit(power_expression_c *symbol) { |
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
611 |
s4o.print("EXPT__LREAL__LREAL__LREAL((BOOL)__BOOL_LITERAL(TRUE),\n"); |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
612 |
s4o.indent_right(); |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
613 |
s4o.print(s4o.indent_spaces + "NULL,\n"); |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
614 |
s4o.print(s4o.indent_spaces + "(LREAL)("); |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
615 |
symbol->l_exp->accept(*this); |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
616 |
s4o.print("),\n"); |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
617 |
s4o.print(s4o.indent_spaces + "(LREAL)("); |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
618 |
symbol->r_exp->accept(*this); |
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
619 |
s4o.print("))"); |
358
a2c4af8f0c18
Add support for '**' (power) operator in ST expressions
Mario de Sousa <msousa@fe.up.pt>
parents:
355
diff
changeset
|
620 |
return NULL; |
257 | 621 |
} |
622 |
||
123 | 623 |
void *visit(neg_expression_c *symbol) { |
257 | 624 |
return print_unary_expression(symbol->exp, " -"); |
123 | 625 |
} |
70 | 626 |
|
627 |
void *visit(not_expression_c *symbol) { |
|
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
628 |
return print_unary_expression(symbol->exp, get_datatype_info_c::is_BOOL_compatible(symbol->datatype)?"!":"~"); |
70 | 629 |
} |
630 |
||
631 |
void *visit(function_invocation_c *symbol) { |
|
149 | 632 |
symbol_c* function_name = NULL; |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
633 |
DECLARE_PARAM_LIST() |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
634 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
635 |
symbol_c *parameter_assignment_list = NULL; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
636 |
if (NULL != symbol-> formal_param_list) parameter_assignment_list = symbol-> formal_param_list; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
637 |
if (NULL != symbol->nonformal_param_list) parameter_assignment_list = symbol->nonformal_param_list; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
638 |
if (NULL == parameter_assignment_list) ERROR; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
639 |
|
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
640 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
641 |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
642 |
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
|
643 |
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
|
644 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
645 |
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
|
646 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
647 |
/* 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
|
648 |
* 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
|
649 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
650 |
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
|
651 |
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
|
652 |
/* 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
|
653 |
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
|
654 |
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
|
655 |
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
|
656 |
/* 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
|
657 |
* 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
|
658 |
* 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
|
659 |
* |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
660 |
* 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
|
661 |
* 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
|
662 |
* 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
|
663 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
664 |
/* 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
|
665 |
* 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
|
666 |
* 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
|
667 |
* 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
|
668 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
669 |
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
|
670 |
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
|
671 |
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
|
672 |
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
|
673 |
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
|
674 |
uint_type_name_c *param_type = new uint_type_name_c(); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
675 |
identifier_c *param_name = new identifier_c(""); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
676 |
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
|
677 |
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
|
678 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
679 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
680 |
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
|
681 |
/* 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
|
682 |
* 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
|
683 |
* 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
|
684 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
685 |
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
|
686 |
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
|
687 |
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
|
688 |
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
|
689 |
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
|
690 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
691 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
692 |
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
|
693 |
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
|
694 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
695 |
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
|
696 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
697 |
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
|
698 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
699 |
/* 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
|
700 |
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
|
701 |
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
|
702 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
703 |
/* 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
|
704 |
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
|
705 |
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
|
706 |
} |
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 |
/* 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
|
709 |
* 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
|
710 |
* have reached the end, and should simply jump out of the for loop. |
70 | 711 |
*/ |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
712 |
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
|
713 |
break; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
714 |
} |
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 |
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
|
717 |
/* 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
|
718 |
/* 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
|
719 |
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
|
720 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
721 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
722 |
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
|
723 |
} /* for(...) */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
724 |
// symbol->parameter_assignment->accept(*this); |
149 | 725 |
|
233
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
726 |
if (function_call_param_iterator.next_nf() != NULL) ERROR; |
3d23a68183d3
Bug on standard functions called with literals fixed
laurent
parents:
231
diff
changeset
|
727 |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
728 |
bool has_output_params = false; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
729 |
|
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
730 |
if (!this->is_variable_prefix_null()) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
731 |
PARAM_LIST_ITERATOR() { |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
732 |
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
|
733 |
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
|
734 |
PARAM_VALUE != NULL) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
735 |
has_output_params = true; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
736 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
737 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
738 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
739 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
740 |
/* Check whether we are calling an overloaded function! */ |
721
5dc33058e041
Fix counting bug in dsymbtable_c
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
741 |
/* (fdecl_mutiplicity > 1) => calling overloaded function */ |
5dc33058e041
Fix counting bug in dsymbtable_c
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
742 |
int fdecl_mutiplicity = function_symtable.count(symbol->function_name); |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
743 |
if (fdecl_mutiplicity == 0) ERROR; |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
744 |
|
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
745 |
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
|
746 |
fcall_number++; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
747 |
s4o.print("__"); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
748 |
fbname->accept(*this); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
749 |
s4o.print("_"); |
149 | 750 |
function_name->accept(*this); |
721
5dc33058e041
Fix counting bug in dsymbtable_c
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
751 |
if (fdecl_mutiplicity > 1) { |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
752 |
/* function being called is overloaded! */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
753 |
s4o.print("__"); |
406
6381589697ff
Fix bug with overloaded function due to literal input values
laurent
parents:
405
diff
changeset
|
754 |
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
|
755 |
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
|
756 |
} |
594
c8092e909886
Clean up code (remove parsing of integers in stage 4).
Mario de Sousa <msousa@fe.up.pt>
parents:
531
diff
changeset
|
757 |
s4o.print(fcall_number); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
758 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
759 |
else { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
760 |
function_name->accept(*this); |
721
5dc33058e041
Fix counting bug in dsymbtable_c
Mario de Sousa <msousa@fe.up.pt>
parents:
718
diff
changeset
|
761 |
if (fdecl_mutiplicity > 1) { |
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
762 |
/* function being called is overloaded! */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
763 |
s4o.print("__"); |
406
6381589697ff
Fix bug with overloaded function due to literal input values
laurent
parents:
405
diff
changeset
|
764 |
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
|
765 |
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
|
766 |
} |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
767 |
} |
149 | 768 |
s4o.print("("); |
769 |
s4o.indent_right(); |
|
770 |
||
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
771 |
int nb_param = 0; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
772 |
PARAM_LIST_ITERATOR() { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
773 |
symbol_c *param_value = PARAM_VALUE; |
235 | 774 |
current_param_type = PARAM_TYPE; |
149 | 775 |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
776 |
switch (PARAM_DIRECTION) { |
149 | 777 |
case function_param_iterator_c::direction_in: |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
778 |
if (nb_param > 0) |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
779 |
s4o.print(",\n"+s4o.indent_spaces); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
780 |
if (param_value == NULL) { |
149 | 781 |
/* If not, get the default value of this variable's type */ |
762 | 782 |
param_value = type_initial_value_c::get(current_param_type); |
149 | 783 |
} |
784 |
if (param_value == NULL) ERROR; |
|
216
136d6ae70745
Bug with using non explicit literals as standard library functions input parameters fixed
laurent
parents:
208
diff
changeset
|
785 |
s4o.print("("); |
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
786 |
if (get_datatype_info_c::is_ANY_INT_literal(current_param_type)) |
693
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
668
diff
changeset
|
787 |
get_datatype_info_c::lint_type_name.accept(*this); |
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
788 |
else if (get_datatype_info_c::is_ANY_REAL_literal(current_param_type)) |
693
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
668
diff
changeset
|
789 |
get_datatype_info_c::lreal_type_name.accept(*this); |
216
136d6ae70745
Bug with using non explicit literals as standard library functions input parameters fixed
laurent
parents:
208
diff
changeset
|
790 |
else |
235 | 791 |
current_param_type->accept(*this); |
216
136d6ae70745
Bug with using non explicit literals as standard library functions input parameters fixed
laurent
parents:
208
diff
changeset
|
792 |
s4o.print(")"); |
235 | 793 |
print_check_function(current_param_type, param_value); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
794 |
nb_param++; |
149 | 795 |
break; |
796 |
case function_param_iterator_c::direction_out: |
|
797 |
case function_param_iterator_c::direction_inout: |
|
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
798 |
if (!has_output_params) { |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
799 |
if (nb_param > 0) |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
800 |
s4o.print(",\n"+s4o.indent_spaces); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
801 |
if (param_value == NULL) |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
802 |
s4o.print("NULL"); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
803 |
else { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
804 |
wanted_variablegeneration = fparam_output_vg; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
805 |
param_value->accept(*this); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
806 |
wanted_variablegeneration = expression_vg; |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
807 |
} |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
808 |
nb_param++; |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
809 |
} |
149 | 810 |
break; |
811 |
case function_param_iterator_c::direction_extref: |
|
812 |
/* TODO! */ |
|
813 |
ERROR; |
|
814 |
break; |
|
815 |
} /* switch */ |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
816 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
817 |
if (has_output_params) { |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
818 |
if (nb_param > 0) |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
819 |
s4o.print(",\n"+s4o.indent_spaces); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
820 |
s4o.print(FB_FUNCTION_PARAM); |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
821 |
} |
149 | 822 |
s4o.print(")"); |
823 |
s4o.indent_left(); |
|
70 | 824 |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
825 |
CLEAR_PARAM_LIST() |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
826 |
|
70 | 827 |
return NULL; |
828 |
} |
|
829 |
||
830 |
/********************/ |
|
831 |
/* B 3.2 Statements */ |
|
832 |
/********************/ |
|
833 |
void *visit(statement_list_c *symbol) { |
|
834 |
return print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); |
|
835 |
} |
|
836 |
||
837 |
/*********************************/ |
|
838 |
/* B 3.2.1 Assignment Statements */ |
|
839 |
/*********************************/ |
|
840 |
void *visit(assignment_statement_c *symbol) { |
|
321
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
309
diff
changeset
|
841 |
symbol_c *left_type = search_varfb_instance_type->get_type_id(symbol->l_exp); |
98 | 842 |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
843 |
if (this->is_variable_prefix_null()) { |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
844 |
symbol->l_exp->accept(*this); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
845 |
s4o.print(" = "); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
846 |
print_check_function(left_type, symbol->r_exp); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
847 |
} |
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
848 |
else { |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
849 |
print_setter(symbol->l_exp, left_type, symbol->r_exp); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
850 |
} |
70 | 851 |
return NULL; |
852 |
} |
|
853 |
||
854 |
/*****************************************/ |
|
855 |
/* B 3.2.2 Subprogram Control Statements */ |
|
856 |
/*****************************************/ |
|
857 |
||
283
214d3fdee596
fixing C code generation of return_statement_c and exit_statement_c
Mario de Sousa <msousa@fe.up.pt>
parents:
282
diff
changeset
|
858 |
void *visit(return_statement_c *symbol) { |
214d3fdee596
fixing C code generation of return_statement_c and exit_statement_c
Mario de Sousa <msousa@fe.up.pt>
parents:
282
diff
changeset
|
859 |
s4o.print("goto "); s4o.print(END_LABEL); |
214d3fdee596
fixing C code generation of return_statement_c and exit_statement_c
Mario de Sousa <msousa@fe.up.pt>
parents:
282
diff
changeset
|
860 |
return NULL; |
214d3fdee596
fixing C code generation of return_statement_c and exit_statement_c
Mario de Sousa <msousa@fe.up.pt>
parents:
282
diff
changeset
|
861 |
} |
214d3fdee596
fixing C code generation of return_statement_c and exit_statement_c
Mario de Sousa <msousa@fe.up.pt>
parents:
282
diff
changeset
|
862 |
|
214d3fdee596
fixing C code generation of return_statement_c and exit_statement_c
Mario de Sousa <msousa@fe.up.pt>
parents:
282
diff
changeset
|
863 |
|
70 | 864 |
/* fb_name '(' [param_assignment_list] ')' */ |
855
a3109442e166
Start using the called_fb_declaration annotation when generating C code from FB calls in ST.
mjsousa
parents:
854
diff
changeset
|
865 |
/* formal_param_list -> may be NULL ! */ |
a3109442e166
Start using the called_fb_declaration annotation when generating C code from FB calls in ST.
mjsousa
parents:
854
diff
changeset
|
866 |
/* nonformal_param_list -> may be NULL ! */ |
a3109442e166
Start using the called_fb_declaration annotation when generating C code from FB calls in ST.
mjsousa
parents:
854
diff
changeset
|
867 |
/* NOTE: The parameter 'called_fb_declaration'is used to pass data between stage 3 and stage4 (although currently it is not used in stage 4 */ |
a3109442e166
Start using the called_fb_declaration annotation when generating C code from FB calls in ST.
mjsousa
parents:
854
diff
changeset
|
868 |
// SYM_REF3(fb_invocation_c, fb_name, formal_param_list, nonformal_param_list, symbol_c *called_fb_declaration;) |
70 | 869 |
void *visit(fb_invocation_c *symbol) { |
870 |
TRACE("fb_invocation_c"); |
|
855
a3109442e166
Start using the called_fb_declaration annotation when generating C code from FB calls in ST.
mjsousa
parents:
854
diff
changeset
|
871 |
|
a3109442e166
Start using the called_fb_declaration annotation when generating C code from FB calls in ST.
mjsousa
parents:
854
diff
changeset
|
872 |
/* find the declaration of the function block type being called... */ |
a3109442e166
Start using the called_fb_declaration annotation when generating C code from FB calls in ST.
mjsousa
parents:
854
diff
changeset
|
873 |
symbol_c *fb_decl = symbol->called_fb_declaration; |
a3109442e166
Start using the called_fb_declaration annotation when generating C code from FB calls in ST.
mjsousa
parents:
854
diff
changeset
|
874 |
if (fb_decl == NULL) ERROR; |
a3109442e166
Start using the called_fb_declaration annotation when generating C code from FB calls in ST.
mjsousa
parents:
854
diff
changeset
|
875 |
/* figure out the name of the function block type of the function block being called... */ |
a3109442e166
Start using the called_fb_declaration annotation when generating C code from FB calls in ST.
mjsousa
parents:
854
diff
changeset
|
876 |
symbol_c *function_block_type_name = get_datatype_info_c::get_id(fb_decl); |
a3109442e166
Start using the called_fb_declaration annotation when generating C code from FB calls in ST.
mjsousa
parents:
854
diff
changeset
|
877 |
if (NULL == function_block_type_name) ERROR; |
a3109442e166
Start using the called_fb_declaration annotation when generating C code from FB calls in ST.
mjsousa
parents:
854
diff
changeset
|
878 |
|
70 | 879 |
/* loop through each function block parameter, find the value we should pass |
880 |
* to it, and then output the c equivalent... |
|
881 |
*/ |
|
882 |
function_param_iterator_c fp_iterator(fb_decl); |
|
883 |
identifier_c *param_name; |
|
884 |
function_call_param_iterator_c function_call_param_iterator(symbol); |
|
885 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
886 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
160 | 887 |
|
162
60a124678842
Fixed typo in EN/ENO parameters handling for std library functions
etisserant
parents:
160
diff
changeset
|
888 |
/*fprintf(stderr, "param : %s\n", param_name->value);*/ |
160 | 889 |
|
70 | 890 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
891 |
symbol_c *param_value = function_call_param_iterator.search_f(param_name); |
70 | 892 |
|
893 |
/* Get the value from a foo(<param_value>) style call */ |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
894 |
/* When using the informal invocation style, user can not pass values to EN or ENO parameters if these |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
895 |
* were implicitly defined! |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
896 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
897 |
if ((param_value == NULL) && !fp_iterator.is_en_eno_param_implicit()) |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
898 |
param_value = function_call_param_iterator.next_nf(); |
70 | 899 |
|
98 | 900 |
symbol_c *param_type = fp_iterator.param_type(); |
901 |
if (param_type == NULL) ERROR; |
|
902 |
||
70 | 903 |
/* now output the value assignment */ |
904 |
if (param_value != NULL) |
|
905 |
if ((param_direction == function_param_iterator_c::direction_in) || |
|
906 |
(param_direction == function_param_iterator_c::direction_inout)) { |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
907 |
if (this->is_variable_prefix_null()) { |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
908 |
symbol->fb_name->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
909 |
s4o.print("."); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
910 |
param_name->accept(*this); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
911 |
s4o.print(" = "); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
912 |
print_check_function(param_type, param_value); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
913 |
} |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
914 |
else { |
228
43831b683764
Adding support for setter and getter on complex datatype in IL
berem
parents:
226
diff
changeset
|
915 |
print_setter(param_name, param_type, param_value, symbol->fb_name); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
916 |
} |
70 | 917 |
s4o.print(";\n" + s4o.indent_spaces); |
918 |
} |
|
919 |
} /* for(...) */ |
|
920 |
||
921 |
/* now call the function... */ |
|
922 |
function_block_type_name->accept(*this); |
|
923 |
s4o.print(FB_FUNCTION_SUFFIX); |
|
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
924 |
s4o.print("("); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
925 |
if (search_var_instance_decl->get_vartype(symbol->fb_name) != 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
|
926 |
s4o.print("&"); |
70 | 927 |
print_variable_prefix(); |
928 |
symbol->fb_name->accept(*this); |
|
929 |
s4o.print(")"); |
|
930 |
||
931 |
/* loop through each function parameter, find the variable to which |
|
932 |
* we should atribute the value of all output or inoutput parameters. |
|
933 |
*/ |
|
934 |
fp_iterator.reset(); |
|
935 |
function_call_param_iterator.reset(); |
|
936 |
for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
|
937 |
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
|
938 |
||
939 |
/* Get the value from a foo(<param_name> = <param_value>) style call */ |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
940 |
symbol_c *param_value = function_call_param_iterator.search_f(param_name); |
70 | 941 |
|
942 |
/* Get the value from a foo(<param_value>) style call */ |
|
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
943 |
/* When using the informal invocation style, user can not pass values to EN or ENO parameters if these |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
944 |
* were implicitly defined! |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
945 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
336
diff
changeset
|
946 |
if ((param_value == NULL) && !fp_iterator.is_en_eno_param_implicit()) |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
169
diff
changeset
|
947 |
param_value = function_call_param_iterator.next_nf(); |
70 | 948 |
|
949 |
/* now output the value assignment */ |
|
950 |
if (param_value != NULL) |
|
951 |
if ((param_direction == function_param_iterator_c::direction_out) || |
|
952 |
(param_direction == function_param_iterator_c::direction_inout)) { |
|
321
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
309
diff
changeset
|
953 |
symbol_c *param_type = search_varfb_instance_type->get_type_id(param_value); |
240 | 954 |
s4o.print(";\n" + s4o.indent_spaces); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
955 |
if (this->is_variable_prefix_null()) { |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
956 |
param_value->accept(*this); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
957 |
s4o.print(" = "); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
958 |
print_check_function(param_type, param_name, symbol->fb_name); |
98 | 959 |
} |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
960 |
else { |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
221
diff
changeset
|
961 |
print_setter(param_value, param_type, param_name, NULL, symbol->fb_name); |
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
216
diff
changeset
|
962 |
} |
70 | 963 |
} |
964 |
} /* for(...) */ |
|
965 |
||
966 |
return NULL; |
|
967 |
} |
|
968 |
||
969 |
||
970 |
||
971 |
||
972 |
/* helper symbol for fb_invocation */ |
|
973 |
/* param_assignment_list ',' param_assignment */ |
|
974 |
void *visit(param_assignment_list_c *symbol) { |
|
975 |
TRACE("param_assignment_list_c"); |
|
976 |
/* this should never be called... */ |
|
977 |
ERROR; |
|
978 |
return NULL; |
|
979 |
// return print_list(symbol, "", ", "); |
|
980 |
} |
|
981 |
||
982 |
||
983 |
void *visit(input_variable_param_assignment_c *symbol) { |
|
984 |
TRACE("input_variable_param_assignment_c"); |
|
985 |
/* this should never be called... */ |
|
986 |
ERROR; |
|
987 |
return NULL; |
|
988 |
/* |
|
989 |
symbol->variable_name->accept(*this); |
|
990 |
s4o.print(" = "); |
|
991 |
symbol->expression->accept(*this); |
|
992 |
return NULL; |
|
993 |
*/ |
|
994 |
} |
|
995 |
||
996 |
void *visit(output_variable_param_assignment_c *symbol) { |
|
997 |
TRACE("output_variable_param_assignment_c"); |
|
998 |
/* this should never be called... */ |
|
999 |
ERROR; |
|
1000 |
return NULL; |
|
1001 |
/* |
|
1002 |
s4o.print(s4o.indent_spaces); |
|
1003 |
if (symbol->not_param != NULL) |
|
1004 |
symbol->not_param->accept(*this); |
|
1005 |
symbol->variable_name->accept(*this); |
|
1006 |
s4o.print(" => "); |
|
1007 |
symbol->variable->accept(*this); |
|
1008 |
return NULL; |
|
1009 |
*/ |
|
1010 |
} |
|
1011 |
||
1012 |
// TODO: the NOT symbol in function (block) calls... |
|
1013 |
void *visit(not_paramassign_c *symbol) { |
|
1014 |
TRACE("not_paramassign_c"); |
|
1015 |
/* this should never be called... */ |
|
1016 |
ERROR; |
|
1017 |
return NULL; |
|
1018 |
/* |
|
1019 |
s4o.print("NOT "); |
|
1020 |
return NULL; |
|
1021 |
*/ |
|
1022 |
} |
|
1023 |
||
1024 |
||
1025 |
/********************************/ |
|
1026 |
/* B 3.2.3 Selection Statements */ |
|
1027 |
/********************************/ |
|
1028 |
void *visit(if_statement_c *symbol) { |
|
1029 |
s4o.print("if ("); |
|
1030 |
symbol->expression->accept(*this); |
|
1031 |
s4o.print(") {\n"); |
|
1032 |
s4o.indent_right(); |
|
1033 |
symbol->statement_list->accept(*this); |
|
1034 |
s4o.indent_left(); |
|
1035 |
symbol->elseif_statement_list->accept(*this); |
|
1036 |
||
1037 |
if (symbol->else_statement_list != NULL) { |
|
1038 |
s4o.print(s4o.indent_spaces); s4o.print("} else {\n"); |
|
1039 |
s4o.indent_right(); |
|
1040 |
symbol->else_statement_list->accept(*this); |
|
1041 |
s4o.indent_left(); |
|
1042 |
} |
|
1043 |
s4o.print(s4o.indent_spaces); s4o.print("}"); |
|
1044 |
return NULL; |
|
1045 |
} |
|
1046 |
||
1047 |
/* helper symbol for if_statement */ |
|
1048 |
void *visit(elseif_statement_list_c *symbol) {return print_list(symbol);} |
|
1049 |
||
1050 |
/* helper symbol for elseif_statement_list */ |
|
1051 |
void *visit(elseif_statement_c *symbol) { |
|
1052 |
s4o.print(s4o.indent_spaces); s4o.print("} else if ("); |
|
1053 |
symbol->expression->accept(*this); |
|
1054 |
s4o.print(") {\n"); |
|
1055 |
s4o.indent_right(); |
|
1056 |
symbol->statement_list->accept(*this); |
|
1057 |
s4o.indent_left(); |
|
1058 |
return NULL; |
|
1059 |
} |
|
1060 |
||
1061 |
void *visit(case_statement_c *symbol) { |
|
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
1062 |
symbol_c *expression_type = symbol->expression->datatype; |
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1063 |
s4o.print("{\n"); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1064 |
s4o.indent_right(); |
376 | 1065 |
s4o.print(s4o.indent_spaces); |
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
1066 |
if (get_datatype_info_c::is_ANY_INT_literal(expression_type)) |
693
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
668
diff
changeset
|
1067 |
get_datatype_info_c::lint_type_name.accept(*this); |
668
90b6eb7f1775
Deprecating use of search_expression_type_c, so it may later be deleted!
Mario de Sousa <msousa@fe.up.pt>
parents:
667
diff
changeset
|
1068 |
else if (get_datatype_info_c::is_ANY_REAL_literal(expression_type)) |
693
51a2fa6441b9
Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents:
668
diff
changeset
|
1069 |
get_datatype_info_c::lreal_type_name.accept(*this); |
376 | 1070 |
else |
1071 |
expression_type->accept(*this); |
|
1072 |
s4o.print(" __case_expression = "); |
|
70 | 1073 |
symbol->expression->accept(*this); |
376 | 1074 |
s4o.print(";\n" + s4o.indent_spaces + "switch (__case_expression) {\n"); |
70 | 1075 |
s4o.indent_right(); |
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1076 |
wanted_casegeneration = single_cg; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1077 |
symbol->case_element_list->accept(*this); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1078 |
wanted_casegeneration = subrange_cg; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1079 |
s4o.print(s4o.indent_spaces + "default:\n"); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1080 |
s4o.indent_right(); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1081 |
first_subrange_case_list = true; |
70 | 1082 |
symbol->case_element_list->accept(*this); |
1083 |
if (symbol->statement_list != NULL) { |
|
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1084 |
if (!first_subrange_case_list) { |
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1085 |
s4o.print(s4o.indent_spaces + "else {\n"); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1086 |
s4o.indent_right(); |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1087 |
} |
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1088 |
symbol->statement_list->accept(*this); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1089 |
if (!first_subrange_case_list) { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1090 |
s4o.indent_left(); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1091 |
s4o.print(s4o.indent_spaces + "}\n"); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1092 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1093 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1094 |
s4o.print(s4o.indent_spaces + "break;\n"); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1095 |
s4o.indent_left(); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1096 |
wanted_casegeneration = none_cg; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1097 |
s4o.indent_left(); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1098 |
s4o.print(s4o.indent_spaces + "}\n"); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1099 |
s4o.indent_left(); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1100 |
s4o.print(s4o.indent_spaces + "}"); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1101 |
return NULL; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1102 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1103 |
|
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1104 |
/* helper symbol for case_statement */ |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1105 |
void *visit(case_element_list_c *symbol) {return print_list(symbol);} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1106 |
|
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1107 |
void *visit(case_element_c *symbol) { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1108 |
case_element_iterator_c *case_element_iterator; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1109 |
symbol_c* element = NULL; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1110 |
bool first_element = true; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1111 |
|
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1112 |
switch (wanted_casegeneration) { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1113 |
case single_cg: |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1114 |
case_element_iterator = new case_element_iterator_c(symbol->case_list, case_element_iterator_c::element_single); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1115 |
for (element = case_element_iterator->next(); element != NULL; element = case_element_iterator->next()) { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1116 |
if (first_element) first_element = false; |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1117 |
s4o.print(s4o.indent_spaces + "case "); |
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1118 |
element->accept(*this); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1119 |
s4o.print(":\n"); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1120 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1121 |
delete case_element_iterator; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1122 |
break; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1123 |
|
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1124 |
case subrange_cg: |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1125 |
case_element_iterator = new case_element_iterator_c(symbol->case_list, case_element_iterator_c::element_subrange); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1126 |
for (element = case_element_iterator->next(); element != NULL; element = case_element_iterator->next()) { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1127 |
if (first_element) { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1128 |
if (first_subrange_case_list) { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1129 |
s4o.print(s4o.indent_spaces + "if ("); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1130 |
first_subrange_case_list = false; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1131 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1132 |
else { |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1133 |
s4o.print(s4o.indent_spaces + "else if ("); |
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1134 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1135 |
first_element = false; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1136 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1137 |
else { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1138 |
s4o.print(" && "); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1139 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1140 |
element->accept(*this); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1141 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1142 |
delete case_element_iterator; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1143 |
if (!first_element) { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1144 |
s4o.print(") {\n"); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1145 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1146 |
break; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1147 |
|
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1148 |
default: |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1149 |
break; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1150 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1151 |
|
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1152 |
if (!first_element) { |
70 | 1153 |
s4o.indent_right(); |
1154 |
symbol->statement_list->accept(*this); |
|
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1155 |
switch (wanted_casegeneration) { |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1156 |
case single_cg: |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1157 |
s4o.print(s4o.indent_spaces + "break;\n"); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1158 |
s4o.indent_left(); |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1159 |
break; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1160 |
case subrange_cg: |
706
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1161 |
s4o.indent_left(); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1162 |
s4o.print(s4o.indent_spaces + "}\n"); |
31553c22f318
Adding support for declaring function block instances as global and external variables
Laurent Bessard
parents:
625
diff
changeset
|
1163 |
break; |
347
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1164 |
default: |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1165 |
break; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1166 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1167 |
} |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1168 |
return NULL; |
44ff2a6fcadc
Fix case statement in ST, adding support for enumerated types
laurent
parents:
344
diff
changeset
|
1169 |
} |
70 | 1170 |
|
1171 |
/********************************/ |
|
1172 |
/* B 3.2.4 Iteration Statements */ |
|
1173 |
/********************************/ |
|
1174 |
void *visit(for_statement_c *symbol) { |
|
1175 |
s4o.print("for("); |
|
1176 |
symbol->control_variable->accept(*this); |
|
1177 |
s4o.print(" = "); |
|
1178 |
symbol->beg_expression->accept(*this); |
|
1179 |
s4o.print("; "); |
|
387
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1180 |
if (symbol->by_expression == NULL) { |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1181 |
/* increment by 1 */ |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1182 |
symbol->control_variable->accept(*this); |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1183 |
s4o.print(" <= "); |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1184 |
symbol->end_expression->accept(*this); |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1185 |
s4o.print("; "); |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1186 |
symbol->control_variable->accept(*this); |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1187 |
s4o.print("++"); |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1188 |
} else { |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1189 |
/* increment by user defined value */ |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1190 |
/* The user defined increment value may be negative, in which case |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1191 |
* the expression to determine whether we have reached the end of the loop |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1192 |
* changes from a '<=' to a '>='. |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1193 |
* Since the increment value may change during runtime (remember, it is |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1194 |
* an expression, so may contain variables), choosing which test |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1195 |
* to use has to be done at runtime. |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1196 |
*/ |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1197 |
s4o.print("(("); |
70 | 1198 |
symbol->by_expression->accept(*this); |
387
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1199 |
s4o.print(") > 0)? ("); |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1200 |
symbol->control_variable->accept(*this); |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1201 |
s4o.print(" <= ("); |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1202 |
symbol->end_expression->accept(*this); |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1203 |
s4o.print(")) : ("); |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1204 |
symbol->control_variable->accept(*this); |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1205 |
s4o.print(" >= ("); |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1206 |
symbol->end_expression->accept(*this); |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1207 |
s4o.print(")); "); |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1208 |
symbol->control_variable->accept(*this); |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1209 |
s4o.print(" += ("); |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1210 |
symbol->by_expression->accept(*this); |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1211 |
s4o.print(")"); |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1212 |
} |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1213 |
s4o.print(")"); |
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1214 |
|
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1215 |
s4o.print(" {\n"); |
70 | 1216 |
s4o.indent_right(); |
1217 |
symbol->statement_list->accept(*this); |
|
1218 |
s4o.indent_left(); |
|
1219 |
s4o.print(s4o.indent_spaces); s4o.print("}"); |
|
1220 |
return NULL; |
|
1221 |
} |
|
387
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1222 |
|
70 | 1223 |
void *visit(while_statement_c *symbol) { |
1224 |
s4o.print("while ("); |
|
1225 |
symbol->expression->accept(*this); |
|
1226 |
s4o.print(") {\n"); |
|
1227 |
s4o.indent_right(); |
|
1228 |
symbol->statement_list->accept(*this); |
|
1229 |
s4o.indent_left(); |
|
1230 |
s4o.print(s4o.indent_spaces); s4o.print("}"); |
|
1231 |
return NULL; |
|
1232 |
} |
|
387
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1233 |
|
70 | 1234 |
void *visit(repeat_statement_c *symbol) { |
1235 |
s4o.print("do {\n"); |
|
1236 |
s4o.indent_right(); |
|
1237 |
symbol->statement_list->accept(*this); |
|
1238 |
s4o.indent_left(); |
|
1239 |
s4o.print(s4o.indent_spaces); s4o.print("} while("); |
|
1240 |
symbol->expression->accept(*this); |
|
1241 |
s4o.print(")"); |
|
1242 |
return NULL; |
|
1243 |
} |
|
387
db368e53133c
Fix code generation of FOR loops. Now handles negative values of BY correctly.
Mario de Sousa <msousa@fe.up.pt>
parents:
382
diff
changeset
|
1244 |
|
70 | 1245 |
void *visit(exit_statement_c *symbol) { |
281
686fa44e3832
fixing exit_statement_c: produce 'break' instead of 'exit(0); (Thanks to Manuele)
Mario de Sousa <msousa@fe.up.pt>
parents:
258
diff
changeset
|
1246 |
s4o.print("break"); |
70 | 1247 |
return NULL; |
1248 |
} |
|
1249 |
||
1250 |
||
1251 |
||
1252 |
}; /* generate_c_st_c */ |
|
1253 |
||
1254 |
||
1255 |
||
1256 |
||
1257 |
||
1258 |
||
1259 |
||
1260 |
||
1261 |