[RISCV] Reduce redundancy in vnsrl tests
[llvm-project.git] / lldb / source / API / SBTypeNameSpecifier.cpp
blob308b1cd6b2bec854852565167eb7f416c858d4e3
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 //===----------------------------------------------------------------------===//
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"
17 using namespace lldb;
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)
34 m_opaque_sp.reset();
37 SBTypeNameSpecifier::SBTypeNameSpecifier(SBType type) {
38 LLDB_INSTRUMENT_VA(this, type);
40 if (type.IsValid())
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);
65 if (!IsValid())
66 return nullptr;
68 return ConstString(m_opaque_sp->GetName()).GetCString();
71 SBType SBTypeNameSpecifier::GetType() {
72 LLDB_INSTRUMENT_VA(this);
74 if (!IsValid())
75 return SBType();
76 lldb_private::CompilerType c_type = m_opaque_sp->GetCompilerType();
77 if (c_type.IsValid())
78 return SBType(c_type);
79 return SBType();
82 FormatterMatchType SBTypeNameSpecifier::GetMatchType() {
83 LLDB_INSTRUMENT_VA(this);
84 if (!IsValid())
85 return eFormatterMatchExact;
86 return m_opaque_sp->GetMatchType();
89 bool SBTypeNameSpecifier::IsRegex() {
90 LLDB_INSTRUMENT_VA(this);
92 if (!IsValid())
93 return false;
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"
106 : "callback");
107 if (!IsValid())
108 return false;
109 description.Printf("SBTypeNameSpecifier(%s,%s)", GetName(), match_type_str);
110 return true;
113 lldb::SBTypeNameSpecifier &SBTypeNameSpecifier::
114 operator=(const lldb::SBTypeNameSpecifier &rhs) {
115 LLDB_INSTRUMENT_VA(this, rhs);
117 if (this != &rhs) {
118 m_opaque_sp = rhs.m_opaque_sp;
120 return *this;
123 bool SBTypeNameSpecifier::operator==(lldb::SBTypeNameSpecifier &rhs) {
124 LLDB_INSTRUMENT_VA(this, rhs);
126 if (!IsValid())
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);
134 if (!IsValid())
135 return !rhs.IsValid();
137 if (GetMatchType() != rhs.GetMatchType())
138 return false;
139 if (GetName() == nullptr || rhs.GetName() == nullptr)
140 return false;
142 return (strcmp(GetName(), rhs.GetName()) == 0);
145 bool SBTypeNameSpecifier::operator!=(lldb::SBTypeNameSpecifier &rhs) {
146 LLDB_INSTRUMENT_VA(this, rhs);
148 if (!IsValid())
149 return !rhs.IsValid();
150 return m_opaque_sp != rhs.m_opaque_sp;
153 lldb::TypeNameSpecifierImplSP SBTypeNameSpecifier::GetSP() {
154 return m_opaque_sp;
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) {}