]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/include/lldb/Symbol/Declaration.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / include / lldb / Symbol / Declaration.h
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 liblldb_Declaration_h_
10 #define liblldb_Declaration_h_
11
12 #include "lldb/Utility/FileSpec.h"
13 #include "lldb/lldb-private.h"
14
15 namespace lldb_private {
16
17 /// \class Declaration Declaration.h "lldb/Symbol/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.
24 class Declaration {
25 public:
26   /// Default constructor.
27   Declaration()
28       : m_file(), m_line(0)
29 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
30         ,
31         m_column(0)
32 #endif
33   {
34   }
35
36   /// Construct with file specification, and optional line and column.
37   ///
38   /// \param[in] file_spec
39   ///     The file specification that describes where this was
40   ///     declared.
41   ///
42   /// \param[in] line
43   ///     The line number that describes where this was declared. Set
44   ///     to zero if there is no line number information.
45   ///
46   /// \param[in] column
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
52         ,
53         m_column(column)
54 #endif
55   {
56   }
57
58   /// Construct with a pointer to another Declaration object.
59   Declaration(const Declaration *decl_ptr)
60       : m_file(), m_line(0)
61 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
62         ,
63         m_column(0)
64 #endif
65   {
66     if (decl_ptr)
67       *this = *decl_ptr;
68   }
69
70   /// Clear the object's state.
71   ///
72   /// Sets the file specification to be empty, and the line and column to
73   /// zero.
74   void Clear() {
75     m_file.Clear();
76     m_line = 0;
77 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
78     m_column = 0;
79 #endif
80   }
81
82   /// Compare two declaration objects.
83   ///
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.
87   ///
88   /// \param[in] lhs
89   ///     The Left Hand Side const Declaration object reference.
90   ///
91   /// \param[in] rhs
92   ///     The Right Hand Side const Declaration object reference.
93   ///
94   /// \return
95   ///     -1 if lhs < rhs
96   ///     0 if lhs == rhs
97   ///     1 if lhs > rhs
98   static int Compare(const Declaration &lhs, const Declaration &rhs);
99
100   /// Checks if this object has the same file and line as another declaration
101   /// object.
102   ///
103   /// \param[in] declaration
104   ///     The const Declaration object to compare with.
105   ///
106   /// \return
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;
110
111   /// Dump a description of this object to a Stream.
112   ///
113   /// Dump a description of the contents of this object to the supplied stream
114   /// \a s.
115   ///
116   /// \param[in] s
117   ///     The stream to which to dump the object description.
118   void Dump(Stream *s, bool show_fullpaths) const;
119
120   bool DumpStopContext(Stream *s, bool show_fullpaths) const;
121   /// Get accessor for the declaration column number.
122   ///
123   /// \return
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
128     return m_column;
129 #else
130     return 0;
131 #endif
132   }
133
134   /// Get accessor for file specification.
135   ///
136   /// \return
137   ///     A reference to the file specification object.
138   FileSpec &GetFile() { return m_file; }
139
140   /// Get const accessor for file specification.
141   ///
142   /// \return
143   ///     A const reference to the file specification object.
144   const FileSpec &GetFile() const { return m_file; }
145
146   /// Get accessor for the declaration line number.
147   ///
148   /// \return
149   ///     Non-zero indicates a valid line number, zero indicates no
150   ///     line information is available.
151   uint32_t GetLine() const { return m_line; }
152
153   bool IsValid() const { return m_file && m_line != 0; }
154
155   /// Get the memory cost of this object.
156   ///
157   /// \return
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.
161   ///
162   /// \see ConstString::StaticMemorySize ()
163   size_t MemorySize() const;
164
165   /// Set accessor for the declaration column number.
166   ///
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
172     m_column = col;
173 #endif
174   }
175
176   /// Set accessor for the declaration file specification.
177   ///
178   /// \param[in] file_spec
179   ///     The new declaration file specification.
180   void SetFile(const FileSpec &file_spec) { m_file = file_spec; }
181
182   /// Set accessor for the declaration line number.
183   ///
184   /// \param[in] line
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; }
188
189 protected:
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.
198 #endif
199 };
200
201 bool operator==(const Declaration &lhs, const Declaration &rhs);
202
203 } // namespace lldb_private
204
205 #endif // liblldb_Declaration_h_