summaryrefslogtreecommitdiff
path: root/Zend/zend_ast.c
diff options
context:
space:
mode:
Diffstat (limited to 'Zend/zend_ast.c')
-rw-r--r--Zend/zend_ast.c70
1 files changed, 9 insertions, 61 deletions
diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c
index e486aa326c..07d38dc6bf 100644
--- a/Zend/zend_ast.c
+++ b/Zend/zend_ast.c
@@ -28,8 +28,7 @@ ZEND_API zend_ast *zend_ast_create_constant(zval *zv)
zend_ast *ast = emalloc(sizeof(zend_ast) + sizeof(zval));
ast->kind = ZEND_CONST;
ast->children = 0;
- ast->u.val = (zval*)(ast + 1);
- INIT_PZVAL_COPY(ast->u.val, zv);
+ ZVAL_COPY_VALUE(&ast->u.val, zv);
return ast;
}
@@ -63,33 +62,12 @@ ZEND_API zend_ast* zend_ast_create_ternary(uint kind, zend_ast *op0, zend_ast *o
return ast;
}
-ZEND_API zend_ast* zend_ast_create_dynamic(uint kind)
-{
- zend_ast *ast = emalloc(sizeof(zend_ast) + sizeof(zend_ast*) * 3); /* use 4 children as deafult */
- ast->kind = kind;
- ast->children = 0;
- return ast;
-}
-
-ZEND_API void zend_ast_dynamic_add(zend_ast **ast, zend_ast *op)
-{
- if ((*ast)->children >= 4 && (*ast)->children == ((*ast)->children & -(*ast)->children)) {
- *ast = erealloc(*ast, sizeof(zend_ast) + sizeof(zend_ast*) * ((*ast)->children * 2 + 1));
- }
- (&(*ast)->u.child)[(*ast)->children++] = op;
-}
-
-ZEND_API void zend_ast_dynamic_shrink(zend_ast **ast)
-{
- *ast = erealloc(*ast, sizeof(zend_ast) + sizeof(zend_ast*) * ((*ast)->children - 1));
-}
-
ZEND_API int zend_ast_is_ct_constant(zend_ast *ast)
{
int i;
if (ast->kind == ZEND_CONST) {
- return !IS_CONSTANT_TYPE(Z_TYPE_P(ast->u.val));
+ return !Z_CONSTANT(ast->u.val);
} else {
for (i = 0; i < ast->children; i++) {
if ((&ast->u.child)[i]) {
@@ -251,10 +229,9 @@ ZEND_API void zend_ast_evaluate(zval *result, zend_ast *ast, zend_class_entry *s
zval_dtor(&op2);
break;
case ZEND_CONST:
- *result = *ast->u.val;
- zval_copy_ctor(result);
- if (IS_CONSTANT_TYPE(Z_TYPE_P(result))) {
- zval_update_constant_ex(&result, 1, scope TSRMLS_CC);
+ ZVAL_DUP(result, &ast->u.val);
+ if (Z_OPT_CONSTANT_P(result)) {
+ zval_update_constant_ex(result, 1, scope TSRMLS_CC);
}
break;
case ZEND_BOOL_AND:
@@ -305,35 +282,6 @@ ZEND_API void zend_ast_evaluate(zval *result, zend_ast *ast, zend_class_entry *s
sub_function(result, &op1, &op2 TSRMLS_CC);
zval_dtor(&op2);
break;
- case ZEND_INIT_ARRAY:
- INIT_PZVAL(result);
- array_init(result);
- {
- int i;
- zend_bool has_key;
- for (i = 0; i < ast->children; i+=2) {
- zval *expr;
- MAKE_STD_ZVAL(expr);
- if ((has_key = !!(&ast->u.child)[i])) {
- zend_ast_evaluate(&op1, (&ast->u.child)[i], scope TSRMLS_CC);
- }
- zend_ast_evaluate(expr, (&ast->u.child)[i+1], scope TSRMLS_CC);
- zend_do_add_static_array_element(result, has_key?&op1:NULL, expr);
- }
- }
- break;
- case ZEND_FETCH_DIM_R:
- zend_ast_evaluate(&op1, (&ast->u.child)[0], scope TSRMLS_CC);
- zend_ast_evaluate(&op2, (&ast->u.child)[1], scope TSRMLS_CC);
- {
- zval *tmp;
- zend_fetch_dimension_by_zval(&tmp, &op1, &op2 TSRMLS_CC);
- *result = *tmp;
- efree(tmp);
- }
- zval_dtor(&op1);
- zval_dtor(&op2);
- break;
default:
zend_error(E_ERROR, "Unsupported constant expression");
}
@@ -344,8 +292,8 @@ ZEND_API zend_ast *zend_ast_copy(zend_ast *ast)
if (ast == NULL) {
return NULL;
} else if (ast->kind == ZEND_CONST) {
- zend_ast *copy = zend_ast_create_constant(ast->u.val);
- zval_copy_ctor(copy->u.val);
+ zend_ast *copy = zend_ast_create_constant(&ast->u.val);
+ zval_copy_ctor(&copy->u.val);
return copy;
} else if (ast->children) {
zend_ast *new = emalloc(sizeof(zend_ast) + sizeof(zend_ast*) * (ast->children - 1));
@@ -357,7 +305,7 @@ ZEND_API zend_ast *zend_ast_copy(zend_ast *ast)
}
return new;
}
- return zend_ast_create_dynamic(ast->kind);
+ return NULL;
}
ZEND_API void zend_ast_destroy(zend_ast *ast)
@@ -365,7 +313,7 @@ ZEND_API void zend_ast_destroy(zend_ast *ast)
int i;
if (ast->kind == ZEND_CONST) {
- zval_dtor(ast->u.val);
+ zval_dtor(&ast->u.val);
} else {
for (i = 0; i < ast->children; i++) {
if ((&ast->u.child)[i]) {