mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Swift: tweak location extractor using new concept
This commit is contained in:
@@ -175,7 +175,7 @@ class SwiftDispatcher {
|
||||
CODEQL_ASSERT(found != store.end(), "createEntry called on non-fetched label");
|
||||
using Tag = ConcreteTrapTagOf<E>;
|
||||
auto label = TrapLabel<Tag>::unsafeCreateFromUntyped(found->second);
|
||||
if constexpr (requires { locationExtractor.attachLocation(sourceManager, e, label); }) {
|
||||
if constexpr (IsLocatable<E>) {
|
||||
locationExtractor.attachLocation(sourceManager, e, label);
|
||||
}
|
||||
return TrapClassOf<E>{label};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user