1 //===-- SBTypeNameSpecifier.cpp -------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/API/SBTypeNameSpecifier.h"
10 #include "lldb/Utility/Instrumentation.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/API/SBType.h"
15 #include "lldb/DataFormatters/DataVisualization.h"
18 using namespace lldb_private
;
20 SBTypeNameSpecifier::SBTypeNameSpecifier() { LLDB_INSTRUMENT_VA(this); }
22 SBTypeNameSpecifier::SBTypeNameSpecifier(const char *name
, bool is_regex
)
23 : SBTypeNameSpecifier(name
, is_regex
? eFormatterMatchRegex
24 : eFormatterMatchExact
) {
25 LLDB_INSTRUMENT_VA(this, name
, is_regex
);
28 SBTypeNameSpecifier::SBTypeNameSpecifier(const char *name
,
29 FormatterMatchType match_type
)
30 : m_opaque_sp(new TypeNameSpecifierImpl(name
, match_type
)) {
31 LLDB_INSTRUMENT_VA(this, name
, match_type
);
33 if (name
== nullptr || (*name
) == 0)
37 SBTypeNameSpecifier::SBTypeNameSpecifier(SBType type
) {
38 LLDB_INSTRUMENT_VA(this, type
);
41 m_opaque_sp
= TypeNameSpecifierImplSP(
42 new TypeNameSpecifierImpl(type
.m_opaque_sp
->GetCompilerType(true)));
45 SBTypeNameSpecifier::SBTypeNameSpecifier(const lldb::SBTypeNameSpecifier
&rhs
)
46 : m_opaque_sp(rhs
.m_opaque_sp
) {
47 LLDB_INSTRUMENT_VA(this, rhs
);
50 SBTypeNameSpecifier::~SBTypeNameSpecifier() = default;
52 bool SBTypeNameSpecifier::IsValid() const {
53 LLDB_INSTRUMENT_VA(this);
54 return this->operator bool();
56 SBTypeNameSpecifier::operator bool() const {
57 LLDB_INSTRUMENT_VA(this);
59 return m_opaque_sp
.get() != nullptr;
62 const char *SBTypeNameSpecifier::GetName() {
63 LLDB_INSTRUMENT_VA(this);
68 return ConstString(m_opaque_sp
->GetName()).GetCString();
71 SBType
SBTypeNameSpecifier::GetType() {
72 LLDB_INSTRUMENT_VA(this);
76 lldb_private::CompilerType c_type
= m_opaque_sp
->GetCompilerType();
78 return SBType(c_type
);
82 FormatterMatchType
SBTypeNameSpecifier::GetMatchType() {
83 LLDB_INSTRUMENT_VA(this);
85 return eFormatterMatchExact
;
86 return m_opaque_sp
->GetMatchType();
89 bool SBTypeNameSpecifier::IsRegex() {
90 LLDB_INSTRUMENT_VA(this);
95 return m_opaque_sp
->GetMatchType() == eFormatterMatchRegex
;
98 bool SBTypeNameSpecifier::GetDescription(
99 lldb::SBStream
&description
, lldb::DescriptionLevel description_level
) {
100 LLDB_INSTRUMENT_VA(this, description
, description_level
);
102 lldb::FormatterMatchType match_type
= GetMatchType();
103 const char *match_type_str
=
104 (match_type
== eFormatterMatchExact
? "plain"
105 : match_type
== eFormatterMatchRegex
? "regex"
109 description
.Printf("SBTypeNameSpecifier(%s,%s)", GetName(), match_type_str
);
113 lldb::SBTypeNameSpecifier
&SBTypeNameSpecifier::
114 operator=(const lldb::SBTypeNameSpecifier
&rhs
) {
115 LLDB_INSTRUMENT_VA(this, rhs
);
118 m_opaque_sp
= rhs
.m_opaque_sp
;
123 bool SBTypeNameSpecifier::operator==(lldb::SBTypeNameSpecifier
&rhs
) {
124 LLDB_INSTRUMENT_VA(this, rhs
);
127 return !rhs
.IsValid();
128 return m_opaque_sp
== rhs
.m_opaque_sp
;
131 bool SBTypeNameSpecifier::IsEqualTo(lldb::SBTypeNameSpecifier
&rhs
) {
132 LLDB_INSTRUMENT_VA(this, rhs
);
135 return !rhs
.IsValid();
137 if (GetMatchType() != rhs
.GetMatchType())
139 if (GetName() == nullptr || rhs
.GetName() == nullptr)
142 return (strcmp(GetName(), rhs
.GetName()) == 0);
145 bool SBTypeNameSpecifier::operator!=(lldb::SBTypeNameSpecifier
&rhs
) {
146 LLDB_INSTRUMENT_VA(this, rhs
);
149 return !rhs
.IsValid();
150 return m_opaque_sp
!= rhs
.m_opaque_sp
;
153 lldb::TypeNameSpecifierImplSP
SBTypeNameSpecifier::GetSP() {
157 void SBTypeNameSpecifier::SetSP(
158 const lldb::TypeNameSpecifierImplSP
&type_namespec_sp
) {
159 m_opaque_sp
= type_namespec_sp
;
162 SBTypeNameSpecifier::SBTypeNameSpecifier(
163 const lldb::TypeNameSpecifierImplSP
&type_namespec_sp
)
164 : m_opaque_sp(type_namespec_sp
) {}