[PATCH] D138648: [include-cleaner] Make Symbol (and Macro) hashable.
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 24 03:31:31 PST 2022
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.
For now, we decided not to add operator< or handle other variants.
(If we do so in future we may want to extract a base class).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D138648
Files:
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
Index: clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
===================================================================
--- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
+++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
@@ -67,6 +67,9 @@
// FIXME: Add support for macros.
// Order must match Kind enum!
std::variant<const Decl *, struct Macro> Storage;
+
+ Symbol(decltype(Storage) Sentinel) : Storage(std::move(Sentinel)) {}
+ friend llvm::DenseMapInfo<Symbol>;
};
llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Symbol &);
@@ -137,4 +140,37 @@
} // namespace include_cleaner
} // namespace clang
+namespace llvm {
+
+template <> struct DenseMapInfo<clang::include_cleaner::Symbol> {
+ using Outer = clang::include_cleaner::Symbol;
+ constexpr static auto Member = &Outer::Storage;
+ using Base = DenseMapInfo<decltype(Outer::Storage)>;
+
+ static inline Outer getEmptyKey() { return {Base::getEmptyKey()}; }
+ static inline Outer getTombstoneKey() { return {Base::getTombstoneKey()}; }
+ static unsigned getHashValue(const Outer &Val) {
+ return Base::getHashValue(Val.Storage);
+ }
+ static bool isEqual(const Outer &LHS, const Outer &RHS) {
+ return Base::isEqual(LHS.Storage, RHS.Storage);
+ }
+};
+template <> struct DenseMapInfo<clang::include_cleaner::Macro> {
+ using Outer = clang::include_cleaner::Macro;
+ using Base = DenseMapInfo<decltype(Outer::Definition)>;
+
+ static inline Outer getEmptyKey() { return {nullptr, Base::getEmptyKey()}; }
+ static inline Outer getTombstoneKey() {
+ return {nullptr, Base::getTombstoneKey()};
+ }
+ static unsigned getHashValue(const Outer &Val) {
+ return Base::getHashValue(Val.Definition);
+ }
+ static bool isEqual(const Outer &LHS, const Outer &RHS) {
+ return Base::isEqual(LHS.Definition, RHS.Definition);
+ }
+};
+} // namespace llvm
+
#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138648.477723.patch
Type: text/x-patch
Size: 1941 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221124/b36dce12/attachment-0001.bin>
More information about the cfe-commits
mailing list