3
3
*/
4
4
5
5
private import codeql.ruby.AST as Ast
6
- private import Completion
6
+ private import Completion as Comp
7
+ private import Comp
7
8
private import ControlFlowGraphImpl
8
9
private import SuccessorTypes
9
10
private import codeql.ruby.controlflow.ControlFlowGraph
@@ -31,7 +32,7 @@ class Split extends TSplit {
31
32
string toString ( ) { none ( ) }
32
33
}
33
34
34
- private module ConditionalCompletionSplitting {
35
+ module ConditionalCompletionSplitting {
35
36
/**
36
37
* A split for conditional completions. For example, in
37
38
*
@@ -51,67 +52,61 @@ private module ConditionalCompletionSplitting {
51
52
52
53
ConditionalCompletionSplit ( ) { this = TConditionalCompletionSplit ( completion ) }
53
54
55
+ ConditionalCompletion getCompletion ( ) { result = completion }
56
+
54
57
override string toString ( ) { result = completion .toString ( ) }
55
58
}
56
59
57
- private class ConditionalCompletionSplitKind extends SplitKind , TConditionalCompletionSplitKind {
60
+ private class ConditionalCompletionSplitKind_ extends SplitKind , TConditionalCompletionSplitKind {
58
61
override int getListOrder ( ) { result = 0 }
59
62
60
63
override predicate isEnabled ( AstNode n ) { this .appliesTo ( n ) }
61
64
62
65
override string toString ( ) { result = "ConditionalCompletion" }
63
66
}
64
67
65
- int getNextListOrder ( ) { result = 1 }
68
+ module ConditionalCompletionSplittingInput {
69
+ private import Completion as Comp
66
70
67
- private class ConditionalCompletionSplitImpl extends SplitImpl instanceof ConditionalCompletionSplit
68
- {
69
- ConditionalCompletion completion ;
71
+ class ConditionalCompletion = Comp:: ConditionalCompletion ;
70
72
71
- ConditionalCompletionSplitImpl ( ) { this = TConditionalCompletionSplit ( completion ) }
73
+ class ConditionalCompletionSplitKind extends ConditionalCompletionSplitKind_ , TSplitKind { }
72
74
73
- override ConditionalCompletionSplitKind getKind ( ) { any ( ) }
75
+ class ConditionalCompletionSplit = ConditionalCompletionSplitting :: ConditionalCompletionSplit ;
74
76
75
- override predicate hasEntry ( AstNode pred , AstNode succ , Completion c ) {
76
- succ ( pred , succ , c ) and
77
- last ( succ , _, completion ) and
77
+ bindingset [ parent, parentCompletion]
78
+ predicate condPropagateExpr (
79
+ AstNode parent , ConditionalCompletion parentCompletion , AstNode child ,
80
+ ConditionalCompletion childCompletion
81
+ ) {
82
+ child = parent .( Ast:: NotExpr ) .getOperand ( ) and
83
+ childCompletion .( BooleanCompletion ) .getDual ( ) = parentCompletion
84
+ or
85
+ childCompletion = parentCompletion and
78
86
(
79
- last ( succ .( Ast:: NotExpr ) .getOperand ( ) , pred , c ) and
80
- completion .( BooleanCompletion ) .getDual ( ) = c
81
- or
82
- last ( succ .( Ast:: LogicalAndExpr ) .getAnOperand ( ) , pred , c ) and
83
- completion = c
87
+ child = parent .( Ast:: LogicalAndExpr ) .getAnOperand ( )
84
88
or
85
- last ( succ .( Ast:: LogicalOrExpr ) .getAnOperand ( ) , pred , c ) and
86
- completion = c
89
+ child = parent .( Ast:: LogicalOrExpr ) .getAnOperand ( )
87
90
or
88
- last ( succ .( Ast:: StmtSequence ) .getLastStmt ( ) , pred , c ) and
89
- completion = c
91
+ child = parent .( Ast:: StmtSequence ) .getLastStmt ( )
90
92
or
91
- last ( succ .( Ast:: ConditionalExpr ) .getBranch ( _) , pred , c ) and
92
- completion = c
93
+ child = parent .( Ast:: ConditionalExpr ) .getBranch ( _)
93
94
)
94
- or
95
- succ ( pred , succ , c ) and
96
- succ instanceof Ast:: WhenClause and
97
- completion = c
98
95
}
96
+ }
99
97
100
- override predicate hasEntryScope ( CfgScope scope , AstNode succ ) { none ( ) }
98
+ int getNextListOrder ( ) { result = 1 }
101
99
102
- override predicate hasExit ( AstNode pred , AstNode succ , Completion c ) {
103
- this .appliesTo ( pred ) and
100
+ private class ConditionalCompletionSplitImpl extends SplitImplementations:: ConditionalCompletionSplitting:: ConditionalCompletionSplitImpl
101
+ {
102
+ override predicate hasEntry ( AstNode pred , AstNode succ , Completion c ) {
103
+ super .hasEntry ( pred , succ , c )
104
+ or
105
+ // a non-standard case is needed for `when` clauses
104
106
succ ( pred , succ , c ) and
105
- if c instanceof ConditionalCompletion then completion = c else any ( )
106
- }
107
-
108
- override predicate hasExitScope ( CfgScope scope , AstNode last , Completion c ) {
109
- this .appliesTo ( last ) and
110
- succExit ( scope , last , c ) and
111
- if c instanceof ConditionalCompletion then completion = c else any ( )
107
+ succ instanceof Ast:: WhenClause and
108
+ c = this .getCompletion ( )
112
109
}
113
-
114
- override predicate hasSuccessor ( AstNode pred , AstNode succ , Completion c ) { none ( ) }
115
110
}
116
111
}
117
112
0 commit comments