|
9 | 9 |
|
10 | 10 | private import codeql.ruby.controlflow.internal.ControlFlowGraphImpl::TestOutput
|
11 | 11 | private import codeql.IDEContextual
|
| 12 | +private import codeql.Locations |
| 13 | +private import codeql.ruby.controlflow.ControlFlowGraph |
12 | 14 |
|
13 | 15 | /**
|
14 | 16 | * Gets the source file to generate a CFG from.
|
15 | 17 | */
|
16 | 18 | external string selectedSourceFile();
|
17 | 19 |
|
| 20 | +external string selectedSourceLine(); |
| 21 | + |
| 22 | +external string selectedSourceColumn(); |
| 23 | + |
| 24 | +bindingset[file, line, column] |
| 25 | +private CfgScope smallestEnclosingScope(File file, int line, int column) { |
| 26 | + result = |
| 27 | + min(Location loc, CfgScope scope | |
| 28 | + loc = scope.getLocation() and |
| 29 | + ( |
| 30 | + loc.getStartLine() < line |
| 31 | + or |
| 32 | + loc.getStartLine() = line and loc.getStartColumn() <= column |
| 33 | + ) and |
| 34 | + ( |
| 35 | + loc.getEndLine() > line |
| 36 | + or |
| 37 | + loc.getEndLine() = line and loc.getEndColumn() >= column |
| 38 | + ) and |
| 39 | + loc.getFile() = file |
| 40 | + | |
| 41 | + scope |
| 42 | + order by |
| 43 | + loc.getStartLine() desc, loc.getStartColumn() desc, loc.getEndLine(), loc.getEndColumn() |
| 44 | + ) |
| 45 | +} |
| 46 | + |
18 | 47 | class MyRelevantNode extends RelevantNode {
|
19 | 48 | MyRelevantNode() {
|
20 |
| - this.getScope().getLocation().getFile() = getFileBySourceArchiveName(selectedSourceFile()) |
| 49 | + this.getScope() = |
| 50 | + smallestEnclosingScope(getFileBySourceArchiveName(selectedSourceFile()), |
| 51 | + selectedSourceLine().toInt(), selectedSourceColumn().toInt()) |
21 | 52 | }
|
22 | 53 | }
|
0 commit comments