1 //===-- SBValueList.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 //===----------------------------------------------------------------------===//
9 #include "lldb/API/SBValueList.h"
10 #include "lldb/API/SBError.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/API/SBValue.h"
13 #include "lldb/Core/ValueObjectList.h"
14 #include "lldb/Utility/Instrumentation.h"
15 #include "lldb/Utility/Status.h"
19 using namespace lldb_private
;
23 ValueListImpl() = default;
25 ValueListImpl(const ValueListImpl
&rhs
) = default;
27 ValueListImpl
&operator=(const ValueListImpl
&rhs
) {
30 m_values
= rhs
.m_values
;
31 m_error
= rhs
.m_error
;
35 uint32_t GetSize() { return m_values
.size(); }
37 void Append(const lldb::SBValue
&sb_value
) { m_values
.push_back(sb_value
); }
39 void Append(const ValueListImpl
&list
) {
40 for (auto val
: list
.m_values
)
44 lldb::SBValue
GetValueAtIndex(uint32_t index
) {
45 if (index
>= GetSize())
46 return lldb::SBValue();
47 return m_values
[index
];
50 lldb::SBValue
FindValueByUID(lldb::user_id_t uid
) {
51 for (auto val
: m_values
) {
52 if (val
.IsValid() && val
.GetID() == uid
)
55 return lldb::SBValue();
58 lldb::SBValue
GetFirstValueByName(const char *name
) const {
60 for (auto val
: m_values
) {
61 if (val
.IsValid() && val
.GetName() && strcmp(name
, val
.GetName()) == 0)
65 return lldb::SBValue();
68 const Status
&GetError() const { return m_error
; }
70 void SetError(const Status
&error
) { m_error
= error
; }
73 std::vector
<lldb::SBValue
> m_values
;
77 SBValueList::SBValueList() { LLDB_INSTRUMENT_VA(this); }
79 SBValueList::SBValueList(const SBValueList
&rhs
) {
80 LLDB_INSTRUMENT_VA(this, rhs
);
83 m_opaque_up
= std::make_unique
<ValueListImpl
>(*rhs
);
86 SBValueList::SBValueList(const ValueListImpl
*lldb_object_ptr
) {
88 m_opaque_up
= std::make_unique
<ValueListImpl
>(*lldb_object_ptr
);
91 SBValueList::~SBValueList() = default;
93 bool SBValueList::IsValid() const {
94 LLDB_INSTRUMENT_VA(this);
95 return this->operator bool();
97 SBValueList::operator bool() const {
98 LLDB_INSTRUMENT_VA(this);
100 return (m_opaque_up
!= nullptr);
103 void SBValueList::Clear() {
104 LLDB_INSTRUMENT_VA(this);
109 const SBValueList
&SBValueList::operator=(const SBValueList
&rhs
) {
110 LLDB_INSTRUMENT_VA(this, rhs
);
114 m_opaque_up
= std::make_unique
<ValueListImpl
>(*rhs
);
121 ValueListImpl
*SBValueList::operator->() { return m_opaque_up
.get(); }
123 ValueListImpl
&SBValueList::operator*() { return *m_opaque_up
; }
125 const ValueListImpl
*SBValueList::operator->() const {
126 return m_opaque_up
.get();
129 const ValueListImpl
&SBValueList::operator*() const { return *m_opaque_up
; }
131 void SBValueList::Append(const SBValue
&val_obj
) {
132 LLDB_INSTRUMENT_VA(this, val_obj
);
135 m_opaque_up
->Append(val_obj
);
138 void SBValueList::Append(lldb::ValueObjectSP
&val_obj_sp
) {
141 m_opaque_up
->Append(SBValue(val_obj_sp
));
145 void SBValueList::Append(const lldb::SBValueList
&value_list
) {
146 LLDB_INSTRUMENT_VA(this, value_list
);
148 if (value_list
.IsValid()) {
150 m_opaque_up
->Append(*value_list
);
154 SBValue
SBValueList::GetValueAtIndex(uint32_t idx
) const {
155 LLDB_INSTRUMENT_VA(this, idx
);
159 sb_value
= m_opaque_up
->GetValueAtIndex(idx
);
164 uint32_t SBValueList::GetSize() const {
165 LLDB_INSTRUMENT_VA(this);
169 size
= m_opaque_up
->GetSize();
174 void SBValueList::CreateIfNeeded() {
175 if (m_opaque_up
== nullptr)
176 m_opaque_up
= std::make_unique
<ValueListImpl
>();
179 SBValue
SBValueList::FindValueObjectByUID(lldb::user_id_t uid
) {
180 LLDB_INSTRUMENT_VA(this, uid
);
184 sb_value
= m_opaque_up
->FindValueByUID(uid
);
188 SBValue
SBValueList::GetFirstValueByName(const char *name
) const {
189 LLDB_INSTRUMENT_VA(this, name
);
193 sb_value
= m_opaque_up
->GetFirstValueByName(name
);
197 void *SBValueList::opaque_ptr() { return m_opaque_up
.get(); }
199 ValueListImpl
&SBValueList::ref() {
204 lldb::SBError
SBValueList::GetError() {
205 LLDB_INSTRUMENT_VA(this);
208 sb_error
.SetError(m_opaque_up
->GetError());
212 void SBValueList::SetError(const lldb_private::Status
&status
) {
213 ref().SetError(status
);