blob: 3943f02c54741eb23a6fb7b3646df02e64d35bad [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- Declaration.cpp -----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Symbol/Declaration.h"
11#include "lldb/Core/Stream.h"
12
13using namespace lldb_private;
14
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015void
Greg Clayton6dbd3982010-09-15 05:51:24 +000016Declaration::Dump(Stream *s, bool show_fullpaths) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017{
18 if (m_file)
19 {
Greg Clayton6dbd3982010-09-15 05:51:24 +000020 *s << ", decl = ";
21 if (show_fullpaths)
22 *s << m_file;
23 else
24 *s << m_file.GetFilename();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025 if (m_line > 0)
26 s->Printf(":%u", m_line);
Greg Clayton4272cc72011-02-02 02:24:04 +000027#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028 if (m_column > 0)
29 s->Printf(":%u", m_column);
Greg Clayton4272cc72011-02-02 02:24:04 +000030#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031 }
32 else
33 {
34 if (m_line > 0)
35 {
36 s->Printf(", line = %u", m_line);
Greg Clayton4272cc72011-02-02 02:24:04 +000037#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
Chris Lattner30fdc8d2010-06-08 16:52:24 +000038 if (m_column > 0)
39 s->Printf(":%u", m_column);
Greg Clayton4272cc72011-02-02 02:24:04 +000040#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041 }
Greg Clayton4272cc72011-02-02 02:24:04 +000042#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043 else if (m_column > 0)
44 s->Printf(", column = %u", m_column);
Greg Clayton4272cc72011-02-02 02:24:04 +000045#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046 }
47}
48
Greg Clayton45ba8542011-07-10 19:21:23 +000049bool
Greg Clayton6dadd502010-09-02 21:44:10 +000050Declaration::DumpStopContext (Stream *s, bool show_fullpaths) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051{
52 if (m_file)
53 {
Greg Clayton6dadd502010-09-02 21:44:10 +000054 if (show_fullpaths || s->GetVerbose())
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055 *s << m_file;
56 else
57 m_file.GetFilename().Dump(s);
58
59 if (m_line > 0)
60 s->Printf(":%u", m_line);
Greg Clayton4272cc72011-02-02 02:24:04 +000061#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062 if (m_column > 0)
63 s->Printf(":%u", m_column);
Greg Clayton4272cc72011-02-02 02:24:04 +000064#endif
Greg Clayton45ba8542011-07-10 19:21:23 +000065 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066 }
Greg Clayton45ba8542011-07-10 19:21:23 +000067 else if (m_line > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000068 {
69 s->Printf(" line %u", m_line);
Greg Clayton4272cc72011-02-02 02:24:04 +000070#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071 if (m_column > 0)
72 s->Printf(":%u", m_column);
Greg Clayton4272cc72011-02-02 02:24:04 +000073#endif
Greg Clayton45ba8542011-07-10 19:21:23 +000074 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000075 }
Greg Clayton45ba8542011-07-10 19:21:23 +000076 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000077}
78
Chris Lattner30fdc8d2010-06-08 16:52:24 +000079size_t
80Declaration::MemorySize() const
81{
82 return sizeof(Declaration);
83}
84
Chris Lattner30fdc8d2010-06-08 16:52:24 +000085int
86Declaration::Compare(const Declaration& a, const Declaration& b)
87{
88 int result = FileSpec::Compare(a.m_file, b.m_file, true);
89 if (result)
90 return result;
91 if (a.m_line < b.m_line)
92 return -1;
93 else if (a.m_line > b.m_line)
94 return 1;
Greg Clayton4272cc72011-02-02 02:24:04 +000095#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
Chris Lattner30fdc8d2010-06-08 16:52:24 +000096 if (a.m_column < b.m_column)
97 return -1;
98 else if (a.m_column > b.m_column)
99 return 1;
Greg Clayton4272cc72011-02-02 02:24:04 +0000100#endif
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000101 return 0;
102}
Greg Clayton4272cc72011-02-02 02:24:04 +0000103
104bool
105lldb_private::operator == (const Declaration &lhs, const Declaration &rhs)
106{
107#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
108 if (lhs.GetColumn () == rhs.GetColumn ())
109 if (lhs.GetLine () == rhs.GetLine ())
110 return lhs.GetFile() == rhs.GetFile();
111#else
112 if (lhs.GetLine () == rhs.GetLine ())
113 return lhs.GetFile() == rhs.GetFile();
114#endif
115 return false;
116}
117