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/DataFormatters/CXXFormatterFunctions.h"
12 #include "lldb/Core/ConstString.h"
13 #include "lldb/Core/ValueObject.h"
16 using namespace lldb_private;
17 using namespace lldb_private::formatters;
19 namespace lldb_private {
20 namespace formatters {
21 class LibcxxInitializerListSyntheticFrontEnd : public SyntheticChildrenFrontEnd
24 LibcxxInitializerListSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp);
27 CalculateNumChildren ();
29 virtual lldb::ValueObjectSP
30 GetChildAtIndex (size_t idx);
39 GetIndexOfChildWithName (const ConstString &name);
42 ~LibcxxInitializerListSyntheticFrontEnd ();
45 ClangASTType m_element_type;
46 uint32_t m_element_size;
47 size_t m_num_elements;
48 std::map<size_t,lldb::ValueObjectSP> m_children;
53 lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::LibcxxInitializerListSyntheticFrontEnd (lldb::ValueObjectSP valobj_sp) :
54 SyntheticChildrenFrontEnd(*valobj_sp.get()),
66 lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::CalculateNumChildren ()
68 static ConstString g___size_("__size_");
70 ValueObjectSP size_sp(m_backend.GetChildMemberWithName(g___size_, true));
72 m_num_elements = size_sp->GetValueAsUnsigned(0);
73 return m_num_elements;
77 lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::GetChildAtIndex (size_t idx)
80 return lldb::ValueObjectSP();
82 auto cached = m_children.find(idx);
83 if (cached != m_children.end())
84 return cached->second;
86 uint64_t offset = idx * m_element_size;
87 offset = offset + m_start->GetValueAsUnsigned(0);
89 name.Printf("[%" PRIu64 "]", (uint64_t)idx);
90 ValueObjectSP child_sp = CreateValueObjectFromAddress(name.GetData(), offset, m_backend.GetExecutionContextRef(), m_element_type);
91 m_children[idx] = child_sp;
96 lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::Update()
98 static ConstString g___begin_("__begin_");
103 lldb::TemplateArgumentKind kind;
104 m_element_type = m_backend.GetClangType().GetTemplateArgument(0, kind);
105 if (kind != lldb::eTemplateArgumentKindType || false == m_element_type.IsValid())
108 m_element_size = m_element_type.GetByteSize(nullptr);
110 if (m_element_size > 0)
111 m_start = m_backend.GetChildMemberWithName(g___begin_,true).get(); // store raw pointers or end up with a circular dependency
117 lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::MightHaveChildren ()
123 lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::GetIndexOfChildWithName (const ConstString &name)
127 return ExtractIndexFromString(name.GetCString());
130 lldb_private::formatters::LibcxxInitializerListSyntheticFrontEnd::~LibcxxInitializerListSyntheticFrontEnd ()
132 // this needs to stay around because it's a child object who will follow its parent's life cycle
136 lldb_private::SyntheticChildrenFrontEnd*
137 lldb_private::formatters::LibcxxInitializerListSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP valobj_sp)
141 return (new LibcxxInitializerListSyntheticFrontEnd(valobj_sp));