Skip to content

Commit 32ef535

Browse files
authored
Merge pull request github#9430 from github/redsun82/swift-unknown-location
Swift: add `UnknownLocation`
2 parents 28d2fd7 + a0acb19 commit 32ef535

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

swift/extractor/SwiftExtractor.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ static void extractFile(const SwiftExtractorConfiguration& config,
8484
TrapOutput trap{trapStream};
8585
TrapArena arena{};
8686

87+
// TODO move default location emission elsewhere, possibly in a separate global trap file
88+
auto unknownFileLabel = arena.allocateLabel<FileTag>();
89+
// the following cannot conflict with actual files as those have an absolute path starting with /
90+
trap.assignKey(unknownFileLabel, "unknown");
91+
trap.emit(FilesTrap{unknownFileLabel});
92+
auto unknownLocationLabel = arena.allocateLabel<LocationTag>();
93+
trap.assignKey(unknownLocationLabel, "unknown");
94+
trap.emit(LocationsTrap{unknownLocationLabel, unknownFileLabel});
95+
8796
// In the case of emtpy files, the dispatcher is not called, but we still want to 'record' the
8897
// fact that the file was extracted
8998
// TODO: to be moved elsewhere
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
21
private import codeql.swift.generated.Locatable
32

4-
class Locatable extends LocatableBase { }
3+
class Locatable extends LocatableBase {
4+
override Location getLocation() {
5+
result = LocatableBase.super.getLocation()
6+
or
7+
not exists(LocatableBase.super.getLocation()) and result instanceof UnknownLocation
8+
}
9+
}

swift/ql/lib/codeql/swift/elements/Location.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ class Location extends LocationBase {
99
ec = getEndColumn()
1010
}
1111
}
12+
13+
class UnknownLocation extends Location {
14+
UnknownLocation() { hasLocationInfo("", 0, 0, 0, 0) }
15+
}

swift/ql/test/extractor-tests/declarations/accessor.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ predicate isKnownKind(AccessorDecl decl, string kind) {
1212

1313
from AccessorDecl decl, string kind
1414
where
15-
exists(decl.getLocation()) and
15+
decl.getLocation().getFile().getName().matches("%swift/ql/test%") and
1616
(
1717
isKnownKind(decl, kind)
1818
or
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
| file://:0:0:0:0 | |
12
| hello.swift:0:0:0:0 | hello.swift |

0 commit comments

Comments
 (0)