1 //===-- Declaration.h -------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_Declaration_h_
10 #define liblldb_Declaration_h_
12 #include "lldb/Utility/FileSpec.h"
13 #include "lldb/lldb-private.h"
15 namespace lldb_private {
17 /// \class Declaration Declaration.h "lldb/Symbol/Declaration.h"
18 /// A class that describes the declaration location of a
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.
26 /// Default constructor.
29 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
36 /// Construct with file specification, and optional line and column.
38 /// \param[in] file_spec
39 /// The file specification that describes where this was
43 /// The line number that describes where this was declared. Set
44 /// to zero if there is no line number information.
47 /// The column number that describes where this was declared.
48 /// Set to zero if there is no column number information.
49 Declaration(const FileSpec &file_spec, uint32_t line = 0, uint32_t column = 0)
50 : m_file(file_spec), m_line(line)
51 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
58 /// Construct with a pointer to another Declaration object.
59 Declaration(const Declaration *decl_ptr)
61 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
70 /// Clear the object's state.
72 /// Sets the file specification to be empty, and the line and column to
77 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
82 /// Compare two declaration objects.
84 /// Compares the two file specifications from \a lhs and \a rhs. If the file
85 /// specifications are equal, then continue to compare the line number and
86 /// column numbers respectively.
89 /// The Left Hand Side const Declaration object reference.
92 /// The Right Hand Side const Declaration object reference.
98 static int Compare(const Declaration &lhs, const Declaration &rhs);
100 /// Checks if this object has the same file and line as another declaration
103 /// \param[in] declaration
104 /// The const Declaration object to compare with.
107 /// Returns \b true if \b declaration is at the same file and
108 /// line, \b false otherwise.
109 bool FileAndLineEqual(const Declaration &declaration) const;
111 /// Dump a description of this object to a Stream.
113 /// Dump a description of the contents of this object to the supplied stream
117 /// The stream to which to dump the object description.
118 void Dump(Stream *s, bool show_fullpaths) const;
120 bool DumpStopContext(Stream *s, bool show_fullpaths) const;
121 /// Get accessor for the declaration column number.
124 /// Non-zero indicates a valid column number, zero indicates no
125 /// column information is available.
126 uint32_t GetColumn() const {
127 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
134 /// Get accessor for file specification.
137 /// A reference to the file specification object.
138 FileSpec &GetFile() { return m_file; }
140 /// Get const accessor for file specification.
143 /// A const reference to the file specification object.
144 const FileSpec &GetFile() const { return m_file; }
146 /// Get accessor for the declaration line number.
149 /// Non-zero indicates a valid line number, zero indicates no
150 /// line information is available.
151 uint32_t GetLine() const { return m_line; }
153 bool IsValid() const { return m_file && m_line != 0; }
155 /// Get the memory cost of this object.
158 /// The number of bytes that this object occupies in memory.
159 /// The returned value does not include the bytes for any
160 /// shared string values.
162 /// \see ConstString::StaticMemorySize ()
163 size_t MemorySize() const;
165 /// Set accessor for the declaration column number.
167 /// \param[in] column
168 /// Non-zero indicates a valid column number, zero indicates no
169 /// column information is available.
170 void SetColumn(uint32_t column) {
171 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
176 /// Set accessor for the declaration file specification.
178 /// \param[in] file_spec
179 /// The new declaration file specification.
180 void SetFile(const FileSpec &file_spec) { m_file = file_spec; }
182 /// Set accessor for the declaration line number.
185 /// Non-zero indicates a valid line number, zero indicates no
186 /// line information is available.
187 void SetLine(uint32_t line) { m_line = line; }
190 /// Member variables.
191 FileSpec m_file; ///< The file specification that points to the
192 ///< source file where the declaration occurred.
193 uint32_t m_line; ///< Non-zero values indicates a valid line number,
194 ///< zero indicates no line number information is available.
195 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
196 uint32_t m_column; ///< Non-zero values indicates a valid column number,
197 ///< zero indicates no column information is available.
201 bool operator==(const Declaration &lhs, const Declaration &rhs);
203 } // namespace lldb_private
205 #endif // liblldb_Declaration_h_