@@ -429,12 +429,12 @@ module Trees {
429429 not c .( MatchingCompletion ) .getValue ( ) = false
430430 or
431431 not exists ( this .getElseBranch ( ) ) and
432- exists ( Completion lc , Expr lastBranch |
432+ exists ( MatchingCompletion lc , Expr lastBranch |
433433 lastBranch = max ( int i | | this .getBranch ( i ) order by i ) and
434- lc .( MatchingCompletion ) . getValue ( ) = false and
434+ lc .getValue ( ) = false and
435435 last ( lastBranch , last , lc ) and
436- c . getInnerCompletion ( ) = lc and
437- c instanceof RaiseCompletion
436+ c instanceof RaiseCompletion and
437+ not c instanceof NestedCompletion
438438 )
439439 }
440440
@@ -480,7 +480,8 @@ module Trees {
480480 final override predicate last ( AstNode last , Completion c ) {
481481 c .( MatchingCompletion ) .getValue ( ) = false and
482482 (
483- last = this
483+ last = this and
484+ c .isValidFor ( this )
484485 or
485486 exists ( AstNode node |
486487 node = this .getClass ( ) or
@@ -493,6 +494,7 @@ module Trees {
493494 or
494495 c .( MatchingCompletion ) .getValue ( ) = true and
495496 last = this and
497+ c .isValidFor ( this ) and
496498 not exists ( this .getPrefixElement ( _) ) and
497499 not exists ( this .getRestVariableAccess ( ) )
498500 or
@@ -512,14 +514,16 @@ module Trees {
512514 succ = this and
513515 c .( MatchingCompletion ) .getValue ( ) = true
514516 or
515- pred = this and
516- first ( this .getPrefixElement ( 0 ) , succ ) and
517- c .( MatchingCompletion ) .getValue ( ) = true
518- or
519- not exists ( this .getPrefixElement ( _) ) and
520- pred = this and
521- first ( this .getRestVariableAccess ( ) , succ ) and
522- c .( MatchingCompletion ) .getValue ( ) = true
517+ exists ( AstNode next |
518+ pred = this and
519+ c .( MatchingCompletion ) .getValue ( ) = true and
520+ first ( next , succ )
521+ |
522+ next = this .getPrefixElement ( 0 )
523+ or
524+ not exists ( this .getPrefixElement ( _) ) and
525+ next = this .getRestVariableAccess ( )
526+ )
523527 or
524528 last ( max ( int i | | this .getPrefixElement ( i ) order by i ) , pred , c ) and
525529 first ( this .getRestVariableAccess ( ) , succ ) and
@@ -565,7 +569,8 @@ module Trees {
565569 or
566570 c .( MatchingCompletion ) .getValue ( ) = false and
567571 (
568- last = this
572+ last = this and
573+ c .isValidFor ( this )
569574 or
570575 exists ( AstNode node | node = this .getClass ( ) or node = this .getElement ( _) |
571576 last ( node , last , c )
@@ -578,14 +583,16 @@ module Trees {
578583 succ = this and
579584 c .( MatchingCompletion ) .getValue ( ) = true
580585 or
581- pred = this and
582- first ( this .getPrefixVariableAccess ( ) , succ ) and
583- c .( MatchingCompletion ) .getValue ( ) = true
584- or
585- pred = this and
586- first ( this .getElement ( 0 ) , succ ) and
587- not exists ( this .getPrefixVariableAccess ( ) ) and
588- c .( MatchingCompletion ) .getValue ( ) = true
586+ exists ( AstNode next |
587+ pred = this and
588+ c .( MatchingCompletion ) .getValue ( ) = true and
589+ first ( next , succ )
590+ |
591+ next = this .getPrefixVariableAccess ( )
592+ or
593+ not exists ( this .getPrefixVariableAccess ( ) ) and
594+ next = this .getElement ( 0 )
595+ )
589596 or
590597 last ( this .getPrefixVariableAccess ( ) , pred , c ) and
591598 first ( this .getElement ( 0 ) , succ ) and
@@ -619,7 +626,8 @@ module Trees {
619626 final override predicate last ( AstNode last , Completion c ) {
620627 c .( MatchingCompletion ) .getValue ( ) = false and
621628 (
622- last = this
629+ last = this and
630+ c .isValidFor ( this )
623631 or
624632 exists ( AstNode node |
625633 node = this .getClass ( ) or
@@ -646,14 +654,16 @@ module Trees {
646654 succ = this and
647655 c .( MatchingCompletion ) .getValue ( ) = true
648656 or
649- pred = this and
650- first ( this .getValue ( 0 ) , succ ) and
651- c .( MatchingCompletion ) .getValue ( ) = true
652- or
653- not exists ( this .getValue ( _) ) and
654- pred = this and
655- first ( this .getRestVariableAccess ( ) , succ ) and
656- c .( MatchingCompletion ) .getValue ( ) = true
657+ exists ( AstNode next |
658+ pred = this and
659+ c .( MatchingCompletion ) .getValue ( ) = true and
660+ first ( next , succ )
661+ |
662+ next = this .getValue ( 0 )
663+ or
664+ not exists ( this .getValue ( _) ) and
665+ next = this .getRestVariableAccess ( )
666+ )
657667 or
658668 last ( max ( int i | | this .getValue ( i ) order by i ) , pred , c ) and
659669 first ( this .getRestVariableAccess ( ) , succ ) and
@@ -732,20 +742,36 @@ module Trees {
732742 child = this .getCondition ( )
733743 }
734744
745+ private predicate lastCondition ( AstNode last , BooleanCompletion c , boolean flag ) {
746+ last ( this .getCondition ( ) , last , c ) and
747+ (
748+ flag = true and this .hasIfCondition ( )
749+ or
750+ flag = false and this .hasUnlessCondition ( )
751+ )
752+ }
753+
735754 final override predicate last ( AstNode last , Completion c ) {
736755 last ( this .getPattern ( ) , last , c ) and
737756 c .( MatchingCompletion ) .getValue ( ) = false
738757 or
739- exists ( Completion pc |
740- last ( this .getCondition ( ) , last , pc ) and
741- pc .( ConditionalCompletion ) .getValue ( ) = false and
742- c .( MatchingCompletion ) .getValue ( ) = false
758+ exists ( BooleanCompletion bc , boolean flag , MatchingCompletion mc |
759+ lastCondition ( last , bc , flag ) and
760+ c =
761+ any ( NestedMatchingCompletion nmc |
762+ nmc .getInnerCompletion ( ) = bc and nmc .getOuterCompletion ( ) = mc
763+ )
764+ |
765+ mc .getValue ( ) = false and
766+ bc .getValue ( ) = flag .booleanNot ( )
767+ or
768+ not exists ( this .getBody ( ) ) and
769+ mc .getValue ( ) = true and
770+ bc .getValue ( ) = flag
743771 )
744772 or
745773 last ( this .getBody ( ) , last , c )
746774 or
747- not exists ( this .getBody ( ) ) and last ( this .getCondition ( ) , last , c )
748- or
749775 not exists ( this .getBody ( ) ) and
750776 not exists ( this .getCondition ( ) ) and
751777 last ( this .getPattern ( ) , last , c )
@@ -766,15 +792,10 @@ module Trees {
766792 not exists ( this .getCondition ( ) ) and next = this .getBody ( )
767793 )
768794 or
769- exists ( Completion pc , boolean flag |
770- flag = true and this .hasIfCondition ( )
771- or
772- flag = false and this .hasUnlessCondition ( )
773- |
774- last ( this .getCondition ( ) , pred , pc ) and
775- pc .( ConditionalCompletion ) .getValue ( ) = flag and
776- first ( this .getBody ( ) , succ ) and
777- c .( MatchingCompletion ) .getValue ( ) = true
795+ exists ( boolean flag |
796+ lastCondition ( pred , c , flag ) and
797+ c .( BooleanCompletion ) .getValue ( ) = flag and
798+ first ( this .getBody ( ) , succ )
778799 )
779800 }
780801 }
0 commit comments