1ac7ddfbfSEd Maste //===-- Declaration.cpp -----------------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste
10ac7ddfbfSEd Maste #include "lldb/Symbol/Declaration.h"
11f678e45dSDimitry Andric #include "lldb/Utility/Stream.h"
12ac7ddfbfSEd Maste
13ac7ddfbfSEd Maste using namespace lldb_private;
14ac7ddfbfSEd Maste
Dump(Stream * s,bool show_fullpaths) const15435933ddSDimitry Andric void Declaration::Dump(Stream *s, bool show_fullpaths) const {
16435933ddSDimitry Andric if (m_file) {
17ac7ddfbfSEd Maste *s << ", decl = ";
18ac7ddfbfSEd Maste if (show_fullpaths)
19ac7ddfbfSEd Maste *s << m_file;
20ac7ddfbfSEd Maste else
21ac7ddfbfSEd Maste *s << m_file.GetFilename();
22ac7ddfbfSEd Maste if (m_line > 0)
23ac7ddfbfSEd Maste s->Printf(":%u", m_line);
24ac7ddfbfSEd Maste #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
25ac7ddfbfSEd Maste if (m_column > 0)
26ac7ddfbfSEd Maste s->Printf(":%u", m_column);
27ac7ddfbfSEd Maste #endif
28435933ddSDimitry Andric } else {
29435933ddSDimitry Andric if (m_line > 0) {
30ac7ddfbfSEd Maste s->Printf(", line = %u", m_line);
31ac7ddfbfSEd Maste #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
32ac7ddfbfSEd Maste if (m_column > 0)
33ac7ddfbfSEd Maste s->Printf(":%u", m_column);
34ac7ddfbfSEd Maste #endif
35ac7ddfbfSEd Maste }
36ac7ddfbfSEd Maste #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
37ac7ddfbfSEd Maste else if (m_column > 0)
38ac7ddfbfSEd Maste s->Printf(", column = %u", m_column);
39ac7ddfbfSEd Maste #endif
40ac7ddfbfSEd Maste }
41ac7ddfbfSEd Maste }
42ac7ddfbfSEd Maste
DumpStopContext(Stream * s,bool show_fullpaths) const43435933ddSDimitry Andric bool Declaration::DumpStopContext(Stream *s, bool show_fullpaths) const {
44435933ddSDimitry Andric if (m_file) {
45f678e45dSDimitry Andric if (show_fullpaths)
46ac7ddfbfSEd Maste *s << m_file;
47ac7ddfbfSEd Maste else
48ac7ddfbfSEd Maste m_file.GetFilename().Dump(s);
49ac7ddfbfSEd Maste
50ac7ddfbfSEd Maste if (m_line > 0)
51ac7ddfbfSEd Maste s->Printf(":%u", m_line);
52ac7ddfbfSEd Maste #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
53ac7ddfbfSEd Maste if (m_column > 0)
54ac7ddfbfSEd Maste s->Printf(":%u", m_column);
55ac7ddfbfSEd Maste #endif
56ac7ddfbfSEd Maste return true;
57435933ddSDimitry Andric } else if (m_line > 0) {
58ac7ddfbfSEd Maste s->Printf(" line %u", m_line);
59ac7ddfbfSEd Maste #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
60ac7ddfbfSEd Maste if (m_column > 0)
61ac7ddfbfSEd Maste s->Printf(":%u", m_column);
62ac7ddfbfSEd Maste #endif
63ac7ddfbfSEd Maste return true;
64ac7ddfbfSEd Maste }
65ac7ddfbfSEd Maste return false;
66ac7ddfbfSEd Maste }
67ac7ddfbfSEd Maste
MemorySize() const68435933ddSDimitry Andric size_t Declaration::MemorySize() const { return sizeof(Declaration); }
69ac7ddfbfSEd Maste
Compare(const Declaration & a,const Declaration & b)70435933ddSDimitry Andric int Declaration::Compare(const Declaration &a, const Declaration &b) {
71ac7ddfbfSEd Maste int result = FileSpec::Compare(a.m_file, b.m_file, true);
72ac7ddfbfSEd Maste if (result)
73ac7ddfbfSEd Maste return result;
74ac7ddfbfSEd Maste if (a.m_line < b.m_line)
75ac7ddfbfSEd Maste return -1;
76ac7ddfbfSEd Maste else if (a.m_line > b.m_line)
77ac7ddfbfSEd Maste return 1;
78ac7ddfbfSEd Maste #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
79ac7ddfbfSEd Maste if (a.m_column < b.m_column)
80ac7ddfbfSEd Maste return -1;
81ac7ddfbfSEd Maste else if (a.m_column > b.m_column)
82ac7ddfbfSEd Maste return 1;
83ac7ddfbfSEd Maste #endif
84ac7ddfbfSEd Maste return 0;
85ac7ddfbfSEd Maste }
86ac7ddfbfSEd Maste
operator ==(const Declaration & lhs,const Declaration & rhs)87435933ddSDimitry Andric bool lldb_private::operator==(const Declaration &lhs, const Declaration &rhs) {
88ac7ddfbfSEd Maste #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
89ac7ddfbfSEd Maste if (lhs.GetColumn() == rhs.GetColumn())
90ac7ddfbfSEd Maste if (lhs.GetLine() == rhs.GetLine())
91ac7ddfbfSEd Maste return lhs.GetFile() == rhs.GetFile();
92ac7ddfbfSEd Maste #else
93ac7ddfbfSEd Maste if (lhs.GetLine() == rhs.GetLine())
94*4ba319b5SDimitry Andric return FileSpec::Equal(lhs.GetFile(), rhs.GetFile(), true);
95ac7ddfbfSEd Maste #endif
96ac7ddfbfSEd Maste return false;
97ac7ddfbfSEd Maste }
98