Coverage Report

Created: 2020-09-19 12:23

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/ASTVector.h
Line
Count
Source (jump to first uncovered line)
1
//===- ASTVector.h - Vector that uses ASTContext for allocation ---*- 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
//  This file provides ASTVector, a vector  ADT whose contents are
10
//  allocated using the allocator associated with an ASTContext..
11
//
12
//===----------------------------------------------------------------------===//
13
14
// FIXME: Most of this is copy-and-paste from BumpVector.h and SmallVector.h.
15
// We can refactor this core logic into something common.
16
17
#ifndef LLVM_CLANG_AST_ASTVECTOR_H
18
#define LLVM_CLANG_AST_ASTVECTOR_H
19
20
#include "clang/AST/ASTContextAllocate.h"
21
#include "llvm/ADT/PointerIntPair.h"
22
#include <algorithm>
23
#include <cassert>
24
#include <cstddef>
25
#include <cstring>
26
#include <iterator>
27
#include <memory>
28
#include <type_traits>
29
#include <utility>
30
31
namespace clang {
32
33
class ASTContext;
34
35
template<typename T>
36
class ASTVector {
37
private:
38
  T *Begin = nullptr;
39
  T *End = nullptr;
40
  llvm::PointerIntPair<T *, 1, bool> Capacity;
41
42
834k
  void setEnd(T *P) { this->End = P; }
clang::ASTVector<clang::DeclAccessPair>::setEnd(clang::DeclAccessPair*)
Line
Count
Source
42
728
  void setEnd(T *P) { this->End = P; }
clang::ASTVector<clang::Stmt*>::setEnd(clang::Stmt**)
Line
Count
Source
42
610k
  void setEnd(T *P) { this->End = P; }
clang::ASTVector<unsigned long long>::setEnd(unsigned long long*)
Line
Count
Source
42
224k
  void setEnd(T *P) { this->End = P; }
43
44
protected:
45
  // Make a tag bit available to users of this class.
46
  // FIXME: This is a horrible hack.
47
9.86M
  bool getTag() const { return Capacity.getInt(); }
48
28.4k
  void setTag(bool B) { Capacity.setInt(B); }
49
50
public:
51
  // Default ctor - Initialize to empty.
52
6.02M
  ASTVector() : Capacity(nullptr, false) {}
clang::ASTVector<clang::DeclAccessPair>::ASTVector()
Line
Count
Source
52
5.70M
  ASTVector() : Capacity(nullptr, false) {}
clang::ASTVector<unsigned long long>::ASTVector()
Line
Count
Source
52
315k
  ASTVector() : Capacity(nullptr, false) {}
clang::ASTVector<clang::Stmt*>::ASTVector()
Line
Count
Source
52
5.07k
  ASTVector() : Capacity(nullptr, false) {}
53
54
12
  ASTVector(ASTVector &&O) : Begin(O.Begin), End(O.End), Capacity(O.Capacity) {
55
12
    O.Begin = O.End = nullptr;
56
12
    O.Capacity.setPointer(nullptr);
57
12
    O.Capacity.setInt(false);
58
12
  }
59
60
259k
  ASTVector(const ASTContext &C, unsigned N) : Capacity(nullptr, false) {
61
259k
    reserve(C, N);
62
259k
  }
63
64
12
  ASTVector &operator=(ASTVector &&RHS) {
65
12
    ASTVector O(std::move(RHS));
66
12
67
12
    using std::swap;
68
12
69
12
    swap(Begin, O.Begin);
70
12
    swap(End, O.End);
71
12
    swap(Capacity, O.Capacity);
72
12
    return *this;
73
12
  }
74
75
208k
  ~ASTVector() {
76
208k
    if (std::is_class<T>::value) {
77
      // Destroy the constructed elements in the vector.
78
12
      destroy_range(Begin, End);
79
12
    }
80
208k
  }
clang::ASTVector<unsigned long long>::~ASTVector()
Line
Count
Source
75
170k
  ~ASTVector() {
76
170k
    if (std::is_class<T>::value) {
77
      // Destroy the constructed elements in the vector.
78
0
      destroy_range(Begin, End);
79
0
    }
80
170k
  }
clang::ASTVector<clang::DeclAccessPair>::~ASTVector()
Line
Count
Source
75
12
  ~ASTVector() {
76
12
    if (std::is_class<T>::value) {
77
      // Destroy the constructed elements in the vector.
78
12
      destroy_range(Begin, End);
79
12
    }
80
12
  }
clang::ASTVector<clang::Stmt*>::~ASTVector()
Line
Count
Source
75
37.4k
  ~ASTVector() {
76
37.4k
    if (std::is_class<T>::value) {
77
      // Destroy the constructed elements in the vector.
78
0
      destroy_range(Begin, End);
79
0
    }
80
37.4k
  }
81
82
  using size_type = size_t;
83
  using difference_type = ptrdiff_t;
84
  using value_type = T;
85
  using iterator = T *;
86
  using const_iterator = const T *;
87
88
  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
89
  using reverse_iterator = std::reverse_iterator<iterator>;
90
91
  using reference = T &;
92
  using const_reference = const T &;
93
  using pointer = T *;
94
  using const_pointer = const T *;
95
96
  // forward iterator creation methods.
97
7.89M
  iterator begin() { return Begin; }
clang::ASTVector<clang::DeclAccessPair>::begin()
Line
Count
Source
97
6.35M
  iterator begin() { return Begin; }
clang::ASTVector<clang::Stmt*>::begin()
Line
Count
Source
97
1.53M
  iterator begin() { return Begin; }
98
222k
  const_iterator begin() const { return Begin; }
clang::ASTVector<clang::DeclAccessPair>::begin() const
Line
Count
Source
98
113k
  const_iterator begin() const { return Begin; }
clang::ASTVector<clang::Stmt*>::begin() const
Line
Count
Source
98
108k
  const_iterator begin() const { return Begin; }
99
10.3M
  iterator end() { return End; }
clang::ASTVector<clang::DeclAccessPair>::end()
Line
Count
Source
99
6.36M
  iterator end() { return End; }
clang::ASTVector<clang::Stmt*>::end()
Line
Count
Source
99
3.34M
  iterator end() { return End; }
clang::ASTVector<unsigned long long>::end()
Line
Count
Source
99
672k
  iterator end() { return End; }
100
222k
  const_iterator end() const { return End; }
clang::ASTVector<clang::DeclAccessPair>::end() const
Line
Count
Source
100
113k
  const_iterator end() const { return End; }
clang::ASTVector<clang::Stmt*>::end() const
Line
Count
Source
100
108k
  const_iterator end() const { return End; }
101
102
  // reverse iterator creation methods.
103
0
  reverse_iterator rbegin()            { return reverse_iterator(end()); }
104
974
  const_reverse_iterator rbegin() const{ return const_reverse_iterator(end()); }
105
0
  reverse_iterator rend()              { return reverse_iterator(begin()); }
106
974
  const_reverse_iterator rend() const { return const_reverse_iterator(begin());}
107
108
271k
  bool empty() const { return Begin == End; }
clang::ASTVector<clang::DeclAccessPair>::empty() const
Line
Count
Source
108
28.2k
  bool empty() const { return Begin == End; }
clang::ASTVector<clang::Stmt*>::empty() const
Line
Count
Source
108
243k
  bool empty() const { return Begin == End; }
109
9.78M
  size_type size() const { return End-Begin; }
clang::ASTVector<clang::DeclAccessPair>::size() const
Line
Count
Source
109
171k
  size_type size() const { return End-Begin; }
clang::ASTVector<clang::Stmt*>::size() const
Line
Count
Source
109
9.02M
  size_type size() const { return End-Begin; }
clang::ASTVector<unsigned long long>::size() const
Line
Count
Source
109
593k
  size_type size() const { return End-Begin; }
110
111
3.81M
  reference operator[](unsigned idx) {
112
3.81M
    assert(Begin + idx < End);
113
3.81M
    return Begin[idx];
114
3.81M
  }
Unexecuted instantiation: clang::ASTVector<clang::DeclAccessPair>::operator[](unsigned int)
clang::ASTVector<clang::Stmt*>::operator[](unsigned int)
Line
Count
Source
111
3.81M
  reference operator[](unsigned idx) {
112
3.81M
    assert(Begin + idx < End);
113
3.81M
    return Begin[idx];
114
3.81M
  }
115
1.72M
  const_reference operator[](unsigned idx) const {
116
1.72M
    assert(Begin + idx < End);
117
1.72M
    return Begin[idx];
118
1.72M
  }
Unexecuted instantiation: clang::ASTVector<clang::DeclAccessPair>::operator[](unsigned int) const
clang::ASTVector<clang::Stmt*>::operator[](unsigned int) const
Line
Count
Source
115
702k
  const_reference operator[](unsigned idx) const {
116
702k
    assert(Begin + idx < End);
117
702k
    return Begin[idx];
118
702k
  }
clang::ASTVector<unsigned long long>::operator[](unsigned int) const
Line
Count
Source
115
1.02M
  const_reference operator[](unsigned idx) const {
116
1.02M
    assert(Begin + idx < End);
117
1.02M
    return Begin[idx];
118
1.02M
  }
119
120
  reference front() {
121
    return begin()[0];
122
  }
123
  const_reference front() const {
124
    return begin()[0];
125
  }
126
127
0
  reference back() {
128
0
    return end()[-1];
129
0
  }
130
  const_reference back() const {
131
    return end()[-1];
132
  }
133
134
0
  void pop_back() {
135
0
    --End;
136
0
    End->~T();
137
0
  }
138
139
0
  T pop_back_val() {
140
0
    T Result = back();
141
0
    pop_back();
142
0
    return Result;
143
0
  }
144
145
0
  void clear() {
146
0
    if (std::is_class<T>::value) {
147
0
      destroy_range(Begin, End);
148
0
    }
149
0
    End = Begin;
150
0
  }
151
152
  /// data - Return a pointer to the vector's buffer, even if empty().
153
358k
  pointer data() {
154
358k
    return pointer(Begin);
155
358k
  }
156
157
  /// data - Return a pointer to the vector's buffer, even if empty().
158
17
  const_pointer data() const {
159
17
    return const_pointer(Begin);
160
17
  }
161
162
57.3k
  void push_back(const_reference Elt, const ASTContext &C) {
163
57.3k
    if (End < this->capacity_ptr()) {
164
57.3k
    Retry:
165
57.3k
      new (End) T(Elt);
166
57.3k
      ++End;
167
57.3k
      return;
168
29.0k
    }
169
29.0k
    grow(C);
170
29.0k
    goto Retry;
171
29.0k
  }
172
173
1.19M
  void reserve(const ASTContext &C, unsigned N) {
174
1.19M
    if (unsigned(this->capacity_ptr()-Begin) < N)
175
212k
      grow(C, N);
176
1.19M
  }
clang::ASTVector<clang::DeclAccessPair>::reserve(clang::ASTContext const&, unsigned int)
Line
Count
Source
173
851k
  void reserve(const ASTContext &C, unsigned N) {
174
851k
    if (unsigned(this->capacity_ptr()-Begin) < N)
175
27.0k
      grow(C, N);
176
851k
  }
clang::ASTVector<clang::Stmt*>::reserve(clang::ASTContext const&, unsigned int)
Line
Count
Source
173
345k
  void reserve(const ASTContext &C, unsigned N) {
174
345k
    if (unsigned(this->capacity_ptr()-Begin) < N)
175
185k
      grow(C, N);
176
345k
  }
177
178
  /// capacity - Return the total number of elements in the currently allocated
179
  /// buffer.
180
491k
  size_t capacity() const { return this->capacity_ptr() - Begin; }
clang::ASTVector<clang::DeclAccessPair>::capacity() const
Line
Count
Source
180
56.8k
  size_t capacity() const { return this->capacity_ptr() - Begin; }
clang::ASTVector<clang::Stmt*>::capacity() const
Line
Count
Source
180
210k
  size_t capacity() const { return this->capacity_ptr() - Begin; }
clang::ASTVector<unsigned long long>::capacity() const
Line
Count
Source
180
224k
  size_t capacity() const { return this->capacity_ptr() - Begin; }
181
182
  /// append - Add the specified range to the end of the SmallVector.
183
  template<typename in_iter>
184
581k
  void append(const ASTContext &C, in_iter in_start, in_iter in_end) {
185
581k
    size_type NumInputs = std::distance(in_start, in_end);
186
581k
187
581k
    if (NumInputs == 0)
188
256k
      return;
189
324k
190
    // Grow allocated space if needed.
191
324k
    if (NumInputs > size_type(this->capacity_ptr()-this->end()))
192
224k
      this->grow(C, this->size()+NumInputs);
193
324k
194
    // Copy the new elements over.
195
    // TODO: NEED To compile time dispatch on whether in_iter is a random access
196
    // iterator to use the fast uninitialized_copy.
197
324k
    std::uninitialized_copy(in_start, in_end, this->end());
198
324k
    this->setEnd(this->end() + NumInputs);
199
324k
  }
void clang::ASTVector<clang::DeclAccessPair>::append<clang::DeclAccessPair*>(clang::ASTContext const&, clang::DeclAccessPair*, clang::DeclAccessPair*)
Line
Count
Source
184
6.03k
  void append(const ASTContext &C, in_iter in_start, in_iter in_end) {
185
6.03k
    size_type NumInputs = std::distance(in_start, in_end);
186
6.03k
187
6.03k
    if (NumInputs == 0)
188
5.30k
      return;
189
728
190
    // Grow allocated space if needed.
191
728
    if (NumInputs > size_type(this->capacity_ptr()-this->end()))
192
728
      this->grow(C, this->size()+NumInputs);
193
728
194
    // Copy the new elements over.
195
    // TODO: NEED To compile time dispatch on whether in_iter is a random access
196
    // iterator to use the fast uninitialized_copy.
197
728
    std::uninitialized_copy(in_start, in_end, this->end());
198
728
    this->setEnd(this->end() + NumInputs);
199
728
  }
void clang::ASTVector<clang::Stmt*>::append<clang::Expr* const*>(clang::ASTContext const&, clang::Expr* const*, clang::Expr* const*)
Line
Count
Source
184
259k
  void append(const ASTContext &C, in_iter in_start, in_iter in_end) {
185
259k
    size_type NumInputs = std::distance(in_start, in_end);
186
259k
187
259k
    if (NumInputs == 0)
188
159k
      return;
189
100k
190
    // Grow allocated space if needed.
191
100k
    if (NumInputs > size_type(this->capacity_ptr()-this->end()))
192
0
      this->grow(C, this->size()+NumInputs);
193
100k
194
    // Copy the new elements over.
195
    // TODO: NEED To compile time dispatch on whether in_iter is a random access
196
    // iterator to use the fast uninitialized_copy.
197
100k
    std::uninitialized_copy(in_start, in_end, this->end());
198
100k
    this->setEnd(this->end() + NumInputs);
199
100k
  }
Unexecuted instantiation: void clang::ASTVector<clang::Stmt*>::append<clang::Stmt**>(clang::ASTContext const&, clang::Stmt**, clang::Stmt**)
void clang::ASTVector<unsigned long long>::append<unsigned long long const*>(clang::ASTContext const&, unsigned long long const*, unsigned long long const*)
Line
Count
Source
184
315k
  void append(const ASTContext &C, in_iter in_start, in_iter in_end) {
185
315k
    size_type NumInputs = std::distance(in_start, in_end);
186
315k
187
315k
    if (NumInputs == 0)
188
91.9k
      return;
189
224k
190
    // Grow allocated space if needed.
191
224k
    if (NumInputs > size_type(this->capacity_ptr()-this->end()))
192
224k
      this->grow(C, this->size()+NumInputs);
193
224k
194
    // Copy the new elements over.
195
    // TODO: NEED To compile time dispatch on whether in_iter is a random access
196
    // iterator to use the fast uninitialized_copy.
197
224k
    std::uninitialized_copy(in_start, in_end, this->end());
198
224k
    this->setEnd(this->end() + NumInputs);
199
224k
  }
200
201
  /// append - Add the specified range to the end of the SmallVector.
202
504k
  void append(const ASTContext &C, size_type NumInputs, const T &Elt) {
203
    // Grow allocated space if needed.
204
504k
    if (NumInputs > size_type(this->capacity_ptr()-this->end()))
205
19.2k
      this->grow(C, this->size()+NumInputs);
206
504k
207
    // Copy the new elements over.
208
504k
    std::uninitialized_fill_n(this->end(), NumInputs, Elt);
209
504k
    this->setEnd(this->end() + NumInputs);
210
504k
  }
211
212
  /// uninitialized_copy - Copy the range [I, E) onto the uninitialized memory
213
  /// starting with "Dest", constructing elements into it as needed.
214
  template<typename It1, typename It2>
215
0
  static void uninitialized_copy(It1 I, It1 E, It2 Dest) {
216
0
    std::uninitialized_copy(I, E, Dest);
217
0
  }
Unexecuted instantiation: void clang::ASTVector<clang::Stmt*>::uninitialized_copy<clang::Stmt**, clang::Stmt**>(clang::Stmt**, clang::Stmt**, clang::Stmt**)
Unexecuted instantiation: void clang::ASTVector<clang::Stmt*>::uninitialized_copy<clang::Expr* const*, clang::Stmt**>(clang::Expr* const*, clang::Expr* const*, clang::Stmt**)
218
219
  iterator insert(const ASTContext &C, iterator I, const T &Elt) {
220
    if (I == this->end()) {  // Important special case for empty vector.
221
      push_back(Elt, C);
222
      return this->end()-1;
223
    }
224
225
    if (this->End < this->capacity_ptr()) {
226
    Retry:
227
      new (this->end()) T(this->back());
228
      this->setEnd(this->end()+1);
229
      // Push everything else over.
230
      std::copy_backward(I, this->end()-1, this->end());
231
      *I = Elt;
232
      return I;
233
    }
234
    size_t EltNo = I-this->begin();
235
    this->grow(C);
236
    I = this->begin()+EltNo;
237
    goto Retry;
238
  }
239
240
  iterator insert(const ASTContext &C, iterator I, size_type NumToInsert,
241
504k
                  const T &Elt) {
242
    // Convert iterator to elt# to avoid invalidating iterator when we reserve()
243
504k
    size_t InsertElt = I - this->begin();
244
504k
245
504k
    if (I == this->end()) { // Important special case for empty vector.
246
504k
      append(C, NumToInsert, Elt);
247
504k
      return this->begin() + InsertElt;
248
504k
    }
249
0
250
    // Ensure there is enough space.
251
0
    reserve(C, static_cast<unsigned>(this->size() + NumToInsert));
252
0
253
    // Uninvalidate the iterator.
254
0
    I = this->begin()+InsertElt;
255
0
256
    // If there are more elements between the insertion point and the end of the
257
    // range than there are being inserted, we can use a simple approach to
258
    // insertion.  Since we already reserved space, we know that this won't
259
    // reallocate the vector.
260
0
    if (size_t(this->end()-I) >= NumToInsert) {
261
0
      T *OldEnd = this->end();
262
0
      append(C, this->end()-NumToInsert, this->end());
263
0
264
      // Copy the existing elements that get replaced.
265
0
      std::copy_backward(I, OldEnd-NumToInsert, OldEnd);
266
0
267
0
      std::fill_n(I, NumToInsert, Elt);
268
0
      return I;
269
0
    }
270
0
271
    // Otherwise, we're inserting more elements than exist already, and we're
272
    // not inserting at the end.
273
0
274
    // Copy over the elements that we're about to overwrite.
275
0
    T *OldEnd = this->end();
276
0
    this->setEnd(this->end() + NumToInsert);
277
0
    size_t NumOverwritten = OldEnd-I;
278
0
    this->uninitialized_copy(I, OldEnd, this->end()-NumOverwritten);
279
0
280
    // Replace the overwritten part.
281
0
    std::fill_n(I, NumOverwritten, Elt);
282
0
283
    // Insert the non-overwritten middle part.
284
0
    std::uninitialized_fill_n(OldEnd, NumToInsert-NumOverwritten, Elt);
285
0
    return I;
286
0
  }
287
288
  template<typename ItTy>
289
259k
  iterator insert(const ASTContext &C, iterator I, ItTy From, ItTy To) {
290
    // Convert iterator to elt# to avoid invalidating iterator when we reserve()
291
259k
    size_t InsertElt = I - this->begin();
292
259k
293
259k
    if (I == this->end()) { // Important special case for empty vector.
294
259k
      append(C, From, To);
295
259k
      return this->begin() + InsertElt;
296
259k
    }
297
0
298
0
    size_t NumToInsert = std::distance(From, To);
299
0
300
    // Ensure there is enough space.
301
0
    reserve(C, static_cast<unsigned>(this->size() + NumToInsert));
302
0
303
    // Uninvalidate the iterator.
304
0
    I = this->begin()+InsertElt;
305
0
306
    // If there are more elements between the insertion point and the end of the
307
    // range than there are being inserted, we can use a simple approach to
308
    // insertion.  Since we already reserved space, we know that this won't
309
    // reallocate the vector.
310
0
    if (size_t(this->end()-I) >= NumToInsert) {
311
0
      T *OldEnd = this->end();
312
0
      append(C, this->end()-NumToInsert, this->end());
313
0
314
      // Copy the existing elements that get replaced.
315
0
      std::copy_backward(I, OldEnd-NumToInsert, OldEnd);
316
0
317
0
      std::copy(From, To, I);
318
0
      return I;
319
0
    }
320
0
321
    // Otherwise, we're inserting more elements than exist already, and we're
322
    // not inserting at the end.
323
0
324
    // Copy over the elements that we're about to overwrite.
325
0
    T *OldEnd = this->end();
326
0
    this->setEnd(this->end() + NumToInsert);
327
0
    size_t NumOverwritten = OldEnd-I;
328
0
    this->uninitialized_copy(I, OldEnd, this->end()-NumOverwritten);
329
0
330
    // Replace the overwritten part.
331
0
    for (; NumOverwritten > 0; --NumOverwritten) {
332
0
      *I = *From;
333
0
      ++I; ++From;
334
0
    }
335
0
336
    // Insert the non-overwritten middle part.
337
0
    this->uninitialized_copy(From, To, OldEnd);
338
0
    return I;
339
0
  }
340
341
5.60k
  void resize(const ASTContext &C, unsigned N, const T &NV) {
342
5.60k
    if (N < this->size()) {
343
81
      this->destroy_range(this->begin()+N, this->end());
344
81
      this->setEnd(this->begin()+N);
345
5.52k
    } else if (N > this->size()) {
346
5.49k
      if (this->capacity() < N)
347
536
        this->grow(C, N);
348
5.49k
      construct_range(this->end(), this->begin()+N, NV);
349
5.49k
      this->setEnd(this->begin()+N);
350
5.49k
    }
351
5.60k
  }
352
353
private:
354
  /// grow - double the size of the allocated memory, guaranteeing space for at
355
  /// least one more element or MinSize if specified.
356
  void grow(const ASTContext &C, size_type MinSize = 1);
357
358
5.49k
  void construct_range(T *S, T *E, const T &Elt) {
359
24.5k
    for (; S != E; 
++S19.0k
)
360
19.0k
      new (S) T(Elt);
361
5.49k
  }
362
363
1.96k
  void destroy_range(T *S, T *E) {
364
4.05k
    while (S != E) {
365
2.08k
      --E;
366
2.08k
      E->~T();
367
2.08k
    }
368
1.96k
  }
clang::ASTVector<clang::DeclAccessPair>::destroy_range(clang::DeclAccessPair*, clang::DeclAccessPair*)
Line
Count
Source
363
1.88k
  void destroy_range(T *S, T *E) {
364
3.89k
    while (S != E) {
365
2.00k
      --E;
366
2.00k
      E->~T();
367
2.00k
    }
368
1.88k
  }
clang::ASTVector<clang::Stmt*>::destroy_range(clang::Stmt**, clang::Stmt**)
Line
Count
Source
363
81
  void destroy_range(T *S, T *E) {
364
162
    while (S != E) {
365
81
      --E;
366
81
      E->~T();
367
81
    }
368
81
  }
Unexecuted instantiation: clang::ASTVector<unsigned long long>::destroy_range(unsigned long long*, unsigned long long*)
369
370
protected:
371
491k
  const_iterator capacity_ptr() const {
372
491k
    return (iterator) Capacity.getPointer();
373
491k
  }
clang::ASTVector<clang::DeclAccessPair>::capacity_ptr() const
Line
Count
Source
371
56.8k
  const_iterator capacity_ptr() const {
372
56.8k
    return (iterator) Capacity.getPointer();
373
56.8k
  }
clang::ASTVector<clang::Stmt*>::capacity_ptr() const
Line
Count
Source
371
210k
  const_iterator capacity_ptr() const {
372
210k
    return (iterator) Capacity.getPointer();
373
210k
  }
clang::ASTVector<unsigned long long>::capacity_ptr() const
Line
Count
Source
371
224k
  const_iterator capacity_ptr() const {
372
224k
    return (iterator) Capacity.getPointer();
373
224k
  }
374
375
2.08M
  iterator capacity_ptr() { return (iterator)Capacity.getPointer(); }
clang::ASTVector<clang::DeclAccessPair>::capacity_ptr()
Line
Count
Source
375
909k
  iterator capacity_ptr() { return (iterator)Capacity.getPointer(); }
clang::ASTVector<clang::Stmt*>::capacity_ptr()
Line
Count
Source
375
949k
  iterator capacity_ptr() { return (iterator)Capacity.getPointer(); }
clang::ASTVector<unsigned long long>::capacity_ptr()
Line
Count
Source
375
224k
  iterator capacity_ptr() { return (iterator)Capacity.getPointer(); }
376
};
377
378
// Define this out-of-line to dissuade the C++ compiler from inlining it.
379
template <typename T>
380
486k
void ASTVector<T>::grow(const ASTContext &C, size_t MinSize) {
381
486k
  size_t CurCapacity = this->capacity();
382
486k
  size_t CurSize = size();
383
486k
  size_t NewCapacity = 2*CurCapacity;
384
486k
  if (NewCapacity < MinSize)
385
477k
    NewCapacity = MinSize;
386
486k
387
  // Allocate the memory from the ASTContext.
388
486k
  T *NewElts = new (C, alignof(T)) T[NewCapacity];
389
486k
390
  // Copy the elements over.
391
486k
  if (Begin != End) {
392
8.20k
    if (std::is_class<T>::value) {
393
1.87k
      std::uninitialized_copy(Begin, End, NewElts);
394
      // Destroy the original elements.
395
1.87k
      destroy_range(Begin, End);
396
6.33k
    } else {
397
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
398
6.33k
      memcpy(NewElts, Begin, CurSize * sizeof(T));
399
6.33k
    }
400
8.20k
  }
401
486k
402
  // ASTContext never frees any memory.
403
486k
  Begin = NewElts;
404
486k
  End = NewElts+CurSize;
405
486k
  Capacity.setPointer(Begin+NewCapacity);
406
486k
}
clang::ASTVector<clang::DeclAccessPair>::grow(clang::ASTContext const&, unsigned long)
Line
Count
Source
380
56.8k
void ASTVector<T>::grow(const ASTContext &C, size_t MinSize) {
381
56.8k
  size_t CurCapacity = this->capacity();
382
56.8k
  size_t CurSize = size();
383
56.8k
  size_t NewCapacity = 2*CurCapacity;
384
56.8k
  if (NewCapacity < MinSize)
385
55.0k
    NewCapacity = MinSize;
386
56.8k
387
  // Allocate the memory from the ASTContext.
388
56.8k
  T *NewElts = new (C, alignof(T)) T[NewCapacity];
389
56.8k
390
  // Copy the elements over.
391
56.8k
  if (Begin != End) {
392
1.87k
    if (std::is_class<T>::value) {
393
1.87k
      std::uninitialized_copy(Begin, End, NewElts);
394
      // Destroy the original elements.
395
1.87k
      destroy_range(Begin, End);
396
0
    } else {
397
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
398
0
      memcpy(NewElts, Begin, CurSize * sizeof(T));
399
0
    }
400
1.87k
  }
401
56.8k
402
  // ASTContext never frees any memory.
403
56.8k
  Begin = NewElts;
404
56.8k
  End = NewElts+CurSize;
405
56.8k
  Capacity.setPointer(Begin+NewCapacity);
406
56.8k
}
clang::ASTVector<clang::Stmt*>::grow(clang::ASTContext const&, unsigned long)
Line
Count
Source
380
205k
void ASTVector<T>::grow(const ASTContext &C, size_t MinSize) {
381
205k
  size_t CurCapacity = this->capacity();
382
205k
  size_t CurSize = size();
383
205k
  size_t NewCapacity = 2*CurCapacity;
384
205k
  if (NewCapacity < MinSize)
385
198k
    NewCapacity = MinSize;
386
205k
387
  // Allocate the memory from the ASTContext.
388
205k
  T *NewElts = new (C, alignof(T)) T[NewCapacity];
389
205k
390
  // Copy the elements over.
391
205k
  if (Begin != End) {
392
6.33k
    if (std::is_class<T>::value) {
393
0
      std::uninitialized_copy(Begin, End, NewElts);
394
      // Destroy the original elements.
395
0
      destroy_range(Begin, End);
396
6.33k
    } else {
397
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
398
6.33k
      memcpy(NewElts, Begin, CurSize * sizeof(T));
399
6.33k
    }
400
6.33k
  }
401
205k
402
  // ASTContext never frees any memory.
403
205k
  Begin = NewElts;
404
205k
  End = NewElts+CurSize;
405
205k
  Capacity.setPointer(Begin+NewCapacity);
406
205k
}
clang::ASTVector<unsigned long long>::grow(clang::ASTContext const&, unsigned long)
Line
Count
Source
380
224k
void ASTVector<T>::grow(const ASTContext &C, size_t MinSize) {
381
224k
  size_t CurCapacity = this->capacity();
382
224k
  size_t CurSize = size();
383
224k
  size_t NewCapacity = 2*CurCapacity;
384
224k
  if (NewCapacity < MinSize)
385
224k
    NewCapacity = MinSize;
386
224k
387
  // Allocate the memory from the ASTContext.
388
224k
  T *NewElts = new (C, alignof(T)) T[NewCapacity];
389
224k
390
  // Copy the elements over.
391
224k
  if (Begin != End) {
392
0
    if (std::is_class<T>::value) {
393
0
      std::uninitialized_copy(Begin, End, NewElts);
394
      // Destroy the original elements.
395
0
      destroy_range(Begin, End);
396
0
    } else {
397
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
398
0
      memcpy(NewElts, Begin, CurSize * sizeof(T));
399
0
    }
400
0
  }
401
224k
402
  // ASTContext never frees any memory.
403
224k
  Begin = NewElts;
404
224k
  End = NewElts+CurSize;
405
224k
  Capacity.setPointer(Begin+NewCapacity);
406
224k
}
407
408
} // namespace clang
409
410
#endif // LLVM_CLANG_AST_ASTVECTOR_H