com php-src: Add compilation state for static scalars: Zend/zend_compile.c
| From: | Nikita Popov | Date: | Thu, 26 Jun 2014 14:03:15 +0000 |
| Subject: | com php-src: Add compilation state for static scalars: Zend/zend_compile.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-81033@lists.php.net to get a copy of this message | ||
Commit: 08c4e01a1bbe84029dc1fafa23073515bb9ef387
Author: Nikita Popov <nikic@php.net> Thu, 26 Jun 2014 16:03:15 +0200
Parents: 9c169d5a4d4f26b5ee785be66a520ac6471a1dbc
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=08c4e01a1bbe84029dc1fafa23073515bb9ef387
Log:
Add compilation state for static scalars
Changed paths:
M Zend/zend_compile.c
Diff:
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 48c438d..98229e2 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -6106,18 +6106,19 @@ void zend_make_immutable_array_r(zval *zv TSRMLS_DC) /* {{{ */
}
/* }}} */
+void zend_compile_const_expr(zend_ast **ast_ptr TSRMLS_DC);
+
void zend_do_constant_expression(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
{
+ //zend_eval_const_expr(&ast TSRMLS_CC);
if (ast->kind == ZEND_CONST) {
ZVAL_COPY_VALUE(&result->u.constant, zend_ast_get_zval(ast));
- efree(ast);
- } else if (zend_ast_is_ct_constant(ast)) {
- zend_ast_evaluate(&result->u.constant, ast, NULL TSRMLS_CC);
- zend_ast_destroy(ast);
if (Z_TYPE(result->u.constant) == IS_ARRAY) {
zend_make_immutable_array_r(&result->u.constant TSRMLS_CC);
}
+ efree(ast);
} else {
+ zend_compile_const_expr(&ast TSRMLS_CC);
ZVAL_NEW_AST(&result->u.constant, ast);
}
}
@@ -7787,6 +7788,33 @@ 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_AND || kind == ZEND_AST_OR
+ || kind == ZEND_BW_NOT || kind == ZEND_BOOL_NOT
+ || kind == ZEND_AST_UNARY_PLUS || kind == ZEND_AST_UNARY_MINUS
+ || kind == ZEND_AST_CONDITIONAL
+ || kind == ZEND_AST_ARRAY || kind == ZEND_AST_ARRAY_ELEM;
+}
+
+void zend_compile_const_expr(zend_ast **ast_ptr TSRMLS_DC) {
+ zend_ast *ast = *ast_ptr;
+ if (ast == NULL || ast->kind == ZEND_CONST) {
+ return;
+ }
+
+ if (!zend_is_allowed_in_const_expr(ast->kind)) {
+ zend_error_noreturn(E_COMPILE_ERROR, "Constant expression contains invalid
operations");
+ }
+
+ {
+ zend_uint i;
+ for (i = 0; i < ast->children; ++i) {
+ zend_compile_const_expr(&ast->child[i] TSRMLS_CC);
+ }
+ }
+}
+
void zend_compile_stmt(zend_ast *ast TSRMLS_DC) {
switch (ast->kind) {
case ZEND_AST_GLOBAL: