1 //===-- LibCxxTuple.cpp ---------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 #include "lldb/DataFormatters/FormattersHelpers.h"
13 using namespace lldb_private
;
17 class TupleFrontEnd
: public SyntheticChildrenFrontEnd
{
19 TupleFrontEnd(ValueObject
&valobj
) : SyntheticChildrenFrontEnd(valobj
) {
23 size_t GetIndexOfChildWithName(ConstString name
) override
{
24 return formatters::ExtractIndexFromString(name
.GetCString());
27 bool MightHaveChildren() override
{ return true; }
28 lldb::ChildCacheState
Update() override
;
29 llvm::Expected
<uint32_t> CalculateNumChildren() override
{
30 return m_elements
.size();
32 ValueObjectSP
GetChildAtIndex(uint32_t idx
) override
;
35 // The lifetime of a ValueObject and all its derivative ValueObjects
36 // (children, clones, etc.) is managed by a ClusterManager. These
37 // objects are only destroyed when every shared pointer to any of them
38 // is destroyed, so we must not store a shared pointer to any ValueObject
39 // derived from our backend ValueObject (since we're in the same cluster).
40 std::vector
<ValueObject
*> m_elements
;
41 ValueObject
* m_base
= nullptr;
45 lldb::ChildCacheState
TupleFrontEnd::Update() {
49 ValueObjectSP base_sp
;
50 base_sp
= m_backend
.GetChildMemberWithName("__base_");
52 // Pre r304382 name of the base element.
53 base_sp
= m_backend
.GetChildMemberWithName("base_");
56 return lldb::ChildCacheState::eRefetch
;
57 m_base
= base_sp
.get();
58 m_elements
.assign(base_sp
->GetCompilerType().GetNumDirectBaseClasses(),
60 return lldb::ChildCacheState::eRefetch
;
63 ValueObjectSP
TupleFrontEnd::GetChildAtIndex(uint32_t idx
) {
64 if (idx
>= m_elements
.size())
65 return ValueObjectSP();
67 return ValueObjectSP();
69 return m_elements
[idx
]->GetSP();
71 CompilerType holder_type
=
72 m_base
->GetCompilerType().GetDirectBaseClassAtIndex(idx
, nullptr);
74 return ValueObjectSP();
75 ValueObjectSP holder_sp
= m_base
->GetChildAtIndex(idx
);
77 return ValueObjectSP();
79 ValueObjectSP elem_sp
= holder_sp
->GetChildAtIndex(0);
82 elem_sp
->Clone(ConstString(llvm::formatv("[{0}]", idx
).str())).get();
85 return m_elements
[idx
]->GetSP();
86 return ValueObjectSP();
89 SyntheticChildrenFrontEnd
*
90 formatters::LibcxxTupleFrontEndCreator(CXXSyntheticChildren
*,
91 lldb::ValueObjectSP valobj_sp
) {
93 return new TupleFrontEnd(*valobj_sp
);