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/API/SBTypeSynthetic.h"
12 #include "lldb/API/SBStream.h"
14 #include "lldb/DataFormatters/DataVisualization.h"
17 using namespace lldb_private;
19 #ifndef LLDB_DISABLE_PYTHON
21 SBTypeSynthetic::SBTypeSynthetic() :
27 SBTypeSynthetic::CreateWithClassName (const char* data, uint32_t options)
29 if (!data || data[0] == 0)
30 return SBTypeSynthetic();
31 return SBTypeSynthetic(ScriptedSyntheticChildrenSP(new ScriptedSyntheticChildren(options, data, "")));
35 SBTypeSynthetic::CreateWithScriptCode (const char* data, uint32_t options)
37 if (!data || data[0] == 0)
38 return SBTypeSynthetic();
39 return SBTypeSynthetic(ScriptedSyntheticChildrenSP(new ScriptedSyntheticChildren(options, "", data)));
42 SBTypeSynthetic::SBTypeSynthetic (const lldb::SBTypeSynthetic &rhs) :
43 m_opaque_sp(rhs.m_opaque_sp)
47 SBTypeSynthetic::~SBTypeSynthetic ()
52 SBTypeSynthetic::IsValid() const
54 return m_opaque_sp.get() != NULL;
58 SBTypeSynthetic::IsClassCode()
62 const char* code = m_opaque_sp->GetPythonCode();
63 return (code && *code);
67 SBTypeSynthetic::IsClassName()
71 return !IsClassCode();
75 SBTypeSynthetic::GetData ()
80 return m_opaque_sp->GetPythonCode();
82 return m_opaque_sp->GetPythonClassName();
86 SBTypeSynthetic::SetClassName (const char* data)
88 if (IsValid() && data && *data)
89 m_opaque_sp->SetPythonClassName(data);
93 SBTypeSynthetic::SetClassCode (const char* data)
95 if (IsValid() && data && *data)
96 m_opaque_sp->SetPythonCode(data);
100 SBTypeSynthetic::GetOptions ()
103 return lldb::eTypeOptionNone;
104 return m_opaque_sp->GetOptions();
108 SBTypeSynthetic::SetOptions (uint32_t value)
110 if (!CopyOnWrite_Impl())
112 m_opaque_sp->SetOptions(value);
116 SBTypeSynthetic::GetDescription (lldb::SBStream &description,
117 lldb::DescriptionLevel description_level)
121 description.Printf("%s\n",
122 m_opaque_sp->GetDescription().c_str());
128 lldb::SBTypeSynthetic &
129 SBTypeSynthetic::operator = (const lldb::SBTypeSynthetic &rhs)
133 m_opaque_sp = rhs.m_opaque_sp;
139 SBTypeSynthetic::operator == (lldb::SBTypeSynthetic &rhs)
141 if (IsValid() == false)
142 return !rhs.IsValid();
143 return m_opaque_sp == rhs.m_opaque_sp;
147 SBTypeSynthetic::IsEqualTo (lldb::SBTypeSynthetic &rhs)
149 if (IsValid() == false)
150 return !rhs.IsValid();
152 if (m_opaque_sp->IsScripted() != rhs.m_opaque_sp->IsScripted())
155 if (IsClassCode() != rhs.IsClassCode())
158 if ( strcmp(GetData(), rhs.GetData()) )
161 return GetOptions() == rhs.GetOptions();
166 SBTypeSynthetic::operator != (lldb::SBTypeSynthetic &rhs)
168 if (IsValid() == false)
169 return !rhs.IsValid();
170 return m_opaque_sp != rhs.m_opaque_sp;
173 lldb::ScriptedSyntheticChildrenSP
174 SBTypeSynthetic::GetSP ()
180 SBTypeSynthetic::SetSP (const lldb::ScriptedSyntheticChildrenSP &TypeSynthetic_impl_sp)
182 m_opaque_sp = TypeSynthetic_impl_sp;
185 SBTypeSynthetic::SBTypeSynthetic (const lldb::ScriptedSyntheticChildrenSP &TypeSynthetic_impl_sp) :
186 m_opaque_sp(TypeSynthetic_impl_sp)
191 SBTypeSynthetic::CopyOnWrite_Impl()
195 if (m_opaque_sp.unique())
198 ScriptedSyntheticChildrenSP new_sp(new ScriptedSyntheticChildren(m_opaque_sp->GetOptions(),
199 m_opaque_sp->GetPythonClassName(),
200 m_opaque_sp->GetPythonCode()));
207 #endif // LLDB_DISABLE_PYTHON