]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/source/API/SBTypeSynthetic.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / source / API / SBTypeSynthetic.cpp
1 //===-- SBTypeSynthetic.cpp -----------------------------------------*- C++
2 //-*-===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "lldb/API/SBTypeSynthetic.h"
11 #include "SBReproducerPrivate.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 SBTypeSynthetic::SBTypeSynthetic() : m_opaque_sp() {
21   LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTypeSynthetic);
22 }
23
24 SBTypeSynthetic SBTypeSynthetic::CreateWithClassName(const char *data,
25                                                      uint32_t options) {
26   LLDB_RECORD_STATIC_METHOD(lldb::SBTypeSynthetic, SBTypeSynthetic,
27                             CreateWithClassName, (const char *, uint32_t), data,
28                             options);
29
30   if (!data || data[0] == 0)
31     return LLDB_RECORD_RESULT(SBTypeSynthetic());
32   return LLDB_RECORD_RESULT(SBTypeSynthetic(ScriptedSyntheticChildrenSP(
33       new ScriptedSyntheticChildren(options, data, ""))));
34 }
35
36 SBTypeSynthetic SBTypeSynthetic::CreateWithScriptCode(const char *data,
37                                                       uint32_t options) {
38   LLDB_RECORD_STATIC_METHOD(lldb::SBTypeSynthetic, SBTypeSynthetic,
39                             CreateWithScriptCode, (const char *, uint32_t),
40                             data, options);
41
42   if (!data || data[0] == 0)
43     return LLDB_RECORD_RESULT(SBTypeSynthetic());
44   return LLDB_RECORD_RESULT(SBTypeSynthetic(ScriptedSyntheticChildrenSP(
45       new ScriptedSyntheticChildren(options, "", data))));
46 }
47
48 SBTypeSynthetic::SBTypeSynthetic(const lldb::SBTypeSynthetic &rhs)
49     : m_opaque_sp(rhs.m_opaque_sp) {
50   LLDB_RECORD_CONSTRUCTOR(SBTypeSynthetic, (const lldb::SBTypeSynthetic &),
51                           rhs);
52 }
53
54 SBTypeSynthetic::~SBTypeSynthetic() {}
55
56 bool SBTypeSynthetic::IsValid() const {
57   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeSynthetic, IsValid);
58   return this->operator bool();
59 }
60 SBTypeSynthetic::operator bool() const {
61   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeSynthetic, operator bool);
62
63   return m_opaque_sp.get() != nullptr;
64 }
65
66 bool SBTypeSynthetic::IsClassCode() {
67   LLDB_RECORD_METHOD_NO_ARGS(bool, SBTypeSynthetic, IsClassCode);
68
69   if (!IsValid())
70     return false;
71   const char *code = m_opaque_sp->GetPythonCode();
72   return (code && *code);
73 }
74
75 bool SBTypeSynthetic::IsClassName() {
76   LLDB_RECORD_METHOD_NO_ARGS(bool, SBTypeSynthetic, IsClassName);
77
78   if (!IsValid())
79     return false;
80   return !IsClassCode();
81 }
82
83 const char *SBTypeSynthetic::GetData() {
84   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeSynthetic, GetData);
85
86   if (!IsValid())
87     return nullptr;
88   if (IsClassCode())
89     return m_opaque_sp->GetPythonCode();
90   else
91     return m_opaque_sp->GetPythonClassName();
92 }
93
94 void SBTypeSynthetic::SetClassName(const char *data) {
95   LLDB_RECORD_METHOD(void, SBTypeSynthetic, SetClassName, (const char *), data);
96
97   if (IsValid() && data && *data)
98     m_opaque_sp->SetPythonClassName(data);
99 }
100
101 void SBTypeSynthetic::SetClassCode(const char *data) {
102   LLDB_RECORD_METHOD(void, SBTypeSynthetic, SetClassCode, (const char *), data);
103
104   if (IsValid() && data && *data)
105     m_opaque_sp->SetPythonCode(data);
106 }
107
108 uint32_t SBTypeSynthetic::GetOptions() {
109   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeSynthetic, GetOptions);
110
111   if (!IsValid())
112     return lldb::eTypeOptionNone;
113   return m_opaque_sp->GetOptions();
114 }
115
116 void SBTypeSynthetic::SetOptions(uint32_t value) {
117   LLDB_RECORD_METHOD(void, SBTypeSynthetic, SetOptions, (uint32_t), value);
118
119   if (!CopyOnWrite_Impl())
120     return;
121   m_opaque_sp->SetOptions(value);
122 }
123
124 bool SBTypeSynthetic::GetDescription(lldb::SBStream &description,
125                                      lldb::DescriptionLevel description_level) {
126   LLDB_RECORD_METHOD(bool, SBTypeSynthetic, GetDescription,
127                      (lldb::SBStream &, lldb::DescriptionLevel), description,
128                      description_level);
129
130   if (m_opaque_sp) {
131     description.Printf("%s\n", m_opaque_sp->GetDescription().c_str());
132     return true;
133   }
134   return false;
135 }
136
137 lldb::SBTypeSynthetic &SBTypeSynthetic::
138 operator=(const lldb::SBTypeSynthetic &rhs) {
139   LLDB_RECORD_METHOD(lldb::SBTypeSynthetic &,
140                      SBTypeSynthetic, operator=,(const lldb::SBTypeSynthetic &),
141                      rhs);
142
143   if (this != &rhs) {
144     m_opaque_sp = rhs.m_opaque_sp;
145   }
146   return LLDB_RECORD_RESULT(*this);
147 }
148
149 bool SBTypeSynthetic::operator==(lldb::SBTypeSynthetic &rhs) {
150   LLDB_RECORD_METHOD(
151       bool, SBTypeSynthetic, operator==,(lldb::SBTypeSynthetic &), rhs);
152
153   if (!IsValid())
154     return !rhs.IsValid();
155   return m_opaque_sp == rhs.m_opaque_sp;
156 }
157
158 bool SBTypeSynthetic::IsEqualTo(lldb::SBTypeSynthetic &rhs) {
159   LLDB_RECORD_METHOD(bool, SBTypeSynthetic, IsEqualTo,
160                      (lldb::SBTypeSynthetic &), rhs);
161
162   if (!IsValid())
163     return !rhs.IsValid();
164
165   if (m_opaque_sp->IsScripted() != rhs.m_opaque_sp->IsScripted())
166     return false;
167
168   if (IsClassCode() != rhs.IsClassCode())
169     return false;
170
171   if (strcmp(GetData(), rhs.GetData()))
172     return false;
173
174   return GetOptions() == rhs.GetOptions();
175 }
176
177 bool SBTypeSynthetic::operator!=(lldb::SBTypeSynthetic &rhs) {
178   LLDB_RECORD_METHOD(
179       bool, SBTypeSynthetic, operator!=,(lldb::SBTypeSynthetic &), rhs);
180
181   if (!IsValid())
182     return !rhs.IsValid();
183   return m_opaque_sp != rhs.m_opaque_sp;
184 }
185
186 lldb::ScriptedSyntheticChildrenSP SBTypeSynthetic::GetSP() {
187   return m_opaque_sp;
188 }
189
190 void SBTypeSynthetic::SetSP(
191     const lldb::ScriptedSyntheticChildrenSP &TypeSynthetic_impl_sp) {
192   m_opaque_sp = TypeSynthetic_impl_sp;
193 }
194
195 SBTypeSynthetic::SBTypeSynthetic(
196     const lldb::ScriptedSyntheticChildrenSP &TypeSynthetic_impl_sp)
197     : m_opaque_sp(TypeSynthetic_impl_sp) {}
198
199 bool SBTypeSynthetic::CopyOnWrite_Impl() {
200   if (!IsValid())
201     return false;
202   if (m_opaque_sp.unique())
203     return true;
204
205   ScriptedSyntheticChildrenSP new_sp(new ScriptedSyntheticChildren(
206       m_opaque_sp->GetOptions(), m_opaque_sp->GetPythonClassName(),
207       m_opaque_sp->GetPythonCode()));
208
209   SetSP(new_sp);
210
211   return true;
212 }
213
214 namespace lldb_private {
215 namespace repro {
216
217 template <>
218 void RegisterMethods<SBTypeSynthetic>(Registry &R) {
219   LLDB_REGISTER_CONSTRUCTOR(SBTypeSynthetic, ());
220   LLDB_REGISTER_STATIC_METHOD(lldb::SBTypeSynthetic, SBTypeSynthetic,
221                               CreateWithClassName, (const char *, uint32_t));
222   LLDB_REGISTER_STATIC_METHOD(lldb::SBTypeSynthetic, SBTypeSynthetic,
223                               CreateWithScriptCode, (const char *, uint32_t));
224   LLDB_REGISTER_CONSTRUCTOR(SBTypeSynthetic, (const lldb::SBTypeSynthetic &));
225   LLDB_REGISTER_METHOD_CONST(bool, SBTypeSynthetic, IsValid, ());
226   LLDB_REGISTER_METHOD_CONST(bool, SBTypeSynthetic, operator bool, ());
227   LLDB_REGISTER_METHOD(bool, SBTypeSynthetic, IsClassCode, ());
228   LLDB_REGISTER_METHOD(bool, SBTypeSynthetic, IsClassName, ());
229   LLDB_REGISTER_METHOD(const char *, SBTypeSynthetic, GetData, ());
230   LLDB_REGISTER_METHOD(void, SBTypeSynthetic, SetClassName, (const char *));
231   LLDB_REGISTER_METHOD(void, SBTypeSynthetic, SetClassCode, (const char *));
232   LLDB_REGISTER_METHOD(uint32_t, SBTypeSynthetic, GetOptions, ());
233   LLDB_REGISTER_METHOD(void, SBTypeSynthetic, SetOptions, (uint32_t));
234   LLDB_REGISTER_METHOD(bool, SBTypeSynthetic, GetDescription,
235                        (lldb::SBStream &, lldb::DescriptionLevel));
236   LLDB_REGISTER_METHOD(
237       lldb::SBTypeSynthetic &,
238       SBTypeSynthetic, operator=,(const lldb::SBTypeSynthetic &));
239   LLDB_REGISTER_METHOD(bool,
240                        SBTypeSynthetic, operator==,(lldb::SBTypeSynthetic &));
241   LLDB_REGISTER_METHOD(bool, SBTypeSynthetic, IsEqualTo,
242                        (lldb::SBTypeSynthetic &));
243   LLDB_REGISTER_METHOD(bool,
244                        SBTypeSynthetic, operator!=,(lldb::SBTypeSynthetic &));
245 }
246
247 }
248 }