1 //===-- SBDeclaration.cpp -----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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"
19 using namespace lldb_private;
22 SBDeclaration::SBDeclaration () :
27 SBDeclaration::SBDeclaration (const SBDeclaration &rhs) :
34 SBDeclaration::SBDeclaration (const lldb_private::Declaration *lldb_object_ptr) :
38 ref() = *lldb_object_ptr;
42 SBDeclaration::operator = (const SBDeclaration &rhs)
55 SBDeclaration::SetDeclaration (const lldb_private::Declaration &lldb_object_ref)
57 ref() = lldb_object_ref;
61 SBDeclaration::~SBDeclaration ()
67 SBDeclaration::IsValid () const
69 return m_opaque_ap.get() && m_opaque_ap->IsValid();
74 SBDeclaration::GetFileSpec () const
76 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
78 SBFileSpec sb_file_spec;
79 if (m_opaque_ap.get() && m_opaque_ap->GetFile())
80 sb_file_spec.SetFileSpec(m_opaque_ap->GetFile());
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());
94 SBDeclaration::GetLine () const
96 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
99 if (m_opaque_ap.get())
100 line = m_opaque_ap->GetLine();
103 log->Printf ("SBLineEntry(%p)::GetLine () => %u", m_opaque_ap.get(), line);
110 SBDeclaration::GetColumn () const
112 if (m_opaque_ap.get())
113 return m_opaque_ap->GetColumn();
118 SBDeclaration::SetFileSpec (lldb::SBFileSpec filespec)
120 if (filespec.IsValid())
121 ref().SetFile(filespec.ref());
123 ref().SetFile(FileSpec());
126 SBDeclaration::SetLine (uint32_t line)
132 SBDeclaration::SetColumn (uint32_t column)
134 ref().SetColumn(column);
140 SBDeclaration::operator == (const SBDeclaration &rhs) const
142 lldb_private::Declaration *lhs_ptr = m_opaque_ap.get();
143 lldb_private::Declaration *rhs_ptr = rhs.m_opaque_ap.get();
145 if (lhs_ptr && rhs_ptr)
146 return lldb_private::Declaration::Compare (*lhs_ptr, *rhs_ptr) == 0;
148 return lhs_ptr == rhs_ptr;
152 SBDeclaration::operator != (const SBDeclaration &rhs) const
154 lldb_private::Declaration *lhs_ptr = m_opaque_ap.get();
155 lldb_private::Declaration *rhs_ptr = rhs.m_opaque_ap.get();
157 if (lhs_ptr && rhs_ptr)
158 return lldb_private::Declaration::Compare (*lhs_ptr, *rhs_ptr) != 0;
160 return lhs_ptr != rhs_ptr;
163 const lldb_private::Declaration *
164 SBDeclaration::operator->() const
166 return m_opaque_ap.get();
169 lldb_private::Declaration &
172 if (m_opaque_ap.get() == NULL)
173 m_opaque_ap.reset (new lldb_private::Declaration ());
177 const lldb_private::Declaration &
178 SBDeclaration::ref() const
184 SBDeclaration::GetDescription (SBStream &description)
186 Stream &strm = description.ref();
188 if (m_opaque_ap.get())
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());
194 strm.Printf (":%u", GetColumn());
197 strm.PutCString ("No value");
202 lldb_private::Declaration *
203 SBDeclaration::get ()
205 return m_opaque_ap.get();