@@ -4596,11 +4596,11 @@ static void zend_compile_static_var_common(zend_string *var_name, zval *value, u
4596
4596
void zend_compile_static_var (zend_ast * ast ) /* {{{ */
4597
4597
{
4598
4598
zend_ast * var_ast = ast -> child [0 ];
4599
- zend_ast * value_ast = ast -> child [1 ];
4599
+ zend_ast * * value_ast_ptr = & ast -> child [1 ];
4600
4600
zval value_zv ;
4601
4601
4602
- if (value_ast ) {
4603
- zend_const_expr_to_zval (& value_zv , value_ast );
4602
+ if (* value_ast_ptr ) {
4603
+ zend_const_expr_to_zval (& value_zv , value_ast_ptr );
4604
4604
} else {
4605
4605
ZVAL_NULL (& value_zv );
4606
4606
}
@@ -5895,16 +5895,16 @@ void zend_compile_declare(zend_ast *ast) /* {{{ */
5895
5895
for (i = 0 ; i < declares -> children ; ++ i ) {
5896
5896
zend_ast * declare_ast = declares -> child [i ];
5897
5897
zend_ast * name_ast = declare_ast -> child [0 ];
5898
- zend_ast * value_ast = declare_ast -> child [1 ];
5898
+ zend_ast * * value_ast_ptr = & declare_ast -> child [1 ];
5899
5899
zend_string * name = zend_ast_get_str (name_ast );
5900
5900
5901
- if (value_ast -> kind != ZEND_AST_ZVAL ) {
5901
+ if (( * value_ast_ptr ) -> kind != ZEND_AST_ZVAL ) {
5902
5902
zend_error_noreturn (E_COMPILE_ERROR , "declare(%s) value must be a literal" , ZSTR_VAL (name ));
5903
5903
}
5904
5904
5905
5905
if (zend_string_equals_literal_ci (name , "ticks" )) {
5906
5906
zval value_zv ;
5907
- zend_const_expr_to_zval (& value_zv , value_ast );
5907
+ zend_const_expr_to_zval (& value_zv , value_ast_ptr );
5908
5908
FC (declarables ).ticks = zval_get_long (& value_zv );
5909
5909
zval_ptr_dtor_nogc (& value_zv );
5910
5910
} else if (zend_string_equals_literal_ci (name , "encoding" )) {
@@ -5926,7 +5926,7 @@ void zend_compile_declare(zend_ast *ast) /* {{{ */
5926
5926
"use block mode" );
5927
5927
}
5928
5928
5929
- zend_const_expr_to_zval (& value_zv , value_ast );
5929
+ zend_const_expr_to_zval (& value_zv , value_ast_ptr );
5930
5930
5931
5931
if (Z_TYPE (value_zv ) != IS_LONG || (Z_LVAL (value_zv ) != 0 && Z_LVAL (value_zv ) != 1 )) {
5932
5932
zend_error_noreturn (E_COMPILE_ERROR , "strict_types declaration must have 0 or 1 as its value" );
@@ -6233,7 +6233,8 @@ static void zend_compile_attributes(HashTable **attributes, zend_ast *ast, uint3
6233
6233
6234
6234
zend_bool uses_named_args = 0 ;
6235
6235
for (j = 0 ; j < args -> children ; j ++ ) {
6236
- zend_ast * arg_ast = args -> child [j ];
6236
+ zend_ast * * arg_ast_ptr = & args -> child [j ];
6237
+ zend_ast * arg_ast = * arg_ast_ptr ;
6237
6238
6238
6239
if (arg_ast -> kind == ZEND_AST_UNPACK ) {
6239
6240
zend_error_noreturn (E_COMPILE_ERROR ,
@@ -6242,7 +6243,7 @@ static void zend_compile_attributes(HashTable **attributes, zend_ast *ast, uint3
6242
6243
6243
6244
if (arg_ast -> kind == ZEND_AST_NAMED_ARG ) {
6244
6245
attr -> args [j ].name = zend_string_copy (zend_ast_get_str (arg_ast -> child [0 ]));
6245
- arg_ast = arg_ast -> child [1 ];
6246
+ arg_ast_ptr = & arg_ast -> child [1 ];
6246
6247
uses_named_args = 1 ;
6247
6248
6248
6249
for (uint32_t k = 0 ; k < j ; k ++ ) {
@@ -6257,7 +6258,7 @@ static void zend_compile_attributes(HashTable **attributes, zend_ast *ast, uint3
6257
6258
"Cannot use positional argument after named argument" );
6258
6259
}
6259
6260
6260
- zend_const_expr_to_zval (& attr -> args [j ].value , arg_ast );
6261
+ zend_const_expr_to_zval (& attr -> args [j ].value , arg_ast_ptr );
6261
6262
}
6262
6263
}
6263
6264
}
@@ -6324,7 +6325,7 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall
6324
6325
zend_ast * param_ast = list -> child [i ];
6325
6326
zend_ast * type_ast = param_ast -> child [0 ];
6326
6327
zend_ast * var_ast = param_ast -> child [1 ];
6327
- zend_ast * default_ast = param_ast -> child [2 ];
6328
+ zend_ast * * default_ast_ptr = & param_ast -> child [2 ];
6328
6329
zend_ast * attributes_ast = param_ast -> child [3 ];
6329
6330
zend_ast * doc_comment_ast = param_ast -> child [4 ];
6330
6331
zend_string * name = zval_make_interned_string (zend_ast_get_zval (var_ast ));
@@ -6338,12 +6339,6 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall
6338
6339
zend_op * opline ;
6339
6340
zend_arg_info * arg_info ;
6340
6341
6341
- zend_ast_ref * attributes_copy = NULL ;
6342
-
6343
- if (visibility && attributes_ast ) {
6344
- attributes_copy = zend_ast_copy (attributes_ast );
6345
- }
6346
-
6347
6342
if (zend_is_auto_global (name )) {
6348
6343
zend_error_noreturn (E_COMPILE_ERROR , "Cannot re-assign auto-global variable %s" ,
6349
6344
ZSTR_VAL (name ));
@@ -6368,17 +6363,17 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall
6368
6363
default_node .op_type = IS_UNUSED ;
6369
6364
op_array -> fn_flags |= ZEND_ACC_VARIADIC ;
6370
6365
6371
- if (default_ast ) {
6366
+ if (* default_ast_ptr ) {
6372
6367
zend_error_noreturn (E_COMPILE_ERROR ,
6373
6368
"Variadic parameter cannot have a default value" );
6374
6369
}
6375
- } else if (default_ast ) {
6370
+ } else if (* default_ast_ptr ) {
6376
6371
/* we cannot substitute constants here or it will break ReflectionParameter::getDefaultValueConstantName() and ReflectionParameter::isDefaultValueConstant() */
6377
6372
uint32_t cops = CG (compiler_options );
6378
6373
CG (compiler_options ) |= ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION | ZEND_COMPILE_NO_PERSISTENT_CONSTANT_SUBSTITUTION ;
6379
6374
opcode = ZEND_RECV_INIT ;
6380
6375
default_node .op_type = IS_CONST ;
6381
- zend_const_expr_to_zval (& default_node .u .constant , default_ast );
6376
+ zend_const_expr_to_zval (& default_node .u .constant , default_ast_ptr );
6382
6377
CG (compiler_options ) = cops ;
6383
6378
6384
6379
if (!optional_param ) {
@@ -6409,7 +6404,7 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall
6409
6404
}
6410
6405
6411
6406
if (type_ast ) {
6412
- uint32_t default_type = default_ast ? Z_TYPE (default_node .u .constant ) : IS_UNDEF ;
6407
+ uint32_t default_type = * default_ast_ptr ? Z_TYPE (default_node .u .constant ) : IS_UNDEF ;
6413
6408
zend_bool force_nullable = default_type == IS_NULL && !visibility ;
6414
6409
6415
6410
op_array -> fn_flags |= ZEND_ACC_HAS_TYPE_HINTS ;
@@ -6497,8 +6492,7 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall
6497
6492
scope , name , & default_value , visibility | ZEND_ACC_PROMOTED , doc_comment , type );
6498
6493
if (attributes_ast ) {
6499
6494
zend_compile_attributes (
6500
- & prop -> attributes , GC_AST (attributes_copy ), 0 , ZEND_ATTRIBUTE_TARGET_PROPERTY );
6501
- zend_ast_ref_destroy (attributes_copy );
6495
+ & prop -> attributes , attributes_ast , 0 , ZEND_ATTRIBUTE_TARGET_PROPERTY );
6502
6496
}
6503
6497
}
6504
6498
}
@@ -7002,7 +6996,7 @@ void zend_compile_prop_decl(zend_ast *ast, zend_ast *type_ast, uint32_t flags, z
7002
6996
zend_property_info * info ;
7003
6997
zend_ast * prop_ast = list -> child [i ];
7004
6998
zend_ast * name_ast = prop_ast -> child [0 ];
7005
- zend_ast * value_ast = prop_ast -> child [1 ];
6999
+ zend_ast * * value_ast_ptr = & prop_ast -> child [1 ];
7006
7000
zend_ast * doc_comment_ast = prop_ast -> child [2 ];
7007
7001
zend_string * name = zval_make_interned_string (zend_ast_get_zval (name_ast ));
7008
7002
zend_string * doc_comment = NULL ;
@@ -7036,8 +7030,8 @@ void zend_compile_prop_decl(zend_ast *ast, zend_ast *type_ast, uint32_t flags, z
7036
7030
ZSTR_VAL (ce -> name ), ZSTR_VAL (name ));
7037
7031
}
7038
7032
7039
- if (value_ast ) {
7040
- zend_const_expr_to_zval (& value_zv , value_ast );
7033
+ if (* value_ast_ptr ) {
7034
+ zend_const_expr_to_zval (& value_zv , value_ast_ptr );
7041
7035
7042
7036
if (ZEND_TYPE_IS_SET (type ) && !Z_CONSTANT (value_zv )
7043
7037
&& !zend_is_valid_default_value (type , & value_zv )) {
@@ -7111,7 +7105,7 @@ void zend_compile_class_const_decl(zend_ast *ast, uint32_t flags, zend_ast *attr
7111
7105
zend_class_constant * c ;
7112
7106
zend_ast * const_ast = list -> child [i ];
7113
7107
zend_ast * name_ast = const_ast -> child [0 ];
7114
- zend_ast * value_ast = const_ast -> child [1 ];
7108
+ zend_ast * * value_ast_ptr = & const_ast -> child [1 ];
7115
7109
zend_ast * doc_comment_ast = const_ast -> child [2 ];
7116
7110
zend_string * name = zval_make_interned_string (zend_ast_get_zval (name_ast ));
7117
7111
zend_string * doc_comment = doc_comment_ast ? zend_string_copy (zend_ast_get_str (doc_comment_ast )) : NULL ;
@@ -7121,7 +7115,7 @@ void zend_compile_class_const_decl(zend_ast *ast, uint32_t flags, zend_ast *attr
7121
7115
zend_check_const_and_trait_alias_attr (flags , "constant" );
7122
7116
}
7123
7117
7124
- zend_const_expr_to_zval (& value_zv , value_ast );
7118
+ zend_const_expr_to_zval (& value_zv , value_ast_ptr );
7125
7119
c = zend_declare_class_constant_ex (ce , name , & value_zv , flags , doc_comment );
7126
7120
7127
7121
if (attr_ast ) {
@@ -7622,15 +7616,15 @@ void zend_compile_const_decl(zend_ast *ast) /* {{{ */
7622
7616
for (i = 0 ; i < list -> children ; ++ i ) {
7623
7617
zend_ast * const_ast = list -> child [i ];
7624
7618
zend_ast * name_ast = const_ast -> child [0 ];
7625
- zend_ast * value_ast = const_ast -> child [1 ];
7619
+ zend_ast * * value_ast_ptr = & const_ast -> child [1 ];
7626
7620
zend_string * unqualified_name = zend_ast_get_str (name_ast );
7627
7621
7628
7622
zend_string * name ;
7629
7623
znode name_node , value_node ;
7630
7624
zval * value_zv = & value_node .u .constant ;
7631
7625
7632
7626
value_node .op_type = IS_CONST ;
7633
- zend_const_expr_to_zval (value_zv , value_ast );
7627
+ zend_const_expr_to_zval (value_zv , value_ast_ptr );
7634
7628
7635
7629
if (zend_get_special_const (ZSTR_VAL (unqualified_name ), ZSTR_LEN (unqualified_name ))) {
7636
7630
zend_error_noreturn (E_COMPILE_ERROR ,
@@ -9297,23 +9291,18 @@ void zend_compile_const_expr(zend_ast **ast_ptr) /* {{{ */
9297
9291
}
9298
9292
/* }}} */
9299
9293
9300
- void zend_const_expr_to_zval (zval * result , zend_ast * ast ) /* {{{ */
9294
+ void zend_const_expr_to_zval (zval * result , zend_ast * * ast_ptr ) /* {{{ */
9301
9295
{
9302
- zend_ast * orig_ast = ast ;
9303
- zend_eval_const_expr (& ast );
9304
- zend_compile_const_expr (& ast );
9305
- if (ast -> kind == ZEND_AST_ZVAL ) {
9306
- ZVAL_COPY_VALUE (result , zend_ast_get_zval (ast ));
9307
- } else {
9308
- ZVAL_AST (result , zend_ast_copy (ast ));
9309
- /* destroy the ast here, it might have been replaced */
9310
- zend_ast_destroy (ast );
9296
+ zend_eval_const_expr (ast_ptr );
9297
+ zend_compile_const_expr (ast_ptr );
9298
+ if ((* ast_ptr )-> kind != ZEND_AST_ZVAL ) {
9299
+ /* Replace with compiled AST zval representation. */
9300
+ zval ast_zv ;
9301
+ ZVAL_AST (& ast_zv , zend_ast_copy (* ast_ptr ));
9302
+ zend_ast_destroy (* ast_ptr );
9303
+ * ast_ptr = zend_ast_create_zval (& ast_zv );
9311
9304
}
9312
-
9313
- /* Kill this branch of the original AST, as it was already destroyed.
9314
- * It would be nice to find a better solution to this problem in the
9315
- * future. */
9316
- orig_ast -> kind = 0 ;
9305
+ ZVAL_COPY (result , zend_ast_get_zval (* ast_ptr ));
9317
9306
}
9318
9307
/* }}} */
9319
9308
0 commit comments