author | Mario de Sousa <msousa@fe.up.pt> |
Fri, 19 Aug 2011 21:53:11 +0100 | |
changeset 357 | 8a6a69dd23ce |
parent 350 | 2c3c4dc34979 |
child 596 | 4efb11e44065 |
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:
181
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:
181
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:
181
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:
181
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:
181
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:
181
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:
181
diff
changeset
|
11 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
181
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:
181
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:
181
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:
181
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:
181
diff
changeset
|
16 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
181
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:
181
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:
181
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:
181
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 |
* Seperation of type specification and default value constructs |
|
35 |
* (for e.g. simple_spec_init_c), into a type specificiation part, |
|
36 |
* and a default value part. |
|
37 |
*/ |
|
38 |
||
39 |
#include "spec_init_separator.hh" |
|
40 |
||
41 |
//#define DEBUG |
|
42 |
#ifdef DEBUG |
|
43 |
#define TRACE(classname) printf("\n____%s____\n",classname); |
|
44 |
#else |
|
45 |
#define TRACE(classname) |
|
46 |
#endif |
|
47 |
||
48 |
#define ERROR error_exit(__FILE__,__LINE__) |
|
49 |
/* function defined in main.cc */ |
|
50 |
extern void error_exit(const char *file_name, int line_no); |
|
51 |
||
52 |
||
53 |
spec_init_sperator_c *spec_init_sperator_c::get_class_instance(void) { |
|
54 |
if (NULL == class_instance) |
|
55 |
class_instance = new spec_init_sperator_c(); |
|
56 |
||
57 |
if (NULL == class_instance) |
|
58 |
ERROR; |
|
59 |
||
60 |
return class_instance; |
|
61 |
} |
|
62 |
||
63 |
/* the only two public functions... */ |
|
64 |
symbol_c *spec_init_sperator_c::get_spec(symbol_c *spec_init) { |
|
65 |
search_what = search_spec; |
|
66 |
return (symbol_c *)spec_init->accept(*get_class_instance()); |
|
67 |
} |
|
68 |
||
69 |
symbol_c *spec_init_sperator_c::get_init(symbol_c *spec_init) { |
|
70 |
search_what = search_init; |
|
71 |
return (symbol_c *)spec_init->accept(*get_class_instance()); |
|
72 |
} |
|
73 |
||
74 |
/*******************************************/ |
|
75 |
/* B 1.1 - Letters, digits and identifiers */ |
|
76 |
/*******************************************/ |
|
77 |
// SYM_TOKEN(identifier_c) |
|
78 |
void *spec_init_sperator_c::visit(identifier_c *symbol) { |
|
79 |
TRACE("spec_init_sperator_c::identifier_c"); |
|
80 |
switch (search_what) { |
|
81 |
/* if we ever get called sith a simple identifier_c, then it must be a previously declared type... */ |
|
82 |
case search_spec: return symbol; |
|
83 |
case search_init: return NULL; |
|
84 |
} |
|
85 |
ERROR; /* should never occur */ |
|
86 |
return NULL; |
|
87 |
} |
|
88 |
||
89 |
||
90 |
/********************************/ |
|
91 |
/* B 1.3.3 - Derived data types */ |
|
92 |
/********************************/ |
|
93 |
||
94 |
/* simple_specification ASSIGN constant */ |
|
95 |
void *spec_init_sperator_c::visit(simple_spec_init_c *symbol) { |
|
96 |
TRACE("spec_init_sperator_c::simple_spec_init_c"); |
|
97 |
switch (search_what) { |
|
98 |
case search_spec: return symbol->simple_specification; |
|
99 |
case search_init: return symbol->constant; |
|
100 |
} |
|
101 |
ERROR; /* should never occur */ |
|
102 |
return NULL; |
|
103 |
} |
|
104 |
||
105 |
/* subrange_specification ASSIGN signed_integer */ |
|
106 |
void *spec_init_sperator_c::visit(subrange_spec_init_c *symbol) { |
|
107 |
TRACE("spec_init_sperator_c::subrange_spec_init_c"); |
|
108 |
switch (search_what) { |
|
109 |
case search_spec: return symbol->subrange_specification->accept(*this); |
|
110 |
case search_init: return symbol->signed_integer; |
|
111 |
} |
|
112 |
ERROR; /* should never occur */ |
|
113 |
return NULL; |
|
114 |
} |
|
115 |
||
116 |
/* integer_type_name '(' subrange')' */ |
|
117 |
void *spec_init_sperator_c::visit(subrange_specification_c *symbol) { |
|
118 |
TRACE("spec_init_sperator_c::subrange_specification_c"); |
|
119 |
switch (search_what) { |
|
120 |
case search_spec: return symbol->integer_type_name; |
|
121 |
case search_init: return NULL; /* should never occur */ |
|
122 |
} |
|
123 |
ERROR; /* should never occur */ |
|
124 |
return NULL; |
|
125 |
} |
|
126 |
||
127 |
/* array_specification [ASSIGN array_initialization} */ |
|
128 |
/* array_initialization may be NULL ! */ |
|
129 |
void *spec_init_sperator_c::visit(array_spec_init_c *symbol) { |
|
130 |
TRACE("spec_init_sperator_c::array_spec_init_c"); |
|
131 |
switch (search_what) { |
|
132 |
case search_spec: return symbol->array_specification; |
|
133 |
case search_init: return symbol->array_initialization; |
|
134 |
} |
|
135 |
return NULL; |
|
136 |
} |
|
137 |
||
138 |
/* enumerated_specification ASSIGN enumerated_value */ |
|
139 |
void *spec_init_sperator_c::visit(enumerated_spec_init_c *symbol) { |
|
140 |
TRACE("spec_init_sperator_c::enumerated_spec_init_c"); |
|
141 |
switch (search_what) { |
|
142 |
case search_spec: return symbol->enumerated_specification; |
|
143 |
case search_init: return symbol->enumerated_value; |
|
144 |
} |
|
145 |
ERROR; /* should never occur */ |
|
146 |
return NULL; |
|
147 |
} |
|
148 |
||
149 |
/* structure_type_name ASSIGN structure_initialization */ |
|
150 |
/* structure_initialization may be NULL ! */ |
|
151 |
//SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization) |
|
152 |
void *spec_init_sperator_c::visit(initialized_structure_c *symbol) { |
|
153 |
TRACE("spec_init_sperator_c::initialized_structure_c"); |
|
154 |
switch (search_what) { |
|
155 |
case search_spec: return symbol->structure_type_name; |
|
156 |
case search_init: return symbol->structure_initialization; |
|
157 |
} |
|
158 |
ERROR; /* should never occur */ |
|
159 |
return NULL; |
|
160 |
} |
|
161 |
||
162 |
||
163 |
/******************************************/ |
|
164 |
/* B 1.4.3 - Declaration & Initialisation */ |
|
165 |
/******************************************/ |
|
166 |
||
167 |
/* fb_name_list ':' function_block_type_name ASSIGN structure_initialization */ |
|
168 |
/* structure_initialization -> may be NULL ! */ |
|
169 |
void *spec_init_sperator_c::visit(fb_name_decl_c *symbol) { |
|
170 |
TRACE("spec_init_sperator_c::fb_name_decl_c"); |
|
171 |
switch (search_what) { |
|
172 |
case search_spec: return symbol->function_block_type_name; |
|
173 |
case search_init: return symbol->structure_initialization; |
|
174 |
} |
|
175 |
ERROR; /* should never occur */ |
|
176 |
return NULL; |
|
177 |
} |
|
178 |
||
350
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
179 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
180 |
/* STRING '[' integer ']' |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
181 |
* STRING ASSIGN single_byte_character_string |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
182 |
* STRING '[' integer ']' ASSIGN single_byte_character_string |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
183 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
184 |
void *spec_init_sperator_c::visit(single_byte_string_spec_c *symbol) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
185 |
TRACE("spec_init_sperator_c::single_byte_string_spec_c"); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
186 |
switch (search_what) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
187 |
case search_spec: return symbol->string_spec; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
188 |
case search_init: return symbol->single_byte_character_string; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
189 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
190 |
ERROR; /* should never occur */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
191 |
return NULL; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
192 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
193 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
194 |
/* WSTRING '[' integer ']' |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
195 |
* WSTRING ASSIGN double_byte_character_string |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
196 |
* WSTRING '[' integer ']' ASSIGN double_byte_character_string |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
197 |
*/ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
198 |
void *spec_init_sperator_c::visit(double_byte_string_spec_c *symbol) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
199 |
TRACE("spec_init_sperator_c::double_byte_string_spec_c"); |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
200 |
switch (search_what) { |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
201 |
case search_spec: return symbol->string_spec; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
202 |
case search_init: return symbol->double_byte_character_string; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
203 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
204 |
ERROR; /* should never occur */ |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
205 |
return NULL; |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
206 |
} |
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
207 |
|
2c3c4dc34979
Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents:
279
diff
changeset
|
208 |
|
181 | 209 |
spec_init_sperator_c *spec_init_sperator_c ::class_instance = NULL; |
210 |
spec_init_sperator_c::search_what_t spec_init_sperator_c::search_what; |