@@ -605,94 +605,48 @@ class YeetExprTree extends StandardPostOrderTree instanceof YeetExpr {
605
605
* `OrPat`s and `IdentPat`s.
606
606
*/
607
607
module PatternTrees {
608
- abstract class PreOrderPatTree extends PreOrderTree {
608
+ abstract class StandardPatTree extends StandardTree {
609
609
abstract Pat getPat ( int i ) ;
610
610
611
- private Pat getPatRanked ( int i ) {
611
+ Pat getPatRanked ( int i ) {
612
612
result = rank [ i + 1 ] ( Pat pat , int j | pat = this .getPat ( j ) | pat order by j )
613
613
}
614
614
615
- predicate isEmpty ( ) { not any ( Pat p ) = this .getPatRanked ( 0 ) }
616
-
617
- override predicate propagatesAbnormal ( AstNode child ) { child = this .getPatRanked ( _) }
615
+ override AstNode getChildNode ( int i ) { result = this .getPat ( i ) }
616
+ }
618
617
618
+ abstract class PreOrderPatTree extends StandardPatTree , StandardPreOrderTree {
619
619
override predicate succ ( AstNode pred , AstNode succ , Completion c ) {
620
- pred = this and
621
- completionIsValidFor ( c , this ) and
622
620
c .( MatchCompletion ) .succeeded ( ) and
623
- first ( this .getPatRanked ( 0 ) , succ )
624
- or
625
- exists ( int i | last ( this .getPatRanked ( i ) , pred , c ) |
626
- // Edge from successful pattern to the next
627
- c .( MatchCompletion ) .succeeded ( ) and
628
- first ( this .getPatRanked ( i + 1 ) , succ )
629
- )
630
- }
631
-
632
- override predicate last ( AstNode node , Completion c ) {
633
- node = this and
634
621
(
635
- completionIsValidFor ( c , this ) and c . ( MatchCompletion ) . failed ( )
622
+ StandardPatTree . super . succ ( pred , succ , c )
636
623
or
637
- this . isEmpty ( ) and node = this and c . ( MatchCompletion ) . succeeded ( )
624
+ pred = this and first ( this . getFirstChildNode ( ) , succ ) and completionIsValidFor ( c , this )
638
625
)
639
- or
640
- exists ( int i | last ( this .getPatRanked ( i ) , node , c ) |
641
- c .( MatchCompletion ) .failed ( )
642
- or
643
- not exists ( this .getPatRanked ( i + 1 ) ) and
644
- completionIsNormal ( c )
645
- )
646
- }
647
- }
648
-
649
- abstract class PostOrderPatTree extends PostOrderTree {
650
- abstract Pat getPat ( int i ) ;
651
-
652
- private Pat getPatRanked ( int i ) {
653
- result = rank [ i + 1 ] ( Pat pat , int j | pat = this .getPat ( j ) | pat order by j )
654
626
}
655
627
656
- override predicate propagatesAbnormal ( AstNode child ) { child = this .getPatRanked ( _) }
657
-
658
- override predicate first ( AstNode node ) {
659
- first ( this .getPat ( 0 ) , node )
628
+ override predicate last ( AstNode node , Completion c ) {
629
+ super .last ( node , c )
660
630
or
661
- not exists ( this .getPat ( _) ) and
662
- node = this
663
- }
664
-
665
- override predicate succ ( AstNode pred , AstNode succ , Completion c ) {
666
- exists ( int i | last ( this .getPat ( i ) , pred , c ) |
667
- // Edge from unsuccessful pattern to the next
668
- c .( MatchCompletion ) .failed ( ) and
669
- first ( this .getPat ( i + 1 ) , succ )
670
- or
671
- // Edge from successful pattern to this
672
- c .( MatchCompletion ) .succeeded ( ) and
673
- succ = this
674
- or
675
- // Edge from last pattern to this
676
- not exists ( this .getPat ( i + 1 ) ) and
677
- succ = this and
678
- completionIsNormal ( c )
679
- )
631
+ c .( MatchCompletion ) .failed ( ) and
632
+ completionIsValidFor ( c , this ) and
633
+ ( node = this or last ( this .getPatRanked ( _) , node , c ) )
680
634
}
681
635
}
682
636
637
+ abstract class PostOrderPatTree extends StandardPatTree , StandardPostOrderTree { }
638
+
683
639
class IdentPatTree extends PostOrderPatTree , IdentPat {
684
640
override Pat getPat ( int i ) { i = 0 and result = this .getPat ( ) }
685
641
686
642
override predicate last ( AstNode node , Completion c ) {
687
643
super .last ( node , c )
688
644
or
689
- last ( this .getPat ( ) , node , c ) and
690
- c .( MatchCompletion ) .failed ( )
645
+ last ( this .getPat ( ) , node , c ) and c .( MatchCompletion ) .failed ( )
691
646
}
692
647
693
648
override predicate succ ( AstNode pred , AstNode succ , Completion c ) {
694
- super .succ ( pred , succ , c ) and
695
- not ( succ = this and c .( MatchCompletion ) .failed ( ) )
649
+ super .succ ( pred , succ , c ) and c .( MatchCompletion ) .succeeded ( )
696
650
}
697
651
}
698
652
@@ -710,6 +664,14 @@ module PatternTrees {
710
664
711
665
class OrPatTree extends PostOrderPatTree instanceof OrPat {
712
666
override Pat getPat ( int i ) { result = OrPat .super .getPat ( i ) }
667
+
668
+ override predicate succ ( AstNode pred , AstNode succ , Completion c ) {
669
+ // Failed patterns advance normally between children
670
+ c .( MatchCompletion ) .failed ( ) and super .succ ( pred , succ , c )
671
+ or
672
+ // Successful pattern step to this
673
+ c .( MatchCompletion ) .succeeded ( ) and succ = this and last ( this .getPat ( _) , pred , c )
674
+ }
713
675
}
714
676
715
677
class ParenPatTree extends ControlFlowTree , ParenPat {
0 commit comments