LLDB  mainline
SBTypeSynthetic.cpp
Go to the documentation of this file.
1 //===-- SBTypeSynthetic.cpp -----------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #include "SBReproducerPrivate.h"
11 
12 #include "lldb/API/SBStream.h"
13 
15 
16 using namespace lldb;
17 using namespace lldb_private;
18 
21 }
22 
24  uint32_t options) {
26  CreateWithClassName, (const char *, uint32_t), data,
27  options);
28 
29  if (!data || data[0] == 0)
31  return LLDB_RECORD_RESULT(SBTypeSynthetic(ScriptedSyntheticChildrenSP(
32  new ScriptedSyntheticChildren(options, data, ""))));
33 }
34 
36  uint32_t options) {
38  CreateWithScriptCode, (const char *, uint32_t),
39  data, options);
40 
41  if (!data || data[0] == 0)
43  return LLDB_RECORD_RESULT(SBTypeSynthetic(ScriptedSyntheticChildrenSP(
44  new ScriptedSyntheticChildren(options, "", data))));
45 }
46 
48  : m_opaque_sp(rhs.m_opaque_sp) {
50  rhs);
51 }
52 
54 
57  return this->operator bool();
58 }
59 SBTypeSynthetic::operator bool() const {
61 
62  return m_opaque_sp.get() != nullptr;
63 }
64 
67 
68  if (!IsValid())
69  return false;
70  const char *code = m_opaque_sp->GetPythonCode();
71  return (code && *code);
72 }
73 
76 
77  if (!IsValid())
78  return false;
79  return !IsClassCode();
80 }
81 
82 const char *SBTypeSynthetic::GetData() {
84 
85  if (!IsValid())
86  return nullptr;
87  if (IsClassCode())
88  return m_opaque_sp->GetPythonCode();
89  else
90  return m_opaque_sp->GetPythonClassName();
91 }
92 
93 void SBTypeSynthetic::SetClassName(const char *data) {
94  LLDB_RECORD_METHOD(void, SBTypeSynthetic, SetClassName, (const char *), data);
95 
96  if (IsValid() && data && *data)
97  m_opaque_sp->SetPythonClassName(data);
98 }
99 
100 void SBTypeSynthetic::SetClassCode(const char *data) {
101  LLDB_RECORD_METHOD(void, SBTypeSynthetic, SetClassCode, (const char *), data);
102 
103  if (IsValid() && data && *data)
104  m_opaque_sp->SetPythonCode(data);
105 }
106 
109 
110  if (!IsValid())
111  return lldb::eTypeOptionNone;
112  return m_opaque_sp->GetOptions();
113 }
114 
117 
118  if (!CopyOnWrite_Impl())
119  return;
120  m_opaque_sp->SetOptions(value);
121 }
122 
124  lldb::DescriptionLevel description_level) {
126  (lldb::SBStream &, lldb::DescriptionLevel), description,
127  description_level);
128 
129  if (m_opaque_sp) {
130  description.Printf("%s\n", m_opaque_sp->GetDescription().c_str());
131  return true;
132  }
133  return false;
134 }
135 
139  SBTypeSynthetic, operator=,(const lldb::SBTypeSynthetic &),
140  rhs);
141 
142  if (this != &rhs) {
143  m_opaque_sp = rhs.m_opaque_sp;
144  }
145  return LLDB_RECORD_RESULT(*this);
146 }
147 
150  bool, SBTypeSynthetic, operator==,(lldb::SBTypeSynthetic &), rhs);
151 
152  if (!IsValid())
153  return !rhs.IsValid();
154  return m_opaque_sp == rhs.m_opaque_sp;
155 }
156 
159  (lldb::SBTypeSynthetic &), rhs);
160 
161  if (!IsValid())
162  return !rhs.IsValid();
163 
164  if (m_opaque_sp->IsScripted() != rhs.m_opaque_sp->IsScripted())
165  return false;
166 
167  if (IsClassCode() != rhs.IsClassCode())
168  return false;
169 
170  if (strcmp(GetData(), rhs.GetData()))
171  return false;
172 
173  return GetOptions() == rhs.GetOptions();
174 }
175 
178  bool, SBTypeSynthetic, operator!=,(lldb::SBTypeSynthetic &), rhs);
179 
180  if (!IsValid())
181  return !rhs.IsValid();
182  return m_opaque_sp != rhs.m_opaque_sp;
183 }
184 
185 lldb::ScriptedSyntheticChildrenSP SBTypeSynthetic::GetSP() {
186  return m_opaque_sp;
187 }
188 
190  const lldb::ScriptedSyntheticChildrenSP &TypeSynthetic_impl_sp) {
191  m_opaque_sp = TypeSynthetic_impl_sp;
192 }
193 
195  const lldb::ScriptedSyntheticChildrenSP &TypeSynthetic_impl_sp)
196  : m_opaque_sp(TypeSynthetic_impl_sp) {}
197 
199  if (!IsValid())
200  return false;
201  if (m_opaque_sp.unique())
202  return true;
203 
204  ScriptedSyntheticChildrenSP new_sp(new ScriptedSyntheticChildren(
205  m_opaque_sp->GetOptions(), m_opaque_sp->GetPythonClassName(),
206  m_opaque_sp->GetPythonCode()));
207 
208  SetSP(new_sp);
209 
210  return true;
211 }
212 
213 namespace lldb_private {
214 namespace repro {
215 
216 template <>
220  CreateWithClassName, (const char *, uint32_t));
222  CreateWithScriptCode, (const char *, uint32_t));
225  LLDB_REGISTER_METHOD_CONST(bool, SBTypeSynthetic, operator bool, ());
228  LLDB_REGISTER_METHOD(const char *, SBTypeSynthetic, GetData, ());
229  LLDB_REGISTER_METHOD(void, SBTypeSynthetic, SetClassName, (const char *));
230  LLDB_REGISTER_METHOD(void, SBTypeSynthetic, SetClassCode, (const char *));
237  SBTypeSynthetic, operator=,(const lldb::SBTypeSynthetic &));
239  SBTypeSynthetic, operator==,(lldb::SBTypeSynthetic &));
243  SBTypeSynthetic, operator!=,(lldb::SBTypeSynthetic &));
244 }
245 
246 }
247 }
The registry contains a unique mapping between functions and their ID.
A class that represents a running process on the host machine.
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
lldb::ScriptedSyntheticChildrenSP m_opaque_sp
bool GetDescription(lldb::SBStream &description, lldb::DescriptionLevel description_level)
#define LLDB_RECORD_STATIC_METHOD(Result, Class, Method, Signature,...)
static SBTypeSynthetic CreateWithScriptCode(const char *data, uint32_t options=0)
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
#define LLDB_REGISTER_STATIC_METHOD(Result, Class, Method, Signature)
void SetClassName(const char *data)
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method)
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
void Printf(const char *format,...) __attribute__((format(printf
Definition: SBStream.cpp:69
void SetClassCode(const char *data)
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
bool operator==(lldb::SBTypeSynthetic &rhs)
static SBTypeSynthetic CreateWithClassName(const char *data, uint32_t options=0)
lldb::ScriptedSyntheticChildrenSP GetSP()
lldb::SBTypeSynthetic & operator=(const lldb::SBTypeSynthetic &rhs)
Definition: SBAddress.h:15
bool operator!=(lldb::SBTypeSynthetic &rhs)
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
void RegisterMethods< SBTypeSynthetic >(Registry &R)
void SetSP(const lldb::ScriptedSyntheticChildrenSP &typefilter_impl_sp)
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
bool IsEqualTo(lldb::SBTypeSynthetic &rhs)
#define LLDB_RECORD_RESULT(Result)
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)