1 //===-- SBValueList.cpp -----------------------------------------*- C++ -*-===//
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 "SBReproducerPrivate.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/API/SBValue.h"
13 #include "lldb/Core/ValueObjectList.h"
18 using namespace lldb_private
;
22 ValueListImpl() : m_values() {}
24 ValueListImpl(const ValueListImpl
&rhs
) : m_values(rhs
.m_values
) {}
26 ValueListImpl
&operator=(const ValueListImpl
&rhs
) {
29 m_values
= rhs
.m_values
;
33 uint32_t GetSize() { return m_values
.size(); }
35 void Append(const lldb::SBValue
&sb_value
) { m_values
.push_back(sb_value
); }
37 void Append(const ValueListImpl
&list
) {
38 for (auto val
: list
.m_values
)
42 lldb::SBValue
GetValueAtIndex(uint32_t index
) {
43 if (index
>= GetSize())
44 return lldb::SBValue();
45 return m_values
[index
];
48 lldb::SBValue
FindValueByUID(lldb::user_id_t uid
) {
49 for (auto val
: m_values
) {
50 if (val
.IsValid() && val
.GetID() == uid
)
53 return lldb::SBValue();
56 lldb::SBValue
GetFirstValueByName(const char *name
) const {
58 for (auto val
: m_values
) {
59 if (val
.IsValid() && val
.GetName() && strcmp(name
, val
.GetName()) == 0)
63 return lldb::SBValue();
67 std::vector
<lldb::SBValue
> m_values
;
70 SBValueList::SBValueList() : m_opaque_up() {
71 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBValueList
);
74 SBValueList::SBValueList(const SBValueList
&rhs
) : m_opaque_up() {
75 LLDB_RECORD_CONSTRUCTOR(SBValueList
, (const lldb::SBValueList
&), rhs
);
78 m_opaque_up
.reset(new ValueListImpl(*rhs
));
81 SBValueList::SBValueList(const ValueListImpl
*lldb_object_ptr
) : m_opaque_up() {
83 m_opaque_up
.reset(new ValueListImpl(*lldb_object_ptr
));
86 SBValueList::~SBValueList() {}
88 bool SBValueList::IsValid() const {
89 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBValueList
, IsValid
);
90 return this->operator bool();
92 SBValueList::operator bool() const {
93 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBValueList
, operator bool);
95 return (m_opaque_up
!= nullptr);
98 void SBValueList::Clear() {
99 LLDB_RECORD_METHOD_NO_ARGS(void, SBValueList
, Clear
);
104 const SBValueList
&SBValueList::operator=(const SBValueList
&rhs
) {
105 LLDB_RECORD_METHOD(const lldb::SBValueList
&,
106 SBValueList
, operator=,(const lldb::SBValueList
&), rhs
);
110 m_opaque_up
.reset(new ValueListImpl(*rhs
));
114 return LLDB_RECORD_RESULT(*this);
117 ValueListImpl
*SBValueList::operator->() { return m_opaque_up
.get(); }
119 ValueListImpl
&SBValueList::operator*() { return *m_opaque_up
; }
121 const ValueListImpl
*SBValueList::operator->() const {
122 return m_opaque_up
.get();
125 const ValueListImpl
&SBValueList::operator*() const { return *m_opaque_up
; }
127 void SBValueList::Append(const SBValue
&val_obj
) {
128 LLDB_RECORD_METHOD(void, SBValueList
, Append
, (const lldb::SBValue
&),
132 m_opaque_up
->Append(val_obj
);
135 void SBValueList::Append(lldb::ValueObjectSP
&val_obj_sp
) {
138 m_opaque_up
->Append(SBValue(val_obj_sp
));
142 void SBValueList::Append(const lldb::SBValueList
&value_list
) {
143 LLDB_RECORD_METHOD(void, SBValueList
, Append
, (const lldb::SBValueList
&),
146 if (value_list
.IsValid()) {
148 m_opaque_up
->Append(*value_list
);
152 SBValue
SBValueList::GetValueAtIndex(uint32_t idx
) const {
153 LLDB_RECORD_METHOD_CONST(lldb::SBValue
, SBValueList
, GetValueAtIndex
,
159 sb_value
= m_opaque_up
->GetValueAtIndex(idx
);
161 return LLDB_RECORD_RESULT(sb_value
);
164 uint32_t SBValueList::GetSize() const {
165 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBValueList
, GetSize
);
169 size
= m_opaque_up
->GetSize();
174 void SBValueList::CreateIfNeeded() {
175 if (m_opaque_up
== nullptr)
176 m_opaque_up
.reset(new ValueListImpl());
179 SBValue
SBValueList::FindValueObjectByUID(lldb::user_id_t uid
) {
180 LLDB_RECORD_METHOD(lldb::SBValue
, SBValueList
, FindValueObjectByUID
,
181 (lldb::user_id_t
), uid
);
185 sb_value
= m_opaque_up
->FindValueByUID(uid
);
186 return LLDB_RECORD_RESULT(sb_value
);
189 SBValue
SBValueList::GetFirstValueByName(const char *name
) const {
190 LLDB_RECORD_METHOD_CONST(lldb::SBValue
, SBValueList
, GetFirstValueByName
,
191 (const char *), name
);
195 sb_value
= m_opaque_up
->GetFirstValueByName(name
);
196 return LLDB_RECORD_RESULT(sb_value
);
199 void *SBValueList::opaque_ptr() { return m_opaque_up
.get(); }
201 ValueListImpl
&SBValueList::ref() {
206 namespace lldb_private
{
210 void RegisterMethods
<SBValueList
>(Registry
&R
) {
211 LLDB_REGISTER_CONSTRUCTOR(SBValueList
, ());
212 LLDB_REGISTER_CONSTRUCTOR(SBValueList
, (const lldb::SBValueList
&));
213 LLDB_REGISTER_METHOD_CONST(bool, SBValueList
, IsValid
, ());
214 LLDB_REGISTER_METHOD_CONST(bool, SBValueList
, operator bool, ());
215 LLDB_REGISTER_METHOD(void, SBValueList
, Clear
, ());
216 LLDB_REGISTER_METHOD(const lldb::SBValueList
&,
217 SBValueList
, operator=,(const lldb::SBValueList
&));
218 LLDB_REGISTER_METHOD(void, SBValueList
, Append
, (const lldb::SBValue
&));
219 LLDB_REGISTER_METHOD(void, SBValueList
, Append
,
220 (const lldb::SBValueList
&));
221 LLDB_REGISTER_METHOD_CONST(lldb::SBValue
, SBValueList
, GetValueAtIndex
,
223 LLDB_REGISTER_METHOD_CONST(uint32_t, SBValueList
, GetSize
, ());
224 LLDB_REGISTER_METHOD(lldb::SBValue
, SBValueList
, FindValueObjectByUID
,
226 LLDB_REGISTER_METHOD_CONST(lldb::SBValue
, SBValueList
, GetFirstValueByName
,