@@ -21,7 +21,7 @@ abstract private class Split_ extends TSplit {
21
21
22
22
final class Split = Split_ ;
23
23
24
- private module ConditionalCompletionSplitting {
24
+ module ConditionalCompletionSplitting {
25
25
/**
26
26
* A split for conditional completions. For example, in
27
27
*
@@ -39,77 +39,77 @@ private module ConditionalCompletionSplitting {
39
39
40
40
ConditionalCompletionSplit ( ) { this = TConditionalCompletionSplit ( completion ) }
41
41
42
+ ConditionalCompletion getCompletion ( ) { result = completion }
43
+
42
44
override string toString ( ) { result = completion .toString ( ) }
43
45
}
44
46
45
- private class ConditionalCompletionSplitKind extends SplitKind , TConditionalCompletionSplitKind {
47
+ private class ConditionalCompletionSplitKind_ extends SplitKind , TConditionalCompletionSplitKind {
46
48
override int getListOrder ( ) { result = 0 }
47
49
48
50
override predicate isEnabled ( AstNode cfe ) { this .appliesTo ( cfe ) }
49
51
50
52
override string toString ( ) { result = "ConditionalCompletion" }
51
53
}
52
54
53
- private class ConditionalCompletionSplitImpl extends SplitImpl instanceof ConditionalCompletionSplit
54
- {
55
- ConditionalCompletion completion ;
55
+ module ConditionalCompletionSplittingInput {
56
+ private import Completion as Comp
56
57
57
- ConditionalCompletionSplitImpl ( ) { this = TConditionalCompletionSplit ( completion ) }
58
+ class ConditionalCompletion = Comp :: ConditionalCompletion ;
58
59
59
- override ConditionalCompletionSplitKind getKind ( ) { any ( ) }
60
+ class ConditionalCompletionSplitKind extends ConditionalCompletionSplitKind_ , TSplitKind { }
60
61
61
- override predicate hasEntry ( AstNode pred , AstNode succ , Completion c ) {
62
- succ ( pred , succ , c ) and
63
- last ( succ , _, completion ) and
62
+ class ConditionalCompletionSplit = ConditionalCompletionSplitting:: ConditionalCompletionSplit ;
63
+
64
+ bindingset [ parent, parentCompletion]
65
+ predicate condPropagateExpr (
66
+ AstNode parent , ConditionalCompletion parentCompletion , AstNode child ,
67
+ ConditionalCompletion childCompletion
68
+ ) {
69
+ child = parent .( LogicalNotExpr ) .getExpr ( ) and
70
+ childCompletion .getDual ( ) = parentCompletion
71
+ or
72
+ childCompletion = parentCompletion and
64
73
(
65
- last ( succ .( LogicalNotExpr ) .getExpr ( ) , pred , c ) and
66
- completion .( BooleanCompletion ) .getDual ( ) = c
67
- or
68
- last ( succ .( BinaryLogicalOperation ) .getAnOperand ( ) , pred , c ) and
69
- completion = c
74
+ child = parent .( BinaryLogicalOperation ) .getAnOperand ( )
70
75
or
71
- succ =
72
- any ( IfExpr ie |
73
- last ( [ ie .getThen ( ) , ie .getElse ( ) ] , pred , c ) and
74
- completion = c
75
- )
76
+ parent = any ( IfExpr ie | child = [ ie .getThen ( ) , ie .getElse ( ) ] )
76
77
or
77
- last ( succ .( MatchExpr ) .getAnArm ( ) .getExpr ( ) , pred , c ) and
78
- completion = c
78
+ child = parent .( MatchExpr ) .getAnArm ( ) .getExpr ( )
79
79
or
80
- last ( succ .( BlockExpr ) .getStmtList ( ) .getTailExpr ( ) , pred , c ) and
81
- completion = c
80
+ child = parent .( BlockExpr ) .getStmtList ( ) .getTailExpr ( )
82
81
)
83
- or
84
- succ ( pred , succ , c ) and
85
- last ( succ .( BreakExpr ) .getExpr ( ) , pred , c ) and
86
- exists ( AstNode target |
87
- succ ( succ , target , _) and
88
- last ( target , _, completion )
89
- ) and
90
- completion = c
91
82
}
83
+ }
92
84
93
- override predicate hasEntryScope ( CfgScope scope , AstNode first ) { none ( ) }
94
-
95
- override predicate hasExit ( AstNode pred , AstNode succ , Completion c ) {
96
- this .appliesTo ( pred ) and
97
- succ ( pred , succ , c ) and
98
- if c instanceof ConditionalCompletion
99
- then completion = c
100
- else not this .hasSuccessor ( pred , succ , c )
85
+ private class ConditionalCompletionSplitImpl extends SplitImplementations:: ConditionalCompletionSplitting:: ConditionalCompletionSplitImpl
86
+ {
87
+ /**
88
+ * Gets a `break` expression whose target can have a Boolean completion that
89
+ * matches this split.
90
+ */
91
+ private BreakExpr getABreakExpr ( Expr target ) {
92
+ target = result .getTarget ( ) and
93
+ last ( target , _, this .getCompletion ( ) )
101
94
}
102
95
103
- override predicate hasExitScope ( CfgScope scope , AstNode last , Completion c ) {
104
- this .appliesTo ( last ) and
105
- scope .scopeLast ( last , c ) and
106
- if c instanceof ConditionalCompletion then completion = c else any ( )
96
+ override predicate hasEntry ( AstNode pred , AstNode succ , Completion c ) {
97
+ super .hasEntry ( pred , succ , c )
98
+ or
99
+ succ ( pred , succ , c ) and
100
+ last ( succ .( BreakExpr ) .getExpr ( ) , pred , c ) and
101
+ succ = this .getABreakExpr ( _) and
102
+ c = this .getCompletion ( )
107
103
}
108
104
109
105
override predicate hasSuccessor ( AstNode pred , AstNode succ , Completion c ) {
106
+ super .hasSuccessor ( pred , succ , c )
107
+ or
110
108
this .appliesTo ( pred ) and
111
109
succ ( pred , succ , c ) and
112
- not c instanceof ConditionalCompletion
110
+ pred = this . getABreakExpr ( succ )
113
111
}
114
112
}
113
+
114
+ int getNextListOrder ( ) { result = 1 }
115
115
}
0 commit comments