1 //===-- SBTypeSynthetic.cpp -----------------------------------------*- C++
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
8 //===----------------------------------------------------------------------===//
10 #include "lldb/API/SBTypeSynthetic.h"
11 #include "SBReproducerPrivate.h"
13 #include "lldb/API/SBStream.h"
15 #include "lldb/DataFormatters/DataVisualization.h"
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
,
26 LLDB_RECORD_STATIC_METHOD(lldb::SBTypeSynthetic
, SBTypeSynthetic
,
27 CreateWithClassName
, (const char *, uint32_t), data
,
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
,
38 LLDB_RECORD_STATIC_METHOD(lldb::SBTypeSynthetic
, SBTypeSynthetic
,
39 CreateWithScriptCode
, (const char *, uint32_t),
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
&),
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
);
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
);
80 return !IsClassCode();
83 const char *SBTypeSynthetic::GetData() {
84 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeSynthetic
, GetData
);
89 return m_opaque_sp
->GetPythonCode();
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
);
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())
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
,
131 description
.Printf("%s\n", m_opaque_sp
->GetDescription().c_str());
137 lldb::SBTypeSynthetic
&SBTypeSynthetic::
138 operator=(const lldb::SBTypeSynthetic
&rhs
) {
139 LLDB_RECORD_METHOD(lldb::SBTypeSynthetic
&,
140 SBTypeSynthetic
, operator=,(const lldb::SBTypeSynthetic
&),
144 m_opaque_sp
= rhs
.m_opaque_sp
;
146 return LLDB_RECORD_RESULT(*this);
149 bool SBTypeSynthetic::operator==(lldb::SBTypeSynthetic
&rhs
) {
151 bool, SBTypeSynthetic
, operator==,(lldb::SBTypeSynthetic
&), rhs
);
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
);
163 return !rhs
.IsValid();
165 if (m_opaque_sp
->IsScripted() != rhs
.m_opaque_sp
->IsScripted())
168 if (IsClassCode() != rhs
.IsClassCode())
171 if (strcmp(GetData(), rhs
.GetData()))
174 return GetOptions() == rhs
.GetOptions();
177 bool SBTypeSynthetic::operator!=(lldb::SBTypeSynthetic
&rhs
) {
179 bool, SBTypeSynthetic
, operator!=,(lldb::SBTypeSynthetic
&), rhs
);
182 return !rhs
.IsValid();
183 return m_opaque_sp
!= rhs
.m_opaque_sp
;
186 lldb::ScriptedSyntheticChildrenSP
SBTypeSynthetic::GetSP() {
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() {
202 if (m_opaque_sp
.unique())
205 ScriptedSyntheticChildrenSP
new_sp(new ScriptedSyntheticChildren(
206 m_opaque_sp
->GetOptions(), m_opaque_sp
->GetPythonClassName(),
207 m_opaque_sp
->GetPythonCode()));
214 namespace lldb_private
{
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
&));