11private import rust
2- import ControlFlowGraphImplSpecific :: CfgImpl
2+ import codeql.controlflow.Cfg
33import Completion
4+ import codeql.controlflow.Cfg
5+ private import SuccessorType as ST
6+ private import Scope as Scope
47
5- class CallTree extends StandardPostOrderTree instanceof Call {
8+ module CfgInput implements InputSig< Location > {
9+ private import rust as Rust
10+ private import Completion as C
11+ private import Splitting as S
12+
13+ class AstNode = Rust:: AstNode ;
14+
15+ class Completion = C:: Completion ;
16+
17+ predicate completionIsNormal = C:: completionIsNormal / 1 ;
18+
19+ predicate completionIsSimple = C:: completionIsSimple / 1 ;
20+
21+ predicate completionIsValidFor = C:: completionIsValidFor / 2 ;
22+
23+ /** An AST node with an associated control-flow graph. */
24+ class CfgScope = Scope:: CfgScope ;
25+
26+ CfgScope getCfgScope ( AstNode n ) { result = Scope:: scopeOfAst ( n ) }
27+
28+ class SplitKindBase = S:: TSplitKind ;
29+
30+ class Split = S:: Split ;
31+
32+ class SuccessorType = ST:: SuccessorType ;
33+
34+ /** Gets a successor type that matches completion `c`. */
35+ SuccessorType getAMatchingSuccessorType ( Completion c ) { result = c .getAMatchingSuccessorType ( ) }
36+
37+ /**
38+ * Hold if `c` represents simple (normal) evaluation of a statement or an expression.
39+ */
40+ predicate successorTypeIsSimple ( SuccessorType t ) { t instanceof ST:: NormalSuccessor }
41+
42+ /** Holds if `t` is an abnormal exit type out of a CFG scope. */
43+ predicate isAbnormalExitType ( SuccessorType t ) { none ( ) }
44+
45+ /** Hold if `t` represents a conditional successor type. */
46+ predicate successorTypeIsCondition ( SuccessorType t ) { t instanceof ST:: BooleanSuccessor }
47+
48+ /** Gets the maximum number of splits allowed for a given node. */
49+ int maxSplits ( ) { result = 0 }
50+
51+ /** Holds if `first` is first executed when entering `scope`. */
52+ predicate scopeFirst ( CfgScope scope , AstNode first ) {
53+ scope .( CfgImpl:: ControlFlowTree ) .first ( first )
54+ }
55+
56+ /** Holds if `scope` is exited when `last` finishes with completion `c`. */
57+ predicate scopeLast ( CfgScope scope , AstNode last , Completion c ) {
58+ scope .( CfgImpl:: ControlFlowTree ) .last ( last , c )
59+ }
60+ }
61+
62+ module CfgImpl = Make< Location , CfgInput > ;
63+
64+ import CfgImpl
65+
66+ class FunctionTree extends LeafTree instanceof Function { }
67+
68+ class BlockExprTree extends StandardPostOrderTree instanceof BlockExpr {
69+ override ControlFlowTree getChildNode ( int i ) {
70+ result = super .getStatement ( i )
71+ or
72+ exists ( int last |
73+ last + 1 = i and
74+ exists ( super .getStatement ( last ) ) and
75+ not exists ( super .getStatement ( last + 1 ) ) and
76+ result = super .getTail ( )
77+ )
78+ }
79+ }
80+
81+ class CallExprTree extends StandardPostOrderTree instanceof CallExpr {
682 override ControlFlowTree getChildNode ( int i ) { result = super .getArg ( i ) }
783}
884
9- class BinaryOpTree extends StandardPostOrderTree instanceof BinaryOp {
85+ class BinaryOpExprTree extends StandardPostOrderTree instanceof BinaryOpExpr {
1086 override ControlFlowTree getChildNode ( int i ) {
1187 i = 0 and result = super .getLhs ( )
1288 or
1389 i = 1 and result = super .getRhs ( )
1490 }
1591}
1692
17- class IfTree extends PostOrderTree instanceof If {
93+ class IfExprTree extends PostOrderTree instanceof IfExpr {
1894 override predicate first ( AstNode node ) { first ( super .getCondition ( ) , node ) }
1995
20- override predicate propagatesAbnormal ( AstNode child ) { none ( ) }
96+ override predicate propagatesAbnormal ( AstNode child ) {
97+ child = [ super .getCondition ( ) , super .getThen ( ) , super .getElse ( ) ]
98+ }
2199
22100 override predicate succ ( AstNode pred , AstNode succ , Completion c ) {
23101 // Edges from the condition to each branch
@@ -31,17 +109,17 @@ class IfTree extends PostOrderTree instanceof If {
31109 // An edge from the then branch to the last node
32110 last ( super .getThen ( ) , pred , c ) and
33111 succ = this and
34- completionIsSimple ( c )
112+ completionIsNormal ( c )
35113 or
36114 // An edge from the else branch to the last node
37115 last ( super .getElse ( ) , pred , c ) and
38116 succ = this and
39- completionIsSimple ( c )
117+ completionIsNormal ( c )
40118 }
41119}
42120
43- class LetTree extends StandardPostOrderTree instanceof Let {
121+ class LetExprTree extends StandardPostOrderTree instanceof LetExpr {
44122 override ControlFlowTree getChildNode ( int i ) { i = 0 and result = super .getExpr ( ) }
45123}
46124
47- class LiteralTree extends LeafTree instanceof Literal { }
125+ class LiteralExprTree extends LeafTree instanceof LiteralExpr { }
0 commit comments