Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 | Declaration::Declaration() : |
| 16 | m_file(), |
| 17 | m_line(0), |
| 18 | m_column(0) |
| 19 | { |
| 20 | } |
| 21 | |
| 22 | Declaration::Declaration(const FileSpec& f, uint32_t l, uint32_t c) : |
| 23 | m_file(f), |
| 24 | m_line(l), |
| 25 | m_column(c) |
| 26 | { |
| 27 | } |
| 28 | |
| 29 | Declaration::Declaration(const Declaration& rhs) : |
| 30 | m_file(rhs.m_file), |
| 31 | m_line(rhs.m_line), |
| 32 | m_column(rhs.m_column) |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | Declaration::Declaration(const Declaration* decl_ptr) : |
| 37 | m_file(), |
| 38 | m_line(0), |
| 39 | m_column(0) |
| 40 | { |
| 41 | if (decl_ptr != NULL) |
| 42 | *this = *decl_ptr; |
| 43 | } |
| 44 | |
| 45 | bool |
| 46 | Declaration::IsValid() const |
| 47 | { |
| 48 | return m_file && m_line != 0; |
| 49 | } |
| 50 | |
| 51 | void |
| 52 | Declaration::Clear() |
| 53 | { |
| 54 | m_file.Clear(); |
| 55 | m_line= 0; |
| 56 | m_column = 0; |
| 57 | } |
| 58 | |
| 59 | void |
Greg Clayton | 1924e24 | 2010-09-15 05:51:24 +0000 | [diff] [blame] | 60 | Declaration::Dump(Stream *s, bool show_fullpaths) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | { |
| 62 | if (m_file) |
| 63 | { |
Greg Clayton | 1924e24 | 2010-09-15 05:51:24 +0000 | [diff] [blame] | 64 | *s << ", decl = "; |
| 65 | if (show_fullpaths) |
| 66 | *s << m_file; |
| 67 | else |
| 68 | *s << m_file.GetFilename(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 69 | if (m_line > 0) |
| 70 | s->Printf(":%u", m_line); |
| 71 | if (m_column > 0) |
| 72 | s->Printf(":%u", m_column); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 73 | } |
| 74 | else |
| 75 | { |
| 76 | if (m_line > 0) |
| 77 | { |
| 78 | s->Printf(", line = %u", m_line); |
| 79 | if (m_column > 0) |
| 80 | s->Printf(":%u", m_column); |
| 81 | } |
| 82 | else if (m_column > 0) |
| 83 | s->Printf(", column = %u", m_column); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | void |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 88 | Declaration::DumpStopContext (Stream *s, bool show_fullpaths) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 89 | { |
| 90 | if (m_file) |
| 91 | { |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 92 | if (show_fullpaths || s->GetVerbose()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 93 | *s << m_file; |
| 94 | else |
| 95 | m_file.GetFilename().Dump(s); |
| 96 | |
| 97 | if (m_line > 0) |
| 98 | s->Printf(":%u", m_line); |
| 99 | if (m_column > 0) |
| 100 | s->Printf(":%u", m_column); |
| 101 | } |
| 102 | else |
| 103 | { |
| 104 | s->Printf(" line %u", m_line); |
| 105 | if (m_column > 0) |
| 106 | s->Printf(":%u", m_column); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | uint32_t |
| 111 | Declaration::GetColumn() const |
| 112 | { |
| 113 | return m_column; |
| 114 | } |
| 115 | |
| 116 | FileSpec& |
| 117 | Declaration::GetFile() |
| 118 | { |
| 119 | return m_file; |
| 120 | } |
| 121 | |
| 122 | const FileSpec& |
| 123 | Declaration::GetFile() const |
| 124 | { |
| 125 | return m_file; |
| 126 | } |
| 127 | |
| 128 | uint32_t |
| 129 | Declaration::GetLine() const |
| 130 | { |
| 131 | return m_line; |
| 132 | } |
| 133 | |
| 134 | size_t |
| 135 | Declaration::MemorySize() const |
| 136 | { |
| 137 | return sizeof(Declaration); |
| 138 | } |
| 139 | |
| 140 | void |
| 141 | Declaration::SetColumn(uint32_t col) |
| 142 | { |
| 143 | m_column = col; |
| 144 | } |
| 145 | |
| 146 | void |
| 147 | Declaration::SetFile(const FileSpec& file) |
| 148 | { |
| 149 | m_file = file; |
| 150 | } |
| 151 | |
| 152 | void |
| 153 | Declaration::SetLine(uint32_t line) |
| 154 | { |
| 155 | m_line = line; |
| 156 | } |
| 157 | |
| 158 | |
| 159 | |
| 160 | int |
| 161 | Declaration::Compare(const Declaration& a, const Declaration& b) |
| 162 | { |
| 163 | int result = FileSpec::Compare(a.m_file, b.m_file, true); |
| 164 | if (result) |
| 165 | return result; |
| 166 | if (a.m_line < b.m_line) |
| 167 | return -1; |
| 168 | else if (a.m_line > b.m_line) |
| 169 | return 1; |
| 170 | if (a.m_column < b.m_column) |
| 171 | return -1; |
| 172 | else if (a.m_column > b.m_column) |
| 173 | return 1; |
| 174 | return 0; |
| 175 | } |