[Lldb-commits] [lldb] r138254 - in /lldb/trunk: include/lldb/Core/FormatManager.h source/Commands/CommandObjectType.cpp source/Core/FormatManager.cpp

Enrico Granata granata.enrico at gmail.com
Mon Aug 22 11:36:52 PDT 2011


Author: enrico
Date: Mon Aug 22 13:36:52 2011
New Revision: 138254

URL: http://llvm.org/viewvc/llvm-project?rev=138254&view=rev
Log:
Code cleanup and refactoring (round 4):
 - FormatCategories now are directly mapped by ConstString objects instead of going through
   const char* -> ConstString -> const char*
 - FormatCategory callback does not pass category name anymore. This is not necessary because
   FormatCategory objects themselves hold their name as a member variable

Modified:
    lldb/trunk/include/lldb/Core/FormatManager.h
    lldb/trunk/source/Commands/CommandObjectType.cpp
    lldb/trunk/source/Core/FormatManager.cpp

Modified: lldb/trunk/include/lldb/Core/FormatManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FormatManager.h?rev=138254&r1=138253&r2=138254&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/FormatManager.h (original)
+++ lldb/trunk/include/lldb/Core/FormatManager.h Mon Aug 22 13:36:52 2011
@@ -934,7 +934,7 @@
 class CategoryMap
 {
 private:
-    typedef const char* KeyType;
+    typedef ConstString KeyType;
     typedef FormatCategory ValueType;
     typedef ValueType::SharedPointer ValueSP;
     typedef std::list<lldb::FormatCategorySP> ActiveCategoriesList;
@@ -943,7 +943,7 @@
 public:
     typedef std::map<KeyType, ValueSP> MapType;
     typedef MapType::iterator MapIterator;
-    typedef bool(*CallbackType)(void*, KeyType, const ValueSP&);
+    typedef bool(*CallbackType)(void*, const ValueSP&);
     
     CategoryMap(IFormatChangeListener* lst = NULL) :
     m_map_mutex(Mutex::eMutexTypeRecursive),
@@ -1149,7 +1149,7 @@
 
 public:
     
-    typedef bool (*CategoryCallback)(void*, const char*, const lldb::FormatCategorySP&);
+    typedef CategoryMap::CallbackType CategoryCallback;
     
     FormatManager ();
     
@@ -1172,18 +1172,30 @@
     }
     
     void
-    EnableCategory (const char* category_name)
+    EnableCategory (const ConstString& category_name)
     {
         m_categories_map.EnableCategory(category_name);
     }
     
     void
-    DisableCategory (const char* category_name)
+    DisableCategory (const ConstString& category_name)
     {
         m_categories_map.DisableCategory(category_name);
     }
     
     void
+    EnableCategory (const char* category_name)
+    {
+        EnableCategory(ConstString(category_name));
+    }
+    
+    void
+    DisableCategory (const char* category_name)
+    {
+        DisableCategory(ConstString(category_name));
+    }
+    
+    void
     LoopThroughCategories (CategoryCallback callback, void* param)
     {
         m_categories_map.LoopThrough(callback, param);
@@ -1206,10 +1218,18 @@
     {
         if (!category_name)
             return Category(m_default_category_name);
+        return Category(ConstString(category_name));
+    }
+    
+    lldb::FormatCategorySP
+    Category (const ConstString& category_name)
+    {
+        if (!category_name)
+            return Category(m_default_category_name);
         lldb::FormatCategorySP category;
         if (m_categories_map.Get(category_name, category))
             return category;
-        Categories().Add(category_name,lldb::FormatCategorySP(new FormatCategory(this, category_name)));
+        Categories().Add(category_name,lldb::FormatCategorySP(new FormatCategory(this, category_name.AsCString())));
         return Category(category_name);
     }
     
@@ -1287,13 +1307,9 @@
     uint32_t m_last_revision;
     CategoryMap m_categories_map;
     
-    const char* m_default_category_name;
-    const char* m_system_category_name;
-    const char* m_gnu_cpp_category_name;
-    
-    ConstString m_default_cs;
-    ConstString m_system_cs;
-    ConstString m_gnu_stdcpp_cs;
+    ConstString m_default_category_name;
+    ConstString m_system_category_name;
+    ConstString m_gnu_cpp_category_name;
 };
 
 class DataVisualization

