Skip to content

[lldb][DataFormatter][NFC] Use GetFirstValueOfLibCXXCompressedPair throughout formatters #80133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

Michael137
Copy link
Member

@Michael137 Michael137 commented Jan 31, 2024

This avoids duplicating the logic to get the first
element of a libc++ __compressed_pair. This will
be useful in supporting upcoming changes to the layout
of __compressed_pair.

Drive-by changes:

  • Renamed m_item to size_node for readability;
    m_item suggests it's a member variable, which it
    is not.

@llvmbot
Copy link
Member

llvmbot commented Jan 31, 2024

@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)

Changes

This avoids duplicating the logic to get the first element of a libc++ __compressed_pair. This will be useful in upcoming refactorings of this formatter.

Drive-by changes:

  • Renamed m_item to size_node for readability; m_item suggests it's a member variable, which it is not.

Full diff: https://github.com/llvm/llvm-project/pull/80133.diff

1 Files Affected:

  • (modified) lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp (+8-18)
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
index 092a4120376b7..d3ee63a35e107 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
@@ -213,30 +213,20 @@ size_t lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::
     CalculateNumChildren() {
   if (m_count != UINT32_MAX)
     return m_count;
+
   if (m_tree == nullptr)
     return 0;
-  ValueObjectSP m_item(m_tree->GetChildMemberWithName("__pair3_"));
-  if (!m_item)
+
+  ValueObjectSP size_node(m_tree->GetChildMemberWithName("__pair3_"));
+  if (!size_node)
     return 0;
 
-  switch (m_item->GetCompilerType().GetNumDirectBaseClasses()) {
-  case 1:
-    // Assume a pre llvm r300140 __compressed_pair implementation:
-    m_item = m_item->GetChildMemberWithName("__first_");
-    break;
-  case 2: {
-    // Assume a post llvm r300140 __compressed_pair implementation:
-    ValueObjectSP first_elem_parent = m_item->GetChildAtIndex(0);
-    m_item = first_elem_parent->GetChildMemberWithName("__value_");
-    break;
-  }
-  default:
-    return false;
-  }
+  size_node = GetFirstValueOfLibCXXCompressedPair(*size_node);
 
-  if (!m_item)
+  if (!size_node)
     return 0;
-  m_count = m_item->GetValueAsUnsigned(0);
+
+  m_count = size_node->GetValueAsUnsigned(0);
   return m_count;
 }
 

…roughout formatters

This avoids duplicating the logic to get the first
element of a libc++ `__compressed_pair`. This will
be useful in supporting upcoming changes to the layout
of `__compressed_pair`.

Drive-by changes:
* Renamed `m_item` to `size_node` for readability;
  `m_item` suggests it's a member variable, which it
  is not.
@Michael137 Michael137 force-pushed the lldb/nfc/map-formatter-compressed-pair-helper branch from 4380ded to da7c51b Compare January 31, 2024 13:57
@Michael137 Michael137 changed the title [lldb][DataFormatter][NFC] Use GetFirstValueOfLibCXXCompressedPair in std::map formatter [lldb][DataFormatter][NFC] Use GetFirstValueOfLibCXXCompressedPair throughout formatters Jan 31, 2024
Copy link

github-actions bot commented Jan 31, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@felipepiovezan felipepiovezan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice removal of duplicated code!

@Michael137 Michael137 merged commit 08c0eb1 into llvm:main Jan 31, 2024
@Michael137 Michael137 deleted the lldb/nfc/map-formatter-compressed-pair-helper branch January 31, 2024 17:18
Michael137 added a commit to Michael137/llvm-project that referenced this pull request Feb 16, 2024
…roughout formatters (llvm#80133)

This avoids duplicating the logic to get the first
element of a libc++ `__compressed_pair`. This will
be useful in supporting upcoming changes to the layout
of `__compressed_pair`.

Drive-by changes:
* Renamed `m_item` to `size_node` for readability;
  `m_item` suggests it's a member variable, which it
  is not.

(cherry picked from commit 08c0eb1)
Michael137 added a commit to Michael137/llvm-project that referenced this pull request Feb 16, 2024
…roughout formatters (llvm#80133)

This avoids duplicating the logic to get the first
element of a libc++ `__compressed_pair`. This will
be useful in supporting upcoming changes to the layout
of `__compressed_pair`.

Drive-by changes:
* Renamed `m_item` to `size_node` for readability;
  `m_item` suggests it's a member variable, which it
  is not.

(cherry picked from commit 08c0eb1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants