Swift: tweak priority of location information sources

This commit is contained in:
Paolo Tranquilli
2023-08-18 15:18:48 +02:00
parent 386dedb9df
commit b78f12481f

View File

@@ -16,34 +16,38 @@ namespace codeql {
class TrapDomain;
namespace detail {
template <typename T>
concept HasSourceRange = requires(T e) {
e.getSourceRange();
};
template <typename T>
concept HasStartAndEndLoc = requires(T e) {
e.getStartLoc();
e.getEndLoc();
};
}
&&!(HasSourceRange<T>);
template <typename T>
concept HasOneLoc = requires(T e) {
e.getLoc();
}
&&(!HasStartAndEndLoc<T>);
&&!(HasSourceRange<T>)&&(!HasStartAndEndLoc<T>);
template <typename T>
concept HasOneLocField = requires(T e) {
e.Loc;
};
template <typename T>
concept HasSourceRangeOnly = requires(T e) {
e.getSourceRange();
swift::SourceRange getSourceRange(const HasSourceRange auto& locatable) {
return locatable.getSourceRange();
}
&&(!HasStartAndEndLoc<T>)&&(!HasOneLoc<T>);
swift::SourceRange getSourceRange(const HasStartAndEndLoc auto& locatable) {
if (locatable.getStartLoc() && locatable.getEndLoc()) {
return {locatable.getStartLoc(), locatable.getEndLoc()};
}
return {};
return {locatable.getStartLoc()};
}
swift::SourceRange getSourceRange(const HasOneLoc auto& locatable) {
@@ -54,10 +58,6 @@ swift::SourceRange getSourceRange(const HasOneLocField auto& locatable) {
return {locatable.Loc};
}
swift::SourceRange getSourceRange(const HasSourceRangeOnly auto& locatable) {
return locatable.getSourceRange();
}
swift::SourceRange getSourceRange(const swift::Token& token);
template <typename Locatable>
@@ -70,7 +70,7 @@ swift::SourceRange getSourceRange(const llvm::MutableArrayRef<Locatable>& locata
if (startRange.Start && endRange.End) {
return {startRange.Start, endRange.End};
}
return {};
return {startRange.Start};
}
} // namespace detail