Skip to content

Commit de8d25d

Browse files
committed
Move AST_AND, AST_OR to AST_BINARY_OP as well
1 parent 031a5a3 commit de8d25d

File tree

5 files changed

+53
-12
lines changed

5 files changed

+53
-12
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ ast\flags\TYPE_OBJECT
204204
// Used by ast\AST_UNARY_OP (exclusive)
205205
ast\flags\UNARY_BOOL_NOT
206206
ast\flags\UNARY_BITWISE_NOT
207-
ast\flags\UNARY_MINUS
208-
ast\flags\UNARY_PLUS
209-
ast\flags\UNARY_SILENCE
207+
ast\flags\UNARY_MINUS // since version 20
208+
ast\flags\UNARY_PLUS // since version 20
209+
ast\flags\UNARY_SILENCE // since version 20
210210
211211
// Used by ast\AST_BINARY_OP and ast\AST_ASSIGN_OP in version >= 20 (exclusive)
212212
ast\flags\BINARY_BITWISE_OR
@@ -223,6 +223,8 @@ ast\flags\BINARY_SHIFT_LEFT
223223
ast\flags\BINARY_SHIFT_RIGHT
224224
225225
// Used by ast\AST_BINARY_OP (exclusive)
226+
ast\flags\BINARY_BOOL_AND // since version 20
227+
ast\flags\BINARY_BOOL_OR // since version 20
226228
ast\flags\BINARY_BOOL_XOR
227229
ast\flags\BINARY_IS_IDENTICAL
228230
ast\flags\BINARY_IS_NOT_IDENTICAL
@@ -278,8 +280,9 @@ Version changelog
278280

279281
### 20 (unstable)
280282

281-
* `AST_GREATER` and `AST_GREATER_EQUAL` nodes are now instead represented using
282-
`AST_BINARY_OP` with flags `BINARY_IS_GREATER` and `BINARY_IS_GREATER_OR_EQUAL`.
283+
* `AST_GREATER`, `AST_GREATER_EQUAL`, `AST_OR`, `AST_AND` nodes are now represented using
284+
`AST_BINARY_OP` with flags `BINARY_IS_GREATER`, `BINARY_IS_GREATER_OR_EQUAL`, `BINARY_BOOL_OR`
285+
and `BINARY_BOOL_AND`.
283286
* `AST_SILENCE`, `AST_UNARY_MINUS` and `AST_UNARY_PLUS` nodes are noew represented using
284287
`AST_UNARY_OP` with flags `UNARY_SILENCE`, `UNARY_MINUS` and `UNARY_PLUS`
285288
* `AST_ASSIGN_OP` now uses `BINARY_*` flags instead of separate `ASSIGN_*` flags.

ast.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@
3030

3131
#define AST_DEFAULT_VERSION 10
3232

33-
/* Flag for BINARY_OP to use instead of AST_GREATER(_EQUAL) */
33+
/* Additional flags for BINARY_OP */
3434
#define AST_BINARY_IS_GREATER 256
3535
#define AST_BINARY_IS_GREATER_OR_EQUAL 257
36+
#define AST_BINARY_BOOL_OR 258
37+
#define AST_BINARY_BOOL_AND 259
3638

3739
/* Flags for UNARY_OP to use instead of AST_SILENCE, AST_UNARY_PLUS, AST_UNARY_MINUS */
38-
#define AST_SILENCE 258
39-
#define AST_PLUS 259
40-
#define AST_MINUS 260
40+
#define AST_SILENCE 260
41+
#define AST_PLUS 261
42+
#define AST_MINUS 262
4143

