1 //===-- Declaration.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/Symbol/Declaration.h" 11 #include "lldb/Core/Stream.h" 12 13 using namespace lldb_private; 14 15 void 16 Declaration::Dump(Stream *s, bool show_fullpaths) const 17 { 18 if (m_file) 19 { 20 *s << ", decl = "; 21 if (show_fullpaths) 22 *s << m_file; 23 else 24 *s << m_file.GetFilename(); 25 if (m_line > 0) 26 s->Printf(":%u", m_line); 27 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS 28 if (m_column > 0) 29 s->Printf(":%u", m_column); 30 #endif 31 } 32 else 33 { 34 if (m_line > 0) 35 { 36 s->Printf(", line = %u", m_line); 37 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS 38 if (m_column > 0) 39 s->Printf(":%u", m_column); 40 #endif 41 } 42 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS 43 else if (m_column > 0) 44 s->Printf(", column = %u", m_column); 45 #endif 46 } 47 } 48 49 bool 50 Declaration::DumpStopContext (Stream *s, bool show_fullpaths) const 51 { 52 if (m_file) 53 { 54 if (show_fullpaths || s->GetVerbose()) 55 *s << m_file; 56 else 57 m_file.GetFilename().Dump(s); 58 59 if (m_line > 0) 60 s->Printf(":%u", m_line); 61 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS 62 if (m_column > 0) 63 s->Printf(":%u", m_column); 64 #endif 65 return true; 66 } 67 else if (m_line > 0) 68 { 69 s->Printf(" line %u", m_line); 70 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS 71 if (m_column > 0) 72 s->Printf(":%u", m_column); 73 #endif 74 return true; 75 } 76 return false; 77 } 78 79 size_t 80 Declaration::MemorySize() const 81 { 82 return sizeof(Declaration); 83 } 84 85 int 86 Declaration::Compare(const Declaration& a, const Declaration& b) 87 { 88 int result = FileSpec::Compare(a.m_file, b.m_file, true); 89 if (result) 90 return result; 91 if (a.m_line < b.m_line) 92 return -1; 93 else if (a.m_line > b.m_line) 94 return 1; 95 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS 96 if (a.m_column < b.m_column) 97 return -1; 98 else if (a.m_column > b.m_column) 99 return 1; 100 #endif 101 return 0; 102 } 103 104 bool 105 lldb_private::operator == (const Declaration &lhs, const Declaration &rhs) 106 { 107 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS 108 if (lhs.GetColumn () == rhs.GetColumn ()) 109 if (lhs.GetLine () == rhs.GetLine ()) 110 return lhs.GetFile() == rhs.GetFile(); 111 #else 112 if (lhs.GetLine () == rhs.GetLine ()) 113 return lhs.GetFile() == rhs.GetFile(); 114 #endif 115 return false; 116 } 117 118