LLDB  mainline
SBTypeFormat.cpp
Go to the documentation of this file.
1 //===-- SBTypeFormat.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 "SBReproducerPrivate.h"
11 
12 #include "lldb/API/SBStream.h"
13 
15 
16 using namespace lldb;
17 using namespace lldb_private;
18 
19 SBTypeFormat::SBTypeFormat() : m_opaque_sp() {
21 }
22 
24  : m_opaque_sp(
25  TypeFormatImplSP(new TypeFormatImpl_Format(format, options))) {
27  options);
28 }
29 
30 SBTypeFormat::SBTypeFormat(const char *type, uint32_t options)
31  : m_opaque_sp(TypeFormatImplSP(new TypeFormatImpl_EnumType(
32  ConstString(type ? type : ""), options))) {
33  LLDB_RECORD_CONSTRUCTOR(SBTypeFormat, (const char *, uint32_t), type,
34  options);
35 }
36 
38  : m_opaque_sp(rhs.m_opaque_sp) {
40 }
41 
42 SBTypeFormat::~SBTypeFormat() = default;
43 
44 bool SBTypeFormat::IsValid() const {
46  return this->operator bool();
47 }
48 SBTypeFormat::operator bool() const {
49  LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeFormat, operator bool);
50 
51  return m_opaque_sp.get() != nullptr;
52 }
53 
56 
57  if (IsValid() && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat)
58  return ((TypeFormatImpl_Format *)m_opaque_sp.get())->GetFormat();
59  return lldb::eFormatInvalid;
60 }
61 
64 
65  if (IsValid() && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeEnum)
66  return ((TypeFormatImpl_EnumType *)m_opaque_sp.get())
67  ->GetTypeName()
68  .AsCString("");
69  return "";
70 }
71 
74 
75  if (IsValid())
76  return m_opaque_sp->GetOptions();
77  return 0;
78 }
79 
82 
85 }
86 
87 void SBTypeFormat::SetTypeName(const char *type) {
88  LLDB_RECORD_METHOD(void, SBTypeFormat, SetTypeName, (const char *), type);
89 
92  ->SetTypeName(ConstString(type ? type : ""));
93 }
94 
97 
99  m_opaque_sp->SetOptions(value);
100 }
101 
103  lldb::DescriptionLevel description_level) {
105  (lldb::SBStream &, lldb::DescriptionLevel), description,
106  description_level);
107 
108  if (!IsValid())
109  return false;
110  else {
111  description.Printf("%s\n", m_opaque_sp->GetDescription().c_str());
112  return true;
113  }
114 }
115 
118  SBTypeFormat, operator=,(const lldb::SBTypeFormat &), rhs);
119 
120  if (this != &rhs) {
121  m_opaque_sp = rhs.m_opaque_sp;
122  }
123  return LLDB_RECORD_RESULT(*this);
124 }
125 
127  LLDB_RECORD_METHOD(bool, SBTypeFormat, operator==,(lldb::SBTypeFormat &),
128  rhs);
129 
130  if (!IsValid())
131  return !rhs.IsValid();
132  return m_opaque_sp == rhs.m_opaque_sp;
133 }
134 
137  rhs);
138 
139  if (!IsValid())
140  return !rhs.IsValid();
141 
142  if (GetFormat() == rhs.GetFormat())
143  return GetOptions() == rhs.GetOptions();
144  else
145  return false;
146 }
147 
149  LLDB_RECORD_METHOD(bool, SBTypeFormat, operator!=,(lldb::SBTypeFormat &),
150  rhs);
151 
152  if (!IsValid())
153  return !rhs.IsValid();
154  return m_opaque_sp != rhs.m_opaque_sp;
155 }
156 
157 lldb::TypeFormatImplSP SBTypeFormat::GetSP() { return m_opaque_sp; }
158 
159 void SBTypeFormat::SetSP(const lldb::TypeFormatImplSP &typeformat_impl_sp) {
160  m_opaque_sp = typeformat_impl_sp;
161 }
162 
163 SBTypeFormat::SBTypeFormat(const lldb::TypeFormatImplSP &typeformat_impl_sp)
164  : m_opaque_sp(typeformat_impl_sp) {}
165 
167  if (!IsValid())
168  return false;
169 
170  if (m_opaque_sp.unique() &&
171  ((type == Type::eTypeKeepSame) ||
172  (type == Type::eTypeFormat &&
173  m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat) ||
174  (type == Type::eTypeEnum &&
175  m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeEnum)))
176  return true;
177 
178  if (type == Type::eTypeKeepSame) {
179  if (m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat)
180  type = Type::eTypeFormat;
181  else
182  type = Type::eTypeEnum;
183  }
184 
185  if (type == Type::eTypeFormat)
186  SetSP(
187  TypeFormatImplSP(new TypeFormatImpl_Format(GetFormat(), GetOptions())));
188  else
189  SetSP(TypeFormatImplSP(
191 
192  return true;
193 }
194 
195 namespace lldb_private {
196 namespace repro {
197 
198 template <>
205  LLDB_REGISTER_METHOD_CONST(bool, SBTypeFormat, operator bool, ());
207  LLDB_REGISTER_METHOD(const char *, SBTypeFormat, GetTypeName, ());
210  LLDB_REGISTER_METHOD(void, SBTypeFormat, SetTypeName, (const char *));
215  SBTypeFormat, operator=,(const lldb::SBTypeFormat &));
219 }
220 
221 }
222 }
The registry contains a unique mapping between functions and their ID.
lldb::Format GetFormat()
A class that represents a running process on the host machine.
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
bool CopyOnWrite_Impl(Type)
lldb::TypeFormatImplSP GetSP()
void SetTypeName(const char *)
lldb::SBTypeFormat & operator=(const lldb::SBTypeFormat &rhs)
bool operator!=(lldb::SBTypeFormat &rhs)
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
Format
Display format definitions.
void RegisterMethods< SBTypeFormat >(Registry &R)
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method)
bool GetDescription(lldb::SBStream &description, lldb::DescriptionLevel description_level)
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
void Printf(const char *format,...) __attribute__((format(printf
Definition: SBStream.cpp:69
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
void SetOptions(uint32_t)
bool IsEqualTo(lldb::SBTypeFormat &rhs)
A uniqued constant string class.
Definition: ConstString.h:40
Definition: SBAddress.h:15
void SetSP(const lldb::TypeFormatImplSP &typeformat_impl_sp)
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
void SetFormat(lldb::Format)
bool IsValid() const
bool operator==(lldb::SBTypeFormat &rhs)
lldb::TypeFormatImplSP m_opaque_sp
Definition: SBTypeFormat.h:67
#define LLDB_RECORD_RESULT(Result)
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)
uint32_t GetOptions()
const char * GetTypeName()