diff options
author | Mikhail Maltsev <mikhail.maltsev@arm.com> | 2020-10-20 15:52:59 +0100 |
---|---|---|
committer | Mikhail Maltsev <mikhail.maltsev@arm.com> | 2020-10-20 15:52:59 +0100 |
commit | 234c47ae2a8e1877de8c661d5bb862ba952eabf9 (patch) | |
tree | 6d2773906e1d709cd195bf44bce6cbbc3f5e9a50 /clang/lib/Basic/SourceLocation.cpp | |
parent | eaa928b71a090905cb178c22054cdf6aa8eb80cb (diff) | |
download | llvm-234c47ae2a8e1877de8c661d5bb862ba952eabf9.zip llvm-234c47ae2a8e1877de8c661d5bb862ba952eabf9.tar.gz llvm-234c47ae2a8e1877de8c661d5bb862ba952eabf9.tar.bz2 |
[clang][Basic] Make SourceLocation usable as key in hash maps, NFCI
This change creates a `DenseMapInfo` trait specialization for the
SourceLocation class. The empty key, the tombstone key, and the hash
function are identical to `DenseMapInfo<unsigned>`, because we already
have hash maps that use raw the representation of `SourceLocation` as
a key.
The update of existing `DenseMap`s containing raw representation of
`SourceLocation`s will be done in a follow-up patch. As an example
the patch makes use of the new trait in one instance:
clang-tidy/google/UpgradeGoogletestCaseCheck.{h,cpp}
Reviewed By: dexonsmith
Differential Revision: https://reviews.llvm.org/D89719
Diffstat (limited to 'clang/lib/Basic/SourceLocation.cpp')
-rw-r--r-- | clang/lib/Basic/SourceLocation.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/clang/lib/Basic/SourceLocation.cpp b/clang/lib/Basic/SourceLocation.cpp index 8cb0899..2ff1797 100644 --- a/clang/lib/Basic/SourceLocation.cpp +++ b/clang/lib/Basic/SourceLocation.cpp @@ -14,6 +14,7 @@ #include "clang/Basic/LLVM.h" #include "clang/Basic/PrettyStackTrace.h" #include "clang/Basic/SourceManager.h" +#include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/MemoryBuffer.h" @@ -40,6 +41,10 @@ void PrettyStackTraceLoc::print(raw_ostream &OS) const { // SourceLocation //===----------------------------------------------------------------------===// +unsigned SourceLocation::getHashValue() const { + return llvm::DenseMapInfo<unsigned>::getHashValue(ID); +} + void SourceLocation::print(raw_ostream &OS, const SourceManager &SM)const{ if (!isValid()) { OS << "<invalid loc>"; |