[Lldb-commits] [lldb] 58e34ed - [lldb] Small improvements in ValueObjectPrinter::PrintDecl (NFC)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Fri Jun 12 21:05:12 PDT 2020


Author: Jonas Devlieghere
Date: 2020-06-12T21:05:05-07:00
New Revision: 58e34ede5bf741cfc47b3ebd573ae7dfdf9e9c02

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

LOG: [lldb] Small improvements in ValueObjectPrinter::PrintDecl (NFC)

Remove unused argument, simply code and reformat.

Added: 
    

Modified: 
    lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
    lldb/source/DataFormatters/ValueObjectPrinter.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h b/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
index dda91e4178e6..f1301d8595b1 100644
--- a/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
+++ b/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
@@ -57,7 +57,7 @@ class ValueObjectPrinter {
 
   const char *GetDescriptionForDisplay();
 
-  const char *GetRootNameForDisplay(const char *if_fail = nullptr);
+  const char *GetRootNameForDisplay();
 
   bool ShouldPrintValueObject();
 

diff  --git a/lldb/source/DataFormatters/ValueObjectPrinter.cpp b/lldb/source/DataFormatters/ValueObjectPrinter.cpp
index 350d6cde5191..c8a306334cf5 100644
--- a/lldb/source/DataFormatters/ValueObjectPrinter.cpp
+++ b/lldb/source/DataFormatters/ValueObjectPrinter.cpp
@@ -151,11 +151,11 @@ const char *ValueObjectPrinter::GetDescriptionForDisplay() {
   return str;
 }
 
-const char *ValueObjectPrinter::GetRootNameForDisplay(const char *if_fail) {
+const char *ValueObjectPrinter::GetRootNameForDisplay() {
   const char *root_valobj_name = m_options.m_root_valobj_name.empty()
                                      ? m_valobj->GetName().AsCString()
                                      : m_options.m_root_valobj_name.c_str();
-  return root_valobj_name ? root_valobj_name : if_fail;
+  return root_valobj_name ? root_valobj_name : "";
 }
 
 bool ValueObjectPrinter::ShouldPrintValueObject() {
@@ -239,17 +239,14 @@ void ValueObjectPrinter::PrintDecl() {
     // type if there is one to print
     ConstString type_name;
     if (m_compiler_type.IsValid()) {
-      if (m_options.m_use_type_display_name)
-        type_name = m_valobj->GetDisplayTypeName();
-      else
-        type_name = m_valobj->GetQualifiedTypeName();
+      type_name = m_options.m_use_type_display_name
+                      ? m_valobj->GetDisplayTypeName()
+                      : m_valobj->GetQualifiedTypeName();
     } else {
       // only show an invalid type name if the user explicitly triggered
       // show_type
       if (m_options.m_show_types)
         type_name = ConstString("<invalid type>");
-      else
-        type_name.Clear();
     }
 
     if (type_name) {
@@ -260,7 +257,7 @@ void ValueObjectPrinter::PrintDecl() {
           type_name_str.erase(iter, 2);
         }
       }
-      typeName.Printf("%s", type_name_str.c_str());
+      typeName << type_name_str.c_str();
     }
   }
 
@@ -269,10 +266,8 @@ void ValueObjectPrinter::PrintDecl() {
   if (!m_options.m_hide_name) {
     if (m_options.m_flat_output)
       m_valobj->GetExpressionPath(varName);
-    else {
-      const char *name_cstr = GetRootNameForDisplay("");
-      varName.Printf("%s", name_cstr);
-    }
+    else
+      varName << GetRootNameForDisplay();
   }
 
   bool decl_printed = false;
@@ -448,9 +443,9 @@ bool ValueObjectPrinter::PrintObjectDescriptionIfNeeded(bool value_printed,
         // If the description already ends with a \n don't add another one.
         size_t object_end = strlen(object_desc) - 1;
         if (object_desc[object_end] == '\n')
-            m_stream->Printf("%s", object_desc);
+          m_stream->Printf("%s", object_desc);
         else
-            m_stream->Printf("%s\n", object_desc);
+          m_stream->Printf("%s\n", object_desc);
         return true;
       } else if (!value_printed && !summary_printed)
         return true;


        


More information about the lldb-commits mailing list