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
12
13#include "lldb/API/SBStream.h"
14
16
17using namespace lldb;
18using namespace lldb_private;
19
21
23 uint32_t options) {
24 LLDB_INSTRUMENT_VA(data, options);
25
26 if (!data || data[0] == 0)
27 return SBTypeSynthetic();
28 return SBTypeSynthetic(
29 std::make_shared<ScriptedSyntheticChildren>(options, data, ""));
30}
31
33 uint32_t options) {
34 LLDB_INSTRUMENT_VA(data, options);
35
36 if (!data || data[0] == 0)
37 return SBTypeSynthetic();
38 return SBTypeSynthetic(
39 std::make_shared<ScriptedSyntheticChildren>(options, "", data));
40}
41
46
48
51 return this->operator bool();
52}
53SBTypeSynthetic::operator bool() const {
55
56 return m_opaque_sp.get() != nullptr;
57}
58
61
62 if (!IsValid())
63 return false;
64 const char *code = m_opaque_sp->GetPythonCode();
65 return (code && *code);
66}
67
70
71 if (!IsValid())
72 return false;
73 return !IsClassCode();
74}
75
78
79 if (!IsValid())
80 return nullptr;
81 if (IsClassCode())
82 return StringPool::GetSystemPool().Intern(m_opaque_sp->GetPythonCode());
83
84 return StringPool::GetSystemPool().Intern(m_opaque_sp->GetPythonClassName());
85}
86
87void SBTypeSynthetic::SetClassName(const char *data) {
88 LLDB_INSTRUMENT_VA(this, data);
89
90 if (IsValid() && data && *data)
91 m_opaque_sp->SetPythonClassName(data);
92}
93
94void SBTypeSynthetic::SetClassCode(const char *data) {
95 LLDB_INSTRUMENT_VA(this, data);
96
97 if (IsValid() && data && *data)
98 m_opaque_sp->SetPythonCode(data);
99}
100
102 LLDB_INSTRUMENT_VA(this);
103
104 if (!IsValid())
105 return lldb::eTypeOptionNone;
106 return m_opaque_sp->GetOptions();
107}
108
109void SBTypeSynthetic::SetOptions(uint32_t value) {
110 LLDB_INSTRUMENT_VA(this, value);
111
112 if (!CopyOnWrite_Impl())
113 return;
114 m_opaque_sp->SetOptions(value);
115}
116
118 lldb::DescriptionLevel description_level) {
119 LLDB_INSTRUMENT_VA(this, description, description_level);
120
121 if (m_opaque_sp) {
122 description.Printf("%s\n", m_opaque_sp->GetDescription().c_str());
123 return true;
124 }
125 return false;
126}
127
130 LLDB_INSTRUMENT_VA(this, rhs);
131
132 if (this != &rhs) {
134 }
135 return *this;
136}
137
139 LLDB_INSTRUMENT_VA(this, rhs);
140
141 if (!IsValid())
142 return !rhs.IsValid();
143 return m_opaque_sp == rhs.m_opaque_sp;
144}
145
147 LLDB_INSTRUMENT_VA(this, rhs);
148
149 if (!IsValid())
150 return !rhs.IsValid();
151 if (!rhs.IsValid())
152 return false;
153
154 if (m_opaque_sp->IsScripted() != rhs.m_opaque_sp->IsScripted())
155 return false;
156
157 if (IsClassCode() != rhs.IsClassCode())
158 return false;
159
160 if (strcmp(GetData(), rhs.GetData()))
161 return false;
162
163 return GetOptions() == rhs.GetOptions();
164}
165
167 LLDB_INSTRUMENT_VA(this, rhs);
168
169 if (!IsValid())
170 return rhs.IsValid();
171 return m_opaque_sp != rhs.m_opaque_sp;
172}
173
177
179 const lldb::ScriptedSyntheticChildrenSP &TypeSynthetic_impl_sp) {
180 m_opaque_sp = TypeSynthetic_impl_sp;
181}
182
184 const lldb::ScriptedSyntheticChildrenSP &TypeSynthetic_impl_sp)
185 : m_opaque_sp(TypeSynthetic_impl_sp) {}
186
188 if (!IsValid())
189 return false;
190 if (m_opaque_sp.use_count() == 1)
191 return true;
192
194 m_opaque_sp->GetOptions(), m_opaque_sp->GetPythonClassName(),
195 m_opaque_sp->GetPythonCode()));
196
197 SetSP(new_sp);
198
199 return true;
200}
#define LLDB_INSTRUMENT_VA(...)
bool operator==(lldb::SBTypeSynthetic &rhs)
lldb::SBTypeSynthetic & operator=(const lldb::SBTypeSynthetic &rhs)
static SBTypeSynthetic CreateWithScriptCode(const char *data, uint32_t options=0)
lldb::ScriptedSyntheticChildrenSP GetSP()
bool operator!=(lldb::SBTypeSynthetic &rhs)
void SetSP(const lldb::ScriptedSyntheticChildrenSP &typefilter_impl_sp)
bool GetDescription(lldb::SBStream &description, lldb::DescriptionLevel description_level)
void SetClassName(const char *data)
void SetClassCode(const char *data)
bool IsEqualTo(lldb::SBTypeSynthetic &rhs)
static SBTypeSynthetic CreateWithClassName(const char *data, uint32_t options=0)
lldb::ScriptedSyntheticChildrenSP m_opaque_sp
const char * Intern(llvm::StringRef str) const
Definition StringPool.h:78
static StringPoolRef GetSystemPool()
The system pool. Only valid between Initialize and Terminate.
A class that represents a running process on the host machine.
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
std::shared_ptr< lldb_private::ScriptedSyntheticChildren > ScriptedSyntheticChildrenSP