author | Mario de Sousa <msousa@fe.up.pt> |
Tue, 05 Apr 2011 19:42:33 +0100 | |
changeset 284 | 64a4504633d4 |
parent 279 | c0453b7f99df |
child 321 | a96399ab57c2 |
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 |
* A reference to the relevant base type __definition__ is returned. |
|
43 |
* This means that if we find that the variable is of type MY_INT, |
|
44 |
* which was previously declared to be |
|
45 |
* TYPE MY_INT: INT := 9; |
|
46 |
* this class wil return INT, and __not__ MY_INT !! |
|
47 |
* |
|
48 |
* |
|
49 |
* example: |
|
50 |
* window.points[1].coordinate.x |
|
51 |
* window.points[1].colour |
|
52 |
* etc... ARE ALLOWED! |
|
53 |
* |
|
54 |
* This class must be passed the scope within which the |
|
55 |
* variable was declared, and the variable name... |
|
56 |
*/ |
|
57 |
||
58 |
class search_varfb_instance_type_c: public search_base_type_c { |
|
59 |
||
60 |
private: |
|
61 |
search_var_instance_decl_c search_var_instance_decl; |
|
62 |
decompose_var_instance_name_c *decompose_var_instance_name; |
|
63 |
symbol_c *current_structelement_name; |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
181
diff
changeset
|
64 |
symbol_c *current_rawtype; |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
181
diff
changeset
|
65 |
bool is_complex; |
181 | 66 |
|
67 |
public: |
|
68 |
search_varfb_instance_type_c(symbol_c *search_scope); |
|
226
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
181
diff
changeset
|
69 |
symbol_c *get_type(symbol_c *variable_name); |
29f8ffc203c1
Adding support for setter and getter on complex datatype in ST
laurent
parents:
181
diff
changeset
|
70 |
symbol_c *get_rawtype(symbol_c *variable_name); |
181 | 71 |
|
72 |
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
|
73 |
bool type_is_complex(void); |
181 | 74 |
|
75 |
private: |
|
76 |
/* a helper function... */ |
|
77 |
void *visit_list(list_c *list); |
|
78 |
||
79 |
/* a helper function... */ |
|
80 |
void *base_type(symbol_c *symbol); |
|
81 |
||
82 |
||
83 |
private: |
|
84 |
/* We override the base class' visitor to identifier_c. |
|
85 |
* This is so because the base class does not consider a function block |
|
86 |
* to be a type, unlike this class that allows a variable instance |
|
87 |
* of a function block type... |
|
88 |
*/ |
|
89 |
void *visit(identifier_c *type_name); |
|
90 |
||
91 |
/********************************/ |
|
92 |
/* B 1.3.3 - Derived data types */ |
|
93 |
/********************************/ |
|
94 |
||
95 |
/* identifier ':' array_spec_init */ |
|
96 |
void *visit(array_type_declaration_c *symbol); |
|
97 |
||
98 |
/* array_specification [ASSIGN array_initialization} */ |
|
99 |
/* array_initialization may be NULL ! */ |
|
100 |
void *visit(array_spec_init_c *symbol); |
|
101 |
||
102 |
/* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */ |
|
103 |
void *visit(array_specification_c *symbol); |
|
104 |
||
105 |
/* structure_type_name ':' structure_specification */ |
|
106 |
void *visit(structure_type_declaration_c *symbol); |
|
107 |
||
108 |
/* structure_type_name ASSIGN structure_initialization */ |
|
109 |
/* structure_initialization may be NULL ! */ |
|
110 |
// SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization) |
|
111 |
void *visit(initialized_structure_c *symbol); |
|
112 |
||
113 |
/* helper symbol for structure_declaration */ |
|
114 |
/* structure_declaration: STRUCT structure_element_declaration_list END_STRUCT */ |
|
115 |
/* structure_element_declaration_list structure_element_declaration ';' */ |
|
116 |
void *visit(structure_element_declaration_list_c *symbol); |
|
117 |
||
118 |
/* structure_element_name ':' spec_init */ |
|
119 |
void *visit(structure_element_declaration_c *symbol); |
|
120 |
||
121 |
/* helper symbol for structure_initialization */ |
|
122 |
/* structure_initialization: '(' structure_element_initialization_list ')' */ |
|
123 |
/* structure_element_initialization_list ',' structure_element_initialization */ |
|
124 |
void *visit(structure_element_initialization_list_c *symbol); /* should never get called... */ |
|
125 |
/* structure_element_name ASSIGN value */ |
|
126 |
void *visit(structure_element_initialization_c *symbol); /* should never get called... */ |
|
127 |
||
128 |
||
129 |
||
130 |
/**************************************/ |
|
131 |
/* B.1.5 - Program organization units */ |
|
132 |
/**************************************/ |
|
133 |
/*****************************/ |
|
134 |
/* B 1.5.2 - Function Blocks */ |
|
135 |
/*****************************/ |
|
136 |
/* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ |
|
137 |
// SYM_REF4(function_block_declaration_c, fblock_name, var_declarations, fblock_body, unused) |
|
138 |
void *visit(function_block_declaration_c *symbol); |
|
139 |
||
140 |
}; // search_varfb_instance_type_c |
|
141 |
||
142 |
||
143 |
||
144 |
||
145 |
||
146 |