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 // Other libraries and framework includes
16 #include "lldb/Core/ConstString.h"
17 #include "lldb/Core/ValueObject.h"
18 #include "lldb/DataFormatters/FormattersHelpers.h"
21 using namespace lldb_private;
22 using namespace lldb_private::formatters;
24 namespace lldb_private {
25 namespace formatters {
26 class LibcxxInitializerListSyntheticFrontEnd
27 : public SyntheticChildrenFrontEnd {
29 LibcxxInitializerListSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
31 ~LibcxxInitializerListSyntheticFrontEnd() override;
33 size_t CalculateNumChildren() override;
35 lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
37 bool Update() override;
39 bool MightHaveChildren() override;
41 size_t GetIndexOfChildWithName(const ConstString &name) override;
45 CompilerType m_element_type;
46 uint32_t m_element_size;
47 size_t m_num_elements;
49 } // namespace formatters
50 } // namespace lldb_private
52 lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::
53 LibcxxInitializerListSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
54 : SyntheticChildrenFrontEnd(*valobj_sp), m_start(nullptr), m_element_type(),
55 m_element_size(0), m_num_elements(0) {
60 lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::
61 ~LibcxxInitializerListSyntheticFrontEnd() {
62 // this needs to stay around because it's a child object who will follow its
63 // parent's life cycle
67 size_t lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::
68 CalculateNumChildren() {
69 static ConstString g___size_("__size_");
71 ValueObjectSP size_sp(m_backend.GetChildMemberWithName(g___size_, true));
73 m_num_elements = size_sp->GetValueAsUnsigned(0);
74 return m_num_elements;
77 lldb::ValueObjectSP lldb_private::formatters::
78 LibcxxInitializerListSyntheticFrontEnd::GetChildAtIndex(size_t idx) {
80 return lldb::ValueObjectSP();
82 uint64_t offset = idx * m_element_size;
83 offset = offset + m_start->GetValueAsUnsigned(0);
85 name.Printf("[%" PRIu64 "]", (uint64_t)idx);
86 return CreateValueObjectFromAddress(name.GetString(), offset,
87 m_backend.GetExecutionContextRef(),
91 bool lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::
93 static ConstString g___begin_("__begin_");
97 lldb::TemplateArgumentKind kind;
98 m_element_type = m_backend.GetCompilerType().GetTemplateArgument(0, kind);
99 if (kind != lldb::eTemplateArgumentKindType || !m_element_type.IsValid())
102 m_element_size = m_element_type.GetByteSize(nullptr);
104 if (m_element_size > 0)
106 m_backend.GetChildMemberWithName(g___begin_, true)
107 .get(); // store raw pointers or end up with a circular dependency
112 bool lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::
113 MightHaveChildren() {
117 size_t lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::
118 GetIndexOfChildWithName(const ConstString &name) {
121 return ExtractIndexFromString(name.GetCString());
124 lldb_private::SyntheticChildrenFrontEnd *
125 lldb_private::formatters::LibcxxInitializerListSyntheticFrontEndCreator(
126 CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
127 return (valobj_sp ? new LibcxxInitializerListSyntheticFrontEnd(valobj_sp)