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