]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Symbol/Declaration.h
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r305575, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Symbol / Declaration.h
1 //===-- Declaration.h -------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_Declaration_h_
11 #define liblldb_Declaration_h_
12
13 #include "lldb/Utility/FileSpec.h"
14 #include "lldb/lldb-private.h"
15
16 namespace lldb_private {
17
18 //----------------------------------------------------------------------
19 /// @class Declaration Declaration.h "lldb/Symbol/Declaration.h"
20 /// @brief A class that describes the declaration location of a
21 ///        lldb object.
22 ///
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
26 /// declared.
27 //----------------------------------------------------------------------
28 class Declaration {
29 public:
30   //------------------------------------------------------------------
31   /// Default constructor.
32   //------------------------------------------------------------------
33   Declaration()
34       : m_file(), m_line(0)
35 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
36         ,
37         m_column(0)
38 #endif
39   {
40   }
41
42   //------------------------------------------------------------------
43   /// Construct with file specification, and optional line and column.
44   ///
45   /// @param[in] file_spec
46   ///     The file specification that describes where this was
47   ///     declared.
48   ///
49   /// @param[in] line
50   ///     The line number that describes where this was declared. Set
51   ///     to zero if there is no line number information.
52   ///
53   /// @param[in] column
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
60         ,
61         m_column(column)
62 #endif
63   {
64   }
65
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
72         ,
73         m_column(rhs.m_column)
74 #endif
75   {
76   }
77
78   //------------------------------------------------------------------
79   /// Construct with a pointer to another Declaration object.
80   //------------------------------------------------------------------
81   Declaration(const Declaration *decl_ptr)
82       : m_file(), m_line(0)
83 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
84         ,
85         m_column(0)
86 #endif
87   {
88     if (decl_ptr)
89       *this = *decl_ptr;
90   }
91
92   //------------------------------------------------------------------
93   /// Clear the object's state.
94   ///
95   /// Sets the file specification to be empty, and the line and column
96   /// to zero.
97   //------------------------------------------------------------------
98   void Clear() {
99     m_file.Clear();
100     m_line = 0;
101 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
102     m_column = 0;
103 #endif
104   }
105
106   //------------------------------------------------------------------
107   /// Compare two declaration objects.
108   ///
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.
112   ///
113   /// @param[in] lhs
114   ///     The Left Hand Side const Declaration object reference.
115   ///
116   /// @param[in] rhs
117   ///     The Right Hand Side const Declaration object reference.
118   ///
119   /// @return
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);
125
126   //------------------------------------------------------------------
127   /// Dump a description of this object to a Stream.
128   ///
129   /// Dump a description of the contents of this object to the
130   /// supplied stream \a s.
131   ///
132   /// @param[in] s
133   ///     The stream to which to dump the object description.
134   //------------------------------------------------------------------
135   void Dump(Stream *s, bool show_fullpaths) const;
136
137   bool DumpStopContext(Stream *s, bool show_fullpaths) const;
138   //------------------------------------------------------------------
139   /// Get accessor for the declaration column number.
140   ///
141   /// @return
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
147     return m_column;
148 #else
149     return 0;
150 #endif
151   }
152
153   //------------------------------------------------------------------
154   /// Get accessor for file specification.
155   ///
156   /// @return
157   ///     A reference to the file specification object.
158   //------------------------------------------------------------------
159   FileSpec &GetFile() { return m_file; }
160
161   //------------------------------------------------------------------
162   /// Get const accessor for file specification.
163   ///
164   /// @return
165   ///     A const reference to the file specification object.
166   //------------------------------------------------------------------
167   const FileSpec &GetFile() const { return m_file; }
168
169   //------------------------------------------------------------------
170   /// Get accessor for the declaration line number.
171   ///
172   /// @return
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; }
177
178   bool IsValid() const { return m_file && m_line != 0; }
179
180   //------------------------------------------------------------------
181   /// Get the memory cost of this object.
182   ///
183   /// @return
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.
187   ///
188   /// @see ConstString::StaticMemorySize ()
189   //------------------------------------------------------------------
190   size_t MemorySize() const;
191
192   //------------------------------------------------------------------
193   /// Set accessor for the declaration column number.
194   ///
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
201     m_column = col;
202 #endif
203   }
204
205   //------------------------------------------------------------------
206   /// Set accessor for the declaration file specification.
207   ///
208   /// @param[in] file_spec
209   ///     The new declaration file specification.
210   //------------------------------------------------------------------
211   void SetFile(const FileSpec &file_spec) { m_file = file_spec; }
212
213   //------------------------------------------------------------------
214   /// Set accessor for the declaration line number.
215   ///
216   /// @param[in] line
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; }
221
222 protected:
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.
233 #endif
234 };
235
236 bool operator==(const Declaration &lhs, const Declaration &rhs);
237
238 } // namespace lldb_private
239
240 #endif // liblldb_Declaration_h_