Modified: lldb/trunk/source/Commands/CommandObjectType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=138254&r1=138253&r2=138254&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectType.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectType.cpp Mon Aug 22 13:36:52 2011
@@ -1166,7 +1166,6 @@
     
     static bool
     PerCategoryCallback(void* param,
-                        const char* cate_name,
                         const lldb::FormatCategorySP& cate)
     {
         ConstString *name = (ConstString*)param;
@@ -1322,7 +1321,6 @@
     
     static bool
     PerCategoryCallback(void* param,
-                        const char* cate_name,
                         const lldb::FormatCategorySP& cate)
     {
         cate->GetSummaryNavigator()->Clear();
@@ -1532,7 +1530,6 @@
     
     static bool
     PerCategoryCallback(void* param_vp,
-                        const char* cate_name,
                         const lldb::FormatCategorySP& cate)
     {
         
@@ -1540,6 +1537,8 @@
             (CommandObjectTypeSummaryList_LoopCallbackParam*)param_vp;
         CommandReturnObject* result = param->result;
         
+        const char* cate_name = cate->GetName().c_str();
+        
         // if the category is disabled or empty and there is no regex, just skip it
         if ((cate->IsEnabled() == false || cate->GetCount(FormatCategory::eSummary | FormatCategory::eRegexSummary) == 0) && param->cate_regex == NULL)
             return true;
@@ -1615,7 +1614,7 @@
     CommandObjectTypeCategoryEnable (CommandInterpreter &interpreter) :
     CommandObject (interpreter,
                    "type category enable",
-                   "Enable a category as a source of summaries.",
+                   "Enable a category as a source of formatters.",
                    NULL)
     {
         CommandArgumentEntry type_arg;
@@ -1658,6 +1657,14 @@
                 return false;
             }
             DataVisualization::Categories::Enable(typeCS);
+            lldb::FormatCategorySP cate;
+            if (DataVisualization::Categories::Get(typeCS, cate) && cate.get())
+            {
+                if (cate->GetCount() == 0)
+                {
+                    result.AppendWarning("empty category enabled (typo?)");
+                }
+            }
         }
         
         result.SetStatus(eReturnStatusSuccessFinishResult);
@@ -1676,7 +1683,7 @@
     CommandObjectTypeCategoryDelete (CommandInterpreter &interpreter) :
     CommandObject (interpreter,
                    "type category delete",
-                   "Delete a category and all associated summaries.",
+                   "Delete a category and all associated formatters.",
                    NULL)
     {
         CommandArgumentEntry type_arg;
@@ -1748,7 +1755,7 @@
     CommandObjectTypeCategoryDisable (CommandInterpreter &interpreter) :
     CommandObject (interpreter,
                    "type category disable",
-                   "Disable a category as a source of summaries.",
+                   "Disable a category as a source of formatters.",
                    NULL)
     {
         CommandArgumentEntry type_arg;
@@ -1824,7 +1831,6 @@
     
     static bool
     PerCategoryCallback(void* param_vp,
-                        const char* cate_name,
                         const lldb::FormatCategorySP& cate)
     {
         CommandObjectTypeCategoryList_CallbackParam* param =
@@ -1832,6 +1838,8 @@
         CommandReturnObject* result = param->result;
         RegularExpression* regex = param->regex;
         
+        const char* cate_name = cate->GetName().c_str();
+        
         if (regex == NULL || regex->Execute(cate_name))
             result->GetOutputStream().Printf("Category %s is%s enabled\n",
                                        cate_name,
@@ -2028,10 +2036,11 @@
     
     static bool
     PerCategoryCallback(void* param_vp,
-                        const char* cate_name,
                         const lldb::FormatCategorySP& cate)
     {
         
+        const char* cate_name = cate->GetName().c_str();
+        
         CommandObjectTypeFilterList_LoopCallbackParam* param = 
         (CommandObjectTypeFilterList_LoopCallbackParam*)param_vp;
         CommandReturnObject* result = param->result;
@@ -2237,7 +2246,6 @@
     
     static bool
     PerCategoryCallback(void* param_vp,
-                        const char* cate_name,
                         const lldb::FormatCategorySP& cate)
     {
         
@@ -2245,6 +2253,8 @@
         (CommandObjectTypeSynthList_LoopCallbackParam*)param_vp;
         CommandReturnObject* result = param->result;
         
+        const char* cate_name = cate->GetName().c_str();
+        
         // if the category is disabled or empty and there is no regex, just skip it
         if ((cate->IsEnabled() == false || cate->GetCount(FormatCategory::eSynth | FormatCategory::eRegexSynth) == 0) && param->cate_regex == NULL)
             return true;
@@ -2384,7 +2394,6 @@
     
     static bool
     PerCategoryCallback(void* param,
-                        const char* cate_name,
                         const lldb::FormatCategorySP& cate)
     {
         ConstString *name = (ConstString*)param;
@@ -2547,7 +2556,6 @@
     
     static bool
     PerCategoryCallback(void* param,
-                        const char* cate_name,
                         const lldb::FormatCategorySP& cate)
     {
         ConstString* name = (ConstString*)param;
@@ -2706,7 +2714,6 @@
     
     static bool
     PerCategoryCallback(void* param,
-                        const char* cate_name,
                         const lldb::FormatCategorySP& cate)
     {
         cate->Clear(FormatCategory::eFilter | FormatCategory::eRegexFilter);
@@ -2833,7 +2840,6 @@
     
     static bool
     PerCategoryCallback(void* param,
-                        const char* cate_name,
                         const lldb::FormatCategorySP& cate)
     {
         cate->Clear(FormatCategory::eSynth | FormatCategory::eRegexSynth);

Modified: lldb/trunk/source/Core/FormatManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FormatManager.cpp?rev=138254&r1=138253&r2=138254&view=diff
==============================================================================
--- lldb/trunk/source/Core/FormatManager.cpp (original)
+++ lldb/trunk/source/Core/FormatManager.cpp Mon Aug 22 13:36:52 2011
@@ -321,8 +321,8 @@
             for (begin = m_active_categories.begin(); begin != end; begin++)
             {
                 lldb::FormatCategorySP category = *begin;
-                const char* type = category->GetName().c_str();
-                if (!callback(param, type, category))
+                ConstString type = ConstString(category->GetName().c_str());
+                if (!callback(param, category))
                     break;
             }
         }
@@ -335,7 +335,7 @@
                 if (pos->second->IsEnabled())
                     continue;
                 KeyType type = pos->first;
-                if (!callback(param, type, pos->second))
+                if (!callback(param, pos->second))
                     break;
             }
         }
@@ -383,17 +383,11 @@
     m_named_summaries_map(this),
     m_last_revision(0),
     m_categories_map(this),
-    m_default_cs(ConstString("default")),
-    m_system_cs(ConstString("system")), 
-    m_gnu_stdcpp_cs(ConstString("gnu-libstdc++"))
+    m_default_category_name(ConstString("default")),
+    m_system_category_name(ConstString("system")), 
+    m_gnu_cpp_category_name(ConstString("gnu-libstdc++"))
 {
     
-    // build default categories
-    
-    m_default_category_name = m_default_cs.GetCString();
-    m_system_category_name = m_system_cs.GetCString();
-    m_gnu_cpp_category_name = m_gnu_stdcpp_cs.AsCString();
-    
     // add some default stuff
     // most formats, summaries, ... actually belong to the users' lldbinit file rather than here
     lldb::SummaryFormatSP string_format(new StringSummaryFormat(false,
@@ -553,21 +547,21 @@
 bool
 DataVisualization::Categories::Get(const ConstString &category, lldb::FormatCategorySP &entry)
 {
-    entry = GetFormatManager().Category(category.GetCString());
+    entry = GetFormatManager().Category(category);
     return true;
 }
 
 void
 DataVisualization::Categories::Add(const ConstString &category)
 {
-    GetFormatManager().Category(category.GetCString());
+    GetFormatManager().Category(category);
 }
 
 bool
 DataVisualization::Categories::Delete(const ConstString &category)
 {
-    GetFormatManager().DisableCategory(category.GetCString());
-    return GetFormatManager().Categories().Delete(category.GetCString());
+    GetFormatManager().DisableCategory(category);
+    return GetFormatManager().Categories().Delete(category);
 }
 
 void
@@ -579,26 +573,26 @@
 void
 DataVisualization::Categories::Clear(ConstString &category)
 {
-    GetFormatManager().Category(category.GetCString())->ClearSummaries();
+    GetFormatManager().Category(category)->ClearSummaries();
 }
 
 void
 DataVisualization::Categories::Enable(ConstString& category)
 {
-    if (GetFormatManager().Category(category.GetCString())->IsEnabled() == false)
-        GetFormatManager().EnableCategory(category.GetCString());
+    if (GetFormatManager().Category(category)->IsEnabled() == false)
+        GetFormatManager().EnableCategory(category);
     else
     {
-        GetFormatManager().DisableCategory(category.GetCString());
-        GetFormatManager().EnableCategory(category.GetCString());
+        GetFormatManager().DisableCategory(category);
+        GetFormatManager().EnableCategory(category);
     }
 }
 
 void
 DataVisualization::Categories::Disable(ConstString& category)
 {
-    if (GetFormatManager().Category(category.GetCString())->IsEnabled() == true)
-        GetFormatManager().DisableCategory(category.GetCString());
+    if (GetFormatManager().Category(category)->IsEnabled() == true)
+        GetFormatManager().DisableCategory(category);
 }
 
 void





More information about the lldb-commits mailing list