Python: start on local flow

This commit is contained in:
Rasmus Lerchedahl Petersen
2020-06-15 16:25:41 +02:00
parent 6dfb3a5df8
commit f8eb5839cd
2 changed files with 26 additions and 3 deletions

View File

@@ -1,6 +1,11 @@
private import python
private import DataFlowPublic
// Data flow graph
// Nodes
class DataFlowCall extends Call {
/** Gets the enclosing callable of this call. */
abstract DataFlowCallable getEnclosingCallable();
@@ -92,7 +97,16 @@ predicate compatibleTypes(DataFlowType t1, DataFlowType t2) {
* excludes SSA flow through instance fields.
*/
predicate simpleLocalFlowStep(Node nodeFrom, Node nodeTo) {
none()
exists(EssaEdgeRefinement r |
nodeTo.asEssaNode() = r.getVariable() and
nodeFrom.asEssaNode() = r.getInput()
)
or
exists(EssaNodeRefinement r |
nodeTo.asEssaNode() = r.getVariable() and
nodeFrom.asEssaNode() = r.getInput()
)
}
/**

View File

@@ -5,11 +5,19 @@
import python
private import DataFlowPrivate
newtype TNode =
TEssaNode(EssaVariable var)
/**
* An element, viewed as a node in a data flow graph. Either an expression
* (`ExprNode`) or a parameter (`ParameterNode`).
*/
class Node extends ControlFlowNode {
class Node extends TNode {
EssaVariable asEssaNode() { this = TEssaNode(result) }
string toString() { result = this.asEssaNode().toString() }
/** Gets the enclosing callable of this node. */
final DataFlowCallable getEnclosingCallable() {
none()
@@ -32,9 +40,10 @@ class Node extends ControlFlowNode {
predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
this.asEssaNode().getDefinition().getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}
}
/**