@@ -5221,12 +5221,72 @@ void zend_compile_declare(zend_ast *ast) /* {{{ */
5221
5221
}
5222
5222
/* }}} */
5223
5223
5224
+ static zend_ast * * _ast_find (zend_ast * * begin , zend_ast * * end ,
5225
+ zend_bool (* pred )(zend_ast * )) {
5226
+ for (; begin < end ; ++ begin )
5227
+ if (pred (* begin ))
5228
+ return begin ;
5229
+ return begin ;
5230
+ }
5231
+
5232
+ static zend_bool _is_type_decl (zend_ast * ast ) {
5233
+ return ast && ast -> kind == ZEND_AST_CLASS ;
5234
+ }
5235
+
5236
+ static zend_bool _is_not_decl_stmt (zend_ast * ast ) {
5237
+ if (ast ) {
5238
+ /* todo: what else should be considered a decl stmt? */
5239
+ switch (ast -> kind ) {
5240
+ case ZEND_AST_CLASS :
5241
+ case ZEND_AST_CONST_DECL :
5242
+ case ZEND_AST_FUNC_DECL :
5243
+ return 0 ;
5244
+
5245
+ default :
5246
+ return 1 ;
5247
+ }
5248
+ }
5249
+
5250
+ /* todo: why are these sometimes null? */
5251
+ return 0 ;
5252
+ }
5253
+
5224
5254
void zend_compile_stmt_list (zend_ast * ast ) /* {{{ */
5225
5255
{
5226
- zend_ast_list * list = zend_ast_get_list (ast );
5227
- uint32_t i ;
5228
- for (i = 0 ; i < list -> children ; ++ i ) {
5229
- zend_compile_stmt (list -> child [i ]);
5256
+ zend_ast_list * const list = zend_ast_get_list (ast );
5257
+ zend_ast * * const begin = list -> child ;
5258
+ zend_ast * * const end = begin + list -> children ;
5259
+ zend_ast * * first_decl = _ast_find (begin , end , & _is_type_decl );
5260
+ zend_ast * * p ;
5261
+
5262
+ /* Compile opcodes before first type decl */
5263
+ for (p = begin ; p < first_decl ; ++ p ) {
5264
+ zend_compile_stmt (* p );
5265
+ }
5266
+
5267
+ /* Compile decl stmts */
5268
+ while (first_decl != end ) {
5269
+ zend_ast * * last_decl = _ast_find (first_decl , end , & _is_not_decl_stmt );
5270
+ HashTable unverified_types ;
5271
+ HashTable * prev_unverified_types ;
5272
+ _backup_unverified_variance_types (& unverified_types , & prev_unverified_types );
5273
+
5274
+ for (p = first_decl ; p < last_decl ; ++ p ) {
5275
+ zend_compile_stmt (* p );
5276
+ }
5277
+
5278
+ _compile_verify_variance (& unverified_types );
5279
+
5280
+ zend_hash_destroy (& unverified_types );
5281
+ CG (unverified_types ) = prev_unverified_types ;
5282
+
5283
+ /* There can be non-consecutive type decls, so continue searching */
5284
+ first_decl = _ast_find (last_decl , end , & _is_type_decl );
5285
+
5286
+ /* Compile any stmts between the two type decls (or the end) */
5287
+ for (p = last_decl ; p < first_decl ; ++ p ) {
5288
+ zend_compile_stmt (* p );
5289
+ }
5230
5290
}
5231
5291
}
5232
5292
/* }}} */
@@ -6343,7 +6403,7 @@ zend_op *zend_compile_class_decl(zend_ast *ast, zend_bool toplevel) /* {{{ */
6343
6403
if (CG (unverified_types )) {
6344
6404
zend_hash_add_empty_element (CG (unverified_types ), lcname );
6345
6405
} else {
6346
- // todo: figure out why it's null; need a caller (somewhere) to initialize, emit, and destroy the unverified types
6406
+ ZEND_ASSERT ( 0 && " todo: find out why this is null" );
6347
6407
}
6348
6408
}
6349
6409
@@ -8178,36 +8238,6 @@ void zend_const_expr_to_zval(zval *result, zend_ast *ast) /* {{{ */
8178
8238
}
8179
8239
/* }}} */
8180
8240
8181
- static zend_bool _is_type_decl (zend_ast * ast ) {
8182
- return ast && ast -> kind == ZEND_AST_CLASS ;
8183
- }
8184
-
8185
- static zend_bool _is_not_decl_stmt (zend_ast * ast ) {
8186
- if (ast ) {
8187
- /* todo: what else should be considered a decl stmt? */
8188
- switch (ast -> kind ) {
8189
- case ZEND_AST_CLASS :
8190
- case ZEND_AST_CONST_DECL :
8191
- case ZEND_AST_FUNC_DECL :
8192
- return 0 ;
8193
-
8194
- default :
8195
- return 1 ;
8196
- }
8197
- }
8198
-
8199
- /* todo: why are these sometimes null? */
8200
- return 0 ;
8201
- }
8202
-
8203
- static zend_ast * * _ast_find (zend_ast * * begin , zend_ast * * end ,
8204
- zend_bool (* pred )(zend_ast * )) {
8205
- for (; begin < end ; ++ begin )
8206
- if (pred (* begin ))
8207
- return begin ;
8208
- return begin ;
8209
- }
8210
-
8211
8241
/* Same as compile_stmt, but with early binding */
8212
8242
void zend_compile_top_stmt (zend_ast * ast ) /* {{{ */
8213
8243
{
0 commit comments