Skip to content

Commit 5012eff

Browse files
committed
Store original AST as string for zend_ast_op_array
1 parent 45057db commit 5012eff

File tree

6 files changed

+21
-23
lines changed

6 files changed

+21
-23
lines changed

Zend/zend_ast.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,15 @@ ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_constant(zend_string *name, ze
100100
return (zend_ast *) ast;
101101
}
102102

103-
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_op_array(zend_op_array *op_array, zend_ast *original_ast, zend_ast_attr attr) {
103+
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_op_array(zend_op_array *op_array, zend_string *original_ast) {
104104
zend_ast_op_array *ast;
105105

106106
ast = zend_ast_alloc(sizeof(zend_ast_op_array));
107107
ast->kind = ZEND_AST_OP_ARRAY;
108-
ast->attr = attr;
108+
ast->attr = 0;
109+
ast->lineno = CG(zend_lineno);
109110
ast->op_array = op_array;
110-
ast->ast = original_ast;
111+
ast->original_ast = original_ast;
111112

112113
return (zend_ast *) ast;
113114
}
@@ -1091,7 +1092,7 @@ static size_t ZEND_FASTCALL zend_ast_tree_size(zend_ast *ast)
10911092
if (ast->kind == ZEND_AST_ZVAL || ast->kind == ZEND_AST_CONSTANT) {
10921093
size = sizeof(zend_ast_zval);
10931094
} else if (ast->kind == ZEND_AST_OP_ARRAY) {
1094-
size = sizeof(zend_ast_op_array) + zend_ast_tree_size(zend_ast_get_op_array(ast)->ast);
1095+
size = sizeof(zend_ast_op_array);
10951096
} else if (zend_ast_is_list(ast)) {
10961097
uint32_t i;
10971098
zend_ast_list *list = zend_ast_get_list(ast);
@@ -1161,10 +1162,10 @@ static void* ZEND_FASTCALL zend_ast_tree_copy(zend_ast *ast, void *buf)
11611162
zend_ast_op_array *new = (zend_ast_op_array*)buf;
11621163
new->kind = old->kind;
11631164
new->attr = old->attr;
1165+
new->lineno = old->lineno;
11641166
new->op_array = old->op_array;
1167+
new->original_ast = zend_string_copy(old->original_ast);
11651168
buf = (void*)((char*)buf + sizeof(zend_ast_op_array));
1166-
new->ast = (zend_ast*)buf;
1167-
buf = zend_ast_tree_copy(old->ast, buf);
11681169
} else if (zend_ast_is_decl(ast)) {
11691170
zend_ast_decl *old = (zend_ast_decl*)ast;
11701171
zend_ast_decl *new = (zend_ast_decl*)buf;
@@ -1257,7 +1258,7 @@ ZEND_API void ZEND_FASTCALL zend_ast_destroy(zend_ast *ast)
12571258
} else if (EXPECTED(ast->kind == ZEND_AST_CONSTANT)) {
12581259
zend_string_release_ex(zend_ast_get_constant_name(ast), 0);
12591260
} else if (EXPECTED(ast->kind == ZEND_AST_OP_ARRAY)) {
1260-
zend_ast_destroy(zend_ast_get_op_array(ast)->ast);
1261+
zend_string_release_ex(zend_ast_get_op_array(ast)->original_ast, 0);
12611262
} else if (zend_ast_is_decl(ast)) {
12621263
zend_ast_decl *decl = (zend_ast_decl *) ast;
12631264

@@ -1875,10 +1876,9 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
18751876
smart_str_appendl(str, ZSTR_VAL(name), ZSTR_LEN(name));
18761877
break;
18771878
}
1878-
case ZEND_AST_OP_ARRAY: {
1879-
zend_ast_export_ex(str, zend_ast_get_op_array(ast)->ast, priority, indent);
1879+
case ZEND_AST_OP_ARRAY:
1880+
smart_str_append(str, zend_ast_get_op_array(ast)->original_ast);
18801881
break;
1881-
}
18821882
case ZEND_AST_CONSTANT_CLASS:
18831883
smart_str_appendl(str, "__CLASS__", sizeof("__CLASS__")-1);
18841884
break;

Zend/zend_ast.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,9 @@ typedef struct _zend_op_array zend_op_array;
212212
typedef struct _zend_ast_op_array {
213213
zend_ast_kind kind;
214214
zend_ast_attr attr;
215+
uint32_t lineno;
215216
zend_op_array *op_array;
216-
zend_ast *ast;
217+
zend_string *original_ast;
217218
} zend_ast_op_array;
218219

219220
/* Separate structure for function and class declaration, as they need extra information. */
@@ -240,7 +241,7 @@ ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_zval_from_long(zend_long lval)
240241
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_constant(zend_string *name, zend_ast_attr attr);
241242
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_class_const_or_name(zend_ast *class_name, zend_ast *name);
242243

243-
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_op_array(zend_op_array *op_array, zend_ast *original_ast, zend_ast_attr attr);
244+
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_op_array(zend_op_array *op_array, zend_string *original_ast);
244245

245246
#if ZEND_AST_SPEC
246247
# define ZEND_AST_SPEC_CALL(name, ...) \
@@ -386,8 +387,6 @@ static zend_always_inline uint32_t zend_ast_get_lineno(zend_ast *ast) {
386387
} else if (ast->kind == ZEND_AST_CONSTANT) {
387388
zval *zv = &((zend_ast_zval *) ast)->val;
388389
return Z_LINENO_P(zv);
389-
} else if (ast->kind == ZEND_AST_OP_ARRAY) {
390-
return zend_ast_get_op_array(ast)->ast->lineno;
391390
} else {
392391
return ast->lineno;
393392
}

Zend/zend_compile.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11222,7 +11222,10 @@ static void zend_compile_const_expr_closure(zend_ast **ast_ptr)
1122211222
znode node;
1122311223
zend_op_array *op = zend_compile_func_decl(&node, (zend_ast*)closure_ast, FUNC_DECL_LEVEL_CONSTEXPR);
1122411224

11225-
*ast_ptr = zend_ast_create_op_array(op, (zend_ast*)closure_ast, 0);
11225+
zend_string *original_ast = zend_ast_export("", *ast_ptr, "");
11226+
zend_ast_destroy(*ast_ptr);
11227+
*ast_ptr = zend_ast_create_op_array(op, original_ast);
11228+
1122611229
}
1122711230

