@@ -225,8 +225,9 @@ static void init_compiler_declarables(void) /* {{{ */
225
225
}
226
226
/* }}} */
227
227
228
- void zend_init_compiler_context ( void ) /* {{{ */
228
+ void zend_oparray_context_begin ( zend_oparray_context * prev_context ) /* {{{ */
229
229
{
230
+ * prev_context = CG (context );
230
231
CG (context ).opcodes_size = INITIAL_OP_ARRAY_SIZE ;
231
232
CG (context ).vars_size = 0 ;
232
233
CG (context ).literals_size = 0 ;
@@ -238,6 +239,56 @@ void zend_init_compiler_context(void) /* {{{ */
238
239
}
239
240
/* }}} */
240
241
242
+ void zend_oparray_context_end (zend_oparray_context * prev_context ) /* {{{ */
243
+ {
244
+ if (CG (context ).labels ) {
245
+ zend_hash_destroy (CG (context ).labels );
246
+ FREE_HASHTABLE (CG (context ).labels );
247
+ CG (context ).labels = NULL ;
248
+ }
249
+ CG (context ) = * prev_context ;
250
+ }
251
+ /* }}} */
252
+
253
+ static void zend_reset_import_tables (void ) /* {{{ */
254
+ {
255
+ zend_file_context * ctx = & CG (file_context );
256
+ if (ctx -> imports ) {
257
+ zend_hash_destroy (ctx -> imports );
258
+ efree (ctx -> imports );
259
+ ctx -> imports = NULL ;
260
+ }
261
+
262
+ if (ctx -> imports_function ) {
263
+ zend_hash_destroy (ctx -> imports_function );
264
+ efree (ctx -> imports_function );
265
+ ctx -> imports_function = NULL ;
266
+ }
267
+
268
+ if (ctx -> imports_const ) {
269
+ zend_hash_destroy (ctx -> imports_const );
270
+ efree (ctx -> imports_const );
271
+ ctx -> imports_const = NULL ;
272
+ }
273
+ }
274
+ /* }}} */
275
+
276
+ void zend_file_context_begin (zend_file_context * prev_context ) /* {{{ */
277
+ {
278
+ * prev_context = CG (file_context );
279
+ CG (file_context ).imports = NULL ;
280
+ CG (file_context ).imports_function = NULL ;
281
+ CG (file_context ).imports_const = NULL ;
282
+ }
283
+ /* }}} */
284
+
285
+ void zend_file_context_end (zend_file_context * prev_context ) /* {{{ */
286
+ {
287
+ zend_reset_import_tables ();
288
+ CG (file_context ) = * prev_context ;
289
+ }
290
+ /* }}} */
291
+
241
292
void zend_init_compiler_data_structures (void ) /* {{{ */
242
293
{
243
294
zend_stack_init (& CG (loop_var_stack ), sizeof (znode ));
@@ -248,12 +299,8 @@ void zend_init_compiler_data_structures(void) /* {{{ */
248
299
CG (current_namespace ) = NULL ;
249
300
CG (in_namespace ) = 0 ;
250
301
CG (has_bracketed_namespaces ) = 0 ;
251
- CG (current_import ) = NULL ;
252
- CG (current_import_function ) = NULL ;
253
- CG (current_import_const ) = NULL ;
254
302
zend_hash_init (& CG (const_filenames ), 8 , NULL , NULL , 0 );
255
303
init_compiler_declarables ();
256
- zend_stack_init (& CG (context_stack ), sizeof (CG (context )));
257
304
258
305
CG (encoding_declared ) = 0 ;
259
306
}
@@ -285,7 +332,6 @@ void shutdown_compiler(void) /* {{{ */
285
332
zend_stack_destroy (& CG (delayed_oplines_stack ));
286
333
zend_hash_destroy (& CG (filenames_table ));
287
334
zend_hash_destroy (& CG (const_filenames ));
288
- zend_stack_destroy (& CG (context_stack ));
289
335
zend_arena_destroy (CG (arena ));
290
336
}
291
337
/* }}} */
@@ -731,10 +777,10 @@ zend_string *zend_resolve_non_class_name(
731
777
* is_fully_qualified = 1 ;
732
778
}
733
779
734
- if (compound && CG (current_import ) ) {
780
+ if (compound && CG (file_context ). imports ) {
735
781
/* If the first part of a qualified name is an alias, substitute it. */
736
782
size_t len = compound - name -> val ;
737
- zend_string * import_name = zend_hash_find_ptr_lc (CG (current_import ) , name -> val , len );
783
+ zend_string * import_name = zend_hash_find_ptr_lc (CG (file_context ). imports , name -> val , len );
738
784
739
785
if (import_name ) {
740
786
return zend_concat_names (
@@ -749,13 +795,13 @@ zend_string *zend_resolve_non_class_name(
749
795
zend_string * zend_resolve_function_name (zend_string * name , uint32_t type , zend_bool * is_fully_qualified ) /* {{{ */
750
796
{
751
797
return zend_resolve_non_class_name (
752
- name , type , is_fully_qualified , 0 , CG (current_import_function ) );
798
+ name , type , is_fully_qualified , 0 , CG (file_context ). imports_function );
753
799
}
754
800
/* }}} */
755
801
756
802
zend_string * zend_resolve_const_name (zend_string * name , uint32_t type , zend_bool * is_fully_qualified ) /* {{{ */ {
757
803
return zend_resolve_non_class_name (
758
- name , type , is_fully_qualified , 1 , CG (current_import_const ) );
804
+ name , type , is_fully_qualified , 1 , CG (file_context ). imports_const );
759
805
}
760
806
/* }}} */
761
807
@@ -781,12 +827,13 @@ zend_string *zend_resolve_class_name(zend_string *name, uint32_t type) /* {{{ */
781
827
return name ;
782
828
}
783
829
784
- if (CG (current_import ) ) {
830
+ if (CG (file_context ). imports ) {
785
831
compound = memchr (name -> val , '\\' , name -> len );
786
832
if (compound ) {
787
833
/* If the first part of a qualified name is an alias, substitute it. */
788
834
size_t len = compound - name -> val ;
789
- zend_string * import_name = zend_hash_find_ptr_lc (CG (current_import ), name -> val , len );
835
+ zend_string * import_name =
836
+ zend_hash_find_ptr_lc (CG (file_context ).imports , name -> val , len );
790
837
791
838
if (import_name ) {
792
839
return zend_concat_names (
@@ -795,7 +842,7 @@ zend_string *zend_resolve_class_name(zend_string *name, uint32_t type) /* {{{ */
795
842
} else {
796
843
/* If an unqualified name is an alias, replace it. */
797
844
zend_string * import_name
798
- = zend_hash_find_ptr_lc (CG (current_import ) , name -> val , name -> len );
845
+ = zend_hash_find_ptr_lc (CG (file_context ). imports , name -> val , name -> len );
799
846
800
847
if (import_name ) {
801
848
return zend_string_copy (import_name );
@@ -881,21 +928,6 @@ void zend_resolve_goto_label(zend_op_array *op_array, zend_op *opline, int pass2
881
928
}
882
929
/* }}} */
883
930
884
- void zend_release_labels (int temporary ) /* {{{ */
885
- {
886
- if (CG (context ).labels ) {
887
- zend_hash_destroy (CG (context ).labels );
888
- FREE_HASHTABLE (CG (context ).labels );
889
- CG (context ).labels = NULL ;
890
- }
891
- if (!temporary && !zend_stack_is_empty (& CG (context_stack ))) {
892
- zend_compiler_context * ctx = zend_stack_top (& CG (context_stack ));
893
- CG (context ) = * ctx ;
894
- zend_stack_del_top (& CG (context_stack ));
895
- }
896
- }
897
- /* }}} */
898
-
899
931
static zend_bool zend_is_call (zend_ast * ast );
900
932
901
933
static int generate_free_loop_var (znode * var ) /* {{{ */
@@ -1621,28 +1653,6 @@ void zend_verify_namespace(void) /* {{{ */
1621
1653
}
1622
1654
/* }}} */
1623
1655
1624
- static void zend_reset_import_tables (void ) /* {{{ */
1625
- {
1626
- if (CG (current_import )) {
1627
- zend_hash_destroy (CG (current_import ));
1628
- efree (CG (current_import ));
1629
- CG (current_import ) = NULL ;
1630
- }
1631
-
1632
- if (CG (current_import_function )) {
1633
- zend_hash_destroy (CG (current_import_function ));
1634
- efree (CG (current_import_function ));
1635
- CG (current_import_function ) = NULL ;
1636
- }
1637
-
1638
- if (CG (current_import_const )) {
1639
- zend_hash_destroy (CG (current_import_const ));
1640
- efree (CG (current_import_const ));
1641
- CG (current_import_const ) = NULL ;
1642
- }
1643
- }
1644
- /* }}} */
1645
-
1646
1656
static void zend_end_namespace (void ) /* {{{ */ {
1647
1657
CG (in_namespace ) = 0 ;
1648
1658
zend_reset_import_tables ();
@@ -4503,8 +4513,8 @@ static void zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_as
4503
4513
4504
4514
lcname = zend_string_tolower (name );
4505
4515
4506
- if (CG (current_import_function ) ) {
4507
- zend_string * import_name = zend_hash_find_ptr (CG (current_import_function ) , lcname );
4516
+ if (CG (file_context ). imports_function ) {
4517
+ zend_string * import_name = zend_hash_find_ptr (CG (file_context ). imports_function , lcname );
4508
4518
if (import_name && !zend_string_equals_ci (lcname , import_name )) {
4509
4519
zend_error_noreturn (E_COMPILE_ERROR , "Cannot declare function %s "
4510
4520
"because the name is already in use" , name -> val );
@@ -4551,6 +4561,7 @@ void zend_compile_func_decl(znode *result, zend_ast *ast) /* {{{ */
4551
4561
4552
4562
zend_op_array * orig_op_array = CG (active_op_array );
4553
4563
zend_op_array * op_array = zend_arena_alloc (& CG (arena ), sizeof (zend_op_array ));
4564
+ zend_oparray_context orig_oparray_context ;
4554
4565
4555
4566
// TODO.AST interactive (not just here - also bpc etc!)
4556
4567
@@ -4575,8 +4586,7 @@ void zend_compile_func_decl(znode *result, zend_ast *ast) /* {{{ */
4575
4586
}
4576
4587
4577
4588
CG (active_op_array ) = op_array ;
4578
- zend_stack_push (& CG (context_stack ), (void * ) & CG (context ));
4579
- zend_init_compiler_context ();
4589
+ zend_oparray_context_begin (& orig_oparray_context );
4580
4590
4581
4591
if (CG (compiler_options ) & ZEND_COMPILE_EXTENDED_INFO ) {
4582
4592
zend_op * opline_ext = zend_emit_op (NULL , ZEND_EXT_NOP , NULL , NULL );
@@ -4606,7 +4616,7 @@ void zend_compile_func_decl(znode *result, zend_ast *ast) /* {{{ */
4606
4616
zend_emit_final_return (NULL );
4607
4617
4608
4618
pass_two (CG (active_op_array ));
4609
- zend_release_labels ( 0 );
4619
+ zend_oparray_context_end ( & orig_oparray_context );
4610
4620
4611
4621
/* Pop the loop variable stack separator */
4612
4622
zend_stack_del_top (& CG (loop_var_stack ));
@@ -4884,8 +4894,8 @@ void zend_compile_class_decl(zend_ast *ast) /* {{{ */
4884
4894
4885
4895
lcname = zend_string_tolower (name );
4886
4896
4887
- if (CG (current_import ) ) {
4888
- import_name = zend_hash_find_ptr (CG (current_import ) , lcname );
4897
+ if (CG (file_context ). imports ) {
4898
+ import_name = zend_hash_find_ptr (CG (file_context ). imports , lcname );
4889
4899
}
4890
4900
4891
4901
if (CG (current_namespace )) {
@@ -5036,25 +5046,26 @@ void zend_compile_class_decl(zend_ast *ast) /* {{{ */
5036
5046
5037
5047
static HashTable * zend_get_import_ht (uint32_t type ) /* {{{ */
5038
5048
{
5049
+ zend_file_context * ctx = & CG (file_context );
5039
5050
switch (type ) {
5040
5051
case T_CLASS :
5041
- if (!CG ( current_import ) ) {
5042
- CG ( current_import ) = emalloc (sizeof (HashTable ));
5043
- zend_hash_init (CG ( current_import ) , 8 , NULL , str_dtor , 0 );
5052
+ if (!ctx -> imports ) {
5053
+ ctx -> imports = emalloc (sizeof (HashTable ));
5054
+ zend_hash_init (ctx -> imports , 8 , NULL , str_dtor , 0 );
5044
5055
}
5045
- return CG ( current_import ) ;
5056
+ return ctx -> imports ;
5046
5057
case T_FUNCTION :
5047
- if (!CG ( current_import_function ) ) {
5048
- CG ( current_import_function ) = emalloc (sizeof (HashTable ));
5049
- zend_hash_init (CG ( current_import_function ) , 8 , NULL , str_dtor , 0 );
5058
+ if (!ctx -> imports_function ) {
5059
+ ctx -> imports_function = emalloc (sizeof (HashTable ));
5060
+ zend_hash_init (ctx -> imports_function , 8 , NULL , str_dtor , 0 );
5050
5061
}
5051
- return CG ( current_import_function ) ;
5062
+ return ctx -> imports_function ;
5052
5063
case T_CONST :
5053
- if (!CG ( current_import_const ) ) {
5054
- CG ( current_import_const ) = emalloc (sizeof (HashTable ));
5055
- zend_hash_init (CG ( current_import_const ) , 8 , NULL , str_dtor , 0 );
5064
+ if (!ctx -> imports_const ) {
5065
+ ctx -> imports_const = emalloc (sizeof (HashTable ));
5066
+ zend_hash_init (ctx -> imports_const , 8 , NULL , str_dtor , 0 );
5056
5067
}
5057
- return CG ( current_import_const ) ;
5068
+ return ctx -> imports_const ;
5058
5069
EMPTY_SWITCH_DEFAULT_CASE ()
5059
5070
}
5060
5071
@@ -5241,8 +5252,8 @@ void zend_compile_const_decl(zend_ast *ast) /* {{{ */
5241
5252
name = zend_prefix_with_ns (name );
5242
5253
name = zend_new_interned_string (name );
5243
5254
5244
- if (CG (current_import_const )
5245
- && (import_name = zend_hash_find_ptr (CG (current_import_const ) , name ))
5255
+ if (CG (file_context ). imports_const
5256
+ && (import_name = zend_hash_find_ptr (CG (file_context ). imports_const , name ))
5246
5257
) {
5247
5258
if (!zend_string_equals (import_name , name )) {
5248
5259
zend_error_noreturn (E_COMPILE_ERROR , "Cannot declare const %s because "
0 commit comments