Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 81c907a

Browse files
committed
CFG: fix BEGIN and END blocks
1 parent f2fd1c7 commit 81c907a

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

ql/src/codeql_ruby/controlflow/ControlFlowGraph.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,26 @@ private module CfgScope {
2323

2424
private class BeginBlockScope extends Range, Generated::BeginBlock {
2525
final override string getName() { result = "BEGIN block" }
26+
27+
final override predicate entry(Generated::AstNode first) {
28+
first(this.(Trees::BeginBlockTree).getFirstChildNode(), first)
29+
}
30+
31+
final override predicate exit(Generated::AstNode last, Completion c) {
32+
last(this.(Trees::BeginBlockTree).getLastChildNode(), last, c)
33+
}
2634
}
2735

2836
private class EndBlockScope extends Range, Generated::EndBlock {
2937
final override string getName() { result = "END block" }
38+
39+
final override predicate entry(Generated::AstNode first) {
40+
first(this.(Trees::EndBlockTree).getFirstChildNode(), first)
41+
}
42+
43+
final override predicate exit(Generated::AstNode last, Completion c) {
44+
last(this.(Trees::EndBlockTree).getLastChildNode(), last, c)
45+
}
3046
}
3147

3248
private class MethodScope extends Range, Generated::AstNode {

ql/src/codeql_ruby/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ module Trees {
274274
override predicate isHidden() { any() }
275275
}
276276

277-
private class BeginBlockTree extends StandardPreOrderTree, BeginBlock {
277+
class BeginBlockTree extends PreOrderTree, PostOrderTree, StandardNode, BeginBlock {
278278
final override AstNode getChildNode(int i) { result = this.getChild(i) }
279279
}
280280

@@ -456,7 +456,7 @@ module Trees {
456456

457457
private class EmptyStatementTree extends LeafTree, EmptyStatement { }
458458

459-
private class EndBlockTree extends StandardPreOrderTree, EndBlock {
459+
class EndBlockTree extends StandardNode, PreOrderTree, PostOrderTree, EndBlock {
460460
final override AstNode getChildNode(int i) { result = this.getChild(i) }
461461
}
462462

ql/test/library-tests/controlflow/graph/Cfg.expected

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ cfg.rb:
2626
#-----| -> bar
2727

2828
# 15| enter BEGIN block
29-
#-----| -> BeginBlock
29+
#-----| -> String
3030

3131
# 19| enter END block
32-
#-----| -> EndBlock
32+
#-----| -> String
3333

3434
# 25| enter block
3535
#-----| -> x
@@ -608,10 +608,9 @@ cfg.rb:
608608
#-----| -> puts
609609

610610
# 15| BeginBlock
611-
#-----| -> String
611+
#-----| -> EndBlock
612612

613613
# 16| Call
614-
#-----| -> EndBlock
615614
#-----| -> exit BEGIN block (normal)
616615

617616
# 16| puts
@@ -621,10 +620,9 @@ cfg.rb:
621620
#-----| -> puts
622621

623622
# 19| EndBlock
624-
#-----| -> String
623+
#-----| -> 41
625624

626625
# 20| Call
627-
#-----| -> 41
628626
#-----| -> exit END block (normal)
629627

630628
# 20| puts

0 commit comments

Comments
 (0)