[CodeGen][NFC] Remove redundant map lookup (#125342)
[llvm-project.git] / lldb / source / Core / Declaration.cpp
bloba485c4b9ba48a7d5d1d55b1c52808287f8ec92a1
1 //===-- Declaration.cpp ---------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Core/Declaration.h"
10 #include "lldb/Utility/Stream.h"
12 using namespace lldb_private;
14 void Declaration::Dump(Stream *s, bool show_fullpaths) const {
15 if (m_file) {
16 *s << ", decl = ";
17 if (show_fullpaths)
18 *s << m_file;
19 else
20 *s << m_file.GetFilename();
21 if (m_line > 0)
22 s->Printf(":%u", m_line);
23 if (m_column != LLDB_INVALID_COLUMN_NUMBER)
24 s->Printf(":%u", m_column);
25 } else {
26 if (m_line > 0) {
27 s->Printf(", line = %u", m_line);
28 if (m_column != LLDB_INVALID_COLUMN_NUMBER)
29 s->Printf(":%u", m_column);
30 } else if (m_column != LLDB_INVALID_COLUMN_NUMBER)
31 s->Printf(", column = %u", m_column);
35 bool Declaration::DumpStopContext(Stream *s, bool show_fullpaths) const {
36 if (m_file) {
37 if (show_fullpaths)
38 *s << m_file;
39 else
40 m_file.GetFilename().Dump(s);
42 if (m_line > 0)
43 s->Printf(":%u", m_line);
44 if (m_column != LLDB_INVALID_COLUMN_NUMBER)
45 s->Printf(":%u", m_column);
46 return true;
47 } else if (m_line > 0) {
48 s->Printf(" line %u", m_line);
49 if (m_column != LLDB_INVALID_COLUMN_NUMBER)
50 s->Printf(":%u", m_column);
51 return true;
53 return false;
56 size_t Declaration::MemorySize() const { return sizeof(Declaration); }
58 int Declaration::Compare(const Declaration &a, const Declaration &b) {
59 int result = FileSpec::Compare(a.m_file, b.m_file, true);
60 if (result)
61 return result;
62 if (a.m_line < b.m_line)
63 return -1;
64 else if (a.m_line > b.m_line)
65 return 1;
66 if (a.m_column < b.m_column)
67 return -1;
68 else if (a.m_column > b.m_column)
69 return 1;
70 return 0;
73 bool Declaration::FileAndLineEqual(const Declaration &declaration,
74 bool full) const {
75 int file_compare = FileSpec::Compare(this->m_file, declaration.m_file, full);
76 return file_compare == 0 && this->m_line == declaration.m_line;
79 bool lldb_private::operator==(const Declaration &lhs, const Declaration &rhs) {
80 if (lhs.GetColumn() != rhs.GetColumn())
81 return false;
83 return lhs.GetLine() == rhs.GetLine() && lhs.GetFile() == rhs.GetFile();