author | laurent |
Thu, 22 Mar 2012 00:22:48 +0100 | |
changeset 408 | 34a5571c859c |
parent 377 | 60b012b7793f |
child 412 | aad38592bdde |
child 417 | d48f53715f77 |
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:
257
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:
257
diff
changeset
|
3 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
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:
257
diff
changeset
|
6 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
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:
257
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:
257
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:
257
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:
257
diff
changeset
|
11 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
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:
257
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:
257
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:
257
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:
257
diff
changeset
|
16 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
257
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:
257
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:
257
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:
257
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 on which another data type is based on. |
|
35 |
* If a new default initial value is given, we DO NOT consider it a |
|
36 |
* new base class, and continue looking further! |
|
37 |
* |
|
38 |
* E.g. TYPE new_int_t : INT; END_TYPE; |
|
39 |
* TYPE new_int2_t : INT = 2; END_TYPE; |
|
40 |
* TYPE new_subr_t : INT (4..5); END_TYPE; |
|
41 |
* |
|
42 |
* new_int_t is really an INT!! |
|
43 |
* new_int2_t is also really an INT!! |
|
44 |
* new_subr_t is also really an INT!! |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
45 |
* |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
46 |
* Note that a FB declaration is also considered a base type, as |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
47 |
* we may have FB instances declared of a specific FB type. |
181 | 48 |
*/ |
49 |
||
50 |
||
51 |
class search_base_type_c: public null_visitor_c { |
|
52 |
||
53 |
private: |
|
54 |
symbol_c *current_type_name; |
|
377
60b012b7793f
Adding support for compiling direct array specification inside variable declaration
laurent
parents:
279
diff
changeset
|
55 |
bool is_array; |
181 | 56 |
bool is_subrange; |
57 |
bool is_enumerated; |
|
58 |
||
59 |
public: |
|
60 |
search_base_type_c(void); |
|
61 |
||
62 |
public: |
|
63 |
void *visit(identifier_c *type_name); |
|
64 |
bool type_is_subrange(symbol_c* type_decl); |
|
65 |
bool type_is_enumerated(symbol_c* type_decl); |
|
66 |
||
67 |
public: |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
68 |
/*********************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
69 |
/* B 1.2 - Constants */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
70 |
/*********************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
71 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
72 |
/******************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
73 |
/* B 1.2.1 - Numeric Literals */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
74 |
/******************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
75 |
/* Numeric literals without any explicit type cast have unknown data type, |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
76 |
* so we continue considering them as their own basic data types until |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
77 |
* they can be resolved (for example, when using '30+x' where 'x' is a LINT variable, the |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
78 |
* numeric literal '30' must then be considered a LINT so the ADD function may be called |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
79 |
* with all inputs of the same data type. |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
80 |
* If 'x' were a SINT, then the '30' would have to be a SINT too! |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
81 |
*/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
82 |
void *visit(real_c *symbol); |
257 | 83 |
void *visit(neg_real_c *symbol); |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
84 |
void *visit(integer_c *symbol); |
257 | 85 |
void *visit(neg_integer_c *symbol); |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
86 |
void *visit(binary_integer_c *symbol); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
87 |
void *visit(octal_integer_c *symbol); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
88 |
void *visit(hex_integer_c *symbol); |
257 | 89 |
void *visit(boolean_true_c *symbol); |
90 |
void *visit(boolean_false_c *symbol); |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
91 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
92 |
|
181 | 93 |
/***********************************/ |
94 |
/* B 1.3.1 - Elementary Data Types */ |
|
95 |
/***********************************/ |
|
96 |
void *visit(time_type_name_c *symbol); |
|
97 |
void *visit(bool_type_name_c *symbol); |
|
98 |
void *visit(sint_type_name_c *symbol); |
|
99 |
void *visit(int_type_name_c *symbol); |
|
100 |
void *visit(dint_type_name_c *symbol); |
|
101 |
void *visit(lint_type_name_c *symbol); |
|
102 |
void *visit(usint_type_name_c *symbol); |
|
103 |
void *visit(uint_type_name_c *symbol); |
|
104 |
void *visit(udint_type_name_c *symbol); |
|
105 |
void *visit(ulint_type_name_c *symbol); |
|
106 |
void *visit(real_type_name_c *symbol); |
|
107 |
void *visit(lreal_type_name_c *symbol); |
|
108 |
void *visit(date_type_name_c *symbol); |
|
109 |
void *visit(tod_type_name_c *symbol); |
|
110 |
void *visit(dt_type_name_c *symbol) ; |
|
111 |
void *visit(byte_type_name_c *symbol); |
|
112 |
void *visit(word_type_name_c *symbol); |
|
113 |
void *visit(dword_type_name_c *symbol); |
|
114 |
void *visit(lword_type_name_c *symbol); |
|
115 |
void *visit(string_type_name_c *symbol); |
|
116 |
void *visit(wstring_type_name_c *symbol); |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
117 |
|
181 | 118 |
/******************************************************/ |
119 |
/* Extensions to the base standard as defined in */ |
|
120 |
/* "Safety Software Technical Specification, */ |
|
121 |
/* Part 1: Concepts and Function Blocks, */ |
|
122 |
/* Version 1.0 – Official Release" */ |
|
123 |
/* by PLCopen - Technical Committee 5 - 2006-01-31 */ |
|
124 |
/******************************************************/ |
|
257 | 125 |
void *visit(safetime_type_name_c *symbol); |
181 | 126 |
void *visit(safebool_type_name_c *symbol); |
257 | 127 |
void *visit(safesint_type_name_c *symbol); |
128 |
void *visit(safeint_type_name_c *symbol); |
|
129 |
void *visit(safedint_type_name_c *symbol); |
|
130 |
void *visit(safelint_type_name_c *symbol); |
|
131 |
void *visit(safeusint_type_name_c *symbol); |
|
132 |
void *visit(safeuint_type_name_c *symbol); |
|
133 |
void *visit(safeudint_type_name_c *symbol); |
|
134 |
void *visit(safeulint_type_name_c *symbol); |
|
135 |
void *visit(safereal_type_name_c *symbol); |
|
136 |
void *visit(safelreal_type_name_c *symbol); |
|
137 |
void *visit(safedate_type_name_c *symbol); |
|
138 |
void *visit(safetod_type_name_c *symbol); |
|
139 |
void *visit(safedt_type_name_c *symbol) ; |
|
140 |
void *visit(safebyte_type_name_c *symbol); |
|
141 |
void *visit(safeword_type_name_c *symbol); |
|
142 |
void *visit(safedword_type_name_c *symbol); |
|
143 |
void *visit(safelword_type_name_c *symbol); |
|
144 |
void *visit(safestring_type_name_c *symbol); |
|
145 |
void *visit(safewstring_type_name_c *symbol); |
|
181 | 146 |
|
147 |
/********************************/ |
|
148 |
/* B 1.3.3 - Derived data types */ |
|
149 |
/********************************/ |
|
150 |
/* simple_type_name ':' simple_spec_init */ |
|
151 |
void *visit(simple_type_declaration_c *symbol); |
|
152 |
/* simple_specification ASSIGN constant */ |
|
153 |
void *visit(simple_spec_init_c *symbol); |
|
154 |
/* subrange_type_name ':' subrange_spec_init */ |
|
155 |
void *visit(subrange_type_declaration_c *symbol); |
|
156 |
/* subrange_specification ASSIGN signed_integer */ |
|
157 |
void *visit(subrange_spec_init_c *symbol); |
|
158 |
/* integer_type_name '(' subrange')' */ |
|
159 |
void *visit(subrange_specification_c *symbol); |
|
160 |
/* signed_integer DOTDOT signed_integer */ |
|
161 |
void *visit(subrange_c *symbol); |
|
162 |
||
163 |
/* enumerated_type_name ':' enumerated_spec_init */ |
|
164 |
void *visit(enumerated_type_declaration_c *symbol); |
|
165 |
/* enumerated_specification ASSIGN enumerated_value */ |
|
166 |
void *visit(enumerated_spec_init_c *symbol); |
|
167 |
/* helper symbol for enumerated_specification->enumerated_spec_init */ |
|
168 |
/* enumerated_value_list ',' enumerated_value */ |
|
169 |
void *visit(enumerated_value_list_c *symbol); |
|
170 |
/* enumerated_type_name '#' identifier */ |
|
171 |
// SYM_REF2(enumerated_value_c, type, value) |
|
172 |
void *visit(enumerated_value_c *symbol); |
|
173 |
/* identifier ':' array_spec_init */ |
|
174 |
void *visit(array_type_declaration_c *symbol); |
|
175 |
/* array_specification [ASSIGN array_initialization} */ |
|
176 |
/* array_initialization may be NULL ! */ |
|
177 |
void *visit(array_spec_init_c *symbol); |
|
178 |
/* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */ |
|
179 |
void *visit(array_specification_c *symbol); |
|
180 |
/* helper symbol for array_specification */ |
|
181 |
/* array_subrange_list ',' subrange */ |
|
182 |
void *visit(array_subrange_list_c *symbol); |
|
183 |
/* array_initialization: '[' array_initial_elements_list ']' */ |
|
184 |
/* helper symbol for array_initialization */ |
|
185 |
/* array_initial_elements_list ',' array_initial_elements */ |
|
186 |
void *visit(array_initial_elements_list_c *symbol); |
|
187 |
/* integer '(' [array_initial_element] ')' */ |
|
188 |
/* array_initial_element may be NULL ! */ |
|
189 |
void *visit(array_initial_elements_c *symbol); |
|
190 |
/* structure_type_name ':' structure_specification */ |
|
191 |
/* NOTE: structure_specification will point to either a |
|
192 |
* initialized_structure_c |
|
193 |
* OR A |
|
194 |
* structure_element_declaration_list_c |
|
195 |
*/ |
|
196 |
void *visit(structure_type_declaration_c *symbol); |
|
197 |
/* structure_type_name ASSIGN structure_initialization */ |
|
198 |
/* structure_initialization may be NULL ! */ |
|
199 |
void *visit(initialized_structure_c *symbol); |
|
200 |
/* helper symbol for structure_declaration */ |
|
201 |
/* structure_declaration: STRUCT structure_element_declaration_list END_STRUCT */ |
|
202 |
/* structure_element_declaration_list structure_element_declaration ';' */ |
|
203 |
void *visit(structure_element_declaration_list_c *symbol); |
|
204 |
/* structure_element_name ':' *_spec_init */ |
|
205 |
void *visit(structure_element_declaration_c *symbol); |
|
206 |
/* helper symbol for structure_initialization */ |
|
207 |
/* structure_initialization: '(' structure_element_initialization_list ')' */ |
|
208 |
/* structure_element_initialization_list ',' structure_element_initialization */ |
|
209 |
void *visit(structure_element_initialization_list_c *symbol); |
|
210 |
/* structure_element_name ASSIGN value */ |
|
211 |
void *visit(structure_element_initialization_c *symbol); |
|
212 |
/* string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */ |
|
213 |
/* |
|
214 |
SYM_REF4(string_type_declaration_c, string_type_name, |
|
215 |
elementary_string_type_name, |
|
216 |
string_type_declaration_size, |
|
217 |
string_type_declaration_init) // may be == NULL! |
|
218 |
*/ |
|
219 |
void *visit(string_type_declaration_c *symbol); |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
220 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
221 |
/*****************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
222 |
/* B 1.5.2 - Function Blocks */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
223 |
/*****************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
224 |
/* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
225 |
// SYM_REF3(function_block_declaration_c, fblock_name, var_declarations, fblock_body) |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
226 |
void *visit(function_block_declaration_c *symbol); |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
227 |
|
181 | 228 |
}; // search_base_type_c |
229 |
||
230 |
||
231 |
||
232 |