1 //===-- SBTypeSynthetic.cpp -----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-python.h"
12 #include "lldb/API/SBTypeSynthetic.h"
14 #include "lldb/API/SBStream.h"
16 #include "lldb/DataFormatters/DataVisualization.h"
19 using namespace lldb_private;
21 #ifndef LLDB_DISABLE_PYTHON
23 SBTypeSynthetic::SBTypeSynthetic() :
29 SBTypeSynthetic::CreateWithClassName (const char* data, uint32_t options)
31 if (!data || data[0] == 0)
32 return SBTypeSynthetic();
33 return SBTypeSynthetic(ScriptedSyntheticChildrenSP(new ScriptedSyntheticChildren(options, data, "")));
37 SBTypeSynthetic::CreateWithScriptCode (const char* data, uint32_t options)
39 if (!data || data[0] == 0)
40 return SBTypeSynthetic();
41 return SBTypeSynthetic(ScriptedSyntheticChildrenSP(new ScriptedSyntheticChildren(options, "", data)));
44 SBTypeSynthetic::SBTypeSynthetic (const lldb::SBTypeSynthetic &rhs) :
45 m_opaque_sp(rhs.m_opaque_sp)
49 SBTypeSynthetic::~SBTypeSynthetic ()
54 SBTypeSynthetic::IsValid() const
56 return m_opaque_sp.get() != NULL;
60 SBTypeSynthetic::IsClassCode()
64 const char* code = m_opaque_sp->GetPythonCode();
65 return (code && *code);
69 SBTypeSynthetic::IsClassName()
73 return !IsClassCode();
77 SBTypeSynthetic::GetData ()
82 return m_opaque_sp->GetPythonCode();
84 return m_opaque_sp->GetPythonClassName();
88 SBTypeSynthetic::SetClassName (const char* data)
90 if (IsValid() && data && *data)
91 m_opaque_sp->SetPythonClassName(data);
95 SBTypeSynthetic::SetClassCode (const char* data)
97 if (IsValid() && data && *data)
98 m_opaque_sp->SetPythonCode(data);
102 SBTypeSynthetic::GetOptions ()
105 return lldb::eTypeOptionNone;
106 return m_opaque_sp->GetOptions();
110 SBTypeSynthetic::SetOptions (uint32_t value)
112 if (!CopyOnWrite_Impl())
114 m_opaque_sp->SetOptions(value);
118 SBTypeSynthetic::GetDescription (lldb::SBStream &description,
119 lldb::DescriptionLevel description_level)
123 description.Printf("%s\n",
124 m_opaque_sp->GetDescription().c_str());
130 lldb::SBTypeSynthetic &
131 SBTypeSynthetic::operator = (const lldb::SBTypeSynthetic &rhs)
135 m_opaque_sp = rhs.m_opaque_sp;
141 SBTypeSynthetic::operator == (lldb::SBTypeSynthetic &rhs)
143 if (IsValid() == false)
144 return !rhs.IsValid();
145 return m_opaque_sp == rhs.m_opaque_sp;
149 SBTypeSynthetic::IsEqualTo (lldb::SBTypeSynthetic &rhs)
151 if (IsValid() == false)
152 return !rhs.IsValid();
154 if (m_opaque_sp->IsScripted() != rhs.m_opaque_sp->IsScripted())
157 if (IsClassCode() != rhs.IsClassCode())
160 if ( strcmp(GetData(), rhs.GetData()) )
163 return GetOptions() == rhs.GetOptions();
168 SBTypeSynthetic::operator != (lldb::SBTypeSynthetic &rhs)
170 if (IsValid() == false)
171 return !rhs.IsValid();
172 return m_opaque_sp != rhs.m_opaque_sp;
175 lldb::ScriptedSyntheticChildrenSP
176 SBTypeSynthetic::GetSP ()
182 SBTypeSynthetic::SetSP (const lldb::ScriptedSyntheticChildrenSP &TypeSynthetic_impl_sp)
184 m_opaque_sp = TypeSynthetic_impl_sp;
187 SBTypeSynthetic::SBTypeSynthetic (const lldb::ScriptedSyntheticChildrenSP &TypeSynthetic_impl_sp) :
188 m_opaque_sp(TypeSynthetic_impl_sp)
193 SBTypeSynthetic::CopyOnWrite_Impl()
197 if (m_opaque_sp.unique())
200 ScriptedSyntheticChildrenSP new_sp(new ScriptedSyntheticChildren(m_opaque_sp->GetOptions(),
201 m_opaque_sp->GetPythonClassName(),
202 m_opaque_sp->GetPythonCode()));
209 #endif // LLDB_DISABLE_PYTHON