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 
11 
12 #include "lldb/API/SBStream.h"
13 
15 
16 using namespace lldb;
17 using namespace lldb_private;
18 
20 
22  uint32_t options) {
23  LLDB_INSTRUMENT_VA(data, options);
24 
25  if (!data || data[0] == 0)
26  return SBTypeSynthetic();
27  return SBTypeSynthetic(ScriptedSyntheticChildrenSP(
28  new ScriptedSyntheticChildren(options, data, "")));
29 }
30 
32  uint32_t options) {
33  LLDB_INSTRUMENT_VA(data, options);
34 
35  if (!data || data[0] == 0)
36  return SBTypeSynthetic();
37  return SBTypeSynthetic(ScriptedSyntheticChildrenSP(
38  new ScriptedSyntheticChildren(options, "", data)));
39 }
40 
42  : m_opaque_sp(rhs.m_opaque_sp) {
43  LLDB_INSTRUMENT_VA(this, rhs);
44 }
45 
47 
49  LLDB_INSTRUMENT_VA(this);
50  return this->operator bool();
51 }
52 SBTypeSynthetic::operator bool() const {
53  LLDB_INSTRUMENT_VA(this);
54 
55  return m_opaque_sp.get() != nullptr;
56 }
57 
59  LLDB_INSTRUMENT_VA(this);
60 
61  if (!IsValid())
62  return false;
63  const char *code = m_opaque_sp->GetPythonCode();
64  return (code && *code);
65 }
66 
68  LLDB_INSTRUMENT_VA(this);
69 
70  if (!IsValid())
71  return false;
72  return !IsClassCode();
73 }
74 
75 const char *SBTypeSynthetic::GetData() {
76  LLDB_INSTRUMENT_VA(this);
77 
78  if (!IsValid())
79  return nullptr;
80  if (IsClassCode())
81  return m_opaque_sp->GetPythonCode();
82  else
83  return m_opaque_sp->GetPythonClassName();
84 }
85 
86 void SBTypeSynthetic::SetClassName(const char *data) {
87  LLDB_INSTRUMENT_VA(this, data);
88 
89  if (IsValid() && data && *data)
90  m_opaque_sp->SetPythonClassName(data);
91 }
92 
93 void SBTypeSynthetic::SetClassCode(const char *data) {
94  LLDB_INSTRUMENT_VA(this, data);
95 
96  if (IsValid() && data && *data)
97  m_opaque_sp->SetPythonCode(data);
98 }
99 
101  LLDB_INSTRUMENT_VA(this);
102 
103  if (!IsValid())
104  return lldb::eTypeOptionNone;
105  return m_opaque_sp->GetOptions();
106 }
107 
109  LLDB_INSTRUMENT_VA(this, value);
110 
111  if (!CopyOnWrite_Impl())
112  return;
113  m_opaque_sp->SetOptions(value);
114 }
115 
117  lldb::DescriptionLevel description_level) {
118  LLDB_INSTRUMENT_VA(this, description, description_level);
119 
120  if (m_opaque_sp) {
121  description.Printf("%s\n", m_opaque_sp->GetDescription().c_str());
122  return true;
123  }
124  return false;
125 }
126 
129  LLDB_INSTRUMENT_VA(this, rhs);
130 
131  if (this != &rhs) {
132  m_opaque_sp = rhs.m_opaque_sp;
133  }
134  return *this;
135 }
136 
138  LLDB_INSTRUMENT_VA(this, rhs);
139 
140  if (!IsValid())
141  return !rhs.IsValid();
142  return m_opaque_sp == rhs.m_opaque_sp;
143 }
144 
146  LLDB_INSTRUMENT_VA(this, rhs);
147 
148  if (!IsValid())
149  return !rhs.IsValid();
150 
151  if (m_opaque_sp->IsScripted() != rhs.m_opaque_sp->IsScripted())
152  return false;
153 
154  if (IsClassCode() != rhs.IsClassCode())
155  return false;
156 
157  if (strcmp(GetData(), rhs.GetData()))
158  return false;
159 
160  return GetOptions() == rhs.GetOptions();
161 }
162 
164  LLDB_INSTRUMENT_VA(this, rhs);
165 
166  if (!IsValid())
167  return !rhs.IsValid();
168  return m_opaque_sp != rhs.m_opaque_sp;
169 }
170 
171 lldb::ScriptedSyntheticChildrenSP SBTypeSynthetic::GetSP() {
172  return m_opaque_sp;
173 }
174 
176  const lldb::ScriptedSyntheticChildrenSP &TypeSynthetic_impl_sp) {
177  m_opaque_sp = TypeSynthetic_impl_sp;
178 }
179 
181  const lldb::ScriptedSyntheticChildrenSP &TypeSynthetic_impl_sp)
182  : m_opaque_sp(TypeSynthetic_impl_sp) {}
183 
185  if (!IsValid())
186  return false;
187  if (m_opaque_sp.unique())
188  return true;
189 
190  ScriptedSyntheticChildrenSP new_sp(new ScriptedSyntheticChildren(
191  m_opaque_sp->GetOptions(), m_opaque_sp->GetPythonClassName(),
192  m_opaque_sp->GetPythonCode()));
193 
194  SetSP(new_sp);
195 
196  return true;
197 }
Instrumentation.h
SBTypeSynthetic.h
lldb_private::ScriptedSyntheticChildren
Definition: TypeSynthetic.h:387
lldb::SBTypeSynthetic::GetSP
lldb::ScriptedSyntheticChildrenSP GetSP()
Definition: SBTypeSynthetic.cpp:171
lldb::SBTypeSynthetic::CreateWithScriptCode
static SBTypeSynthetic CreateWithScriptCode(const char *data, uint32_t options=0)
Definition: SBTypeSynthetic.cpp:31
lldb::SBStream::Printf
void Printf(const char *format,...) __attribute__((format(printf
Definition: SBStream.cpp:70
lldb::SBTypeSynthetic::SetOptions
void SetOptions(uint32_t)
Definition: SBTypeSynthetic.cpp:108
lldb::SBTypeSynthetic
class LLDB_API SBTypeSynthetic
Definition: SBDefines.h:102
lldb::SBTypeSynthetic::~SBTypeSynthetic
~SBTypeSynthetic()
lldb::SBTypeSynthetic::SetClassName
void SetClassName(const char *data)
Definition: SBTypeSynthetic.cpp:86
lldb::SBTypeSynthetic::operator=
lldb::SBTypeSynthetic & operator=(const lldb::SBTypeSynthetic &rhs)
Definition: SBTypeSynthetic.cpp:128
lldb::SBTypeSynthetic::IsValid
bool IsValid() const
Definition: SBTypeSynthetic.cpp:48
lldb::SBTypeSynthetic::GetDescription
bool GetDescription(lldb::SBStream &description, lldb::DescriptionLevel description_level)
Definition: SBTypeSynthetic.cpp:116
SBStream.h
bool
lldb::SBTypeSynthetic::GetData
const char * GetData()
Definition: SBTypeSynthetic.cpp:75
lldb::SBTypeSynthetic::IsClassName
bool IsClassName()
Definition: SBTypeSynthetic.cpp:67
lldb::SBTypeSynthetic::SetClassCode
void SetClassCode(const char *data)
Definition: SBTypeSynthetic.cpp:93
lldb::SBTypeSynthetic::CopyOnWrite_Impl
bool CopyOnWrite_Impl()
Definition: SBTypeSynthetic.cpp:184
lldb::SBTypeSynthetic::GetOptions
uint32_t GetOptions()
Definition: SBTypeSynthetic.cpp:100
lldb::SBTypeSynthetic::operator==
bool operator==(lldb::SBTypeSynthetic &rhs)
Definition: SBTypeSynthetic.cpp:137
DataVisualization.h
uint32_t
lldb::SBTypeSynthetic::m_opaque_sp
lldb::ScriptedSyntheticChildrenSP m_opaque_sp
Definition: SBTypeSynthetic.h:71
lldb::SBTypeSynthetic
Definition: SBTypeSynthetic.h:17
lldb::SBTypeSynthetic::operator!=
bool operator!=(lldb::SBTypeSynthetic &rhs)
Definition: SBTypeSynthetic.cpp:163
lldb::SBTypeSynthetic::CreateWithClassName
static SBTypeSynthetic CreateWithClassName(const char *data, uint32_t options=0)
Definition: SBTypeSynthetic.cpp:21
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb::SBTypeSynthetic::IsClassCode
bool IsClassCode()
Definition: SBTypeSynthetic.cpp:58
LLDB_INSTRUMENT_VA
#define LLDB_INSTRUMENT_VA(...)
Definition: Instrumentation.h:98
lldb::SBTypeSynthetic::SetSP
void SetSP(const lldb::ScriptedSyntheticChildrenSP &typefilter_impl_sp)
Definition: SBTypeSynthetic.cpp:175
lldb::SBStream
Definition: SBStream.h:18
lldb
Definition: SBAddress.h:15
lldb::SBTypeSynthetic::SBTypeSynthetic
SBTypeSynthetic()
Definition: SBTypeSynthetic.cpp:19
lldb::DescriptionLevel
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
Definition: lldb-enumerations.h:207
lldb::SBTypeSynthetic::IsEqualTo
bool IsEqualTo(lldb::SBTypeSynthetic &rhs)
Definition: SBTypeSynthetic.cpp:145