[Lldb-commits] [lldb] r246612 - Move the functions that FormatManager uses to actually load formatters into their own file

Enrico Granata via lldb-commits lldb-commits at lists.llvm.org
Tue Sep 1 18:21:32 PDT 2015


Author: enrico
Date: Tue Sep  1 20:21:31 2015
New Revision: 246612

URL: http://llvm.org/viewvc/llvm-project?rev=246612&view=rev
Log:
Move the functions that FormatManager uses to actually load formatters into their own file

These are useful helpers over the low-level API of the FormattersContainer, and since we're actually going to start moving formatters into plugins, it makes sense to simplify things


Added:
    lldb/trunk/include/lldb/DataFormatters/FormattersHelpers.h
    lldb/trunk/source/DataFormatters/FormattersHelpers.cpp
Modified:
    lldb/trunk/lldb.xcodeproj/project.pbxproj
    lldb/trunk/source/DataFormatters/CMakeLists.txt
    lldb/trunk/source/DataFormatters/FormatManager.cpp

Added: lldb/trunk/include/lldb/DataFormatters/FormattersHelpers.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/FormattersHelpers.h?rev=246612&view=auto
==============================================================================
--- lldb/trunk/include/lldb/DataFormatters/FormattersHelpers.h (added)
+++ lldb/trunk/include/lldb/DataFormatters/FormattersHelpers.h Tue Sep  1 20:21:31 2015
@@ -0,0 +1,76 @@
+//===-- FormattersHelpers.h --------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef lldb_FormattersHelpers_h_
+#define lldb_FormattersHelpers_h_
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/lldb-forward.h"
+#include "lldb/lldb-enumerations.h"
+
+#include "lldb/DataFormatters/TypeCategory.h"
+#include "lldb/DataFormatters/TypeFormat.h"
+#include "lldb/DataFormatters/TypeSummary.h"
+#include "lldb/DataFormatters/TypeSynthetic.h"
+
+namespace lldb_private {
+    namespace formatters {
+        void
+        AddFormat (TypeCategoryImpl::SharedPointer category_sp,
+                   lldb::Format format,
+                   ConstString type_name,
+                   TypeFormatImpl::Flags flags,
+                   bool regex = false);
+        
+        void
+        AddStringSummary(TypeCategoryImpl::SharedPointer category_sp,
+                         const char* string,
+                         ConstString type_name,
+                         TypeSummaryImpl::Flags flags,
+                         bool regex = false);
+        
+        void
+        AddOneLineSummary (TypeCategoryImpl::SharedPointer category_sp,
+                           ConstString type_name,
+                           TypeSummaryImpl::Flags flags,
+                           bool regex = false);
+
+#ifndef LLDB_DISABLE_PYTHON
+        void
+        AddCXXSummary (TypeCategoryImpl::SharedPointer category_sp,
+                       CXXFunctionSummaryFormat::Callback funct,
+                       const char* description,
+                       ConstString type_name,
+                       TypeSummaryImpl::Flags flags,
+                       bool regex = false);
+
+        void
+        AddCXXSynthetic  (TypeCategoryImpl::SharedPointer category_sp,
+                          CXXSyntheticChildren::CreateFrontEndCallback generator,
+                          const char* description,
+                          ConstString type_name,
+                          ScriptedSyntheticChildren::Flags flags,
+                          bool regex = false);
+
+        void
+        AddFilter  (TypeCategoryImpl::SharedPointer category_sp,
+                    std::vector<std::string> children,
+                    const char* description,
+                    ConstString type_name,
+                    ScriptedSyntheticChildren::Flags flags,
+                    bool regex = false);
+#endif
+
+    } // namespace formatters
+} // namespace lldb_private
+
+#endif	// lldb_FormattersHelpers_h_

Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=246612&r1=246611&r2=246612&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Tue Sep  1 20:21:31 2015
@@ -779,6 +779,7 @@
 		94CD705216F8F5BC00CF1E42 /* LibCxxMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94CD705116F8F5BC00CF1E42 /* LibCxxMap.cpp */; };
 		94CD7D0919A3FBA300908B7C /* AppleObjCClassDescriptorV2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94CD7D0819A3FBA300908B7C /* AppleObjCClassDescriptorV2.cpp */; };
 		94CD7D0C19A3FBCE00908B7C /* AppleObjCTypeEncodingParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94CD7D0B19A3FBCE00908B7C /* AppleObjCTypeEncodingParser.cpp */; };
