From b16d6bf5b4b5411ba9165859d84e75dd60a95ecd Mon Sep 17 00:00:00 2001 From: Arthur Baars Date: Wed, 24 Feb 2021 19:18:42 +0100 Subject: [PATCH] CFG: make isValidFor work for hidden nodes --- .../controlflow/internal/ControlFlowGraphImpl.qll | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ql/src/codeql_ruby/controlflow/internal/ControlFlowGraphImpl.qll b/ql/src/codeql_ruby/controlflow/internal/ControlFlowGraphImpl.qll index 8d7b67ce4a8..da10ca2282a 100644 --- a/ql/src/codeql_ruby/controlflow/internal/ControlFlowGraphImpl.qll +++ b/ql/src/codeql_ruby/controlflow/internal/ControlFlowGraphImpl.qll @@ -31,6 +31,7 @@ * caught up by its surrounding loop and turned into a `NormalCompletion`. */ +private import codeql_ruby.AST as AST private import codeql_ruby.ast.internal.TreeSitter::Generated private import AstNodes private import codeql_ruby.ast.internal.Variable @@ -306,12 +307,19 @@ abstract private class PreOrderTree extends ControlFlowTree { final override predicate first(AstNode first) { first = this } } +// TODO: remove this predicate +predicate isValidFor(Completion c, ControlFlowTree node) { + c instanceof SimpleCompletion and isHidden(node) + or + c.isValidFor(node) +} + abstract private class StandardPreOrderTree extends StandardNode, PreOrderTree { final override predicate last(AstNode last, Completion c) { last(this.getLastChildNode(), last, c) or not exists(this.getLastChildNode()) and - c.isValidFor(this) and + isValidFor(c, this) and last = this } @@ -327,7 +335,7 @@ abstract private class StandardPreOrderTree extends StandardNode, PreOrderTree { abstract private class PostOrderTree extends ControlFlowTree { override predicate last(AstNode last, Completion c) { last = this and - c.isValidFor(last) + isValidFor(c, last) } } @@ -840,7 +848,7 @@ module Trees { or not exists(this.getExceptions()) and last = this and - c.isValidFor(this) + isValidFor(c, this) ) ) }