@@ -5220,12 +5220,72 @@ void zend_compile_declare(zend_ast *ast) /* {{{ */
5220
5220
}
5221
5221
/* }}} */
5222
5222
5223
+ static zend_ast * * _ast_find (zend_ast * * begin , zend_ast * * end ,
5224
+ zend_bool (* pred )(zend_ast * )) {
5225
+ for (; begin < end ; ++ begin )
5226
+ if (pred (* begin ))
5227
+ return begin ;
5228
+ return begin ;
5229
+ }
5230
+
5231
+ static zend_bool _is_type_decl (zend_ast * ast ) {
5232
+ return ast && ast -> kind == ZEND_AST_CLASS ;
5233
+ }
5234
+
5235
+ static zend_bool _is_not_decl_stmt (zend_ast * ast ) {
5236
+ if (ast ) {
5237
+ /* todo: what else should be considered a decl stmt? */
5238
+ switch (ast -> kind ) {
5239
+ case ZEND_AST_CLASS :
5240
+ case ZEND_AST_CONST_DECL :
5241
+ case ZEND_AST_FUNC_DECL :
5242
+ return 0 ;
5243
+
5244
+ default :
5245
+ return 1 ;
5246
+ }
5247
+ }
5248
+
5249
+ /* todo: why are these sometimes null? */
5250
+ return 0 ;
5251
+ }
5252
+
5223
5253
void zend_compile_stmt_list (zend_ast * ast ) /* {{{ */
5224
5254
{
5225
- zend_ast_list * list = zend_ast_get_list (ast );
5226
- uint32_t i ;
5227
- for (i = 0 ; i < list -> children ; ++ i ) {
5228
- zend_compile_stmt (list -> child [i ]);
5255
+ zend_ast_list * const list = zend_ast_get_list (ast );
5256
+ zend_ast * * const begin = list -> child ;
5257
+ zend_ast * * const end = begin + list -> children ;
5258
+ zend_ast * * first_decl = _ast_find (begin , end , & _is_type_decl );
5259
+ zend_ast * * p ;
5260
+
5261
+ /* Compile opcodes before first type decl */
5262
+ for (p = begin ; p < first_decl ; ++ p ) {
5263
+ zend_compile_stmt (* p );
5264
+ }
5265
+
5266
+ /* Compile decl stmts */
5267
+ while (first_decl != end ) {
5268
+ zend_ast * * last_decl = _ast_find (first_decl , end , & _is_not_decl_stmt );
5269
+ HashTable unverified_types ;
5270
+ HashTable * prev_unverified_types ;
5271
+ _backup_unverified_variance_types (& unverified_types , & prev_unverified_types );
5272
+
5273
+ for (p = first_decl ; p < last_decl ; ++ p ) {
5274
+ zend_compile_stmt (* p );
5275
+ }
5276
+
5277
+ _compile_verify_variance (& unverified_types );
5278
+
5279
+ zend_hash_destroy (& unverified_types );
5280
+ CG (unverified_types ) = prev_unverified_types ;
5281
+
5282
+ /* There can be non-consecutive type decls, so continue searching */
5283
+ first_decl = _ast_find (last_decl , end , & _is_type_decl );
5284
+
5285
+ /* Compile any stmts between the two type decls (or the end) */
5286
+ for (p = last_decl ; p < first_decl ; ++ p ) {
5287
+ zend_compile_stmt (* p );
5288
+ }
5229
5289
}
5230
5290
}
5231
5291
/* }}} */
@@ -6327,7 +6387,7 @@ void zend_compile_class_decl(zend_ast *ast, zend_bool toplevel) /* {{{ */
6327
6387
if (CG (unverified_types )) {
6328
6388
zend_hash_add_empty_element (CG (unverified_types ), lcname );
6329
6389
} else {
6330
- // todo: figure out why it's null; need a caller (somewhere) to initialize, emit, and destroy the unverified types
6390
+ ZEND_ASSERT ( 0 && " todo: find out why this is null" );
6331
6391
}
6332
6392
}
6333
6393
@@ -8129,36 +8189,6 @@ void zend_const_expr_to_zval(zval *result, zend_ast *ast) /* {{{ */
8129
8189
}
8130
8190
/* }}} */
8131
8191
8132
- static zend_bool _is_type_decl (zend_ast * ast ) {
8133
- return ast && ast -> kind == ZEND_AST_CLASS ;
8134
- }
8135
-
8136
- static zend_bool _is_not_decl_stmt (zend_ast * ast ) {
8137
- if (ast ) {
8138
- /* todo: what else should be considered a decl stmt? */
8139
- switch (ast -> kind ) {
8140
- case ZEND_AST_CLASS :
8141
- case ZEND_AST_CONST_DECL :
8142
- case ZEND_AST_FUNC_DECL :
8143
- return 0 ;
8144
-
8145
- default :
8146
- return 1 ;
8147
- }
8148
- }
8149
-
8150
- /* todo: why are these sometimes null? */
8151
- return 0 ;
8152
- }
8153
-
8154
- static zend_ast * * _ast_find (zend_ast * * begin , zend_ast * * end ,
8155
- zend_bool (* pred )(zend_ast * )) {
8156
- for (; begin < end ; ++ begin )
8157
- if (pred (* begin ))
8158
- return begin ;
8159
- return begin ;
8160
- }
8161
-
8162
8192
/* Same as compile_stmt, but with early binding */
8163
8193
void zend_compile_top_stmt (zend_ast * ast ) /* {{{ */
8164
8194
{
0 commit comments