Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1 | //===-- SBDeclaration.cpp -----------------------------------------*- C++ |
| 2 | //-*-===// |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 3 | // |
| 4 | // The LLVM Compiler Infrastructure |
| 5 | // |
| 6 | // This file is distributed under the University of Illinois Open Source |
| 7 | // License. See LICENSE.TXT for details. |
| 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #include "lldb/API/SBDeclaration.h" |
| 12 | #include "lldb/API/SBStream.h" |
| 13 | #include "lldb/Core/Log.h" |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 14 | #include "lldb/Symbol/Declaration.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame^] | 15 | #include "lldb/Utility/Stream.h" |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 16 | |
Greg Clayton | df3df25 | 2012-10-12 16:23:23 +0000 | [diff] [blame] | 17 | #include <limits.h> |
| 18 | |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 19 | using namespace lldb; |
| 20 | using namespace lldb_private; |
| 21 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 22 | SBDeclaration::SBDeclaration() : m_opaque_ap() {} |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 23 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 24 | SBDeclaration::SBDeclaration(const SBDeclaration &rhs) : m_opaque_ap() { |
| 25 | if (rhs.IsValid()) |
| 26 | ref() = rhs.ref(); |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 27 | } |
| 28 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 29 | SBDeclaration::SBDeclaration(const lldb_private::Declaration *lldb_object_ptr) |
| 30 | : m_opaque_ap() { |
| 31 | if (lldb_object_ptr) |
| 32 | ref() = *lldb_object_ptr; |
| 33 | } |
| 34 | |
| 35 | const SBDeclaration &SBDeclaration::operator=(const SBDeclaration &rhs) { |
| 36 | if (this != &rhs) { |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 37 | if (rhs.IsValid()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 38 | ref() = rhs.ref(); |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 39 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 40 | m_opaque_ap.reset(); |
| 41 | } |
| 42 | return *this; |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 45 | void SBDeclaration::SetDeclaration( |
| 46 | const lldb_private::Declaration &lldb_object_ref) { |
| 47 | ref() = lldb_object_ref; |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 50 | SBDeclaration::~SBDeclaration() {} |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 51 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 52 | bool SBDeclaration::IsValid() const { |
| 53 | return m_opaque_ap.get() && m_opaque_ap->IsValid(); |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 56 | SBFileSpec SBDeclaration::GetFileSpec() const { |
| 57 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 58 | |
| 59 | SBFileSpec sb_file_spec; |
| 60 | if (m_opaque_ap.get() && m_opaque_ap->GetFile()) |
| 61 | sb_file_spec.SetFileSpec(m_opaque_ap->GetFile()); |
| 62 | |
| 63 | if (log) { |
| 64 | SBStream sstr; |
| 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()); |
| 69 | } |
| 70 | |
| 71 | return sb_file_spec; |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 74 | uint32_t SBDeclaration::GetLine() const { |
| 75 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 76 | |
| 77 | uint32_t line = 0; |
| 78 | if (m_opaque_ap.get()) |
| 79 | line = m_opaque_ap->GetLine(); |
| 80 | |
| 81 | if (log) |
| 82 | log->Printf("SBLineEntry(%p)::GetLine () => %u", |
| 83 | static_cast<void *>(m_opaque_ap.get()), line); |
| 84 | |
| 85 | return line; |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 88 | uint32_t SBDeclaration::GetColumn() const { |
| 89 | if (m_opaque_ap.get()) |
| 90 | return m_opaque_ap->GetColumn(); |
| 91 | return 0; |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 94 | void SBDeclaration::SetFileSpec(lldb::SBFileSpec filespec) { |
| 95 | if (filespec.IsValid()) |
| 96 | ref().SetFile(filespec.ref()); |
| 97 | else |
| 98 | ref().SetFile(FileSpec()); |
| 99 | } |
| 100 | void SBDeclaration::SetLine(uint32_t line) { ref().SetLine(line); } |
| 101 | |
| 102 | void SBDeclaration::SetColumn(uint32_t column) { ref().SetColumn(column); } |
| 103 | |
| 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(); |
| 107 | |
| 108 | if (lhs_ptr && rhs_ptr) |
| 109 | return lldb_private::Declaration::Compare(*lhs_ptr, *rhs_ptr) == 0; |
| 110 | |
| 111 | return lhs_ptr == rhs_ptr; |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 112 | } |
| 113 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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(); |
| 117 | |
| 118 | if (lhs_ptr && rhs_ptr) |
| 119 | return lldb_private::Declaration::Compare(*lhs_ptr, *rhs_ptr) != 0; |
| 120 | |
| 121 | return lhs_ptr != rhs_ptr; |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 124 | const lldb_private::Declaration *SBDeclaration::operator->() const { |
| 125 | return m_opaque_ap.get(); |
Enrico Granata | 10de090 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 126 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 127 | |
| 128 | lldb_private::Declaration &SBDeclaration::ref() { |
| 129 | if (m_opaque_ap.get() == NULL) |
| 130 | m_opaque_ap.reset(new lldb_private::Declaration()); |
| 131 | return *m_opaque_ap; |
| 132 | } |
| 133 | |
| 134 | const lldb_private::Declaration &SBDeclaration::ref() const { |
| 135 | return *m_opaque_ap; |
| 136 | } |
| 137 | |
| 138 | bool SBDeclaration::GetDescription(SBStream &description) { |
| 139 | Stream &strm = description.ref(); |
| 140 | |
| 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()); |
| 145 | if (GetColumn() > 0) |
| 146 | strm.Printf(":%u", GetColumn()); |
| 147 | } else |
| 148 | strm.PutCString("No value"); |
| 149 | |
| 150 | return true; |
| 151 | } |
| 152 | |
| 153 | lldb_private::Declaration *SBDeclaration::get() { return m_opaque_ap.get(); } |