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