Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a8f9a91

Browse files
committed
cached stages iteration 4
1 parent f68357a commit a8f9a91

4 files changed

Lines changed: 17 additions & 3 deletions

File tree

python/ql/lib/semmle/python/AstExtended.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ abstract class AstNode extends AstNode_ {
1818
* NOTE: For some statements and other purely syntactic elements,
1919
* there may not be a `ControlFlowNode`
2020
*/
21-
ControlFlowNode getAFlowNode() { py_flow_bb_node(result, this, _, _) }
21+
cached
22+
ControlFlowNode getAFlowNode() {
23+
Stages::SSA::ref() and
24+
py_flow_bb_node(result, this, _, _)
25+
}
2226

2327
/** Gets the location for this AST node */
2428
cached

python/ql/lib/semmle/python/Flow.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ class ControlFlowNode extends @py_flow_node {
194194
BasicBlock getBasicBlock() { result.contains(this) }
195195

196196
/** Gets the scope containing this flow node */
197+
cached
197198
Scope getScope() {
199+
Stages::SSA::ref() and
198200
if this.getNode() instanceof Scope
199201
then
200202
/* Entry or exit node */

python/ql/lib/semmle/python/internal/CachedStages.qll

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
* on some but not all the cached predicates in the combined stage.
2121
*/
2222

23-
import python
24-
2523
/**
2624
* Contains a `cached module` for each stage.
2725
* Each `cached module` ensures that predicates that are supposed to be in the same stage, are in the same stage.
@@ -79,11 +77,15 @@ module Stages {
7977
or
8078
any(AstExtended::AstNode n).contains(_)
8179
or
80+
exists(any(AstExtended::AstNode n).getAFlowNode())
81+
or
8282
exists(any(PyFlow::BasicBlock b).getImmediateDominator())
8383
or
8484
any(PyFlow::BasicBlock b).strictlyDominates(_)
8585
or
8686
any(PyFlow::BasicBlock b).dominates(_)
87+
or
88+
exists(any(PyFlow::ControlFlowNode b).getScope())
8789
}
8890
}
8991

@@ -136,6 +138,7 @@ module Stages {
136138
private import semmle.python.objects.TObject as TObject
137139
private import semmle.python.Flow as Flow
138140
private import semmle.python.objects.ObjectInternal as ObjectInternal
141+
private import semmle.python.objects.ObjectAPI as ObjectAPI
139142

140143
/**
141144
* DONT USE!
@@ -162,6 +165,8 @@ module Stages {
162165
exists(any(Flow::ControlFlowNode c).toString())
163166
or
164167
exists(any(ObjectInternal::ObjectInternal o).toString())
168+
or
169+
exists(any(ObjectAPI::Value::named(_)))
165170
}
166171
}
167172

python/ql/lib/semmle/python/objects/ObjectAPI.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ private import semmle.python.pointsto.PointsTo
1010
private import semmle.python.pointsto.PointsToContext
1111
private import semmle.python.pointsto.MRO
1212
private import semmle.python.types.Builtins
13+
private import semmle.python.internal.CachedStages
1314

1415
/*
1516
* Use the term `ObjectSource` to refer to DB entity. Either a CFG node
@@ -263,7 +264,9 @@ module Value {
263264
* object of that name.
264265
* For example `Value::named("len")` is the `Value` representing the `len` built-in function.
265266
*/
267+
cached
266268
Value named(string name) {
269+
Stages::DataFlow::ref() and
267270
exists(string modname, string attrname | name = modname + "." + attrname |
268271
result = Module::named(modname).attr(attrname)
269272
)

0 commit comments

Comments
 (0)