1 //===-- SBTypeSynthetic.cpp -----------------------------------------*- C++
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #include "lldb/API/SBTypeSynthetic.h"
13 #include "lldb/API/SBStream.h"
15 #include "lldb/DataFormatters/DataVisualization.h"
18 using namespace lldb_private;
20 #ifndef LLDB_DISABLE_PYTHON
22 SBTypeSynthetic::SBTypeSynthetic() : m_opaque_sp() {}
24 SBTypeSynthetic SBTypeSynthetic::CreateWithClassName(const char *data,
26 if (!data || data[0] == 0)
27 return SBTypeSynthetic();
28 return SBTypeSynthetic(ScriptedSyntheticChildrenSP(
29 new ScriptedSyntheticChildren(options, data, "")));
32 SBTypeSynthetic SBTypeSynthetic::CreateWithScriptCode(const char *data,
34 if (!data || data[0] == 0)
35 return SBTypeSynthetic();
36 return SBTypeSynthetic(ScriptedSyntheticChildrenSP(
37 new ScriptedSyntheticChildren(options, "", data)));
40 SBTypeSynthetic::SBTypeSynthetic(const lldb::SBTypeSynthetic &rhs)
41 : m_opaque_sp(rhs.m_opaque_sp) {}
43 SBTypeSynthetic::~SBTypeSynthetic() {}
45 bool SBTypeSynthetic::IsValid() const { return m_opaque_sp.get() != NULL; }
47 bool SBTypeSynthetic::IsClassCode() {
50 const char *code = m_opaque_sp->GetPythonCode();
51 return (code && *code);
54 bool SBTypeSynthetic::IsClassName() {
57 return !IsClassCode();
60 const char *SBTypeSynthetic::GetData() {
64 return m_opaque_sp->GetPythonCode();
66 return m_opaque_sp->GetPythonClassName();
69 void SBTypeSynthetic::SetClassName(const char *data) {
70 if (IsValid() && data && *data)
71 m_opaque_sp->SetPythonClassName(data);
74 void SBTypeSynthetic::SetClassCode(const char *data) {
75 if (IsValid() && data && *data)
76 m_opaque_sp->SetPythonCode(data);
79 uint32_t SBTypeSynthetic::GetOptions() {
81 return lldb::eTypeOptionNone;
82 return m_opaque_sp->GetOptions();
85 void SBTypeSynthetic::SetOptions(uint32_t value) {
86 if (!CopyOnWrite_Impl())
88 m_opaque_sp->SetOptions(value);
91 bool SBTypeSynthetic::GetDescription(lldb::SBStream &description,
92 lldb::DescriptionLevel description_level) {
94 description.Printf("%s\n", m_opaque_sp->GetDescription().c_str());
100 lldb::SBTypeSynthetic &SBTypeSynthetic::
101 operator=(const lldb::SBTypeSynthetic &rhs) {
103 m_opaque_sp = rhs.m_opaque_sp;
108 bool SBTypeSynthetic::operator==(lldb::SBTypeSynthetic &rhs) {
109 if (IsValid() == false)
110 return !rhs.IsValid();
111 return m_opaque_sp == rhs.m_opaque_sp;
114 bool SBTypeSynthetic::IsEqualTo(lldb::SBTypeSynthetic &rhs) {
115 if (IsValid() == false)
116 return !rhs.IsValid();
118 if (m_opaque_sp->IsScripted() != rhs.m_opaque_sp->IsScripted())
121 if (IsClassCode() != rhs.IsClassCode())
124 if (strcmp(GetData(), rhs.GetData()))
127 return GetOptions() == rhs.GetOptions();
130 bool SBTypeSynthetic::operator!=(lldb::SBTypeSynthetic &rhs) {
131 if (IsValid() == false)
132 return !rhs.IsValid();
133 return m_opaque_sp != rhs.m_opaque_sp;
136 lldb::ScriptedSyntheticChildrenSP SBTypeSynthetic::GetSP() {
140 void SBTypeSynthetic::SetSP(
141 const lldb::ScriptedSyntheticChildrenSP &TypeSynthetic_impl_sp) {
142 m_opaque_sp = TypeSynthetic_impl_sp;
145 SBTypeSynthetic::SBTypeSynthetic(
146 const lldb::ScriptedSyntheticChildrenSP &TypeSynthetic_impl_sp)
147 : m_opaque_sp(TypeSynthetic_impl_sp) {}
149 bool SBTypeSynthetic::CopyOnWrite_Impl() {
152 if (m_opaque_sp.unique())
155 ScriptedSyntheticChildrenSP new_sp(new ScriptedSyntheticChildren(
156 m_opaque_sp->GetOptions(), m_opaque_sp->GetPythonClassName(),
157 m_opaque_sp->GetPythonCode()));
164 #endif // LLDB_DISABLE_PYTHON