LLDB  mainline
SBTypeFormat.cpp
Go to the documentation of this file.
1 //===-- SBTypeFormat.cpp ------------------------------------------*- C++
2 //-*-===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "lldb/API/SBTypeFormat.h"
11 #include "SBReproducerPrivate.h"
12 
13 #include "lldb/API/SBStream.h"
14 
16 
17 using namespace lldb;
18 using namespace lldb_private;
19 
20 SBTypeFormat::SBTypeFormat() : m_opaque_sp() {
22 }
23 
25  : m_opaque_sp(
26  TypeFormatImplSP(new TypeFormatImpl_Format(format, options))) {
28  options);
29 }
30 
31 SBTypeFormat::SBTypeFormat(const char *type, uint32_t options)
32  : m_opaque_sp(TypeFormatImplSP(new TypeFormatImpl_EnumType(
33  ConstString(type ? type : ""), options))) {
34  LLDB_RECORD_CONSTRUCTOR(SBTypeFormat, (const char *, uint32_t), type,
35  options);
36 }
37 
39  : m_opaque_sp(rhs.m_opaque_sp) {
41 }
42 
44 
45 bool SBTypeFormat::IsValid() const {
47  return this->operator bool();
48 }
49 SBTypeFormat::operator bool() const {
50  LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeFormat, operator bool);
51 
52  return m_opaque_sp.get() != NULL;
53 }
54 
57 
58  if (IsValid() && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat)
59  return ((TypeFormatImpl_Format *)m_opaque_sp.get())->GetFormat();
60  return lldb::eFormatInvalid;
61 }
62 
65 
66  if (IsValid() && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeEnum)
67  return ((TypeFormatImpl_EnumType *)m_opaque_sp.get())
68  ->GetTypeName()
69  .AsCString("");
70  return "";
71 }
72 
75 
76  if (IsValid())
77  return m_opaque_sp->GetOptions();
78  return 0;
79 }
80 
83 
86 }
87 
88 void SBTypeFormat::SetTypeName(const char *type) {
89  LLDB_RECORD_METHOD(void, SBTypeFormat, SetTypeName, (const char *), type);
90 
93  ->SetTypeName(ConstString(type ? type : ""));
94 }
95 
98 
100  m_opaque_sp->SetOptions(value);
101 }
102 
104  lldb::DescriptionLevel description_level) {
106  (lldb::SBStream &, lldb::DescriptionLevel), description,
107  description_level);
108 
109  if (!IsValid())
110  return false;
111  else {
112  description.Printf("%s\n", m_opaque_sp->GetDescription().c_str());
113  return true;
114  }
115 }
116 
119  SBTypeFormat, operator=,(const lldb::SBTypeFormat &), rhs);
120 
121  if (this != &rhs) {
122  m_opaque_sp = rhs.m_opaque_sp;
123  }
124  return LLDB_RECORD_RESULT(*this);
125 }
126 
128  LLDB_RECORD_METHOD(bool, SBTypeFormat, operator==,(lldb::SBTypeFormat &),
129  rhs);
130 
131  if (!IsValid())
132  return !rhs.IsValid();
133  return m_opaque_sp == rhs.m_opaque_sp;
134 }
135 
138  rhs);
139 
140  if (!IsValid())
141  return !rhs.IsValid();
142 
143  if (GetFormat() == rhs.GetFormat())
144  return GetOptions() == rhs.GetOptions();
145  else
146  return false;
147 }
148 
150  LLDB_RECORD_METHOD(bool, SBTypeFormat, operator!=,(lldb::SBTypeFormat &),
151  rhs);
152 
153  if (!IsValid())
154  return !rhs.IsValid();
155  return m_opaque_sp != rhs.m_opaque_sp;
156 }
157 
158 lldb::TypeFormatImplSP SBTypeFormat::GetSP() { return m_opaque_sp; }
159 
160 void SBTypeFormat::SetSP(const lldb::TypeFormatImplSP &typeformat_impl_sp) {
161  m_opaque_sp = typeformat_impl_sp;
162 }
163 
164 SBTypeFormat::SBTypeFormat(const lldb::TypeFormatImplSP &typeformat_impl_sp)
165  : m_opaque_sp(typeformat_impl_sp) {}
166 
168  if (!IsValid())
169  return false;
170 
171  if (m_opaque_sp.unique() &&
172  ((type == Type::eTypeKeepSame) ||
173  (type == Type::eTypeFormat &&
174  m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat) ||
175  (type == Type::eTypeEnum &&
176  m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeEnum)))
177  return true;
178 
179  if (type == Type::eTypeKeepSame) {
180  if (m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat)
181  type = Type::eTypeFormat;
182  else
183  type = Type::eTypeEnum;
184  }
185 
186  if (type == Type::eTypeFormat)
187  SetSP(
188  TypeFormatImplSP(new TypeFormatImpl_Format(GetFormat(), GetOptions())));
189  else
190  SetSP(TypeFormatImplSP(
192 
193  return true;
194 }
195 
196 namespace lldb_private {
197 namespace repro {
198 
199 template <>
206  LLDB_REGISTER_METHOD_CONST(bool, SBTypeFormat, operator bool, ());
208  LLDB_REGISTER_METHOD(const char *, SBTypeFormat, GetTypeName, ());
211  LLDB_REGISTER_METHOD(void, SBTypeFormat, SetTypeName, (const char *));
216  SBTypeFormat, operator=,(const lldb::SBTypeFormat &));
220 }
221 
222 }
223 }
The registry contains a unique mapping between functions and their ID.
lldb::Format GetFormat()
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
#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)
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:62
#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:38
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()