[Lldb-commits] [lldb] f0a61c2 - Remove `friend` classes from TypeCategoryMap

Jorge Gorbe Moya via lldb-commits lldb-commits at lists.llvm.org
Mon May 23 11:32:41 PDT 2022


Author: Jorge Gorbe Moya
Date: 2022-05-23T11:31:53-07:00
New Revision: f0a61c2ce2afec200967c59d45181c7a9fbe2c3f

URL: https://github.com/llvm/llvm-project/commit/f0a61c2ce2afec200967c59d45181c7a9fbe2c3f
DIFF: https://github.com/llvm/llvm-project/commit/f0a61c2ce2afec200967c59d45181c7a9fbe2c3f.diff

LOG: Remove `friend` classes from TypeCategoryMap

As far as I can tell, the only thing those friend classes access is the
`ValueSP` typedef.

Given that this is a map-ish class, with "Map" in its name, it doesn't
seem like a stretch to make `KeyType`, `ValueType` and `ValueSP` public.
More so when the public methods of the class have `KeyType` and
`ValueSP` arguments and clearly `ValueSP` needs to be accessed from the
outside.

`friend` complicates local reasoning about who can access private
members, which is valuable in a class like this that has every method
locking a mutex to prevent concurrent access.

Differential Revision: https://reviews.llvm.org/D126103

Added: 
    

Modified: 
    lldb/include/lldb/DataFormatters/TypeCategoryMap.h

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/DataFormatters/TypeCategoryMap.h b/lldb/include/lldb/DataFormatters/TypeCategoryMap.h
index 4dbca29db066d..45dbb306aa758 100644
--- a/lldb/include/lldb/DataFormatters/TypeCategoryMap.h
+++ b/lldb/include/lldb/DataFormatters/TypeCategoryMap.h
@@ -23,13 +23,13 @@
 namespace lldb_private {
 class TypeCategoryMap {
 private:
-  typedef ConstString KeyType;
-  typedef TypeCategoryImpl ValueType;
-  typedef ValueType::SharedPointer ValueSP;
   typedef std::list<lldb::TypeCategoryImplSP> ActiveCategoriesList;
   typedef ActiveCategoriesList::iterator ActiveCategoriesIterator;
 
 public:
+  typedef ConstString KeyType;
+  typedef TypeCategoryImpl ValueType;
+  typedef ValueType::SharedPointer ValueSP;
   typedef std::map<KeyType, ValueSP> MapType;
   typedef MapType::iterator MapIterator;
   typedef std::function<bool(const ValueSP &)> ForEachCallback;
@@ -103,9 +103,6 @@ class TypeCategoryMap {
   ActiveCategoriesList &active_list() { return m_active_categories; }
 
   std::recursive_mutex &mutex() { return m_map_mutex; }
-
-  friend class FormattersContainer<ValueType>;
-  friend class FormatManager;
 };
 } // namespace lldb_private
 


        


More information about the lldb-commits mailing list