CFG: add AstNode for @in

This commit is contained in:
Arthur Baars
2021-02-24 17:02:18 +01:00
parent b16d6bf5b4
commit 7c0ea7b3bc
2 changed files with 15 additions and 3 deletions

View File

@@ -5,7 +5,6 @@
*/
private import codeql_ruby.AST
private import codeql_ruby.ast.internal.Control
private import codeql_ruby.controlflow.ControlFlowGraph
private import ControlFlowGraphImpl
private import NonReturning
@@ -54,7 +53,7 @@ private predicate nestedEnsureCompletion(Completion outer, int nestLevel) {
pragma[noinline]
private predicate completionIsValidForStmt(AstNode n, Completion c) {
n instanceof In::Range and
n instanceof InRange and
c instanceof EmptinessCompletion
or
n instanceof BreakStmt and

View File

@@ -31,7 +31,8 @@
* caught up by its surrounding loop and turned into a `NormalCompletion`.
*/
private import codeql_ruby.AST as AST
private import codeql_ruby.ast.internal.AST as ASTInternal
private import codeql_ruby.ast.internal.Control as Control
private import codeql_ruby.ast.internal.TreeSitter::Generated
private import AstNodes
private import codeql_ruby.ast.internal.Variable
@@ -307,6 +308,18 @@ abstract private class PreOrderTree extends ControlFlowTree {
final override predicate first(AstNode first) { first = this }
}
class InRange extends ASTInternal::AstNode::Range, @in {
final override string toString() { result = "In" }
}
class ForRange extends Control::ForExpr::Range, @for {
override predicate child(string label, ASTInternal::AstNode::Range child) {
Control::ForExpr::Range.super.child(label, child)
or
label = "<in>" and this.(AstNode).getAFieldOrChild().(In) = child
}
}
// TODO: remove this predicate
predicate isValidFor(Completion c, ControlFlowTree node) {
c instanceof SimpleCompletion and isHidden(node)