Reuse expr for static_scalar

This commit is contained in:
Nikita Popov 2014-06-26 22:02:54 +02:00
parent dd60b9bb91
commit dd60c8e0f1
3 changed files with 16 additions and 2 deletions

View file

@ -178,6 +178,19 @@ ZEND_API void zend_ast_evaluate(zval *result, zend_ast *ast, zend_class_entry *s
zval_dtor(&op2); zval_dtor(&op2);
break; 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: case ZEND_BW_NOT:
zend_ast_evaluate(&op1, ast->child[0], scope TSRMLS_CC); zend_ast_evaluate(&op1, ast->child[0], scope TSRMLS_CC);
bitwise_not_function(result, &op1 TSRMLS_CC); bitwise_not_function(result, &op1 TSRMLS_CC);

View 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) { zend_bool zend_is_allowed_in_const_expr(zend_ast_kind kind) {
return kind == ZEND_CONST || kind == ZEND_AST_BINARY_OP 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_AST_AND || kind == ZEND_AST_OR
|| kind == ZEND_BW_NOT || kind == ZEND_BOOL_NOT || kind == ZEND_BW_NOT || kind == ZEND_BOOL_NOT
|| kind == ZEND_AST_UNARY_PLUS || kind == ZEND_AST_UNARY_MINUS || kind == ZEND_AST_UNARY_PLUS || kind == ZEND_AST_UNARY_MINUS

View file

@ -799,7 +799,7 @@ expr_without_variable:
| expr T_LOGICAL_AND expr | expr T_LOGICAL_AND expr
{ $$.u.ast = zend_ast_create_binary(ZEND_AST_AND, $1.u.ast, $3.u.ast); } { $$.u.ast = zend_ast_create_binary(ZEND_AST_AND, $1.u.ast, $3.u.ast); }
| expr T_LOGICAL_XOR expr | 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_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_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); } | 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: /* 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: static_scalar_value: