Skip to content

Commit b78f124

Browse files
committed
Swift: tweak priority of location information sources
1 parent 386dedb commit b78f124

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

swift/extractor/infra/SwiftLocationExtractor.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,38 @@ namespace codeql {
1616
class TrapDomain;
1717

1818
namespace detail {
19+
template <typename T>
20+
concept HasSourceRange = requires(T e) {
21+
e.getSourceRange();
22+
};
23+
1924
template <typename T>
2025
concept HasStartAndEndLoc = requires(T e) {
2126
e.getStartLoc();
2227
e.getEndLoc();
23-
};
28+
}
29+
&&!(HasSourceRange<T>);
2430

2531
template <typename T>
2632
concept HasOneLoc = requires(T e) {
2733
e.getLoc();
2834
}
29-
&&(!HasStartAndEndLoc<T>);
35+
&&!(HasSourceRange<T>)&&(!HasStartAndEndLoc<T>);
3036

3137
template <typename T>
3238
concept HasOneLocField = requires(T e) {
3339
e.Loc;
3440
};
3541

36-
template <typename T>
37-
concept HasSourceRangeOnly = requires(T e) {
38-
e.getSourceRange();
42+
swift::SourceRange getSourceRange(const HasSourceRange auto& locatable) {
43+
return locatable.getSourceRange();
3944
}
40-
&&(!HasStartAndEndLoc<T>)&&(!HasOneLoc<T>);
4145

4246
swift::SourceRange getSourceRange(const HasStartAndEndLoc auto& locatable) {
4347
if (locatable.getStartLoc() && locatable.getEndLoc()) {
4448
return {locatable.getStartLoc(), locatable.getEndLoc()};
4549
}
46-
return {};
50+
return {locatable.getStartLoc()};
4751
}
4852

4953
swift::SourceRange getSourceRange(const HasOneLoc auto& locatable) {
@@ -54,10 +58,6 @@ swift::SourceRange getSourceRange(const HasOneLocField auto& locatable) {
5458
return {locatable.Loc};
5559
}
5660

57-
swift::SourceRange getSourceRange(const HasSourceRangeOnly auto& locatable) {
58-
return locatable.getSourceRange();
59-
}
60-
6161
swift::SourceRange getSourceRange(const swift::Token& token);
6262

6363
template <typename Locatable>
@@ -70,7 +70,7 @@ swift::SourceRange getSourceRange(const llvm::MutableArrayRef<Locatable>& locata
7070
if (startRange.Start && endRange.End) {
7171
return {startRange.Start, endRange.End};
7272
}
73-
return {};
73+
return {startRange.Start};
7474
}
7575
} // namespace detail
7676

0 commit comments

Comments
 (0)