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 reference to another Declaration object.
59 Declaration(const Declaration &rhs)
60 : m_file(rhs.m_file), m_line(rhs.m_line)
61 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
63 m_column(rhs.m_column)
68 /// Construct with a pointer to another Declaration object.
69 Declaration(const Declaration *decl_ptr)
71 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
80 /// Clear the object's state.
82 /// Sets the file specification to be empty, and the line and column to
87 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
92 /// Compare two declaration objects.
94 /// Compares the two file specifications from \a lhs and \a rhs. If the file
95 /// specifications are equal, then continue to compare the line number and
96 /// column numbers respectively.
99 /// The Left Hand Side const Declaration object reference.
102 /// The Right Hand Side const Declaration object reference.
105 /// \li -1 if lhs < rhs
106 /// \li 0 if lhs == rhs
107 /// \li 1 if lhs > rhs
108 static int Compare(const Declaration &lhs, const Declaration &rhs);
110 /// Checks if this object has the same file and line as another declaration
113 /// \param[in] declaration
114 /// The const Declaration object to compare with.
117 /// Returns \b true if \b declaration is at the same file and
118 /// line, \b false otherwise.
119 bool FileAndLineEqual(const Declaration &declaration) const;
121 /// Dump a description of this object to a Stream.
123 /// Dump a description of the contents of this object to the supplied stream
127 /// The stream to which to dump the object description.
128 void Dump(Stream *s, bool show_fullpaths) const;
130 bool DumpStopContext(Stream *s, bool show_fullpaths) const;
131 /// Get accessor for the declaration column number.
134 /// Non-zero indicates a valid column number, zero indicates no
135 /// column information is available.
136 uint32_t GetColumn() const {
137 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
144 /// Get accessor for file specification.
147 /// A reference to the file specification object.
148 FileSpec &GetFile() { return m_file; }
150 /// Get const accessor for file specification.
153 /// A const reference to the file specification object.
154 const FileSpec &GetFile() const { return m_file; }
156 /// Get accessor for the declaration line number.
159 /// Non-zero indicates a valid line number, zero indicates no
160 /// line information is available.
161 uint32_t GetLine() const { return m_line; }
163 bool IsValid() const { return m_file && m_line != 0; }
165 /// Get the memory cost of this object.
168 /// The number of bytes that this object occupies in memory.
169 /// The returned value does not include the bytes for any
170 /// shared string values.
172 /// \see ConstString::StaticMemorySize ()
173 size_t MemorySize() const;
175 /// Set accessor for the declaration column number.
177 /// \param[in] column
178 /// Non-zero indicates a valid column number, zero indicates no
179 /// column information is available.
180 void SetColumn(uint32_t column) {
181 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
186 /// Set accessor for the declaration file specification.
188 /// \param[in] file_spec
189 /// The new declaration file specification.
190 void SetFile(const FileSpec &file_spec) { m_file = file_spec; }
192 /// Set accessor for the declaration line number.
195 /// Non-zero indicates a valid line number, zero indicates no
196 /// line information is available.
197 void SetLine(uint32_t line) { m_line = line; }
200 /// Member variables.
201 FileSpec m_file; ///< The file specification that points to the
202 ///< source file where the declaration occurred.
203 uint32_t m_line; ///< Non-zero values indicates a valid line number,
204 ///< zero indicates no line number information is available.
205 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
206 uint32_t m_column; ///< Non-zero values indicates a valid column number,
207 ///< zero indicates no column information is available.
211 bool operator==(const Declaration &lhs, const Declaration &rhs);
213 } // namespace lldb_private
215 #endif // liblldb_Declaration_h_