Python: support for with-definitions

This commit is contained in:
Rasmus Lerchedahl Petersen
2020-06-23 07:45:30 +02:00
parent e8289d6fa1
commit a55b4660d4
3 changed files with 14 additions and 1 deletions

View File

@@ -42,6 +42,19 @@ module EssaFlow {
// nodeTo is `x`, essa var
nodeFrom.asCfgNode() = nodeTo.asEssaNode().getDefinition().(AssignmentDefinition).getValue()
or
// With definition
// `with f(42) as x:`
// nodeFrom is `f(42)`, cfg node
// nodeTo is `x`, essa var
exists(With with, ControlFlowNode contextManager, ControlFlowNode var |
nodeFrom.asCfgNode() = contextManager and
nodeTo.asEssaNode().getDefinition().(WithDefinition).getDefiningNode() = var and
// see `with_flow`
with.getContextExpr() = contextManager.getNode() and
with.getOptionalVars() = var.getNode() and
contextManager.strictlyDominates(var)
)
or
// Use
// `y = 42`
// `x = f(y)`

View File

@@ -6,6 +6,7 @@
| test.py:37:13:37:18 | ControlFlowNode for SOURCE | test.py:41:14:41:14 | ControlFlowNode for t |
| test.py:76:9:76:14 | ControlFlowNode for SOURCE | test.py:78:10:78:10 | ControlFlowNode for t |
| test.py:108:13:108:18 | ControlFlowNode for SOURCE | test.py:112:14:112:14 | ControlFlowNode for t |
| test.py:139:10:139:15 | ControlFlowNode for SOURCE | test.py:140:14:140:14 | ControlFlowNode for t |
| test.py:143:9:143:14 | ControlFlowNode for SOURCE | test.py:145:10:145:10 | ControlFlowNode for s |
| test.py:158:9:158:14 | ControlFlowNode for SOURCE | test.py:160:14:160:14 | ControlFlowNode for t |
| test.py:158:9:158:14 | ControlFlowNode for SOURCE | test.py:162:14:162:14 | ControlFlowNode for t |

View File

@@ -4,7 +4,6 @@ from
DataFlow::Node source,
DataFlow::Node sink
where
// source != sink and
exists(TestConfiguration cfg | cfg.hasFlow(source, sink))
select
source, sink