|
8 | 8 | */ |
9 | 9 |
|
10 | 10 | import ql |
11 | | -import codeql_ql.ast.internal.Module |
12 | | -import codeql_ql.ast.internal.Type |
| 11 | +import Definitions |
13 | 12 | import codeql.IDEContextual |
14 | 13 |
|
15 | 14 | external string selectedSourceFile(); |
16 | 15 |
|
17 | | -newtype TLoc = |
18 | | - TAst(AstNode n) or |
19 | | - TFileOrModule(FileOrModule m) |
20 | | - |
21 | | -class Loc extends TLoc { |
22 | | - string toString() { result = "" } |
23 | | - |
24 | | - AstNode asAst() { this = TAst(result) } |
25 | | - |
26 | | - FileOrModule asMod() { this = TFileOrModule(result) } |
27 | | - |
28 | | - predicate hasLocationInfo( |
29 | | - string filepath, int startline, int startcolumn, int endline, int endcolumn |
30 | | - ) { |
31 | | - exists(AstNode n | this = TAst(n) | |
32 | | - n.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) |
33 | | - ) |
34 | | - or |
35 | | - exists(FileOrModule m | this = TFileOrModule(m) | |
36 | | - m.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) |
37 | | - ) |
38 | | - } |
39 | | -} |
40 | | - |
41 | | -predicate resolveModule(ModuleRef ref, FileOrModule target, string kind) { |
42 | | - target = ref.getResolvedModule() and |
43 | | - kind = "module" and |
44 | | - ref.getLocation().getFile() = getFileBySourceArchiveName(selectedSourceFile()) |
45 | | -} |
46 | | - |
47 | | -predicate resolveType(TypeExpr ref, AstNode target, string kind) { |
48 | | - target = ref.getResolvedType().getDeclaration() and |
49 | | - kind = "type" and |
50 | | - ref.getLocation().getFile() = getFileBySourceArchiveName(selectedSourceFile()) |
51 | | -} |
52 | | - |
53 | | -predicate resolvePredicate(PredicateExpr ref, Predicate target, string kind) { |
54 | | - target = ref.getResolvedPredicate() and |
55 | | - kind = "predicate" and |
56 | | - ref.getLocation().getFile() = getFileBySourceArchiveName(selectedSourceFile()) |
57 | | -} |
58 | | - |
59 | | -predicate resolve(Loc ref, Loc target, string kind) { |
60 | | - resolveModule(ref.asAst(), target.asMod(), kind) |
61 | | - or |
62 | | - resolveType(ref.asAst(), target.asAst(), kind) |
63 | | - or |
64 | | - resolvePredicate(ref.asAst(), target.asAst(), kind) |
65 | | -} |
66 | | - |
67 | 16 | from Loc ref, Loc target, string kind |
68 | | -where resolve(ref, target, kind) |
| 17 | +where |
| 18 | + resolve(ref, target, kind) and |
| 19 | + ref.getFile() = getFileBySourceArchiveName(selectedSourceFile()) |
69 | 20 | select ref, target, kind |
0 commit comments