author | laurent |
Fri, 24 Feb 2012 14:16:51 +0100 | |
changeset 406 | 6381589697ff |
parent 372 | 25332e048742 |
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:
226
diff
changeset
|
2 |
* matiec - a compiler for the programming languages defined in IEC 61131-3 |
181 | 3 |
* |
265
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 |
181 | 6 |
* |
265
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 |
||
35 |
/* Determine the data type of a variable. |
|
36 |
* The variable may be a simple variable, a function block instance, a |
|
37 |
* struture element within a data structured type (a struct or a fb), or |
|
38 |
* an array element. |
|
39 |
* A mixture of array element of a structure element of a structure element |
|
40 |
* of a .... is also suported! |
|
41 |
* |
|
42 |
* example: |
|
43 |
* window.points[1].coordinate.x |
|
44 |
* window.points[1].colour |
|
45 |
* etc... ARE ALLOWED! |
|
46 |
* |
|
47 |
* This class must be passed the scope within which the |
|
48 |
* variable was declared, and the variable name... |
|
321
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
49 |
* |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
50 |
* |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
51 |
* |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
52 |
* |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
53 |
* |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
54 |
* This class has several members, depending on the exact data the caller |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
55 |
* is looking for... |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
56 |
* |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
57 |
* - item i: we can get either the name of the data type(A), |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
58 |
* or it's declaration (B) |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
59 |
* (notice however that some variables belong to a data type that does |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
60 |
* not have a name, only a declaration as in |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
61 |
* VAR a: ARRAY [1..3] of INT; END_VAR |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
62 |
* ) |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
63 |
* - item ii: we can get either the direct data type (1), |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
64 |
* or the base type (2) |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
65 |
* |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
66 |
* By direct type, I mean the data type of the variable. By base type, I |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
67 |
* mean the data type on which the direct type is based on. For example, in |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
68 |
* a subrange on INT, the direct type is the subrange itself, while the |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
69 |
* base type is INT. |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
70 |
* e.g. |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
71 |
* This means that if we find that the variable is of type MY_INT, |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
72 |
* which was previously declared to be |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
73 |
* TYPE MY_INT: INT := 9; |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
74 |
* option (1) will return MY_INT |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
75 |
* option (2) will return INT |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
76 |
* |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
77 |
* |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
78 |
* Member functions: |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
79 |
* ================ |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
80 |
* get_basetype_decl() ---> returns 2B |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
81 |
* get_type_id() ---> returns 1A |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
82 |
* |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
83 |
* Since we haven't yet needed them, we don't yet implement |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
84 |
* get_basetype_id() ----> would return 2A |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
85 |
* get_type_decl() ----> would return 1B |
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
86 |
*/ |
181 | 87 |
|
88 |
class search_varfb_instance_type_c: public search_base_type_c { |
|
89 |
||
90 |
private: |
|
91 |
search_var_instance_decl_c search_var_instance_decl; |
|
92 |
decompose_var_instance_name_c *decompose_var_instance_name; |
|
93 |
symbol_c *current_structelement_name; |
|
371
926490780952
Cleaning up: Getting some sense into the code handling structures.
Mario de Sousa <msousa@fe.up.pt>
parents:
321
diff
changeset
|
94 |
symbol_c *current_typeid; |
372
25332e048742
Implement get_type_decl(), as it seems Manuele will need it later...
Mario de Sousa <msousa@fe.up.pt>
parents:
371
diff
changeset
|
95 |
symbol_c *current_basetypeid; |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
181
diff
changeset
|
96 |
bool is_complex; |
181 | 97 |
|
98 |
public: |
|
99 |
search_varfb_instance_type_c(symbol_c *search_scope); |
|
321
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
100 |
symbol_c *get_basetype_decl(symbol_c *variable_name); |
372
25332e048742
Implement get_type_decl(), as it seems Manuele will need it later...
Mario de Sousa <msousa@fe.up.pt>
parents:
371
diff
changeset
|
101 |
symbol_c *get_type_decl(symbol_c *variable_name); |
321
a96399ab57c2
Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
102 |
symbol_c *get_type_id(symbol_c *variable_name); |
181 | 103 |
|
372
25332e048742
Implement get_type_decl(), as it seems Manuele will need it later...
Mario de Sousa <msousa@fe.up.pt>
parents:
371
diff
changeset
|
104 |
/* NOTE: this function should be remvoed/deleted. |
25332e048742
Implement get_type_decl(), as it seems Manuele will need it later...
Mario de Sousa <msousa@fe.up.pt>
parents:
371
diff
changeset
|
105 |
* However, it is currently used in stage 4, and before deleting it |
25332e048742
Implement get_type_decl(), as it seems Manuele will need it later...
Mario de Sousa <msousa@fe.up.pt>
parents:
371
diff
changeset
|
106 |
* requires that the stage4 code be analysed and fixed (i.e. replace by |
25332e048742
Implement get_type_decl(), as it seems Manuele will need it later...
Mario de Sousa <msousa@fe.up.pt>
parents:
371
diff
changeset
|
107 |
* a call to one of the above functions get_basetype_decl(), |
25332e048742
Implement get_type_decl(), as it seems Manuele will need it later...
Mario de Sousa <msousa@fe.up.pt>
parents:
371
diff
changeset
|
108 |
* get_type_decl(), get_type_id(). |
25332e048742
Implement get_type_decl(), as it seems Manuele will need it later...
Mario de Sousa <msousa@fe.up.pt>
parents:
371
diff
changeset
|
109 |
* |
25332e048742
Implement get_type_decl(), as it seems Manuele will need it later...
Mario de Sousa <msousa@fe.up.pt>
parents:
371
diff
changeset
|
110 |
* At the moment, I have a feeling that this whole class search_varfb_instance_type_c |
25332e048742
Implement get_type_decl(), as it seems Manuele will need it later...
Mario de Sousa <msousa@fe.up.pt>
parents:
371
diff
changeset
|
111 |
* will not be needed in the future (i.e. when we finish implementing type checking |
25332e048742
Implement get_type_decl(), as it seems Manuele will need it later...
Mario de Sousa <msousa@fe.up.pt>
parents:
371
diff
changeset
|
112 |
* in stage 3 correctly, where we store on each symbol in the abstract syntax |
25332e048742
Implement get_type_decl(), as it seems Manuele will need it later...
Mario de Sousa <msousa@fe.up.pt>
parents:
371
diff
changeset
|
113 |
* tree it's data type, so stage4 implementations will not need to deduce the data |
25332e048742
Implement get_type_decl(), as it seems Manuele will need it later...
Mario de Sousa <msousa@fe.up.pt>
parents:
371
diff
changeset
|
114 |
* types again), so it does not make much sense to spend more time on it. |
25332e048742
Implement get_type_decl(), as it seems Manuele will need it later...
Mario de Sousa <msousa@fe.up.pt>
parents:
371
diff
changeset
|
115 |
*/ |
181 | 116 |
unsigned int get_vartype(symbol_c *variable_name); |
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
181
diff
changeset
|
117 |
bool type_is_complex(void); |
181 | 118 |
|
119 |
private: |
|
120 |
/* a helper function... */ |
|
121 |
void *visit_list(list_c *list); |
|
122 |
||
123 |
/* a helper function... */ |
|
124 |
void *base_type(symbol_c *symbol); |
|
125 |
||
126 |
||
127 |
private: |
|
128 |
/* We override the base class' visitor to identifier_c. |
|
129 |
* This is so because the base class does not consider a function block |
|
130 |
* to be a type, unlike this class that allows a variable instance |
|
131 |
* of a function block type... |
|
132 |
*/ |
|
133 |
void *visit(identifier_c *type_name); |
|
134 |
||
135 |
/********************************/ |
|
136 |
/* B 1.3.3 - Derived data types */ |
|
137 |
/********************************/ |
|
138 |
||
139 |
/* identifier ':' array_spec_init */ |
|
140 |
void *visit(array_type_declaration_c *symbol); |
|
141 |
||
142 |
/* array_specification [ASSIGN array_initialization} */ |
|
143 |
/* array_initialization may be NULL ! */ |
|
144 |
void *visit(array_spec_init_c *symbol); |
|
145 |
||
146 |
/* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */ |
|
147 |
void *visit(array_specification_c *symbol); |
|
148 |
||
149 |
/* structure_type_name ':' structure_specification */ |
|
150 |
void *visit(structure_type_declaration_c *symbol); |
|
151 |
||
152 |
/* structure_type_name ASSIGN structure_initialization */ |
|
153 |
/* structure_initialization may be NULL ! */ |
|
154 |
// SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization) |
|
155 |
void *visit(initialized_structure_c *symbol); |
|
156 |
||
157 |
/* helper symbol for structure_declaration */ |
|
158 |
/* structure_declaration: STRUCT structure_element_declaration_list END_STRUCT */ |
|
159 |
/* structure_element_declaration_list structure_element_declaration ';' */ |
|
160 |
void *visit(structure_element_declaration_list_c *symbol); |
|
161 |
||
162 |
/* structure_element_name ':' spec_init */ |
|
163 |
void *visit(structure_element_declaration_c *symbol); |
|
164 |
||
165 |
/* helper symbol for structure_initialization */ |
|
166 |
/* structure_initialization: '(' structure_element_initialization_list ')' */ |
|
167 |
/* structure_element_initialization_list ',' structure_element_initialization */ |
|
168 |
void *visit(structure_element_initialization_list_c *symbol); /* should never get called... */ |
|
169 |
/* structure_element_name ASSIGN value */ |
|
170 |
void *visit(structure_element_initialization_c *symbol); /* should never get called... */ |
|
171 |
||
172 |
||
173 |
||
174 |
/**************************************/ |
|
175 |
/* B.1.5 - Program organization units */ |
|
176 |
/**************************************/ |
|
177 |
/*****************************/ |
|
178 |
/* B 1.5.2 - Function Blocks */ |
|
179 |
/*****************************/ |
|
180 |
/* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ |
|
181 |
// SYM_REF4(function_block_declaration_c, fblock_name, var_declarations, fblock_body, unused) |
|
182 |
void *visit(function_block_declaration_c *symbol); |
|
183 |
||
184 |
}; // search_varfb_instance_type_c |
|
185 |
||
186 |
||
187 |
||
188 |
||
189 |
||
190 |