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

Skip to content

Commit f68357a

Browse files
committed
cached stages iteration 3.5
1 parent 37a9b41 commit f68357a

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,18 @@ abstract class AstNode extends AstNode_ {
4747
* Expr.getASubExpression(), Stmt.getASubStatement(), Stmt.getASubExpression() or
4848
* Scope.getAStmt() applied to the parent.
4949
*/
50-
AstNode getParentNode() { result.getAChildNode() = this }
50+
cached
51+
AstNode getParentNode() {
52+
Stages::SSA::ref() and
53+
result.getAChildNode() = this
54+
}
5155

5256
/** Whether this contains `inner` syntactically */
53-
predicate contains(AstNode inner) { this.getAChildNode+() = inner }
57+
cached
58+
predicate contains(AstNode inner) {
59+
Stages::SSA::ref() and
60+
this.getAChildNode+() = inner
61+
}
5462

5563
pragma[noinline]
5664
private predicate containsInScope(AstNode inner, Scope scope) {
@@ -114,6 +122,7 @@ class Comprehension extends Comprehension_, AstNode {
114122
result = Comprehension_.super.getLocation()
115123
}
116124

125+
pragma[nomagic]
117126
override AstNode getAChildNode() {
118127
Stages::SSA::ref() and
119128
result = this.getASubExpression()

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ module Stages {
7575
or
7676
exists(any(AstExtended::AstNode n).getAChildNode())
7777
or
78+
exists(any(AstExtended::AstNode n).getParentNode())
79+
or
80+
any(AstExtended::AstNode n).contains(_)
81+
or
7882
exists(any(PyFlow::BasicBlock b).getImmediateDominator())
7983
or
8084
any(PyFlow::BasicBlock b).strictlyDominates(_)

0 commit comments

Comments
 (0)