LLDB  mainline
Declaration.cpp
Go to the documentation of this file.
1 //===-- Declaration.cpp ---------------------------------------------------===//
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);
24  s->Printf(":%u", m_column);
25  } else {
26  if (m_line > 0) {
27  s->Printf(", line = %u", m_line);
29  s->Printf(":%u", m_column);
31  s->Printf(", column = %u", m_column);
32  }
33 }
34 
35 bool Declaration::DumpStopContext(Stream *s, bool show_fullpaths) const {
36  if (m_file) {
37  if (show_fullpaths)
38  *s << m_file;
39  else
40  m_file.GetFilename().Dump(s);
41 
42  if (m_line > 0)
43  s->Printf(":%u", m_line);
45  s->Printf(":%u", m_column);
46  return true;
47  } else if (m_line > 0) {
48  s->Printf(" line %u", m_line);
50  s->Printf(":%u", m_column);
51  return true;
52  }
53  return false;
54 }
55 
56 size_t Declaration::MemorySize() const { return sizeof(Declaration); }
57 
58 int Declaration::Compare(const Declaration &a, const Declaration &b) {
59  int result = FileSpec::Compare(a.m_file, b.m_file, true);
60  if (result)
61  return result;
62  if (a.m_line < b.m_line)
63  return -1;
64  else if (a.m_line > b.m_line)
65  return 1;
66  if (a.m_column < b.m_column)
67  return -1;
68  else if (a.m_column > b.m_column)
69  return 1;
70  return 0;
71 }
72 
73 bool Declaration::FileAndLineEqual(const Declaration &declaration) const {
74  int file_compare = FileSpec::Compare(this->m_file, declaration.m_file, true);
75  return file_compare == 0 && this->m_line == declaration.m_line;
76 }
77 
78 bool lldb_private::operator==(const Declaration &lhs, const Declaration &rhs) {
79  if (lhs.GetColumn() != rhs.GetColumn())
80  return false;
81 
82  return lhs.GetLine() == rhs.GetLine() && lhs.GetFile() == rhs.GetFile();
83 }
lldb_private::Declaration::m_file
FileSpec m_file
The file specification that points to the source file where the declaration occurred.
Definition: Declaration.h:182
LLDB_INVALID_COLUMN_NUMBER
#define LLDB_INVALID_COLUMN_NUMBER
Definition: lldb-defines.h:99
lldb_private::Declaration::m_line
uint32_t m_line
Non-zero values indicates a valid line number, zero indicates no line number information is available...
Definition: Declaration.h:185
lldb_private::Declaration::GetFile
FileSpec & GetFile()
Get accessor for file specification.
Definition: Declaration.h:107
lldb_private::Declaration::GetColumn
uint16_t GetColumn() const
Get accessor for the declaration column number.
Definition: Declaration.h:127
lldb_private::Stream
Definition: Stream.h:28
lldb_private::operator==
bool operator==(const Address &lhs, const Address &rhs)
Definition: Address.cpp:999
lldb_private::FileSpec::Compare
static int Compare(const FileSpec &lhs, const FileSpec &rhs, bool full)
Compare two FileSpec objects.
Definition: FileSpec.cpp:274
lldb_private::Declaration::Dump
void Dump(Stream *s, bool show_fullpaths) const
Dump a description of this object to a Stream.
Definition: Declaration.cpp:14
lldb_private::Declaration::DumpStopContext
bool DumpStopContext(Stream *s, bool show_fullpaths) const
Definition: Declaration.cpp:35
Declaration.h
lldb_private::Declaration::MemorySize
size_t MemorySize() const
Get the memory cost of this object.
Definition: Declaration.cpp:56
lldb_private::ConstString::Dump
void Dump(Stream *s, const char *value_if_empty=nullptr) const
Dump the object description to a stream.
Definition: ConstString.cpp:283
lldb_private::Declaration::GetLine
uint32_t GetLine() const
Get accessor for the declaration line number.
Definition: Declaration.h:120
lldb_private::Declaration::FileAndLineEqual
bool FileAndLineEqual(const Declaration &declaration) const
Checks if this object has the same file and line as another declaration object.
Definition: Declaration.cpp:73
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::Declaration::m_column
uint16_t m_column
Non-zero values indicates a valid column number, zero indicates no column information is available.
Definition: Declaration.h:188
Stream.h
lldb_private::Declaration::Compare
static int Compare(const Declaration &lhs, const Declaration &rhs)
Compare two declaration objects.
Definition: Declaration.cpp:58
lldb_private::Declaration
Definition: Declaration.h:24
lldb_private::FileSpec::GetFilename
ConstString & GetFilename()
Filename string get accessor.
Definition: FileSpec.cpp:341
lldb_private::Declaration::Declaration
Declaration()
Default constructor.
Definition: Declaration.h:27