1 //===-- SBTypeNameSpecifier.cpp ------------------------------------*- C++
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
8 //===----------------------------------------------------------------------===//
10 #include "lldb/API/SBTypeNameSpecifier.h"
11 #include "SBReproducerPrivate.h"
13 #include "lldb/API/SBStream.h"
14 #include "lldb/API/SBType.h"
16 #include "lldb/DataFormatters/DataVisualization.h"
19 using namespace lldb_private
;
21 SBTypeNameSpecifier::SBTypeNameSpecifier() : m_opaque_sp() {
22 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTypeNameSpecifier
);
25 SBTypeNameSpecifier::SBTypeNameSpecifier(const char *name
, bool is_regex
)
26 : m_opaque_sp(new TypeNameSpecifierImpl(name
, is_regex
)) {
27 LLDB_RECORD_CONSTRUCTOR(SBTypeNameSpecifier
, (const char *, bool), name
,
30 if (name
== nullptr || (*name
) == 0)
34 SBTypeNameSpecifier::SBTypeNameSpecifier(SBType type
) : m_opaque_sp() {
35 LLDB_RECORD_CONSTRUCTOR(SBTypeNameSpecifier
, (lldb::SBType
), type
);
38 m_opaque_sp
= TypeNameSpecifierImplSP(
39 new TypeNameSpecifierImpl(type
.m_opaque_sp
->GetCompilerType(true)));
42 SBTypeNameSpecifier::SBTypeNameSpecifier(const lldb::SBTypeNameSpecifier
&rhs
)
43 : m_opaque_sp(rhs
.m_opaque_sp
) {
44 LLDB_RECORD_CONSTRUCTOR(SBTypeNameSpecifier
,
45 (const lldb::SBTypeNameSpecifier
&), rhs
);
48 SBTypeNameSpecifier::~SBTypeNameSpecifier() {}
50 bool SBTypeNameSpecifier::IsValid() const {
51 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeNameSpecifier
, IsValid
);
52 return this->operator bool();
54 SBTypeNameSpecifier::operator bool() const {
55 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeNameSpecifier
, operator bool);
57 return m_opaque_sp
.get() != nullptr;
60 const char *SBTypeNameSpecifier::GetName() {
61 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeNameSpecifier
, GetName
);
66 return m_opaque_sp
->GetName();
69 SBType
SBTypeNameSpecifier::GetType() {
70 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType
, SBTypeNameSpecifier
, GetType
);
73 return LLDB_RECORD_RESULT(SBType());
74 lldb_private::CompilerType c_type
= m_opaque_sp
->GetCompilerType();
76 return LLDB_RECORD_RESULT(SBType(c_type
));
77 return LLDB_RECORD_RESULT(SBType());
80 bool SBTypeNameSpecifier::IsRegex() {
81 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTypeNameSpecifier
, IsRegex
);
86 return m_opaque_sp
->IsRegex();
89 bool SBTypeNameSpecifier::GetDescription(
90 lldb::SBStream
&description
, lldb::DescriptionLevel description_level
) {
91 LLDB_RECORD_METHOD(bool, SBTypeNameSpecifier
, GetDescription
,
92 (lldb::SBStream
&, lldb::DescriptionLevel
), description
,
97 description
.Printf("SBTypeNameSpecifier(%s,%s)", GetName(),
98 IsRegex() ? "regex" : "plain");
102 lldb::SBTypeNameSpecifier
&SBTypeNameSpecifier::
103 operator=(const lldb::SBTypeNameSpecifier
&rhs
) {
105 lldb::SBTypeNameSpecifier
&,
106 SBTypeNameSpecifier
, operator=,(const lldb::SBTypeNameSpecifier
&), rhs
);
109 m_opaque_sp
= rhs
.m_opaque_sp
;
111 return LLDB_RECORD_RESULT(*this);
114 bool SBTypeNameSpecifier::operator==(lldb::SBTypeNameSpecifier
&rhs
) {
116 bool, SBTypeNameSpecifier
, operator==,(lldb::SBTypeNameSpecifier
&), rhs
);
119 return !rhs
.IsValid();
120 return m_opaque_sp
== rhs
.m_opaque_sp
;
123 bool SBTypeNameSpecifier::IsEqualTo(lldb::SBTypeNameSpecifier
&rhs
) {
124 LLDB_RECORD_METHOD(bool, SBTypeNameSpecifier
, IsEqualTo
,
125 (lldb::SBTypeNameSpecifier
&), rhs
);
128 return !rhs
.IsValid();
130 if (IsRegex() != rhs
.IsRegex())
132 if (GetName() == nullptr || rhs
.GetName() == nullptr)
135 return (strcmp(GetName(), rhs
.GetName()) == 0);
138 bool SBTypeNameSpecifier::operator!=(lldb::SBTypeNameSpecifier
&rhs
) {
140 bool, SBTypeNameSpecifier
, operator!=,(lldb::SBTypeNameSpecifier
&), rhs
);
143 return !rhs
.IsValid();
144 return m_opaque_sp
!= rhs
.m_opaque_sp
;
147 lldb::TypeNameSpecifierImplSP
SBTypeNameSpecifier::GetSP() {
151 void SBTypeNameSpecifier::SetSP(
152 const lldb::TypeNameSpecifierImplSP
&type_namespec_sp
) {
153 m_opaque_sp
= type_namespec_sp
;
156 SBTypeNameSpecifier::SBTypeNameSpecifier(
157 const lldb::TypeNameSpecifierImplSP
&type_namespec_sp
)
158 : m_opaque_sp(type_namespec_sp
) {}
160 namespace lldb_private
{
164 void RegisterMethods
<SBTypeNameSpecifier
>(Registry
&R
) {
165 LLDB_REGISTER_CONSTRUCTOR(SBTypeNameSpecifier
, ());
166 LLDB_REGISTER_CONSTRUCTOR(SBTypeNameSpecifier
, (const char *, bool));
167 LLDB_REGISTER_CONSTRUCTOR(SBTypeNameSpecifier
, (lldb::SBType
));
168 LLDB_REGISTER_CONSTRUCTOR(SBTypeNameSpecifier
,
169 (const lldb::SBTypeNameSpecifier
&));
170 LLDB_REGISTER_METHOD_CONST(bool, SBTypeNameSpecifier
, IsValid
, ());
171 LLDB_REGISTER_METHOD_CONST(bool, SBTypeNameSpecifier
, operator bool, ());
172 LLDB_REGISTER_METHOD(const char *, SBTypeNameSpecifier
, GetName
, ());
173 LLDB_REGISTER_METHOD(lldb::SBType
, SBTypeNameSpecifier
, GetType
, ());
174 LLDB_REGISTER_METHOD(bool, SBTypeNameSpecifier
, IsRegex
, ());
175 LLDB_REGISTER_METHOD(bool, SBTypeNameSpecifier
, GetDescription
,
176 (lldb::SBStream
&, lldb::DescriptionLevel
));
177 LLDB_REGISTER_METHOD(
178 lldb::SBTypeNameSpecifier
&,
179 SBTypeNameSpecifier
, operator=,(const lldb::SBTypeNameSpecifier
&));
180 LLDB_REGISTER_METHOD(
181 bool, SBTypeNameSpecifier
, operator==,(lldb::SBTypeNameSpecifier
&));
182 LLDB_REGISTER_METHOD(bool, SBTypeNameSpecifier
, IsEqualTo
,
183 (lldb::SBTypeNameSpecifier
&));
184 LLDB_REGISTER_METHOD(
185 bool, SBTypeNameSpecifier
, operator!=,(lldb::SBTypeNameSpecifier
&));