]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/API/SBTypeSynthetic.cpp
Update LLDB snapshot to upstream r241361
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / API / SBTypeSynthetic.cpp
1 //===-- SBTypeSynthetic.cpp -----------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "lldb/API/SBTypeSynthetic.h"
11
12 #include "lldb/API/SBStream.h"
13
14 #include "lldb/DataFormatters/DataVisualization.h"
15
16 using namespace lldb;
17 using namespace lldb_private;
18
19 #ifndef LLDB_DISABLE_PYTHON
20
21 SBTypeSynthetic::SBTypeSynthetic() :
22 m_opaque_sp()
23 {
24 }
25
26 SBTypeSynthetic
27 SBTypeSynthetic::CreateWithClassName (const char* data, uint32_t options)
28 {
29     if (!data || data[0] == 0)
30         return SBTypeSynthetic();
31     return SBTypeSynthetic(ScriptedSyntheticChildrenSP(new ScriptedSyntheticChildren(options, data, "")));
32 }
33
34 SBTypeSynthetic
35 SBTypeSynthetic::CreateWithScriptCode (const char* data, uint32_t options)
36 {
37     if (!data || data[0] == 0)
38         return SBTypeSynthetic();
39     return SBTypeSynthetic(ScriptedSyntheticChildrenSP(new ScriptedSyntheticChildren(options, "", data)));
40 }
41
42 SBTypeSynthetic::SBTypeSynthetic (const lldb::SBTypeSynthetic &rhs) :
43 m_opaque_sp(rhs.m_opaque_sp)
44 {
45 }
46
47 SBTypeSynthetic::~SBTypeSynthetic ()
48 {
49 }
50
51 bool
52 SBTypeSynthetic::IsValid() const
53 {
54     return m_opaque_sp.get() != NULL;
55 }
56
57 bool
58 SBTypeSynthetic::IsClassCode()
59 {
60     if (!IsValid())
61         return false;
62     const char* code = m_opaque_sp->GetPythonCode();
63     return (code && *code);
64 }
65
66 bool
67 SBTypeSynthetic::IsClassName()
68 {
69     if (!IsValid())
70         return false;
71     return !IsClassCode();
72 }
73
74 const char*
75 SBTypeSynthetic::GetData ()
76 {
77     if (!IsValid())
78         return NULL;
79     if (IsClassCode())
80         return m_opaque_sp->GetPythonCode();
81     else
82         return m_opaque_sp->GetPythonClassName();
83 }
84
85 void
86 SBTypeSynthetic::SetClassName (const char* data)
87 {
88     if (IsValid() && data && *data)
89         m_opaque_sp->SetPythonClassName(data);
90 }
91
92 void
93 SBTypeSynthetic::SetClassCode (const char* data)
94 {
95     if (IsValid() && data && *data)
96         m_opaque_sp->SetPythonCode(data);
97 }
98
99 uint32_t
100 SBTypeSynthetic::GetOptions ()
101 {
102     if (!IsValid())
103         return lldb::eTypeOptionNone;
104     return m_opaque_sp->GetOptions();
105 }
106
107 void
108 SBTypeSynthetic::SetOptions (uint32_t value)
109 {
110     if (!CopyOnWrite_Impl())
111         return;
112     m_opaque_sp->SetOptions(value);
113 }
114
115 bool
116 SBTypeSynthetic::GetDescription (lldb::SBStream &description, 
117                                  lldb::DescriptionLevel description_level)
118 {
119     if (m_opaque_sp)
120     {
121         description.Printf("%s\n",
122                            m_opaque_sp->GetDescription().c_str());
123         return true;
124     }
125     return false;
126 }
127
128 lldb::SBTypeSynthetic &
129 SBTypeSynthetic::operator = (const lldb::SBTypeSynthetic &rhs)
130 {
131     if (this != &rhs)
132     {
133         m_opaque_sp = rhs.m_opaque_sp;
134     }
135     return *this;
136 }
137
138 bool
139 SBTypeSynthetic::operator == (lldb::SBTypeSynthetic &rhs)
140 {
141     if (IsValid() == false)
142         return !rhs.IsValid();
143     return m_opaque_sp == rhs.m_opaque_sp;
144 }
145
146 bool
147 SBTypeSynthetic::IsEqualTo (lldb::SBTypeSynthetic &rhs)
148 {
149     if (IsValid() == false)
150         return !rhs.IsValid();
151     
152     if (m_opaque_sp->IsScripted() != rhs.m_opaque_sp->IsScripted())
153         return false;
154     
155     if (IsClassCode() != rhs.IsClassCode())
156         return false;
157     
158     if ( strcmp(GetData(), rhs.GetData()) )
159         return false;
160     
161     return GetOptions() == rhs.GetOptions();
162     
163 }
164
165 bool
166 SBTypeSynthetic::operator != (lldb::SBTypeSynthetic &rhs)
167 {
168     if (IsValid() == false)
169         return !rhs.IsValid();
170     return m_opaque_sp != rhs.m_opaque_sp;
171 }
172
173 lldb::ScriptedSyntheticChildrenSP
174 SBTypeSynthetic::GetSP ()
175 {
176     return m_opaque_sp;
177 }
178
179 void
180 SBTypeSynthetic::SetSP (const lldb::ScriptedSyntheticChildrenSP &TypeSynthetic_impl_sp)
181 {
182     m_opaque_sp = TypeSynthetic_impl_sp;
183 }
184
185 SBTypeSynthetic::SBTypeSynthetic (const lldb::ScriptedSyntheticChildrenSP &TypeSynthetic_impl_sp) :
186 m_opaque_sp(TypeSynthetic_impl_sp)
187 {
188 }
189
190 bool
191 SBTypeSynthetic::CopyOnWrite_Impl()
192 {
193     if (!IsValid())
194         return false;
195     if (m_opaque_sp.unique())
196         return true;
197     
198     ScriptedSyntheticChildrenSP new_sp(new ScriptedSyntheticChildren(m_opaque_sp->GetOptions(),
199                                                      m_opaque_sp->GetPythonClassName(),
200                                                      m_opaque_sp->GetPythonCode()));
201     
202     SetSP(new_sp);
203     
204     return true;
205 }
206
207 #endif // LLDB_DISABLE_PYTHON