]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/tools/lldb/source/API/SBDeclaration.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 / SBDeclaration.cpp
1 //===-- SBDeclaration.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/SBDeclaration.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/Core/Log.h"
13 #include "lldb/Core/Stream.h"
14 #include "lldb/Symbol/Declaration.h"
15
16 #include <limits.h>
17
18 using namespace lldb;
19 using namespace lldb_private;
20
21
22 SBDeclaration::SBDeclaration () :
23     m_opaque_ap ()
24 {
25 }
26
27 SBDeclaration::SBDeclaration (const SBDeclaration &rhs) :
28     m_opaque_ap ()
29 {
30     if (rhs.IsValid())
31         ref() = rhs.ref();
32 }
33
34 SBDeclaration::SBDeclaration (const lldb_private::Declaration *lldb_object_ptr) :
35     m_opaque_ap ()
36 {
37     if (lldb_object_ptr)
38         ref() = *lldb_object_ptr;
39 }
40
41 const SBDeclaration &
42 SBDeclaration::operator = (const SBDeclaration &rhs)
43 {
44     if (this != &rhs)
45     {
46         if (rhs.IsValid())
47             ref() = rhs.ref();
48         else
49             m_opaque_ap.reset();
50     }
51     return *this;
52 }
53
54 void
55 SBDeclaration::SetDeclaration (const lldb_private::Declaration &lldb_object_ref)
56 {
57     ref() = lldb_object_ref;
58 }
59
60
61 SBDeclaration::~SBDeclaration ()
62 {
63 }
64
65
66 bool
67 SBDeclaration::IsValid () const
68 {
69     return m_opaque_ap.get() && m_opaque_ap->IsValid();
70 }
71
72
73 SBFileSpec
74 SBDeclaration::GetFileSpec () const
75 {
76     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
77     
78     SBFileSpec sb_file_spec;
79     if (m_opaque_ap.get() && m_opaque_ap->GetFile())
80         sb_file_spec.SetFileSpec(m_opaque_ap->GetFile());
81     
82     if (log)
83     {
84         SBStream sstr;
85         sb_file_spec.GetDescription (sstr);
86         log->Printf ("SBLineEntry(%p)::GetFileSpec () => SBFileSpec(%p): %s", m_opaque_ap.get(),
87                      sb_file_spec.get(), sstr.GetData());
88     }
89     
90     return sb_file_spec;
91 }
92
93 uint32_t
94 SBDeclaration::GetLine () const
95 {
96     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
97     
98     uint32_t line = 0;
99     if (m_opaque_ap.get())
100         line = m_opaque_ap->GetLine();
101     
102     if (log)
103         log->Printf ("SBLineEntry(%p)::GetLine () => %u", m_opaque_ap.get(), line);
104     
105     return line;
106 }
107
108
109 uint32_t
110 SBDeclaration::GetColumn () const
111 {
112     if (m_opaque_ap.get())
113         return m_opaque_ap->GetColumn();
114     return 0;
115 }
116
117 void
118 SBDeclaration::SetFileSpec (lldb::SBFileSpec filespec)
119 {
120     if (filespec.IsValid())
121         ref().SetFile(filespec.ref());
122     else
123         ref().SetFile(FileSpec());
124 }
125 void
126 SBDeclaration::SetLine (uint32_t line)
127 {
128     ref().SetLine(line);
129 }
130
131 void
132 SBDeclaration::SetColumn (uint32_t column)
133 {
134     ref().SetColumn(column);
135 }
136
137
138
139 bool
140 SBDeclaration::operator == (const SBDeclaration &rhs) const
141 {
142     lldb_private::Declaration *lhs_ptr = m_opaque_ap.get();
143     lldb_private::Declaration *rhs_ptr = rhs.m_opaque_ap.get();
144     
145     if (lhs_ptr && rhs_ptr)
146         return lldb_private::Declaration::Compare (*lhs_ptr, *rhs_ptr) == 0;
147     
148     return lhs_ptr == rhs_ptr;
149 }
150
151 bool
152 SBDeclaration::operator != (const SBDeclaration &rhs) const
153 {
154     lldb_private::Declaration *lhs_ptr = m_opaque_ap.get();
155     lldb_private::Declaration *rhs_ptr = rhs.m_opaque_ap.get();
156     
157     if (lhs_ptr && rhs_ptr)
158         return lldb_private::Declaration::Compare (*lhs_ptr, *rhs_ptr) != 0;
159     
160     return lhs_ptr != rhs_ptr;
161 }
162
163 const lldb_private::Declaration *
164 SBDeclaration::operator->() const
165 {
166     return m_opaque_ap.get();
167 }
168
169 lldb_private::Declaration &
170 SBDeclaration::ref()
171 {
172     if (m_opaque_ap.get() == NULL)
173         m_opaque_ap.reset (new lldb_private::Declaration ());
174     return *m_opaque_ap;
175 }
176
177 const lldb_private::Declaration &
178 SBDeclaration::ref() const
179 {
180     return *m_opaque_ap;
181 }
182
183 bool
184 SBDeclaration::GetDescription (SBStream &description)
185 {
186     Stream &strm = description.ref();
187     
188     if (m_opaque_ap.get())
189     {
190         char file_path[PATH_MAX*2];
191         m_opaque_ap->GetFile().GetPath (file_path, sizeof (file_path));
192         strm.Printf ("%s:%u", file_path, GetLine());
193         if (GetColumn() > 0)
194             strm.Printf (":%u", GetColumn());
195     }
196     else
197         strm.PutCString ("No value");
198     
199     return true;
200 }
201
202 lldb_private::Declaration *
203 SBDeclaration::get ()
204 {
205     return m_opaque_ap.get();
206 }