1 //===-- SBTypeNameSpecifier.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
9 #include "lldb/API/SBTypeNameSpecifier.h"
10 #include "lldb/Utility/Instrumentation.h"
11
12 #include "lldb/API/SBStream.h"
13 #include "lldb/API/SBType.h"
14
15 #include "lldb/DataFormatters/DataVisualization.h"
16
17 using namespace lldb;
18 using namespace lldb_private;
19
SBTypeNameSpecifier()20 SBTypeNameSpecifier::SBTypeNameSpecifier() { LLDB_INSTRUMENT_VA(this); }
21
SBTypeNameSpecifier(const char * name,bool is_regex)22 SBTypeNameSpecifier::SBTypeNameSpecifier(const char *name, bool is_regex)
23 : m_opaque_sp(new TypeNameSpecifierImpl(name, is_regex)) {
24 LLDB_INSTRUMENT_VA(this, name, is_regex);
25
26 if (name == nullptr || (*name) == 0)
27 m_opaque_sp.reset();
28 }
29
SBTypeNameSpecifier(SBType type)30 SBTypeNameSpecifier::SBTypeNameSpecifier(SBType type) {
31 LLDB_INSTRUMENT_VA(this, type);
32
33 if (type.IsValid())
34 m_opaque_sp = TypeNameSpecifierImplSP(
35 new TypeNameSpecifierImpl(type.m_opaque_sp->GetCompilerType(true)));
36 }
37
SBTypeNameSpecifier(const lldb::SBTypeNameSpecifier & rhs)38 SBTypeNameSpecifier::SBTypeNameSpecifier(const lldb::SBTypeNameSpecifier &rhs)
39 : m_opaque_sp(rhs.m_opaque_sp) {
40 LLDB_INSTRUMENT_VA(this, rhs);
41 }
42
43 SBTypeNameSpecifier::~SBTypeNameSpecifier() = default;
44
IsValid() const45 bool SBTypeNameSpecifier::IsValid() const {
46 LLDB_INSTRUMENT_VA(this);
47 return this->operator bool();
48 }
operator bool() const49 SBTypeNameSpecifier::operator bool() const {
50 LLDB_INSTRUMENT_VA(this);
51
52 return m_opaque_sp.get() != nullptr;
53 }
54
GetName()55 const char *SBTypeNameSpecifier::GetName() {
56 LLDB_INSTRUMENT_VA(this);
57
58 if (!IsValid())
59 return nullptr;
60
61 return m_opaque_sp->GetName();
62 }
63
GetType()64 SBType SBTypeNameSpecifier::GetType() {
65 LLDB_INSTRUMENT_VA(this);
66
67 if (!IsValid())
68 return SBType();
69 lldb_private::CompilerType c_type = m_opaque_sp->GetCompilerType();
70 if (c_type.IsValid())
71 return SBType(c_type);
72 return SBType();
73 }
74
IsRegex()75 bool SBTypeNameSpecifier::IsRegex() {
76 LLDB_INSTRUMENT_VA(this);
77
78 if (!IsValid())
79 return false;
80
81 return m_opaque_sp->IsRegex();
82 }
83
GetDescription(lldb::SBStream & description,lldb::DescriptionLevel description_level)84 bool SBTypeNameSpecifier::GetDescription(
85 lldb::SBStream &description, lldb::DescriptionLevel description_level) {
86 LLDB_INSTRUMENT_VA(this, description, description_level);
87
88 if (!IsValid())
89 return false;
90 description.Printf("SBTypeNameSpecifier(%s,%s)", GetName(),
91 IsRegex() ? "regex" : "plain");
92 return true;
93 }
94
95 lldb::SBTypeNameSpecifier &SBTypeNameSpecifier::
operator =(const lldb::SBTypeNameSpecifier & rhs)96 operator=(const lldb::SBTypeNameSpecifier &rhs) {
97 LLDB_INSTRUMENT_VA(this, rhs);
98
99 if (this != &rhs) {
100 m_opaque_sp = rhs.m_opaque_sp;
101 }
102 return *this;
103 }
104
operator ==(lldb::SBTypeNameSpecifier & rhs)105 bool SBTypeNameSpecifier::operator==(lldb::SBTypeNameSpecifier &rhs) {
106 LLDB_INSTRUMENT_VA(this, rhs);
107
108 if (!IsValid())
109 return !rhs.IsValid();
110 return m_opaque_sp == rhs.m_opaque_sp;
111 }
112
IsEqualTo(lldb::SBTypeNameSpecifier & rhs)113 bool SBTypeNameSpecifier::IsEqualTo(lldb::SBTypeNameSpecifier &rhs) {
114 LLDB_INSTRUMENT_VA(this, rhs);
115
116 if (!IsValid())
117 return !rhs.IsValid();
118
119 if (IsRegex() != rhs.IsRegex())
120 return false;
121 if (GetName() == nullptr || rhs.GetName() == nullptr)
122 return false;
123
124 return (strcmp(GetName(), rhs.GetName()) == 0);
125 }
126
operator !=(lldb::SBTypeNameSpecifier & rhs)127 bool SBTypeNameSpecifier::operator!=(lldb::SBTypeNameSpecifier &rhs) {
128 LLDB_INSTRUMENT_VA(this, rhs);
129
130 if (!IsValid())
131 return !rhs.IsValid();
132 return m_opaque_sp != rhs.m_opaque_sp;
133 }
134
GetSP()135 lldb::TypeNameSpecifierImplSP SBTypeNameSpecifier::GetSP() {
136 return m_opaque_sp;
137 }
138
SetSP(const lldb::TypeNameSpecifierImplSP & type_namespec_sp)139 void SBTypeNameSpecifier::SetSP(
140 const lldb::TypeNameSpecifierImplSP &type_namespec_sp) {
141 m_opaque_sp = type_namespec_sp;
142 }
143
SBTypeNameSpecifier(const lldb::TypeNameSpecifierImplSP & type_namespec_sp)144 SBTypeNameSpecifier::SBTypeNameSpecifier(
145 const lldb::TypeNameSpecifierImplSP &type_namespec_sp)
146 : m_opaque_sp(type_namespec_sp) {}
147