Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/include/lldb/Core/Declaration.h
Line
Count
Source (jump to first uncovered line)
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 LLDB_SYMBOL_DECLARATION_H
10
#define LLDB_SYMBOL_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/Core/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
177k
  Declaration() {}
28
29
  /// Construct with file specification, and optional line and column.
30
  ///
31
  /// \param[in] file_spec
32
  ///     The file specification that describes where this was
33
  ///     declared.
34
  ///
35
  /// \param[in] line
36
  ///     The line number that describes where this was declared. Set
37
  ///     to zero if there is no line number information.
38
  ///
39
  /// \param[in] column
40
  ///     The column number that describes where this was declared.
41
  ///     Set to zero if there is no column number information.
42
  Declaration(const FileSpec &file_spec, uint32_t line = 0,
43
              uint16_t column = LLDB_INVALID_COLUMN_NUMBER)
44
172k
      : m_file(file_spec), m_line(line), m_column(column) {}
45
46
  /// Construct with a pointer to another Declaration object.
47
  Declaration(const Declaration *decl_ptr)
48
163k
      : m_line(0), m_column(LLDB_INVALID_COLUMN_NUMBER) {
49
163k
    if (decl_ptr)
50
163k
      *this = *decl_ptr;
51
163k
  }
52
53
  /// Clear the object's state.
54
  ///
55
  /// Sets the file specification to be empty, and the line and column to
56
  /// zero.
57
11.8k
  void Clear() {
58
11.8k
    m_file.Clear();
59
11.8k
    m_line = 0;
60
11.8k
    m_column = 0;
61
11.8k
  }
62
63
  /// Compare two declaration objects.
64
  ///
65
  /// Compares the two file specifications from \a lhs and \a rhs. If the file
66
  /// specifications are equal, then continue to compare the line number and
67
  /// column numbers respectively.
68
  ///
69
  /// \param[in] lhs
70
  ///     The Left Hand Side const Declaration object reference.
71
  ///
72
  /// \param[in] rhs
73
  ///     The Right Hand Side const Declaration object reference.
74
  ///
75
  /// \return
76
  ///     -1 if lhs < rhs
77
  ///     0 if lhs == rhs
78
  ///     1 if lhs > rhs
79
  static int Compare(const Declaration &lhs, const Declaration &rhs);
80
81
  /// Checks if this object has the same file and line as another declaration
82
  /// object.
83
  ///
84
  /// \param[in] declaration
85
  ///     The const Declaration object to compare with.
86
  ///
87
  /// \return
88
  ///     Returns \b true if \b declaration is at the same file and
89
  ///     line, \b false otherwise.
90
  bool FileAndLineEqual(const Declaration &declaration) const;
91
92
  /// Dump a description of this object to a Stream.
93
  ///
94
  /// Dump a description of the contents of this object to the supplied stream
95
  /// \a s.
96
  ///
97
  /// \param[in] s
98
  ///     The stream to which to dump the object description.
99
  void Dump(Stream *s, bool show_fullpaths) const;
100
101
  bool DumpStopContext(Stream *s, bool show_fullpaths) const;
102
103
  /// Get accessor for file specification.
104
  ///
105
  /// \return
106
  ///     A reference to the file specification object.
107
9
  FileSpec &GetFile() { return m_file; }
108
109
  /// Get const accessor for file specification.
110
  ///
111
  /// \return
112
  ///     A const reference to the file specification object.
113
458k
  const FileSpec &GetFile() const { return m_file; }
114
115
  /// Get accessor for the declaration line number.
116
  ///
117
  /// \return
118
  ///     Non-zero indicates a valid line number, zero indicates no
119
  ///     line information is available.
120
327k
  uint32_t GetLine() const { return m_line; }
121
122
  /// Get accessor for the declaration column number.
123
  ///
124
  /// \return
125
  ///     Non-zero indicates a valid column number, zero indicates no
126
  ///     column information is available.
127
314k
  uint16_t GetColumn() const { return m_column; }
128
129
  /// Convert to boolean operator.
130
  ///
131
  /// This allows code to check a Declaration object to see if it
132
  /// contains anything valid using code such as:
133
  ///
134
  /// \code
135
  /// Declaration decl(...);
136
  /// if (decl)
137
  /// { ...
138
  /// \endcode
139
  ///
140
  /// \return
141
  ///     A \b true if both the file_spec and the line are valid,
142
  ///     \b false otherwise.
143
0
  explicit operator bool() const { return IsValid(); }
144
145
1.68k
  bool IsValid() const {
146
1.68k
    return m_file && 
m_line != 01.68k
&&
m_line != 1.68k
LLDB_INVALID_LINE_NUMBER1.68k
;
147
1.68k
  }
148
149
  /// Get the memory cost of this object.
150
  ///
151
  /// \return
152
  ///     The number of bytes that this object occupies in memory.
153
  ///     The returned value does not include the bytes for any
154
  ///     shared string values.
155
  ///
156
  /// \see ConstString::StaticMemorySize ()
157
  size_t MemorySize() const;
158
159
  /// Set accessor for the declaration file specification.
160
  ///
161
  /// \param[in] file_spec
162
  ///     The new declaration file specification.
163
117k
  void SetFile(const FileSpec &file_spec) { m_file = file_spec; }
164
165
  /// Set accessor for the declaration line number.
166
  ///
167
  /// \param[in] line
168
  ///     Non-zero indicates a valid line number, zero indicates no
169
  ///     line information is available.
170
117k
  void SetLine(uint32_t line) { m_line = line; }
171
172
  /// Set accessor for the declaration column number.
173
  ///
174
  /// \param[in] column
175
  ///     Non-zero indicates a valid column number, zero indicates no
176
  ///     column information is available.
177
0
  void SetColumn(uint16_t column) { m_column = column; }
178
179
protected:
180
  /// The file specification that points to the source file where the
181
  /// declaration occurred.
182
  FileSpec m_file;
183
  /// Non-zero values indicates a valid line number, zero indicates no line
184
  /// number information is available.
185
  uint32_t m_line = 0;
186
  /// Non-zero values indicates a valid column number, zero indicates no column
187
  /// information is available.
188
  uint16_t m_column = LLDB_INVALID_COLUMN_NUMBER;
189
};
190
191
bool operator==(const Declaration &lhs, const Declaration &rhs);
192
193
} // namespace lldb_private
194
195
#endif // LLDB_SYMBOL_DECLARATION_H