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