Enrico Granata | 4930614 | 2012-10-10 22:54:17 +0000 | [diff] [blame] | 1 | //===-- 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 | |
| 16 | using namespace lldb; |
| 17 | using namespace lldb_private; |
| 18 | |
| 19 | |
| 20 | SBDeclaration::SBDeclaration () : |
| 21 | m_opaque_ap () |
| 22 | { |
| 23 | } |
| 24 | |
| 25 | SBDeclaration::SBDeclaration (const SBDeclaration &rhs) : |
| 26 | m_opaque_ap () |
| 27 | { |
| 28 | if (rhs.IsValid()) |
| 29 | ref() = rhs.ref(); |
| 30 | } |
| 31 | |
| 32 | SBDeclaration::SBDeclaration (const lldb_private::Declaration *lldb_object_ptr) : |
| 33 | m_opaque_ap () |
| 34 | { |
| 35 | if (lldb_object_ptr) |
| 36 | ref() = *lldb_object_ptr; |
| 37 | } |
| 38 | |
| 39 | const SBDeclaration & |
| 40 | SBDeclaration::operator = (const SBDeclaration &rhs) |
| 41 | { |
| 42 | if (this != &rhs) |
| 43 | { |
| 44 | if (rhs.IsValid()) |
| 45 | ref() = rhs.ref(); |
| 46 | else |
| 47 | m_opaque_ap.reset(); |
| 48 | } |
| 49 | return *this; |
| 50 | } |
| 51 | |
| 52 | void |
| 53 | SBDeclaration::SetDeclaration (const lldb_private::Declaration &lldb_object_ref) |
| 54 | { |
| 55 | ref() = lldb_object_ref; |
| 56 | } |
| 57 | |
| 58 | |
| 59 | SBDeclaration::~SBDeclaration () |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | |
| 64 | bool |
| 65 | SBDeclaration::IsValid () const |
| 66 | { |
| 67 | return m_opaque_ap.get() && m_opaque_ap->IsValid(); |
| 68 | } |
| 69 | |
| 70 | |
| 71 | SBFileSpec |
| 72 | SBDeclaration::GetFileSpec () const |
| 73 | { |
| 74 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 75 | |
| 76 | SBFileSpec sb_file_spec; |
| 77 | if (m_opaque_ap.get() && m_opaque_ap->GetFile()) |
| 78 | sb_file_spec.SetFileSpec(m_opaque_ap->GetFile()); |
| 79 | |
| 80 | if (log) |
| 81 | { |
| 82 | SBStream sstr; |
| 83 | sb_file_spec.GetDescription (sstr); |
| 84 | log->Printf ("SBLineEntry(%p)::GetFileSpec () => SBFileSpec(%p): %s", m_opaque_ap.get(), |
| 85 | sb_file_spec.get(), sstr.GetData()); |
| 86 | } |
| 87 | |
| 88 | return sb_file_spec; |
| 89 | } |
| 90 | |
| 91 | uint32_t |
| 92 | SBDeclaration::GetLine () const |
| 93 | { |
| 94 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 95 | |
| 96 | uint32_t line = 0; |
| 97 | if (m_opaque_ap.get()) |
| 98 | line = m_opaque_ap->GetLine(); |
| 99 | |
| 100 | if (log) |
| 101 | log->Printf ("SBLineEntry(%p)::GetLine () => %u", m_opaque_ap.get(), line); |
| 102 | |
| 103 | return line; |
| 104 | } |
| 105 | |
| 106 | |
| 107 | uint32_t |
| 108 | SBDeclaration::GetColumn () const |
| 109 | { |
| 110 | if (m_opaque_ap.get()) |
| 111 | return m_opaque_ap->GetColumn(); |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | void |
| 116 | SBDeclaration::SetFileSpec (lldb::SBFileSpec filespec) |
| 117 | { |
| 118 | if (filespec.IsValid()) |
| 119 | ref().SetFile(filespec.ref()); |
| 120 | else |
| 121 | ref().SetFile(FileSpec()); |
| 122 | } |
| 123 | void |
| 124 | SBDeclaration::SetLine (uint32_t line) |
| 125 | { |
| 126 | ref().SetLine(line); |
| 127 | } |
| 128 | |
| 129 | void |
| 130 | SBDeclaration::SetColumn (uint32_t column) |
| 131 | { |
| 132 | ref().SetColumn(column); |
| 133 | } |
| 134 | |
| 135 | |
| 136 | |
| 137 | bool |
| 138 | SBDeclaration::operator == (const SBDeclaration &rhs) const |
| 139 | { |
| 140 | lldb_private::Declaration *lhs_ptr = m_opaque_ap.get(); |
| 141 | lldb_private::Declaration *rhs_ptr = rhs.m_opaque_ap.get(); |
| 142 | |
| 143 | if (lhs_ptr && rhs_ptr) |
| 144 | return lldb_private::Declaration::Compare (*lhs_ptr, *rhs_ptr) == 0; |
| 145 | |
| 146 | return lhs_ptr == rhs_ptr; |
| 147 | } |
| 148 | |
| 149 | bool |
| 150 | SBDeclaration::operator != (const SBDeclaration &rhs) const |
| 151 | { |
| 152 | lldb_private::Declaration *lhs_ptr = m_opaque_ap.get(); |
| 153 | lldb_private::Declaration *rhs_ptr = rhs.m_opaque_ap.get(); |
| 154 | |
| 155 | if (lhs_ptr && rhs_ptr) |
| 156 | return lldb_private::Declaration::Compare (*lhs_ptr, *rhs_ptr) != 0; |
| 157 | |
| 158 | return lhs_ptr != rhs_ptr; |
| 159 | } |
| 160 | |
| 161 | const lldb_private::Declaration * |
| 162 | SBDeclaration::operator->() const |
| 163 | { |
| 164 | return m_opaque_ap.get(); |
| 165 | } |
| 166 | |
| 167 | lldb_private::Declaration & |
| 168 | SBDeclaration::ref() |
| 169 | { |
| 170 | if (m_opaque_ap.get() == NULL) |
| 171 | m_opaque_ap.reset (new lldb_private::Declaration ()); |
| 172 | return *m_opaque_ap; |
| 173 | } |
| 174 | |
| 175 | const lldb_private::Declaration & |
| 176 | SBDeclaration::ref() const |
| 177 | { |
| 178 | return *m_opaque_ap; |
| 179 | } |
| 180 | |
| 181 | bool |
| 182 | SBDeclaration::GetDescription (SBStream &description) |
| 183 | { |
| 184 | Stream &strm = description.ref(); |
| 185 | |
| 186 | if (m_opaque_ap.get()) |
| 187 | { |
| 188 | char file_path[PATH_MAX*2]; |
| 189 | m_opaque_ap->GetFile().GetPath (file_path, sizeof (file_path)); |
| 190 | strm.Printf ("%s:%u", file_path, GetLine()); |
| 191 | if (GetColumn() > 0) |
| 192 | strm.Printf (":%u", GetColumn()); |
| 193 | } |
| 194 | else |
| 195 | strm.PutCString ("No value"); |
| 196 | |
| 197 | return true; |
| 198 | } |
| 199 | |
| 200 | lldb_private::Declaration * |
| 201 | SBDeclaration::get () |
| 202 | { |
| 203 | return m_opaque_ap.get(); |
| 204 | } |