Skip to content

Commit db1fb38

Browse files
authored
Merge pull request #18417 from mhong/denseinfo_source_range
2 parents b3c9dbe + 83d4bca commit db1fb38

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

include/swift/Basic/SourceLoc.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define SWIFT_BASIC_SOURCELOC_H
1919

2020
#include "swift/Basic/LLVM.h"
21+
#include "llvm/ADT/DenseMapInfo.h"
2122
#include "llvm/ADT/StringRef.h"
2223
#include "llvm/Support/SMLoc.h"
2324
#include <functional>
@@ -214,4 +215,58 @@ class CharSourceRange {
214215

215216
} // end namespace swift
216217

218+
namespace llvm {
219+
template <typename T> struct DenseMapInfo;
220+
221+
template <> struct DenseMapInfo<swift::SourceLoc> {
222+
static swift::SourceLoc getEmptyKey() {
223+
return swift::SourceLoc(
224+
SMLoc::getFromPointer(DenseMapInfo<const char *>::getEmptyKey()));
225+
}
226+
227+
static swift::SourceLoc getTombstoneKey() {
228+
// Make this different from empty key. See for context:
229+
// http://lists.llvm.org/pipermail/llvm-dev/2015-July/088744.html
230+
return swift::SourceLoc(
231+
SMLoc::getFromPointer(DenseMapInfo<const char *>::getTombstoneKey()));
232+
}
233+
234+
static unsigned getHashValue(const swift::SourceLoc &Val) {
235+
return DenseMapInfo<const void *>::getHashValue(
236+
Val.getOpaquePointerValue());
237+
}
238+
239+
static bool isEqual(const swift::SourceLoc &LHS,
240+
const swift::SourceLoc &RHS) {
241+
return LHS == RHS;
242+
}
243+
};
244+
245+
template <> struct DenseMapInfo<swift::SourceRange> {
246+
static swift::SourceRange getEmptyKey() {
247+
return swift::SourceRange(swift::SourceLoc(
248+
SMLoc::getFromPointer(DenseMapInfo<const char *>::getEmptyKey())));
249+
}
250+
251+
static swift::SourceRange getTombstoneKey() {
252+
// Make this different from empty key. See for context:
253+
// http://lists.llvm.org/pipermail/llvm-dev/2015-July/088744.html
254+
return swift::SourceRange(swift::SourceLoc(
255+
SMLoc::getFromPointer(DenseMapInfo<const char *>::getTombstoneKey())));
256+
}
257+
258+
static unsigned getHashValue(const swift::SourceRange &Val) {
259+
return hash_combine(DenseMapInfo<const void *>::getHashValue(
260+
Val.Start.getOpaquePointerValue()),
261+
DenseMapInfo<const void *>::getHashValue(
262+
Val.End.getOpaquePointerValue()));
263+
}
264+
265+
static bool isEqual(const swift::SourceRange &LHS,
266+
const swift::SourceRange &RHS) {
267+
return LHS == RHS;
268+
}
269+
};
270+
} // namespace llvm
271+
217272
#endif // SWIFT_BASIC_SOURCELOC_H

0 commit comments

Comments
 (0)