• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- SBTypeFilter.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 
10 #include "lldb/lldb-python.h"
11 
12 #include "lldb/API/SBTypeFilter.h"
13 
14 #include "lldb/API/SBStream.h"
15 
16 #include "lldb/DataFormatters/DataVisualization.h"
17 
18 using namespace lldb;
19 using namespace lldb_private;
20 
SBTypeFilter()21 SBTypeFilter::SBTypeFilter() :
22 m_opaque_sp()
23 {
24 }
25 
SBTypeFilter(uint32_t options)26 SBTypeFilter::SBTypeFilter (uint32_t options)
27 : m_opaque_sp(TypeFilterImplSP(new TypeFilterImpl(options)))
28 {
29 }
30 
SBTypeFilter(const lldb::SBTypeFilter & rhs)31 SBTypeFilter::SBTypeFilter (const lldb::SBTypeFilter &rhs) :
32 m_opaque_sp(rhs.m_opaque_sp)
33 {
34 }
35 
~SBTypeFilter()36 SBTypeFilter::~SBTypeFilter ()
37 {
38 }
39 
40 bool
IsValid() const41 SBTypeFilter::IsValid() const
42 {
43     return m_opaque_sp.get() != NULL;
44 }
45 
46 uint32_t
GetOptions()47 SBTypeFilter::GetOptions()
48 {
49     if (IsValid())
50         return m_opaque_sp->GetOptions();
51     return 0;
52 }
53 
54 void
SetOptions(uint32_t value)55 SBTypeFilter::SetOptions (uint32_t value)
56 {
57     if (CopyOnWrite_Impl())
58         m_opaque_sp->SetOptions(value);
59 }
60 
61 bool
GetDescription(lldb::SBStream & description,lldb::DescriptionLevel description_level)62 SBTypeFilter::GetDescription (lldb::SBStream &description,
63                               lldb::DescriptionLevel description_level)
64 {
65     if (!IsValid())
66         return false;
67     else {
68         description.Printf("%s\n",
69                            m_opaque_sp->GetDescription().c_str());
70         return true;
71     }
72 }
73 
74 void
Clear()75 SBTypeFilter::Clear()
76 {
77     if (CopyOnWrite_Impl())
78         m_opaque_sp->Clear();
79 }
80 
81 uint32_t
GetNumberOfExpressionPaths()82 SBTypeFilter::GetNumberOfExpressionPaths()
83 {
84     if (IsValid())
85         return m_opaque_sp->GetCount();
86     return 0;
87 }
88 
89 const char*
GetExpressionPathAtIndex(uint32_t i)90 SBTypeFilter::GetExpressionPathAtIndex (uint32_t i)
91 {
92     if (IsValid())
93     {
94         const char* item = m_opaque_sp->GetExpressionPathAtIndex(i);
95         if (item && *item == '.')
96             item++;
97         return item;
98     }
99     return NULL;
100 }
101 
102 bool
ReplaceExpressionPathAtIndex(uint32_t i,const char * item)103 SBTypeFilter::ReplaceExpressionPathAtIndex (uint32_t i, const char* item)
104 {
105     if (CopyOnWrite_Impl())
106         return m_opaque_sp->SetExpressionPathAtIndex(i, item);
107     else
108         return false;
109 }
110 
111 void
AppendExpressionPath(const char * item)112 SBTypeFilter::AppendExpressionPath (const char* item)
113 {
114     if (CopyOnWrite_Impl())
115         m_opaque_sp->AddExpressionPath(item);
116 }
117 
118 lldb::SBTypeFilter &
operator =(const lldb::SBTypeFilter & rhs)119 SBTypeFilter::operator = (const lldb::SBTypeFilter &rhs)
120 {
121     if (this != &rhs)
122     {
123         m_opaque_sp = rhs.m_opaque_sp;
124     }
125     return *this;
126 }
127 
128 bool
operator ==(lldb::SBTypeFilter & rhs)129 SBTypeFilter::operator == (lldb::SBTypeFilter &rhs)
130 {
131     if (IsValid() == false)
132         return !rhs.IsValid();
133 
134     return m_opaque_sp == rhs.m_opaque_sp;
135 }
136 
137 bool
IsEqualTo(lldb::SBTypeFilter & rhs)138 SBTypeFilter::IsEqualTo (lldb::SBTypeFilter &rhs)
139 {
140     if (IsValid() == false)
141         return !rhs.IsValid();
142 
143     if (GetNumberOfExpressionPaths() != rhs.GetNumberOfExpressionPaths())
144         return false;
145 
146     for (uint32_t j = 0;
147          j < GetNumberOfExpressionPaths();
148          j++)
149         if ( strcmp(GetExpressionPathAtIndex(j),rhs.GetExpressionPathAtIndex(j)) != 0)
150             return false;
151 
152     return GetOptions() == rhs.GetOptions();
153 }
154 
155 bool
operator !=(lldb::SBTypeFilter & rhs)156 SBTypeFilter::operator != (lldb::SBTypeFilter &rhs)
157 {
158     if (IsValid() == false)
159         return !rhs.IsValid();
160 
161     return m_opaque_sp != rhs.m_opaque_sp;
162 }
163 
164 lldb::TypeFilterImplSP
GetSP()165 SBTypeFilter::GetSP ()
166 {
167     return m_opaque_sp;
168 }
169 
170 void
SetSP(const lldb::TypeFilterImplSP & typefilter_impl_sp)171 SBTypeFilter::SetSP (const lldb::TypeFilterImplSP &typefilter_impl_sp)
172 {
173     m_opaque_sp = typefilter_impl_sp;
174 }
175 
SBTypeFilter(const lldb::TypeFilterImplSP & typefilter_impl_sp)176 SBTypeFilter::SBTypeFilter (const lldb::TypeFilterImplSP &typefilter_impl_sp) :
177 m_opaque_sp(typefilter_impl_sp)
178 {
179 }
180 
181 bool
CopyOnWrite_Impl()182 SBTypeFilter::CopyOnWrite_Impl()
183 {
184     if (!IsValid())
185         return false;
186     if (m_opaque_sp.unique())
187         return true;
188 
189     TypeFilterImplSP new_sp(new TypeFilterImpl(GetOptions()));
190 
191     for (uint32_t j = 0;
192          j < GetNumberOfExpressionPaths();
193          j++)
194         new_sp->AddExpressionPath(GetExpressionPathAtIndex(j));
195 
196     SetSP(new_sp);
197 
198     return true;
199 }
200