[Lldb-commits] [lldb] [lldb] Simplify DumpValueObjectOptions::PointerDepth (NFC) (PR #117504)

Dave Lee via lldb-commits lldb-commits at lists.llvm.org
Sun Nov 24 11:07:55 PST 2024


https://github.com/kastiglione created https://github.com/llvm/llvm-project/pull/117504

`Mode::Always` and `Mode::Default` are handled identically. `Mode::Never` is the same as
having a count of 0.


>From 92e1118f6f62aae0c98485fecc8598a95dc44ab7 Mon Sep 17 00:00:00 2001
From: Dave Lee <davelee.com at gmail.com>
Date: Sun, 24 Nov 2024 11:01:06 -0800
Subject: [PATCH] [lldb] Simplify DumpValueObjectOptions::PointerDepth (NFC)

`Mode::Always` and `Mode::Default` are handled identically. `Mode::Never` is the same as
having a count of 0.
---
 .../lldb/DataFormatters/DumpValueObjectOptions.h       | 10 ++++------
 lldb/source/DataFormatters/DumpValueObjectOptions.cpp  | 10 ++++------
 lldb/source/DataFormatters/ValueObjectPrinter.cpp      |  9 +--------
 .../Interpreter/OptionGroupValueObjectDisplay.cpp      |  3 +--
 4 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h b/lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h
index c7f8cccc116c48..ce15963ab5662c 100644
--- a/lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h
+++ b/lldb/include/lldb/DataFormatters/DumpValueObjectOptions.h
@@ -22,13 +22,12 @@ namespace lldb_private {
 class DumpValueObjectOptions {
 public:
   struct PointerDepth {
-    enum class Mode { Always, Default, Never } m_mode;
-    uint32_t m_count;
+    uint32_t m_count = 0;
 
     PointerDepth Decremented() const {
       if (m_count > 0)
-        return PointerDepth{m_mode, m_count - 1};
-      return PointerDepth{m_mode, m_count};
+        return {m_count - 1};
+      return *this;
     }
 
     bool CanAllowExpansion() const;
@@ -65,8 +64,7 @@ class DumpValueObjectOptions {
 
   DumpValueObjectOptions(ValueObject &valobj);
 
-  DumpValueObjectOptions &
-  SetMaximumPointerDepth(PointerDepth depth = {PointerDepth::Mode::Never, 0});
+  DumpValueObjectOptions &SetMaximumPointerDepth(uint32_t depth);
 
   DumpValueObjectOptions &SetMaximumDepth(uint32_t depth, bool is_default);
 
diff --git a/lldb/source/DataFormatters/DumpValueObjectOptions.cpp b/lldb/source/DataFormatters/DumpValueObjectOptions.cpp
index 18d590d47d9a0c..b952fb643f13ef 100644
--- a/lldb/source/DataFormatters/DumpValueObjectOptions.cpp
+++ b/lldb/source/DataFormatters/DumpValueObjectOptions.cpp
@@ -14,10 +14,8 @@ using namespace lldb;
 using namespace lldb_private;
 
 DumpValueObjectOptions::DumpValueObjectOptions()
-    : m_summary_sp(), m_root_valobj_name(),
-      m_max_ptr_depth(PointerDepth{PointerDepth::Mode::Default, 0}),
-      m_decl_printing_helper(), m_child_printing_decider(),
-      m_pointer_as_array(), m_use_synthetic(true),
+    : m_summary_sp(), m_root_valobj_name(), m_decl_printing_helper(),
+      m_child_printing_decider(), m_pointer_as_array(), m_use_synthetic(true),
       m_scope_already_checked(false), m_flat_output(false), m_ignore_cap(false),
       m_show_types(false), m_show_location(false), m_use_objc(false),
       m_hide_root_type(false), m_hide_root_name(false), m_hide_name(false),
@@ -33,8 +31,8 @@ DumpValueObjectOptions::DumpValueObjectOptions(ValueObject &valobj)
 }
 
 DumpValueObjectOptions &
-DumpValueObjectOptions::SetMaximumPointerDepth(PointerDepth depth) {
-  m_max_ptr_depth = depth;
+DumpValueObjectOptions::SetMaximumPointerDepth(uint32_t depth) {
+  m_max_ptr_depth = {depth};
   return *this;
 }
 
diff --git a/lldb/source/DataFormatters/ValueObjectPrinter.cpp b/lldb/source/DataFormatters/ValueObjectPrinter.cpp
index face38253efab8..01e604e019f25f 100644
--- a/lldb/source/DataFormatters/ValueObjectPrinter.cpp
+++ b/lldb/source/DataFormatters/ValueObjectPrinter.cpp
@@ -503,14 +503,7 @@ ValueObjectPrinter::PrintObjectDescriptionIfNeeded(bool value_printed,
 }
 
 bool DumpValueObjectOptions::PointerDepth::CanAllowExpansion() const {
-  switch (m_mode) {
-  case Mode::Always:
-  case Mode::Default:
-    return m_count > 0;
-  case Mode::Never:
-    return false;
-  }
-  return false;
+  return m_count > 0;
 }
 
 bool ValueObjectPrinter::ShouldPrintChildren(
diff --git a/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp b/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp
index 0e8c1f4b5f1d9a..d633c469e603ec 100644
--- a/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp
+++ b/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp
@@ -190,8 +190,7 @@ DumpValueObjectOptions OptionGroupValueObjectDisplay::GetAsDumpOptions(
     LanguageRuntimeDescriptionDisplayVerbosity lang_descr_verbosity,
     lldb::Format format, lldb::TypeSummaryImplSP summary_sp) {
   DumpValueObjectOptions options;
-  options.SetMaximumPointerDepth(
-      {DumpValueObjectOptions::PointerDepth::Mode::Always, ptr_depth});
+  options.SetMaximumPointerDepth(ptr_depth);
   if (use_objc)
     options.SetShowSummary(false);
   else



More information about the lldb-commits mailing list