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