Coverage Report

Created: 2022-01-22 13:19

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/include/lldb/Core/FileSpecList.h
Line
Count
Source (jump to first uncovered line)
1
//===-- FileSpecList.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_CORE_FILESPECLIST_H
10
#define LLDB_CORE_FILESPECLIST_H
11
#if defined(__cplusplus)
12
13
#include "lldb/Utility/FileSpec.h"
14
15
#include <vector>
16
17
#include <cstddef>
18
19
namespace lldb_private {
20
class Stream;
21
22
/// \class FileSpecList FileSpecList.h "lldb/Core/FileSpecList.h"
23
/// A file collection class.
24
///
25
/// A class that contains a mutable list of FileSpec objects.
26
class FileSpecList {
27
public:
28
  typedef std::vector<FileSpec> collection;
29
  typedef collection::const_iterator const_iterator;
30
31
  /// Default constructor.
32
  ///
33
  /// Initialize this object with an empty file list.
34
  FileSpecList();
35
36
  /// Copy constructor.
37
597k
  FileSpecList(const FileSpecList &rhs) = default;
38
39
  /// Move constructor
40
17
  FileSpecList(FileSpecList &&rhs) = default;
41
42
  /// Initialize this object from a vector of FileSpecs
43
14
  FileSpecList(std::vector<FileSpec> &&rhs) : m_files(std::move(rhs)) {}
44
45
  /// Destructor.
46
  ~FileSpecList();
47
48
  /// Assignment operator.
49
  ///
50
  /// Replace the file list in this object with the file list from \a rhs.
51
  ///
52
  /// \param[in] rhs
53
  ///     A file list object to copy.
54
  ///
55
  /// \return
56
  ///     A const reference to this object.
57
5.84k
  FileSpecList &operator=(const FileSpecList &rhs) = default;
58
59
  /// Move-assignment operator.
60
5.86k
  FileSpecList &operator=(FileSpecList &&rhs) = default;
61
62
  /// Append a FileSpec object to the list.
63
  ///
64
  /// Appends \a file to the end of the file list.
65
  ///
66
  /// \param[in] file
67
  ///     A new file to append to this file list.
68
  void Append(const FileSpec &file);
69
70
  /// Append a FileSpec object if unique.
71
  ///
72
  /// Appends \a file to the end of the file list if it doesn't already exist
73
  /// in the file list.
74
  ///
75
  /// \param[in] file
76
  ///     A new file to append to this file list.
77
  ///
78
  /// \return
79
  ///     \b true if the file was appended, \b false otherwise.
80
  bool AppendIfUnique(const FileSpec &file);
81
82
  /// Inserts a new FileSpec into the FileSpecList constructed in-place with
83
  /// the given arguments.
84
  ///
85
  /// \param[in] args
86
  ///     Arguments to create the FileSpec
87
122k
  template <class... Args> void EmplaceBack(Args &&... args) {
88
122k
    m_files.emplace_back(std::forward<Args>(args)...);
89
122k
  }
void lldb_private::FileSpecList::EmplaceBack<llvm::StringRef&>(llvm::StringRef&)
Line
Count
Source
87
15
  template <class... Args> void EmplaceBack(Args &&... args) {
88
15
    m_files.emplace_back(std::forward<Args>(args)...);
89
15
  }
void lldb_private::FileSpecList::EmplaceBack<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, llvm::sys::path::Style&>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, llvm::sys::path::Style&)
Line
Count
Source
87
117k
  template <class... Args> void EmplaceBack(Args &&... args) {
88
117k
    m_files.emplace_back(std::forward<Args>(args)...);
89
117k
  }
void lldb_private::FileSpecList::EmplaceBack<char const (&) [16]>(char const (&) [16])
Line
Count
Source
87
1.24k
  template <class... Args> void EmplaceBack(Args &&... args) {
88
1.24k
    m_files.emplace_back(std::forward<Args>(args)...);
89
1.24k
  }
void lldb_private::FileSpecList::EmplaceBack<char const (&) [18]>(char const (&) [18])
Line
Count
Source
87
1.24k
  template <class... Args> void EmplaceBack(Args &&... args) {
88
1.24k
    m_files.emplace_back(std::forward<Args>(args)...);
89
1.24k
  }
Unexecuted instantiation: void lldb_private::FileSpecList::EmplaceBack<llvm::SmallString<128u>&>(llvm::SmallString<128u>&)
void lldb_private::FileSpecList::EmplaceBack<char const*&>(char const*&)
Line
Count
Source
87
2.67k
  template <class... Args> void EmplaceBack(Args &&... args) {
88
2.67k
    m_files.emplace_back(std::forward<Args>(args)...);
89
2.67k
  }
90
91
  /// Clears the file list.
92
  void Clear();
93
94
  /// Dumps the file list to the supplied stream pointer "s".
95
  ///
96
  /// \param[in] s
97
  ///     The stream that will be used to dump the object description.
98
  void Dump(Stream *s, const char *separator_cstr = "\n") const;
99
100
  /// Find a file index.
101
  ///
102
  /// Find the index of the file in the file spec list that matches \a file
103
  /// starting \a idx entries into the file spec list.
104
  ///
105
  /// \param[in] idx
106
  ///     An index into the file list.
107
  ///
108
  /// \param[in] file
109
  ///     The file specification to search for.
110
  ///
111
  /// \param[in] full
112
  ///     Should FileSpec::Equal be called with "full" true or false.
113
  ///
114
  /// \return
115
  ///     The index of the file that matches \a file if it is found,
116
  ///     else UINT32_MAX is returned.
117
  size_t FindFileIndex(size_t idx, const FileSpec &file, bool full) const;
118
119
  /// Get file at index.
120
  ///
121
  /// Gets a file from the file list. If \a idx is not a valid index, an empty
122
  /// FileSpec object will be returned. The file objects that are returned can
123
  /// be tested using FileSpec::operator void*().
124
  ///
125
  /// \param[in] idx
126
  ///     An index into the file list.
127
  ///
128
  /// \return
129
  ///     A copy of the FileSpec object at index \a idx. If \a idx
130
  ///     is out of range, then an empty FileSpec object will be
131
  ///     returned.
132
  const FileSpec &GetFileSpecAtIndex(size_t idx) const;
133
134
  /// Get file specification pointer at index.
135
  ///
136
  /// Gets a file from the file list. The file objects that are returned can
137
  /// be tested using FileSpec::operator void*().
138
  ///
139
  /// \param[in] idx
140
  ///     An index into the file list.
141
  ///
142
  /// \return
143
  ///     A pointer to a contained FileSpec object at index \a idx.
144
  ///     If \a idx is out of range, then an NULL is returned.
145
  const FileSpec *GetFileSpecPointerAtIndex(size_t idx) const;
146
147
  /// Get the memory cost of this object.
148
  ///
149
  /// Return the size in bytes that this object takes in memory. This returns
150
  /// the size in bytes of this object, not any shared string values it may
151
  /// refer to.
152
  ///
153
  /// \return
154
  ///     The number of bytes that this object occupies in memory.
155
  ///
156
  /// \see ConstString::StaticMemorySize ()
157
  size_t MemorySize() const;
158
159
35
  bool IsEmpty() const { return m_files.empty(); }
160
161
  /// Get the number of files in the file list.
162
  ///
163
  /// \return
164
  ///     The number of files in the file spec list.
165
  size_t GetSize() const;
166
167
0
  bool Insert(size_t idx, const FileSpec &file) {
168
0
    if (idx < m_files.size()) {
169
0
      m_files.insert(m_files.begin() + idx, file);
170
0
      return true;
171
0
    } else if (idx == m_files.size()) {
172
0
      m_files.push_back(file);
173
0
      return true;
174
0
    }
175
0
    return false;
176
0
  }
177
178
1
  bool Replace(size_t idx, const FileSpec &file) {
179
1
    if (idx < m_files.size()) {
180
1
      m_files[idx] = file;
181
1
      return true;
182
1
    }
183
0
    return false;
184
1
  }
185
186
0
  bool Remove(size_t idx) {
187
0
    if (idx < m_files.size()) {
188
0
      m_files.erase(m_files.begin() + idx);
189
0
      return true;
190
0
    }
191
0
    return false;
192
0
  }
193
194
  static size_t GetFilesMatchingPartialPath(const char *path, bool dir_okay,
195
                                            FileSpecList &matches);
196
197
4.47k
  const_iterator begin() const { return m_files.begin(); }
198
4.47k
  const_iterator end() const { return m_files.end(); }
199
200
protected:
201
  collection m_files; ///< A collection of FileSpec objects.
202
};
203
204
} // namespace lldb_private
205
206
#endif // #if defined(__cplusplus)
207
#endif // LLDB_CORE_FILESPECLIST_H