Skip to content

Commit 77db0cf

Browse files
authored
Merge pull request github#13334 from aibaars/print-cfg-2
Ruby: printCfg: only show graph for selected CfgScope
2 parents 9359bea + e93b446 commit 77db0cf

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

ruby/ql/lib/ide-contextual-queries/printCfg.ql

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,45 @@
99

1010
private import codeql.ruby.controlflow.internal.ControlFlowGraphImpl::TestOutput
1111
private import codeql.IDEContextual
12+
private import codeql.Locations
13+
private import codeql.ruby.controlflow.ControlFlowGraph
1214

1315
/**
1416
* Gets the source file to generate a CFG from.
1517
*/
1618
external string selectedSourceFile();
1719

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+
1847
class MyRelevantNode extends RelevantNode {
1948
MyRelevantNode() {
20-
this.getScope().getLocation().getFile() = getFileBySourceArchiveName(selectedSourceFile())
49+
this.getScope() =
50+
smallestEnclosingScope(getFileBySourceArchiveName(selectedSourceFile()),
51+
selectedSourceLine().toInt(), selectedSourceColumn().toInt())
2152
}
2253
}

0 commit comments

Comments
 (0)