Skip to content

Commit 597c62a

Browse files
committed
Ruby: Cfg replacement wip
1 parent ca391eb commit 597c62a

25 files changed

Lines changed: 85 additions & 2917 deletions

File tree

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,2 @@
1-
import codeql.ruby.controlflow.internal.ControlFlowGraphImpl::Consistency as Consistency
2-
import Consistency
3-
import codeql.ruby.AST
41
import codeql.ruby.CFG
5-
import codeql.ruby.controlflow.internal.Completion
6-
import codeql.ruby.controlflow.internal.ControlFlowGraphImpl as CfgImpl
7-
8-
/**
9-
* All `Expr` nodes are `PostOrderTree`s
10-
*/
11-
query predicate nonPostOrderExpr(Expr e, string cls) {
12-
cls = e.getPrimaryQlClasses() and
13-
not exists(e.getDesugared()) and
14-
not e instanceof BodyStmt and
15-
exists(AstNode last, Completion c |
16-
CfgImpl::last(e, last, c) and
17-
last != e and
18-
c instanceof NormalCompletion
19-
)
20-
}
21-
22-
query predicate scopeNoFirst(CfgScope scope) {
23-
Consistency::scopeNoFirst(scope) and
24-
not scope = any(StmtSequence seq | not exists(seq.getAStmt())) and
25-
not scope =
26-
any(Callable c |
27-
not exists(c.getAParameter()) and
28-
not c.getBody().hasEnsure() and
29-
not exists(c.getBody().getARescue())
30-
)
31-
}
2+
import ControlFlow::Consistency

ruby/ql/consistency-queries/DataFlowConsistency.ql

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,6 @@ private module Input implements InputSig<Location, RubyDataFlow> {
2222
not isNonConstantExpr(n.asExpr())
2323
}
2424

25-
predicate multipleArgumentCallExclude(ArgumentNode arg, DataFlowCall call) {
26-
// An argument such as `x` in `if not x then ...` has two successors (and hence
27-
// two calls); one for each Boolean outcome of `x`.
28-
exists(CfgNodes::ExprCfgNode n |
29-
arg.argumentOf(call, _) and
30-
n = call.asCall() and
31-
arg.asExpr().getASuccessor(any(ConditionalSuccessor c)).getASuccessor*() = n and
32-
n.getASplit() instanceof Split::ConditionalCompletionSplit
33-
)
34-
}
35-
3625
predicate uniqueTypeExclude(Node n) {
3726
n =
3827
any(DataFlow::CallNode call |

ruby/ql/lib/codeql/ruby/CFG.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
import codeql.Locations
44
import controlflow.ControlFlowGraph
55
import controlflow.CfgNodes as CfgNodes
6-
import controlflow.BasicBlocks

ruby/ql/lib/codeql/ruby/ast/Statement.qll

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,21 @@ private import codeql.ruby.CFG
66
private import internal.AST
77
private import internal.TreeSitter
88
private import internal.Variable
9-
private import codeql.ruby.controlflow.internal.ControlFlowGraphImpl as CfgImpl
109

1110
/**
1211
* A statement.
1312
*
1413
* This is the root QL class for all statements.
1514
*/
1615
class Stmt extends AstNode, TStmt {
16+
/** Gets the control-flow node for this statement, if any. */
17+
ControlFlowNode getControlFlowNode() { result.injects(this) }
18+
1719
/** Gets a control-flow node for this statement, if any. */
1820
CfgNodes::AstCfgNode getAControlFlowNode() { result.getAstNode() = this }
1921

20-
/** Gets a control-flow entry node for this statement, if any */
21-
AstNode getAControlFlowEntryNode() { result = CfgImpl::getAControlFlowEntryNode(this) }
22-
2322
/** Gets the control-flow scope of this statement, if any. */
24-
CfgScope getCfgScope() { result = CfgImpl::getCfgScope(this) }
23+
CfgScope getCfgScope() { result = getEnclosingCallable(this) }
2524

2625
/** Gets the enclosing callable, if any. */
2726
Callable getEnclosingCallable() { result = this.getCfgScope() }

ruby/ql/lib/codeql/ruby/controlflow/BasicBlocks.qll

Lines changed: 0 additions & 314 deletions
This file was deleted.

0 commit comments

Comments
 (0)