LLDB mainline
SBTypeEnumMember.cpp
Go to the documentation of this file.
1//===-- SBTypeEnumMember.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//===----------------------------------------------------------------------===//
8
10#include "Utils.h"
11#include "lldb/API/SBDefines.h"
12#include "lldb/API/SBStream.h"
13#include "lldb/API/SBType.h"
15#include "lldb/Symbol/Type.h"
17#include "lldb/Utility/Stream.h"
19
20#include <memory>
21
22using namespace lldb;
23using namespace lldb_private;
24
26
28
30 const lldb::TypeEnumMemberImplSP &enum_member_sp)
31 : m_opaque_sp(enum_member_sp) {}
32
38
40 LLDB_INSTRUMENT_VA(this, rhs);
41
42 if (this != &rhs)
44 return *this;
45}
46
49 return this->operator bool();
50}
51SBTypeEnumMember::operator bool() const {
53
54 return m_opaque_sp.get();
55}
56
59
60 if (m_opaque_sp.get())
61 return StringPool::GetSystemPool().Intern(m_opaque_sp->GetName());
62 return nullptr;
63}
64
67
68 if (m_opaque_sp.get())
69 return m_opaque_sp->GetValueAsSigned();
70 return 0;
71}
72
75
76 if (m_opaque_sp.get())
77 return m_opaque_sp->GetValueAsUnsigned();
78 return 0;
79}
80
83
84 SBType sb_type;
85 if (m_opaque_sp.get()) {
86 sb_type.SetSP(m_opaque_sp->GetIntegerType());
87 }
88 return sb_type;
89}
90
92 m_opaque_sp.reset(type_member_impl);
93}
94
96 if (m_opaque_sp.get() == nullptr)
97 m_opaque_sp = std::make_shared<TypeEnumMemberImpl>();
98 return *m_opaque_sp.get();
99}
100
102 return *m_opaque_sp.get();
103}
104
109
112 LLDB_INSTRUMENT_VA(this, rhs);
113
114 for (uint32_t i = 0,
115 rhs_size = const_cast<SBTypeEnumMemberList &>(rhs).GetSize();
116 i < rhs_size; i++)
118}
119
121 LLDB_INSTRUMENT_VA(this);
122 return this->operator bool();
123}
124SBTypeEnumMemberList::operator bool() const {
125 LLDB_INSTRUMENT_VA(this);
126
127 return (m_opaque_up != nullptr);
128}
129
132 LLDB_INSTRUMENT_VA(this, rhs);
133
134 if (this != &rhs) {
135 m_opaque_up = std::make_unique<TypeEnumMemberListImpl>();
136 for (uint32_t i = 0,
137 rhs_size = const_cast<SBTypeEnumMemberList &>(rhs).GetSize();
138 i < rhs_size; i++)
139 Append(
140 const_cast<SBTypeEnumMemberList &>(rhs).GetTypeEnumMemberAtIndex(i));
141 }
142 return *this;
143}
144
146 LLDB_INSTRUMENT_VA(this, enum_member);
147
148 if (enum_member.IsValid())
149 m_opaque_up->Append(enum_member.m_opaque_sp);
150}
151
154 LLDB_INSTRUMENT_VA(this, index);
155
156 if (m_opaque_up)
157 return SBTypeEnumMember(m_opaque_up->GetTypeEnumMemberAtIndex(index));
158 return SBTypeEnumMember();
159}
160
162 LLDB_INSTRUMENT_VA(this);
163
164 return m_opaque_up->GetSize();
165}
166
168
170 lldb::SBStream &description, lldb::DescriptionLevel description_level) {
171 LLDB_INSTRUMENT_VA(this, description, description_level);
172
173 Stream &strm = description.ref();
174
175 if (m_opaque_sp.get()) {
176 if (m_opaque_sp->GetIntegerType()->GetDescription(strm,
177 description_level)) {
178 strm.Printf(" %s", m_opaque_sp->GetName().GetCString());
179 }
180 } else {
181 strm.PutCString("No value");
182 }
183 return true;
184}
#define LLDB_INSTRUMENT_VA(...)
lldb_private::Stream & ref()
Definition SBStream.cpp:179
std::unique_ptr< lldb_private::TypeEnumMemberListImpl > m_opaque_up
SBTypeEnumMember GetTypeEnumMemberAtIndex(uint32_t index)
SBTypeEnumMemberList & operator=(const SBTypeEnumMemberList &rhs)
void Append(SBTypeEnumMember entry)
SBTypeEnumMember & operator=(const SBTypeEnumMember &rhs)
lldb::TypeEnumMemberImplSP m_opaque_sp
bool GetDescription(lldb::SBStream &description, lldb::DescriptionLevel description_level)
lldb_private::TypeEnumMemberImpl & ref()
void reset(lldb_private::TypeEnumMemberImpl *)
void SetSP(const lldb::TypeImplSP &type_impl_sp)
Definition SBType.cpp:85
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:63
const char * Intern(llvm::StringRef str) const
Definition StringPool.h:78
static StringPoolRef GetSystemPool()
The system pool. Only valid between Initialize and Terminate.
A class that represents a running process on the host machine.
std::unique_ptr< T > clone(const std::unique_ptr< T > &src)
Definition Utils.h:25
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
std::shared_ptr< lldb_private::TypeEnumMemberImpl > TypeEnumMemberImplSP
class LLDB_API SBTypeEnumMember
Definition SBDefines.h:126