LLDB mainline
Declaration.h
Go to the documentation of this file.
1//===-- Declaration.h -------------------------------------------*- 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
9#ifndef LLDB_SYMBOL_DECLARATION_H
10#define LLDB_SYMBOL_DECLARATION_H
11
13#include "lldb/lldb-private.h"
14
15namespace lldb_private {
16
17/// \class Declaration Declaration.h "lldb/Core/Declaration.h"
18/// A class that describes the declaration location of a
19/// lldb object.
20///
21/// The declarations include the file specification, line number, and the
22/// column info and can help track where functions, blocks, inlined functions,
23/// types, variables, any many other debug core objects were declared.
25public:
26 /// Default constructor.
27 Declaration() = default;
28
29 /// Construct with file specification, and optional line and column.
30 ///
31 /// \param[in] file_spec
32 /// The file specification that describes where this was
33 /// declared.
34 ///
35 /// \param[in] line
36 /// The line number that describes where this was declared. Set
37 /// to zero if there is no line number information.
38 ///
39 /// \param[in] column
40 /// The column number that describes where this was declared.
41 /// Set to zero if there is no column number information.
42 Declaration(const FileSpec &file_spec, uint32_t line = 0,
43 uint16_t column = LLDB_INVALID_COLUMN_NUMBER)
44 : m_file(file_spec), m_line(line), m_column(column) {}
45
46 /// Construct with a pointer to another Declaration object.
47 Declaration(const Declaration *decl_ptr)
49 if (decl_ptr)
50 *this = *decl_ptr;
51 }
52
53 /// Clear the object's state.
54 ///
55 /// Sets the file specification to be empty, and the line and column to
56 /// zero.
57 void Clear() {
58 m_file.Clear();
59 m_line = 0;
60 m_column = 0;
61 }
62
63 /// Compare two declaration objects.
64 ///
65 /// Compares the two file specifications from \a lhs and \a rhs. If the file
66 /// specifications are equal, then continue to compare the line number and
67 /// column numbers respectively.
68 ///
69 /// \param[in] lhs
70 /// The Left Hand Side const Declaration object reference.
71 ///
72 /// \param[in] rhs
73 /// The Right Hand Side const Declaration object reference.
74 ///
75 /// \return
76 /// -1 if lhs < rhs
77 /// 0 if lhs == rhs
78 /// 1 if lhs > rhs
79 static int Compare(const Declaration &lhs, const Declaration &rhs);
80
81 /// Checks if this object has the same file and line as another declaration
82 /// object.
83 ///
84 /// \param[in] declaration
85 /// The const Declaration object to compare with.
86 ///
87 /// \param[in] full
88 /// Same meaning as Full in FileSpec::Equal. True means an empty
89 /// directory is not equal to a specified one, false means it is equal.
90 ///
91 /// \return
92 /// Returns \b true if \b declaration is at the same file and
93 /// line, \b false otherwise.
94 bool FileAndLineEqual(const Declaration &declaration, bool full) const;
95
96 /// Dump a description of this object to a Stream.
97 ///
98 /// Dump a description of the contents of this object to the supplied stream
99 /// \a s.
100 ///
101 /// \param[in] s
102 /// The stream to which to dump the object description.
103 void Dump(Stream *s, bool show_fullpaths) const;
104
105 bool DumpStopContext(Stream *s, bool show_fullpaths) const;
106
107 /// Get accessor for file specification.
108 ///
109 /// \return
110 /// A reference to the file specification object.
111 FileSpec &GetFile() { return m_file; }
112
113 /// Get const accessor for file specification.
114 ///
115 /// \return
116 /// A const reference to the file specification object.
117 const FileSpec &GetFile() const { return m_file; }
118
119 /// Get accessor for the declaration line number.
120 ///
121 /// \return
122 /// Non-zero indicates a valid line number, zero indicates no
123 /// line information is available.
124 uint32_t GetLine() const { return m_line; }
125
126 /// Get accessor for the declaration column number.
127 ///
128 /// \return
129 /// Non-zero indicates a valid column number, zero indicates no
130 /// column information is available.
131 uint16_t GetColumn() const { return m_column; }
132
133 /// Convert to boolean operator.
134 ///
135 /// This allows code to check a Declaration object to see if it
136 /// contains anything valid using code such as:
137 ///
138 /// \code
139 /// Declaration decl(...);
140 /// if (decl)
141 /// { ...
142 /// \endcode
143 ///
144 /// \return
145 /// A \b true if both the file_spec and the line are valid,
146 /// \b false otherwise.
147 explicit operator bool() const { return IsValid(); }
148
149 bool IsValid() const {
150 return m_file && m_line != 0 && m_line != LLDB_INVALID_LINE_NUMBER;
151 }
152
153 /// Get the memory cost of this object.
154 ///
155 /// \return
156 /// The number of bytes that this object occupies in memory.
157 /// The returned value does not include the bytes for any
158 /// shared string values.
159 size_t MemorySize() const;
160
161 /// Set accessor for the declaration file specification.
162 ///
163 /// \param[in] file_spec
164 /// The new declaration file specification.
165 void SetFile(const FileSpec &file_spec) { m_file = file_spec; }
166
167 /// Set accessor for the declaration line number.
168 ///
169 /// \param[in] line
170 /// Non-zero indicates a valid line number, zero indicates no
171 /// line information is available.
172 void SetLine(uint32_t line) { m_line = line; }
173
174 /// Set accessor for the declaration column number.
175 ///
176 /// \param[in] column
177 /// Non-zero indicates a valid column number, zero indicates no
178 /// column information is available.
179 void SetColumn(uint16_t column) { m_column = column; }
180
181protected:
182 /// The file specification that points to the source file where the
183 /// declaration occurred.
185 /// Non-zero values indicates a valid line number, zero indicates no line
186 /// number information is available.
187 uint32_t m_line = 0;
188 /// Non-zero values indicates a valid column number, zero indicates no column
189 /// information is available.
191};
192
193bool operator==(const Declaration &lhs, const Declaration &rhs);
194
195} // namespace lldb_private
196
197#endif // LLDB_SYMBOL_DECLARATION_H
A class that describes the declaration location of a lldb object.
Definition: Declaration.h:24
FileSpec m_file
The file specification that points to the source file where the declaration occurred.
Definition: Declaration.h:184
Declaration(const FileSpec &file_spec, uint32_t line=0, uint16_t column=LLDB_INVALID_COLUMN_NUMBER)
Construct with file specification, and optional line and column.
Definition: Declaration.h:42
uint32_t GetLine() const
Get accessor for the declaration line number.
Definition: Declaration.h:124
size_t MemorySize() const
Get the memory cost of this object.
Definition: Declaration.cpp:56
uint16_t GetColumn() const
Get accessor for the declaration column number.
Definition: Declaration.h:131
void SetLine(uint32_t line)
Set accessor for the declaration line number.
Definition: Declaration.h:172
void Dump(Stream *s, bool show_fullpaths) const
Dump a description of this object to a Stream.
Definition: Declaration.cpp:14
void SetColumn(uint16_t column)
Set accessor for the declaration column number.
Definition: Declaration.h:179
void Clear()
Clear the object's state.
Definition: Declaration.h:57
void SetFile(const FileSpec &file_spec)
Set accessor for the declaration file specification.
Definition: Declaration.h:165
uint32_t m_line
Non-zero values indicates a valid line number, zero indicates no line number information is available...
Definition: Declaration.h:187
uint16_t m_column
Non-zero values indicates a valid column number, zero indicates no column information is available.
Definition: Declaration.h:190
static int Compare(const Declaration &lhs, const Declaration &rhs)
Compare two declaration objects.
Definition: Declaration.cpp:58
const FileSpec & GetFile() const
Get const accessor for file specification.
Definition: Declaration.h:117
Declaration()=default
Default constructor.
Declaration(const Declaration *decl_ptr)
Construct with a pointer to another Declaration object.
Definition: Declaration.h:47
bool FileAndLineEqual(const Declaration &declaration, bool full) const
Checks if this object has the same file and line as another declaration object.
Definition: Declaration.cpp:73
bool DumpStopContext(Stream *s, bool show_fullpaths) const
Definition: Declaration.cpp:35
FileSpec & GetFile()
Get accessor for file specification.
Definition: Declaration.h:111
A file utility class.
Definition: FileSpec.h:56
void Clear()
Clears the object state.
Definition: FileSpec.cpp:259
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
#define LLDB_INVALID_LINE_NUMBER
Definition: lldb-defines.h:94
#define LLDB_INVALID_COLUMN_NUMBER
Definition: lldb-defines.h:95
A class that represents a running process on the host machine.
bool operator==(const Address &lhs, const Address &rhs)
Definition: Address.cpp:1023