+		94D0858C1B9675B8000D24BD /* FormattersHelpers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94D0858B1B9675B8000D24BD /* FormattersHelpers.cpp */; settings = {ASSET_TAGS = (); }; };
 		94D0B10C16D5535900EA9C70 /* LibCxx.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94D0B10A16D5535900EA9C70 /* LibCxx.cpp */; };
 		94D0B10D16D5535900EA9C70 /* LibStdcpp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94D0B10B16D5535900EA9C70 /* LibStdcpp.cpp */; };
 		94D6A0AA16CEB55F00833B6E /* NSArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94D6A0A716CEB55F00833B6E /* NSArray.cpp */; };
@@ -2510,6 +2511,8 @@
 		94CD7D0819A3FBA300908B7C /* AppleObjCClassDescriptorV2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AppleObjCClassDescriptorV2.cpp; sourceTree = "<group>"; };
 		94CD7D0A19A3FBC300908B7C /* AppleObjCTypeEncodingParser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppleObjCTypeEncodingParser.h; sourceTree = "<group>"; };
 		94CD7D0B19A3FBCE00908B7C /* AppleObjCTypeEncodingParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = AppleObjCTypeEncodingParser.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
+		94D0858A1B9675A0000D24BD /* FormattersHelpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = FormattersHelpers.h; path = include/lldb/DataFormatters/FormattersHelpers.h; sourceTree = "<group>"; };
+		94D0858B1B9675B8000D24BD /* FormattersHelpers.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FormattersHelpers.cpp; path = source/DataFormatters/FormattersHelpers.cpp; sourceTree = "<group>"; };
 		94D0B10A16D5535900EA9C70 /* LibCxx.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LibCxx.cpp; path = source/DataFormatters/LibCxx.cpp; sourceTree = "<group>"; };
 		94D0B10B16D5535900EA9C70 /* LibStdcpp.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LibStdcpp.cpp; path = source/DataFormatters/LibStdcpp.cpp; sourceTree = "<group>"; };
 		94D6A0A716CEB55F00833B6E /* NSArray.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NSArray.cpp; path = source/DataFormatters/NSArray.cpp; sourceTree = "<group>"; };
@@ -5300,6 +5303,8 @@
 				94CB256216B069800059775D /* FormatManager.h */,
 				94CB255A16B069770059775D /* FormatManager.cpp */,
 				94EE33F218643C6900CD703B /* FormattersContainer.h */,
+				94D0858A1B9675A0000D24BD /* FormattersHelpers.h */,
+				94D0858B1B9675B8000D24BD /* FormattersHelpers.cpp */,
 				942612F51B94FFE900EF842E /* LanguageCategory.h */,
 				942612F61B95000000EF842E /* LanguageCategory.cpp */,
 				94D0B10A16D5535900EA9C70 /* LibCxx.cpp */,
@@ -6550,6 +6555,7 @@
 				26FFC19D14FC072100087D58 /* DynamicLoaderPOSIXDYLD.cpp in Sources */,
 				2694E99D14FC0BB30076DE67 /* PlatformFreeBSD.cpp in Sources */,
 				2694E9A414FC0BBD0076DE67 /* PlatformLinux.cpp in Sources */,
+				94D0858C1B9675B8000D24BD /* FormattersHelpers.cpp in Sources */,
 				945E8D80152F6AB40019BCCD /* StreamGDBRemote.cpp in Sources */,
 				945759671534941F005A9070 /* PlatformPOSIX.cpp in Sources */,
 				26B1EFAE154638AF00E2DAC7 /* DWARFDeclContext.cpp in Sources */,

