|
18 | 18 | #define SWIFT_BASIC_SOURCELOC_H
|
19 | 19 |
|
20 | 20 | #include "swift/Basic/LLVM.h"
|
| 21 | +#include "llvm/ADT/DenseMapInfo.h" |
21 | 22 | #include "llvm/ADT/StringRef.h"
|
22 | 23 | #include "llvm/Support/SMLoc.h"
|
23 | 24 | #include <functional>
|
@@ -214,4 +215,58 @@ class CharSourceRange {
|
214 | 215 |
|
215 | 216 | } // end namespace swift
|
216 | 217 |
|
| 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 | + |
217 | 272 | #endif // SWIFT_BASIC_SOURCELOC_H
|
0 commit comments