1122811231
static void zend_compile_const_expr_args(zend_ast **ast_ptr)

ext/opcache/zend_file_cache.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,7 @@ static void zend_file_cache_serialize_ast(zend_ast *ast,
367367
/* The op_array itself will be serialized as part of the dynamic_func_defs. */
368368
SERIALIZE_PTR(((zend_ast_op_array*)ast)->op_array);
369369

370-
SERIALIZE_PTR(((zend_ast_op_array*)ast)->ast);
371-
tmp = ((zend_ast_op_array*)ast)->ast;
372-
UNSERIALIZE_PTR(tmp);
373-
zend_file_cache_serialize_ast(tmp, script, info, buf);
370+
SERIALIZE_STR(((zend_ast_op_array*)ast)->original_ast);
374371
} else if (zend_ast_is_decl(ast)) {
375372
zend_ast_decl *decl = (zend_ast_decl*)ast;
376373
for (i = 0; i < 5; i++) {
@@ -1264,8 +1261,7 @@ static void zend_file_cache_unserialize_ast(zend_ast *ast,
12641261
/* The op_array itself will be unserialized as part of the dynamic_func_defs. */
12651262
UNSERIALIZE_PTR(((zend_ast_op_array*)ast)->op_array);
12661263

1267-
UNSERIALIZE_PTR(((zend_ast_op_array*)ast)->ast);
1268-
zend_file_cache_unserialize_ast(((zend_ast_op_array*)ast)->ast, script, buf);
1264+
UNSERIALIZE_STR(((zend_ast_op_array*)ast)->original_ast);
12691265
} else if (zend_ast_is_decl(ast)) {
12701266
zend_ast_decl *decl = (zend_ast_decl*)ast;
12711267
for (i = 0; i < 5; i++) {

ext/opcache/zend_persist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static zend_ast *zend_persist_ast(zend_ast *ast)
194194
ZVAL_PTR(&z, copy->op_array);
195195
zend_persist_op_array(&z);
196196
copy->op_array = Z_PTR(z);
197-
copy->ast = zend_persist_ast(copy->ast);
197+
zend_accel_store_interned_string(copy->original_ast);
198198
node = (zend_ast *) copy;
199199
} else if (zend_ast_is_decl(ast)) {
200200
zend_ast_decl *copy = zend_shared_memdup(ast, sizeof(zend_ast_decl));

ext/opcache/zend_persist_calc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static void zend_persist_ast_calc(zend_ast *ast)
9191
zval z;
9292
ZVAL_PTR(&z, zend_ast_get_op_array(ast)->op_array);
9393
zend_persist_op_array_calc(&z);
94-
zend_persist_ast_calc(zend_ast_get_op_array(ast)->ast);
94+
ADD_INTERNED_STRING(zend_ast_get_op_array(ast)->original_ast);
9595
} else if (zend_ast_is_decl(ast)) {
9696
zend_ast_decl *decl = (zend_ast_decl*)ast;
9797
ADD_SIZE(sizeof(zend_ast_decl));

0 commit comments

Comments
 (0)