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 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-python.h"
12 #include "lldb/DataFormatters/CXXFormatterFunctions.h"
14 #include "lldb/Core/ConstString.h"
15 #include "lldb/Core/ValueObject.h"
18 using namespace lldb_private;
19 using namespace lldb_private::formatters;
21 namespace lldb_private {
22 namespace formatters {
23 class LibcxxInitializerListSyntheticFrontEnd : public SyntheticChildrenFrontEnd
26 LibcxxInitializerListSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp);
29 CalculateNumChildren ();
31 virtual lldb::ValueObjectSP
32 GetChildAtIndex (size_t idx);
41 GetIndexOfChildWithName (const ConstString &name);
44 ~LibcxxInitializerListSyntheticFrontEnd ();
47 ClangASTType m_element_type;
48 uint32_t m_element_size;
49 size_t m_num_elements;
50 std::map<size_t,lldb::ValueObjectSP> m_children;
55 lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::LibcxxInitializerListSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp) :
56 SyntheticChildrenFrontEnd(*valobj_sp.get()),
68 lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::CalculateNumChildren ()
70 static ConstString g___size_("__size_");
72 ValueObjectSP size_sp(m_backend.GetChildMemberWithName(g___size_, true));
74 m_num_elements = size_sp->GetValueAsUnsigned(0);
75 return m_num_elements;
79 lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::GetChildAtIndex (size_t idx)
82 return lldb::ValueObjectSP();
84 auto cached = m_children.find(idx);
85 if (cached != m_children.end())
86 return cached->second;
88 uint64_t offset = idx * m_element_size;
89 offset = offset + m_start->GetValueAsUnsigned(0);
91 name.Printf("[%" PRIu64 "]", (uint64_t)idx);
92 ValueObjectSP child_sp = CreateValueObjectFromAddress(name.GetData(), offset, m_backend.GetExecutionContextRef(), m_element_type);
93 m_children[idx] = child_sp;
98 lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::Update()
100 static ConstString g___begin_("__begin_");
105 lldb::TemplateArgumentKind kind;
106 m_element_type = m_backend.GetClangType().GetTemplateArgument(0, kind);
107 if (kind != lldb::eTemplateArgumentKindType || false == m_element_type.IsValid())
110 m_element_size = m_element_type.GetByteSize();
112 if (m_element_size > 0)
113 m_start = m_backend.GetChildMemberWithName(g___begin_,true).get(); // store raw pointers or end up with a circular dependency
119 lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::MightHaveChildren ()
125 lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::GetIndexOfChildWithName (const ConstString &name)
129 return ExtractIndexFromString(name.GetCString());
132 lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::~LibcxxInitializerListSyntheticFrontEnd ()
134 // this needs to stay around because it's a child object who will follow its parent's life cycle
138 lldb_private::SyntheticChildrenFrontEnd*
139 lldb_private::formatters::LibcxxInitializerListSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP valobj_sp)
143 return (new LibcxxInitializerListSyntheticFrontEnd(valobj_sp));