xref: /freebsd-src/contrib/llvm-project/lldb/source/Core/Declaration.cpp (revision fe6060f10f634930ff71b7c50291ddc610da2475)
1*fe6060f1SDimitry Andric //===-- Declaration.cpp ---------------------------------------------------===//
2*fe6060f1SDimitry Andric //
3*fe6060f1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*fe6060f1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*fe6060f1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*fe6060f1SDimitry Andric //
7*fe6060f1SDimitry Andric //===----------------------------------------------------------------------===//
8*fe6060f1SDimitry Andric 
9*fe6060f1SDimitry Andric #include "lldb/Core/Declaration.h"
10*fe6060f1SDimitry Andric #include "lldb/Utility/Stream.h"
11*fe6060f1SDimitry Andric 
12*fe6060f1SDimitry Andric using namespace lldb_private;
13*fe6060f1SDimitry Andric 
Dump(Stream * s,bool show_fullpaths) const14*fe6060f1SDimitry Andric void Declaration::Dump(Stream *s, bool show_fullpaths) const {
15*fe6060f1SDimitry Andric   if (m_file) {
16*fe6060f1SDimitry Andric     *s << ", decl = ";
17*fe6060f1SDimitry Andric     if (show_fullpaths)
18*fe6060f1SDimitry Andric       *s << m_file;
19*fe6060f1SDimitry Andric     else
20*fe6060f1SDimitry Andric       *s << m_file.GetFilename();
21*fe6060f1SDimitry Andric     if (m_line > 0)
22*fe6060f1SDimitry Andric       s->Printf(":%u", m_line);
23*fe6060f1SDimitry Andric     if (m_column != LLDB_INVALID_COLUMN_NUMBER)
24*fe6060f1SDimitry Andric       s->Printf(":%u", m_column);
25*fe6060f1SDimitry Andric   } else {
26*fe6060f1SDimitry Andric     if (m_line > 0) {
27*fe6060f1SDimitry Andric       s->Printf(", line = %u", m_line);
28*fe6060f1SDimitry Andric       if (m_column != LLDB_INVALID_COLUMN_NUMBER)
29*fe6060f1SDimitry Andric         s->Printf(":%u", m_column);
30*fe6060f1SDimitry Andric     } else if (m_column != LLDB_INVALID_COLUMN_NUMBER)
31*fe6060f1SDimitry Andric       s->Printf(", column = %u", m_column);
32*fe6060f1SDimitry Andric   }
33*fe6060f1SDimitry Andric }
34*fe6060f1SDimitry Andric 
DumpStopContext(Stream * s,bool show_fullpaths) const35*fe6060f1SDimitry Andric bool Declaration::DumpStopContext(Stream *s, bool show_fullpaths) const {
36*fe6060f1SDimitry Andric   if (m_file) {
37*fe6060f1SDimitry Andric     if (show_fullpaths)
38*fe6060f1SDimitry Andric       *s << m_file;
39*fe6060f1SDimitry Andric     else
40*fe6060f1SDimitry Andric       m_file.GetFilename().Dump(s);
41*fe6060f1SDimitry Andric 
42*fe6060f1SDimitry Andric     if (m_line > 0)
43*fe6060f1SDimitry Andric       s->Printf(":%u", m_line);
44*fe6060f1SDimitry Andric     if (m_column != LLDB_INVALID_COLUMN_NUMBER)
45*fe6060f1SDimitry Andric       s->Printf(":%u", m_column);
46*fe6060f1SDimitry Andric     return true;
47*fe6060f1SDimitry Andric   } else if (m_line > 0) {
48*fe6060f1SDimitry Andric     s->Printf(" line %u", m_line);
49*fe6060f1SDimitry Andric     if (m_column != LLDB_INVALID_COLUMN_NUMBER)
50*fe6060f1SDimitry Andric       s->Printf(":%u", m_column);
51*fe6060f1SDimitry Andric     return true;
52*fe6060f1SDimitry Andric   }
53*fe6060f1SDimitry Andric   return false;
54*fe6060f1SDimitry Andric }
55*fe6060f1SDimitry Andric 
MemorySize() const56*fe6060f1SDimitry Andric size_t Declaration::MemorySize() const { return sizeof(Declaration); }
57*fe6060f1SDimitry Andric 
Compare(const Declaration & a,const Declaration & b)58*fe6060f1SDimitry Andric int Declaration::Compare(const Declaration &a, const Declaration &b) {
59*fe6060f1SDimitry Andric   int result = FileSpec::Compare(a.m_file, b.m_file, true);
60*fe6060f1SDimitry Andric   if (result)
61*fe6060f1SDimitry Andric     return result;
62*fe6060f1SDimitry Andric   if (a.m_line < b.m_line)
63*fe6060f1SDimitry Andric     return -1;
64*fe6060f1SDimitry Andric   else if (a.m_line > b.m_line)
65*fe6060f1SDimitry Andric     return 1;
66*fe6060f1SDimitry Andric   if (a.m_column < b.m_column)
67*fe6060f1SDimitry Andric     return -1;
68*fe6060f1SDimitry Andric   else if (a.m_column > b.m_column)
69*fe6060f1SDimitry Andric     return 1;
70*fe6060f1SDimitry Andric   return 0;
71*fe6060f1SDimitry Andric }
72*fe6060f1SDimitry Andric 
FileAndLineEqual(const Declaration & declaration) const73*fe6060f1SDimitry Andric bool Declaration::FileAndLineEqual(const Declaration &declaration) const {
74*fe6060f1SDimitry Andric   int file_compare = FileSpec::Compare(this->m_file, declaration.m_file, true);
75*fe6060f1SDimitry Andric   return file_compare == 0 && this->m_line == declaration.m_line;
76*fe6060f1SDimitry Andric }
77*fe6060f1SDimitry Andric 
operator ==(const Declaration & lhs,const Declaration & rhs)78*fe6060f1SDimitry Andric bool lldb_private::operator==(const Declaration &lhs, const Declaration &rhs) {
79*fe6060f1SDimitry Andric   if (lhs.GetColumn() != rhs.GetColumn())
80*fe6060f1SDimitry Andric     return false;
81*fe6060f1SDimitry Andric 
82*fe6060f1SDimitry Andric   return lhs.GetLine() == rhs.GetLine() && lhs.GetFile() == rhs.GetFile();
83*fe6060f1SDimitry Andric }
84