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 <>
204  LLDB_REGISTER_METHOD_CONST(bool, SBTypeFormat, IsValid, ());
205  LLDB_REGISTER_METHOD_CONST(bool, SBTypeFormat, operator bool, ());
207  LLDB_REGISTER_METHOD(const char *, SBTypeFormat, GetTypeName, ());
208  LLDB_REGISTER_METHOD(uint32_t, SBTypeFormat, GetOptions, ());
209  LLDB_REGISTER_METHOD(void, SBTypeFormat, SetFormat, (lldb::Format));
210  LLDB_REGISTER_METHOD(void, SBTypeFormat, SetTypeName, (const char *));
211  LLDB_REGISTER_METHOD(void, SBTypeFormat, SetOptions, (uint32_t));
212  LLDB_REGISTER_METHOD(bool, SBTypeFormat, GetDescription,
215  SBTypeFormat, operator=,(const lldb::SBTypeFormat &));
219 }
220 
221 }
222 }
lldb::SBTypeFormat::SetTypeName
void SetTypeName(const char *)
Definition: SBTypeFormat.cpp:87
lldb::SBTypeFormat::operator==
bool operator==(lldb::SBTypeFormat &rhs)
Definition: SBTypeFormat.cpp:126
lldb::SBTypeFormat::GetOptions
uint32_t GetOptions()
Definition: SBTypeFormat.cpp:72
lldb::SBStream::Printf
void Printf(const char *format,...) __attribute__((format(printf
Definition: SBStream.cpp:69
lldb::Format
Format
Display format definitions.
Definition: lldb-enumerations.h:155
lldb::SBTypeFormat::SetOptions
void SetOptions(uint32_t)
Definition: SBTypeFormat.cpp:95
LLDB_RECORD_RESULT
#define LLDB_RECORD_RESULT(Result)
Definition: ReproducerInstrumentation.h:211
LLDB_RECORD_METHOD_CONST_NO_ARGS
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:168
lldb::SBTypeFormat::m_opaque_sp
lldb::TypeFormatImplSP m_opaque_sp
Definition: SBTypeFormat.h:67
lldb_private::repro::RegisterMethods< SBTypeFormat >
void RegisterMethods< SBTypeFormat >(Registry &R)
Definition: SBTypeFormat.cpp:199
LLDB_RECORD_METHOD_NO_ARGS
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:165
LLDB_RECORD_CONSTRUCTOR_NO_ARGS
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
Definition: ReproducerInstrumentation.h:136
LLDB_REGISTER_METHOD_CONST
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:98
lldb::SBTypeFormat::~SBTypeFormat
~SBTypeFormat()
SBReproducerPrivate.h
LLDB_REGISTER_CONSTRUCTOR
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
Definition: ReproducerInstrumentation.h:89
lldb::SBTypeFormat::Type::eTypeEnum
@ eTypeEnum
lldb::SBTypeFormat::GetFormat
lldb::Format GetFormat()
Definition: SBTypeFormat.cpp:54
SBStream.h
LLDB_RECORD_METHOD
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:158
lldb::SBTypeFormat::CopyOnWrite_Impl
bool CopyOnWrite_Impl(Type)
Definition: SBTypeFormat.cpp:166
lldb::SBTypeFormat::SBTypeFormat
SBTypeFormat()
Definition: SBTypeFormat.cpp:19
lldb::SBTypeFormat::SetFormat
void SetFormat(lldb::Format)
Definition: SBTypeFormat.cpp:80
lldb::SBTypeFormat
Definition: SBTypeFormat.h:17
lldb_private::ConstString
Definition: ConstString.h:40
lldb::SBTypeFormat::Type::eTypeKeepSame
@ eTypeKeepSame
lldb::SBTypeFormat::SetSP
void SetSP(const lldb::TypeFormatImplSP &typeformat_impl_sp)
Definition: SBTypeFormat.cpp:159
lldb_private::TypeFormatImpl_EnumType
Definition: TypeFormat.h:189
lldb::SBTypeFormat::operator=
lldb::SBTypeFormat & operator=(const lldb::SBTypeFormat &rhs)
Definition: SBTypeFormat.cpp:116
LLDB_RECORD_CONSTRUCTOR
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
Definition: ReproducerInstrumentation.h:133
lldb_private::repro::Registry
The registry contains a unique mapping between functions and their ID.
Definition: ReproducerInstrumentation.h:517
DataVisualization.h
uint32_t
lldb::SBTypeFormat::operator!=
bool operator!=(lldb::SBTypeFormat &rhs)
Definition: SBTypeFormat.cpp:148
lldb::SBTypeFormat::IsEqualTo
bool IsEqualTo(lldb::SBTypeFormat &rhs)
Definition: SBTypeFormat.cpp:135
lldb::SBTypeFormat::Type
Type
Definition: SBTypeFormat.h:71
lldb::SBTypeFormat::GetSP
lldb::TypeFormatImplSP GetSP()
Definition: SBTypeFormat.cpp:157
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
SBTypeFormat.h
lldb_private::TypeFormatImpl_Format
Definition: TypeFormat.h:159
lldb::SBStream
Definition: SBStream.h:18
lldb::SBTypeFormat::GetTypeName
const char * GetTypeName()
Definition: SBTypeFormat.cpp:62
lldb::SBTypeFormat::IsValid
bool IsValid() const
Definition: SBTypeFormat.cpp:44
lldb
Definition: SBAddress.h:15
lldb::SBTypeFormat::Type::eTypeFormat
@ eTypeFormat
lldb::DescriptionLevel
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
Definition: lldb-enumerations.h:207
lldb::SBTypeFormat::GetDescription
bool GetDescription(lldb::SBStream &description, lldb::DescriptionLevel description_level)
Definition: SBTypeFormat.cpp:102
lldb::eFormatInvalid
@ eFormatInvalid
Definition: lldb-enumerations.h:157
LLDB_REGISTER_METHOD
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:93