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"
18 
19 #include <memory>
20 
21 using namespace lldb;
22 using namespace lldb_private;
23 
25 
27 
29  const lldb::TypeEnumMemberImplSP &enum_member_sp)
30  : m_opaque_sp(enum_member_sp) {}
31 
33  LLDB_INSTRUMENT_VA(this, rhs);
34 
36 }
37 
39  LLDB_INSTRUMENT_VA(this, rhs);
40 
41  if (this != &rhs)
43  return *this;
44 }
45 
47  LLDB_INSTRUMENT_VA(this);
48  return this->operator bool();
49 }
50 SBTypeEnumMember::operator bool() const {
51  LLDB_INSTRUMENT_VA(this);
52 
53  return m_opaque_sp.get();
54 }
55 
57  LLDB_INSTRUMENT_VA(this);
58 
59  if (m_opaque_sp.get())
60  return m_opaque_sp->GetName().GetCString();
61  return nullptr;
62 }
63 
65  LLDB_INSTRUMENT_VA(this);
66 
67  if (m_opaque_sp.get())
68  return m_opaque_sp->GetValueAsSigned();
69  return 0;
70 }
71 
73  LLDB_INSTRUMENT_VA(this);
74 
75  if (m_opaque_sp.get())
76  return m_opaque_sp->GetValueAsUnsigned();
77  return 0;
78 }
79 
81  LLDB_INSTRUMENT_VA(this);
82 
83  SBType sb_type;
84  if (m_opaque_sp.get()) {
85  sb_type.SetSP(m_opaque_sp->GetIntegerType());
86  }
87  return sb_type;
88 }
89 
91  m_opaque_sp.reset(type_member_impl);
92 }
93 
95  if (m_opaque_sp.get() == nullptr)
96  m_opaque_sp = std::make_shared<TypeEnumMemberImpl>();
97  return *m_opaque_sp.get();
98 }
99 
101  return *m_opaque_sp.get();
102 }
103 
105  : m_opaque_up(new TypeEnumMemberListImpl()) {
106  LLDB_INSTRUMENT_VA(this);
107 }
108 
110  : m_opaque_up(new TypeEnumMemberListImpl()) {
111  LLDB_INSTRUMENT_VA(this, rhs);
112 
113  for (uint32_t i = 0,
114  rhs_size = const_cast<SBTypeEnumMemberList &>(rhs).GetSize();
115  i < rhs_size; i++)
117 }
118 
120  LLDB_INSTRUMENT_VA(this);
121  return this->operator bool();
122 }
123 SBTypeEnumMemberList::operator bool() const {
124  LLDB_INSTRUMENT_VA(this);
125 
126  return (m_opaque_up != nullptr);
127 }
128 
131  LLDB_INSTRUMENT_VA(this, rhs);
132 
133  if (this != &rhs) {
134  m_opaque_up = std::make_unique<TypeEnumMemberListImpl>();
135  for (uint32_t i = 0,
136  rhs_size = const_cast<SBTypeEnumMemberList &>(rhs).GetSize();
137  i < rhs_size; i++)
138  Append(
139  const_cast<SBTypeEnumMemberList &>(rhs).GetTypeEnumMemberAtIndex(i));
140  }
141  return *this;
142 }
143 
145  LLDB_INSTRUMENT_VA(this, enum_member);
146 
147  if (enum_member.IsValid())
148  m_opaque_up->Append(enum_member.m_opaque_sp);
149 }
150 
153  LLDB_INSTRUMENT_VA(this, index);
154 
155  if (m_opaque_up)
156  return SBTypeEnumMember(m_opaque_up->GetTypeEnumMemberAtIndex(index));
157  return SBTypeEnumMember();
158 }
159 
161  LLDB_INSTRUMENT_VA(this);
162 
163  return m_opaque_up->GetSize();
164 }
165 
167 
169  lldb::SBStream &description, lldb::DescriptionLevel description_level) {
170  LLDB_INSTRUMENT_VA(this, description, description_level);
171 
172  Stream &strm = description.ref();
173 
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());
178  }
179  } else {
180  strm.PutCString("No value");
181  }
182  return true;
183 }
Instrumentation.h
lldb::SBStream::ref
lldb_private::Stream & ref()
Definition: SBStream.cpp:176
lldb_private::TypeEnumMemberImpl
Definition: Type.h:475
SBDefines.h
lldb::SBTypeEnumMemberList
Definition: SBTypeEnumMember.h:57
lldb::SBTypeEnumMember::IsValid
bool IsValid() const
Definition: SBTypeEnumMember.cpp:46
lldb::SBTypeEnumMemberList::m_opaque_up
std::unique_ptr< lldb_private::TypeEnumMemberListImpl > m_opaque_up
Definition: SBTypeEnumMember.h:78
lldb::SBTypeEnumMemberList::operator=
SBTypeEnumMemberList & operator=(const SBTypeEnumMemberList &rhs)
Definition: SBTypeEnumMember.cpp:130
SBTypeEnumMember.h
lldb_private::Stream
Definition: Stream.h:28
SBStream.h
lldb::SBTypeEnumMember::GetValueAsUnsigned
uint64_t GetValueAsUnsigned()
Definition: SBTypeEnumMember.cpp:72
lldb_private::clone
std::unique_ptr< T > clone(const std::unique_ptr< T > &src)
Definition: Utils.h:17
lldb::SBTypeEnumMemberList::IsValid
bool IsValid()
Definition: SBTypeEnumMember.cpp:119
Utils.h
lldb::SBTypeEnumMember::GetDescription
bool GetDescription(lldb::SBStream &description, lldb::DescriptionLevel description_level)
Definition: SBTypeEnumMember.cpp:168
lldb::SBTypeEnumMemberList::GetTypeEnumMemberAtIndex
SBTypeEnumMember GetTypeEnumMemberAtIndex(uint32_t index)
Definition: SBTypeEnumMember.cpp:152
Type.h
lldb::SBTypeEnumMember::GetName
const char * GetName()
Definition: SBTypeEnumMember.cpp:56
lldb::SBTypeEnumMember
class LLDB_API SBTypeEnumMember
Definition: SBDefines.h:93
lldb::SBTypeEnumMember::GetType
lldb::SBType GetType()
Definition: SBTypeEnumMember.cpp:80
lldb::SBTypeEnumMember::operator=
SBTypeEnumMember & operator=(const SBTypeEnumMember &rhs)
Definition: SBTypeEnumMember.cpp:38
CompilerType.h
lldb::SBType
Definition: SBType.h:104
SBType.h
lldb::SBTypeEnumMember::reset
void reset(lldb_private::TypeEnumMemberImpl *)
Definition: SBTypeEnumMember.cpp:90
lldb::SBTypeEnumMember::ref
lldb_private::TypeEnumMemberImpl & ref()
Definition: SBTypeEnumMember.cpp:94
lldb::SBTypeEnumMemberList::Append
void Append(SBTypeEnumMember entry)
Definition: SBTypeEnumMember.cpp:144
lldb::SBTypeEnumMember::SBTypeEnumMember
SBTypeEnumMember()
Definition: SBTypeEnumMember.cpp:24
lldb_private::TypeEnumMemberListImpl
Definition: Type.h:503
uint32_t
lldb::SBTypeEnumMemberList::~SBTypeEnumMemberList
~SBTypeEnumMemberList()
lldb::SBTypeEnumMemberList::SBTypeEnumMemberList
SBTypeEnumMemberList()
Definition: SBTypeEnumMember.cpp:104
lldb::SBTypeEnumMember::m_opaque_sp
lldb::TypeEnumMemberImplSP m_opaque_sp
Definition: SBTypeEnumMember.h:52
lldb::SBTypeEnumMemberList::GetSize
uint32_t GetSize()
Definition: SBTypeEnumMember.cpp:160
lldb::SBTypeEnumMember::GetValueAsSigned
int64_t GetValueAsSigned()
Definition: SBTypeEnumMember.cpp:64
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
LLDB_INSTRUMENT_VA
#define LLDB_INSTRUMENT_VA(...)
Definition: Instrumentation.h:98
Stream.h
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
lldb::SBStream
Definition: SBStream.h:18
lldb::SBTypeEnumMember::~SBTypeEnumMember
~SBTypeEnumMember()
lldb
Definition: SBAddress.h:15
lldb::SBType::SetSP
void SetSP(const lldb::TypeImplSP &type_impl_sp)
Definition: SBType.cpp:79
lldb::SBTypeEnumMember
Definition: SBTypeEnumMember.h:17
lldb::DescriptionLevel
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
Definition: lldb-enumerations.h:207