Merge branch 'slimconfigure'
[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 "php_psi_stdinc.h"
27 #include <assert.h>
28
29 #include "token.h"
30 static inline token_t psi_calc_bool_or(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res)
31 {
32 switch (t1) {
33 case PSI_T_INT8:
34 if (v1->i8)
35 goto return_true;
36 break;
37 case PSI_T_UINT8:
38 if (v1->u8)
39 goto return_true;
40 break;
41 case PSI_T_INT16:
42 if (v1->i16)
43 goto return_true;
44 break;
45 case PSI_T_UINT16:
46 if (v1->u16)
47 goto return_true;
48 break;
49 case PSI_T_INT32:
50 if (v1->i32)
51 goto return_true;
52 break;
53 case PSI_T_UINT32:
54 if (v1->u32)
55 goto return_true;
56 break;
57 case PSI_T_INT64:
58 if (v1->i64)
59 goto return_true;
60 break;
61 case PSI_T_UINT64:
62 if (v1->u64)
63 goto return_true;
64 break;
65 case PSI_T_INT128:
66 if (v1->i128)
67 goto return_true;
68 break;
69 case PSI_T_UINT128:
70 if (v1->u128)
71 goto return_true;
72 break;
73 case PSI_T_FLOAT:
74 if (v1->fval)
75 goto return_true;
76 break;
77 case PSI_T_DOUBLE:
78 if (v1->dval)
79 goto return_true;
80 break;
81 #if HAVE_LONG_DOUBLE
82 case PSI_T_LONG_DOUBLE:
83 if (v1->ldval)
84 goto return_true;
85 break;
86 #endif
87
88 default:
89 assert(0);
90 break;
91 }
92
93 switch (t2) {
94 case PSI_T_INT8:
95 if (v2->i8)
96 goto return_true;
97 break;
98 case PSI_T_UINT8:
99 if (v2->u8)
100 goto return_true;
101 break;
102 case PSI_T_INT16:
103 if (v2->i16)
104 goto return_true;
105 break;
106 case PSI_T_UINT16:
107 if (v2->u16)
108 goto return_true;
109 break;
110 case PSI_T_INT32:
111 if (v2->i32)
112 goto return_true;
113 break;
114 case PSI_T_UINT32:
115 if (v2->u32)
116 goto return_true;
117 break;
118 case PSI_T_INT64:
119 if (v2->i64)
120 goto return_true;
121 break;
122 case PSI_T_UINT64:
123 if (v2->u64)
124 goto return_true;
125 break;
126 case PSI_T_INT128:
127 if (v2->i128)
128 goto return_true;
129 break;
130 case PSI_T_UINT128:
131 if (v2->u128)
132 goto return_true;
133 break;
134 case PSI_T_FLOAT:
135 if (v2->fval)
136 goto return_true;
137 break;
138 case PSI_T_DOUBLE:
139 if (v2->dval)
140 goto return_true;
141 break;
142 #if HAVE_LONG_DOUBLE
143 case PSI_T_LONG_DOUBLE:
144 if (v2->ldval)
145 goto return_true;
146 break;
147 #endif
148
149 default:
150 assert(0);
151 break;
152 }
153
154 res->u8 = 0;
155 return PSI_T_UINT8;
156
157 return_true:
158 res->u8 = 1;
159 return PSI_T_UINT8;
160 }
161
162 static inline token_t psi_calc_bool_and(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res)
163 {
164 switch (t1) {
165 case PSI_T_INT8:
166 if (!v1->i8)
167 goto return_false;
168 break;
169 case PSI_T_UINT8:
170 if (!v1->u8)
171 goto return_false;
172 break;
173 case PSI_T_INT16:
174 if (!v1->i16)
175 goto return_false;
176 break;
177 case PSI_T_UINT16:
178 if (!v1->u16)
179 goto return_false;
180 break;
181 case PSI_T_INT32:
182 if (!v1->i32)
183 goto return_false;
184 break;
185 case PSI_T_UINT32:
186 if (!v1->u32)
187 goto return_false;
188 break;
189 case PSI_T_INT64:
190 if (!v1->i64)
191 goto return_false;
192 break;
193 case PSI_T_UINT64:
194 if (!v1->u64)
195 goto return_false;
196 break;
197 case PSI_T_INT128:
198 if (!v1->i128)
199 goto return_false;
200 break;
201 case PSI_T_UINT128:
202 if (!v1->u128)
203 goto return_false;
204 break;
205 case PSI_T_FLOAT:
206 if (!v1->fval)
207 goto return_false;
208 break;
209 case PSI_T_DOUBLE:
210 if (!v1->dval)
211 goto return_false;
212 break;
213 #if HAVE_LONG_DOUBLE
214 case PSI_T_LONG_DOUBLE:
215 if (!v1->ldval)
216 goto return_false;
217 break;
218 #endif
219
220 default:
221 assert(0);
222 break;
223 }
224
225 switch (t2) {
226 case PSI_T_INT8:
227 if (!v2->i8)
228 goto return_false;
229 break;
230 case PSI_T_UINT8:
231 if (!v2->u8)
232 goto return_false;
233 break;
234 case PSI_T_INT16:
235 if (!v2->i16)
236 goto return_false;
237 break;
238 case PSI_T_UINT16:
239 if (!v2->u16)
240 goto return_false;
241 break;
242 case PSI_T_INT32:
243 if (!v2->i32)
244 goto return_false;
245 break;
246 case PSI_T_UINT32:
247 if (!v2->u32)
248 goto return_false;
249 break;
250 case PSI_T_INT64:
251 if (!v2->i64)
252 goto return_false;
253 break;
254 case PSI_T_UINT64:
255 if (!v2->u64)
256 goto return_false;
257 break;
258 case PSI_T_INT128:
259 if (!v2->i128)
260 goto return_false;
261 break;
262 case PSI_T_UINT128:
263 if (!v2->u128)
264 goto return_false;
265 break;
266 case PSI_T_FLOAT:
267 if (!v2->fval)
268 goto return_false;
269 break;
270 case PSI_T_DOUBLE:
271 if (!v2->dval)
272 goto return_false;
273 break;
274 #if HAVE_LONG_DOUBLE
275 case PSI_T_LONG_DOUBLE:
276 if (!v2->ldval)
277 goto return_false;
278 break;
279 #endif
280
281 default:
282 assert(0);
283 break;
284 }
285
286 res->u8 = 1;
287 return PSI_T_UINT8;
288
289 return_false:
290 res->u8 = 0;
291 return PSI_T_UINT8;
292 }