Skip to content

Commit 1829126

Browse files
committed
Python: Get rid of DataFlowCfgNode
Should make modelling data flow nodes that are also specific subclasses of `ControlFlowNode` a bit smoother.
1 parent d3f8fb5 commit 1829126

File tree

3 files changed

+7
-24
lines changed

3 files changed

+7
-24
lines changed

python/ql/src/experimental/dataflow/internal/Attributes.qll

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ abstract class AttrWrite extends AttrRef {
6262
* ```
6363
* Also gives access to the `value` being written, by extending `DefinitionNode`.
6464
*/
65-
private class AttributeAssignmentNode extends DefinitionNode, AttrNode, DataFlowCfgNode {
65+
private class AttributeAssignmentNode extends DefinitionNode, AttrNode {
6666
override ControlFlowNode getValue() { result = DefinitionNode.super.getValue() }
6767
}
6868

@@ -87,7 +87,7 @@ private class AttributeAssignmentAsAttrWrite extends AttrWrite, CfgNode {
8787
import semmle.python.types.Builtins
8888

8989
/** Represents `CallNode`s that may refer to calls to built-in functions or classes. */
90-
private class BuiltInCallNode extends CallNode, DataFlowCfgNode {
90+
private class BuiltInCallNode extends CallNode {
9191
string name;
9292

9393
BuiltInCallNode() {
@@ -159,7 +159,7 @@ private class SetAttrCallAsAttrWrite extends AttrWrite, CfgNode {
159159
* Instances of this class correspond to the `NameNode` for `attr`, and also gives access to `value` by
160160
* virtue of being a `DefinitionNode`.
161161
*/
162-
private class ClassAttributeAssignmentNode extends DefinitionNode, NameNode, DataFlowCfgNode { }
162+
private class ClassAttributeAssignmentNode extends DefinitionNode, NameNode { }
163163

164164
/**
165165
* An attribute assignment via a class field, e.g.
@@ -192,15 +192,9 @@ private class ClassDefinitionAsAttrWrite extends AttrWrite, CfgNode {
192192
*/
193193
abstract class AttrRead extends AttrRef, Node { }
194194

195-
/**
196-
* A convenience class for embedding `AttrNode` into `DataFlowCfgNode`, as the former is not
197-
* obviously a subtype of the latter.
198-
*/
199-
private class DataFlowAttrNode extends AttrNode, DataFlowCfgNode { }
200-
201195
/** A simple attribute read, e.g. `object.attr` */
202196
private class AttributeReadAsAttrRead extends AttrRead, CfgNode {
203-
override DataFlowAttrNode node;
197+
override AttrNode node;
204198

205199
override Node getObject() { result.asCfgNode() = node.getObject() }
206200

@@ -227,12 +221,6 @@ private class GetAttrCallAsAttrRead extends AttrRead, CfgNode {
227221
}
228222
}
229223

230-
/**
231-
* A convenience class for embedding `ImportMemberNode` into `DataFlowCfgNode`, as the former is not
232-
* obviously a subtype of the latter.
233-
*/
234-
private class DataFlowImportMemberNode extends ImportMemberNode, DataFlowCfgNode { }
235-
236224
/**
237225
* Represents a named import as an attribute read. That is,
238226
* ```python
@@ -241,7 +229,7 @@ private class DataFlowImportMemberNode extends ImportMemberNode, DataFlowCfgNode
241229
* is treated as if it is a read of the attribute `module.attr`, even if `module` is not imported directly.
242230
*/
243231
private class ModuleAttributeImportAsAttrRead extends AttrRead, CfgNode {
244-
override DataFlowImportMemberNode node;
232+
override ImportMemberNode node;
245233

246234
override Node getObject() { result.asCfgNode() = node.getModule(_) }
247235

python/ql/src/experimental/dataflow/internal/DataFlowPrivate.qll

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ private import semmle.python.essa.SsaCompute
1111
//--------
1212
predicate isExpressionNode(ControlFlowNode node) { node.getNode() instanceof Expr }
1313

14-
/** A control flow node which is also a dataflow node */
15-
class DataFlowCfgNode extends ControlFlowNode {
16-
DataFlowCfgNode() { isExpressionNode(this) }
17-
}
18-
1914
/** A data flow node for which we should synthesise an associated pre-update node. */
2015
abstract class NeedsSyntheticPreUpdateNode extends Node {
2116
/** A label for this kind of node. This will figure in the textual representation of the synthesized pre-update node. */

python/ql/src/experimental/dataflow/internal/DataFlowPublic.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ newtype TNode =
2323
/** A node corresponding to an SSA variable. */
2424
TEssaNode(EssaVariable var) or
2525
/** A node corresponding to a control flow node. */
26-
TCfgNode(DataFlowCfgNode node) or
26+
TCfgNode(ControlFlowNode node) { isExpressionNode(node) } or
2727
/** A synthetic node representing the value of an object before a state change */
2828
TSyntheticPreUpdateNode(NeedsSyntheticPreUpdateNode post) or
2929
/** A synthetic node representing the value of an object after a state change */
@@ -104,7 +104,7 @@ class EssaNode extends Node, TEssaNode {
104104
}
105105

106106
class CfgNode extends Node, TCfgNode {
107-
DataFlowCfgNode node;
107+
ControlFlowNode node;
108108

109109
CfgNode() { this = TCfgNode(node) }
110110

0 commit comments

Comments
 (0)