@@ -45,18 +45,14 @@ class SwiftDispatcher {
45
45
// the SwiftDispatcher
46
46
SwiftDispatcher (const swift::SourceManager& sourceManager,
47
47
TrapDomain& trap,
48
+ SwiftLocationExtractor& locationExtractor,
48
49
swift::ModuleDecl& currentModule,
49
50
swift::SourceFile* currentPrimarySourceFile = nullptr )
50
51
: sourceManager{sourceManager},
51
52
trap{trap},
53
+ locationExtractor{locationExtractor},
52
54
currentModule{currentModule},
53
- currentPrimarySourceFile{currentPrimarySourceFile},
54
- locationExtractor (trap) {
55
- if (currentPrimarySourceFile) {
56
- // we make sure the file is in the trap output even if the source is empty
57
- locationExtractor.emitFile (currentPrimarySourceFile->getFilename ());
58
- }
59
- }
55
+ currentPrimarySourceFile{currentPrimarySourceFile} {}
60
56
61
57
const std::unordered_set<swift::ModuleDecl*> getEncounteredModules () && {
62
58
return std::move (encounteredModules);
@@ -157,7 +153,7 @@ class SwiftDispatcher {
157
153
// TODO when everything is moved to structured C++ classes, this should be moved to createEntry
158
154
if (auto l = store.get (e)) {
159
155
if constexpr (IsLocatable<E>) {
160
- attachLocation (e, *l);
156
+ locationExtractor. attachLocation (sourceManager, e, *l);
161
157
}
162
158
return *l;
163
159
}
@@ -206,50 +202,10 @@ class SwiftDispatcher {
206
202
template <typename E, typename ... Args>
207
203
auto createUncachedEntry (const E& e, Args&&... args) {
208
204
auto label = trap.createLabel <TrapTagOf<E>>(std::forward<Args>(args)...);
209
- attachLocation (&e, label);
205
+ locationExtractor. attachLocation (sourceManager, &e, label);
210
206
return TrapClassOf<E>{label};
211
207
}
212
208
213
- template <typename Locatable>
214
- void attachLocation (Locatable locatable, TrapLabel<LocatableTag> locatableLabel) {
215
- attachLocation (&locatable, locatableLabel);
216
- }
217
-
218
- // Emits a Location TRAP entry and attaches it to a `Locatable` trap label
219
- template <typename Locatable>
220
- void attachLocation (Locatable* locatable, TrapLabel<LocatableTag> locatableLabel) {
221
- attachLocation (locatable->getStartLoc (), locatable->getEndLoc (), locatableLabel);
222
- }
223
-
224
- void attachLocation (const swift::CapturedValue* capture, TrapLabel<LocatableTag> locatableLabel) {
225
- attachLocation (capture->getLoc (), locatableLabel);
226
- }
227
-
228
- void attachLocation (const swift::IfConfigClause* clause, TrapLabel<LocatableTag> locatableLabel) {
229
- attachLocation (clause->Loc , clause->Loc , locatableLabel);
230
- }
231
-
232
- void attachLocation (swift::AvailabilitySpec* spec, TrapLabel<LocatableTag> locatableLabel) {
233
- attachLocation (spec->getSourceRange ().Start , spec->getSourceRange ().End , locatableLabel);
234
- }
235
-
236
- // Emits a Location TRAP entry and attaches it to a `Locatable` trap label for a given `SourceLoc`
237
- void attachLocation (swift::SourceLoc loc, TrapLabel<LocatableTag> locatableLabel) {
238
- attachLocation (loc, loc, locatableLabel);
239
- }
240
-
241
- // Emits a Location TRAP entry for a list of swift entities and attaches it to a `Locatable` trap
242
- // label
243
- template <typename Locatable>
244
- void attachLocation (llvm::MutableArrayRef<Locatable>* locatables,
245
- TrapLabel<LocatableTag> locatableLabel) {
246
- if (locatables->empty ()) {
247
- return ;
248
- }
249
- attachLocation (locatables->front ().getStartLoc (), locatables->back ().getEndLoc (),
250
- locatableLabel);
251
- }
252
-
253
209
// return `std::optional(fetchLabel(arg))` if arg converts to true, otherwise std::nullopt
254
210
// universal reference `Arg&&` is used to catch both temporary and non-const references, not
255
211
// for perfect forwarding
@@ -317,7 +273,7 @@ class SwiftDispatcher {
317
273
void emitComment (swift::Token& comment) {
318
274
CommentsTrap entry{trap.createLabel <CommentTag>(), comment.getRawText ().str ()};
319
275
trap.emit (entry);
320
- attachLocation (comment. getRange (). getStart () , comment. getRange (). getEnd () , entry.id );
276
+ locationExtractor. attachLocation (sourceManager , comment, entry.id );
321
277
}
322
278
323
279
private:
@@ -333,12 +289,6 @@ class SwiftDispatcher {
333
289
template <typename T>
334
290
struct HasId <T, decltype (std::declval<T>().id, void ())> : std::true_type {};
335
291
336
- void attachLocation (swift::SourceLoc start,
337
- swift::SourceLoc end,
338
- TrapLabel<LocatableTag> locatableLabel) {
339
- locationExtractor.attachLocation (sourceManager, start, end, locatableLabel);
340
- }
341
-
342
292
template <typename Tag, typename ... Ts>
343
293
TrapLabel<Tag> fetchLabelFromUnion (const llvm::PointerUnion<Ts...> u) {
344
294
TrapLabel<Tag> ret{};
@@ -382,11 +332,11 @@ class SwiftDispatcher {
382
332
const swift::SourceManager& sourceManager;
383
333
TrapDomain& trap;
384
334
Store store;
335
+ SwiftLocationExtractor& locationExtractor;
385
336
Store::Handle waitingForNewLabel{std::monostate{}};
386
337
swift::ModuleDecl& currentModule;
387
338
swift::SourceFile* currentPrimarySourceFile;
388
339
std::unordered_set<swift::ModuleDecl*> encounteredModules;
389
- SwiftLocationExtractor locationExtractor;
390
340
};
391
341
392
342
} // namespace codeql
0 commit comments