xref: /src/contrib/llvm-project/lldb/source/Core/Declaration.cpp (revision fe6060f10f634930ff71b7c50291ddc610da2475)
1cfca06d7SDimitry Andric //===-- Declaration.cpp ---------------------------------------------------===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste 
9344a3780SDimitry Andric #include "lldb/Core/Declaration.h"
1074a628f7SDimitry Andric #include "lldb/Utility/Stream.h"
11f034231aSEd Maste 
12f034231aSEd Maste using namespace lldb_private;
13f034231aSEd Maste 
Dump(Stream * s,bool show_fullpaths) const1414f1b3e8SDimitry Andric void Declaration::Dump(Stream *s, bool show_fullpaths) const {
1514f1b3e8SDimitry Andric   if (m_file) {
16f034231aSEd Maste     *s << ", decl = ";
17f034231aSEd Maste     if (show_fullpaths)
18f034231aSEd Maste       *s << m_file;
19f034231aSEd Maste     else
20f034231aSEd Maste       *s << m_file.GetFilename();
21f034231aSEd Maste     if (m_line > 0)
22f034231aSEd Maste       s->Printf(":%u", m_line);
23344a3780SDimitry Andric     if (m_column != LLDB_INVALID_COLUMN_NUMBER)
24f034231aSEd Maste       s->Printf(":%u", m_column);
2514f1b3e8SDimitry Andric   } else {
2614f1b3e8SDimitry Andric     if (m_line > 0) {
27f034231aSEd Maste       s->Printf(", line = %u", m_line);
28344a3780SDimitry Andric       if (m_column != LLDB_INVALID_COLUMN_NUMBER)
29f034231aSEd Maste         s->Printf(":%u", m_column);
30344a3780SDimitry Andric     } else if (m_column != LLDB_INVALID_COLUMN_NUMBER)
31f034231aSEd Maste       s->Printf(", column = %u", m_column);
32f034231aSEd Maste   }
33f034231aSEd Maste }
34f034231aSEd Maste 
DumpStopContext(Stream * s,bool show_fullpaths) const3514f1b3e8SDimitry Andric bool Declaration::DumpStopContext(Stream *s, bool show_fullpaths) const {
3614f1b3e8SDimitry Andric   if (m_file) {
3774a628f7SDimitry Andric     if (show_fullpaths)
38f034231aSEd Maste       *s << m_file;
39f034231aSEd Maste     else
40f034231aSEd Maste       m_file.GetFilename().Dump(s);
41f034231aSEd Maste 
42f034231aSEd Maste     if (m_line > 0)
43f034231aSEd Maste       s->Printf(":%u", m_line);
44344a3780SDimitry Andric     if (m_column != LLDB_INVALID_COLUMN_NUMBER)
45f034231aSEd Maste       s->Printf(":%u", m_column);
46f034231aSEd Maste     return true;
4714f1b3e8SDimitry Andric   } else if (m_line > 0) {
48f034231aSEd Maste     s->Printf(" line %u", m_line);
49344a3780SDimitry Andric     if (m_column != LLDB_INVALID_COLUMN_NUMBER)
50f034231aSEd Maste       s->Printf(":%u", m_column);
51f034231aSEd Maste     return true;
52f034231aSEd Maste   }
53f034231aSEd Maste   return false;
54f034231aSEd Maste }
55f034231aSEd Maste 
MemorySize() const5614f1b3e8SDimitry Andric size_t Declaration::MemorySize() const { return sizeof(Declaration); }
57f034231aSEd Maste 
Compare(const Declaration & a,const Declaration & b)5814f1b3e8SDimitry Andric int Declaration::Compare(const Declaration &a, const Declaration &b) {
59f034231aSEd Maste   int result = FileSpec::Compare(a.m_file, b.m_file, true);
60f034231aSEd Maste   if (result)
61f034231aSEd Maste     return result;
62f034231aSEd Maste   if (a.m_line < b.m_line)
63f034231aSEd Maste     return -1;
64f034231aSEd Maste   else if (a.m_line > b.m_line)
65f034231aSEd Maste     return 1;
66f034231aSEd Maste   if (a.m_column < b.m_column)
67f034231aSEd Maste     return -1;
68f034231aSEd Maste   else if (a.m_column > b.m_column)
69f034231aSEd Maste     return 1;
70f034231aSEd Maste   return 0;
71f034231aSEd Maste }
72f034231aSEd Maste 
FileAndLineEqual(const Declaration & declaration) const735f29bb8aSDimitry Andric bool Declaration::FileAndLineEqual(const Declaration &declaration) const {
745f29bb8aSDimitry Andric   int file_compare = FileSpec::Compare(this->m_file, declaration.m_file, true);
755f29bb8aSDimitry Andric   return file_compare == 0 && this->m_line == declaration.m_line;
765f29bb8aSDimitry Andric }
775f29bb8aSDimitry Andric 
operator ==(const Declaration & lhs,const Declaration & rhs)7814f1b3e8SDimitry Andric bool lldb_private::operator==(const Declaration &lhs, const Declaration &rhs) {
79706b4fc4SDimitry Andric   if (lhs.GetColumn() != rhs.GetColumn())
80f034231aSEd Maste     return false;
81344a3780SDimitry Andric 
82706b4fc4SDimitry Andric   return lhs.GetLine() == rhs.GetLine() && lhs.GetFile() == rhs.GetFile();
83f034231aSEd Maste }
84