[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / lldb / source / API / SBValueList.cpp
blob7e909df260d7d7f8066bc333c5164251cec6fb72
1 //===-- SBValueList.cpp -----------------------------------------*- C++ -*-===//
2 //
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
6 //
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"
15 #include <vector>
17 using namespace lldb;
18 using namespace lldb_private;
20 class ValueListImpl {
21 public:
22 ValueListImpl() : m_values() {}
24 ValueListImpl(const ValueListImpl &rhs) : m_values(rhs.m_values) {}
26 ValueListImpl &operator=(const ValueListImpl &rhs) {
27 if (this == &rhs)
28 return *this;
29 m_values = rhs.m_values;
30 return *this;
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)
39 Append(val);
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)
51 return val;
53 return lldb::SBValue();
56 lldb::SBValue GetFirstValueByName(const char *name) const {
57 if (name) {
58 for (auto val : m_values) {
59 if (val.IsValid() && val.GetName() && strcmp(name, val.GetName()) == 0)
60 return val;
63 return lldb::SBValue();
66 private:
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);
77 if (rhs.IsValid())
78 m_opaque_up.reset(new ValueListImpl(*rhs));
81 SBValueList::SBValueList(const ValueListImpl *lldb_object_ptr) : m_opaque_up() {
82 if (lldb_object_ptr)
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);
101 m_opaque_up.reset();
104 const SBValueList &SBValueList::operator=(const SBValueList &rhs) {
105 LLDB_RECORD_METHOD(const lldb::SBValueList &,
106 SBValueList, operator=,(const lldb::SBValueList &), rhs);
108 if (this != &rhs) {
109 if (rhs.IsValid())
110 m_opaque_up.reset(new ValueListImpl(*rhs));
111 else
112 m_opaque_up.reset();
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 &),
129 val_obj);
131 CreateIfNeeded();
132 m_opaque_up->Append(val_obj);
135 void SBValueList::Append(lldb::ValueObjectSP &val_obj_sp) {
136 if (val_obj_sp) {
137 CreateIfNeeded();
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 &),
144 value_list);
146 if (value_list.IsValid()) {
147 CreateIfNeeded();
148 m_opaque_up->Append(*value_list);
152 SBValue SBValueList::GetValueAtIndex(uint32_t idx) const {
153 LLDB_RECORD_METHOD_CONST(lldb::SBValue, SBValueList, GetValueAtIndex,
154 (uint32_t), idx);
157 SBValue sb_value;
158 if (m_opaque_up)
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);
167 uint32_t size = 0;
168 if (m_opaque_up)
169 size = m_opaque_up->GetSize();
171 return size;
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);
183 SBValue sb_value;
184 if (m_opaque_up)
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);
193 SBValue sb_value;
194 if (m_opaque_up)
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() {
202 CreateIfNeeded();
203 return *m_opaque_up;
206 namespace lldb_private {
207 namespace repro {
209 template <>
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,
222 (uint32_t));
223 LLDB_REGISTER_METHOD_CONST(uint32_t, SBValueList, GetSize, ());
224 LLDB_REGISTER_METHOD(lldb::SBValue, SBValueList, FindValueObjectByUID,
225 (lldb::user_id_t));
226 LLDB_REGISTER_METHOD_CONST(lldb::SBValue, SBValueList, GetFirstValueByName,
227 (const char *));