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!!
|
|
37 |
*/
|
|
38 |
|
|
39 |
|
|
40 |
class search_base_type_c: public null_visitor_c {
|
|
41 |
|
|
42 |
private:
|
|
43 |
symbol_c *current_type_name;
|
|
44 |
bool is_subrange;
|
|
45 |
bool is_enumerated;
|
|
46 |
|
|
47 |
public:
|
|
48 |
search_base_type_c(void);
|
|
49 |
|
|
50 |
public:
|
|
51 |
void *visit(identifier_c *type_name);
|
|
52 |
bool type_is_subrange(symbol_c* type_decl);
|
|
53 |
bool type_is_enumerated(symbol_c* type_decl);
|
|
54 |
|
|
55 |
public:
|
|
56 |
/***********************************/
|
|
57 |
/* B 1.3.1 - Elementary Data Types */
|
|
58 |
/***********************************/
|
|
59 |
void *visit(time_type_name_c *symbol);
|
|
60 |
void *visit(bool_type_name_c *symbol);
|
|
61 |
void *visit(sint_type_name_c *symbol);
|
|
62 |
void *visit(int_type_name_c *symbol);
|
|
63 |
void *visit(dint_type_name_c *symbol);
|
|
64 |
void *visit(lint_type_name_c *symbol);
|
|
65 |
void *visit(usint_type_name_c *symbol);
|
|
66 |
void *visit(uint_type_name_c *symbol);
|
|
67 |
void *visit(udint_type_name_c *symbol);
|
|
68 |
void *visit(ulint_type_name_c *symbol);
|
|
69 |
void *visit(real_type_name_c *symbol);
|
|
70 |
void *visit(lreal_type_name_c *symbol);
|
|
71 |
void *visit(date_type_name_c *symbol);
|
|
72 |
void *visit(tod_type_name_c *symbol);
|
|
73 |
void *visit(dt_type_name_c *symbol) ;
|
|
74 |
void *visit(byte_type_name_c *symbol);
|
|
75 |
void *visit(word_type_name_c *symbol);
|
|
76 |
void *visit(dword_type_name_c *symbol);
|
|
77 |
void *visit(lword_type_name_c *symbol);
|
|
78 |
void *visit(string_type_name_c *symbol);
|
|
79 |
void *visit(wstring_type_name_c *symbol);
|
|
80 |
void *visit(constant_int_type_name_c *symbol);
|
|
81 |
void *visit(constant_real_type_name_c *symbol);
|
|
82 |
|
|
83 |
/******************************************************/
|
|
84 |
/* Extensions to the base standard as defined in */
|
|
85 |
/* "Safety Software Technical Specification, */
|
|
86 |
/* Part 1: Concepts and Function Blocks, */
|
|
87 |
/* Version 1.0 – Official Release" */
|
|
88 |
/* by PLCopen - Technical Committee 5 - 2006-01-31 */
|
|
89 |
/******************************************************/
|
|
90 |
void *visit(safebool_type_name_c *symbol);
|
|
91 |
|
|
92 |
/********************************/
|
|
93 |
/* B 1.3.3 - Derived data types */
|
|
94 |
/********************************/
|
|
95 |
/* simple_type_name ':' simple_spec_init */
|
|
96 |
void *visit(simple_type_declaration_c *symbol);
|
|
97 |
/* simple_specification ASSIGN constant */
|
|
98 |
void *visit(simple_spec_init_c *symbol);
|
|
99 |
/* subrange_type_name ':' subrange_spec_init */
|
|
100 |
void *visit(subrange_type_declaration_c *symbol);
|
|
101 |
/* subrange_specification ASSIGN signed_integer */
|
|
102 |
void *visit(subrange_spec_init_c *symbol);
|
|
103 |
/* integer_type_name '(' subrange')' */
|
|
104 |
void *visit(subrange_specification_c *symbol);
|
|
105 |
/* signed_integer DOTDOT signed_integer */
|
|
106 |
void *visit(subrange_c *symbol);
|
|
107 |
|
|
108 |
/* enumerated_type_name ':' enumerated_spec_init */
|
|
109 |
void *visit(enumerated_type_declaration_c *symbol);
|
|
110 |
/* enumerated_specification ASSIGN enumerated_value */
|
|
111 |
void *visit(enumerated_spec_init_c *symbol);
|
|
112 |
/* helper symbol for enumerated_specification->enumerated_spec_init */
|
|
113 |
/* enumerated_value_list ',' enumerated_value */
|
|
114 |
void *visit(enumerated_value_list_c *symbol);
|
|
115 |
/* enumerated_type_name '#' identifier */
|
|
116 |
// SYM_REF2(enumerated_value_c, type, value)
|
|
117 |
void *visit(enumerated_value_c *symbol);
|
|
118 |
/* identifier ':' array_spec_init */
|
|
119 |
void *visit(array_type_declaration_c *symbol);
|
|
120 |
/* array_specification [ASSIGN array_initialization} */
|
|
121 |
/* array_initialization may be NULL ! */
|
|
122 |
void *visit(array_spec_init_c *symbol);
|
|
123 |
/* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */
|
|
124 |
void *visit(array_specification_c *symbol);
|
|
125 |
/* helper symbol for array_specification */
|
|
126 |
/* array_subrange_list ',' subrange */
|
|
127 |
void *visit(array_subrange_list_c *symbol);
|
|
128 |
/* array_initialization: '[' array_initial_elements_list ']' */
|
|
129 |
/* helper symbol for array_initialization */
|
|
130 |
/* array_initial_elements_list ',' array_initial_elements */
|
|
131 |
void *visit(array_initial_elements_list_c *symbol);
|
|
132 |
/* integer '(' [array_initial_element] ')' */
|
|
133 |
/* array_initial_element may be NULL ! */
|
|
134 |
void *visit(array_initial_elements_c *symbol);
|
|
135 |
/* structure_type_name ':' structure_specification */
|
|
136 |
/* NOTE: structure_specification will point to either a
|
|
137 |
* initialized_structure_c
|
|
138 |
* OR A
|
|
139 |
* structure_element_declaration_list_c
|
|
140 |
*/
|
|
141 |
void *visit(structure_type_declaration_c *symbol);
|
|
142 |
/* structure_type_name ASSIGN structure_initialization */
|
|
143 |
/* structure_initialization may be NULL ! */
|
|
144 |
void *visit(initialized_structure_c *symbol);
|
|
145 |
/* helper symbol for structure_declaration */
|
|
146 |
/* structure_declaration: STRUCT structure_element_declaration_list END_STRUCT */
|
|
147 |
/* structure_element_declaration_list structure_element_declaration ';' */
|
|
148 |
void *visit(structure_element_declaration_list_c *symbol);
|
|
149 |
/* structure_element_name ':' *_spec_init */
|
|
150 |
void *visit(structure_element_declaration_c *symbol);
|
|
151 |
/* helper symbol for structure_initialization */
|
|
152 |
/* structure_initialization: '(' structure_element_initialization_list ')' */
|
|
153 |
/* structure_element_initialization_list ',' structure_element_initialization */
|
|
154 |
void *visit(structure_element_initialization_list_c *symbol);
|
|
155 |
/* structure_element_name ASSIGN value */
|
|
156 |
void *visit(structure_element_initialization_c *symbol);
|
|
157 |
/* string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */
|
|
158 |
/*
|
|
159 |
SYM_REF4(string_type_declaration_c, string_type_name,
|
|
160 |
elementary_string_type_name,
|
|
161 |
string_type_declaration_size,
|
|
162 |
string_type_declaration_init) // may be == NULL!
|
|
163 |
*/
|
|
164 |
void *visit(string_type_declaration_c *symbol);
|
|
165 |
}; // search_base_type_c
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|