]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/tools/lldb/source/API/SBTypeFormat.cpp
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / llvm / tools / lldb / source / API / SBTypeFormat.cpp
1 //===-- SBTypeFormat.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/SBTypeFormat.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
21 SBTypeFormat::SBTypeFormat() :
22 m_opaque_sp()
23 {
24 }
25
26 SBTypeFormat::SBTypeFormat (lldb::Format format,
27                             uint32_t options)
28 : m_opaque_sp(TypeFormatImplSP(new TypeFormatImpl_Format(format,options)))
29 {
30 }
31
32 SBTypeFormat::SBTypeFormat (const char* type,
33                             uint32_t options)
34 : m_opaque_sp(TypeFormatImplSP(new TypeFormatImpl_EnumType(ConstString(type ? type : ""),options)))
35 {
36 }
37
38 SBTypeFormat::SBTypeFormat (const lldb::SBTypeFormat &rhs) :
39 m_opaque_sp(rhs.m_opaque_sp)
40 {
41 }
42
43 SBTypeFormat::~SBTypeFormat ()
44 {
45 }
46
47 bool
48 SBTypeFormat::IsValid() const
49 {
50     return m_opaque_sp.get() != NULL;
51 }
52
53 lldb::Format
54 SBTypeFormat::GetFormat ()
55 {
56     if (IsValid() && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat)
57         return ((TypeFormatImpl_Format*)m_opaque_sp.get())->GetFormat();
58     return lldb::eFormatInvalid;
59 }
60
61 const char*
62 SBTypeFormat::GetTypeName ()
63 {
64     if (IsValid() && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeEnum)
65         return ((TypeFormatImpl_EnumType*)m_opaque_sp.get())->GetTypeName().AsCString("");
66     return "";
67 }
68
69 uint32_t
70 SBTypeFormat::GetOptions()
71 {
72     if (IsValid())
73         return m_opaque_sp->GetOptions();
74     return 0;
75 }
76
77 void
78 SBTypeFormat::SetFormat (lldb::Format fmt)
79 {
80     if (CopyOnWrite_Impl(Type::eTypeFormat))
81         ((TypeFormatImpl_Format*)m_opaque_sp.get())->SetFormat(fmt);
82 }
83
84 void
85 SBTypeFormat::SetTypeName (const char* type)
86 {
87     if (CopyOnWrite_Impl(Type::eTypeEnum))
88         ((TypeFormatImpl_EnumType*)m_opaque_sp.get())->SetTypeName(ConstString(type ? type : ""));
89 }
90
91 void
92 SBTypeFormat::SetOptions (uint32_t value)
93 {
94     if (CopyOnWrite_Impl(Type::eTypeKeepSame))
95         m_opaque_sp->SetOptions(value);
96 }
97
98 bool
99 SBTypeFormat::GetDescription (lldb::SBStream &description, 
100                               lldb::DescriptionLevel description_level)
101 {
102     if (!IsValid())
103         return false;
104     else {
105         description.Printf("%s\n",
106                            m_opaque_sp->GetDescription().c_str());
107         return true;
108     }
109 }
110
111 lldb::SBTypeFormat &
112 SBTypeFormat::operator = (const lldb::SBTypeFormat &rhs)
113 {
114     if (this != &rhs)
115     {
116         m_opaque_sp = rhs.m_opaque_sp;
117     }
118     return *this;
119 }
120
121 bool
122 SBTypeFormat::operator == (lldb::SBTypeFormat &rhs)
123 {
124     if (IsValid() == false)
125         return !rhs.IsValid();
126     return m_opaque_sp == rhs.m_opaque_sp;
127 }
128
129 bool
130 SBTypeFormat::IsEqualTo (lldb::SBTypeFormat &rhs)
131 {
132     if (IsValid() == false)
133         return !rhs.IsValid();
134     
135     if (GetFormat() == rhs.GetFormat())
136         return GetOptions() == rhs.GetOptions();
137     else
138         return false;
139 }
140
141 bool
142 SBTypeFormat::operator != (lldb::SBTypeFormat &rhs)
143 {
144     if (IsValid() == false)
145         return !rhs.IsValid();
146     return m_opaque_sp != rhs.m_opaque_sp;
147 }
148
149 lldb::TypeFormatImplSP
150 SBTypeFormat::GetSP ()
151 {
152     return m_opaque_sp;
153 }
154
155 void
156 SBTypeFormat::SetSP (const lldb::TypeFormatImplSP &typeformat_impl_sp)
157 {
158     m_opaque_sp = typeformat_impl_sp;
159 }
160
161 SBTypeFormat::SBTypeFormat (const lldb::TypeFormatImplSP &typeformat_impl_sp) :
162     m_opaque_sp(typeformat_impl_sp)
163 {
164 }
165
166 bool
167 SBTypeFormat::CopyOnWrite_Impl(Type type)
168 {
169     if (!IsValid())
170         return false;
171     
172     if (m_opaque_sp.unique() &&
173         ((type == Type::eTypeKeepSame) ||
174          (type == Type::eTypeFormat && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat) ||
175          (type == Type::eTypeEnum && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeEnum))
176         )
177         return true;
178
179     if (type == Type::eTypeKeepSame)
180     {
181         if (m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat)
182             type = Type::eTypeFormat;
183         else
184             type = Type::eTypeEnum;
185     }
186     
187     if (type == Type::eTypeFormat)
188         SetSP(TypeFormatImplSP(new TypeFormatImpl_Format(GetFormat(),GetOptions())));
189     else
190         SetSP(TypeFormatImplSP(new TypeFormatImpl_EnumType(ConstString(GetTypeName()),GetOptions())));
191     
192     return true;
193 }