File tree 5 files changed +28
-6
lines changed
lib/semmle/python/dataflow/new/internal
test/experimental/dataflow/typetracking
5 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -361,7 +361,10 @@ module LocalFlow {
361
361
// nodeFrom is `y` on first line
362
362
// nodeTo is `y` on second line
363
363
exists ( EssaDefinition def |
364
- nodeFrom .( CfgNode ) .getNode ( ) = def .( EssaNodeDefinition ) .getDefiningNode ( ) and
364
+ nodeFrom .( CfgNode ) .getNode ( ) = def .( EssaNodeDefinition ) .getDefiningNode ( )
365
+ or
366
+ nodeFrom .( ScopeEntryDefinitionNode ) .getDefinition ( ) = def
367
+ |
365
368
AdjacentUses:: firstUse ( def , nodeTo .( CfgNode ) .getNode ( ) )
366
369
)
367
370
or
Original file line number Diff line number Diff line change @@ -27,9 +27,12 @@ newtype TNode =
27
27
isExpressionNode ( node )
28
28
or
29
29
node .getNode ( ) instanceof Pattern
30
- or
31
- node = any ( ScopeEntryDefinition def | not def .getScope ( ) instanceof Module ) .getDefiningNode ( )
32
30
} or
31
+ /**
32
+ * A node corresponding to a scope entry definition. That is, the value of a variable
33
+ * as it enters a scope.
34
+ */
35
+ TScopeEntryDefinitionNode ( ScopeEntryDefinition def ) { not def .getScope ( ) instanceof Module } or
33
36
/**
34
37
* A synthetic node representing the value of an object before a state change.
35
38
*
@@ -265,6 +268,22 @@ class ExprNode extends CfgNode {
265
268
/** Gets a node corresponding to expression `e`. */
266
269
ExprNode exprNode ( DataFlowExpr e ) { result .getNode ( ) .getNode ( ) = e }
267
270
271
+ class ScopeEntryDefinitionNode extends Node , TScopeEntryDefinitionNode {
272
+ ScopeEntryDefinition def ;
273
+
274
+ ScopeEntryDefinitionNode ( ) { this = TScopeEntryDefinitionNode ( def ) }
275
+
276
+ ScopeEntryDefinition getDefinition ( ) { result = def }
277
+
278
+ SsaSourceVariable getVariable ( ) { result = def .getSourceVariable ( ) }
279
+
280
+ override Location getLocation ( ) { result = def .getLocation ( ) }
281
+
282
+ override Scope getScope ( ) { result = def .getScope ( ) }
283
+
284
+ override string toString ( ) { result = "Entry definition for " + this .getVariable ( ) .toString ( ) }
285
+ }
286
+
268
287
/**
269
288
* The value of a parameter at function entry, viewed as a node in a data
270
289
* flow graph.
Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ class LocalSourceNode extends Node {
71
71
or
72
72
// We include all scope entry definitions, as these act as the local source within the scope they
73
73
// enter.
74
- this . asCfgNode ( ) = any ( ScopeEntryDefinition def ) . getDefiningNode ( )
74
+ this instanceof ScopeEntryDefinitionNode
75
75
or
76
76
this instanceof ParameterNode
77
77
}
Original file line number Diff line number Diff line change @@ -251,7 +251,7 @@ module TypeTrackingInput implements Shared::TypeTrackingInput {
251
251
e .getSourceVariable ( ) = var and
252
252
var .hasDefiningNode ( def )
253
253
|
254
- nodeTo .asCfgNode ( ) = e . getDefiningNode ( ) and
254
+ nodeTo .( DataFlowPublic :: ScopeEntryDefinitionNode ) . getDefinition ( ) = e and
255
255
nodeFrom .asCfgNode ( ) = def .getValue ( ) and
256
256
var .getScope ( ) .getScope * ( ) = nodeFrom .getScope ( )
257
257
)
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ module TrackedTest implements TestSig {
26
26
not e .getLocation ( ) .getStartLine ( ) = 0 and
27
27
// We do not wish to annotate scope entry definitions,
28
28
// as they do not appear in the source code.
29
- not e . asCfgNode ( ) = any ( ScopeEntryDefinition def ) . getDefiningNode ( ) and
29
+ not e instanceof DataFlow :: ScopeEntryDefinitionNode and
30
30
// ...same for `SynthCaptureNode`s
31
31
not e instanceof DataFlow:: SynthCaptureNode and
32
32
tag = "tracked" and
You can’t perform that action at this time.
0 commit comments