com php-src: Rename _tmp_compile_const_expr: Zend/z end_compile.c Zend/zend_compile.h
| From: | Nikita Popov | Date: | Wed, 30 Jul 2014 15:44:43 +0000 |
| Subject: | com php-src: Rename _tmp_compile_const_expr: Zend/z end_compile.c Zend/zend_compile.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-80877@lists.php.net to get a copy of this message | ||
Commit: 0cd9cffb5140876c5ca04c671d2cb842c0d100ea
Author: Nikita Popov <nikic@php.net> Wed, 30 Jul 2014 17:44:26 +0200
Parents: 044e48d0b11e5b061bcf88c381eadced5ef4c7d2
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=0cd9cffb5140876c5ca04c671d2cb842c0d100ea
Log:
Rename _tmp_compile_const_expr
Also remove recursive immutization of arrays there, because this
is already handled when the array is created.
Changed paths:
M Zend/zend_compile.c
M Zend/zend_compile.h
Diff:
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 8683ca9..ac4f691 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -3180,24 +3180,6 @@ void zend_make_immutable_array_r(zval *zv TSRMLS_DC) /* {{{ */
}
/* }}} */
-void zend_compile_const_expr(zend_ast **ast_ptr TSRMLS_DC);
-
-// TODO.AST Sort out the whole constant folding issue
-static void _tmp_compile_const_expr(zval *result, zend_ast *ast TSRMLS_DC) {
- zend_ast *orig_ast = ast;
- zend_eval_const_expr(&ast TSRMLS_CC);
- zend_compile_const_expr(&ast TSRMLS_CC);
- if (ast->kind == ZEND_AST_ZVAL) {
- ZVAL_COPY_VALUE(result, zend_ast_get_zval(ast));
- if (Z_TYPE_P(result) == IS_ARRAY) {
- zend_make_immutable_array_r(result TSRMLS_CC);
- }
- orig_ast->kind = ZEND_AST_ZNODE;
- } else {
- ZVAL_NEW_AST(result, zend_ast_copy(ast));
- }
-}
-
/* {{{ zend_dirname
Returns directory name component of path */
ZEND_API size_t zend_dirname(char *path, size_t len)
@@ -4510,7 +4492,7 @@ void zend_compile_static_var(zend_ast *ast TSRMLS_DC) {
zval value_zv;
if (value_ast) {
- _tmp_compile_const_expr(&value_zv, value_ast TSRMLS_CC);
+ zend_const_expr_to_zval(&value_zv, value_ast TSRMLS_CC);
} else {
ZVAL_NULL(&value_zv);
}
@@ -5101,7 +5083,7 @@ void zend_compile_declare(zend_ast *ast TSRMLS_DC) {
zend_string *name = zend_ast_get_str(name_ast);
zval value_zv;
- _tmp_compile_const_expr(&value_zv, value_ast TSRMLS_CC);
+ zend_const_expr_to_zval(&value_zv, value_ast TSRMLS_CC);
if (zend_str_equals_literal_ci(name, "ticks")) {
convert_to_long(&value_zv);
@@ -5238,7 +5220,7 @@ void zend_compile_params(zend_ast *ast TSRMLS_DC) {
} else if (default_ast) {
opcode = ZEND_RECV_INIT;
default_node.op_type = IS_CONST;
- _tmp_compile_const_expr(&default_node.u.constant, default_ast TSRMLS_CC);
+ zend_const_expr_to_zval(&default_node.u.constant, default_ast TSRMLS_CC);
} else {
opcode = ZEND_RECV;
default_node.op_type = IS_UNUSED;
@@ -5679,7 +5661,7 @@ void zend_compile_prop_decl(zend_ast *ast TSRMLS_DC) {
}
if (value_ast) {
- _tmp_compile_const_expr(&value_zv, value_ast TSRMLS_CC);
+ zend_const_expr_to_zval(&value_zv, value_ast TSRMLS_CC);
} else {
ZVAL_NULL(&value_zv);
}
@@ -5707,7 +5689,7 @@ void zend_compile_class_const_decl(zend_ast *ast TSRMLS_DC) {
return;
}
- _tmp_compile_const_expr(&value_zv, value_ast TSRMLS_CC);
+ zend_const_expr_to_zval(&value_zv, value_ast TSRMLS_CC);
if (Z_TYPE(value_zv) == IS_ARRAY
|| (Z_TYPE(value_zv) == IS_CONSTANT_AST && Z_ASTVAL(value_zv)->kind ==
ZEND_AST_ARRAY)
@@ -6215,7 +6197,7 @@ void zend_compile_const_decl(zend_ast *ast TSRMLS_DC) {
zval *value_zv = &value_node.u.constant;
value_node.op_type = IS_CONST;
- _tmp_compile_const_expr(value_zv, value_ast TSRMLS_CC);
+ zend_const_expr_to_zval(value_zv, value_ast TSRMLS_CC);
if (Z_TYPE_P(value_zv) == IS_ARRAY
|| (Z_TYPE_P(value_zv) == IS_CONSTANT_AST
@@ -7282,6 +7264,22 @@ void zend_compile_const_expr(zend_ast **ast_ptr TSRMLS_DC) {
}
}
+void zend_const_expr_to_zval(zval *result, zend_ast *ast TSRMLS_DC) {
+ zend_ast *orig_ast = ast;
+ zend_eval_const_expr(&ast TSRMLS_CC);
+ zend_compile_const_expr(&ast TSRMLS_CC);
+ if (ast->kind == ZEND_AST_ZVAL) {
+ ZVAL_COPY_VALUE(result, zend_ast_get_zval(ast));
+
+ /* Kill this branch of the original AST, as it was already destroyed.
+ * It would be nice to find a better solution to this problem in the
+ * future. */
+ orig_ast->kind = 0;
+ } else {
+ ZVAL_NEW_AST(result, zend_ast_copy(ast));
+ }
+}
+
/* Same as compile_stmt, but with early binding */
void zend_compile_top_stmt(zend_ast *ast TSRMLS_DC) {
if (!ast) {
diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h
index 68a30e3..9286756 100644
--- a/Zend/zend_compile.h
+++ b/Zend/zend_compile.h
@@ -101,12 +101,12 @@ typedef union _zend_parser_stack_elem {
zend_ulong num;
} zend_parser_stack_elem;
-void zend_ensure_writable_variable(const zend_ast *ast);
void zend_compile_top_stmt(zend_ast *ast TSRMLS_DC);
void zend_compile_stmt(zend_ast *ast TSRMLS_DC);
void zend_compile_expr(znode *node, zend_ast *ast TSRMLS_DC);
void zend_compile_var(znode *node, zend_ast *ast, int type TSRMLS_DC);
void zend_eval_const_expr(zend_ast **ast_ptr TSRMLS_DC);
+void zend_const_expr_to_zval(zval *result, zend_ast *ast TSRMLS_DC);
typedef struct _zend_execute_data zend_execute_data;