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