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 |
| 60 | Declaration::Dump(Stream *s) const |
| 61 | { |
| 62 | if (m_file) |
| 63 | { |
| 64 | *s << ", decl = '" << m_file; |
| 65 | if (m_line > 0) |
| 66 | s->Printf(":%u", m_line); |
| 67 | if (m_column > 0) |
| 68 | s->Printf(":%u", m_column); |
| 69 | s->PutChar('\''); |
| 70 | } |
| 71 | else |
| 72 | { |
| 73 | if (m_line > 0) |
| 74 | { |
| 75 | s->Printf(", line = %u", m_line); |
| 76 | if (m_column > 0) |
| 77 | s->Printf(":%u", m_column); |
| 78 | } |
| 79 | else if (m_column > 0) |
| 80 | s->Printf(", column = %u", m_column); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | void |
| 85 | Declaration::DumpStopContext (Stream *s) const |
| 86 | { |
| 87 | if (m_file) |
| 88 | { |
| 89 | if (s->GetVerbose()) |
| 90 | *s << m_file; |
| 91 | else |
| 92 | m_file.GetFilename().Dump(s); |
| 93 | |
| 94 | if (m_line > 0) |
| 95 | s->Printf(":%u", m_line); |
| 96 | if (m_column > 0) |
| 97 | s->Printf(":%u", m_column); |
| 98 | } |
| 99 | else |
| 100 | { |
| 101 | s->Printf(" line %u", m_line); |
| 102 | if (m_column > 0) |
| 103 | s->Printf(":%u", m_column); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | uint32_t |
| 108 | Declaration::GetColumn() const |
| 109 | { |
| 110 | return m_column; |
| 111 | } |
| 112 | |
| 113 | FileSpec& |
| 114 | Declaration::GetFile() |
| 115 | { |
| 116 | return m_file; |
| 117 | } |
| 118 | |
| 119 | const FileSpec& |
| 120 | Declaration::GetFile() const |
| 121 | { |
| 122 | return m_file; |
| 123 | } |
| 124 | |
| 125 | uint32_t |
| 126 | Declaration::GetLine() const |
| 127 | { |
| 128 | return m_line; |
| 129 | } |
| 130 | |
| 131 | size_t |
| 132 | Declaration::MemorySize() const |
| 133 | { |
| 134 | return sizeof(Declaration); |
| 135 | } |
| 136 | |
| 137 | void |
| 138 | Declaration::SetColumn(uint32_t col) |
| 139 | { |
| 140 | m_column = col; |
| 141 | } |
| 142 | |
| 143 | void |
| 144 | Declaration::SetFile(const FileSpec& file) |
| 145 | { |
| 146 | m_file = file; |
| 147 | } |
| 148 | |
| 149 | void |
| 150 | Declaration::SetLine(uint32_t line) |
| 151 | { |
| 152 | m_line = line; |
| 153 | } |
| 154 | |
| 155 | |
| 156 | |
| 157 | int |
| 158 | Declaration::Compare(const Declaration& a, const Declaration& b) |
| 159 | { |
| 160 | int result = FileSpec::Compare(a.m_file, b.m_file, true); |
| 161 | if (result) |
| 162 | return result; |
| 163 | if (a.m_line < b.m_line) |
| 164 | return -1; |
| 165 | else if (a.m_line > b.m_line) |
| 166 | return 1; |
| 167 | if (a.m_column < b.m_column) |
| 168 | return -1; |
| 169 | else if (a.m_column > b.m_column) |
| 170 | return 1; |
| 171 | return 0; |
| 172 | } |