This repository has been archived by the owner on Nov 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
operators.h
245 lines (209 loc) · 10.4 KB
/
operators.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
+------------------------------------------------------------------------+
| Zephir Language |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2014 Zephir Team (http://www.zephir-lang.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file docs/LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to [email protected] so we can send you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: Andres Gutierrez <[email protected]> |
| Eduar Carvajal <[email protected]> |
| Vladimir Kolesnikov <[email protected]> |
+------------------------------------------------------------------------+
*/
#ifndef ZEPHIR_KERNEL_OPERATORS_H
#define ZEPHIR_KERNEL_OPERATORS_H
/** Strict comparing */
#define ZEPHIR_IS_LONG(op1, op2) ((Z_TYPE_P(op1) == IS_LONG && Z_LVAL_P(op1) == op2) || zephir_compare_strict_long(op1, op2 TSRMLS_CC))
#define ZEPHIR_IS_DOUBLE(op1, op2) ((Z_TYPE_P(op1) == IS_DOUBLE && Z_DVAL_P(op1) == op2) || zephir_compare_strict_double(op1, op2 TSRMLS_CC))
#define ZEPHIR_IS_STRING(op1, op2) zephir_compare_strict_string(op1, op2, strlen(op2))
#define ZEPHIR_IS_LONG_IDENTICAL(op1, op2) (Z_TYPE_P(op1) == IS_LONG && Z_LVAL_P(op1) == op2)
#define ZEPHIR_IS_DOUBLE_IDENTICAL(op1, op2) (Z_TYPE_P(op1) == IS_DOUBLE && Z_DVAL_P(op1) == op2)
#define ZEPHIR_IS_STRING_IDENTICAL(op1, op2) (Z_TYPE_P(op1) == IS_STRING && zephir_compare_strict_string(op1, op2, strlen(op2)))
/** strict boolean comparison */
#define ZEPHIR_IS_FALSE(var) ((Z_TYPE_P(var) == IS_BOOL && !Z_BVAL_P(var)) || zephir_compare_strict_bool(var, 0 TSRMLS_CC))
#define ZEPHIR_IS_TRUE(var) ((Z_TYPE_P(var) == IS_BOOL && Z_BVAL_P(var)) || zephir_compare_strict_bool(var, 1 TSRMLS_CC))
#define ZEPHIR_IS_FALSE_IDENTICAL(var) (Z_TYPE_P(var) == IS_BOOL && !Z_BVAL_P(var))
#define ZEPHIR_IS_TRUE_IDENTICAL(var) (Z_TYPE_P(var) == IS_BOOL && Z_BVAL_P(var))
#define ZEPHIR_IS_NOT_FALSE(var) (Z_TYPE_P(var) != IS_BOOL || (Z_TYPE_P(var) == IS_BOOL && Z_BVAL_P(var)))
#define ZEPHIR_IS_NOT_TRUE(var) (Z_TYPE_P(var) != IS_BOOL || (Z_TYPE_P(var) == IS_BOOL && !Z_BVAL_P(var)))
#define ZEPHIR_IS_BOOL(op1, op2) ((Z_TYPE_P(op1) == IS_BOOL && Z_BVAL_P(op1) == op2) || zephir_compare_strict_bool(op1, op2 TSRMLS_CC))
/** SQL null empty **/
#define ZEPHIR_IS_EMPTY(var) (Z_TYPE_P(var) == IS_NULL || ZEPHIR_IS_FALSE(var) || (Z_TYPE_P(var) == IS_STRING && !Z_STRLEN_P(var)) || (Z_TYPE_P(var) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(var)) == 0))
#define ZEPHIR_IS_NOT_EMPTY(var) (!ZEPHIR_IS_EMPTY(var))
/** Is scalar */
#define ZEPHIR_IS_SCALAR(var) (!ZEPHIR_IS_NOT_SCALAR(var))
#define ZEPHIR_IS_NOT_SCALAR(var) (Z_TYPE_P(var) == IS_NULL || Z_TYPE_P(var) == IS_ARRAY || Z_TYPE_P(var) == IS_OBJECT || Z_TYPE_P(var) == IS_RESOURCE)
/** Equals/Identical */
#define ZEPHIR_IS_EQUAL(op1, op2) zephir_is_equal(op1, op2 TSRMLS_CC)
#define ZEPHIR_IS_IDENTICAL(op1, op2) zephir_is_identical(op1, op2 TSRMLS_CC)
/** Greater/Smaller equals */
#define ZEPHIR_LE(op1, op2) zephir_less_equal(op1, op2 TSRMLS_CC)
#define ZEPHIR_LE_LONG(op1, op2) ((Z_TYPE_P(op1) == IS_LONG && Z_LVAL_P(op1) <= op2) || zephir_less_equal_long(op1, op2 TSRMLS_CC))
#define ZEPHIR_LE_DOUBLE(op1, op2) ((Z_TYPE_P(op1) == IS_DOUBLE && Z_DVAL_P(op1) <= op2) || zephir_less_equal_double(op1, op2 TSRMLS_CC))
#define ZEPHIR_GE(op1, op2) zephir_greater_equal(op1, op2 TSRMLS_CC)
#define ZEPHIR_GE_LONG(op1, op2) zephir_greater_equal_long(op1, op2 TSRMLS_CC)
#define ZEPHIR_LT(op1, op2) ((Z_TYPE_P(op1) == IS_LONG && Z_TYPE_P(op2) == IS_LONG) ? Z_LVAL_P(op1) < Z_LVAL_P(op2) : zephir_less(op1, op2 TSRMLS_CC))
#define ZEPHIR_LT_LONG(op1, op2) ((Z_TYPE_P(op1) == IS_LONG && Z_LVAL_P(op1) < op2) || zephir_less_long(op1, op2 TSRMLS_CC))
#define ZEPHIR_LT_DOUBLE(op1, op2) ((Z_TYPE_P(op1) == IS_DOUBLE && Z_DVAL_P(op1) < op2) || zephir_less_double(op1, op2 TSRMLS_CC))
#define ZEPHIR_GT(op1, op2) zephir_greater(op1, op2 TSRMLS_CC)
#define ZEPHIR_GT_LONG(op1, op2) ((Z_TYPE_P(op1) == IS_LONG && Z_LVAL_P(op1) > op2) || zephir_greater_long(op1, op2 TSRMLS_CC))
#define ZEPHIR_GT_DOUBLE(op1, op2) ((Z_TYPE_P(op1) == IS_DOUBLE && Z_DVAL_P(op1) > op2) || zephir_greater_double(op1, op2 TSRMLS_CC))
#define ZEPHIR_STRING_OFFSET(op1, index) ((index >= 0 && index < Z_STRLEN_P(op1)) ? Z_STRVAL_P(op1)[index] : '\0')
#if PHP_VERSION_ID < 50400
#define zephir_increment(var) increment_function(var)
#else
#define zephir_increment(var) fast_increment_function(var)
#endif
#if PHP_VERSION_ID < 50400
#define zephir_decrement(var) decrement_function(var)
#else
#define zephir_decrement(var) fast_decrement_function(var)
#endif
void zephir_make_printable_zval(zval *expr, zval *expr_copy, int *use_copy);
#if PHP_VERSION_ID < 50400
#define zephir_sub_function(result, left, right) sub_function(result, left, right)
#else
#define zephir_sub_function(result, left, right) fast_sub_function(result, left, right)
#endif
/** Operator functions */
int zephir_add_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
int zephir_and_function(zval *result, zval *left, zval *right);
void zephir_negate(zval *z TSRMLS_DC);
/** Bitwise functions */
int zephir_bitwise_and_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
int zephir_bitwise_or_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
int zephir_bitwise_xor_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
int zephir_shift_left_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
int zephir_shift_right_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
void zephir_concat_self(zval **left, zval *right TSRMLS_DC);
void zephir_concat_self_str(zval **left, const char *right, int right_length TSRMLS_DC);
void zephir_concat_self_long(zval **left, const long right TSRMLS_DC);
void zephir_concat_self_char(zval **left, unsigned char right TSRMLS_DC);
/** Strict comparing */
int zephir_compare_strict_string(zval *op1, const char *op2, int op2_length);
int zephir_compare_strict_long(zval *op1, long op2 TSRMLS_DC);
int zephir_compare_strict_double(zval *op1, double op2 TSRMLS_DC);
int zephir_compare_strict_bool(zval *op1, zend_bool op2 TSRMLS_DC);
void zephir_cast(zval *result, zval *var, zend_uint type);
void zephir_convert_to_object(zval *op);
long zephir_get_intval_ex(const zval *op);
double zephir_get_doubleval_ex(const zval *op);
zend_bool zephir_get_boolval_ex(const zval *op);
int zephir_is_numeric_ex(const zval *op);
int zephir_is_equal(zval *op1, zval *op2 TSRMLS_DC);
int zephir_is_identical(zval *op1, zval *op2 TSRMLS_DC);
int zephir_less(zval *op1, zval *op2 TSRMLS_DC);
int zephir_less_long(zval *op1, long op2 TSRMLS_DC);
int zephir_greater(zval *op1, zval *op2 TSRMLS_DC);
int zephir_greater_long(zval *op1, long op2 TSRMLS_DC);
int zephir_less_equal(zval *op1, zval *op2 TSRMLS_DC);
int zephir_less_equal_long(zval *op1, long op2 TSRMLS_DC);
int zephir_greater_equal(zval *op1, zval *op2 TSRMLS_DC);
int zephir_greater_equal_long(zval *op1, long op2 TSRMLS_DC);
#define zephir_get_numberval(z) (Z_TYPE_P(z) == IS_LONG ? Z_LVAL_P(z) : zephir_get_doubleval(z))
#define zephir_get_intval(z) (Z_TYPE_P(z) == IS_LONG ? Z_LVAL_P(z) : zephir_get_intval_ex(z))
#define zephir_get_doubleval(z) (Z_TYPE_P(z) == IS_DOUBLE ? Z_DVAL_P(z) : zephir_get_doubleval_ex(z))
#define zephir_get_boolval(z) (Z_TYPE_P(z) == IS_BOOL ? Z_BVAL_P(z) : zephir_get_boolval_ex(z))
#define ZEPHIR_ADD_ASSIGN(z, v) \
{ \
zval tmp; \
ZEPHIR_SEPARATE(z); \
if (Z_TYPE_P(z) == IS_LONG && Z_TYPE_P(v) == IS_LONG) { \
Z_LVAL_P(z) += Z_LVAL_P(v); \
} else { \
if (Z_TYPE_P(z) == IS_LONG && Z_TYPE_P(v) == IS_DOUBLE) { \
Z_LVAL_P(z) += Z_DVAL_P(v); \
} else { \
zephir_add_function(&tmp, z, v TSRMLS_CC); \
if (Z_TYPE(tmp) == IS_LONG) { \
Z_LVAL_P(z) = Z_LVAL(tmp); \
} else { \
if (Z_TYPE(tmp) == IS_DOUBLE) { \
Z_DVAL_P(z) = Z_DVAL(tmp); \
} \
} \
} \
} \
}
#define ZEPHIR_SUB_ASSIGN(z, v) \
{ \
zval tmp; \
ZEPHIR_SEPARATE(z); \
if (Z_TYPE_P(z) == IS_LONG && Z_TYPE_P(v) == IS_LONG) { \
Z_LVAL_P(z) -= Z_LVAL_P(v); \
} else { \
if (Z_TYPE_P(z) == IS_LONG && Z_TYPE_P(v) == IS_DOUBLE) { \
Z_LVAL_P(z) -= Z_DVAL_P(v); \
} else { \
sub_function(&tmp, z, v TSRMLS_CC); \
if (Z_TYPE(tmp) == IS_LONG) { \
Z_LVAL_P(z) = Z_LVAL(tmp); \
} else { \
if (Z_TYPE(tmp) == IS_DOUBLE) { \
Z_DVAL_P(z) = Z_DVAL(tmp); \
} \
} \
} \
} \
}
#define ZEPHIR_MUL_ASSIGN(z, v) \
{ \
zval tmp; \
ZEPHIR_SEPARATE(z); \
if (Z_TYPE_P(z) == IS_LONG && Z_TYPE_P(v) == IS_LONG) { \
Z_LVAL_P(z) *= Z_LVAL_P(v); \
} else { \
if (Z_TYPE_P(z) == IS_LONG && Z_TYPE_P(v) == IS_DOUBLE) { \
Z_LVAL_P(z) *= Z_DVAL_P(v); \
} else { \
sub_function(&tmp, z, v TSRMLS_CC); \
if (Z_TYPE(tmp) == IS_LONG) { \
Z_LVAL_P(z) = Z_LVAL(tmp); \
} else { \
if (Z_TYPE(tmp) == IS_DOUBLE) { \
Z_DVAL_P(z) = Z_DVAL(tmp); \
} \
} \
} \
} \
}
#define zephir_get_strval(left, right) \
{ \
int use_copy_right; \
zval right_tmp; \
if (Z_TYPE_P(right) == IS_STRING) { \
ZEPHIR_CPY_WRT(left, right); \
} else { \
INIT_ZVAL(right_tmp); \
zephir_make_printable_zval(right, &right_tmp, &use_copy_right); \
if (use_copy_right) { \
ZEPHIR_INIT_NVAR(left); \
ZVAL_STRINGL(left, Z_STRVAL_P(&right_tmp), Z_STRLEN_P(&right_tmp), 0); \
} \
} \
}
#define zephir_get_arrval(returnValue, passValue) \
{ \
if (Z_TYPE_P(passValue) == IS_ARRAY) { \
ZEPHIR_CPY_WRT(returnValue, passValue); \
} else { \
ZEPHIR_INIT_NVAR(returnValue); \
array_init_size(returnValue, 0); \
} \
}
#define zephir_is_numeric(value) (Z_TYPE_P(value) == IS_LONG || Z_TYPE_P(value) == IS_DOUBLE || zephir_is_numeric_ex(value))
#define zephir_is_true(value) \
(Z_TYPE_P(value) == IS_NULL ? 0 : \
(Z_TYPE_P(value) == IS_BOOL ? Z_BVAL_P(value) : \
(Z_TYPE_P(value) == IS_LONG ? Z_LVAL_P(value) : \
zend_is_true(value) \
) \
) \
)
#endif