Enrico Granata | 16376ed | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 1 | //===-- SBTypeNameSpecifier.cpp ------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Daniel Malea | d891f9b | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Enrico Granata | 16376ed | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBTypeNameSpecifier.h" |
| 13 | |
| 14 | #include "lldb/API/SBStream.h" |
Enrico Granata | d760907c | 2012-02-17 03:18:30 +0000 | [diff] [blame] | 15 | #include "lldb/API/SBType.h" |
Enrico Granata | 16376ed | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 16 | |
Enrico Granata | f509c5e | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 17 | #include "lldb/DataFormatters/DataVisualization.h" |
Enrico Granata | 16376ed | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 18 | |
| 19 | using namespace lldb; |
| 20 | using namespace lldb_private; |
| 21 | |
| 22 | SBTypeNameSpecifier::SBTypeNameSpecifier() : |
| 23 | m_opaque_sp() |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | SBTypeNameSpecifier::SBTypeNameSpecifier (const char* name, |
| 28 | bool is_regex) : |
| 29 | m_opaque_sp(new TypeNameSpecifierImpl(name, is_regex)) |
| 30 | { |
| 31 | if (name == NULL || (*name) == 0) |
| 32 | m_opaque_sp.reset(); |
| 33 | } |
| 34 | |
Enrico Granata | d760907c | 2012-02-17 03:18:30 +0000 | [diff] [blame] | 35 | SBTypeNameSpecifier::SBTypeNameSpecifier (SBType type) : |
| 36 | m_opaque_sp() |
| 37 | { |
| 38 | if (type.IsValid()) |
| 39 | m_opaque_sp = TypeNameSpecifierImplSP(new TypeNameSpecifierImpl(type.m_opaque_sp->GetClangASTType())); |
| 40 | } |
| 41 | |
Enrico Granata | 16376ed | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 42 | SBTypeNameSpecifier::SBTypeNameSpecifier (const lldb::SBTypeNameSpecifier &rhs) : |
| 43 | m_opaque_sp(rhs.m_opaque_sp) |
| 44 | {} |
| 45 | |
| 46 | SBTypeNameSpecifier::~SBTypeNameSpecifier () |
| 47 | { |
| 48 | } |
| 49 | |
| 50 | bool |
| 51 | SBTypeNameSpecifier::IsValid() const |
| 52 | { |
| 53 | return m_opaque_sp.get() != NULL; |
| 54 | } |
| 55 | |
| 56 | const char* |
| 57 | SBTypeNameSpecifier::GetName () |
| 58 | { |
| 59 | if (!IsValid()) |
| 60 | return NULL; |
| 61 | |
| 62 | return m_opaque_sp->GetName(); |
| 63 | } |
| 64 | |
Enrico Granata | d760907c | 2012-02-17 03:18:30 +0000 | [diff] [blame] | 65 | SBType |
| 66 | SBTypeNameSpecifier::GetType () |
| 67 | { |
| 68 | if (!IsValid()) |
| 69 | return SBType(); |
| 70 | lldb_private::ClangASTType c_type = m_opaque_sp->GetClangASTType(); |
| 71 | if (c_type.IsValid()) |
| 72 | return SBType(c_type); |
| 73 | return SBType(); |
| 74 | } |
| 75 | |
Enrico Granata | 16376ed | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 76 | bool |
| 77 | SBTypeNameSpecifier::IsRegex () |
| 78 | { |
| 79 | if (!IsValid()) |
| 80 | return false; |
| 81 | |
| 82 | return m_opaque_sp->IsRegex(); |
| 83 | } |
| 84 | |
| 85 | bool |
| 86 | SBTypeNameSpecifier::GetDescription (lldb::SBStream &description, |
| 87 | lldb::DescriptionLevel description_level) |
| 88 | { |
| 89 | if (!IsValid()) |
| 90 | return false; |
| 91 | description.Printf("SBTypeNameSpecifier(%s,%s)", GetName(), IsRegex() ? "regex" : "plain"); |
| 92 | return true; |
| 93 | } |
| 94 | |
| 95 | lldb::SBTypeNameSpecifier & |
| 96 | SBTypeNameSpecifier::operator = (const lldb::SBTypeNameSpecifier &rhs) |
| 97 | { |
| 98 | if (this != &rhs) |
| 99 | { |
| 100 | m_opaque_sp = rhs.m_opaque_sp; |
| 101 | } |
| 102 | return *this; |
| 103 | } |
| 104 | |
| 105 | bool |
| 106 | SBTypeNameSpecifier::operator == (lldb::SBTypeNameSpecifier &rhs) |
| 107 | { |
| 108 | if (IsValid() == false) |
| 109 | return !rhs.IsValid(); |
| 110 | return m_opaque_sp == rhs.m_opaque_sp; |
| 111 | } |
| 112 | |
| 113 | bool |
| 114 | SBTypeNameSpecifier::IsEqualTo (lldb::SBTypeNameSpecifier &rhs) |
| 115 | { |
| 116 | if (IsValid() == false) |
| 117 | return !rhs.IsValid(); |
| 118 | |
| 119 | if (IsRegex() != rhs.IsRegex()) |
| 120 | return false; |
Jim Ingham | 6f01c93 | 2012-10-12 17:34:26 +0000 | [diff] [blame] | 121 | if (GetName() == NULL || rhs.GetName() == NULL) |
| 122 | return false; |
Enrico Granata | 16376ed | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 123 | |
| 124 | return (strcmp(GetName(), rhs.GetName()) == 0); |
| 125 | } |
| 126 | |
| 127 | bool |
| 128 | SBTypeNameSpecifier::operator != (lldb::SBTypeNameSpecifier &rhs) |
| 129 | { |
| 130 | if (IsValid() == false) |
| 131 | return !rhs.IsValid(); |
| 132 | return m_opaque_sp != rhs.m_opaque_sp; |
| 133 | } |
| 134 | |
| 135 | lldb::TypeNameSpecifierImplSP |
| 136 | SBTypeNameSpecifier::GetSP () |
| 137 | { |
| 138 | return m_opaque_sp; |
| 139 | } |
| 140 | |
| 141 | void |
| 142 | SBTypeNameSpecifier::SetSP (const lldb::TypeNameSpecifierImplSP &type_namespec_sp) |
| 143 | { |
| 144 | m_opaque_sp = type_namespec_sp; |
| 145 | } |
| 146 | |
| 147 | SBTypeNameSpecifier::SBTypeNameSpecifier (const lldb::TypeNameSpecifierImplSP &type_namespec_sp) : |
| 148 | m_opaque_sp(type_namespec_sp) |
| 149 | { |
| 150 | } |