blob: 8aea675afeba9df690311e66d4d3a20b3c41a27d [file] [log] [blame]
Enrico Granata10de0902012-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
Greg Claytondf3df252012-10-12 16:23:23 +000016#include <limits.h>
17
Enrico Granata10de0902012-10-10 22:54:17 +000018using namespace lldb;
19using namespace lldb_private;
20
21
22SBDeclaration::SBDeclaration () :
23 m_opaque_ap ()
24{
25}
26
27SBDeclaration::SBDeclaration (const SBDeclaration &rhs) :
28 m_opaque_ap ()
29{
30 if (rhs.IsValid())
31 ref() = rhs.ref();
32}
33
34SBDeclaration::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
41const SBDeclaration &
42SBDeclaration::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
54void
55SBDeclaration::SetDeclaration (const lldb_private::Declaration &lldb_object_ref)
56{
57 ref() = lldb_object_ref;
58}
59
60
61SBDeclaration::~SBDeclaration ()
62{
63}
64
65
66bool
67SBDeclaration::IsValid () const
68{
69 return m_opaque_ap.get() && m_opaque_ap->IsValid();
70}
71
72
73SBFileSpec
74SBDeclaration::GetFileSpec () const
75{
Greg Clayton5160ce52013-03-27 23:08:40 +000076 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000077
Enrico Granata10de0902012-10-10 22:54:17 +000078 SBFileSpec sb_file_spec;
79 if (m_opaque_ap.get() && m_opaque_ap->GetFile())
80 sb_file_spec.SetFileSpec(m_opaque_ap->GetFile());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000081
Enrico Granata10de0902012-10-10 22:54:17 +000082 if (log)
83 {
84 SBStream sstr;
85 sb_file_spec.GetDescription (sstr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000086 log->Printf ("SBLineEntry(%p)::GetFileSpec () => SBFileSpec(%p): %s",
87 static_cast<void*>(m_opaque_ap.get()),
88 static_cast<const void*>(sb_file_spec.get()),
89 sstr.GetData());
Enrico Granata10de0902012-10-10 22:54:17 +000090 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000091
Enrico Granata10de0902012-10-10 22:54:17 +000092 return sb_file_spec;
93}
94
95uint32_t
96SBDeclaration::GetLine () const
97{
Greg Clayton5160ce52013-03-27 23:08:40 +000098 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000099
Enrico Granata10de0902012-10-10 22:54:17 +0000100 uint32_t line = 0;
101 if (m_opaque_ap.get())
102 line = m_opaque_ap->GetLine();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000103
Enrico Granata10de0902012-10-10 22:54:17 +0000104 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000105 log->Printf ("SBLineEntry(%p)::GetLine () => %u",
106 static_cast<void*>(m_opaque_ap.get()), line);
107
Enrico Granata10de0902012-10-10 22:54:17 +0000108 return line;
109}
110
111
112uint32_t
113SBDeclaration::GetColumn () const
114{
115 if (m_opaque_ap.get())
116 return m_opaque_ap->GetColumn();
117 return 0;
118}
119
120void
121SBDeclaration::SetFileSpec (lldb::SBFileSpec filespec)
122{
123 if (filespec.IsValid())
124 ref().SetFile(filespec.ref());
125 else
126 ref().SetFile(FileSpec());
127}
128void
129SBDeclaration::SetLine (uint32_t line)
130{
131 ref().SetLine(line);
132}
133
134void
135SBDeclaration::SetColumn (uint32_t column)
136{
137 ref().SetColumn(column);
138}
139
140
141
142bool
143SBDeclaration::operator == (const SBDeclaration &rhs) const
144{
145 lldb_private::Declaration *lhs_ptr = m_opaque_ap.get();
146 lldb_private::Declaration *rhs_ptr = rhs.m_opaque_ap.get();
147
148 if (lhs_ptr && rhs_ptr)
149 return lldb_private::Declaration::Compare (*lhs_ptr, *rhs_ptr) == 0;
150
151 return lhs_ptr == rhs_ptr;
152}
153
154bool
155SBDeclaration::operator != (const SBDeclaration &rhs) const
156{
157 lldb_private::Declaration *lhs_ptr = m_opaque_ap.get();
158 lldb_private::Declaration *rhs_ptr = rhs.m_opaque_ap.get();
159
160 if (lhs_ptr && rhs_ptr)
161 return lldb_private::Declaration::Compare (*lhs_ptr, *rhs_ptr) != 0;
162
163 return lhs_ptr != rhs_ptr;
164}
165
166const lldb_private::Declaration *
167SBDeclaration::operator->() const
168{
169 return m_opaque_ap.get();
170}
171
172lldb_private::Declaration &
173SBDeclaration::ref()
174{
175 if (m_opaque_ap.get() == NULL)
176 m_opaque_ap.reset (new lldb_private::Declaration ());
177 return *m_opaque_ap;
178}
179
180const lldb_private::Declaration &
181SBDeclaration::ref() const
182{
183 return *m_opaque_ap;
184}
185
186bool
187SBDeclaration::GetDescription (SBStream &description)
188{
189 Stream &strm = description.ref();
190
191 if (m_opaque_ap.get())
192 {
193 char file_path[PATH_MAX*2];
194 m_opaque_ap->GetFile().GetPath (file_path, sizeof (file_path));
195 strm.Printf ("%s:%u", file_path, GetLine());
196 if (GetColumn() > 0)
197 strm.Printf (":%u", GetColumn());
198 }
199 else
200 strm.PutCString ("No value");
201
202 return true;
203}
204
205lldb_private::Declaration *
206SBDeclaration::get ()
207{
208 return m_opaque_ap.get();
209}