@@ -48,7 +48,7 @@ final class DataFlowCall extends TDataFlowCall {
48
48
49
49
MethodCallExprCfgNode asMethodCallExprCfgNode ( ) { this = TMethodCall ( result ) }
50
50
51
- ExprCfgNode asExprCfgNode ( ) {
51
+ CallExprBaseCfgNode asExprCfgNode ( ) {
52
52
result = this .asCallExprCfgNode ( ) or result = this .asMethodCallExprCfgNode ( )
53
53
}
54
54
@@ -76,7 +76,7 @@ module Node {
76
76
/**
77
77
* Gets the expression that corresponds to this node, if any.
78
78
*/
79
- Expr asExpr ( ) { none ( ) }
79
+ ExprCfgNode asExpr ( ) { none ( ) }
80
80
81
81
/** Gets the enclosing callable. */
82
82
DataFlowCallable getEnclosingCallable ( ) { result = TCfgScope ( this .getCfgScope ( ) ) }
@@ -115,13 +115,13 @@ module Node {
115
115
abstract private class AstCfgFlowNode extends Node {
116
116
AstCfgNode n ;
117
117
118
- override CfgNode getCfgNode ( ) { result = n }
118
+ final override CfgNode getCfgNode ( ) { result = n }
119
119
120
- override CfgScope getCfgScope ( ) { result = n .getAstNode ( ) .getEnclosingCfgScope ( ) }
120
+ final override CfgScope getCfgScope ( ) { result = n .getAstNode ( ) .getEnclosingCfgScope ( ) }
121
121
122
- override Location getLocation ( ) { result = n .getAstNode ( ) .getLocation ( ) }
122
+ final override Location getLocation ( ) { result = n .getAstNode ( ) .getLocation ( ) }
123
123
124
- override string toString ( ) { result = n .getAstNode ( ) .toString ( ) }
124
+ final override string toString ( ) { result = n .getAstNode ( ) .toString ( ) }
125
125
}
126
126
127
127
/**
@@ -137,7 +137,7 @@ module Node {
137
137
138
138
ExprNode ( ) { this = TExprNode ( n ) }
139
139
140
- override Expr asExpr ( ) { result = n . getExpr ( ) }
140
+ override ExprCfgNode asExpr ( ) { result = n }
141
141
}
142
142
143
143
final class PatNode extends AstCfgFlowNode , TPatNode {
@@ -159,7 +159,7 @@ module Node {
159
159
ParameterNode ( ) { this = TParameterNode ( n ) }
160
160
161
161
/** Gets the parameter in the AST that this node corresponds to. */
162
- Param getParameter ( ) { result = n . getParam ( ) }
162
+ ParamCfgNode getParameter ( ) { result = n }
163
163
}
164
164
165
165
final class ArgumentNode = NaNode ;
@@ -197,7 +197,7 @@ module Node {
197
197
}
198
198
199
199
final private class ExprOutNode extends ExprNode , OutNode {
200
- ExprOutNode ( ) { this .asExpr ( ) instanceof CallExpr }
200
+ ExprOutNode ( ) { this .asExpr ( ) instanceof CallExprCfgNode }
201
201
202
202
/** Gets the underlying call CFG node that includes this out node. */
203
203
override DataFlowCall getCall ( ) { result .asExprCfgNode ( ) = this .getCfgNode ( ) }
@@ -228,13 +228,13 @@ final class Node = Node::Node;
228
228
module SsaFlow {
229
229
private module Impl = SsaImpl:: DataFlowIntegration;
230
230
231
- private Node:: ParameterNode toParameterNode ( Param p ) { result .getParameter ( ) = p }
231
+ private Node:: ParameterNode toParameterNode ( ParamCfgNode p ) { result .getParameter ( ) = p }
232
232
233
233
/** Converts a control flow node into an SSA control flow node. */
234
234
Impl:: Node asNode ( Node n ) {
235
235
n = TSsaNode ( result )
236
236
or
237
- result .( Impl:: ExprNode ) .getExpr ( ) = n .( Node :: ExprNode ) . getCfgNode ( )
237
+ result .( Impl:: ExprNode ) .getExpr ( ) = n .asExpr ( )
238
238
or
239
239
n = toParameterNode ( result .( Impl:: ParameterNode ) .getParameter ( ) )
240
240
}
@@ -248,39 +248,28 @@ module SsaFlow {
248
248
}
249
249
}
250
250
251
- /**
252
- * Holds for expressions `e` that evaluate to the value of any last (in
253
- * evaluation order) subexpressions within it. E.g., expressions that propagate
254
- * a values from a subexpression.
255
- *
256
- * For instance, the predicate holds for if expressions as `if b { e1 } else {
257
- * e2 }` evalates to the value of one of the subexpressions `e1` or `e2`.
258
- */
259
- private predicate propagatesValue ( Expr e ) {
260
- e instanceof IfExpr or
261
- e instanceof LoopExpr or
262
- e instanceof ReturnExpr or
263
- e instanceof BreakExpr or
264
- e .( BlockExpr ) .getStmtList ( ) .hasTailExpr ( ) or
265
- e instanceof MatchExpr
266
- }
267
-
268
251
/**
269
252
* Gets a node that may execute last in `n`, and which, when it executes last,
270
253
* will be the value of `n`.
271
254
*/
272
- private ExprCfgNode getALastEvalNode ( ExprCfgNode n ) {
273
- propagatesValue ( n .getExpr ( ) ) and result .getASuccessor ( ) = n
255
+ private ExprCfgNode getALastEvalNode ( ExprCfgNode e ) {
256
+ e = any ( IfExprCfgNode n | result = [ n .getThen ( ) , n .getElse ( ) ] ) or
257
+ result = e .( LoopExprCfgNode ) .getLoopBody ( ) or
258
+ result = e .( ReturnExprCfgNode ) .getExpr ( ) or
259
+ result = e .( BreakExprCfgNode ) .getExpr ( ) or
260
+ result = e .( BlockExprCfgNode ) .getTailExpr ( ) or
261
+ result = e .( MatchExprCfgNode ) .getArmExpr ( _) or
262
+ result .( BreakExprCfgNode ) .getTarget ( ) = e
274
263
}
275
264
276
265
module LocalFlow {
277
266
pragma [ nomagic]
278
267
predicate localFlowStepCommon ( Node nodeFrom , Node nodeTo ) {
279
268
nodeFrom .getCfgNode ( ) = getALastEvalNode ( nodeTo .getCfgNode ( ) )
280
269
or
281
- exists ( LetStmt s |
282
- nodeFrom .getCfgNode ( ) . getAstNode ( ) = s .getInitializer ( ) and
283
- nodeTo .getCfgNode ( ) . getAstNode ( ) = s .getPat ( )
270
+ exists ( LetStmtCfgNode s |
271
+ nodeFrom .getCfgNode ( ) = s .getInitializer ( ) and
272
+ nodeTo .getCfgNode ( ) = s .getPat ( )
284
273
)
285
274
}
286
275
}
@@ -323,7 +312,7 @@ module RustDataFlow implements InputSig<Location> {
323
312
class DataFlowExpr = ExprCfgNode ;
324
313
325
314
/** Gets the node corresponding to `e`. */
326
- Node exprNode ( DataFlowExpr e ) { result .getCfgNode ( ) = e }
315
+ Node exprNode ( DataFlowExpr e ) { result .asExpr ( ) = e }
327
316
328
317
final class DataFlowCall = DataFlowCallAlias ;
329
318
0 commit comments