1 //===-- Declaration.h -------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_Declaration_h_
11 #define liblldb_Declaration_h_
13 #include "lldb/Utility/FileSpec.h"
14 #include "lldb/lldb-private.h"
16 namespace lldb_private {
18 //----------------------------------------------------------------------
19 /// @class Declaration Declaration.h "lldb/Symbol/Declaration.h"
20 /// @brief A class that describes the declaration location of a
23 /// The declarations include the file specification, line number, and
24 /// the column info and can help track where functions, blocks, inlined
25 /// functions, types, variables, any many other debug core objects were
27 //----------------------------------------------------------------------
30 //------------------------------------------------------------------
31 /// Default constructor.
32 //------------------------------------------------------------------
35 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
42 //------------------------------------------------------------------
43 /// Construct with file specification, and optional line and column.
45 /// @param[in] file_spec
46 /// The file specification that describes where this was
50 /// The line number that describes where this was declared. Set
51 /// to zero if there is no line number information.
54 /// The column number that describes where this was declared.
55 /// Set to zero if there is no column number information.
56 //------------------------------------------------------------------
57 Declaration(const FileSpec &file_spec, uint32_t line = 0, uint32_t column = 0)
58 : m_file(file_spec), m_line(line)
59 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
66 //------------------------------------------------------------------
67 /// Construct with a reference to another Declaration object.
68 //------------------------------------------------------------------
69 Declaration(const Declaration &rhs)
70 : m_file(rhs.m_file), m_line(rhs.m_line)
71 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
73 m_column(rhs.m_column)
78 //------------------------------------------------------------------
79 /// Construct with a pointer to another Declaration object.
80 //------------------------------------------------------------------
81 Declaration(const Declaration *decl_ptr)
83 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
92 //------------------------------------------------------------------
93 /// Clear the object's state.
95 /// Sets the file specification to be empty, and the line and column
97 //------------------------------------------------------------------
101 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
106 //------------------------------------------------------------------
107 /// Compare two declaration objects.
109 /// Compares the two file specifications from \a lhs and \a rhs. If
110 /// the file specifications are equal, then continue to compare the
111 /// line number and column numbers respectively.
114 /// The Left Hand Side const Declaration object reference.
117 /// The Right Hand Side const Declaration object reference.
120 /// @li -1 if lhs < rhs
121 /// @li 0 if lhs == rhs
122 /// @li 1 if lhs > rhs
123 //------------------------------------------------------------------
124 static int Compare(const Declaration &lhs, const Declaration &rhs);
126 //------------------------------------------------------------------
127 /// Dump a description of this object to a Stream.
129 /// Dump a description of the contents of this object to the
130 /// supplied stream \a s.
133 /// The stream to which to dump the object description.
134 //------------------------------------------------------------------
135 void Dump(Stream *s, bool show_fullpaths) const;
137 bool DumpStopContext(Stream *s, bool show_fullpaths) const;
138 //------------------------------------------------------------------
139 /// Get accessor for the declaration column number.
142 /// Non-zero indicates a valid column number, zero indicates no
143 /// column information is available.
144 //------------------------------------------------------------------
145 uint32_t GetColumn() const {
146 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
153 //------------------------------------------------------------------
154 /// Get accessor for file specification.
157 /// A reference to the file specification object.
158 //------------------------------------------------------------------
159 FileSpec &GetFile() { return m_file; }
161 //------------------------------------------------------------------
162 /// Get const accessor for file specification.
165 /// A const reference to the file specification object.
166 //------------------------------------------------------------------
167 const FileSpec &GetFile() const { return m_file; }
169 //------------------------------------------------------------------
170 /// Get accessor for the declaration line number.
173 /// Non-zero indicates a valid line number, zero indicates no
174 /// line information is available.
175 //------------------------------------------------------------------
176 uint32_t GetLine() const { return m_line; }
178 bool IsValid() const { return m_file && m_line != 0; }
180 //------------------------------------------------------------------
181 /// Get the memory cost of this object.
184 /// The number of bytes that this object occupies in memory.
185 /// The returned value does not include the bytes for any
186 /// shared string values.
188 /// @see ConstString::StaticMemorySize ()
189 //------------------------------------------------------------------
190 size_t MemorySize() const;
192 //------------------------------------------------------------------
193 /// Set accessor for the declaration column number.
195 /// @param[in] column
196 /// Non-zero indicates a valid column number, zero indicates no
197 /// column information is available.
198 //------------------------------------------------------------------
199 void SetColumn(uint32_t column) {
200 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
205 //------------------------------------------------------------------
206 /// Set accessor for the declaration file specification.
208 /// @param[in] file_spec
209 /// The new declaration file specification.
210 //------------------------------------------------------------------
211 void SetFile(const FileSpec &file_spec) { m_file = file_spec; }
213 //------------------------------------------------------------------
214 /// Set accessor for the declaration line number.
217 /// Non-zero indicates a valid line number, zero indicates no
218 /// line information is available.
219 //------------------------------------------------------------------
220 void SetLine(uint32_t line) { m_line = line; }
223 //------------------------------------------------------------------
224 /// Member variables.
225 //------------------------------------------------------------------
226 FileSpec m_file; ///< The file specification that points to the
227 ///< source file where the declaration occurred.
228 uint32_t m_line; ///< Non-zero values indicates a valid line number,
229 ///< zero indicates no line number information is available.
230 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
231 uint32_t m_column; ///< Non-zero values indicates a valid column number,
232 ///< zero indicates no column information is available.
236 bool operator==(const Declaration &lhs, const Declaration &rhs);
238 } // namespace lldb_private
240 #endif // liblldb_Declaration_h_