4244
static inline void ast_update_property(zval *object, zend_string *name, zval *value, void **cache_slot) {
4345
zval name_zv;
@@ -213,6 +215,14 @@ static void ast_to_zval(zval *zv, zend_ast *ast, zend_long version) {
213215
ast->kind = ZEND_AST_BINARY_OP;
214216
ast->attr = AST_BINARY_IS_GREATER_OR_EQUAL;
215217
break;
218+
case ZEND_AST_OR:
219+
ast->kind = ZEND_AST_BINARY_OP;
220+
ast->attr = AST_BINARY_BOOL_OR;
221+
break;
222+
case ZEND_AST_AND:
223+
ast->kind = ZEND_AST_BINARY_OP;
224+
ast->attr = AST_BINARY_BOOL_AND;
225+
break;
216226
case ZEND_AST_SILENCE:
217227
ast->kind = ZEND_AST_UNARY_OP;
218228
ast->attr = AST_SILENCE;
@@ -490,6 +500,8 @@ PHP_MINIT_FUNCTION(ast) {
490500
ast_register_flag_constant("UNARY_PLUS", AST_PLUS);
491501
ast_register_flag_constant("UNARY_MINUS", AST_MINUS);
492502

503+
ast_register_flag_constant("BINARY_BOOL_AND", AST_BINARY_BOOL_AND);
504+
ast_register_flag_constant("BINARY_BOOL_OR", AST_BINARY_BOOL_OR);
493505
ast_register_flag_constant("BINARY_BOOL_XOR", ZEND_BOOL_XOR);
494506
ast_register_flag_constant("BINARY_BITWISE_OR", ZEND_BW_OR);
495507
ast_register_flag_constant("BINARY_BITWISE_AND", ZEND_BW_AND);

tests/binop_greater.phpt renamed to tests/binary_ops.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ $code = <<<'PHP'
99
<?php
1010
$a > $b;
1111
$a >= $b;
12+
$a and $b;
13+
$a or $b;
1214
PHP;
1315

1416
echo ast_dump(ast\parse_code($code, $version=10)), "\n";
@@ -27,6 +29,16 @@ AST_STMT_LIST
2729
0: "a"
2830
1: AST_VAR
2931
0: "b"
32+
2: AST_AND
33+
0: AST_VAR
34+
0: "a"
35+
1: AST_VAR
36+
0: "b"
37+
3: AST_OR
38+
0: AST_VAR
39+
0: "a"
40+
1: AST_VAR
41+
0: "b"
3042
AST_STMT_LIST
3143
0: AST_BINARY_OP
3244
flags: BINARY_IS_GREATER (256)
@@ -40,3 +52,15 @@ AST_STMT_LIST
4052
0: "a"
4153
1: AST_VAR
4254
0: "b"
55+
2: AST_BINARY_OP
56+
flags: BINARY_BOOL_AND (259)
57+
0: AST_VAR
58+
0: "a"
59+
1: AST_VAR
60+
0: "b"
61+
3: AST_BINARY_OP
62+
flags: BINARY_BOOL_OR (258)
63+
0: AST_VAR
64+
0: "a"
65+
1: AST_VAR
66+
0: "b"

tests/unary_ops.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ AST_STMT_LIST
2727
0: 1
2828
AST_STMT_LIST
2929
0: AST_UNARY_OP
30-
flags: UNARY_SILENCE (258)
30+
flags: UNARY_SILENCE (260)
3131
0: AST_VAR
3232
0: "a"
3333
1: AST_UNARY_OP
34-
flags: UNARY_PLUS (259)
34+
flags: UNARY_PLUS (261)
3535
0: 1
3636
2: AST_UNARY_OP
37-
flags: UNARY_MINUS (260)
37+
flags: UNARY_MINUS (262)
3838
0: 1

util.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ function get_flag_info() : array {
7575
flags\UNARY_SILENCE => 'UNARY_SILENCE',
7676
],
7777
ast\AST_BINARY_OP => $sharedBinaryOps + [
78+
flags\BINARY_BOOL_AND => 'BINARY_BOOL_AND',
79+
flags\BINARY_BOOL_OR => 'BINARY_BOOL_OR',
7880
flags\BINARY_BOOL_XOR => 'BINARY_BOOL_XOR',
7981
flags\BINARY_IS_IDENTICAL => 'BINARY_IS_IDENTICAL',
8082
flags\BINARY_IS_NOT_IDENTICAL => 'BINARY_IS_NOT_IDENTICAL',

0 commit comments

Comments
 (0)