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