Skip to content

Commit e468434

Browse files
alexrfordhvitved
authored andcommitted
ruby: drop special handling of for-in loops in the CFG
1 parent ddfcfc9 commit e468434

File tree

3 files changed

+0
-107
lines changed

3 files changed

+0
-107
lines changed

ruby/ql/lib/codeql/ruby/ast/internal/AST.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ private module Cached {
132132
TFalseLiteral(Ruby::False g) or
133133
TFloatLiteral(Ruby::Float g) { not any(Ruby::Rational r).getChild() = g } or
134134
TForExpr(Ruby::For g) or
135-
TForIn(Ruby::In g) or // TODO REMOVE
136135
TForwardParameter(Ruby::ForwardParameter g) or
137136
TForwardArgument(Ruby::ForwardArgument g) or
138137
TGEExpr(Ruby::Binary g) { g instanceof @ruby_binary_rangleequal } or
@@ -389,7 +388,6 @@ private module Cached {
389388
n = TFalseLiteral(result) or
390389
n = TFloatLiteral(result) or
391390
n = TForExpr(result) or
392-
n = TForIn(result) or // TODO REMOVE
393391
n = TForwardArgument(result) or
394392
n = TForwardParameter(result) or
395393
n = TGEExpr(result) or

ruby/ql/lib/codeql/ruby/controlflow/internal/Completion.qll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ private predicate nestedEnsureCompletion(Completion outer, int nestLevel) {
5454

5555
pragma[noinline]
5656
private predicate completionIsValidForStmt(AstNode n, Completion c) {
57-
n = TForIn(_) and
58-
c instanceof EmptinessCompletion
59-
or
6057
n instanceof BreakStmt and
6158
c = TBreakCompletion()
6259
or

ruby/ql/lib/codeql/ruby/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,6 @@ predicate succEntry(CfgScope::Range_ scope, AstNode first) { scope.entry(first)
9191
pragma[nomagic]
9292
predicate succExit(CfgScope::Range_ scope, AstNode last, Completion c) { scope.exit(last, c) }
9393

94-
// TODO: remove this class; it should be replaced with an implicit non AST node
95-
private class ForIn extends AstNode, ASTInternal::TForIn {
96-
final override string toString() { result = "In" }
97-
}
98-
99-
// TODO: remove this class; it should be replaced with an implicit non AST node
100-
private class ForRange extends ForExpr {
101-
override AstNode getAChild(string pred) {
102-
result = super.getAChild(pred)
103-
or
104-
pred = "<in>" and
105-
result = this.getIn()
106-
}
107-
108-
ForIn getIn() {
109-
result = ASTInternal::TForIn(ASTInternal::toGenerated(this).(Ruby::For).getValue())
110-
}
111-
}
112-
11394
/** Defines the CFG by dispatch on the various AST types. */
11495
module Trees {
11596
private class AliasStmtTree extends StandardPreOrderTree, AliasStmt {
@@ -610,89 +591,6 @@ module Trees {
610591

611592
private class ForwardParameterTree extends LeafTree, ForwardParameter { }
612593

613-
private class ForInTree extends LeafTree, ForIn { }
614-
615-
/**
616-
* Control flow of a for-in loop
617-
*
618-
* For example, this program fragment:
619-
*
620-
* ```rb
621-
* for arg in args do
622-
* puts arg
623-
* end
624-
* puts "done";
625-
* ```
626-
*
627-
* has the following control flow graph:
628-
*
629-
* ```
630-
* args
631-
* |
632-
* in------<-----
633-
* / \ \
634-
* / \ |
635-
* / \ |
636-
* / \ |
637-
* empty non-empty |
638-
* | \ |
639-
* for \ |
640-
* | arg |
641-
* | | |
642-
* puts "done" puts arg |
643-
* \___/
644-
* ```
645-
*/
646-
private class ForTree extends PostOrderTree, ForRange {
647-
final override predicate propagatesAbnormal(AstNode child) {
648-
child = this.getPattern() or child = this.getValue()
649-
}
650-
651-
final override predicate first(AstNode first) { first(this.getValue(), first) }
652-
653-
/**
654-
* for pattern in array do body end
655-
* ```
656-
* array +-> in +--[non empty]--> pattern -> body -> in
657-
* |--[empty]--> for
658-
* ```
659-
*/
660-
final override predicate succ(AstNode pred, AstNode succ, Completion c) {
661-
last(this.getValue(), pred, c) and
662-
first(this.getIn(), succ) and
663-
c instanceof SimpleCompletion
664-
or
665-
last(this.getIn(), pred, c) and
666-
first(this.getPattern(), succ) and
667-
c.(EmptinessCompletion).getValue() = false
668-
or
669-
last(this.getPattern(), pred, c) and
670-
first(this.getBody(), succ) and
671-
c instanceof NormalCompletion
672-
or
673-
last(this.getBody(), pred, c) and
674-
first(this.getIn(), succ) and
675-
c.continuesLoop()
676-
or
677-
last(this.getBody(), pred, c) and
678-
first(this.getBody(), succ) and
679-
c instanceof RedoCompletion
680-
or
681-
succ = this and
682-
(
683-
last(this.getIn(), pred, c) and
684-
c.(EmptinessCompletion).getValue() = true
685-
or
686-
last(this.getBody(), pred, c) and
687-
not c.continuesLoop() and
688-
not c instanceof BreakCompletion and
689-
not c instanceof RedoCompletion
690-
or
691-
last(this.getBody(), pred, c.(NestedBreakCompletion).getAnInnerCompatibleCompletion())
692-
)
693-
}
694-
}
695-
696594
private class GlobalVariableTree extends LeafTree, GlobalVariableAccess { }
697595

698596
private class HashLiteralTree extends StandardPostOrderTree, HashLiteral {

0 commit comments

Comments
 (0)