Swift: tweak location extractor using new concept

This commit is contained in:
Paolo Tranquilli
2023-08-18 06:45:11 +02:00
parent eb8997dc7a
commit 53ed39065c
2 changed files with 6 additions and 8 deletions

View File

@@ -59,13 +59,11 @@ swift::SourceRange getSourceRange(const llvm::MutableArrayRef<Locatable>& locata
auto endRange = getSourceRange(locatables.back());
return {startRange.Start, endRange.End};
}
// default case, no location
swift::SourceRange getSourceRange(const auto&) {
return {};
}
} // namespace detail
template <typename E>
concept IsLocatable = requires(E e) { detail::getSourceRange(e); };
class SwiftLocationExtractor {
public:
explicit SwiftLocationExtractor(TrapDomain& trap) : trap(trap) {}
@@ -75,13 +73,13 @@ class SwiftLocationExtractor {
// Emits a Location TRAP entry and attaches it to a `Locatable` trap label
void attachLocation(const swift::SourceManager& sourceManager,
const auto& locatable,
const IsLocatable auto& locatable,
TrapLabel<LocatableTag> locatableLabel) {
attachLocationImpl(sourceManager, detail::getSourceRange(locatable), locatableLabel);
}
void attachLocation(const swift::SourceManager& sourceManager,
const auto* locatable,
const IsLocatable auto* locatable,
TrapLabel<LocatableTag> locatableLabel) {
attachLocation(sourceManager, *locatable, locatableLabel);
}