Skip to content

Commit dd52a70

Browse files
authored
Merge pull request github#9292 from github/nickrolfe/cfg_scope
Ruby: rename CfgScope::Range_ to CfgScopeImpl
2 parents daace0f + 4b4a15c commit dd52a70

File tree

3 files changed

+38
-40
lines changed

3 files changed

+38
-40
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ private import internal.Splitting
99
private import internal.Completion
1010

1111
/** An AST node with an associated control-flow graph. */
12-
class CfgScope extends Scope instanceof CfgScope::Range_ {
12+
class CfgScope extends Scope instanceof CfgScopeImpl {
1313
/** Gets the CFG scope that this scope is nested under, if any. */
1414
final CfgScope getOuterCfgScope() {
1515
exists(AstNode parent |

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

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -41,61 +41,59 @@ private import codeql.ruby.controlflow.ControlFlowGraph
4141
private import Completion
4242
import ControlFlowGraphImplShared
4343

44-
module CfgScope {
45-
abstract class Range_ extends AstNode {
46-
abstract predicate entry(AstNode first);
44+
abstract class CfgScopeImpl extends AstNode {
45+
abstract predicate entry(AstNode first);
4746

48-
abstract predicate exit(AstNode last, Completion c);
49-
}
47+
abstract predicate exit(AstNode last, Completion c);
48+
}
5049

51-
private class ToplevelScope extends Range_, Toplevel {
52-
final override predicate entry(AstNode first) { first(this, first) }
50+
private class ToplevelScope extends CfgScopeImpl, Toplevel {
51+
final override predicate entry(AstNode first) { first(this, first) }
5352

54-
final override predicate exit(AstNode last, Completion c) { last(this, last, c) }
55-
}
53+
final override predicate exit(AstNode last, Completion c) { last(this, last, c) }
54+
}
5655

57-
private class EndBlockScope extends Range_, EndBlock {
58-
final override predicate entry(AstNode first) {
59-
first(this.(Trees::EndBlockTree).getBodyChild(0, _), first)
60-
}
56+
private class EndBlockScope extends CfgScopeImpl, EndBlock {
57+
final override predicate entry(AstNode first) {
58+
first(this.(Trees::EndBlockTree).getBodyChild(0, _), first)
59+
}
6160

62-
final override predicate exit(AstNode last, Completion c) {
63-
last(this.(Trees::EndBlockTree).getLastBodyChild(), last, c)
64-
or
65-
last(this.(Trees::EndBlockTree).getBodyChild(_, _), last, c) and
66-
not c instanceof NormalCompletion
67-
}
61+
final override predicate exit(AstNode last, Completion c) {
62+
last(this.(Trees::EndBlockTree).getLastBodyChild(), last, c)
63+
or
64+
last(this.(Trees::EndBlockTree).getBodyChild(_, _), last, c) and
65+
not c instanceof NormalCompletion
6866
}
67+
}
6968

70-
private class BodyStmtCallableScope extends Range_, ASTInternal::TBodyStmt, Callable {
71-
final override predicate entry(AstNode first) { this.(Trees::BodyStmtTree).firstInner(first) }
69+
private class BodyStmtCallableScope extends CfgScopeImpl, ASTInternal::TBodyStmt, Callable {
70+
final override predicate entry(AstNode first) { this.(Trees::BodyStmtTree).firstInner(first) }
7271

73-
final override predicate exit(AstNode last, Completion c) {
74-
this.(Trees::BodyStmtTree).lastInner(last, c)
75-
}
72+
final override predicate exit(AstNode last, Completion c) {
73+
this.(Trees::BodyStmtTree).lastInner(last, c)
7674
}
75+
}
7776

78-
private class BraceBlockScope extends Range_, BraceBlock {
79-
final override predicate entry(AstNode first) {
80-
first(this.(Trees::BraceBlockTree).getBodyChild(0, _), first)
81-
}
77+
private class BraceBlockScope extends CfgScopeImpl, BraceBlock {
78+
final override predicate entry(AstNode first) {
79+
first(this.(Trees::BraceBlockTree).getBodyChild(0, _), first)
80+
}
8281

83-
final override predicate exit(AstNode last, Completion c) {
84-
last(this.(Trees::BraceBlockTree).getLastBodyChild(), last, c)
85-
or
86-
last(this.(Trees::BraceBlockTree).getBodyChild(_, _), last, c) and
87-
not c instanceof NormalCompletion
88-
}
82+
final override predicate exit(AstNode last, Completion c) {
83+
last(this.(Trees::BraceBlockTree).getLastBodyChild(), last, c)
84+
or
85+
last(this.(Trees::BraceBlockTree).getBodyChild(_, _), last, c) and
86+
not c instanceof NormalCompletion
8987
}
9088
}
9189

9290
/** Holds if `first` is first executed when entering `scope`. */
9391
pragma[nomagic]
94-
predicate succEntry(CfgScope::Range_ scope, AstNode first) { scope.entry(first) }
92+
predicate succEntry(CfgScopeImpl scope, AstNode first) { scope.entry(first) }
9593

9694
/** Holds if `last` with completion `c` can exit `scope`. */
9795
pragma[nomagic]
98-
predicate succExit(CfgScope::Range_ scope, AstNode last, Completion c) { scope.exit(last, c) }
96+
predicate succExit(CfgScopeImpl scope, AstNode last, Completion c) { scope.exit(last, c) }
9997

10098
/** Defines the CFG by dispatch on the various AST types. */
10199
module Trees {
@@ -1431,7 +1429,7 @@ module Trees {
14311429

14321430
private Scope parent(Scope n) {
14331431
result = n.getOuterScope() and
1434-
not n instanceof CfgScope::Range_
1432+
not n instanceof CfgScopeImpl
14351433
}
14361434

14371435
cached

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ predicate getCfgScope = Impl::getCfgScope/1;
3535

3636
/** Holds if `first` is first executed when entering `scope`. */
3737
predicate scopeFirst(CfgScope scope, ControlFlowElement first) {
38-
scope.(Impl::CfgScope::Range_).entry(first)
38+
scope.(Impl::CfgScopeImpl).entry(first)
3939
}
4040

4141
/** Holds if `scope` is exited when `last` finishes with completion `c`. */
4242
predicate scopeLast(CfgScope scope, ControlFlowElement last, Completion c) {
43-
scope.(Impl::CfgScope::Range_).exit(last, c)
43+
scope.(Impl::CfgScopeImpl).exit(last, c)
4444
}
4545

4646
/** The maximum number of splits allowed for a given node. */

0 commit comments

Comments
 (0)