[lldb][dwarf] Compute fully qualified names on simplified template names with DWARFT...
[llvm-project.git] / lldb / source / API / SBValueList.cpp
blob0a90ea66f974f7d04daba143f778e0a4858018cd
1 //===-- SBValueList.cpp ---------------------------------------------------===//
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 "lldb/API/SBError.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/API/SBValue.h"
13 #include "lldb/Utility/Instrumentation.h"
14 #include "lldb/Utility/Status.h"
15 #include "lldb/ValueObject/ValueObjectList.h"
16 #include <vector>
18 using namespace lldb;
19 using namespace lldb_private;
21 class ValueListImpl {
22 public:
23 ValueListImpl() = default;
25 ValueListImpl(const ValueListImpl &rhs)
26 : m_values(rhs.m_values), m_error(rhs.m_error.Clone()) {}
28 ValueListImpl &operator=(const ValueListImpl &rhs) {
29 if (this == &rhs)
30 return *this;
31 m_values = rhs.m_values;
32 m_error = rhs.m_error.Clone();
33 return *this;
36 uint32_t GetSize() { return m_values.size(); }
38 void Append(const lldb::SBValue &sb_value) { m_values.push_back(sb_value); }
40 void Append(const ValueListImpl &list) {
41 for (auto val : list.m_values)
42 Append(val);
45 lldb::SBValue GetValueAtIndex(uint32_t index) {
46 if (index >= GetSize())
47 return lldb::SBValue();
48 return m_values[index];
51 lldb::SBValue FindValueByUID(lldb::user_id_t uid) {
52 for (auto val : m_values) {
53 if (val.IsValid() && val.GetID() == uid)
54 return val;
56 return lldb::SBValue();
59 lldb::SBValue GetFirstValueByName(const char *name) const {
60 if (name) {
61 for (auto val : m_values) {
62 if (val.IsValid() && val.GetName() && strcmp(name, val.GetName()) == 0)
63 return val;
66 return lldb::SBValue();
69 const Status &GetError() const { return m_error; }
71 void SetError(Status &&error) { m_error = std::move(error); }
73 private:
74 std::vector<lldb::SBValue> m_values;
75 Status m_error;
78 SBValueList::SBValueList() { LLDB_INSTRUMENT_VA(this); }
80 SBValueList::SBValueList(const SBValueList &rhs) {
81 LLDB_INSTRUMENT_VA(this, rhs);
83 if (rhs.IsValid())
84 m_opaque_up = std::make_unique<ValueListImpl>(*rhs);
87 SBValueList::SBValueList(const ValueListImpl *lldb_object_ptr) {
88 if (lldb_object_ptr)
89 m_opaque_up = std::make_unique<ValueListImpl>(*lldb_object_ptr);
92 SBValueList::~SBValueList() = default;
94 bool SBValueList::IsValid() const {
95 LLDB_INSTRUMENT_VA(this);
96 return this->operator bool();
98 SBValueList::operator bool() const {
99 LLDB_INSTRUMENT_VA(this);
101 return (m_opaque_up != nullptr);
104 void SBValueList::Clear() {
105 LLDB_INSTRUMENT_VA(this);
107 m_opaque_up.reset();
110 const SBValueList &SBValueList::operator=(const SBValueList &rhs) {
111 LLDB_INSTRUMENT_VA(this, rhs);
113 if (this != &rhs) {
114 if (rhs.IsValid())
115 m_opaque_up = std::make_unique<ValueListImpl>(*rhs);
116 else
117 m_opaque_up.reset();
119 return *this;
122 ValueListImpl *SBValueList::operator->() { return m_opaque_up.get(); }
124 ValueListImpl &SBValueList::operator*() { return *m_opaque_up; }
126 const ValueListImpl *SBValueList::operator->() const {
127 return m_opaque_up.get();
130 const ValueListImpl &SBValueList::operator*() const { return *m_opaque_up; }
132 void SBValueList::Append(const SBValue &val_obj) {
133 LLDB_INSTRUMENT_VA(this, val_obj);
135 CreateIfNeeded();
136 m_opaque_up->Append(val_obj);
139 void SBValueList::Append(lldb::ValueObjectSP &val_obj_sp) {
140 if (val_obj_sp) {
141 CreateIfNeeded();
142 m_opaque_up->Append(SBValue(val_obj_sp));
146 void SBValueList::Append(const lldb::SBValueList &value_list) {
147 LLDB_INSTRUMENT_VA(this, value_list);
149 if (value_list.IsValid()) {
150 CreateIfNeeded();
151 m_opaque_up->Append(*value_list);
155 SBValue SBValueList::GetValueAtIndex(uint32_t idx) const {
156 LLDB_INSTRUMENT_VA(this, idx);
158 SBValue sb_value;
159 if (m_opaque_up)
160 sb_value = m_opaque_up->GetValueAtIndex(idx);
162 return sb_value;
165 uint32_t SBValueList::GetSize() const {
166 LLDB_INSTRUMENT_VA(this);
168 uint32_t size = 0;
169 if (m_opaque_up)
170 size = m_opaque_up->GetSize();
172 return size;
175 void SBValueList::CreateIfNeeded() {
176 if (m_opaque_up == nullptr)
177 m_opaque_up = std::make_unique<ValueListImpl>();
180 SBValue SBValueList::FindValueObjectByUID(lldb::user_id_t uid) {
181 LLDB_INSTRUMENT_VA(this, uid);
183 SBValue sb_value;
184 if (m_opaque_up)
185 sb_value = m_opaque_up->FindValueByUID(uid);
186 return sb_value;
189 SBValue SBValueList::GetFirstValueByName(const char *name) const {
190 LLDB_INSTRUMENT_VA(this, name);
192 SBValue sb_value;
193 if (m_opaque_up)
194 sb_value = m_opaque_up->GetFirstValueByName(name);
195 return sb_value;
198 void *SBValueList::opaque_ptr() { return m_opaque_up.get(); }
200 ValueListImpl &SBValueList::ref() {
201 CreateIfNeeded();
202 return *m_opaque_up;
205 lldb::SBError SBValueList::GetError() {
206 LLDB_INSTRUMENT_VA(this);
207 SBError sb_error;
208 if (m_opaque_up)
209 sb_error.SetError(m_opaque_up->GetError().Clone());
210 return sb_error;
213 void SBValueList::SetError(lldb_private::Status &&status) {
214 ref().SetError(std::move(status));