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