[Lldb-commits] [lldb] r216004 - Refactor the hardcoded formatters facility to use sequences of lambdas - still no feature change as none are present now, but this feels cleaner. Also, hardcoded formatters do not need to be per-type, so disable caching thereof

Enrico Granata egranata at apple.com
Tue Aug 19 11:47:59 PDT 2014


Author: enrico
Date: Tue Aug 19 13:47:58 2014
New Revision: 216004

URL: http://llvm.org/viewvc/llvm-project?rev=216004&view=rev
Log:
Refactor the hardcoded formatters facility to use sequences of lambdas - still no feature change as none are present now, but this feels cleaner. Also, hardcoded formatters do not need to be per-type, so disable caching thereof

Modified:
    lldb/trunk/include/lldb/DataFormatters/FormatManager.h
    lldb/trunk/source/DataFormatters/FormatManager.cpp

Modified: lldb/trunk/include/lldb/DataFormatters/FormatManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/FormatManager.h?rev=216004&r1=216003&r2=216004&view=diff
==============================================================================
--- lldb/trunk/include/lldb/DataFormatters/FormatManager.h (original)
+++ lldb/trunk/include/lldb/DataFormatters/FormatManager.h Tue Aug 19 13:47:58 2014
@@ -25,6 +25,7 @@
 #include "lldb/DataFormatters/TypeCategoryMap.h"
 
 #include <atomic>
+#include <functional>
 
 namespace lldb_private {
     
@@ -39,6 +40,14 @@ class FormatManager : public IFormatChan
     typedef TypeCategoryMap::MapType::iterator CategoryMapIterator;
 public:
     
+    template <typename FormatterType>
+    using HardcodedFormatterFinder = std::function<typename FormatterType::SharedPointer (lldb_private::ValueObject&,
+                                                                                          lldb::DynamicValueType,
+                                                                                          FormatManager&)>;
+    
+    template <typename FormatterType>
+    using HardcodedFormatterFinders = std::vector<HardcodedFormatterFinder<FormatterType>>;
+    
     typedef TypeCategoryMap::CallbackType CategoryCallback;
     
     FormatManager ();
@@ -260,6 +269,19 @@ private:
     ConstString m_vectortypes_category_name;
     ConstString m_appkit_category_name;
     
+    HardcodedFormatterFinders<TypeFormatImpl> m_hardcoded_formats;
+    HardcodedFormatterFinders<TypeSummaryImpl> m_hardcoded_summaries;
+    HardcodedFormatterFinders<SyntheticChildren> m_hardcoded_synthetics;
+    
+    lldb::TypeFormatImplSP
+    GetHardcodedFormat (ValueObject&,lldb::DynamicValueType);
+    
+    lldb::TypeSummaryImplSP
+    GetHardcodedSummaryFormat (ValueObject&,lldb::DynamicValueType);
+
+    lldb::SyntheticChildrenSP
+    GetHardcodedSyntheticChildren (ValueObject&,lldb::DynamicValueType);
+    
     TypeCategoryMap&
     GetCategories ()
     {
@@ -281,8 +303,11 @@ private:
     
     void
     LoadObjCFormatters ();
+    
+    void
+    LoadHardcodedFormatters ();
 };
     
 } // namespace lldb_private
-
+    
 #endif	// lldb_FormatManager_h_

Modified: lldb/trunk/source/DataFormatters/FormatManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/FormatManager.cpp?rev=216004&r1=216003&r2=216004&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/FormatManager.cpp (original)
+++ lldb/trunk/source/DataFormatters/FormatManager.cpp Tue Aug 19 13:47:58 2014
@@ -583,11 +583,17 @@ GetTypeForCache (ValueObject& valobj,
     return ConstString();
 }
 
-static lldb::TypeFormatImplSP
-GetHardcodedFormat (ValueObject& valobj,
-                    lldb::DynamicValueType use_dynamic)
+lldb::TypeFormatImplSP
+FormatManager::GetHardcodedFormat (ValueObject& valobj,
+                                   lldb::DynamicValueType use_dynamic)
 {
-    return lldb::TypeFormatImplSP();
+    for (const auto& candidate: m_hardcoded_formats)
+    {
+        auto result = candidate(valobj,use_dynamic,*this);
+        if (result)
+            return result;
+    }
+    return nullptr;
 }
 
 lldb::TypeFormatImplSP
@@ -621,7 +627,7 @@ FormatManager::GetFormat (ValueObject& v
             log->Printf("[FormatManager::GetFormat] Search failed. Giving hardcoded a chance.");
         retval = GetHardcodedFormat(valobj, use_dynamic);
     }
