Skip to content

Commit c0569da

Browse files
authored
Python: Move track/backtrack to LocalSourceNode
This is merely making explicit what was implicitly enforced. The move to change the return type of `step` already meant that `this` and `result` had to be `LocalSourceNode`. By moving these methods to their rightful place, we should hopefully avoid a bit of suprising behaviour.
1 parent 2a07441 commit c0569da

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

python/change-notes/2021-04-20-stepsummary-localsourcenode.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ lgtm,codescanning
33
to use the more restrictive type `LocalSourceNode` for their second argument. For cases where
44
stepping between non-`LocalSourceNode`s is required, the `StepSummary::smallstep` predicate may be
55
used instead.
6+
* The methods `Node::track` and `Node::backtrack` have been moved to the class `LocalSourceNode`. If
7+
the old behavior is required, one can use `LocalSourceNode::flowsTo` to add back the missing flow.

python/ql/src/semmle/python/dataflow/new/internal/DataFlowPublic.qll

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,22 +119,6 @@ class Node extends TNode {
119119
/** Gets the expression corresponding to this node, if any. */
120120
Expr asExpr() { none() }
121121

122-
/**
123-
* Gets a node that this node may flow to using one heap and/or interprocedural step.
124-
*
125-
* See `TypeTracker` for more details about how to use this.
126-
*/
127-
pragma[inline]
128-
Node track(TypeTracker t2, TypeTracker t) { t = t2.step(this, result) }
129-
130-
/**
131-
* Gets a node that may flow into this one using one heap and/or interprocedural step.
132-
*
133-
* See `TypeBackTracker` for more details about how to use this.
134-
*/
135-
pragma[inline]
136-
LocalSourceNode backtrack(TypeBackTracker t2, TypeBackTracker t) { t2 = t.step(result, this) }
137-
138122
/**
139123
* Gets a local source node from which data may flow to this node in zero or more local data-flow steps.
140124
*/

python/ql/src/semmle/python/dataflow/new/internal/LocalSources.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ class LocalSourceNode extends Node {
7777
* Gets a call to this node.
7878
*/
7979
CallCfgNode getACall() { Cached::call(this, result) }
80+
81+
/**
82+
* Gets a node that this node may flow to using one heap and/or interprocedural step.
83+
*
84+
* See `TypeTracker` for more details about how to use this.
85+
*/
86+
pragma[inline]
87+
LocalSourceNode track(TypeTracker t2, TypeTracker t) { t = t2.step(this, result) }
88+
89+
/**
90+
* Gets a node that may flow into this one using one heap and/or interprocedural step.
91+
*
92+
* See `TypeBackTracker` for more details about how to use this.
93+
*/
94+
pragma[inline]
95+
LocalSourceNode backtrack(TypeBackTracker t2, TypeBackTracker t) { t2 = t.step(result, this) }
8096
}
8197

8298
cached

0 commit comments

Comments
 (0)