LLDB  mainline
Declaration.h
Go to the documentation of this file.
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.
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 reference to another Declaration object.
60  : m_file(rhs.m_file), m_line(rhs.m_line)
61 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
62  ,
63  m_column(rhs.m_column)
64 #endif
65  {
66  }
67 
68  /// Construct with a pointer to another Declaration object.
69  Declaration(const Declaration *decl_ptr)
70  : m_file(), m_line(0)
71 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
72  ,
73  m_column(0)
74 #endif
75  {
76  if (decl_ptr)
77  *this = *decl_ptr;
78  }
79 
80  /// Clear the object's state.
81  ///
82  /// Sets the file specification to be empty, and the line and column to
83  /// zero.
84  void Clear() {
85  m_file.Clear();
86  m_line = 0;
87 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS
88  m_column = 0;
89 #endif
90  }
91 
92  /// Compare two declaration objects.
93  ///
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.
97  ///
98  /// \param[in] lhs
99  /// The Left Hand Side const Declaration object reference.
100  ///
101  /// \param[in] rhs
102  /// The Right Hand Side const Declaration object reference.
103  ///
104  /// \return
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);
109 
110  /// Checks if this object has the same file and line as another declaration
111  /// object.
112  ///
113  /// \param[in] declaration
114  /// The const Declaration object to compare with.
115  ///
116  /// \return
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;
120 
121  /// Dump a description of this object to a Stream.
122  ///
123  /// Dump a description of the contents of this object to the supplied stream
124  /// \a s.
125  ///
126  /// \param[in] s
127  /// The stream to which to dump the object description.
128  void Dump(Stream *s, bool show_fullpaths) const;
129 
130  bool DumpStopContext(Stream *s, bool show_fullpaths) const;
131  /// Get accessor for the declaration column number.
132  ///
133  /// \return
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
138  return m_column;
139 #else
140  return 0;
141 #endif
142  }
143 
144  /// Get accessor for file specification.
145  ///
146  /// \return
147  /// A reference to the file specification object.
148  FileSpec &GetFile() { return m_file; }
149 
150  /// Get const accessor for file specification.
151  ///
152  /// \return
153  /// A const reference to the file specification object.
154  const FileSpec &GetFile() const { return m_file; }
155 
156  /// Get accessor for the declaration line number.
157  ///
158  /// \return
159  /// Non-zero indicates a valid line number, zero indicates no
160  /// line information is available.
161  uint32_t GetLine() const { return m_line; }
162 
163  bool IsValid() const { return m_file && m_line != 0; }
164 
165  /// Get the memory cost of this object.
166  ///
167  /// \return
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.
171  ///
172  /// \see ConstString::StaticMemorySize ()
173  size_t MemorySize() const;
174 
175  /// Set accessor for the declaration column number.
176  ///
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
182  m_column = col;
183 #endif
184  }
185 
186  /// Set accessor for the declaration file specification.
187  ///
188  /// \param[in] file_spec
189  /// The new declaration file specification.
190  void SetFile(const FileSpec &file_spec) { m_file = file_spec; }
191 
192  /// Set accessor for the declaration line number.
193  ///
194  /// \param[in] line
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; }
198 
199 protected:
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.
208 #endif
209 };
210 
211 bool operator==(const Declaration &lhs, const Declaration &rhs);
212 
213 } // namespace lldb_private
214 
215 #endif // liblldb_Declaration_h_
Declaration(const FileSpec &file_spec, uint32_t line=0, uint32_t column=0)
Construct with file specification, and optional line and column.
Definition: Declaration.h:49
void SetFile(const FileSpec &file_spec)
Set accessor for the declaration file specification.
Definition: Declaration.h:190
void SetColumn(uint32_t column)
Set accessor for the declaration column number.
Definition: Declaration.h:180
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
void Clear()
Clear the object&#39;s state.
Definition: Declaration.h:84
static int Compare(const Declaration &lhs, const Declaration &rhs)
Compare two declaration objects.
Definition: Declaration.cpp:69
A file utility class.
Definition: FileSpec.h:55
void Clear()
Clears the object state.
Definition: FileSpec.cpp:285
Declaration()
Default constructor.
Definition: Declaration.h:27
FileSpec m_file
Member variables.
Definition: Declaration.h:201
bool operator==(const Address &lhs, const Address &rhs)
Definition: Address.cpp:973
FileSpec & GetFile()
Get accessor for file specification.
Definition: Declaration.h:148
bool DumpStopContext(Stream *s, bool show_fullpaths) const
Definition: Declaration.cpp:42
uint32_t GetLine() const
Get accessor for the declaration line number.
Definition: Declaration.h:161
Declaration(const Declaration *decl_ptr)
Construct with a pointer to another Declaration object.
Definition: Declaration.h:69
void Dump(Stream *s, bool show_fullpaths) const
Dump a description of this object to a Stream.
Definition: Declaration.cpp:14
const FileSpec & GetFile() const
Get const accessor for file specification.
Definition: Declaration.h:154
Declaration(const Declaration &rhs)
Construct with a reference to another Declaration object.
Definition: Declaration.h:59
bool FileAndLineEqual(const Declaration &declaration) const
Checks if this object has the same file and line as another declaration object.
Definition: Declaration.cpp:86
void SetLine(uint32_t line)
Set accessor for the declaration line number.
Definition: Declaration.h:197
size_t MemorySize() const
Get the memory cost of this object.
Definition: Declaration.cpp:67
A class that describes the declaration location of a lldb object.
Definition: Declaration.h:24
uint32_t m_line
Non-zero values indicates a valid line number, zero indicates no line number information is available...
Definition: Declaration.h:203
uint32_t GetColumn() const
Get accessor for the declaration column number.
Definition: Declaration.h:136