-    if (valobj_type)
+    else if (valobj_type)
     {
         if (log)
             log->Printf("[FormatManager::GetFormat] Caching %p for type %s",
@@ -634,11 +640,17 @@ FormatManager::GetFormat (ValueObject& v
     return retval;
 }
 
-static lldb::TypeSummaryImplSP
-GetHardcodedSummaryFormat (ValueObject& valobj,
-                               lldb::DynamicValueType use_dynamic)
+lldb::TypeSummaryImplSP
+FormatManager::GetHardcodedSummaryFormat (ValueObject& valobj,
+                                          lldb::DynamicValueType use_dynamic)
 {
-    return lldb::TypeSummaryImplSP();
+    for (const auto& candidate: m_hardcoded_summaries)
+    {
+        auto result = candidate(valobj,use_dynamic,*this);
+        if (result)
+            return result;
+    }
+    return nullptr;
 }
 
 lldb::TypeSummaryImplSP
@@ -672,7 +684,7 @@ FormatManager::GetSummaryFormat (ValueOb
             log->Printf("[FormatManager::GetSummaryFormat] Search failed. Giving hardcoded a chance.");
         retval = GetHardcodedSummaryFormat(valobj, use_dynamic);
     }
-    if (valobj_type)
+    else if (valobj_type)
     {
         if (log)
             log->Printf("[FormatManager::GetSummaryFormat] Caching %p for type %s",
@@ -686,11 +698,17 @@ FormatManager::GetSummaryFormat (ValueOb
 }
 
 #ifndef LLDB_DISABLE_PYTHON
-static lldb::SyntheticChildrenSP
-GetHardcodedSyntheticChildren (ValueObject& valobj,
-                               lldb::DynamicValueType use_dynamic)
+lldb::SyntheticChildrenSP
+FormatManager::GetHardcodedSyntheticChildren (ValueObject& valobj,
+                                              lldb::DynamicValueType use_dynamic)
 {
-    return lldb::SyntheticChildrenSP();
+    for (const auto& candidate: m_hardcoded_synthetics)
+    {
+        auto result = candidate(valobj,use_dynamic,*this);
+        if (result)
+            return result;
+    }
+    return nullptr;
 }
 
 lldb::SyntheticChildrenSP
@@ -724,7 +742,7 @@ FormatManager::GetSyntheticChildren (Val
             log->Printf("[FormatManager::GetSyntheticChildren] Search failed. Giving hardcoded a chance.");
         retval = GetHardcodedSyntheticChildren(valobj, use_dynamic);
     }
-    if (valobj_type)
+    else if (valobj_type)
     {
         if (log)
             log->Printf("[FormatManager::GetSyntheticChildren] Caching %p for type %s",
@@ -752,12 +770,17 @@ FormatManager::FormatManager() :
     m_coregraphics_category_name(ConstString("CoreGraphics")),
     m_coreservices_category_name(ConstString("CoreServices")),
     m_vectortypes_category_name(ConstString("VectorTypes")),
-    m_appkit_category_name(ConstString("AppKit"))
+    m_appkit_category_name(ConstString("AppKit")),
+    m_hardcoded_formats(),
+    m_hardcoded_summaries(),
+    m_hardcoded_synthetics()
+    
 {
     LoadSystemFormatters();
     LoadLibStdcppFormatters();
     LoadLibcxxFormatters();
     LoadObjCFormatters();
+    LoadHardcodedFormatters();
     
     EnableCategory(m_objc_category_name,TypeCategoryMap::Last);
     EnableCategory(m_corefoundation_category_name,TypeCategoryMap::Last);
@@ -984,6 +1007,7 @@ FormatManager::LoadLibcxxFormatters()
     AddCXXSynthetic(libcxx_category_sp, lldb_private::formatters::LibcxxSharedPtrSyntheticFrontEndCreator, "weak_ptr synthetic children", ConstString("^(std::__1::)weak_ptr<.+>(( )?&)?$"), stl_synth_flags, true);
     
     stl_summary_flags.SetDontShowChildren(false);stl_summary_flags.SetSkipPointers(false);
+    AddCXXSynthetic(libcxx_category_sp, lldb_private::formatters::LibcxxVectorBoolSyntheticFrontEndCreator, "libc++ std::vector<bool> synthetic children", ConstString("std::__1::vector<bool, std::__1::allocator<bool> >"), stl_synth_flags);
     
     AddCXXSummary(libcxx_category_sp, lldb_private::formatters::LibcxxContainerSummaryProvider, "libc++ std::vector summary provider", ConstString("^std::__1::vector<.+>(( )?&)?$"), stl_summary_flags, true);
     AddCXXSummary(libcxx_category_sp, lldb_private::formatters::LibcxxContainerSummaryProvider, "libc++ std::list summary provider", ConstString("^std::__1::list<.+>(( )?&)?$"), stl_summary_flags, true);
@@ -1003,6 +1027,7 @@ FormatManager::LoadLibcxxFormatters()
     
     AddCXXSynthetic(libcxx_category_sp, lldb_private::formatters::LibCxxVectorIteratorSyntheticFrontEndCreator, "std::vector iterator synthetic children", ConstString("^std::__1::__wrap_iter<.+>$"), stl_synth_flags, true);
     
+    AddCXXSummary(libcxx_category_sp, lldb_private::formatters::LibcxxContainerSummaryProvider, "libc++ std::vector<bool> summary provider", ConstString("std::__1::vector<bool, std::__1::allocator<bool> >"), stl_summary_flags);
     AddCXXSynthetic(libcxx_category_sp, lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEndCreator, "std::map iterator synthetic children", ConstString("^std::__1::__map_iterator<.+>$"), stl_synth_flags, true);
     
     AddFilter(libcxx_category_sp, {"__a_"}, "libc++ std::atomic filter", ConstString("^std::__1::atomic<.*>$"), stl_synth_flags, true);
@@ -1436,3 +1461,17 @@ FormatManager::LoadObjCFormatters()
                      ConstString("vBool32"),
                      vector_flags);
 }
+
+void
+FormatManager::LoadHardcodedFormatters()
+{
+    {
+        // insert code to load formats here
+    }
+    {
+        // insert code to load summaries here
+    }
+    {
+        // insert code to load synthetics here
+    }
+}





More information about the lldb-commits mailing list