[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / lldb / source / API / SBTypeEnumMember.cpp
blobbd0755a140c33c072f56bf77518afde630502a70
1 //===-- SBTypeEnumMember.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/SBTypeEnumMember.h"
10 #include "SBReproducerPrivate.h"
11 #include "Utils.h"
12 #include "lldb/API/SBDefines.h"
13 #include "lldb/API/SBStream.h"
14 #include "lldb/API/SBType.h"
15 #include "lldb/Symbol/CompilerType.h"
16 #include "lldb/Symbol/Type.h"
17 #include "lldb/Utility/Stream.h"
19 #include <memory>
21 using namespace lldb;
22 using namespace lldb_private;
24 SBTypeEnumMember::SBTypeEnumMember() : m_opaque_sp() {
25 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTypeEnumMember);
28 SBTypeEnumMember::~SBTypeEnumMember() {}
30 SBTypeEnumMember::SBTypeEnumMember(
31 const lldb::TypeEnumMemberImplSP &enum_member_sp)
32 : m_opaque_sp(enum_member_sp) {}
34 SBTypeEnumMember::SBTypeEnumMember(const SBTypeEnumMember &rhs)
35 : m_opaque_sp() {
36 LLDB_RECORD_CONSTRUCTOR(SBTypeEnumMember, (const lldb::SBTypeEnumMember &),
37 rhs);
39 m_opaque_sp = clone(rhs.m_opaque_sp);
42 SBTypeEnumMember &SBTypeEnumMember::operator=(const SBTypeEnumMember &rhs) {
43 LLDB_RECORD_METHOD(
44 SBTypeEnumMember &,
45 SBTypeEnumMember, operator=,(const lldb::SBTypeEnumMember &), rhs);
47 if (this != &rhs)
48 m_opaque_sp = clone(rhs.m_opaque_sp);
49 return LLDB_RECORD_RESULT(*this);
52 bool SBTypeEnumMember::IsValid() const {
53 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeEnumMember, IsValid);
54 return this->operator bool();
56 SBTypeEnumMember::operator bool() const {
57 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeEnumMember, operator bool);
59 return m_opaque_sp.get();
62 const char *SBTypeEnumMember::GetName() {
63 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeEnumMember, GetName);
65 if (m_opaque_sp.get())
66 return m_opaque_sp->GetName().GetCString();
67 return nullptr;
70 int64_t SBTypeEnumMember::GetValueAsSigned() {
71 LLDB_RECORD_METHOD_NO_ARGS(int64_t, SBTypeEnumMember, GetValueAsSigned);
73 if (m_opaque_sp.get())
74 return m_opaque_sp->GetValueAsSigned();
75 return 0;
78 uint64_t SBTypeEnumMember::GetValueAsUnsigned() {
79 LLDB_RECORD_METHOD_NO_ARGS(uint64_t, SBTypeEnumMember, GetValueAsUnsigned);
81 if (m_opaque_sp.get())
82 return m_opaque_sp->GetValueAsUnsigned();
83 return 0;
86 SBType SBTypeEnumMember::GetType() {
87 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBTypeEnumMember, GetType);
89 SBType sb_type;
90 if (m_opaque_sp.get()) {
91 sb_type.SetSP(m_opaque_sp->GetIntegerType());
93 return LLDB_RECORD_RESULT(sb_type);
96 void SBTypeEnumMember::reset(TypeEnumMemberImpl *type_member_impl) {
97 m_opaque_sp.reset(type_member_impl);
100 TypeEnumMemberImpl &SBTypeEnumMember::ref() {
101 if (m_opaque_sp.get() == nullptr)
102 m_opaque_sp = std::make_shared<TypeEnumMemberImpl>();
103 return *m_opaque_sp.get();
106 const TypeEnumMemberImpl &SBTypeEnumMember::ref() const {
107 return *m_opaque_sp.get();
110 SBTypeEnumMemberList::SBTypeEnumMemberList()
111 : m_opaque_up(new TypeEnumMemberListImpl()) {
112 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTypeEnumMemberList);
115 SBTypeEnumMemberList::SBTypeEnumMemberList(const SBTypeEnumMemberList &rhs)
116 : m_opaque_up(new TypeEnumMemberListImpl()) {
117 LLDB_RECORD_CONSTRUCTOR(SBTypeEnumMemberList,
118 (const lldb::SBTypeEnumMemberList &), rhs);
120 for (uint32_t i = 0,
121 rhs_size = const_cast<SBTypeEnumMemberList &>(rhs).GetSize();
122 i < rhs_size; i++)
123 Append(const_cast<SBTypeEnumMemberList &>(rhs).GetTypeEnumMemberAtIndex(i));
126 bool SBTypeEnumMemberList::IsValid() {
127 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTypeEnumMemberList, IsValid);
128 return this->operator bool();
130 SBTypeEnumMemberList::operator bool() const {
131 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeEnumMemberList, operator bool);
133 return (m_opaque_up != nullptr);
136 SBTypeEnumMemberList &SBTypeEnumMemberList::
137 operator=(const SBTypeEnumMemberList &rhs) {
138 LLDB_RECORD_METHOD(
139 lldb::SBTypeEnumMemberList &,
140 SBTypeEnumMemberList, operator=,(const lldb::SBTypeEnumMemberList &),
141 rhs);
143 if (this != &rhs) {
144 m_opaque_up.reset(new TypeEnumMemberListImpl());
145 for (uint32_t i = 0,
146 rhs_size = const_cast<SBTypeEnumMemberList &>(rhs).GetSize();
147 i < rhs_size; i++)
148 Append(
149 const_cast<SBTypeEnumMemberList &>(rhs).GetTypeEnumMemberAtIndex(i));
151 return LLDB_RECORD_RESULT(*this);
154 void SBTypeEnumMemberList::Append(SBTypeEnumMember enum_member) {
155 LLDB_RECORD_METHOD(void, SBTypeEnumMemberList, Append,
156 (lldb::SBTypeEnumMember), enum_member);
158 if (enum_member.IsValid())
159 m_opaque_up->Append(enum_member.m_opaque_sp);
162 SBTypeEnumMember
163 SBTypeEnumMemberList::GetTypeEnumMemberAtIndex(uint32_t index) {
164 LLDB_RECORD_METHOD(lldb::SBTypeEnumMember, SBTypeEnumMemberList,
165 GetTypeEnumMemberAtIndex, (uint32_t), index);
167 if (m_opaque_up)
168 return LLDB_RECORD_RESULT(
169 SBTypeEnumMember(m_opaque_up->GetTypeEnumMemberAtIndex(index)));
170 return LLDB_RECORD_RESULT(SBTypeEnumMember());
173 uint32_t SBTypeEnumMemberList::GetSize() {
174 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeEnumMemberList, GetSize);
176 return m_opaque_up->GetSize();
179 SBTypeEnumMemberList::~SBTypeEnumMemberList() {}
181 bool SBTypeEnumMember::GetDescription(
182 lldb::SBStream &description, lldb::DescriptionLevel description_level) {
183 LLDB_RECORD_METHOD(bool, SBTypeEnumMember, GetDescription,
184 (lldb::SBStream &, lldb::DescriptionLevel), description,
185 description_level);
187 Stream &strm = description.ref();
189 if (m_opaque_sp.get()) {
190 if (m_opaque_sp->GetIntegerType()->GetDescription(strm,
191 description_level)) {
192 strm.Printf(" %s", m_opaque_sp->GetName().GetCString());
194 } else {
195 strm.PutCString("No value");
197 return true;
200 namespace lldb_private {
201 namespace repro {
203 template <>
204 void RegisterMethods<SBTypeEnumMember>(Registry &R) {
205 LLDB_REGISTER_CONSTRUCTOR(SBTypeEnumMember, ());
206 LLDB_REGISTER_CONSTRUCTOR(SBTypeEnumMember,
207 (const lldb::SBTypeEnumMember &));
208 LLDB_REGISTER_METHOD(
209 lldb::SBTypeEnumMember &,
210 SBTypeEnumMember, operator=,(const lldb::SBTypeEnumMember &));
211 LLDB_REGISTER_METHOD_CONST(bool, SBTypeEnumMember, IsValid, ());
212 LLDB_REGISTER_METHOD_CONST(bool, SBTypeEnumMember, operator bool, ());
213 LLDB_REGISTER_METHOD(const char *, SBTypeEnumMember, GetName, ());
214 LLDB_REGISTER_METHOD(int64_t, SBTypeEnumMember, GetValueAsSigned, ());
215 LLDB_REGISTER_METHOD(uint64_t, SBTypeEnumMember, GetValueAsUnsigned, ());
216 LLDB_REGISTER_METHOD(lldb::SBType, SBTypeEnumMember, GetType, ());
217 LLDB_REGISTER_CONSTRUCTOR(SBTypeEnumMemberList, ());
218 LLDB_REGISTER_CONSTRUCTOR(SBTypeEnumMemberList,
219 (const lldb::SBTypeEnumMemberList &));
220 LLDB_REGISTER_METHOD(bool, SBTypeEnumMemberList, IsValid, ());
221 LLDB_REGISTER_METHOD_CONST(bool, SBTypeEnumMemberList, operator bool, ());
222 LLDB_REGISTER_METHOD(
223 lldb::SBTypeEnumMemberList &,
224 SBTypeEnumMemberList, operator=,(const lldb::SBTypeEnumMemberList &));
225 LLDB_REGISTER_METHOD(void, SBTypeEnumMemberList, Append,
226 (lldb::SBTypeEnumMember));
227 LLDB_REGISTER_METHOD(lldb::SBTypeEnumMember, SBTypeEnumMemberList,
228 GetTypeEnumMemberAtIndex, (uint32_t));
229 LLDB_REGISTER_METHOD(uint32_t, SBTypeEnumMemberList, GetSize, ());
230 LLDB_REGISTER_METHOD(bool, SBTypeEnumMember, GetDescription,
231 (lldb::SBStream &, lldb::DescriptionLevel));