author | Mario de Sousa <msousa@fe.up.pt> |
Thu, 16 Feb 2012 12:59:02 +0000 | |
changeset 444 | 92d40d2a7adc |
parent 417 | d48f53715f77 |
child 504 | f8d422b98315 |
permissions | -rwxr-xr-x |
181 | 1 |
/* |
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
diff
changeset
|
2 |
* matiec - a compiler for the programming languages defined in IEC 61131-3 |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
diff
changeset
|
3 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
diff
changeset
|
4 |
* Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt) |
279
c0453b7f99df
Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents:
265
diff
changeset
|
5 |
* Copyright (C) 2007-2011 Laurent Bessard and Edouard Tisserant |
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
diff
changeset
|
6 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
diff
changeset
|
7 |
* This program is free software: you can redistribute it and/or modify |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
diff
changeset
|
8 |
* it under the terms of the GNU General Public License as published by |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
diff
changeset
|
9 |
* the Free Software Foundation, either version 3 of the License, or |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
diff
changeset
|
10 |
* (at your option) any later version. |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
diff
changeset
|
11 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
diff
changeset
|
12 |
* This program is distributed in the hope that it will be useful, |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
diff
changeset
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
diff
changeset
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
diff
changeset
|
15 |
* GNU General Public License for more details. |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
diff
changeset
|
16 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
diff
changeset
|
18 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
diff
changeset
|
19 |
* |
181 | 20 |
* |
21 |
* This code is made available on the understanding that it will not be |
|
22 |
* used in safety-critical situations without a full and competent review. |
|
23 |
*/ |
|
24 |
||
25 |
/* |
|
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
226
diff
changeset
|
26 |
* An IEC 61131-3 compiler. |
181 | 27 |
* |
28 |
* Based on the |
|
29 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
30 |
* |
|
31 |
*/ |
|
32 |
||
33 |
||
34 |
/* Determine the data type of a specific variable instance, including |
|
35 |
* function block instances. |
|
36 |
* A reference to the relevant variable declaration is returned. |
|
37 |
* The variable instance may NOT be a member of a structure of a memeber |
|
38 |
* of a structure of an element of an array of ... |
|
39 |
* |
|
40 |
* example: |
|
41 |
* window.points[1].coordinate.x |
|
42 |
* window.points[1].colour |
|
43 |
* etc... ARE NOT ALLOWED! |
|
44 |
* |
|
45 |
* This class must only be passed the name of the variable that will appear |
|
46 |
* in the variable declaration. In the above examples, this would be |
|
47 |
* 'window' !! |
|
48 |
* |
|
49 |
* |
|
50 |
* If you need to pass a complete name of a variable instance (such as |
|
51 |
* 'window.points[1].coordinate.x') use the search_varfb_instance_type_c instead! |
|
52 |
*/ |
|
53 |
/* Note that current_type_decl that this class returns may reference the |
|
54 |
* name of a type, or the type declaration itself! |
|
55 |
* For an example of the first, consider a variable declared as ... |
|
56 |
* x : AAA; |
|
57 |
* where the AAA type is previously declared as whatever. |
|
58 |
* For an example of the second, consider a variable declared as ... |
|
59 |
* x : array of int [10]; ----> is allowed |
|
60 |
* |
|
61 |
* If it is the first, we will return a reference to the name, if the second |
|
62 |
* we return a reference to the declaration!! |
|
63 |
*/ |
|
64 |
||
65 |
||
66 |
class search_var_instance_decl_c: public search_visitor_c { |
|
67 |
||
68 |
private: |
|
69 |
symbol_c *search_scope; |
|
70 |
symbol_c *search_name; |
|
71 |
symbol_c *current_type_decl; |
|
72 |
||
73 |
/* variable used to store the type of variable currently being processed... */ |
|
74 |
/* Will contain a single value of generate_c_vardecl_c::XXXX_vt */ |
|
75 |
unsigned int current_vartype; |
|
76 |
||
77 |
public: |
|
78 |
search_var_instance_decl_c(symbol_c *search_scope); |
|
79 |
symbol_c *get_decl(symbol_c *variable_instance_name); |
|
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:
279
diff
changeset
|
80 |
|
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:
279
diff
changeset
|
81 |
unsigned int get_vartype(symbol_c *variable_instance_name); |
181 | 82 |
|
83 |
public: |
|
84 |
||
85 |
/* the types of variables that need to be processed... */ |
|
86 |
static const unsigned int none_vt = 0x0000; |
|
87 |
static const unsigned int input_vt = 0x0001; // VAR_INPUT |
|
88 |
static const unsigned int output_vt = 0x0002; // VAR_OUTPUT |
|
89 |
static const unsigned int inoutput_vt = 0x0004; // VAR_IN_OUT |
|
90 |
static const unsigned int private_vt = 0x0008; // VAR |
|
91 |
static const unsigned int temp_vt = 0x0010; // VAR_TEMP |
|
92 |
static const unsigned int external_vt = 0x0020; // VAR_EXTERNAL |
|
93 |
static const unsigned int global_vt = 0x0040; // VAR_GLOBAL |
|
94 |
static const unsigned int located_vt = 0x0080; // VAR <var_name> AT <location> |
|
95 |
||
96 |
private: |
|
97 |
/***************************/ |
|
98 |
/* B 0 - Programming Model */ |
|
99 |
/***************************/ |
|
100 |
void *visit(library_c *symbol); |
|
101 |
||
102 |
/******************************************/ |
|
103 |
/* B 1.4.3 - Declaration & Initialisation */ |
|
104 |
/******************************************/ |
|
217
f5dfadf5de54
Adding support for declare, init, get and set macros
laurent
parents:
202
diff
changeset
|
105 |
|
181 | 106 |
/* edge -> The F_EDGE or R_EDGE directive */ |
107 |
// SYM_REF2(edge_declaration_c, edge, var1_list) |
|
108 |
// TODO |
|
109 |
void *visit(input_declarations_c *symbol); |
|
110 |
/* VAR_OUTPUT [RETAIN | NON_RETAIN] var_init_decl_list END_VAR */ |
|
111 |
/* option -> may be NULL ! */ |
|
112 |
void *visit(output_declarations_c *symbol); |
|
113 |
/* VAR_IN_OUT var_declaration_list END_VAR */ |
|
114 |
void *visit(input_output_declarations_c *symbol); |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
115 |
/* ENO : BOOL */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
116 |
void *visit(eno_param_declaration_c *symbol); |
181 | 117 |
/* VAR [CONSTANT] var_init_decl_list END_VAR */ |
118 |
/* option -> may be NULL ! */ |
|
119 |
/* helper symbol for input_declarations */ |
|
120 |
void *visit(var_declarations_c *symbol); |
|
121 |
/* VAR RETAIN var_init_decl_list END_VAR */ |
|
122 |
void *visit(retentive_var_declarations_c *symbol); |
|
123 |
/* VAR [CONSTANT|RETAIN|NON_RETAIN] located_var_decl_list END_VAR */ |
|
124 |
/* option -> may be NULL ! */ |
|
125 |
//SYM_REF2(located_var_declarations_c, option, located_var_decl_list) |
|
126 |
void *visit(located_var_declarations_c *symbol); |
|
127 |
/*| VAR_EXTERNAL [CONSTANT] external_declaration_list END_VAR */ |
|
128 |
/* option -> may be NULL ! */ |
|
129 |
//SYM_REF2(external_var_declarations_c, option, external_declaration_list) |
|
130 |
void *visit(external_var_declarations_c *symbol); |
|
131 |
/*| VAR_GLOBAL [CONSTANT|RETAIN] global_var_decl_list END_VAR */ |
|
132 |
/* option -> may be NULL ! */ |
|
133 |
//SYM_REF2(global_var_declarations_c, option, global_var_decl_list) |
|
134 |
void *visit(global_var_declarations_c *symbol); |
|
135 |
/* var1_list is one of the following... |
|
136 |
* simple_spec_init_c * |
|
137 |
* subrange_spec_init_c * |
|
138 |
* enumerated_spec_init_c * |
|
139 |
*/ |
|
140 |
// SYM_REF2(var1_init_decl_c, var1_list, spec_init) |
|
141 |
void *visit(var1_init_decl_c *symbol); |
|
142 |
/* var1_list ',' variable_name */ |
|
143 |
// SYM_LIST(var1_list_c) |
|
144 |
void *visit(var1_list_c *symbol); |
|
145 |
/* name_list ':' function_block_type_name ASSIGN structure_initialization */ |
|
146 |
/* structure_initialization -> may be NULL ! */ |
|
147 |
void *visit(fb_name_decl_c *symbol); |
|
148 |
/* name_list ',' fb_name */ |
|
149 |
void *visit(fb_name_list_c *symbol); |
|
150 |
/* var1_list ':' array_spec_init */ |
|
151 |
// SYM_REF2(array_var_init_decl_c, var1_list, array_spec_init) |
|
152 |
void *visit(array_var_init_decl_c *symbol); |
|
153 |
/* var1_list ':' initialized_structure */ |
|
154 |
// SYM_REF2(structured_var_init_decl_c, var1_list, initialized_structure) |
|
155 |
void *visit(structured_var_init_decl_c *symbol); |
|
156 |
/* var1_list ':' array_specification */ |
|
157 |
// SYM_REF2(array_var_declaration_c, var1_list, array_specification) |
|
158 |
void *visit(array_var_declaration_c *symbol); |
|
159 |
/* var1_list ':' structure_type_name */ |
|
160 |
// SYM_REF2(structured_var_declaration_c, var1_list, structure_type_name) |
|
161 |
void *visit(structured_var_declaration_c *symbol); |
|
162 |
/* [variable_name] location ':' located_var_spec_init */ |
|
163 |
/* variable_name -> may be NULL ! */ |
|
164 |
// SYM_REF4(located_var_decl_c, variable_name, location, located_var_spec_init, unused) |
|
165 |
// TODO!! |
|
166 |
||
167 |
/* global_var_name ':' (simple_specification|subrange_specification|enumerated_specification|array_specification|prev_declared_structure_type_name|function_block_type_name */ |
|
168 |
// SYM_REF2(external_declaration_c, global_var_name, specification) |
|
169 |
void *visit(external_declaration_c *symbol); |
|
170 |
/*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */ |
|
171 |
/* type_specification ->may be NULL ! */ |
|
172 |
// SYM_REF2(global_var_decl_c, global_var_spec, type_specification) |
|
173 |
void *visit(global_var_decl_c *symbol); |
|
174 |
/*| global_var_name location */ |
|
175 |
//SYM_REF2(global_var_spec_c, global_var_name, location) |
|
176 |
void *visit(global_var_spec_c *symbol); |
|
177 |
/*| global_var_list ',' global_var_name */ |
|
178 |
//SYM_LIST(global_var_list_c) |
|
179 |
void *visit(global_var_list_c *symbol); |
|
180 |
/* [variable_name] location ':' located_var_spec_init */ |
|
181 |
/* variable_name -> may be NULL ! */ |
|
182 |
//SYM_REF4(located_var_decl_c, variable_name, location, located_var_spec_init, unused) |
|
183 |
void *visit(located_var_decl_c *symbol); |
|
184 |
/*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */ |
|
185 |
/* type_specification ->may be NULL ! */ |
|
186 |
// SYM_REF2(global_var_decl_c, global_var_spec, type_specification) |
|
187 |
// TODO!! |
|
188 |
/* AT direct_variable */ |
|
189 |
// SYM_REF2(location_c, direct_variable, unused) |
|
190 |
void *visit(location_c *symbol); |
|
191 |
/*| global_var_list ',' global_var_name */ |
|
192 |
// SYM_LIST(global_var_list_c) |
|
193 |
// TODO!! |
|
194 |
/* var1_list ':' single_byte_string_spec */ |
|
195 |
// SYM_REF2(single_byte_string_var_declaration_c, var1_list, single_byte_string_spec) |
|
196 |
void *visit(single_byte_string_var_declaration_c *symbol); |
|
197 |
/* STRING ['[' integer ']'] [ASSIGN single_byte_character_string] */ |
|
198 |
/* integer ->may be NULL ! */ |
|
199 |
/* single_byte_character_string ->may be NULL ! */ |
|
200 |
// SYM_REF2(single_byte_string_spec_c, integer, single_byte_character_string) |
|
201 |
// TODO!! |
|
202 |
||
203 |
/* var1_list ':' double_byte_string_spec */ |
|
204 |
// SYM_REF2(double_byte_string_var_declaration_c, var1_list, double_byte_string_spec) |
|
205 |
void *visit(double_byte_string_var_declaration_c *symbol); |
|
206 |
/* WSTRING ['[' integer ']'] [ASSIGN double_byte_character_string] */ |
|
207 |
/* integer ->may be NULL ! */ |
|
208 |
/* double_byte_character_string ->may be NULL ! */ |
|
209 |
// SYM_REF2(double_byte_string_spec_c, integer, double_byte_character_string) |
|
210 |
// TODO!! |
|
211 |
||
212 |
/* variable_name incompl_location ':' var_spec */ |
|
213 |
// SYM_REF4(incompl_located_var_decl_c, variable_name, incompl_location, var_spec, unused) |
|
214 |
// TODO!! |
|
215 |
||
216 |
/* AT incompl_location_token */ |
|
217 |
// SYM_TOKEN(incompl_location_c) |
|
218 |
// TODO!! |
|
219 |
||
220 |
||
221 |
/**************************************/ |
|
222 |
/* B.1.5 - Program organization units */ |
|
223 |
/**************************************/ |
|
224 |
/***********************/ |
|
225 |
/* B 1.5.1 - Functions */ |
|
226 |
/***********************/ |
|
227 |
// SYM_REF4(function_declaration_c, derived_function_name, type_name, var_declarations_list, function_body) |
|
228 |
void *visit(function_declaration_c *symbol); |
|
229 |
||
230 |
/*****************************/ |
|
231 |
/* B 1.5.2 - Function Blocks */ |
|
232 |
/*****************************/ |
|
233 |
void *visit(function_block_declaration_c *symbol); |
|
234 |
||
235 |
/**********************/ |
|
236 |
/* B 1.5.3 - Programs */ |
|
237 |
/**********************/ |
|
238 |
void *visit(program_declaration_c *symbol); |
|
239 |
||
240 |
/********************************/ |
|
241 |
/* B 1.7 Configuration elements */ |
|
242 |
/********************************/ |
|
243 |
||
244 |
/* |
|
245 |
CONFIGURATION configuration_name |
|
246 |
optional_global_var_declarations |
|
247 |
(resource_declaration_list | single_resource_declaration) |
|
248 |
optional_access_declarations |
|
249 |
optional_instance_specific_initializations |
|
250 |
END_CONFIGURATION |
|
251 |
*/ |
|
252 |
/* |
|
253 |
SYM_REF6(configuration_declaration_c, configuration_name, global_var_declarations, resource_declarations, access_declarations, instance_specific_initializations, unused) |
|
254 |
*/ |
|
255 |
void *visit(configuration_declaration_c *symbol); |
|
256 |
/* |
|
257 |
RESOURCE resource_name ON resource_type_name |
|
258 |
optional_global_var_declarations |
|
259 |
single_resource_declaration |
|
260 |
END_RESOURCE |
|
261 |
*/ |
|
262 |
// SYM_REF4(resource_declaration_c, resource_name, resource_type_name, global_var_declarations, resource_declaration) |
|
263 |
void *visit(resource_declaration_c *symbol); |
|
264 |
||
265 |
/* task_configuration_list program_configuration_list */ |
|
266 |
// SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list) |
|
267 |
void *visit(single_resource_declaration_c *symbol); |
|
268 |
||
269 |
#if 0 |
|
270 |
/*********************/ |
|
271 |
/* B 1.4 - Variables */ |
|
272 |
/*********************/ |
|
273 |
SYM_REF2(symbolic_variable_c, var_name, unused) |
|
274 |
||
275 |
/********************************************/ |
|
276 |
/* B.1.4.1 Directly Represented Variables */ |
|
277 |
/********************************************/ |
|
278 |
SYM_TOKEN(direct_variable_c) |
|
279 |
||
280 |
/*************************************/ |
|
281 |
/* B.1.4.2 Multi-element Variables */ |
|
282 |
/*************************************/ |
|
283 |
/* subscripted_variable '[' subscript_list ']' */ |
|
284 |
SYM_REF2(array_variable_c, subscripted_variable, subscript_list) |
|
285 |
||
286 |
/* subscript_list ',' subscript */ |
|
287 |
SYM_LIST(subscript_list_c) |
|
288 |
||
289 |
/* record_variable '.' field_selector */ |
|
290 |
/* WARNING: input and/or output variables of function blocks |
|
291 |
* may be accessed as fields of a tructured variable! |
|
292 |
* Code handling a structured_variable_c must take |
|
293 |
* this into account! |
|
294 |
*/ |
|
295 |
SYM_REF2(structured_variable_c, record_variable, field_selector) |
|
296 |
#endif |
|
297 |
||
298 |
}; // search_var_instance_decl_c |
|
299 |