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/Host/PosixApi.h"
13 #include "lldb/Symbol/Declaration.h"
14 #include "lldb/Utility/Log.h"
15 #include "lldb/Utility/Stream.h"
20 using namespace lldb_private;
22 SBDeclaration::SBDeclaration() : m_opaque_ap() {}
24 SBDeclaration::SBDeclaration(const SBDeclaration &rhs) : m_opaque_ap() {
29 SBDeclaration::SBDeclaration(const lldb_private::Declaration *lldb_object_ptr)
32 ref() = *lldb_object_ptr;
35 const SBDeclaration &SBDeclaration::operator=(const SBDeclaration &rhs) {
45 void SBDeclaration::SetDeclaration(
46 const lldb_private::Declaration &lldb_object_ref) {
47 ref() = lldb_object_ref;
50 SBDeclaration::~SBDeclaration() {}
52 bool SBDeclaration::IsValid() const {
53 return m_opaque_ap.get() && m_opaque_ap->IsValid();
56 SBFileSpec SBDeclaration::GetFileSpec() const {
57 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
59 SBFileSpec sb_file_spec;
60 if (m_opaque_ap.get() && m_opaque_ap->GetFile())
61 sb_file_spec.SetFileSpec(m_opaque_ap->GetFile());
65 sb_file_spec.GetDescription(sstr);
66 log->Printf("SBLineEntry(%p)::GetFileSpec () => SBFileSpec(%p): %s",
67 static_cast<void *>(m_opaque_ap.get()),
68 static_cast<const void *>(sb_file_spec.get()), sstr.GetData());
74 uint32_t SBDeclaration::GetLine() const {
75 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
78 if (m_opaque_ap.get())
79 line = m_opaque_ap->GetLine();
82 log->Printf("SBLineEntry(%p)::GetLine () => %u",
83 static_cast<void *>(m_opaque_ap.get()), line);
88 uint32_t SBDeclaration::GetColumn() const {
89 if (m_opaque_ap.get())
90 return m_opaque_ap->GetColumn();
94 void SBDeclaration::SetFileSpec(lldb::SBFileSpec filespec) {
95 if (filespec.IsValid())
96 ref().SetFile(filespec.ref());
98 ref().SetFile(FileSpec());
100 void SBDeclaration::SetLine(uint32_t line) { ref().SetLine(line); }
102 void SBDeclaration::SetColumn(uint32_t column) { ref().SetColumn(column); }
104 bool SBDeclaration::operator==(const SBDeclaration &rhs) const {
105 lldb_private::Declaration *lhs_ptr = m_opaque_ap.get();
106 lldb_private::Declaration *rhs_ptr = rhs.m_opaque_ap.get();
108 if (lhs_ptr && rhs_ptr)
109 return lldb_private::Declaration::Compare(*lhs_ptr, *rhs_ptr) == 0;
111 return lhs_ptr == rhs_ptr;
114 bool SBDeclaration::operator!=(const SBDeclaration &rhs) const {
115 lldb_private::Declaration *lhs_ptr = m_opaque_ap.get();
116 lldb_private::Declaration *rhs_ptr = rhs.m_opaque_ap.get();
118 if (lhs_ptr && rhs_ptr)
119 return lldb_private::Declaration::Compare(*lhs_ptr, *rhs_ptr) != 0;
121 return lhs_ptr != rhs_ptr;
124 const lldb_private::Declaration *SBDeclaration::operator->() const {
125 return m_opaque_ap.get();
128 lldb_private::Declaration &SBDeclaration::ref() {
129 if (m_opaque_ap.get() == NULL)
130 m_opaque_ap.reset(new lldb_private::Declaration());
134 const lldb_private::Declaration &SBDeclaration::ref() const {
138 bool SBDeclaration::GetDescription(SBStream &description) {
139 Stream &strm = description.ref();
141 if (m_opaque_ap.get()) {
142 char file_path[PATH_MAX * 2];
143 m_opaque_ap->GetFile().GetPath(file_path, sizeof(file_path));
144 strm.Printf("%s:%u", file_path, GetLine());
146 strm.Printf(":%u", GetColumn());
148 strm.PutCString("No value");
153 lldb_private::Declaration *SBDeclaration::get() { return m_opaque_ap.get(); }