|
1 /* |
|
2 * matiec - a compiler for the programming languages defined in IEC 61131-3 |
|
3 * |
|
4 * Copyright (C) 2009-2012 Mario de Sousa (msousa@fe.up.pt) |
|
5 * Copyright (C) 2012 Manuele Conti (conti.ma@alice.it) |
|
6 * |
|
7 * This program is free software: you can redistribute it and/or modify |
|
8 * it under the terms of the GNU General Public License as published by |
|
9 * the Free Software Foundation, either version 3 of the License, or |
|
10 * (at your option) any later version. |
|
11 * |
|
12 * This program is distributed in the hope that it will be useful, |
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 * GNU General Public License for more details. |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License |
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
19 * |
|
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 #include "datatype_functions.hh" |
|
26 #include "../absyntax_utils/absyntax_utils.hh" |
|
27 #include <vector> |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 elementary_type_c *elementary_type_c::singleton = NULL; |
|
35 |
|
36 const char *elementary_type_c::to_string(symbol_c *symbol) { |
|
37 if (NULL == singleton) singleton = new elementary_type_c; |
|
38 if (NULL == singleton) ERROR; |
|
39 const char *res = (const char *)symbol->accept(*singleton); |
|
40 if (NULL == res) ERROR; |
|
41 return res; |
|
42 } |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 /* Macro that expand to subtypes */ |
|
49 /* copied from matiec/lib/create_standard_functions_txt.sh */ |
|
50 #define __ANY(DO) __ANY_DERIVED(DO) __ANY_ELEMENTARY(DO) |
|
51 #define __ANY_DERIVED(DO) |
|
52 #define __ANY_ELEMENTARY(DO) __ANY_MAGNITUDE(DO) __ANY_BIT(DO) __ANY_STRING(DO) __ANY_DATE(DO) |
|
53 #define __ANY_MAGNITUDE(DO) __ANY_NUM(DO) DO(time) |
|
54 #define __ANY_BIT(DO) __ANY_NBIT(DO) DO(bool) |
|
55 #define __ANY_NBIT(DO) DO(byte) DO(word) DO(dword) DO(lword) |
|
56 //#define __ANY_STRING(DO) DO(string) DO(wstring) |
|
57 #define __ANY_STRING(DO) DO(string) |
|
58 #define __ANY_DATE(DO) DO(date) DO(tod) DO(dt) |
|
59 #define __ANY_NUM(DO) __ANY_REAL(DO) __ANY_INT(DO) |
|
60 #define __ANY_REAL(DO) DO(real) DO(lreal) |
|
61 #define __ANY_INT(DO) __ANY_SINT(DO) __ANY_UINT(DO) |
|
62 #define __ANY_SINT(DO) DO(sint) DO(int) DO(dint) DO(lint) |
|
63 #define __ANY_UINT(DO) DO(usint) DO(uint) DO(udint) DO(ulint) |
|
64 |
|
65 #define __ANY_1(DO,P1) __ANY_DERIVED_1(DO,P1) __ANY_ELEMENTARY_1(DO,P1) |
|
66 #define __ANY_DERIVED_1(DO,P1) |
|
67 #define __ANY_ELEMENTARY_1(DO,P1) __ANY_MAGNITUDE_1(DO,P1) __ANY_BIT_1(DO,P1) __ANY_STRING_1(DO,P1) __ANY_DATE_1(DO,P1) |
|
68 #define __ANY_MAGNITUDE_1(DO,P1) __ANY_NUM_1(DO,P1) DO(time,P1) |
|
69 #define __ANY_BIT_1(DO,P1) __ANY_NBIT_1(DO,P1) DO(bool,P1) |
|
70 #define __ANY_NBIT_1(DO,P1) DO(byte,P1) DO(word,P1) DO(dword,P1) DO(lword,P1) |
|
71 // #define __ANY_STRING_1(DO,P1) DO(string,P1) DO(wstring,P1) |
|
72 #define __ANY_STRING_1(DO,P1) DO(string,P1) |
|
73 #define __ANY_DATE_1(DO,P1) DO(date,P1) DO(tod,P1) DO(dt,P1) |
|
74 #define __ANY_NUM_1(DO,P1) __ANY_REAL_1(DO,P1) __ANY_INT_1(DO,P1) |
|
75 #define __ANY_REAL_1(DO,P1) DO(real,P1) DO(lreal,P1) |
|
76 #define __ANY_INT_1(DO,P1) __ANY_SINT_1(DO,P1) __ANY_UINT_1(DO,P1) |
|
77 #define __ANY_SINT_1(DO,P1) DO(sint,P1) DO(int,P1) DO(dint,P1) DO(lint,P1) |
|
78 #define __ANY_UINT_1(DO,P1) DO(usint,P1) DO(uint,P1) DO(udint,P1) DO(ulint,P1) |
|
79 |
|
80 |
|
81 /**************************************************************/ |
|
82 /**************************************************************/ |
|
83 /**************************************************************/ |
|
84 /******* TABLE 24: Standard arithmetic functions *******/ |
|
85 /******* merged with *******/ |
|
86 /******* TABLE 30: Functions of time data types *******/ |
|
87 /**************************************************************/ |
|
88 /**************************************************************/ |
|
89 /**************************************************************/ |
|
90 |
|
91 /* NOTE: IEC 61131-3 v2 declares that using implicit operations ('+', '-', '*', '/') on ANYTIME data types is |
|
92 * valid, but deprecated, suposedly meaning that they will be removed in the following version of the standard. |
|
93 * However, the current draft version of IEC 61131-3 v3 still allows this use, and no longer declares these |
|
94 * implicit operations as deprecated. |
|
95 * Because of this, and although we are implementing v2 of the standard, we will no longer mark these |
|
96 * operations as deprecated. |
|
97 */ |
|
98 #define ANYTIME_OPER_DEPRECATION_STATUS widen_entry::ok |
|
99 //#define ANYTIME_OPER_DEPRECATION_STATUS widen_entry::deprecated |
|
100 |
|
101 |
|
102 const struct widen_entry widen_ADD_table[] = { |
|
103 #define __add(TYPE) \ |
|
104 { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
105 { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
106 { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
107 { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, widen_entry::ok }, |
|
108 __ANY_NUM(__add) |
|
109 #undef __add |
|
110 |
|
111 /*******************************************/ |
|
112 /*******************************************/ |
|
113 /*** Operations with TIME, DT and TOD... ***/ |
|
114 /*******************************************/ |
|
115 /*******************************************/ |
|
116 { &search_constant_type_c::time_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::time_type_name, widen_entry::ok }, |
|
117 { &search_constant_type_c::tod_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::tod_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
118 /* NOTE: the standard des not explicitly support the following semantics. However, since 'addition' is supposed to be commutative, we add it anyway... */ |
|
119 /* not currently supported by stage4, so it is best no tto add it for now... */ |
|
120 // { &search_constant_type_c::time_type_name, &search_constant_type_c::tod_type_name, &search_constant_type_c::tod_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
121 { &search_constant_type_c::dt_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::dt_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
122 /* NOTE: the standard des not explicitly support the following semantics. However, since 'addition' is supposed to be commutative, we add it anyway... */ |
|
123 /* not currently supported by stage4, so it is best no tto add it for now... */ |
|
124 // { &search_constant_type_c::time_type_name, &search_constant_type_c::dt_type_name, &search_constant_type_c::dt_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
125 |
|
126 /*******************************/ |
|
127 /* SAFE version on the left... */ |
|
128 /*******************************/ |
|
129 { &search_constant_type_c::safetime_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::time_type_name, widen_entry::ok }, |
|
130 { &search_constant_type_c::safetod_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::tod_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
131 /* NOTE: the standard des not explicitly support the following semantics. However, since 'addition' is supposed to be commutative, we add it anyway... */ |
|
132 /* not currently supported by stage4, so it is best no tto add it for now... */ |
|
133 // { &search_constant_type_c::safetime_type_name, &search_constant_type_c::tod_type_name, &search_constant_type_c::tod_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
134 { &search_constant_type_c::safedt_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::dt_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
135 /* NOTE: the standard des not explicitly support the following semantics. However, since 'addition' is supposed to be commutative, we add it anyway... */ |
|
136 /* not currently supported by stage4, so it is best no tto add it for now... */ |
|
137 // { &search_constant_type_c::safetime_type_name, &search_constant_type_c::dt_type_name, &search_constant_type_c::dt_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
138 |
|
139 /********************************/ |
|
140 /* SAFE version on the right... */ |
|
141 /********************************/ |
|
142 { &search_constant_type_c::time_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::time_type_name, widen_entry::ok }, |
|
143 { &search_constant_type_c::tod_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::tod_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
144 /* NOTE: the standard des not explicitly support the following semantics. However, since 'addition' is supposed to be commutative, we add it anyway... */ |
|
145 /* not currently supported by stage4, so it is best no tto add it for now... */ |
|
146 // { &search_constant_type_c::time_type_name, &search_constant_type_c::safetod_type_name, &search_constant_type_c::tod_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
147 { &search_constant_type_c::dt_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::dt_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
148 /* NOTE: the standard des not explicitly support the following semantics. However, since 'addition' is supposed to be commutative, we add it anyway... */ |
|
149 /* not currently supported by stage4, so it is best no tto add it for now... */ |
|
150 // { &search_constant_type_c::time_type_name, &search_constant_type_c::safedt_type_name, &search_constant_type_c::dt_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
151 |
|
152 /*************************************/ |
|
153 /* SAFE version on left and right... */ |
|
154 /*************************************/ |
|
155 { &search_constant_type_c::safetime_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::safetime_type_name, widen_entry::ok }, |
|
156 { &search_constant_type_c::safetod_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::safetod_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
157 /* NOTE: the standard des not explicitly support the following semantics. However, since 'addition' is supposed to be commutative, we add it anyway... */ |
|
158 /* not currently supported by stage4, so it is best no tto add it for now... */ |
|
159 // { &search_constant_type_c::safetime_type_name, &search_constant_type_c::safetod_type_name, &search_constant_type_c::safetod_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
160 { &search_constant_type_c::safedt_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::safedt_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
161 /* NOTE: the standard des not explicitly support the following semantics. However, since 'addition' is supposed to be commutative, we add it anyway... */ |
|
162 /* not currently supported by stage4, so it is best no tto add it for now... */ |
|
163 // { &search_constant_type_c::safetime_type_name, &search_constant_type_c::safedt_type_name, &search_constant_type_c::safedt_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
164 |
|
165 { NULL, NULL, NULL, widen_entry::ok }, |
|
166 }; |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 const struct widen_entry widen_SUB_table[] = { |
|
175 #define __sub(TYPE) \ |
|
176 { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
177 { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
178 { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
179 { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, widen_entry::ok }, |
|
180 __ANY_NUM(__sub) |
|
181 #undef __sub |
|
182 |
|
183 /*******************************************/ |
|
184 /*******************************************/ |
|
185 /*** Operations with TIME, DT and TOD... ***/ |
|
186 /*******************************************/ |
|
187 /*******************************************/ |
|
188 { &search_constant_type_c::time_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::time_type_name, widen_entry::ok }, |
|
189 { &search_constant_type_c::date_type_name, &search_constant_type_c::date_type_name, &search_constant_type_c::time_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
190 { &search_constant_type_c::tod_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::tod_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
191 { &search_constant_type_c::tod_type_name, &search_constant_type_c::tod_type_name, &search_constant_type_c::time_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
192 { &search_constant_type_c::dt_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::dt_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
193 { &search_constant_type_c::dt_type_name, &search_constant_type_c::dt_type_name, &search_constant_type_c::time_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
194 |
|
195 /*******************************/ |
|
196 /* SAFE version on the left... */ |
|
197 /*******************************/ |
|
198 { &search_constant_type_c::safetime_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::time_type_name, widen_entry::ok }, |
|
199 { &search_constant_type_c::safedate_type_name, &search_constant_type_c::date_type_name, &search_constant_type_c::time_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
200 { &search_constant_type_c::safetod_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::tod_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
201 { &search_constant_type_c::safetod_type_name, &search_constant_type_c::tod_type_name, &search_constant_type_c::time_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
202 { &search_constant_type_c::safedt_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::dt_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
203 { &search_constant_type_c::safedt_type_name, &search_constant_type_c::dt_type_name, &search_constant_type_c::time_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
204 |
|
205 /********************************/ |
|
206 /* SAFE version on the right... */ |
|
207 /********************************/ |
|
208 { &search_constant_type_c::time_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::time_type_name, widen_entry::ok }, |
|
209 { &search_constant_type_c::date_type_name, &search_constant_type_c::safedate_type_name, &search_constant_type_c::time_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
210 { &search_constant_type_c::tod_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::tod_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
211 { &search_constant_type_c::tod_type_name, &search_constant_type_c::safetod_type_name, &search_constant_type_c::time_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
212 { &search_constant_type_c::dt_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::dt_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
213 { &search_constant_type_c::dt_type_name, &search_constant_type_c::safedt_type_name, &search_constant_type_c::time_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
214 |
|
215 /*************************************/ |
|
216 /* SAFE version on left and right... */ |
|
217 /*************************************/ |
|
218 { &search_constant_type_c::safetime_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::safetime_type_name, widen_entry::ok }, |
|
219 { &search_constant_type_c::safedate_type_name, &search_constant_type_c::safedate_type_name, &search_constant_type_c::safetime_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
220 { &search_constant_type_c::safetod_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::safetod_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
221 { &search_constant_type_c::safetod_type_name, &search_constant_type_c::safetod_type_name, &search_constant_type_c::safetime_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
222 { &search_constant_type_c::safedt_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::safedt_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
223 { &search_constant_type_c::safedt_type_name, &search_constant_type_c::safedt_type_name, &search_constant_type_c::safetime_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
224 |
|
225 { NULL, NULL, NULL, widen_entry::ok }, |
|
226 }; |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 const struct widen_entry widen_MUL_table[] = { |
|
235 #define __mul(TYPE) \ |
|
236 { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
237 { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
238 { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
239 { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, widen_entry::ok }, |
|
240 __ANY_NUM(__mul) |
|
241 #undef __mul |
|
242 |
|
243 /*******************************************/ |
|
244 /*******************************************/ |
|
245 /*** Operations with TIME, DT and TOD... ***/ |
|
246 /*******************************************/ |
|
247 /*******************************************/ |
|
248 #define __multime(TYPE) \ |
|
249 { &search_constant_type_c::time_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::time_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, \ |
|
250 { &search_constant_type_c::safetime_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::time_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, \ |
|
251 { &search_constant_type_c::time_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::time_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, \ |
|
252 { &search_constant_type_c::safetime_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safetime_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, \ |
|
253 /* NOTE: the standard des not explicitly support the following semantics. However, since 'multiplication' is supposed to be commutative, we add it anyway... */ \ |
|
254 { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::time_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, \ |
|
255 { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::time_type_name, &search_constant_type_c::time_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, \ |
|
256 { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::time_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, \ |
|
257 { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safetime_type_name, &search_constant_type_c::safetime_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
258 __ANY_NUM(__multime) |
|
259 #undef __multime |
|
260 |
|
261 { NULL, NULL, NULL, widen_entry::ok }, |
|
262 }; |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 const struct widen_entry widen_DIV_table[] = { |
|
269 #define __div(TYPE) \ |
|
270 { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
271 { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
272 { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
273 { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, widen_entry::ok }, |
|
274 __ANY_NUM(__div) |
|
275 #undef __div |
|
276 |
|
277 /*******************************************/ |
|
278 /*******************************************/ |
|
279 /*** Operations with TIME, DT and TOD... ***/ |
|
280 /*******************************************/ |
|
281 /*******************************************/ |
|
282 #define __divtime(TYPE) \ |
|
283 { &search_constant_type_c::time_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::time_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, \ |
|
284 { &search_constant_type_c::safetime_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::time_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, \ |
|
285 { &search_constant_type_c::time_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::time_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, \ |
|
286 { &search_constant_type_c::safetime_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safetime_type_name, ANYTIME_OPER_DEPRECATION_STATUS }, |
|
287 __ANY_NUM(__divtime) |
|
288 #undef __divtime |
|
289 |
|
290 { NULL, NULL, NULL, widen_entry::ok }, |
|
291 }; |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 const struct widen_entry widen_MOD_table[] = { |
|
297 #define __mod(TYPE) \ |
|
298 { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
299 { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
300 { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
301 { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, widen_entry::ok }, |
|
302 __ANY_NUM(__mod) |
|
303 #undef __mod |
|
304 |
|
305 { NULL, NULL, NULL, widen_entry::ok }, |
|
306 }; |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 const struct widen_entry widen_EXPT_table[] = { |
|
312 #define __expt(IN2TYPE, IN1TYPE) \ |
|
313 { &search_constant_type_c::IN1TYPE##_type_name, &search_constant_type_c::IN2TYPE##_type_name, &search_constant_type_c::IN1TYPE##_type_name, widen_entry::ok }, \ |
|
314 { &search_constant_type_c::safe##IN1TYPE##_type_name, &search_constant_type_c::IN2TYPE##_type_name, &search_constant_type_c::IN1TYPE##_type_name, widen_entry::ok }, \ |
|
315 { &search_constant_type_c::IN1TYPE##_type_name, &search_constant_type_c::safe##IN2TYPE##_type_name, &search_constant_type_c::IN1TYPE##_type_name, widen_entry::ok }, \ |
|
316 { &search_constant_type_c::safe##IN1TYPE##_type_name, &search_constant_type_c::safe##IN2TYPE##_type_name, &search_constant_type_c::safe##IN1TYPE##_type_name, widen_entry::ok }, |
|
317 #define __IN2_anynum_(IN1_TYPENAME) __ANY_NUM_1(__expt,IN1_TYPENAME) |
|
318 __ANY_REAL(__IN2_anynum_) |
|
319 #undef __expt |
|
320 #undef __IN2_anynum_ |
|
321 { NULL, NULL, NULL, widen_entry::ok }, |
|
322 }; |
|
323 |
|
324 |
|
325 |
|
326 /**************************************************************/ |
|
327 /**************************************************************/ |
|
328 /**************************************************************/ |
|
329 /******* *******/ |
|
330 /******* TABLE 26: Standard bitwise Boolean functions *******/ |
|
331 /******* *******/ |
|
332 /**************************************************************/ |
|
333 /**************************************************************/ |
|
334 /**************************************************************/ |
|
335 /* table used by AND and ANDN operators, and and_expression */ |
|
336 const struct widen_entry widen_AND_table[] = { |
|
337 #define __and(TYPE) \ |
|
338 { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
339 { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
340 { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
341 { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, widen_entry::ok }, |
|
342 __ANY_BIT(__and) |
|
343 #undef __and |
|
344 |
|
345 { NULL, NULL, NULL, widen_entry::ok }, |
|
346 }; |
|
347 |
|
348 /* table used by OR and ORN operators, and or_expression */ |
|
349 const struct widen_entry widen_OR_table[] = { |
|
350 #define __or(TYPE) \ |
|
351 { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
352 { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
353 { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
354 { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, widen_entry::ok }, |
|
355 __ANY_BIT(__or) |
|
356 #undef __or |
|
357 |
|
358 { NULL, NULL, NULL, widen_entry::ok }, |
|
359 }; |
|
360 |
|
361 |
|
362 /* table used by XOR and XORN operators, and xor_expression */ |
|
363 const struct widen_entry widen_XOR_table[] = { |
|
364 #define __xor(TYPE) \ |
|
365 { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
366 { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
367 { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, widen_entry::ok }, \ |
|
368 { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, widen_entry::ok }, |
|
369 __ANY_BIT(__xor) |
|
370 #undef __xor |
|
371 |
|
372 { NULL, NULL, NULL, widen_entry::ok }, |
|
373 }; |
|
374 |
|
375 /**************************************************************/ |
|
376 /**************************************************************/ |
|
377 /**************************************************************/ |
|
378 /******* *******/ |
|
379 /******* TABLE 28: Standard comparison functions *******/ |
|
380 /******* *******/ |
|
381 /**************************************************************/ |
|
382 /**************************************************************/ |
|
383 /**************************************************************/ |
|
384 /* table used by GT, GE, EQ, LE, LT, and NE operators, and equivalent ST expressions. */ |
|
385 const struct widen_entry widen_CMP_table[] = { |
|
386 #define __cmp(TYPE) \ |
|
387 { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::bool_type_name, widen_entry::ok }, \ |
|
388 { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::bool_type_name, widen_entry::ok }, \ |
|
389 { &search_constant_type_c::TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::bool_type_name, widen_entry::ok }, \ |
|
390 { &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safe##TYPE##_type_name, &search_constant_type_c::safebool_type_name, widen_entry::ok }, |
|
391 __ANY_ELEMENTARY(__cmp) |
|
392 #undef __cmp |
|
393 |
|
394 { NULL, NULL, NULL, widen_entry::ok }, |
|
395 }; |
|
396 |
|
397 |
|
398 /* Search for a datatype inside a candidate_datatypes list. |
|
399 * Returns: position of datatype in the list, or -1 if not found. |
|
400 */ |
|
401 int search_in_candidate_datatype_list(symbol_c *datatype, const std::vector <symbol_c *> &candidate_datatypes) { |
|
402 if (NULL == datatype) |
|
403 return -1; |
|
404 |
|
405 for(unsigned int i = 0; i < candidate_datatypes.size(); i++) |
|
406 if (is_type_equal(datatype, candidate_datatypes[i])) |
|
407 return i; |
|
408 /* Not found ! */ |
|
409 return -1; |
|
410 } |
|
411 |
|
412 /* Remove a datatype inside a candidate_datatypes list. |
|
413 * Returns: If successful it returns true, false otherwise. |
|
414 */ |
|
415 bool remove_from_candidate_datatype_list(symbol_c *datatype, std::vector <symbol_c *> &candidate_datatypes) { |
|
416 int pos = search_in_candidate_datatype_list(datatype, candidate_datatypes); |
|
417 if (pos < 0) |
|
418 return false; |
|
419 |
|
420 candidate_datatypes.erase(candidate_datatypes.begin() + pos); |
|
421 return true; |
|
422 } |
|
423 |
|
424 |
|
425 |
|
426 /* Intersect two candidate_datatype_lists. |
|
427 * Remove from list1 (origin, dest.) all elements that are not found in list2 (with). |
|
428 * In essence, list1 will contain the result of the intersection of list1 with list2. |
|
429 * In other words, modify list1 so it only contains the elelements that are simultaneously in list1 and list2! |
|
430 */ |
|
431 void intersect_candidate_datatype_list(symbol_c *list1 /*origin, dest.*/, symbol_c *list2 /*with*/) { |
|
432 if ((NULL == list1) || (NULL == list2)) |
|
433 /* In principle, we should never call it with NULL values. Best to abort the compiler just in case! */ |
|
434 return; |
|
435 |
|
436 for(std::vector<symbol_c *>::iterator i = list1->candidate_datatypes.begin(); i < list1->candidate_datatypes.end(); ) { |
|
437 /* Note that we do _not_ increment i in the for() loop! |
|
438 * When we erase an element from position i, a new element will take it's place, that must also be tested! |
|
439 */ |
|
440 if (search_in_candidate_datatype_list(*i, list2->candidate_datatypes) < 0) |
|
441 /* remove this element! This will change the value of candidate_datatypes.size() */ |
|
442 list1->candidate_datatypes.erase(i); |
|
443 else i++; |
|
444 } |
|
445 } |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 /* intersect the candidate_datatype lists of all prev_il_intructions, and set the local candidate_datatype list to the result! */ |
|
451 void intersect_prev_candidate_datatype_lists(il_instruction_c *symbol) { |
|
452 if (symbol->prev_il_instruction.empty()) |
|
453 return; |
|
454 |
|
455 symbol->candidate_datatypes = symbol->prev_il_instruction[0]->candidate_datatypes; |
|
456 for (unsigned int i = 1; i < symbol->prev_il_instruction.size(); i++) { |
|
457 intersect_candidate_datatype_list(symbol /*origin, dest.*/, symbol->prev_il_instruction[i] /*with*/); |
|
458 } |
|
459 } |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 /* A helper function... */ |
|
465 bool is_ANY_ELEMENTARY_type(symbol_c *type_symbol) { |
|
466 if (type_symbol == NULL) {return false;} |
|
467 return is_ANY_MAGNITUDE_type(type_symbol) |
|
468 || is_ANY_BIT_type (type_symbol) |
|
469 || is_ANY_STRING_type (type_symbol) |
|
470 || is_ANY_DATE_type (type_symbol); |
|
471 } |
|
472 |
|
473 /* A helper function... */ |
|
474 bool is_ANY_SAFEELEMENTARY_type(symbol_c *type_symbol) { |
|
475 if (type_symbol == NULL) {return false;} |
|
476 return is_ANY_SAFEMAGNITUDE_type(type_symbol) |
|
477 || is_ANY_SAFEBIT_type (type_symbol) |
|
478 || is_ANY_SAFESTRING_type (type_symbol) |
|
479 || is_ANY_SAFEDATE_type (type_symbol); |
|
480 } |
|
481 |
|
482 /* A helper function... */ |
|
483 bool is_ANY_ELEMENTARY_compatible(symbol_c *type_symbol) { |
|
484 if (type_symbol == NULL) {return false;} |
|
485 /* NOTE: doing |
|
486 * return is_ANY_SAFEELEMENTARY_type() || is_ANY_ELEMENTARY_type() |
|
487 * is incorrect, as the literals would never be considered compatible... |
|
488 */ |
|
489 return is_ANY_MAGNITUDE_compatible(type_symbol) |
|
490 || is_ANY_BIT_compatible (type_symbol) |
|
491 || is_ANY_STRING_compatible (type_symbol) |
|
492 || is_ANY_DATE_compatible (type_symbol); |
|
493 } |
|
494 |
|
495 |
|
496 /* A helper function... */ |
|
497 bool is_ANY_MAGNITUDE_type(symbol_c *type_symbol) { |
|
498 if (type_symbol == NULL) {return false;} |
|
499 if (typeid(*type_symbol) == typeid(time_type_name_c)) {return true;} |
|
500 return is_ANY_NUM_type(type_symbol); |
|
501 } |
|
502 |
|
503 /* A helper function... */ |
|
504 bool is_ANY_signed_MAGNITUDE_type(symbol_c *type_symbol) { |
|
505 if (type_symbol == NULL) {return false;} |
|
506 if (typeid(*type_symbol) == typeid(time_type_name_c)) {return true;} |
|
507 return is_ANY_signed_NUM_type(type_symbol); |
|
508 } |
|
509 |
|
510 /* A helper function... */ |
|
511 bool is_ANY_SAFEMAGNITUDE_type(symbol_c *type_symbol) { |
|
512 if (type_symbol == NULL) {return false;} |
|
513 if (typeid(*type_symbol) == typeid(safetime_type_name_c)) {return true;} |
|
514 return is_ANY_SAFENUM_type(type_symbol); |
|
515 } |
|
516 |
|
517 /* A helper function... */ |
|
518 bool is_ANY_signed_SAFEMAGNITUDE_type(symbol_c *type_symbol) { |
|
519 if (type_symbol == NULL) {return false;} |
|
520 if (typeid(*type_symbol) == typeid(safetime_type_name_c)) {return true;} |
|
521 return is_ANY_signed_SAFENUM_type(type_symbol); |
|
522 } |
|
523 |
|
524 /* A helper function... */ |
|
525 bool is_ANY_MAGNITUDE_compatible(symbol_c *type_symbol) { |
|
526 if (type_symbol == NULL) {return false;} |
|
527 if (is_ANY_MAGNITUDE_type (type_symbol)) {return true;} |
|
528 if (is_ANY_SAFEMAGNITUDE_type(type_symbol)) {return true;} |
|
529 return is_ANY_NUM_compatible(type_symbol); |
|
530 } |
|
531 |
|
532 /* A helper function... */ |
|
533 bool is_ANY_signed_MAGNITUDE_compatible(symbol_c *type_symbol) { |
|
534 if (type_symbol == NULL) {return false;} |
|
535 if (is_ANY_signed_MAGNITUDE_type (type_symbol)) {return true;} |
|
536 if (is_ANY_signed_SAFEMAGNITUDE_type(type_symbol)) {return true;} |
|
537 return is_ANY_signed_NUM_compatible(type_symbol); |
|
538 } |
|
539 |
|
540 /* A helper function... */ |
|
541 bool is_ANY_NUM_type(symbol_c *type_symbol) { |
|
542 if (type_symbol == NULL) {return false;} |
|
543 if (is_ANY_REAL_type(type_symbol)) {return true;} |
|
544 if (is_ANY_INT_type(type_symbol)) {return true;} |
|
545 return false; |
|
546 } |
|
547 |
|
548 /* A helper function... */ |
|
549 bool is_ANY_signed_NUM_type(symbol_c *type_symbol) { |
|
550 if (type_symbol == NULL) {return false;} |
|
551 if (is_ANY_REAL_type(type_symbol)) {return true;} |
|
552 if (is_ANY_signed_INT_type(type_symbol)) {return true;} |
|
553 return false; |
|
554 } |
|
555 |
|
556 /* A helper function... */ |
|
557 bool is_ANY_SAFENUM_type(symbol_c *type_symbol) { |
|
558 if (type_symbol == NULL) {return false;} |
|
559 return is_ANY_SAFEREAL_type(type_symbol) |
|
560 || is_ANY_SAFEINT_type (type_symbol); |
|
561 } |
|
562 |
|
563 /* A helper function... */ |
|
564 bool is_ANY_signed_SAFENUM_type(symbol_c *type_symbol) { |
|
565 if (type_symbol == NULL) {return false;} |
|
566 return is_ANY_SAFEREAL_type(type_symbol) |
|
567 || is_ANY_signed_SAFEINT_type (type_symbol); |
|
568 } |
|
569 |
|
570 /* A helper function... */ |
|
571 bool is_ANY_NUM_compatible(symbol_c *type_symbol) { |
|
572 if (type_symbol == NULL) {return false;} |
|
573 if (is_ANY_REAL_compatible(type_symbol)) {return true;} |
|
574 if (is_ANY_INT_compatible(type_symbol)) {return true;} |
|
575 return false; |
|
576 } |
|
577 |
|
578 /* A helper function... */ |
|
579 bool is_ANY_signed_NUM_compatible(symbol_c *type_symbol) { |
|
580 if (type_symbol == NULL) {return false;} |
|
581 if (is_ANY_REAL_compatible(type_symbol)) {return true;} |
|
582 if (is_ANY_signed_INT_compatible(type_symbol)) {return true;} |
|
583 return false; |
|
584 } |
|
585 |
|
586 /* A helper function... */ |
|
587 bool is_ANY_DATE_type(symbol_c *type_symbol) { |
|
588 if (type_symbol == NULL) {return false;} |
|
589 if (typeid(*type_symbol) == typeid(date_type_name_c)) {return true;} |
|
590 if (typeid(*type_symbol) == typeid(tod_type_name_c)) {return true;} |
|
591 if (typeid(*type_symbol) == typeid(dt_type_name_c)) {return true;} |
|
592 return false; |
|
593 } |
|
594 |
|
595 /* A helper function... */ |
|
596 bool is_ANY_SAFEDATE_type(symbol_c *type_symbol) { |
|
597 if (type_symbol == NULL) {return false;} |
|
598 if (typeid(*type_symbol) == typeid(safedate_type_name_c)) {return true;} |
|
599 if (typeid(*type_symbol) == typeid(safetod_type_name_c)) {return true;} |
|
600 if (typeid(*type_symbol) == typeid(safedt_type_name_c)) {return true;} |
|
601 return false; |
|
602 } |
|
603 |
|
604 /* A helper function... */ |
|
605 bool is_ANY_DATE_compatible(symbol_c *type_symbol) { |
|
606 if (type_symbol == NULL) {return false;} |
|
607 if (is_ANY_DATE_type (type_symbol)) {return true;} |
|
608 if (is_ANY_SAFEDATE_type(type_symbol)) {return true;} |
|
609 return false; |
|
610 } |
|
611 |
|
612 /* A helper function... */ |
|
613 bool is_ANY_STRING_type(symbol_c *type_symbol) { |
|
614 if (type_symbol == NULL) {return false;} |
|
615 if (typeid(*type_symbol) == typeid(string_type_name_c)) {return true;} |
|
616 if (typeid(*type_symbol) == typeid(wstring_type_name_c)) {return true;} |
|
617 return false; |
|
618 } |
|
619 |
|
620 /* A helper function... */ |
|
621 bool is_ANY_SAFESTRING_type(symbol_c *type_symbol) { |
|
622 if (type_symbol == NULL) {return false;} |
|
623 if (typeid(*type_symbol) == typeid(safestring_type_name_c)) {return true;} |
|
624 if (typeid(*type_symbol) == typeid(safewstring_type_name_c)) {return true;} |
|
625 return false; |
|
626 } |
|
627 |
|
628 /* A helper function... */ |
|
629 bool is_ANY_STRING_compatible(symbol_c *type_symbol) { |
|
630 if (type_symbol == NULL) {return false;} |
|
631 if (is_ANY_STRING_type (type_symbol)) {return true;} |
|
632 if (is_ANY_SAFESTRING_type(type_symbol)) {return true;} |
|
633 return false; |
|
634 } |
|
635 |
|
636 /* A helper function... */ |
|
637 bool is_ANY_INT_type(symbol_c *type_symbol) { |
|
638 if (type_symbol == NULL) {return false;} |
|
639 if (typeid(*type_symbol) == typeid(sint_type_name_c)) {return true;} |
|
640 if (typeid(*type_symbol) == typeid(int_type_name_c)) {return true;} |
|
641 if (typeid(*type_symbol) == typeid(dint_type_name_c)) {return true;} |
|
642 if (typeid(*type_symbol) == typeid(lint_type_name_c)) {return true;} |
|
643 if (typeid(*type_symbol) == typeid(usint_type_name_c)) {return true;} |
|
644 if (typeid(*type_symbol) == typeid(uint_type_name_c)) {return true;} |
|
645 if (typeid(*type_symbol) == typeid(udint_type_name_c)) {return true;} |
|
646 if (typeid(*type_symbol) == typeid(ulint_type_name_c)) {return true;} |
|
647 return false; |
|
648 } |
|
649 |
|
650 /* A helper function... */ |
|
651 bool is_ANY_signed_INT_type(symbol_c *type_symbol) { |
|
652 if (type_symbol == NULL) {return false;} |
|
653 if (typeid(*type_symbol) == typeid(sint_type_name_c)) {return true;} |
|
654 if (typeid(*type_symbol) == typeid(int_type_name_c)) {return true;} |
|
655 if (typeid(*type_symbol) == typeid(dint_type_name_c)) {return true;} |
|
656 if (typeid(*type_symbol) == typeid(lint_type_name_c)) {return true;} |
|
657 return false; |
|
658 } |
|
659 |
|
660 /* A helper function... */ |
|
661 bool is_ANY_signed_SAFEINT_type(symbol_c *type_symbol) { |
|
662 if (type_symbol == NULL) {return false;} |
|
663 if (typeid(*type_symbol) == typeid(safesint_type_name_c)) {return true;} |
|
664 if (typeid(*type_symbol) == typeid(safeint_type_name_c)) {return true;} |
|
665 if (typeid(*type_symbol) == typeid(safedint_type_name_c)) {return true;} |
|
666 if (typeid(*type_symbol) == typeid(safelint_type_name_c)) {return true;} |
|
667 return false; |
|
668 } |
|
669 |
|
670 /* A helper function... */ |
|
671 bool is_ANY_SAFEINT_type(symbol_c *type_symbol) { |
|
672 if (type_symbol == NULL) {return false;} |
|
673 if (typeid(*type_symbol) == typeid(safesint_type_name_c)) {return true;} |
|
674 if (typeid(*type_symbol) == typeid(safeint_type_name_c)) {return true;} |
|
675 if (typeid(*type_symbol) == typeid(safedint_type_name_c)) {return true;} |
|
676 if (typeid(*type_symbol) == typeid(safelint_type_name_c)) {return true;} |
|
677 if (typeid(*type_symbol) == typeid(safeusint_type_name_c)) {return true;} |
|
678 if (typeid(*type_symbol) == typeid(safeuint_type_name_c)) {return true;} |
|
679 if (typeid(*type_symbol) == typeid(safeudint_type_name_c)) {return true;} |
|
680 if (typeid(*type_symbol) == typeid(safeulint_type_name_c)) {return true;} |
|
681 return false; |
|
682 } |
|
683 |
|
684 /* A helper function... */ |
|
685 bool is_ANY_signed_INT_compatible(symbol_c *type_symbol) { |
|
686 if (type_symbol == NULL) {return false;} |
|
687 if (is_ANY_signed_INT_type (type_symbol)) {return true;} |
|
688 if (is_ANY_signed_SAFEINT_type(type_symbol)) {return true;} |
|
689 return false; |
|
690 } |
|
691 |
|
692 /* A helper function... */ |
|
693 bool is_ANY_INT_compatible(symbol_c *type_symbol) { |
|
694 if (type_symbol == NULL) {return false;} |
|
695 if (is_ANY_INT_type (type_symbol)) {return true;} |
|
696 if (is_ANY_SAFEINT_type(type_symbol)) {return true;} |
|
697 return false; |
|
698 } |
|
699 |
|
700 /* A helper function... */ |
|
701 bool is_ANY_REAL_type(symbol_c *type_symbol) { |
|
702 if (type_symbol == NULL) {return false;} |
|
703 if (typeid(*type_symbol) == typeid(real_type_name_c)) {return true;} |
|
704 if (typeid(*type_symbol) == typeid(lreal_type_name_c)) {return true;} |
|
705 return false; |
|
706 } |
|
707 |
|
708 /* A helper function... */ |
|
709 bool is_ANY_SAFEREAL_type(symbol_c *type_symbol) { |
|
710 if (type_symbol == NULL) {return false;} |
|
711 if (typeid(*type_symbol) == typeid(safereal_type_name_c)) {return true;} |
|
712 if (typeid(*type_symbol) == typeid(safelreal_type_name_c)) {return true;} |
|
713 return false; |
|
714 } |
|
715 |
|
716 /* A helper function... */ |
|
717 bool is_ANY_REAL_compatible(symbol_c *type_symbol) { |
|
718 if (type_symbol == NULL) {return false;} |
|
719 if (is_ANY_REAL_type (type_symbol)) {return true;} |
|
720 if (is_ANY_SAFEREAL_type(type_symbol)) {return true;} |
|
721 return false; |
|
722 } |
|
723 |
|
724 /* A helper function... */ |
|
725 bool is_ANY_BIT_type(symbol_c *type_symbol) { |
|
726 if (type_symbol == NULL) {return false;} |
|
727 if (typeid(*type_symbol) == typeid(bool_type_name_c)) {return true;} |
|
728 if (typeid(*type_symbol) == typeid(byte_type_name_c)) {return true;} |
|
729 if (typeid(*type_symbol) == typeid(word_type_name_c)) {return true;} |
|
730 if (typeid(*type_symbol) == typeid(dword_type_name_c)) {return true;} |
|
731 if (typeid(*type_symbol) == typeid(lword_type_name_c)) {return true;} |
|
732 return false; |
|
733 } |
|
734 |
|
735 /* A helper function... */ |
|
736 bool is_ANY_SAFEBIT_type(symbol_c *type_symbol) { |
|
737 if (type_symbol == NULL) {return false;} |
|
738 if (typeid(*type_symbol) == typeid(safebool_type_name_c)) {return true;} |
|
739 if (typeid(*type_symbol) == typeid(safebyte_type_name_c)) {return true;} |
|
740 if (typeid(*type_symbol) == typeid(safeword_type_name_c)) {return true;} |
|
741 if (typeid(*type_symbol) == typeid(safedword_type_name_c)) {return true;} |
|
742 if (typeid(*type_symbol) == typeid(safelword_type_name_c)) {return true;} |
|
743 return false; |
|
744 } |
|
745 |
|
746 /* A helper function... */ |
|
747 bool is_ANY_BIT_compatible(symbol_c *type_symbol) { |
|
748 if (type_symbol == NULL) {return false;} |
|
749 if (is_ANY_BIT_type (type_symbol)) {return true;} |
|
750 if (is_ANY_SAFEBIT_type(type_symbol)) {return true;} |
|
751 return false; |
|
752 } |
|
753 |
|
754 /* A helper function... */ |
|
755 bool is_BOOL_type(symbol_c *type_symbol) { |
|
756 if (type_symbol == NULL) {return false;} |
|
757 if (typeid(*type_symbol) == typeid(bool_type_name_c)) {return true;} |
|
758 return false; |
|
759 } |
|
760 |
|
761 /* A helper function... */ |
|
762 bool is_SAFEBOOL_type(symbol_c *type_symbol){ |
|
763 if (type_symbol == NULL) {return false;} |
|
764 if (typeid(*type_symbol) == typeid(safebool_type_name_c)) {return true;} |
|
765 return false; |
|
766 } |
|
767 |
|
768 /* A helper function... */ |
|
769 bool is_ANY_BOOL_compatible(symbol_c *type_symbol) { |
|
770 if (type_symbol == NULL) {return false;} |
|
771 if (is_BOOL_type (type_symbol)) {return true;} |
|
772 if (is_SAFEBOOL_type(type_symbol)) {return true;} |
|
773 return false; |
|
774 } |
|
775 |
|
776 |
|
777 |
|
778 |
|
779 |
|
780 bool is_type_equal(symbol_c *first_type, symbol_c *second_type) { |
|
781 if ((NULL == first_type) || (NULL == second_type)) |
|
782 return false; |
|
783 if (typeid(* first_type) == typeid(invalid_type_name_c)) |
|
784 return false; |
|
785 if (typeid(*second_type) == typeid(invalid_type_name_c)) |
|
786 return false; |
|
787 |
|
788 if (is_ANY_ELEMENTARY_type(first_type)) { |
|
789 if (typeid(*first_type) == typeid(*second_type)) |
|
790 return true; |
|
791 } else /* ANY_DERIVED */ |
|
792 return (first_type == second_type); |
|
793 |
|
794 return false; |
|
795 } |
|
796 |
|
797 |
|
798 |
|
799 bool is_type_valid(symbol_c *type) { |
|
800 if (NULL == type) |
|
801 return false; |
|
802 if (typeid(*type) == typeid(invalid_type_name_c)) |
|
803 return false; |
|
804 |
|
805 return true; |
|
806 } |