1 //===-- Declaration.cpp -----------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Symbol/Declaration.h"
10 #include "lldb/Utility/Stream.h"
12 using namespace lldb_private;
14 void Declaration::Dump(Stream *s, bool show_fullpaths) const {
20 *s << m_file.GetFilename();
22 s->Printf(":%u", m_line);
23 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
25 s->Printf(":%u", m_column);
29 s->Printf(", line = %u", m_line);
30 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
32 s->Printf(":%u", m_column);
35 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
36 else if (m_column > 0)
37 s->Printf(", column = %u", m_column);
42 bool Declaration::DumpStopContext(Stream *s, bool show_fullpaths) const {
47 m_file.GetFilename().Dump(s);
50 s->Printf(":%u", m_line);
51 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
53 s->Printf(":%u", m_column);
56 } else if (m_line > 0) {
57 s->Printf(" line %u", m_line);
58 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
60 s->Printf(":%u", m_column);
67 size_t Declaration::MemorySize() const { return sizeof(Declaration); }
69 int Declaration::Compare(const Declaration &a, const Declaration &b) {
70 int result = FileSpec::Compare(a.m_file, b.m_file, true);
73 if (a.m_line < b.m_line)
75 else if (a.m_line > b.m_line)
77 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
78 if (a.m_column < b.m_column)
80 else if (a.m_column > b.m_column)
86 bool Declaration::FileAndLineEqual(const Declaration &declaration) const {
87 int file_compare = FileSpec::Compare(this->m_file, declaration.m_file, true);
88 return file_compare == 0 && this->m_line == declaration.m_line;
91 bool lldb_private::operator==(const Declaration &lhs, const Declaration &rhs) {
92 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
93 if (lhs.GetColumn() == rhs.GetColumn())
94 if (lhs.GetLine() == rhs.GetLine())
95 return lhs.GetFile() == rhs.GetFile();
97 if (lhs.GetLine() == rhs.GetLine())
98 return FileSpec::Equal(lhs.GetFile(), rhs.GetFile(), true);