@@ -8138,7 +8138,13 @@ static uint32_t zend_add_dynamic_func_def(zend_op_array *def) {
8138
8138
return def_offset ;
8139
8139
}
8140
8140
8141
- static zend_string * zend_begin_func_decl (znode * result , zend_op_array * op_array , zend_ast_decl * decl , bool toplevel ) /* {{{ */
8141
+ enum func_decl_level {
8142
+ FUNC_DECL_LEVEL_TOPLEVEL ,
8143
+ FUNC_DECL_LEVEL_NESTED ,
8144
+ FUNC_DECL_LEVEL_CONSTEXPR ,
8145
+ };
8146
+
8147
+ static zend_string * zend_begin_func_decl (znode * result , zend_op_array * op_array , zend_ast_decl * decl , enum func_decl_level level ) /* {{{ */
8142
8148
{
8143
8149
zend_string * unqualified_name , * name , * lcname ;
8144
8150
zend_op * opline ;
@@ -8208,9 +8214,9 @@ static zend_string *zend_begin_func_decl(znode *result, zend_op_array *op_array,
8208
8214
}
8209
8215
8210
8216
zend_register_seen_symbol (lcname , ZEND_SYMBOL_FUNCTION );
8211
- if (! toplevel ) {
8217
+ if (level != FUNC_DECL_LEVEL_TOPLEVEL ) {
8212
8218
uint32_t func_ref = zend_add_dynamic_func_def (op_array );
8213
- if (decl -> kind != ZEND_AST_OP_ARRAY ) {
8219
+ if (level != FUNC_DECL_LEVEL_CONSTEXPR ) {
8214
8220
if (op_array -> fn_flags & ZEND_ACC_CLOSURE ) {
8215
8221
opline = zend_emit_op_tmp (result , ZEND_DECLARE_LAMBDA_FUNCTION , NULL , NULL );
8216
8222
opline -> op2 .num = func_ref ;
@@ -8228,7 +8234,7 @@ static zend_string *zend_begin_func_decl(znode *result, zend_op_array *op_array,
8228
8234
/* }}} */
8229
8235
8230
8236
static zend_op_array * zend_compile_func_decl_ex (
8231
- znode * result , zend_ast * ast , bool toplevel ,
8237
+ znode * result , zend_ast * ast , enum func_decl_level level ,
8232
8238
const zend_property_info * property_info ,
8233
8239
zend_property_hook_kind hook_kind
8234
8240
) {
@@ -8262,7 +8268,7 @@ static zend_op_array *zend_compile_func_decl_ex(
8262
8268
op_array -> doc_comment = zend_string_copy (decl -> doc_comment );
8263
8269
}
8264
8270
8265
- if (decl -> kind == ZEND_AST_CLOSURE || decl -> kind == ZEND_AST_ARROW_FUNC || decl -> kind == ZEND_AST_OP_ARRAY ) {
8271
+ if (decl -> kind == ZEND_AST_CLOSURE || decl -> kind == ZEND_AST_ARROW_FUNC ) {
8266
8272
op_array -> fn_flags |= ZEND_ACC_CLOSURE ;
8267
8273
}
8268
8274
@@ -8274,7 +8280,7 @@ static zend_op_array *zend_compile_func_decl_ex(
8274
8280
bool has_body = stmt_ast != NULL ;
8275
8281
lcname = zend_begin_method_decl (op_array , decl -> name , has_body );
8276
8282
} else {
8277
- lcname = zend_begin_func_decl (result , op_array , decl , toplevel );
8283
+ lcname = zend_begin_func_decl (result , op_array , decl , level );
8278
8284
if (decl -> kind == ZEND_AST_ARROW_FUNC ) {
8279
8285
find_implicit_binds (& info , params_ast , stmt_ast );
8280
8286
compile_implicit_lexical_binds (& info , result , op_array );
@@ -8322,7 +8328,7 @@ static zend_op_array *zend_compile_func_decl_ex(
8322
8328
CG (active_class_entry ) = NULL ;
8323
8329
}
8324
8330
8325
- if (toplevel ) {
8331
+ if (level == FUNC_DECL_LEVEL_TOPLEVEL ) {
8326
8332
op_array -> fn_flags |= ZEND_ACC_TOP_LEVEL ;
8327
8333
}
8328
8334
@@ -8369,7 +8375,7 @@ static zend_op_array *zend_compile_func_decl_ex(
8369
8375
CG (zend_lineno ) = decl -> start_lineno ;
8370
8376
zend_check_magic_method_implementation (
8371
8377
CG (active_class_entry ), (zend_function * ) op_array , lcname , E_COMPILE_ERROR );
8372
- } else if (toplevel ) {
8378
+ } else if (level == FUNC_DECL_LEVEL_TOPLEVEL ) {
8373
8379
/* Only register the function after a successful compile */
8374
8380
if (UNEXPECTED (zend_hash_add_ptr (CG (function_table ), lcname , op_array ) == NULL )) {
8375
8381
CG (zend_lineno ) = decl -> start_lineno ;
@@ -8389,7 +8395,7 @@ static zend_op_array *zend_compile_func_decl_ex(
8389
8395
/* Pop the loop variable stack separator */
8390
8396
zend_stack_del_top (& CG (loop_var_stack ));
8391
8397
8392
- if (toplevel ) {
8398
+ if (level == FUNC_DECL_LEVEL_TOPLEVEL ) {
8393
8399
zend_observer_function_declared_notify (op_array , lcname );
8394
8400
}
8395
8401
@@ -8403,9 +8409,9 @@ static zend_op_array *zend_compile_func_decl_ex(
8403
8409
return op_array ;
8404
8410
}
8405
8411
8406
- static zend_op_array * zend_compile_func_decl (znode * result , zend_ast * ast , bool toplevel )
8412
+ static zend_op_array * zend_compile_func_decl (znode * result , zend_ast * ast , enum func_decl_level level )
8407
8413
{
8408
- return zend_compile_func_decl_ex (result , ast , toplevel , /* property_info */ NULL , (zend_property_hook_kind )- 1 );
8414
+ return zend_compile_func_decl_ex (result , ast , level , /* property_info */ NULL , (zend_property_hook_kind )- 1 );
8409
8415
}
8410
8416
8411
8417
zend_property_hook_kind zend_get_property_hook_kind_from_name (zend_string * name ) {
@@ -8544,7 +8550,7 @@ static void zend_compile_property_hooks(
8544
8550
hook -> name = zend_strpprintf (0 , "$%s::%s" , ZSTR_VAL (prop_name ), ZSTR_VAL (name ));
8545
8551
8546
8552
zend_function * func = (zend_function * ) zend_compile_func_decl_ex (
8547
- NULL , (zend_ast * ) hook , /* toplevel */ false , prop_info , hook_kind );
8553
+ NULL , (zend_ast * ) hook , FUNC_DECL_LEVEL_NESTED , prop_info , hook_kind );
8548
8554
8549
8555
func -> common .prop_info = prop_info ;
8550
8556
@@ -11200,11 +11206,7 @@ static void zend_compile_const_expr_closure(zend_ast **ast_ptr)
11200
11206
}
11201
11207
11202
11208
znode node ;
11203
- zend_ast * ast = * ast_ptr ;
11204
- zend_ast_kind old_kind = ast -> kind ;
11205
- ast -> kind = ZEND_AST_OP_ARRAY ;
11206
- zend_op_array * op = zend_compile_func_decl (& node , ast , /* toplevel */ false);
11207
- ast -> kind = old_kind ;
11209
+ zend_op_array * op = zend_compile_func_decl (& node , * ast_ptr , FUNC_DECL_LEVEL_CONSTEXPR );
11208
11210
11209
11211
zend_ast_destroy (* ast_ptr );
11210
11212
zval z ;
@@ -11320,7 +11322,7 @@ void zend_compile_top_stmt(zend_ast *ast) /* {{{ */
11320
11322
11321
11323
if (ast -> kind == ZEND_AST_FUNC_DECL ) {
11322
11324
CG (zend_lineno ) = ast -> lineno ;
11323
- zend_compile_func_decl (NULL , ast , 1 );
11325
+ zend_compile_func_decl (NULL , ast , FUNC_DECL_LEVEL_TOPLEVEL );
11324
11326
CG (zend_lineno ) = ((zend_ast_decl * ) ast )-> end_lineno ;
11325
11327
} else if (ast -> kind == ZEND_AST_CLASS ) {
11326
11328
CG (zend_lineno ) = ast -> lineno ;
@@ -11402,7 +11404,7 @@ static void zend_compile_stmt(zend_ast *ast) /* {{{ */
11402
11404
break ;
11403
11405
case ZEND_AST_FUNC_DECL :
11404
11406
case ZEND_AST_METHOD :
11405
- zend_compile_func_decl (NULL , ast , 0 );
11407
+ zend_compile_func_decl (NULL , ast , FUNC_DECL_LEVEL_NESTED );
11406
11408
break ;
11407
11409
case ZEND_AST_ENUM_CASE :
11408
11410
zend_compile_enum_case (ast );
@@ -11579,7 +11581,7 @@ static void zend_compile_expr_inner(znode *result, zend_ast *ast) /* {{{ */
11579
11581
return ;
11580
11582
case ZEND_AST_CLOSURE :
11581
11583
case ZEND_AST_ARROW_FUNC :
11582
- zend_compile_func_decl (result , ast , 0 );
11584
+ zend_compile_func_decl (result , ast , FUNC_DECL_LEVEL_NESTED );
11583
11585
return ;
11584
11586
case ZEND_AST_THROW :
11585
11587
zend_compile_throw (result , ast );
0 commit comments