author | Mario de Sousa <msousa@fe.up.pt> |
Thu, 31 Mar 2011 10:52:03 +0100 | |
changeset 259 | b6d7c71ff6d8 |
parent 257 | 90782e241346 |
child 265 | 4d222f46f8cc |
permissions | -rwxr-xr-x |
181 | 1 |
/* |
2 |
* (c) 2003 Mario de Sousa |
|
3 |
* |
|
4 |
* Offered to the public under the terms of the GNU General Public License |
|
5 |
* as published by the Free Software Foundation; either version 2 of the |
|
6 |
* License, or (at your option) any later version. |
|
7 |
* |
|
8 |
* This program is distributed in the hope that it will be useful, but |
|
9 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
11 |
* Public License for more details. |
|
12 |
* |
|
13 |
* This code is made available on the understanding that it will not be |
|
14 |
* used in safety-critical situations without a full and competent review. |
|
15 |
*/ |
|
16 |
||
17 |
/* |
|
18 |
* An IEC 61131-3 IL and ST compiler. |
|
19 |
* |
|
20 |
* Based on the |
|
21 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
||
26 |
/* Determine the data type on which another data type is based on. |
|
27 |
* If a new default initial value is given, we DO NOT consider it a |
|
28 |
* new base class, and continue looking further! |
|
29 |
* |
|
30 |
* E.g. TYPE new_int_t : INT; END_TYPE; |
|
31 |
* TYPE new_int2_t : INT = 2; END_TYPE; |
|
32 |
* TYPE new_subr_t : INT (4..5); END_TYPE; |
|
33 |
* |
|
34 |
* new_int_t is really an INT!! |
|
35 |
* new_int2_t is also really an INT!! |
|
36 |
* 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
|
37 |
* |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
38 |
* 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
|
39 |
* we may have FB instances declared of a specific FB type. |
181 | 40 |
*/ |
41 |
||
42 |
||
43 |
class search_base_type_c: public null_visitor_c { |
|
44 |
||
45 |
private: |
|
46 |
symbol_c *current_type_name; |
|
47 |
bool is_subrange; |
|
48 |
bool is_enumerated; |
|
49 |
||
50 |
public: |
|
51 |
search_base_type_c(void); |
|
52 |
||
53 |
public: |
|
54 |
void *visit(identifier_c *type_name); |
|
55 |
bool type_is_subrange(symbol_c* type_decl); |
|
56 |
bool type_is_enumerated(symbol_c* type_decl); |
|
57 |
||
58 |
public: |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
59 |
/*********************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
60 |
/* B 1.2 - Constants */ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
61 |
/*********************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
62 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
63 |
/******************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
64 |
/* 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
|
65 |
/******************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
66 |
/* 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
|
67 |
* 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
|
68 |
* 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
|
69 |
* 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
|
70 |
* 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
|
71 |
* 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
|
72 |
*/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
73 |
void *visit(real_c *symbol); |
257 | 74 |
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
|
75 |
void *visit(integer_c *symbol); |
257 | 76 |
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
|
77 |
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
|
78 |
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
|
79 |
void *visit(hex_integer_c *symbol); |
257 | 80 |
void *visit(boolean_true_c *symbol); |
81 |
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
|
82 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
83 |
|
181 | 84 |
/***********************************/ |
85 |
/* B 1.3.1 - Elementary Data Types */ |
|
86 |
/***********************************/ |
|
87 |
void *visit(time_type_name_c *symbol); |
|
88 |
void *visit(bool_type_name_c *symbol); |
|
89 |
void *visit(sint_type_name_c *symbol); |
|
90 |
void *visit(int_type_name_c *symbol); |
|
91 |
void *visit(dint_type_name_c *symbol); |
|
92 |
void *visit(lint_type_name_c *symbol); |
|
93 |
void *visit(usint_type_name_c *symbol); |
|
94 |
void *visit(uint_type_name_c *symbol); |
|
95 |
void *visit(udint_type_name_c *symbol); |
|
96 |
void *visit(ulint_type_name_c *symbol); |
|
97 |
void *visit(real_type_name_c *symbol); |
|
98 |
void *visit(lreal_type_name_c *symbol); |
|
99 |
void *visit(date_type_name_c *symbol); |
|
100 |
void *visit(tod_type_name_c *symbol); |
|
101 |
void *visit(dt_type_name_c *symbol) ; |
|
102 |
void *visit(byte_type_name_c *symbol); |
|
103 |
void *visit(word_type_name_c *symbol); |
|
104 |
void *visit(dword_type_name_c *symbol); |
|
105 |
void *visit(lword_type_name_c *symbol); |
|
106 |
void *visit(string_type_name_c *symbol); |
|
107 |
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
|
108 |
|
181 | 109 |
/******************************************************/ |
110 |
/* Extensions to the base standard as defined in */ |
|
111 |
/* "Safety Software Technical Specification, */ |
|
112 |
/* Part 1: Concepts and Function Blocks, */ |
|
113 |
/* Version 1.0 – Official Release" */ |
|
114 |
/* by PLCopen - Technical Committee 5 - 2006-01-31 */ |
|
115 |
/******************************************************/ |
|
257 | 116 |
void *visit(safetime_type_name_c *symbol); |
181 | 117 |
void *visit(safebool_type_name_c *symbol); |
257 | 118 |
void *visit(safesint_type_name_c *symbol); |
119 |
void *visit(safeint_type_name_c *symbol); |
|
120 |
void *visit(safedint_type_name_c *symbol); |
|
121 |
void *visit(safelint_type_name_c *symbol); |
|
122 |
void *visit(safeusint_type_name_c *symbol); |
|
123 |
void *visit(safeuint_type_name_c *symbol); |
|
124 |
void *visit(safeudint_type_name_c *symbol); |
|
125 |
void *visit(safeulint_type_name_c *symbol); |
|
126 |
void *visit(safereal_type_name_c *symbol); |
|
127 |
void *visit(safelreal_type_name_c *symbol); |
|
128 |
void *visit(safedate_type_name_c *symbol); |
|
129 |
void *visit(safetod_type_name_c *symbol); |
|
130 |
void *visit(safedt_type_name_c *symbol) ; |
|
131 |
void *visit(safebyte_type_name_c *symbol); |
|
132 |
void *visit(safeword_type_name_c *symbol); |
|
133 |
void *visit(safedword_type_name_c *symbol); |
|
134 |
void *visit(safelword_type_name_c *symbol); |
|
135 |
void *visit(safestring_type_name_c *symbol); |
|
136 |
void *visit(safewstring_type_name_c *symbol); |
|
181 | 137 |
|
138 |
/********************************/ |
|
139 |
/* B 1.3.3 - Derived data types */ |
|
140 |
/********************************/ |
|
141 |
/* simple_type_name ':' simple_spec_init */ |
|
142 |
void *visit(simple_type_declaration_c *symbol); |
|
143 |
/* simple_specification ASSIGN constant */ |
|
144 |
void *visit(simple_spec_init_c *symbol); |
|
145 |
/* subrange_type_name ':' subrange_spec_init */ |
|
146 |
void *visit(subrange_type_declaration_c *symbol); |
|
147 |
/* subrange_specification ASSIGN signed_integer */ |
|
148 |
void *visit(subrange_spec_init_c *symbol); |
|
149 |
/* integer_type_name '(' subrange')' */ |
|
150 |
void *visit(subrange_specification_c *symbol); |
|
151 |
/* signed_integer DOTDOT signed_integer */ |
|
152 |
void *visit(subrange_c *symbol); |
|
153 |
||
154 |
/* enumerated_type_name ':' enumerated_spec_init */ |
|
155 |
void *visit(enumerated_type_declaration_c *symbol); |
|
156 |
/* enumerated_specification ASSIGN enumerated_value */ |
|
157 |
void *visit(enumerated_spec_init_c *symbol); |
|
158 |
/* helper symbol for enumerated_specification->enumerated_spec_init */ |
|
159 |
/* enumerated_value_list ',' enumerated_value */ |
|
160 |
void *visit(enumerated_value_list_c *symbol); |
|
161 |
/* enumerated_type_name '#' identifier */ |
|
162 |
// SYM_REF2(enumerated_value_c, type, value) |
|
163 |
void *visit(enumerated_value_c *symbol); |
|
164 |
/* identifier ':' array_spec_init */ |
|
165 |
void *visit(array_type_declaration_c *symbol); |
|
166 |
/* array_specification [ASSIGN array_initialization} */ |
|
167 |
/* array_initialization may be NULL ! */ |
|
168 |
void *visit(array_spec_init_c *symbol); |
|
169 |
/* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */ |
|
170 |
void *visit(array_specification_c *symbol); |
|
171 |
/* helper symbol for array_specification */ |
|
172 |
/* array_subrange_list ',' subrange */ |
|
173 |
void *visit(array_subrange_list_c *symbol); |
|
174 |
/* array_initialization: '[' array_initial_elements_list ']' */ |
|
175 |
/* helper symbol for array_initialization */ |
|
176 |
/* array_initial_elements_list ',' array_initial_elements */ |
|
177 |
void *visit(array_initial_elements_list_c *symbol); |
|
178 |
/* integer '(' [array_initial_element] ')' */ |
|
179 |
/* array_initial_element may be NULL ! */ |
|
180 |
void *visit(array_initial_elements_c *symbol); |
|
181 |
/* structure_type_name ':' structure_specification */ |
|
182 |
/* NOTE: structure_specification will point to either a |
|
183 |
* initialized_structure_c |
|
184 |
* OR A |
|
185 |
* structure_element_declaration_list_c |
|
186 |
*/ |
|
187 |
void *visit(structure_type_declaration_c *symbol); |
|
188 |
/* structure_type_name ASSIGN structure_initialization */ |
|
189 |
/* structure_initialization may be NULL ! */ |
|
190 |
void *visit(initialized_structure_c *symbol); |
|
191 |
/* helper symbol for structure_declaration */ |
|
192 |
/* structure_declaration: STRUCT structure_element_declaration_list END_STRUCT */ |
|
193 |
/* structure_element_declaration_list structure_element_declaration ';' */ |
|
194 |
void *visit(structure_element_declaration_list_c *symbol); |
|
195 |
/* structure_element_name ':' *_spec_init */ |
|
196 |
void *visit(structure_element_declaration_c *symbol); |
|
197 |
/* helper symbol for structure_initialization */ |
|
198 |
/* structure_initialization: '(' structure_element_initialization_list ')' */ |
|
199 |
/* structure_element_initialization_list ',' structure_element_initialization */ |
|
200 |
void *visit(structure_element_initialization_list_c *symbol); |
|
201 |
/* structure_element_name ASSIGN value */ |
|
202 |
void *visit(structure_element_initialization_c *symbol); |
|
203 |
/* string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */ |
|
204 |
/* |
|
205 |
SYM_REF4(string_type_declaration_c, string_type_name, |
|
206 |
elementary_string_type_name, |
|
207 |
string_type_declaration_size, |
|
208 |
string_type_declaration_init) // may be == NULL! |
|
209 |
*/ |
|
210 |
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
|
211 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
212 |
/*****************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
213 |
/* 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
|
214 |
/*****************************/ |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
194
diff
changeset
|
215 |
/* 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
|
216 |
// 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
|
217 |
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
|
218 |
|
181 | 219 |
}; // search_base_type_c |
220 |
||
221 |
||
222 |
||
223 |