[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 06:15:58 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG0cb2dd5322f4: [include-cleaner] Make Symbol (and Macro) hashable. (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D138648?vs=477723&id=477768#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138648/new/

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
@@ -64,9 +64,11 @@
   struct Macro macro() const { return std::get<Macro>(Storage); }
 
 private:
-  // 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 +139,36 @@
 } // namespace include_cleaner
 } // namespace clang
 
+namespace llvm {
+
+template <> struct DenseMapInfo<clang::include_cleaner::Symbol> {
+  using Outer = clang::include_cleaner::Symbol;
+  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.477768.patch
Type: text/x-patch
Size: 1970 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221124/594c771a/attachment.bin>


More information about the cfe-commits mailing list