cached stages iteration 3

This commit is contained in:
Erik Krogh Kristensen
2021-12-07 21:55:53 +01:00
parent 60b5af215f
commit 37a9b41e26
3 changed files with 22 additions and 8 deletions

View File

@@ -37,6 +37,7 @@ abstract class AstNode extends AstNode_ {
* Expr.getASubExpression(), Stmt.getASubStatement(), Stmt.getASubExpression() or
* Scope.getAStmt().
*/
cached
abstract AstNode getAChildNode();
/**
@@ -113,7 +114,10 @@ class Comprehension extends Comprehension_, AstNode {
result = Comprehension_.super.getLocation()
}
override AstNode getAChildNode() { result = this.getASubExpression() }
override AstNode getAChildNode() {
Stages::SSA::ref() and
result = this.getASubExpression()
}
Expr getASubExpression() {
result = this.getIter() or

View File

@@ -32,18 +32,26 @@ class GenericGeneratedFile extends GeneratedFile {
override string getTool() { lax_generated_by(this, result) or strict_generated_by(this, result) }
}
pragma[nomagic]
int minStmtLine(File file) {
result =
min(int line |
line = any(Stmt s | s.getLocation().getFile() = file).getLocation().getStartLine()
)
}
pragma[nomagic]
predicate isBeforeCode(Comment c, File f) {
f = c.getLocation().getFile() and
minStmtLine(f) < c.getLocation().getStartLine()
}
private string comment_or_docstring(File f, boolean before_code) {
exists(Comment c |
c.getLocation().getFile() = f and
result = c.getText()
|
if
exists(Stmt s |
s.getEnclosingModule().getFile() = f and
s.getLocation().getStartLine() < c.getLocation().getStartLine()
)
then before_code = false
else before_code = true
if isBeforeCode(c, f) then before_code = true else before_code = false
)
or
exists(Module m | m.getFile() = f |

View File

@@ -73,6 +73,8 @@ module Stages {
or
exists(any(AstExtended::AstNode n).getLocation())
or
exists(any(AstExtended::AstNode n).getAChildNode())
or
exists(any(PyFlow::BasicBlock b).getImmediateDominator())
or
any(PyFlow::BasicBlock b).strictlyDominates(_)