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",
87 static_cast<void*>(m_opaque_ap.get()),
88 static_cast<const void*>(sb_file_spec.get()),
96 SBDeclaration::GetLine () const
98 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
101 if (m_opaque_ap.get())
102 line = m_opaque_ap->GetLine();
105 log->Printf ("SBLineEntry(%p)::GetLine () => %u",
106 static_cast<void*>(m_opaque_ap.get()), line);
113 SBDeclaration::GetColumn () const
115 if (m_opaque_ap.get())
116 return m_opaque_ap->GetColumn();
121 SBDeclaration::SetFileSpec (lldb::SBFileSpec filespec)
123 if (filespec.IsValid())
124 ref().SetFile(filespec.ref());
126 ref().SetFile(FileSpec());
129 SBDeclaration::SetLine (uint32_t line)
135 SBDeclaration::SetColumn (uint32_t column)
137 ref().SetColumn(column);
143 SBDeclaration::operator == (const SBDeclaration &rhs) const
145 lldb_private::Declaration *lhs_ptr = m_opaque_ap.get();
146 lldb_private::Declaration *rhs_ptr = rhs.m_opaque_ap.get();
148 if (lhs_ptr && rhs_ptr)
149 return lldb_private::Declaration::Compare (*lhs_ptr, *rhs_ptr) == 0;
151 return lhs_ptr == rhs_ptr;
155 SBDeclaration::operator != (const SBDeclaration &rhs) const
157 lldb_private::Declaration *lhs_ptr = m_opaque_ap.get();
158 lldb_private::Declaration *rhs_ptr = rhs.m_opaque_ap.get();
160 if (lhs_ptr && rhs_ptr)
161 return lldb_private::Declaration::Compare (*lhs_ptr, *rhs_ptr) != 0;
163 return lhs_ptr != rhs_ptr;
166 const lldb_private::Declaration *
167 SBDeclaration::operator->() const
169 return m_opaque_ap.get();
172 lldb_private::Declaration &
175 if (m_opaque_ap.get() == NULL)
176 m_opaque_ap.reset (new lldb_private::Declaration ());
180 const lldb_private::Declaration &
181 SBDeclaration::ref() const
187 SBDeclaration::GetDescription (SBStream &description)
189 Stream &strm = description.ref();
191 if (m_opaque_ap.get())
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());
197 strm.Printf (":%u", GetColumn());
200 strm.PutCString ("No value");
205 lldb_private::Declaration *
206 SBDeclaration::get ()
208 return m_opaque_ap.get();