[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / lldb / source / API / SBTypeFormat.cpp
blob6024631e7054fbcbe2b8d25f4129d3a5b924b2d5
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 //===----------------------------------------------------------------------===//
10 #include "lldb/API/SBTypeFormat.h"
11 #include "SBReproducerPrivate.h"
13 #include "lldb/API/SBStream.h"
15 #include "lldb/DataFormatters/DataVisualization.h"
17 using namespace lldb;
18 using namespace lldb_private;
20 SBTypeFormat::SBTypeFormat() : m_opaque_sp() {
21 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTypeFormat);
24 SBTypeFormat::SBTypeFormat(lldb::Format format, uint32_t options)
25 : m_opaque_sp(
26 TypeFormatImplSP(new TypeFormatImpl_Format(format, options))) {
27 LLDB_RECORD_CONSTRUCTOR(SBTypeFormat, (lldb::Format, uint32_t), format,
28 options);
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);
38 SBTypeFormat::SBTypeFormat(const lldb::SBTypeFormat &rhs)
39 : m_opaque_sp(rhs.m_opaque_sp) {
40 LLDB_RECORD_CONSTRUCTOR(SBTypeFormat, (const lldb::SBTypeFormat &), rhs);
43 SBTypeFormat::~SBTypeFormat() {}
45 bool SBTypeFormat::IsValid() const {
46 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeFormat, IsValid);
47 return this->operator bool();
49 SBTypeFormat::operator bool() const {
50 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeFormat, operator bool);
52 return m_opaque_sp.get() != nullptr;
55 lldb::Format SBTypeFormat::GetFormat() {
56 LLDB_RECORD_METHOD_NO_ARGS(lldb::Format, SBTypeFormat, GetFormat);
58 if (IsValid() && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat)
59 return ((TypeFormatImpl_Format *)m_opaque_sp.get())->GetFormat();
60 return lldb::eFormatInvalid;
63 const char *SBTypeFormat::GetTypeName() {
64 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeFormat, GetTypeName);
66 if (IsValid() && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeEnum)
67 return ((TypeFormatImpl_EnumType *)m_opaque_sp.get())
68 ->GetTypeName()
69 .AsCString("");
70 return "";
73 uint32_t SBTypeFormat::GetOptions() {
74 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeFormat, GetOptions);
76 if (IsValid())
77 return m_opaque_sp->GetOptions();
78 return 0;
81 void SBTypeFormat::SetFormat(lldb::Format fmt) {
82 LLDB_RECORD_METHOD(void, SBTypeFormat, SetFormat, (lldb::Format), fmt);
84 if (CopyOnWrite_Impl(Type::eTypeFormat))
85 ((TypeFormatImpl_Format *)m_opaque_sp.get())->SetFormat(fmt);
88 void SBTypeFormat::SetTypeName(const char *type) {
89 LLDB_RECORD_METHOD(void, SBTypeFormat, SetTypeName, (const char *), type);
91 if (CopyOnWrite_Impl(Type::eTypeEnum))
92 ((TypeFormatImpl_EnumType *)m_opaque_sp.get())
93 ->SetTypeName(ConstString(type ? type : ""));
96 void SBTypeFormat::SetOptions(uint32_t value) {
97 LLDB_RECORD_METHOD(void, SBTypeFormat, SetOptions, (uint32_t), value);
99 if (CopyOnWrite_Impl(Type::eTypeKeepSame))
100 m_opaque_sp->SetOptions(value);
103 bool SBTypeFormat::GetDescription(lldb::SBStream &description,
104 lldb::DescriptionLevel description_level) {
105 LLDB_RECORD_METHOD(bool, SBTypeFormat, GetDescription,
106 (lldb::SBStream &, lldb::DescriptionLevel), description,
107 description_level);
109 if (!IsValid())
110 return false;
111 else {
112 description.Printf("%s\n", m_opaque_sp->GetDescription().c_str());
113 return true;
117 lldb::SBTypeFormat &SBTypeFormat::operator=(const lldb::SBTypeFormat &rhs) {
118 LLDB_RECORD_METHOD(lldb::SBTypeFormat &,
119 SBTypeFormat, operator=,(const lldb::SBTypeFormat &), rhs);
121 if (this != &rhs) {
122 m_opaque_sp = rhs.m_opaque_sp;
124 return LLDB_RECORD_RESULT(*this);
127 bool SBTypeFormat::operator==(lldb::SBTypeFormat &rhs) {
128 LLDB_RECORD_METHOD(bool, SBTypeFormat, operator==,(lldb::SBTypeFormat &),
129 rhs);
131 if (!IsValid())
132 return !rhs.IsValid();
133 return m_opaque_sp == rhs.m_opaque_sp;
136 bool SBTypeFormat::IsEqualTo(lldb::SBTypeFormat &rhs) {
137 LLDB_RECORD_METHOD(bool, SBTypeFormat, IsEqualTo, (lldb::SBTypeFormat &),
138 rhs);
140 if (!IsValid())
141 return !rhs.IsValid();
143 if (GetFormat() == rhs.GetFormat())
144 return GetOptions() == rhs.GetOptions();
145 else
146 return false;
149 bool SBTypeFormat::operator!=(lldb::SBTypeFormat &rhs) {
150 LLDB_RECORD_METHOD(bool, SBTypeFormat, operator!=,(lldb::SBTypeFormat &),
151 rhs);
153 if (!IsValid())
154 return !rhs.IsValid();
155 return m_opaque_sp != rhs.m_opaque_sp;
158 lldb::TypeFormatImplSP SBTypeFormat::GetSP() { return m_opaque_sp; }
160 void SBTypeFormat::SetSP(const lldb::TypeFormatImplSP &typeformat_impl_sp) {
161 m_opaque_sp = typeformat_impl_sp;
164 SBTypeFormat::SBTypeFormat(const lldb::TypeFormatImplSP &typeformat_impl_sp)
165 : m_opaque_sp(typeformat_impl_sp) {}
167 bool SBTypeFormat::CopyOnWrite_Impl(Type type) {
168 if (!IsValid())
169 return false;
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;
179 if (type == Type::eTypeKeepSame) {
180 if (m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat)
181 type = Type::eTypeFormat;
182 else
183 type = Type::eTypeEnum;
186 if (type == Type::eTypeFormat)
187 SetSP(
188 TypeFormatImplSP(new TypeFormatImpl_Format(GetFormat(), GetOptions())));
189 else
190 SetSP(TypeFormatImplSP(
191 new TypeFormatImpl_EnumType(ConstString(GetTypeName()), GetOptions())));
193 return true;
196 namespace lldb_private {
197 namespace repro {
199 template <>
200 void RegisterMethods<SBTypeFormat>(Registry &R) {
201 LLDB_REGISTER_CONSTRUCTOR(SBTypeFormat, ());
202 LLDB_REGISTER_CONSTRUCTOR(SBTypeFormat, (lldb::Format, uint32_t));
203 LLDB_REGISTER_CONSTRUCTOR(SBTypeFormat, (const char *, uint32_t));
204 LLDB_REGISTER_CONSTRUCTOR(SBTypeFormat, (const lldb::SBTypeFormat &));
205 LLDB_REGISTER_METHOD_CONST(bool, SBTypeFormat, IsValid, ());
206 LLDB_REGISTER_METHOD_CONST(bool, SBTypeFormat, operator bool, ());
207 LLDB_REGISTER_METHOD(lldb::Format, SBTypeFormat, GetFormat, ());
208 LLDB_REGISTER_METHOD(const char *, SBTypeFormat, GetTypeName, ());
209 LLDB_REGISTER_METHOD(uint32_t, SBTypeFormat, GetOptions, ());
210 LLDB_REGISTER_METHOD(void, SBTypeFormat, SetFormat, (lldb::Format));
211 LLDB_REGISTER_METHOD(void, SBTypeFormat, SetTypeName, (const char *));
212 LLDB_REGISTER_METHOD(void, SBTypeFormat, SetOptions, (uint32_t));
213 LLDB_REGISTER_METHOD(bool, SBTypeFormat, GetDescription,
214 (lldb::SBStream &, lldb::DescriptionLevel));
215 LLDB_REGISTER_METHOD(lldb::SBTypeFormat &,
216 SBTypeFormat, operator=,(const lldb::SBTypeFormat &));
217 LLDB_REGISTER_METHOD(bool, SBTypeFormat, operator==,(lldb::SBTypeFormat &));
218 LLDB_REGISTER_METHOD(bool, SBTypeFormat, IsEqualTo, (lldb::SBTypeFormat &));
219 LLDB_REGISTER_METHOD(bool, SBTypeFormat, operator!=,(lldb::SBTypeFormat &));