@@ -5349,12 +5349,72 @@ void zend_compile_declare(zend_ast *ast) /* {{{ */
5349
5349
}
5350
5350
/* }}} */
5351
5351
5352
+ static zend_ast * * _ast_find (zend_ast * * begin , zend_ast * * end ,
5353
+ zend_bool (* pred )(zend_ast * )) {
5354
+ for (; begin < end ; ++ begin )
5355
+ if (pred (* begin ))
5356
+ return begin ;
5357
+ return begin ;
5358
+ }
5359
+
5360
+ static zend_bool _is_type_decl (zend_ast * ast ) {
5361
+ return ast && ast -> kind == ZEND_AST_CLASS ;
5362
+ }
5363
+
5364
+ static zend_bool _is_not_decl_stmt (zend_ast * ast ) {
5365
+ if (ast ) {
5366
+ /* todo: what else should be considered a decl stmt? */
5367
+ switch (ast -> kind ) {
5368
+ case ZEND_AST_CLASS :
5369
+ case ZEND_AST_CONST_DECL :
5370
+ case ZEND_AST_FUNC_DECL :
5371
+ return 0 ;
5372
+
5373
+ default :
5374
+ return 1 ;
5375
+ }
5376
+ }
5377
+
5378
+ /* todo: why are these sometimes null? */
5379
+ return 0 ;
5380
+ }
5381
+
5352
5382
void zend_compile_stmt_list (zend_ast * ast ) /* {{{ */
5353
5383
{
5354
- zend_ast_list * list = zend_ast_get_list (ast );
5355
- uint32_t i ;
5356
- for (i = 0 ; i < list -> children ; ++ i ) {
5357
- zend_compile_stmt (list -> child [i ]);
5384
+ zend_ast_list * const list = zend_ast_get_list (ast );
5385
+ zend_ast * * const begin = list -> child ;
5386
+ zend_ast * * const end = begin + list -> children ;
5387
+ zend_ast * * first_decl = _ast_find (begin , end , & _is_type_decl );
5388
+ zend_ast * * p ;
5389
+
5390
+ /* Compile opcodes before first type decl */
5391
+ for (p = begin ; p < first_decl ; ++ p ) {
5392
+ zend_compile_stmt (* p );
5393
+ }
5394
+
5395
+ /* Compile decl stmts */
5396
+ while (first_decl != end ) {
5397
+ zend_ast * * last_decl = _ast_find (first_decl , end , & _is_not_decl_stmt );
5398
+ HashTable unverified_types ;
5399
+ HashTable * prev_unverified_types ;
5400
+ _backup_unverified_variance_types (& unverified_types , & prev_unverified_types );
5401
+
5402
+ for (p = first_decl ; p < last_decl ; ++ p ) {
5403
+ zend_compile_stmt (* p );
5404
+ }
5405
+
5406
+ _compile_verify_variance (& unverified_types );
5407
+
5408
+ zend_hash_destroy (& unverified_types );
5409
+ CG (unverified_types ) = prev_unverified_types ;
5410
+
5411
+ /* There can be non-consecutive type decls, so continue searching */
5412
+ first_decl = _ast_find (last_decl , end , & _is_type_decl );
5413
+
5414
+ /* Compile any stmts between the two type decls (or the end) */
5415
+ for (p = last_decl ; p < first_decl ; ++ p ) {
5416
+ zend_compile_stmt (* p );
5417
+ }
5358
5418
}
5359
5419
}
5360
5420
/* }}} */
@@ -6401,7 +6461,7 @@ void zend_compile_class_decl(zend_ast *ast, zend_bool toplevel) /* {{{ */
6401
6461
if (CG (unverified_types )) {
6402
6462
zend_hash_add_empty_element (CG (unverified_types ), lcname );
6403
6463
} else {
6404
- // todo: figure out why it's null; need a caller (somewhere) to initialize, emit, and destroy the unverified types
6464
+ ZEND_ASSERT ( 0 && " todo: find out why this is null" );
6405
6465
}
6406
6466
}
6407
6467
@@ -8082,36 +8142,6 @@ void zend_const_expr_to_zval(zval *result, zend_ast *ast) /* {{{ */
8082
8142
}
8083
8143
/* }}} */
8084
8144
8085
- static zend_bool _is_type_decl (zend_ast * ast ) {
8086
- return ast && ast -> kind == ZEND_AST_CLASS ;
8087
- }
8088
-
8089
- static zend_bool _is_not_decl_stmt (zend_ast * ast ) {
8090
- if (ast ) {
8091
- /* todo: what else should be considered a decl stmt? */
8092
- switch (ast -> kind ) {
8093
- case ZEND_AST_CLASS :
8094
- case ZEND_AST_CONST_DECL :
8095
- case ZEND_AST_FUNC_DECL :
8096
- return 0 ;
8097
-
8098
- default :
8099
- return 1 ;
8100
- }
8101
- }
8102
-
8103
- /* todo: why are these sometimes null? */
8104
- return 0 ;
8105
- }
8106
-
8107
- static zend_ast * * _ast_find (zend_ast * * begin , zend_ast * * end ,
8108
- zend_bool (* pred )(zend_ast * )) {
8109
- for (; begin < end ; ++ begin )
8110
- if (pred (* begin ))
8111
- return begin ;
8112
- return begin ;
8113
- }
8114
-
8115
8145
/* Same as compile_stmt, but with early binding */
8116
8146
void zend_compile_top_stmt (zend_ast * ast ) /* {{{ */
8117
8147
{
0 commit comments