brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.4 KiB · dd81720 Raw
165 lines · cpp
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-exception6//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 17using namespace lldb;18using namespace lldb_private;19 20SBTypeNameSpecifier::SBTypeNameSpecifier() { LLDB_INSTRUMENT_VA(this); }21 22SBTypeNameSpecifier::SBTypeNameSpecifier(const char *name, bool is_regex)23    : SBTypeNameSpecifier(name, is_regex ? eFormatterMatchRegex24                                         : eFormatterMatchExact) {25  LLDB_INSTRUMENT_VA(this, name, is_regex);26}27 28SBTypeNameSpecifier::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);32 33  if (name == nullptr || (*name) == 0)34    m_opaque_sp.reset();35}36 37SBTypeNameSpecifier::SBTypeNameSpecifier(SBType type) {38  LLDB_INSTRUMENT_VA(this, type);39 40  if (type.IsValid())41    m_opaque_sp = std::make_shared<TypeNameSpecifierImpl>(42        type.m_opaque_sp->GetCompilerType(true));43}44 45SBTypeNameSpecifier::SBTypeNameSpecifier(const lldb::SBTypeNameSpecifier &rhs)46    : m_opaque_sp(rhs.m_opaque_sp) {47  LLDB_INSTRUMENT_VA(this, rhs);48}49 50SBTypeNameSpecifier::~SBTypeNameSpecifier() = default;51 52bool SBTypeNameSpecifier::IsValid() const {53  LLDB_INSTRUMENT_VA(this);54  return this->operator bool();55}56SBTypeNameSpecifier::operator bool() const {57  LLDB_INSTRUMENT_VA(this);58 59  return m_opaque_sp.get() != nullptr;60}61 62const char *SBTypeNameSpecifier::GetName() {63  LLDB_INSTRUMENT_VA(this);64 65  if (!IsValid())66    return nullptr;67 68  return ConstString(m_opaque_sp->GetName()).GetCString();69}70 71SBType SBTypeNameSpecifier::GetType() {72  LLDB_INSTRUMENT_VA(this);73 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();80}81 82FormatterMatchType SBTypeNameSpecifier::GetMatchType() {83  LLDB_INSTRUMENT_VA(this);84  if (!IsValid())85    return eFormatterMatchExact;86  return m_opaque_sp->GetMatchType();87}88 89bool SBTypeNameSpecifier::IsRegex() {90  LLDB_INSTRUMENT_VA(this);91 92  if (!IsValid())93    return false;94 95  return m_opaque_sp->GetMatchType() == eFormatterMatchRegex;96}97 98bool SBTypeNameSpecifier::GetDescription(99    lldb::SBStream &description, lldb::DescriptionLevel description_level) {100  LLDB_INSTRUMENT_VA(this, description, description_level);101 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;111}112 113lldb::SBTypeNameSpecifier &SBTypeNameSpecifier::114operator=(const lldb::SBTypeNameSpecifier &rhs) {115  LLDB_INSTRUMENT_VA(this, rhs);116 117  if (this != &rhs) {118    m_opaque_sp = rhs.m_opaque_sp;119  }120  return *this;121}122 123bool SBTypeNameSpecifier::operator==(lldb::SBTypeNameSpecifier &rhs) {124  LLDB_INSTRUMENT_VA(this, rhs);125 126  if (!IsValid())127    return !rhs.IsValid();128  return m_opaque_sp == rhs.m_opaque_sp;129}130 131bool SBTypeNameSpecifier::IsEqualTo(lldb::SBTypeNameSpecifier &rhs) {132  LLDB_INSTRUMENT_VA(this, rhs);133 134  if (!IsValid())135    return !rhs.IsValid();136 137  if (GetMatchType() != rhs.GetMatchType())138    return false;139  if (GetName() == nullptr || rhs.GetName() == nullptr)140    return false;141 142  return (strcmp(GetName(), rhs.GetName()) == 0);143}144 145bool SBTypeNameSpecifier::operator!=(lldb::SBTypeNameSpecifier &rhs) {146  LLDB_INSTRUMENT_VA(this, rhs);147 148  if (!IsValid())149    return !rhs.IsValid();150  return m_opaque_sp != rhs.m_opaque_sp;151}152 153lldb::TypeNameSpecifierImplSP SBTypeNameSpecifier::GetSP() {154  return m_opaque_sp;155}156 157void SBTypeNameSpecifier::SetSP(158    const lldb::TypeNameSpecifierImplSP &type_namespec_sp) {159  m_opaque_sp = type_namespec_sp;160}161 162SBTypeNameSpecifier::SBTypeNameSpecifier(163    const lldb::TypeNameSpecifierImplSP &type_namespec_sp)164    : m_opaque_sp(type_namespec_sp) {}165