LLDB  mainline
Declaration.cpp
Go to the documentation of this file.
1 //===-- Declaration.cpp -----------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #include "lldb/Utility/Stream.h"
11 
12 using namespace lldb_private;
13 
14 void Declaration::Dump(Stream *s, bool show_fullpaths) const {
15  if (m_file) {
16  *s << ", decl = ";
17  if (show_fullpaths)
18  *s << m_file;
19  else
20  *s << m_file.GetFilename();
21  if (m_line > 0)
22  s->Printf(":%u", m_line);
23 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
24  if (m_column > 0)
25  s->Printf(":%u", m_column);
26 #endif
27  } else {
28  if (m_line > 0) {
29  s->Printf(", line = %u", m_line);
30 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
31  if (m_column > 0)
32  s->Printf(":%u", m_column);
33 #endif
34  }
35 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
36  else if (m_column > 0)
37  s->Printf(", column = %u", m_column);
38 #endif
39  }
40 }
41 
42 bool Declaration::DumpStopContext(Stream *s, bool show_fullpaths) const {
43  if (m_file) {
44  if (show_fullpaths)
45  *s << m_file;
46  else
47  m_file.GetFilename().Dump(s);
48 
49  if (m_line > 0)
50  s->Printf(":%u", m_line);
51 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
52  if (m_column > 0)
53  s->Printf(":%u", m_column);
54 #endif
55  return true;
56  } else if (m_line > 0) {
57  s->Printf(" line %u", m_line);
58 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
59  if (m_column > 0)
60  s->Printf(":%u", m_column);
61 #endif
62  return true;
63  }
64  return false;
65 }
66 
67 size_t Declaration::MemorySize() const { return sizeof(Declaration); }
68 
69 int Declaration::Compare(const Declaration &a, const Declaration &b) {
70  int result = FileSpec::Compare(a.m_file, b.m_file, true);
71  if (result)
72  return result;
73  if (a.m_line < b.m_line)
74  return -1;
75  else if (a.m_line > b.m_line)
76  return 1;
77 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
78  if (a.m_column < b.m_column)
79  return -1;
80  else if (a.m_column > b.m_column)
81  return 1;
82 #endif
83  return 0;
84 }
85 
86 bool Declaration::FileAndLineEqual(const Declaration &declaration) const {
87  int file_compare = FileSpec::Compare(this->m_file, declaration.m_file, true);
88  return file_compare == 0 && this->m_line == declaration.m_line;
89 }
90 
91 bool lldb_private::operator==(const Declaration &lhs, const Declaration &rhs) {
92 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
93  if (lhs.GetColumn() == rhs.GetColumn())
94  if (lhs.GetLine() == rhs.GetLine())
95  return lhs.GetFile() == rhs.GetFile();
96 #else
97  if (lhs.GetLine() == rhs.GetLine())
98  return FileSpec::Equal(lhs.GetFile(), rhs.GetFile(), true);
99 #endif
100  return false;
101 }
ConstString & GetFilename()
Filename string get accessor.
Definition: FileSpec.cpp:369
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
static int Compare(const Declaration &lhs, const Declaration &rhs)
Compare two declaration objects.
Definition: Declaration.cpp:69
static int Compare(const FileSpec &lhs, const FileSpec &rhs, bool full)
Compare two FileSpec objects.
Definition: FileSpec.cpp:298
Declaration()
Default constructor.
Definition: Declaration.h:27
FileSpec m_file
Member variables.
Definition: Declaration.h:201
bool operator==(const Address &lhs, const Address &rhs)
Definition: Address.cpp:973
FileSpec & GetFile()
Get accessor for file specification.
Definition: Declaration.h:148
bool DumpStopContext(Stream *s, bool show_fullpaths) const
Definition: Declaration.cpp:42
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:106
uint32_t GetLine() const
Get accessor for the declaration line number.
Definition: Declaration.h:161
void Dump(Stream *s, const char *value_if_empty=nullptr) const
Dump the object description to a stream.
void Dump(Stream *s, bool show_fullpaths) const
Dump a description of this object to a Stream.
Definition: Declaration.cpp:14
static bool Equal(const FileSpec &a, const FileSpec &b, bool full)
Definition: FileSpec.cpp:319
bool FileAndLineEqual(const Declaration &declaration) const
Checks if this object has the same file and line as another declaration object.
Definition: Declaration.cpp:86
size_t MemorySize() const
Get the memory cost of this object.
Definition: Declaration.cpp:67
A class that describes the declaration location of a lldb object.
Definition: Declaration.h:24
uint32_t m_line
Non-zero values indicates a valid line number, zero indicates no line number information is available...
Definition: Declaration.h:203
uint32_t GetColumn() const
Get accessor for the declaration column number.
Definition: Declaration.h:136