1 //===-- LibCxxInitializerList.cpp -------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 #include "lldb/Core/ValueObject.h"
13 #include "lldb/DataFormatters/FormattersHelpers.h"
14 #include "lldb/Utility/ConstString.h"
17 using namespace lldb_private;
18 using namespace lldb_private::formatters;
20 namespace lldb_private {
21 namespace formatters {
22 class LibcxxInitializerListSyntheticFrontEnd
23 : public SyntheticChildrenFrontEnd {
25 LibcxxInitializerListSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
27 ~LibcxxInitializerListSyntheticFrontEnd() override;
29 size_t CalculateNumChildren() override;
31 lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
33 bool Update() override;
35 bool MightHaveChildren() override;
37 size_t GetIndexOfChildWithName(const ConstString &name) override;
41 CompilerType m_element_type;
42 uint32_t m_element_size;
43 size_t m_num_elements;
45 } // namespace formatters
46 } // namespace lldb_private
48 lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::
49 LibcxxInitializerListSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
50 : SyntheticChildrenFrontEnd(*valobj_sp), m_start(nullptr), m_element_type(),
51 m_element_size(0), m_num_elements(0) {
56 lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::
57 ~LibcxxInitializerListSyntheticFrontEnd() {
58 // this needs to stay around because it's a child object who will follow its
59 // parent's life cycle
63 size_t lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::
64 CalculateNumChildren() {
65 static ConstString g___size_("__size_");
67 ValueObjectSP size_sp(m_backend.GetChildMemberWithName(g___size_, true));
69 m_num_elements = size_sp->GetValueAsUnsigned(0);
70 return m_num_elements;
73 lldb::ValueObjectSP lldb_private::formatters::
74 LibcxxInitializerListSyntheticFrontEnd::GetChildAtIndex(size_t idx) {
76 return lldb::ValueObjectSP();
78 uint64_t offset = idx * m_element_size;
79 offset = offset + m_start->GetValueAsUnsigned(0);
81 name.Printf("[%" PRIu64 "]", (uint64_t)idx);
82 return CreateValueObjectFromAddress(name.GetString(), offset,
83 m_backend.GetExecutionContextRef(),
87 bool lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::
89 static ConstString g___begin_("__begin_");
93 m_element_type = m_backend.GetCompilerType().GetTypeTemplateArgument(0);
94 if (!m_element_type.IsValid())
97 if (llvm::Optional<uint64_t> size = m_element_type.GetByteSize(nullptr)) {
98 m_element_size = *size;
99 // Store raw pointers or end up with a circular dependency.
100 m_start = m_backend.GetChildMemberWithName(g___begin_, true).get();
106 bool lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::
107 MightHaveChildren() {
111 size_t lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::
112 GetIndexOfChildWithName(const ConstString &name) {
115 return ExtractIndexFromString(name.GetCString());
118 lldb_private::SyntheticChildrenFrontEnd *
119 lldb_private::formatters::LibcxxInitializerListSyntheticFrontEndCreator(
120 CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
121 return (valobj_sp ? new LibcxxInitializerListSyntheticFrontEnd(valobj_sp)