Path: blob/main/contrib/llvm-project/lldb/source/Plugins/Language/CPlusPlus/LibCxxRangesRefView.cpp
39642 views
//===-- LibCxxRangesRefView.cpp -------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "LibCxx.h"910#include "lldb/Core/ValueObject.h"11#include "lldb/DataFormatters/FormattersHelpers.h"12#include "lldb/Utility/ConstString.h"13#include "llvm/ADT/APSInt.h"1415using namespace lldb;16using namespace lldb_private;17using namespace lldb_private::formatters;1819namespace lldb_private {20namespace formatters {2122class LibcxxStdRangesRefViewSyntheticFrontEnd23: public SyntheticChildrenFrontEnd {24public:25LibcxxStdRangesRefViewSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);2627~LibcxxStdRangesRefViewSyntheticFrontEnd() override = default;2829llvm::Expected<uint32_t> CalculateNumChildren() override {30// __range_ will be the sole child of this type31return 1;32}3334lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override {35// Since we only have a single child, return it36assert(idx == 0);37return m_range_sp;38}3940lldb::ChildCacheState Update() override;4142bool MightHaveChildren() override { return true; }4344size_t GetIndexOfChildWithName(ConstString name) override {45// We only have a single child46return 0;47}4849private:50/// Pointer to the dereferenced __range_ member51lldb::ValueObjectSP m_range_sp = nullptr;52};5354lldb_private::formatters::LibcxxStdRangesRefViewSyntheticFrontEnd::55LibcxxStdRangesRefViewSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)56: SyntheticChildrenFrontEnd(*valobj_sp) {57if (valobj_sp)58Update();59}6061lldb::ChildCacheState62lldb_private::formatters::LibcxxStdRangesRefViewSyntheticFrontEnd::Update() {63ValueObjectSP range_ptr =64GetChildMemberWithName(m_backend, {ConstString("__range_")});65if (!range_ptr)66return lldb::ChildCacheState::eRefetch;6768lldb_private::Status error;69m_range_sp = range_ptr->Dereference(error);7071return error.Success() ? lldb::ChildCacheState::eReuse72: lldb::ChildCacheState::eRefetch;73}7475lldb_private::SyntheticChildrenFrontEnd *76LibcxxStdRangesRefViewSyntheticFrontEndCreator(CXXSyntheticChildren *,77lldb::ValueObjectSP valobj_sp) {78if (!valobj_sp)79return nullptr;80CompilerType type = valobj_sp->GetCompilerType();81if (!type.IsValid())82return nullptr;83return new LibcxxStdRangesRefViewSyntheticFrontEnd(valobj_sp);84}8586} // namespace formatters87} // namespace lldb_private888990