blob: a31a304b06f9bdc7ad5007d5c831ad580bbd3cc3 [file] [log] [blame]
Chris Lattner24943d22010-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
15Declaration::Declaration() :
16 m_file(),
17 m_line(0),
18 m_column(0)
19{
20}
21
22Declaration::Declaration(const FileSpec& f, uint32_t l, uint32_t c) :
23 m_file(f),
24 m_line(l),
25 m_column(c)
26{
27}
28
29Declaration::Declaration(const Declaration& rhs) :
30 m_file(rhs.m_file),
31 m_line(rhs.m_line),
32 m_column(rhs.m_column)
33{
34}
35
36Declaration::Declaration(const Declaration* decl_ptr) :
37 m_file(),
38 m_line(0),
39 m_column(0)
40{
41 if (decl_ptr != NULL)
42 *this = *decl_ptr;
43}
44
45bool
46Declaration::IsValid() const
47{
48 return m_file && m_line != 0;
49}
50
51void
52Declaration::Clear()
53{
54 m_file.Clear();
55 m_line= 0;
56 m_column = 0;
57}
58
59void
60Declaration::Dump(Stream *s) const
61{
62 if (m_file)
63 {
64 *s << ", decl = '" << m_file;
65 if (m_line > 0)
66 s->Printf(":%u", m_line);
67 if (m_column > 0)
68 s->Printf(":%u", m_column);
69 s->PutChar('\'');
70 }
71 else
72 {
73 if (m_line > 0)
74 {
75 s->Printf(", line = %u", m_line);
76 if (m_column > 0)
77 s->Printf(":%u", m_column);
78 }
79 else if (m_column > 0)
80 s->Printf(", column = %u", m_column);
81 }
82}
83
84void
85Declaration::DumpStopContext (Stream *s) const
86{
87 if (m_file)
88 {
89 if (s->GetVerbose())
90 *s << m_file;
91 else
92 m_file.GetFilename().Dump(s);
93
94 if (m_line > 0)
95 s->Printf(":%u", m_line);
96 if (m_column > 0)
97 s->Printf(":%u", m_column);
98 }
99 else
100 {
101 s->Printf(" line %u", m_line);
102 if (m_column > 0)
103 s->Printf(":%u", m_column);
104 }
105}
106
107uint32_t
108Declaration::GetColumn() const
109{
110 return m_column;
111}
112
113FileSpec&
114Declaration::GetFile()
115{
116 return m_file;
117}
118
119const FileSpec&
120Declaration::GetFile() const
121{
122 return m_file;
123}
124
125uint32_t
126Declaration::GetLine() const
127{
128 return m_line;
129}
130
131size_t
132Declaration::MemorySize() const
133{
134 return sizeof(Declaration);
135}
136
137void
138Declaration::SetColumn(uint32_t col)
139{
140 m_column = col;
141}
142
143void
144Declaration::SetFile(const FileSpec& file)
145{
146 m_file = file;
147}
148
149void
150Declaration::SetLine(uint32_t line)
151{
152 m_line = line;
153}
154
155
156
157int
158Declaration::Compare(const Declaration& a, const Declaration& b)
159{
160 int result = FileSpec::Compare(a.m_file, b.m_file, true);
161 if (result)
162 return result;
163 if (a.m_line < b.m_line)
164 return -1;
165 else if (a.m_line > b.m_line)
166 return 1;
167 if (a.m_column < b.m_column)
168 return -1;
169 else if (a.m_column > b.m_column)
170 return 1;
171 return 0;
172}