1 //===-- LibCxxRangesRefView.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 //===----------------------------------------------------------------------===//
11 #include "lldb/DataFormatters/FormattersHelpers.h"
12 #include "lldb/Utility/ConstString.h"
13 #include "lldb/ValueObject/ValueObject.h"
14 #include "llvm/ADT/APSInt.h"
17 using namespace lldb_private
;
18 using namespace lldb_private::formatters
;
20 namespace lldb_private
{
21 namespace formatters
{
23 class LibcxxStdRangesRefViewSyntheticFrontEnd
24 : public SyntheticChildrenFrontEnd
{
26 LibcxxStdRangesRefViewSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp
);
28 ~LibcxxStdRangesRefViewSyntheticFrontEnd() override
= default;
30 llvm::Expected
<uint32_t> CalculateNumChildren() override
{
31 // __range_ will be the sole child of this type
35 lldb::ValueObjectSP
GetChildAtIndex(uint32_t idx
) override
{
36 // Since we only have a single child, return it
41 lldb::ChildCacheState
Update() override
;
43 bool MightHaveChildren() override
{ return true; }
45 size_t GetIndexOfChildWithName(ConstString name
) override
{
46 // We only have a single child
51 /// Pointer to the dereferenced __range_ member
52 lldb::ValueObjectSP m_range_sp
= nullptr;
55 lldb_private::formatters::LibcxxStdRangesRefViewSyntheticFrontEnd::
56 LibcxxStdRangesRefViewSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp
)
57 : SyntheticChildrenFrontEnd(*valobj_sp
) {
63 lldb_private::formatters::LibcxxStdRangesRefViewSyntheticFrontEnd::Update() {
64 ValueObjectSP range_ptr
=
65 GetChildMemberWithName(m_backend
, {ConstString("__range_")});
67 return lldb::ChildCacheState::eRefetch
;
69 lldb_private::Status error
;
70 m_range_sp
= range_ptr
->Dereference(error
);
72 return error
.Success() ? lldb::ChildCacheState::eReuse
73 : lldb::ChildCacheState::eRefetch
;
76 lldb_private::SyntheticChildrenFrontEnd
*
77 LibcxxStdRangesRefViewSyntheticFrontEndCreator(CXXSyntheticChildren
*,
78 lldb::ValueObjectSP valobj_sp
) {
81 CompilerType type
= valobj_sp
->GetCompilerType();
84 return new LibcxxStdRangesRefViewSyntheticFrontEnd(valobj_sp
);
87 } // namespace formatters
88 } // namespace lldb_private