Swift: add UnknownLocation

`getLocation()` will now exists for all entities. When there is no
valid location, the location will still not be emitted in the DB, but
on the QL side we will then assign a special `UnknownLocation` with
empty filename and 0 for line/column start/end.

This unknown location is currently emitted (with a unique `@` key) at
the start of every extraction, but we can move it elsewhere (and
possibly in a unique global trap file) at a later stage, possibly after
or when we rework the trap file strategy.

This should solve flakiness that was observed on the control flow tests,
which is probably caused by the `nodes` predicate in the `TestOutput`
class in `ControlFlowGraphImplShared.qll` not able to assign a proper
rank when the node does not have a location.
This commit is contained in:
Paolo Tranquilli
2022-06-03 14:44:47 +02:00
parent 4a025053cc
commit 01e1c13c29
5 changed files with 23 additions and 3 deletions

View File

@@ -84,6 +84,15 @@ static void extractFile(const SwiftExtractorConfiguration& config,
TrapOutput trap{trapStream};
TrapArena arena{};
// TODO move default location emission elsewhere, possibly in a separate global trap file
auto unknownFileLabel = arena.allocateLabel<FileTag>();
// the following cannot conflict with actual files as those have an absolute path starting with /
trap.assignKey(unknownFileLabel, "unknown");
trap.emit(FilesTrap{unknownFileLabel});
auto unknownLocationLabel = arena.allocateLabel<LocationTag>();
trap.assignKey(unknownLocationLabel, "unknown");
trap.emit(LocationsTrap{unknownLocationLabel, unknownFileLabel});
// In the case of emtpy files, the dispatcher is not called, but we still want to 'record' the
// fact that the file was extracted
// TODO: to be moved elsewhere