1 //===-- SBTypeEnumMember.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/SBTypeEnumMember.h"
11 #include "lldb/API/SBDefines.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/API/SBType.h"
14 #include "lldb/Symbol/CompilerType.h"
15 #include "lldb/Symbol/Type.h"
16 #include "lldb/Utility/Instrumentation.h"
17 #include "lldb/Utility/Stream.h"
22 using namespace lldb_private
;
24 SBTypeEnumMember::SBTypeEnumMember() { LLDB_INSTRUMENT_VA(this); }
26 SBTypeEnumMember::~SBTypeEnumMember() = default;
28 SBTypeEnumMember::SBTypeEnumMember(
29 const lldb::TypeEnumMemberImplSP
&enum_member_sp
)
30 : m_opaque_sp(enum_member_sp
) {}
32 SBTypeEnumMember::SBTypeEnumMember(const SBTypeEnumMember
&rhs
) {
33 LLDB_INSTRUMENT_VA(this, rhs
);
35 m_opaque_sp
= clone(rhs
.m_opaque_sp
);
38 SBTypeEnumMember
&SBTypeEnumMember::operator=(const SBTypeEnumMember
&rhs
) {
39 LLDB_INSTRUMENT_VA(this, rhs
);
42 m_opaque_sp
= clone(rhs
.m_opaque_sp
);
46 bool SBTypeEnumMember::IsValid() const {
47 LLDB_INSTRUMENT_VA(this);
48 return this->operator bool();
50 SBTypeEnumMember::operator bool() const {
51 LLDB_INSTRUMENT_VA(this);
53 return m_opaque_sp
.get();
56 const char *SBTypeEnumMember::GetName() {
57 LLDB_INSTRUMENT_VA(this);
59 if (m_opaque_sp
.get())
60 return m_opaque_sp
->GetName().GetCString();
64 int64_t SBTypeEnumMember::GetValueAsSigned() {
65 LLDB_INSTRUMENT_VA(this);
67 if (m_opaque_sp
.get())
68 return m_opaque_sp
->GetValueAsSigned();
72 uint64_t SBTypeEnumMember::GetValueAsUnsigned() {
73 LLDB_INSTRUMENT_VA(this);
75 if (m_opaque_sp
.get())
76 return m_opaque_sp
->GetValueAsUnsigned();
80 SBType
SBTypeEnumMember::GetType() {
81 LLDB_INSTRUMENT_VA(this);
84 if (m_opaque_sp
.get()) {
85 sb_type
.SetSP(m_opaque_sp
->GetIntegerType());
90 void SBTypeEnumMember::reset(TypeEnumMemberImpl
*type_member_impl
) {
91 m_opaque_sp
.reset(type_member_impl
);
94 TypeEnumMemberImpl
&SBTypeEnumMember::ref() {
95 if (m_opaque_sp
.get() == nullptr)
96 m_opaque_sp
= std::make_shared
<TypeEnumMemberImpl
>();
97 return *m_opaque_sp
.get();
100 const TypeEnumMemberImpl
&SBTypeEnumMember::ref() const {
101 return *m_opaque_sp
.get();
104 SBTypeEnumMemberList::SBTypeEnumMemberList()
105 : m_opaque_up(new TypeEnumMemberListImpl()) {
106 LLDB_INSTRUMENT_VA(this);
109 SBTypeEnumMemberList::SBTypeEnumMemberList(const SBTypeEnumMemberList
&rhs
)
110 : m_opaque_up(new TypeEnumMemberListImpl()) {
111 LLDB_INSTRUMENT_VA(this, rhs
);
114 rhs_size
= const_cast<SBTypeEnumMemberList
&>(rhs
).GetSize();
116 Append(const_cast<SBTypeEnumMemberList
&>(rhs
).GetTypeEnumMemberAtIndex(i
));
119 bool SBTypeEnumMemberList::IsValid() {
120 LLDB_INSTRUMENT_VA(this);
121 return this->operator bool();
123 SBTypeEnumMemberList::operator bool() const {
124 LLDB_INSTRUMENT_VA(this);
126 return (m_opaque_up
!= nullptr);
129 SBTypeEnumMemberList
&SBTypeEnumMemberList::
130 operator=(const SBTypeEnumMemberList
&rhs
) {
131 LLDB_INSTRUMENT_VA(this, rhs
);
134 m_opaque_up
= std::make_unique
<TypeEnumMemberListImpl
>();
136 rhs_size
= const_cast<SBTypeEnumMemberList
&>(rhs
).GetSize();
139 const_cast<SBTypeEnumMemberList
&>(rhs
).GetTypeEnumMemberAtIndex(i
));
144 void SBTypeEnumMemberList::Append(SBTypeEnumMember enum_member
) {
145 LLDB_INSTRUMENT_VA(this, enum_member
);
147 if (enum_member
.IsValid())
148 m_opaque_up
->Append(enum_member
.m_opaque_sp
);
152 SBTypeEnumMemberList::GetTypeEnumMemberAtIndex(uint32_t index
) {
153 LLDB_INSTRUMENT_VA(this, index
);
156 return SBTypeEnumMember(m_opaque_up
->GetTypeEnumMemberAtIndex(index
));
157 return SBTypeEnumMember();
160 uint32_t SBTypeEnumMemberList::GetSize() {
161 LLDB_INSTRUMENT_VA(this);
163 return m_opaque_up
->GetSize();
166 SBTypeEnumMemberList::~SBTypeEnumMemberList() = default;
168 bool SBTypeEnumMember::GetDescription(
169 lldb::SBStream
&description
, lldb::DescriptionLevel description_level
) {
170 LLDB_INSTRUMENT_VA(this, description
, description_level
);
172 Stream
&strm
= description
.ref();
174 if (m_opaque_sp
.get()) {
175 if (m_opaque_sp
->GetIntegerType()->GetDescription(strm
,
176 description_level
)) {
177 strm
.Printf(" %s", m_opaque_sp
->GetName().GetCString());
180 strm
.PutCString("No value");