[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / lldb / source / API / SBTypeSynthetic.cpp
blobdf6fce1269f099225edae83c60748f6d23ed7d65
1 //===-- SBTypeSynthetic.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/SBTypeSynthetic.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 SBTypeSynthetic::SBTypeSynthetic() : m_opaque_sp() {
21 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTypeSynthetic);
24 SBTypeSynthetic SBTypeSynthetic::CreateWithClassName(const char *data,
25 uint32_t options) {
26 LLDB_RECORD_STATIC_METHOD(lldb::SBTypeSynthetic, SBTypeSynthetic,
27 CreateWithClassName, (const char *, uint32_t), data,
28 options);
30 if (!data || data[0] == 0)
31 return LLDB_RECORD_RESULT(SBTypeSynthetic());
32 return LLDB_RECORD_RESULT(SBTypeSynthetic(ScriptedSyntheticChildrenSP(
33 new ScriptedSyntheticChildren(options, data, ""))));
36 SBTypeSynthetic SBTypeSynthetic::CreateWithScriptCode(const char *data,
37 uint32_t options) {
38 LLDB_RECORD_STATIC_METHOD(lldb::SBTypeSynthetic, SBTypeSynthetic,
39 CreateWithScriptCode, (const char *, uint32_t),
40 data, options);
42 if (!data || data[0] == 0)
43 return LLDB_RECORD_RESULT(SBTypeSynthetic());
44 return LLDB_RECORD_RESULT(SBTypeSynthetic(ScriptedSyntheticChildrenSP(
45 new ScriptedSyntheticChildren(options, "", data))));
48 SBTypeSynthetic::SBTypeSynthetic(const lldb::SBTypeSynthetic &rhs)
49 : m_opaque_sp(rhs.m_opaque_sp) {
50 LLDB_RECORD_CONSTRUCTOR(SBTypeSynthetic, (const lldb::SBTypeSynthetic &),
51 rhs);
54 SBTypeSynthetic::~SBTypeSynthetic() {}
56 bool SBTypeSynthetic::IsValid() const {
57 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeSynthetic, IsValid);
58 return this->operator bool();
60 SBTypeSynthetic::operator bool() const {
61 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeSynthetic, operator bool);
63 return m_opaque_sp.get() != nullptr;
66 bool SBTypeSynthetic::IsClassCode() {
67 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTypeSynthetic, IsClassCode);
69 if (!IsValid())
70 return false;
71 const char *code = m_opaque_sp->GetPythonCode();
72 return (code && *code);
75 bool SBTypeSynthetic::IsClassName() {
76 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTypeSynthetic, IsClassName);
78 if (!IsValid())
79 return false;
80 return !IsClassCode();
83 const char *SBTypeSynthetic::GetData() {
84 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeSynthetic, GetData);
86 if (!IsValid())
87 return nullptr;
88 if (IsClassCode())
89 return m_opaque_sp->GetPythonCode();
90 else
91 return m_opaque_sp->GetPythonClassName();
94 void SBTypeSynthetic::SetClassName(const char *data) {
95 LLDB_RECORD_METHOD(void, SBTypeSynthetic, SetClassName, (const char *), data);
97 if (IsValid() && data && *data)
98 m_opaque_sp->SetPythonClassName(data);
101 void SBTypeSynthetic::SetClassCode(const char *data) {
102 LLDB_RECORD_METHOD(void, SBTypeSynthetic, SetClassCode, (const char *), data);
104 if (IsValid() && data && *data)
105 m_opaque_sp->SetPythonCode(data);
108 uint32_t SBTypeSynthetic::GetOptions() {
109 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeSynthetic, GetOptions);
111 if (!IsValid())
112 return lldb::eTypeOptionNone;
113 return m_opaque_sp->GetOptions();
116 void SBTypeSynthetic::SetOptions(uint32_t value) {
117 LLDB_RECORD_METHOD(void, SBTypeSynthetic, SetOptions, (uint32_t), value);
119 if (!CopyOnWrite_Impl())
120 return;
121 m_opaque_sp->SetOptions(value);
124 bool SBTypeSynthetic::GetDescription(lldb::SBStream &description,
125 lldb::DescriptionLevel description_level) {
126 LLDB_RECORD_METHOD(bool, SBTypeSynthetic, GetDescription,
127 (lldb::SBStream &, lldb::DescriptionLevel), description,
128 description_level);
130 if (m_opaque_sp) {
131 description.Printf("%s\n", m_opaque_sp->GetDescription().c_str());
132 return true;
134 return false;
137 lldb::SBTypeSynthetic &SBTypeSynthetic::
138 operator=(const lldb::SBTypeSynthetic &rhs) {
139 LLDB_RECORD_METHOD(lldb::SBTypeSynthetic &,
140 SBTypeSynthetic, operator=,(const lldb::SBTypeSynthetic &),
141 rhs);
143 if (this != &rhs) {
144 m_opaque_sp = rhs.m_opaque_sp;
146 return LLDB_RECORD_RESULT(*this);
149 bool SBTypeSynthetic::operator==(lldb::SBTypeSynthetic &rhs) {
150 LLDB_RECORD_METHOD(
151 bool, SBTypeSynthetic, operator==,(lldb::SBTypeSynthetic &), rhs);
153 if (!IsValid())
154 return !rhs.IsValid();
155 return m_opaque_sp == rhs.m_opaque_sp;
158 bool SBTypeSynthetic::IsEqualTo(lldb::SBTypeSynthetic &rhs) {
159 LLDB_RECORD_METHOD(bool, SBTypeSynthetic, IsEqualTo,
160 (lldb::SBTypeSynthetic &), rhs);
162 if (!IsValid())
163 return !rhs.IsValid();
165 if (m_opaque_sp->IsScripted() != rhs.m_opaque_sp->IsScripted())
166 return false;
168 if (IsClassCode() != rhs.IsClassCode())
169 return false;
171 if (strcmp(GetData(), rhs.GetData()))
172 return false;
174 return GetOptions() == rhs.GetOptions();
177 bool SBTypeSynthetic::operator!=(lldb::SBTypeSynthetic &rhs) {
178 LLDB_RECORD_METHOD(
179 bool, SBTypeSynthetic, operator!=,(lldb::SBTypeSynthetic &), rhs);
181 if (!IsValid())
182 return !rhs.IsValid();
183 return m_opaque_sp != rhs.m_opaque_sp;
186 lldb::ScriptedSyntheticChildrenSP SBTypeSynthetic::GetSP() {
187 return m_opaque_sp;
190 void SBTypeSynthetic::SetSP(
191 const lldb::ScriptedSyntheticChildrenSP &TypeSynthetic_impl_sp) {
192 m_opaque_sp = TypeSynthetic_impl_sp;
195 SBTypeSynthetic::SBTypeSynthetic(
196 const lldb::ScriptedSyntheticChildrenSP &TypeSynthetic_impl_sp)
197 : m_opaque_sp(TypeSynthetic_impl_sp) {}
199 bool SBTypeSynthetic::CopyOnWrite_Impl() {
200 if (!IsValid())
201 return false;
202 if (m_opaque_sp.unique())
203 return true;
205 ScriptedSyntheticChildrenSP new_sp(new ScriptedSyntheticChildren(
206 m_opaque_sp->GetOptions(), m_opaque_sp->GetPythonClassName(),
207 m_opaque_sp->GetPythonCode()));
209 SetSP(new_sp);
211 return true;
214 namespace lldb_private {
215 namespace repro {
217 template <>
218 void RegisterMethods<SBTypeSynthetic>(Registry &R) {
219 LLDB_REGISTER_CONSTRUCTOR(SBTypeSynthetic, ());
220 LLDB_REGISTER_STATIC_METHOD(lldb::SBTypeSynthetic, SBTypeSynthetic,
221 CreateWithClassName, (const char *, uint32_t));
222 LLDB_REGISTER_STATIC_METHOD(lldb::SBTypeSynthetic, SBTypeSynthetic,
223 CreateWithScriptCode, (const char *, uint32_t));
224 LLDB_REGISTER_CONSTRUCTOR(SBTypeSynthetic, (const lldb::SBTypeSynthetic &));
225 LLDB_REGISTER_METHOD_CONST(bool, SBTypeSynthetic, IsValid, ());
226 LLDB_REGISTER_METHOD_CONST(bool, SBTypeSynthetic, operator bool, ());
227 LLDB_REGISTER_METHOD(bool, SBTypeSynthetic, IsClassCode, ());
228 LLDB_REGISTER_METHOD(bool, SBTypeSynthetic, IsClassName, ());
229 LLDB_REGISTER_METHOD(const char *, SBTypeSynthetic, GetData, ());
230 LLDB_REGISTER_METHOD(void, SBTypeSynthetic, SetClassName, (const char *));
231 LLDB_REGISTER_METHOD(void, SBTypeSynthetic, SetClassCode, (const char *));
232 LLDB_REGISTER_METHOD(uint32_t, SBTypeSynthetic, GetOptions, ());
233 LLDB_REGISTER_METHOD(void, SBTypeSynthetic, SetOptions, (uint32_t));
234 LLDB_REGISTER_METHOD(bool, SBTypeSynthetic, GetDescription,
235 (lldb::SBStream &, lldb::DescriptionLevel));
236 LLDB_REGISTER_METHOD(
237 lldb::SBTypeSynthetic &,
238 SBTypeSynthetic, operator=,(const lldb::SBTypeSynthetic &));
239 LLDB_REGISTER_METHOD(bool,
240 SBTypeSynthetic, operator==,(lldb::SBTypeSynthetic &));
241 LLDB_REGISTER_METHOD(bool, SBTypeSynthetic, IsEqualTo,
242 (lldb::SBTypeSynthetic &));
243 LLDB_REGISTER_METHOD(bool,
244 SBTypeSynthetic, operator!=,(lldb::SBTypeSynthetic &));