]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/API/SBTypeFilter.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / API / SBTypeFilter.cpp
1 //===-- SBTypeFilter.cpp ------------------------------------------*- C++
2 //-*-===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #include "lldb/API/SBTypeFilter.h"
12
13 #include "lldb/API/SBStream.h"
14
15 #include "lldb/DataFormatters/DataVisualization.h"
16
17 using namespace lldb;
18 using namespace lldb_private;
19
20 SBTypeFilter::SBTypeFilter() : m_opaque_sp() {}
21
22 SBTypeFilter::SBTypeFilter(uint32_t options)
23     : m_opaque_sp(TypeFilterImplSP(new TypeFilterImpl(options))) {}
24
25 SBTypeFilter::SBTypeFilter(const lldb::SBTypeFilter &rhs)
26     : m_opaque_sp(rhs.m_opaque_sp) {}
27
28 SBTypeFilter::~SBTypeFilter() {}
29
30 bool SBTypeFilter::IsValid() const { return m_opaque_sp.get() != NULL; }
31
32 uint32_t SBTypeFilter::GetOptions() {
33   if (IsValid())
34     return m_opaque_sp->GetOptions();
35   return 0;
36 }
37
38 void SBTypeFilter::SetOptions(uint32_t value) {
39   if (CopyOnWrite_Impl())
40     m_opaque_sp->SetOptions(value);
41 }
42
43 bool SBTypeFilter::GetDescription(lldb::SBStream &description,
44                                   lldb::DescriptionLevel description_level) {
45   if (!IsValid())
46     return false;
47   else {
48     description.Printf("%s\n", m_opaque_sp->GetDescription().c_str());
49     return true;
50   }
51 }
52
53 void SBTypeFilter::Clear() {
54   if (CopyOnWrite_Impl())
55     m_opaque_sp->Clear();
56 }
57
58 uint32_t SBTypeFilter::GetNumberOfExpressionPaths() {
59   if (IsValid())
60     return m_opaque_sp->GetCount();
61   return 0;
62 }
63
64 const char *SBTypeFilter::GetExpressionPathAtIndex(uint32_t i) {
65   if (IsValid()) {
66     const char *item = m_opaque_sp->GetExpressionPathAtIndex(i);
67     if (item && *item == '.')
68       item++;
69     return item;
70   }
71   return NULL;
72 }
73
74 bool SBTypeFilter::ReplaceExpressionPathAtIndex(uint32_t i, const char *item) {
75   if (CopyOnWrite_Impl())
76     return m_opaque_sp->SetExpressionPathAtIndex(i, item);
77   else
78     return false;
79 }
80
81 void SBTypeFilter::AppendExpressionPath(const char *item) {
82   if (CopyOnWrite_Impl())
83     m_opaque_sp->AddExpressionPath(item);
84 }
85
86 lldb::SBTypeFilter &SBTypeFilter::operator=(const lldb::SBTypeFilter &rhs) {
87   if (this != &rhs) {
88     m_opaque_sp = rhs.m_opaque_sp;
89   }
90   return *this;
91 }
92
93 bool SBTypeFilter::operator==(lldb::SBTypeFilter &rhs) {
94   if (!IsValid())
95     return !rhs.IsValid();
96
97   return m_opaque_sp == rhs.m_opaque_sp;
98 }
99
100 bool SBTypeFilter::IsEqualTo(lldb::SBTypeFilter &rhs) {
101   if (!IsValid())
102     return !rhs.IsValid();
103
104   if (GetNumberOfExpressionPaths() != rhs.GetNumberOfExpressionPaths())
105     return false;
106
107   for (uint32_t j = 0; j < GetNumberOfExpressionPaths(); j++)
108     if (strcmp(GetExpressionPathAtIndex(j), rhs.GetExpressionPathAtIndex(j)) !=
109         0)
110       return false;
111
112   return GetOptions() == rhs.GetOptions();
113 }
114
115 bool SBTypeFilter::operator!=(lldb::SBTypeFilter &rhs) {
116   if (!IsValid())
117     return !rhs.IsValid();
118
119   return m_opaque_sp != rhs.m_opaque_sp;
120 }
121
122 lldb::TypeFilterImplSP SBTypeFilter::GetSP() { return m_opaque_sp; }
123
124 void SBTypeFilter::SetSP(const lldb::TypeFilterImplSP &typefilter_impl_sp) {
125   m_opaque_sp = typefilter_impl_sp;
126 }
127
128 SBTypeFilter::SBTypeFilter(const lldb::TypeFilterImplSP &typefilter_impl_sp)
129     : m_opaque_sp(typefilter_impl_sp) {}
130
131 bool SBTypeFilter::CopyOnWrite_Impl() {
132   if (!IsValid())
133     return false;
134   if (m_opaque_sp.unique())
135     return true;
136
137   TypeFilterImplSP new_sp(new TypeFilterImpl(GetOptions()));
138
139   for (uint32_t j = 0; j < GetNumberOfExpressionPaths(); j++)
140     new_sp->AddExpressionPath(GetExpressionPathAtIndex(j));
141
142   SetSP(new_sp);
143
144   return true;
145 }