Address comments

This commit is contained in:
Arthur Baars
2021-02-12 17:50:00 +01:00
parent 874ac121d9
commit c0c155361f
6 changed files with 40 additions and 5 deletions

View File

@@ -43,14 +43,14 @@ class Toplevel extends ModuleBase, @program {
final override string getAPrimaryQlClass() { result = "Toplevel" }
/**
* Get the `n`th `BEGIN` block.
* Gets the `n`th `BEGIN` block.
*/
final StmtSequence getBeginBlock(int n) { result = range.getBeginBlock(n) }
final BeginBlock getBeginBlock(int n) { result = range.getBeginBlock(n) }
/**
* Get a `BEGIN` block.
* Gets a `BEGIN` block.
*/
final StmtSequence getABeginBlock() { result = getBeginBlock(_) }
final BeginBlock getABeginBlock() { result = getBeginBlock(_) }
}
/**

View File

@@ -35,10 +35,22 @@ class EmptyStmt extends Stmt, @token_empty_statement {
final override string getAPrimaryQlClass() { result = "EmptyStmt" }
}
/**
* An `BEGIN` block.
* ```rb
* BEGIN { puts "starting ..." }
* ```
*/
class BeginBlock extends StmtSequence, @begin_block {
final override BeginBlock::Range range;
final override string getAPrimaryQlClass() { result = "BeginBlock" }
}
/**
* An `END` block.
* ```rb
* END{ puts "shutting down" }
* END { puts "shutting down" }
* ```
*/
class EndBlock extends StmtSequence, @end_block {

View File

@@ -22,6 +22,7 @@ moduleBases
| modules.rb:48:1:57:3 | Bar | Module |
| modules.rb:49:3:50:5 | ClassInAnotherDefinitionOfFooBar | Class |
| modules.rb:60:1:61:3 | MyModuleInGlobalScope | Module |
| toplevel.rb:1:1:5:23 | toplevel.rb | Toplevel |
moduleBaseClasses
| classes.rb:2:1:56:3 | classes.rb | classes.rb:3:1:4:3 | Foo |
| classes.rb:2:1:56:3 | classes.rb | classes.rb:7:1:8:3 | Bar |

View File

@@ -0,0 +1,8 @@
toplevel
| classes.rb:2:1:56:3 | classes.rb | Toplevel |
| modules.rb:1:1:61:3 | modules.rb | Toplevel |
| toplevel.rb:1:1:5:23 | toplevel.rb | Toplevel |
beginBlocks
| toplevel.rb:1:1:5:23 | toplevel.rb | 1 | toplevel.rb:5:1:5:22 | BEGIN { ... } |
endBlocks
| toplevel.rb:1:1:5:23 | toplevel.rb | toplevel.rb:3:1:3:18 | END { ... } |

View File

@@ -0,0 +1,9 @@
import ruby
query predicate toplevel(Toplevel m, string pClass) { pClass = m.getAPrimaryQlClass() }
query predicate beginBlocks(Toplevel m, int i, BeginBlock b) { b = m.getBeginBlock(i) }
query predicate endBlocks(Toplevel m, EndBlock b) {
b.getLocation().getFile() = m.getLocation().getFile()
}

View File

@@ -0,0 +1,5 @@
puts "world"
END { puts "!!!" }
BEGIN { puts "hello" }