Modified: lldb/trunk/source/DataFormatters/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/CMakeLists.txt?rev=246612&r1=246611&r2=246612&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/CMakeLists.txt (original)
+++ lldb/trunk/source/DataFormatters/CMakeLists.txt Tue Sep  1 20:21:31 2015
@@ -9,6 +9,7 @@ add_lldb_library(lldbDataFormatters
   FormatCache.cpp
   FormatClasses.cpp
   FormatManager.cpp
+  FormattersHelpers.cpp
   LanguageCategory.cpp
   LibCxx.cpp
   LibCxxInitializerList.cpp

Modified: lldb/trunk/source/DataFormatters/FormatManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/FormatManager.cpp?rev=246612&r1=246611&r2=246612&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/FormatManager.cpp (original)
+++ lldb/trunk/source/DataFormatters/FormatManager.cpp Tue Sep  1 20:21:31 2015
@@ -16,6 +16,7 @@
 
 #include "lldb/Core/Debugger.h"
 #include "lldb/DataFormatters/CXXFormatterFunctions.h"
+#include "lldb/DataFormatters/FormattersHelpers.h"
 #include "lldb/DataFormatters/LanguageCategory.h"
 #include "lldb/Target/ExecutionContext.h"
 #include "lldb/Target/Platform.h"
@@ -25,7 +26,7 @@
 
 using namespace lldb;
 using namespace lldb_private;
-
+using namespace lldb_private::formatters;
 
 struct FormatInfo
 {
@@ -1024,104 +1025,6 @@ FormatManager::FormatManager() :
     EnableCategory(m_system_category_name,TypeCategoryMap::Last);
 }
 
-static void
-AddFormat (TypeCategoryImpl::SharedPointer category_sp,
-           lldb::Format format,
-           ConstString type_name,
-           TypeFormatImpl::Flags flags,
-           bool regex = false)
-{
-    lldb::TypeFormatImplSP format_sp(new TypeFormatImpl_Format(format, flags));
-    
-    if (regex)
-        category_sp->GetRegexTypeFormatsContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())),format_sp);
-    else
-        category_sp->GetTypeFormatsContainer()->Add(type_name, format_sp);
-}
-
-
-static void
-AddStringSummary(TypeCategoryImpl::SharedPointer category_sp,
-                 const char* string,
-                 ConstString type_name,
-                 TypeSummaryImpl::Flags flags,
-                 bool regex = false)
-{
-    lldb::TypeSummaryImplSP summary_sp(new StringSummaryFormat(flags,
-                                                               string));
-    
-    if (regex)
-        category_sp->GetRegexTypeSummariesContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())),summary_sp);
-    else
-        category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp);
-}
-
-static void
-AddOneLineSummary (TypeCategoryImpl::SharedPointer category_sp,
-                   ConstString type_name,
-                   TypeSummaryImpl::Flags flags,
-                   bool regex = false)
-{
-    flags.SetShowMembersOneLiner(true);
-    lldb::TypeSummaryImplSP summary_sp(new StringSummaryFormat(flags, ""));
-    
-    if (regex)
-        category_sp->GetRegexTypeSummariesContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())),summary_sp);
-    else
-        category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp);
-}
-
-#ifndef LLDB_DISABLE_PYTHON
-static void
-AddCXXSummary (TypeCategoryImpl::SharedPointer category_sp,
-               CXXFunctionSummaryFormat::Callback funct,
-               const char* description,
-               ConstString type_name,
-               TypeSummaryImpl::Flags flags,
-               bool regex = false)
-{
-    lldb::TypeSummaryImplSP summary_sp(new CXXFunctionSummaryFormat(flags,funct,description));
-    if (regex)
-        category_sp->GetRegexTypeSummariesContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())),summary_sp);
-    else
-        category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp);
-}
-#endif
-
-#ifndef LLDB_DISABLE_PYTHON
-static void AddCXXSynthetic  (TypeCategoryImpl::SharedPointer category_sp,
-                              CXXSyntheticChildren::CreateFrontEndCallback generator,
-                              const char* description,
-                              ConstString type_name,
-                              ScriptedSyntheticChildren::Flags flags,
-                              bool regex = false)
-{
-    lldb::SyntheticChildrenSP synth_sp(new CXXSyntheticChildren(flags,description,generator));
-    if (regex)
-        category_sp->GetRegexTypeSyntheticsContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())), synth_sp);
-    else
-        category_sp->GetTypeSyntheticsContainer()->Add(type_name,synth_sp);
-}
-#endif
-
-#ifndef LLDB_DISABLE_PYTHON
-static void AddFilter  (TypeCategoryImpl::SharedPointer category_sp,
-                        std::vector<std::string> children,
-                        const char* description,
-                        ConstString type_name,
-                        ScriptedSyntheticChildren::Flags flags,
-                        bool regex = false)
-{
-    TypeFilterImplSP filter_sp(new TypeFilterImpl(flags));
-    for (auto child : children)
-        filter_sp->AddExpressionPath(child);
-    if (regex)
-        category_sp->GetRegexTypeFiltersContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())), filter_sp);
-    else
-        category_sp->GetTypeFiltersContainer()->Add(type_name,filter_sp);
-}
-#endif
-
 void
 FormatManager::LoadLibStdcppFormatters()
 {

Added: lldb/trunk/source/DataFormatters/FormattersHelpers.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/FormattersHelpers.cpp?rev=246612&view=auto
==============================================================================
--- lldb/trunk/source/DataFormatters/FormattersHelpers.cpp (added)
+++ lldb/trunk/source/DataFormatters/FormattersHelpers.cpp Tue Sep  1 20:21:31 2015
@@ -0,0 +1,120 @@
+//===-- FormattersHelpers.cpp -------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// C Includes
+
+// C++ Includes
+
+// Other libraries and framework includes
+
+// Project includes
+#include "lldb/DataFormatters/FormattersHelpers.h"
+
+#include "lldb/Core/ConstString.h"
+#include "lldb/Core/RegularExpression.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::formatters;
+
+void
+lldb_private::formatters::AddFormat (TypeCategoryImpl::SharedPointer category_sp,
+                                     lldb::Format format,
+                                     ConstString type_name,
+                                     TypeFormatImpl::Flags flags,
+                                     bool regex)
+{
+    lldb::TypeFormatImplSP format_sp(new TypeFormatImpl_Format(format, flags));
+    
+    if (regex)
+        category_sp->GetRegexTypeFormatsContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())),format_sp);
+    else
+        category_sp->GetTypeFormatsContainer()->Add(type_name, format_sp);
+}
+
+
+void
+lldb_private::formatters::AddStringSummary(TypeCategoryImpl::SharedPointer category_sp,
+                                           const char* string,
+                                           ConstString type_name,
+                                           TypeSummaryImpl::Flags flags,
+                                           bool regex)
+{
+    lldb::TypeSummaryImplSP summary_sp(new StringSummaryFormat(flags,
+                                                               string));
+    
+    if (regex)
+        category_sp->GetRegexTypeSummariesContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())),summary_sp);
+    else
+        category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp);
+}
+
+void
+lldb_private::formatters::AddOneLineSummary (TypeCategoryImpl::SharedPointer category_sp,
+                                             ConstString type_name,
+                                             TypeSummaryImpl::Flags flags,
+                                             bool regex)
+{
+    flags.SetShowMembersOneLiner(true);
+    lldb::TypeSummaryImplSP summary_sp(new StringSummaryFormat(flags, ""));
+    
+    if (regex)
+        category_sp->GetRegexTypeSummariesContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())),summary_sp);
+    else
+        category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp);
+}
+
+#ifndef LLDB_DISABLE_PYTHON
+void
+lldb_private::formatters::AddCXXSummary (TypeCategoryImpl::SharedPointer category_sp,
+                                         CXXFunctionSummaryFormat::Callback funct,
+                                         const char* description,
+                                         ConstString type_name,
+                                         TypeSummaryImpl::Flags flags,
+                                         bool regex)
+{
+    lldb::TypeSummaryImplSP summary_sp(new CXXFunctionSummaryFormat(flags,funct,description));
+    if (regex)
+        category_sp->GetRegexTypeSummariesContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())),summary_sp);
+    else
+        category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp);
+}
+
+void
+lldb_private::formatters::AddCXXSynthetic  (TypeCategoryImpl::SharedPointer category_sp,
+                                            CXXSyntheticChildren::CreateFrontEndCallback generator,
+                                            const char* description,
+                                            ConstString type_name,
+                                            ScriptedSyntheticChildren::Flags flags,
+                                            bool regex)
+{
+    lldb::SyntheticChildrenSP synth_sp(new CXXSyntheticChildren(flags,description,generator));
+    if (regex)
+        category_sp->GetRegexTypeSyntheticsContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())), synth_sp);
+    else
+        category_sp->GetTypeSyntheticsContainer()->Add(type_name,synth_sp);
+}
+
+void
+lldb_private::formatters::AddFilter  (TypeCategoryImpl::SharedPointer category_sp,
+                                      std::vector<std::string> children,
+                                      const char* description,
+                                      ConstString type_name,
+                                      ScriptedSyntheticChildren::Flags flags,
+                                      bool regex)
+{
+    TypeFilterImplSP filter_sp(new TypeFilterImpl(flags));
+    for (auto child : children)
+        filter_sp->AddExpressionPath(child);
+    if (regex)
+        category_sp->GetRegexTypeFiltersContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())), filter_sp);
+    else
+        category_sp->GetTypeFiltersContainer()->Add(type_name,filter_sp);
+}
+#endif




More information about the lldb-commits mailing list