@@ -498,17 +498,23 @@ zend_class_entry *zend_ast_fetch_class(zend_ast *ast, zend_class_entry *scope)
498
498
return zend_fetch_class_with_scope (zend_ast_get_str (ast ), (ast -> attr >> ZEND_CONST_EXPR_NEW_FETCH_TYPE_SHIFT ) | ZEND_FETCH_CLASS_EXCEPTION , scope );
499
499
}
500
500
501
- ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_ex (zval * result , zend_ast * ast , zend_class_entry * scope , zend_ast_evaluate_ctx * ctx )
502
- {
501
+ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_ex (
502
+ zval * result ,
503
+ zend_ast * ast ,
504
+ zend_class_entry * scope ,
505
+ bool * short_circuited_ptr ,
506
+ zend_ast_evaluate_ctx * ctx
507
+ ) {
503
508
zval op1 , op2 ;
504
509
zend_result ret = SUCCESS ;
505
- ctx -> short_circuited = false;
510
+ bool short_circuited ;
511
+ * short_circuited_ptr = false;
506
512
507
513
switch (ast -> kind ) {
508
514
case ZEND_AST_BINARY_OP :
509
- if (UNEXPECTED (zend_ast_evaluate_ex (& op1 , ast -> child [0 ], scope , ctx ) != SUCCESS )) {
515
+ if (UNEXPECTED (zend_ast_evaluate_ex (& op1 , ast -> child [0 ], scope , & short_circuited , ctx ) != SUCCESS )) {
510
516
ret = FAILURE ;
511
- } else if (UNEXPECTED (zend_ast_evaluate_ex (& op2 , ast -> child [1 ], scope , ctx ) != SUCCESS )) {
517
+ } else if (UNEXPECTED (zend_ast_evaluate_ex (& op2 , ast -> child [1 ], scope , & short_circuited , ctx ) != SUCCESS )) {
512
518
zval_ptr_dtor_nogc (& op1 );
513
519
ret = FAILURE ;
514
520
} else {
@@ -520,9 +526,9 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_ex(zval *result, zend_ast *
520
526
break ;
521
527
case ZEND_AST_GREATER :
522
528
case ZEND_AST_GREATER_EQUAL :
523
- if (UNEXPECTED (zend_ast_evaluate_ex (& op1 , ast -> child [0 ], scope , ctx ) != SUCCESS )) {
529
+ if (UNEXPECTED (zend_ast_evaluate_ex (& op1 , ast -> child [0 ], scope , & short_circuited , ctx ) != SUCCESS )) {
524
530
ret = FAILURE ;
525
- } else if (UNEXPECTED (zend_ast_evaluate_ex (& op2 , ast -> child [1 ], scope , ctx ) != SUCCESS )) {
531
+ } else if (UNEXPECTED (zend_ast_evaluate_ex (& op2 , ast -> child [1 ], scope , & short_circuited , ctx ) != SUCCESS )) {
526
532
zval_ptr_dtor_nogc (& op1 );
527
533
ret = FAILURE ;
528
534
} else {
@@ -535,7 +541,7 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_ex(zval *result, zend_ast *
535
541
}
536
542
break ;
537
543
case ZEND_AST_UNARY_OP :
538
- if (UNEXPECTED (zend_ast_evaluate_ex (& op1 , ast -> child [0 ], scope , ctx ) != SUCCESS )) {
544
+ if (UNEXPECTED (zend_ast_evaluate_ex (& op1 , ast -> child [0 ], scope , & short_circuited , ctx ) != SUCCESS )) {
539
545
ret = FAILURE ;
540
546
} else {
541
547
unary_op_type op = get_unary_op (ast -> attr );
@@ -588,12 +594,12 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_ex(zval *result, zend_ast *
588
594
}
589
595
break ;
590
596
case ZEND_AST_AND :
591
- if (UNEXPECTED (zend_ast_evaluate_ex (& op1 , ast -> child [0 ], scope , ctx ) != SUCCESS )) {
597
+ if (UNEXPECTED (zend_ast_evaluate_ex (& op1 , ast -> child [0 ], scope , & short_circuited , ctx ) != SUCCESS )) {
592
598
ret = FAILURE ;
593
599
break ;
594
600
}
595
601
if (zend_is_true (& op1 )) {
596
- if (UNEXPECTED (zend_ast_evaluate_ex (& op2 , ast -> child [1 ], scope , ctx ) != SUCCESS )) {
602
+ if (UNEXPECTED (zend_ast_evaluate_ex (& op2 , ast -> child [1 ], scope , & short_circuited , ctx ) != SUCCESS )) {
597
603
zval_ptr_dtor_nogc (& op1 );
598
604
ret = FAILURE ;
599
605
break ;
@@ -606,14 +612,14 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_ex(zval *result, zend_ast *
606
612
zval_ptr_dtor_nogc (& op1 );
607
613
break ;
608
614
case ZEND_AST_OR :
609
- if (UNEXPECTED (zend_ast_evaluate_ex (& op1 , ast -> child [0 ], scope , ctx ) != SUCCESS )) {
615
+ if (UNEXPECTED (zend_ast_evaluate_ex (& op1 , ast -> child [0 ], scope , & short_circuited , ctx ) != SUCCESS )) {
610
616
ret = FAILURE ;
611
617
break ;
612
618
}
613
619
if (zend_is_true (& op1 )) {
614
620
ZVAL_TRUE (result );
615
621
} else {
616
- if (UNEXPECTED (zend_ast_evaluate_ex (& op2 , ast -> child [1 ], scope , ctx ) != SUCCESS )) {
622
+ if (UNEXPECTED (zend_ast_evaluate_ex (& op2 , ast -> child [1 ], scope , & short_circuited , ctx ) != SUCCESS )) {
617
623
zval_ptr_dtor_nogc (& op1 );
618
624
ret = FAILURE ;
619
625
break ;
@@ -624,23 +630,23 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_ex(zval *result, zend_ast *
624
630
zval_ptr_dtor_nogc (& op1 );
625
631
break ;
626
632
case ZEND_AST_CONDITIONAL :
627
- if (UNEXPECTED (zend_ast_evaluate_ex (& op1 , ast -> child [0 ], scope , ctx ) != SUCCESS )) {
633
+ if (UNEXPECTED (zend_ast_evaluate_ex (& op1 , ast -> child [0 ], scope , & short_circuited , ctx ) != SUCCESS )) {
628
634
ret = FAILURE ;
629
635
break ;
630
636
}
631
637
if (zend_is_true (& op1 )) {
632
638
if (!ast -> child [1 ]) {
633
639
* result = op1 ;
634
640
} else {
635
- if (UNEXPECTED (zend_ast_evaluate_ex (result , ast -> child [1 ], scope , ctx ) != SUCCESS )) {
641
+ if (UNEXPECTED (zend_ast_evaluate_ex (result , ast -> child [1 ], scope , & short_circuited , ctx ) != SUCCESS )) {
636
642
zval_ptr_dtor_nogc (& op1 );
637
643
ret = FAILURE ;
638
644
break ;
639
645
}
640
646
zval_ptr_dtor_nogc (& op1 );
641
647
}
642
648
} else {
643
- if (UNEXPECTED (zend_ast_evaluate_ex (result , ast -> child [2 ], scope , ctx ) != SUCCESS )) {
649
+ if (UNEXPECTED (zend_ast_evaluate_ex (result , ast -> child [2 ], scope , & short_circuited , ctx ) != SUCCESS )) {
644
650
zval_ptr_dtor_nogc (& op1 );
645
651
ret = FAILURE ;
646
652
break ;
@@ -649,14 +655,14 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_ex(zval *result, zend_ast *
649
655
}
650
656
break ;
651
657
case ZEND_AST_COALESCE :
652
- if (UNEXPECTED (zend_ast_evaluate_ex (& op1 , ast -> child [0 ], scope , ctx ) != SUCCESS )) {
658
+ if (UNEXPECTED (zend_ast_evaluate_ex (& op1 , ast -> child [0 ], scope , & short_circuited , ctx ) != SUCCESS )) {
653
659
ret = FAILURE ;
654
660
break ;
655
661
}
656
662
if (Z_TYPE (op1 ) > IS_NULL ) {
657
663
* result = op1 ;
658
664
} else {
659
- if (UNEXPECTED (zend_ast_evaluate_ex (result , ast -> child [1 ], scope , ctx ) != SUCCESS )) {
665
+ if (UNEXPECTED (zend_ast_evaluate_ex (result , ast -> child [1 ], scope , & short_circuited , ctx ) != SUCCESS )) {
660
666
zval_ptr_dtor_nogc (& op1 );
661
667
ret = FAILURE ;
662
668
break ;
@@ -665,7 +671,7 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_ex(zval *result, zend_ast *
665
671
}
666
672
break ;
667
673
case ZEND_AST_UNARY_PLUS :
668
- if (UNEXPECTED (zend_ast_evaluate_ex (& op2 , ast -> child [0 ], scope , ctx ) != SUCCESS )) {
674
+ if (UNEXPECTED (zend_ast_evaluate_ex (& op2 , ast -> child [0 ], scope , & short_circuited , ctx ) != SUCCESS )) {
669
675
ret = FAILURE ;
670
676
} else {
671
677
ZVAL_LONG (& op1 , 0 );
@@ -674,7 +680,7 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_ex(zval *result, zend_ast *
674
680
}
675
681
break ;
676
682
case ZEND_AST_UNARY_MINUS :
677
- if (UNEXPECTED (zend_ast_evaluate_ex (& op2 , ast -> child [0 ], scope , ctx ) != SUCCESS )) {
683
+ if (UNEXPECTED (zend_ast_evaluate_ex (& op2 , ast -> child [0 ], scope , & short_circuited , ctx ) != SUCCESS )) {
678
684
ret = FAILURE ;
679
685
} else {
680
686
ZVAL_LONG (& op1 , 0 );
@@ -695,7 +701,7 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_ex(zval *result, zend_ast *
695
701
for (i = 0 ; i < list -> children ; i ++ ) {
696
702
zend_ast * elem = list -> child [i ];
697
703
if (elem -> kind == ZEND_AST_UNPACK ) {
698
- if (UNEXPECTED (zend_ast_evaluate_ex (& op1 , elem -> child [0 ], scope , ctx ) != SUCCESS )) {
704
+ if (UNEXPECTED (zend_ast_evaluate_ex (& op1 , elem -> child [0 ], scope , & short_circuited , ctx ) != SUCCESS )) {
699
705
zval_ptr_dtor_nogc (result );
700
706
return FAILURE ;
701
707
}
@@ -708,14 +714,14 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_ex(zval *result, zend_ast *
708
714
continue ;
709
715
}
710
716
if (elem -> child [1 ]) {
711
- if (UNEXPECTED (zend_ast_evaluate_ex (& op1 , elem -> child [1 ], scope , ctx ) != SUCCESS )) {
717
+ if (UNEXPECTED (zend_ast_evaluate_ex (& op1 , elem -> child [1 ], scope , & short_circuited , ctx ) != SUCCESS )) {
712
718
zval_ptr_dtor_nogc (result );
713
719
return FAILURE ;
714
720
}
715
721
} else {
716
722
ZVAL_UNDEF (& op1 );
717
723
}
718
- if (UNEXPECTED (zend_ast_evaluate_ex (& op2 , elem -> child [0 ], scope , ctx ) != SUCCESS )) {
724
+ if (UNEXPECTED (zend_ast_evaluate_ex (& op2 , elem -> child [0 ], scope , & short_circuited , ctx ) != SUCCESS )) {
719
725
zval_ptr_dtor_nogc (& op1 );
720
726
zval_ptr_dtor_nogc (result );
721
727
return FAILURE ;
@@ -734,11 +740,12 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_ex(zval *result, zend_ast *
734
740
zend_error_noreturn (E_COMPILE_ERROR , "Cannot use [] for reading" );
735
741
}
736
742
737
- if (UNEXPECTED (zend_ast_evaluate_ex (& op1 , ast -> child [0 ], scope , ctx ) != SUCCESS )) {
743
+ if (UNEXPECTED (zend_ast_evaluate_ex (& op1 , ast -> child [0 ], scope , & short_circuited , ctx ) != SUCCESS )) {
738
744
ret = FAILURE ;
739
745
break ;
740
746
}
741
- if (ctx -> short_circuited ) {
747
+ if (short_circuited ) {
748
+ * short_circuited_ptr = true;
742
749
ZVAL_NULL (result );
743
750
return SUCCESS ;
744
751
}
@@ -751,7 +758,7 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_ex(zval *result, zend_ast *
751
758
break ;
752
759
}
753
760
754
- if (UNEXPECTED (zend_ast_evaluate_ex (& op2 , ast -> child [1 ], scope , ctx ) != SUCCESS )) {
761
+ if (UNEXPECTED (zend_ast_evaluate_ex (& op2 , ast -> child [1 ], scope , & short_circuited , ctx ) != SUCCESS )) {
755
762
zval_ptr_dtor_nogc (& op1 );
756
763
ret = FAILURE ;
757
764
break ;
@@ -785,7 +792,7 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_ex(zval *result, zend_ast *
785
792
zval case_value_zv ;
786
793
ZVAL_UNDEF (& case_value_zv );
787
794
if (case_value_ast != NULL ) {
788
- if (UNEXPECTED (zend_ast_evaluate_ex (& case_value_zv , case_value_ast , scope , ctx ) != SUCCESS )) {
795
+ if (UNEXPECTED (zend_ast_evaluate_ex (& case_value_zv , case_value_ast , scope , & short_circuited , ctx ) != SUCCESS )) {
789
796
return FAILURE ;
790
797
}
791
798
}
@@ -847,7 +854,7 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_ex(zval *result, zend_ast *
847
854
name = zend_ast_get_str (arg_ast -> child [0 ]);
848
855
arg_ast = arg_ast -> child [1 ];
849
856
}
850
- if (zend_ast_evaluate_ex (& arg , arg_ast , scope , ctx ) == FAILURE ) {
857
+ if (zend_ast_evaluate_ex (& arg , arg_ast , scope , & short_circuited , ctx ) == FAILURE ) {
851
858
zend_array_destroy (args );
852
859
zval_ptr_dtor (result );
853
860
return FAILURE ;
@@ -877,7 +884,7 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_ex(zval *result, zend_ast *
877
884
ALLOCA_FLAG (use_heap )
878
885
zval * args = do_alloca (sizeof (zval ) * args_ast -> children , use_heap );
879
886
for (uint32_t i = 0 ; i < args_ast -> children ; i ++ ) {
880
- if (zend_ast_evaluate_ex (& args [i ], args_ast -> child [i ], scope , ctx ) == FAILURE ) {
887
+ if (zend_ast_evaluate_ex (& args [i ], args_ast -> child [i ], scope , & short_circuited , ctx ) == FAILURE ) {
881
888
for (uint32_t j = 0 ; j < i ; j ++ ) {
882
889
zval_ptr_dtor (& args [j ]);
883
890
}
@@ -909,20 +916,21 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_ex(zval *result, zend_ast *
909
916
case ZEND_AST_PROP :
910
917
case ZEND_AST_NULLSAFE_PROP :
911
918
{
912
- if (UNEXPECTED (zend_ast_evaluate_ex (& op1 , ast -> child [0 ], scope , ctx ) != SUCCESS )) {
919
+ if (UNEXPECTED (zend_ast_evaluate_ex (& op1 , ast -> child [0 ], scope , & short_circuited , ctx ) != SUCCESS )) {
913
920
return FAILURE ;
914
921
}
915
- if (ctx -> short_circuited ) {
922
+ if (short_circuited ) {
923
+ * short_circuited_ptr = true;
916
924
ZVAL_NULL (result );
917
925
return SUCCESS ;
918
926
}
919
927
if (ast -> kind == ZEND_AST_NULLSAFE_PROP && Z_TYPE (op1 ) == IS_NULL ) {
920
- ctx -> short_circuited = true;
928
+ * short_circuited_ptr = true;
921
929
ZVAL_NULL (result );
922
930
return SUCCESS ;
923
931
}
924
932
925
- if (UNEXPECTED (zend_ast_evaluate_ex (& op2 , ast -> child [1 ], scope , ctx ) != SUCCESS )) {
933
+ if (UNEXPECTED (zend_ast_evaluate_ex (& op2 , ast -> child [1 ], scope , & short_circuited , ctx ) != SUCCESS )) {
926
934
zval_ptr_dtor_nogc (& op1 );
927
935
return FAILURE ;
928
936
}
@@ -976,7 +984,8 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_ex(zval *result, zend_ast *
976
984
ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate (zval * result , zend_ast * ast , zend_class_entry * scope )
977
985
{
978
986
zend_ast_evaluate_ctx ctx = {0 };
979
- return zend_ast_evaluate_ex (result , ast , scope , & ctx );
987
+ bool short_circuited ;
988
+ return zend_ast_evaluate_ex (result , ast , scope , & short_circuited , & ctx );
980
989
}
981
990
982
991
static size_t ZEND_FASTCALL zend_ast_tree_size (zend_ast * ast )
0 commit comments