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 
11 
12 #include "lldb/API/SBStream.h"
13 
15 
16 using namespace lldb;
17 using namespace lldb_private;
18 
20 
22  : m_opaque_sp(
23  TypeFormatImplSP(new TypeFormatImpl_Format(format, options))) {
24  LLDB_INSTRUMENT_VA(this, format, options);
25 }
26 
27 SBTypeFormat::SBTypeFormat(const char *type, uint32_t options)
28  : m_opaque_sp(TypeFormatImplSP(new TypeFormatImpl_EnumType(
29  ConstString(type ? type : ""), options))) {
30  LLDB_INSTRUMENT_VA(this, type, options);
31 }
32 
34  : m_opaque_sp(rhs.m_opaque_sp) {
35  LLDB_INSTRUMENT_VA(this, rhs);
36 }
37 
38 SBTypeFormat::~SBTypeFormat() = default;
39 
40 bool SBTypeFormat::IsValid() const {
41  LLDB_INSTRUMENT_VA(this);
42  return this->operator bool();
43 }
44 SBTypeFormat::operator bool() const {
45  LLDB_INSTRUMENT_VA(this);
46 
47  return m_opaque_sp.get() != nullptr;
48 }
49 
51  LLDB_INSTRUMENT_VA(this);
52 
53  if (IsValid() && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat)
54  return ((TypeFormatImpl_Format *)m_opaque_sp.get())->GetFormat();
55  return lldb::eFormatInvalid;
56 }
57 
59  LLDB_INSTRUMENT_VA(this);
60 
61  if (IsValid() && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeEnum)
62  return ((TypeFormatImpl_EnumType *)m_opaque_sp.get())
63  ->GetTypeName()
64  .AsCString("");
65  return "";
66 }
67 
69  LLDB_INSTRUMENT_VA(this);
70 
71  if (IsValid())
72  return m_opaque_sp->GetOptions();
73  return 0;
74 }
75 
77  LLDB_INSTRUMENT_VA(this, fmt);
78 
81 }
82 
83 void SBTypeFormat::SetTypeName(const char *type) {
84  LLDB_INSTRUMENT_VA(this, type);
85 
88  ->SetTypeName(ConstString(type ? type : ""));
89 }
90 
92  LLDB_INSTRUMENT_VA(this, value);
93 
95  m_opaque_sp->SetOptions(value);
96 }
97 
99  lldb::DescriptionLevel description_level) {
100  LLDB_INSTRUMENT_VA(this, description, description_level);
101 
102  if (!IsValid())
103  return false;
104  else {
105  description.Printf("%s\n", m_opaque_sp->GetDescription().c_str());
106  return true;
107  }
108 }
109 
111  LLDB_INSTRUMENT_VA(this, rhs);
112 
113  if (this != &rhs) {
114  m_opaque_sp = rhs.m_opaque_sp;
115  }
116  return *this;
117 }
118 
120  LLDB_INSTRUMENT_VA(this, rhs);
121 
122  if (!IsValid())
123  return !rhs.IsValid();
124  return m_opaque_sp == rhs.m_opaque_sp;
125 }
126 
128  LLDB_INSTRUMENT_VA(this, rhs);
129 
130  if (!IsValid())
131  return !rhs.IsValid();
132 
133  if (GetFormat() == rhs.GetFormat())
134  return GetOptions() == rhs.GetOptions();
135  else
136  return false;
137 }
138 
140  LLDB_INSTRUMENT_VA(this, rhs);
141 
142  if (!IsValid())
143  return !rhs.IsValid();
144  return m_opaque_sp != rhs.m_opaque_sp;
145 }
146 
147 lldb::TypeFormatImplSP SBTypeFormat::GetSP() { return m_opaque_sp; }
148 
149 void SBTypeFormat::SetSP(const lldb::TypeFormatImplSP &typeformat_impl_sp) {
150  m_opaque_sp = typeformat_impl_sp;
151 }
152 
153 SBTypeFormat::SBTypeFormat(const lldb::TypeFormatImplSP &typeformat_impl_sp)
154  : m_opaque_sp(typeformat_impl_sp) {}
155 
157  if (!IsValid())
158  return false;
159 
160  if (m_opaque_sp.unique() &&
161  ((type == Type::eTypeKeepSame) ||
162  (type == Type::eTypeFormat &&
163  m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat) ||
164  (type == Type::eTypeEnum &&
165  m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeEnum)))
166  return true;
167 
168  if (type == Type::eTypeKeepSame) {
169  if (m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat)
170  type = Type::eTypeFormat;
171  else
172  type = Type::eTypeEnum;
173  }
174 
175  if (type == Type::eTypeFormat)
176  SetSP(
177  TypeFormatImplSP(new TypeFormatImpl_Format(GetFormat(), GetOptions())));
178  else
179  SetSP(TypeFormatImplSP(
181 
182  return true;
183 }
Instrumentation.h
lldb::SBTypeFormat::SetTypeName
void SetTypeName(const char *)
Definition: SBTypeFormat.cpp:83
lldb::SBTypeFormat::operator==
bool operator==(lldb::SBTypeFormat &rhs)
Definition: SBTypeFormat.cpp:119
lldb::SBTypeFormat::GetOptions
uint32_t GetOptions()
Definition: SBTypeFormat.cpp:68
lldb::SBStream::Printf
void Printf(const char *format,...) __attribute__((format(printf
Definition: SBStream.cpp:70
lldb::Format
Format
Display format definitions.
Definition: lldb-enumerations.h:155
lldb::SBTypeFormat::SetOptions
void SetOptions(uint32_t)
Definition: SBTypeFormat.cpp:91
lldb::SBTypeFormat::m_opaque_sp
lldb::TypeFormatImplSP m_opaque_sp
Definition: SBTypeFormat.h:67
lldb::SBTypeFormat::~SBTypeFormat
~SBTypeFormat()
lldb::SBTypeFormat::Type::eTypeEnum
@ eTypeEnum
lldb::SBTypeFormat::GetFormat
lldb::Format GetFormat()
Definition: SBTypeFormat.cpp:50
SBStream.h
lldb::SBTypeFormat::CopyOnWrite_Impl
bool CopyOnWrite_Impl(Type)
Definition: SBTypeFormat.cpp:156
lldb::SBTypeFormat::SBTypeFormat
SBTypeFormat()
Definition: SBTypeFormat.cpp:19
lldb::SBTypeFormat::SetFormat
void SetFormat(lldb::Format)
Definition: SBTypeFormat.cpp:76
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:149
lldb_private::TypeFormatImpl_EnumType
Definition: TypeFormat.h:189
lldb::SBTypeFormat::operator=
lldb::SBTypeFormat & operator=(const lldb::SBTypeFormat &rhs)
Definition: SBTypeFormat.cpp:110
DataVisualization.h
uint32_t
lldb::SBTypeFormat::operator!=
bool operator!=(lldb::SBTypeFormat &rhs)
Definition: SBTypeFormat.cpp:139
lldb::SBTypeFormat::IsEqualTo
bool IsEqualTo(lldb::SBTypeFormat &rhs)
Definition: SBTypeFormat.cpp:127
lldb::SBTypeFormat::Type
Type
Definition: SBTypeFormat.h:71
lldb::SBTypeFormat::GetSP
lldb::TypeFormatImplSP GetSP()
Definition: SBTypeFormat.cpp:147
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_INSTRUMENT_VA
#define LLDB_INSTRUMENT_VA(...)
Definition: Instrumentation.h:98
lldb::SBStream
Definition: SBStream.h:18
lldb::SBTypeFormat::GetTypeName
const char * GetTypeName()
Definition: SBTypeFormat.cpp:58
lldb::SBTypeFormat::IsValid
bool IsValid() const
Definition: SBTypeFormat.cpp:40
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:98
lldb::eFormatInvalid
@ eFormatInvalid
Definition: lldb-enumerations.h:157