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