diff options
author | Mikhail Maltsev <mikhail.maltsev@arm.com> | 2020-10-20 16:21:38 +0100 |
---|---|---|
committer | Mikhail Maltsev <mikhail.maltsev@arm.com> | 2020-10-20 16:24:09 +0100 |
commit | 781941183700b52d11b27227e3341385447610fa (patch) | |
tree | 5dec0334d46c225f0ee46575e4ecc39710d85c90 /clang/lib/Tooling/Syntax/BuildTree.cpp | |
parent | c76cdeac93380b434349738d96f83d3ffda9869c (diff) | |
download | llvm-781941183700b52d11b27227e3341385447610fa.zip llvm-781941183700b52d11b27227e3341385447610fa.tar.gz llvm-781941183700b52d11b27227e3341385447610fa.tar.bz2 |
[clang] Use SourceLocation as key in hash maps, NFCI
The patch adjusts the existing `llvm::DenseMap<unsigned, T>` and
`llvm::DenseSet<unsigned>` objects that store source locations, so
that they use `SourceLocation` directly instead of `unsigned`.
This patch relies on the `DenseMapInfo` trait added in D89719.
It also replaces the construction of `SourceLocation` objects from
the constants -1 and -2 with calls to the trait's methods `getEmptyKey`
and `getTombstoneKey` where appropriate.
Reviewed By: dexonsmith
Differential Revision: https://reviews.llvm.org/D69840
Diffstat (limited to 'clang/lib/Tooling/Syntax/BuildTree.cpp')
-rw-r--r-- | clang/lib/Tooling/Syntax/BuildTree.cpp | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/clang/lib/Tooling/Syntax/BuildTree.cpp b/clang/lib/Tooling/Syntax/BuildTree.cpp index e1ed55f..1975905 100644 --- a/clang/lib/Tooling/Syntax/BuildTree.cpp +++ b/clang/lib/Tooling/Syntax/BuildTree.cpp @@ -367,7 +367,7 @@ class syntax::TreeBuilder { public: TreeBuilder(syntax::Arena &Arena) : Arena(Arena), Pending(Arena) { for (const auto &T : Arena.getTokenBuffer().expandedTokens()) - LocationToToken.insert({T.location().getRawEncoding(), &T}); + LocationToToken.insert({T.location(), &T}); } llvm::BumpPtrAllocator &allocator() { return Arena.getAllocator(); } @@ -689,8 +689,7 @@ private: syntax::Arena &Arena; /// To quickly find tokens by their start location. - llvm::DenseMap</*SourceLocation*/ unsigned, const syntax::Token *> - LocationToToken; + llvm::DenseMap<SourceLocation, const syntax::Token *> LocationToToken; Forest Pending; llvm::DenseSet<Decl *> DeclsWithoutSemicolons; ASTToSyntaxMapping Mapping; @@ -1708,7 +1707,7 @@ void syntax::TreeBuilder::markExprChild(Expr *Child, NodeRole Role) { const syntax::Token *syntax::TreeBuilder::findToken(SourceLocation L) const { if (L.isInvalid()) return nullptr; - auto It = LocationToToken.find(L.getRawEncoding()); + auto It = LocationToToken.find(L); assert(It != LocationToToken.end()); return It->second; } |