]> granicus.if.org Git - php/commitdiff
Reuse expr for static_scalar
authorNikita Popov <nikic@php.net>
Thu, 26 Jun 2014 20:02:54 +0000 (22:02 +0200)
committerNikita Popov <nikic@php.net>
Thu, 26 Jun 2014 20:02:54 +0000 (22:02 +0200)
Zend/zend_ast.c
Zend/zend_compile.c
Zend/zend_language_parser.y

index ec3e9dbc84583cecc7cc8f9e2c3e622cddf9f172..c84842eeb182ae7b89a5a5d72dab3819fd2c95bc 100644 (file)
@@ -178,6 +178,19 @@ ZEND_API void zend_ast_evaluate(zval *result, zend_ast *ast, zend_class_entry *s
                        zval_dtor(&op2);
                        break;
                }
+               case ZEND_AST_GREATER:
+               case ZEND_AST_GREATER_EQUAL:
+               {
+                       /* op1 > op2 is the same as op2 < op1 */
+                       binary_op_type op = ast->kind == ZEND_AST_GREATER
+                               ? is_smaller_function : is_smaller_or_equal_function;
+                       zend_ast_evaluate(&op1, ast->child[0], scope TSRMLS_CC);
+                       zend_ast_evaluate(&op2, ast->child[1], scope TSRMLS_CC);
+                       op(result, &op2, &op1 TSRMLS_CC);
+                       zval_dtor(&op1);
+                       zval_dtor(&op2);
+                       break;
+               }
                case ZEND_BW_NOT:
                        zend_ast_evaluate(&op1, ast->child[0], scope TSRMLS_CC);
                        bitwise_not_function(result, &op1 TSRMLS_CC);
index 1c5c951a4b3f1bbc06ca9e7f86ce832188383e77..ef02d31a5fa925694983bb632b9955a66f821abe 100644 (file)
@@ -7790,6 +7790,7 @@ void zend_compile_encaps_list(znode *result, zend_ast *ast TSRMLS_DC) {
 
 zend_bool zend_is_allowed_in_const_expr(zend_ast_kind kind) {
        return kind == ZEND_CONST || kind == ZEND_AST_BINARY_OP
+               || kind == ZEND_AST_GREATER || kind == ZEND_AST_GREATER_EQUAL
                || kind == ZEND_AST_AND || kind == ZEND_AST_OR
                || kind == ZEND_BW_NOT || kind == ZEND_BOOL_NOT
                || kind == ZEND_AST_UNARY_PLUS || kind == ZEND_AST_UNARY_MINUS
index 3dbb27675c6675166d63051bee4463608604a276..945a900213b8b8d4113ab4082734e3d74ec18e75 100644 (file)
@@ -799,7 +799,7 @@ expr_without_variable:
        |       expr T_LOGICAL_AND expr
                        { $$.u.ast = zend_ast_create_binary(ZEND_AST_AND, $1.u.ast, $3.u.ast); }
        |       expr T_LOGICAL_XOR expr
-                       { $$.u.ast = zend_ast_create_binary(ZEND_BOOL_XOR, $1.u.ast, $3.u.ast); }
+                       { $$.u.ast = zend_ast_create_binary_op(ZEND_BOOL_XOR, $1.u.ast, $3.u.ast); }
        |       expr '|' expr   { $$.u.ast = zend_ast_create_binary_op(ZEND_BW_OR, $1.u.ast, $3.u.ast); }
        |       expr '&' expr   { $$.u.ast = zend_ast_create_binary_op(ZEND_BW_AND, $1.u.ast, $3.u.ast); }
        |       expr '^' expr   { $$.u.ast = zend_ast_create_binary_op(ZEND_BW_XOR, $1.u.ast, $3.u.ast); }
@@ -973,7 +973,7 @@ common_scalar:
 ;
 
 static_scalar: /* compile-time evaluated scalars */
-       static_scalar_value { zend_do_constant_expression(&$$, $1.u.ast TSRMLS_CC); }
+       expr { zend_do_constant_expression(&$$, $1.u.ast TSRMLS_CC); }
 ;
 
 static_scalar_value: