build administrativa
[m6w6/ext-psi] / src / calc / bool.h
1 /*******************************************************************************
2 Copyright (c) 2016, Michael Wallner <mike@php.net>.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 * Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
18 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *******************************************************************************/
25
26 #include <assert.h>
27
28 #include "token.h"
29 static inline token_t psi_calc_bool_or(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res)
30 {
31 switch (t1) {
32 case PSI_T_INT8:
33 if (v1->i8)
34 goto return_true;
35 break;
36 case PSI_T_UINT8:
37 if (v1->u8)
38 goto return_true;
39 break;
40 case PSI_T_INT16:
41 if (v1->i16)
42 goto return_true;
43 break;
44 case PSI_T_UINT16:
45 if (v1->u16)
46 goto return_true;
47 break;
48 case PSI_T_INT32:
49 if (v1->i32)
50 goto return_true;
51 break;
52 case PSI_T_UINT32:
53 if (v1->u32)
54 goto return_true;
55 break;
56 case PSI_T_INT64:
57 if (v1->i64)
58 goto return_true;
59 break;
60 case PSI_T_UINT64:
61 if (v1->u64)
62 goto return_true;
63 break;
64 #if HAVE_INT128
65 case PSI_T_INT128:
66 if (v1->i128)
67 goto return_true;
68 break;
69 #endif
70
71 #if HAVE_UINT128
72 case PSI_T_UINT128:
73 if (v1->u128)
74 goto return_true;
75 break;
76 #endif
77
78 case PSI_T_FLOAT:
79 if (v1->fval)
80 goto return_true;
81 break;
82 case PSI_T_DOUBLE:
83 if (v1->dval)
84 goto return_true;
85 break;
86 #if HAVE_LONG_DOUBLE
87 case PSI_T_LONG_DOUBLE:
88 if (v1->ldval)
89 goto return_true;
90 break;
91 #endif
92
93 default:
94 assert(0);
95 break;
96 }
97
98 switch (t2) {
99 case PSI_T_INT8:
100 if (v2->i8)
101 goto return_true;
102 break;
103 case PSI_T_UINT8:
104 if (v2->u8)
105 goto return_true;
106 break;
107 case PSI_T_INT16:
108 if (v2->i16)
109 goto return_true;
110 break;
111 case PSI_T_UINT16:
112 if (v2->u16)
113 goto return_true;
114 break;
115 case PSI_T_INT32:
116 if (v2->i32)
117 goto return_true;
118 break;
119 case PSI_T_UINT32:
120 if (v2->u32)
121 goto return_true;
122 break;
123 case PSI_T_INT64:
124 if (v2->i64)
125 goto return_true;
126 break;
127 case PSI_T_UINT64:
128 if (v2->u64)
129 goto return_true;
130 break;
131 #if HAVE_INT128
132 case PSI_T_INT128:
133 if (v2->i128)
134 goto return_true;
135 break;
136 #endif
137
138 #if HAVE_UINT128
139 case PSI_T_UINT128:
140 if (v2->u128)
141 goto return_true;
142 break;
143 #endif
144
145 case PSI_T_FLOAT:
146 if (v2->fval)
147 goto return_true;
148 break;
149 case PSI_T_DOUBLE:
150 if (v2->dval)
151 goto return_true;
152 break;
153 #if HAVE_LONG_DOUBLE
154 case PSI_T_LONG_DOUBLE:
155 if (v2->ldval)
156 goto return_true;
157 break;
158 #endif
159
160 default:
161 assert(0);
162 break;
163 }
164
165 res->u8 = 0;
166 return PSI_T_UINT8;
167
168 return_true:
169 res->u8 = 1;
170 return PSI_T_UINT8;
171 }
172
173 static inline token_t psi_calc_bool_and(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res)
174 {
175 switch (t1) {
176 case PSI_T_INT8:
177 if (!v1->i8)
178 goto return_false;
179 break;
180 case PSI_T_UINT8:
181 if (!v1->u8)
182 goto return_false;
183 break;
184 case PSI_T_INT16:
185 if (!v1->i16)
186 goto return_false;
187 break;
188 case PSI_T_UINT16:
189 if (!v1->u16)
190 goto return_false;
191 break;
192 case PSI_T_INT32:
193 if (!v1->i32)
194 goto return_false;
195 break;
196 case PSI_T_UINT32:
197 if (!v1->u32)
198 goto return_false;
199 break;
200 case PSI_T_INT64:
201 if (!v1->i64)
202 goto return_false;
203 break;
204 case PSI_T_UINT64:
205 if (!v1->u64)
206 goto return_false;
207 break;
208 #if HAVE_INT128
209 case PSI_T_INT128:
210 if (!v1->i128)
211 goto return_false;
212 break;
213 #endif
214
215 #if HAVE_UINT128
216 case PSI_T_UINT128:
217 if (!v1->u128)
218 goto return_false;
219 break;
220 #endif
221
222 case PSI_T_FLOAT:
223 if (!v1->fval)
224 goto return_false;
225 break;
226 case PSI_T_DOUBLE:
227 if (!v1->dval)
228 goto return_false;
229 break;
230 #if HAVE_LONG_DOUBLE
231 case PSI_T_LONG_DOUBLE:
232 if (!v1->ldval)
233 goto return_false;
234 break;
235 #endif
236
237 default:
238 assert(0);
239 break;
240 }
241
242 switch (t2) {
243 case PSI_T_INT8:
244 if (!v2->i8)
245 goto return_false;
246 break;
247 case PSI_T_UINT8:
248 if (!v2->u8)
249 goto return_false;
250 break;
251 case PSI_T_INT16:
252 if (!v2->i16)
253 goto return_false;
254 break;
255 case PSI_T_UINT16:
256 if (!v2->u16)
257 goto return_false;
258 break;
259 case PSI_T_INT32:
260 if (!v2->i32)
261 goto return_false;
262 break;
263 case PSI_T_UINT32:
264 if (!v2->u32)
265 goto return_false;
266 break;
267 case PSI_T_INT64:
268 if (!v2->i64)
269 goto return_false;
270 break;
271 case PSI_T_UINT64:
272 if (!v2->u64)
273 goto return_false;
274 break;
275 #if HAVE_INT128
276 case PSI_T_INT128:
277 if (!v2->i128)
278 goto return_false;
279 break;
280 #endif
281
282 #if HAVE_UINT128
283 case PSI_T_UINT128:
284 if (!v2->u128)
285 goto return_false;
286 break;
287 #endif
288
289 case PSI_T_FLOAT:
290 if (!v2->fval)
291 goto return_false;
292 break;
293 case PSI_T_DOUBLE:
294 if (!v2->dval)
295 goto return_false;
296 break;
297 #if HAVE_LONG_DOUBLE
298 case PSI_T_LONG_DOUBLE:
299 if (!v2->ldval)
300 goto return_false;
301 break;
302 #endif
303
304 default:
305 assert(0);
306 break;
307 }
308
309 res->u8 = 1;
310 return PSI_T_UINT8;
311
312 return_false:
313 res->u8 = 0;
314 return PSI_T_UINT8;
315 }