Coverage Report

Created: 2018-07-22 10:17

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/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
//                     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
//  This file provides ASTVector, a vector  ADT whose contents are
11
//  allocated using the allocator associated with an ASTContext..
12
//
13
//===----------------------------------------------------------------------===//
14
15
// FIXME: Most of this is copy-and-paste from BumpVector.h and SmallVector.h.
16
// We can refactor this core logic into something common.
17
18
#ifndef LLVM_CLANG_AST_ASTVECTOR_H
19
#define LLVM_CLANG_AST_ASTVECTOR_H
20
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
1.25M
  void setEnd(T *P) { this->End = P; }
clang::ASTVector<clang::DeclAccessPair>::setEnd(clang::DeclAccessPair*)
Line
Count
Source
42
705
  void setEnd(T *P) { this->End = P; }
clang::ASTVector<clang::Stmt*>::setEnd(clang::Stmt**)
Line
Count
Source
42
1.11M
  void setEnd(T *P) { this->End = P; }
clang::ASTVector<unsigned long long>::setEnd(unsigned long long*)
Line
Count
Source
42
141k
  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.98M
  bool getTag() const { return Capacity.getInt(); }
48
707
  void setTag(bool B) { Capacity.setInt(B); }
49
50
public:
51
  // Default ctor - Initialize to empty.
52
4.05M
  ASTVector() : Capacity(nullptr, false) {}
clang::ASTVector<clang::Stmt*>::ASTVector()
Line
Count
Source
52
1.72k
  ASTVector() : Capacity(nullptr, false) {}
clang::ASTVector<clang::DeclAccessPair>::ASTVector()
Line
Count
Source
52
3.88M
  ASTVector() : Capacity(nullptr, false) {}
clang::ASTVector<unsigned long long>::ASTVector()
Line
Count
Source
52
175k
  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
240k
  ASTVector(const ASTContext &C, unsigned N) : Capacity(nullptr, false) {
61
240k
    reserve(C, N);
62
240k
  }
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
63.5k
  ~ASTVector() {
76
63.5k
    if (std::is_class<T>::value) {
77
12
      // Destroy the constructed elements in the vector.
78
12
      destroy_range(Begin, End);
79
12
    }
80
63.5k
  }
clang::ASTVector<clang::DeclAccessPair>::~ASTVector()
Line
Count
Source
75
12
  ~ASTVector() {
76
12
    if (std::is_class<T>::value) {
77
12
      // 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
25.5k
  ~ASTVector() {
76
25.5k
    if (std::is_class<T>::value) {
77
0
      // Destroy the constructed elements in the vector.
78
0
      destroy_range(Begin, End);
79
0
    }
80
25.5k
  }
clang::ASTVector<unsigned long long>::~ASTVector()
Line
Count
Source
75
37.9k
  ~ASTVector() {
76
37.9k
    if (std::is_class<T>::value) {
77
0
      // Destroy the constructed elements in the vector.
78
0
      destroy_range(Begin, End);
79
0
    }
80
37.9k
  }
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
8.89M
  iterator begin() { return Begin; }
clang::ASTVector<clang::Stmt*>::begin()
Line
Count
Source
97
2.51M
  iterator begin() { return Begin; }
clang::ASTVector<clang::DeclAccessPair>::begin()
Line
Count
Source
97
6.38M
  iterator begin() { return Begin; }
98
51.3k
  const_iterator begin() const { return Begin; }
clang::ASTVector<clang::Stmt*>::begin() const
Line
Count
Source
98
1.05k
  const_iterator begin() const { return Begin; }
clang::ASTVector<clang::DeclAccessPair>::begin() const
Line
Count
Source
98
50.3k
  const_iterator begin() const { return Begin; }
99
12.6M
  iterator end() { return End; }
clang::ASTVector<clang::Stmt*>::end()
Line
Count
Source
99
5.84M
  iterator end() { return End; }
clang::ASTVector<clang::DeclAccessPair>::end()
Line
Count
Source
99
6.38M
  iterator end() { return End; }
clang::ASTVector<unsigned long long>::end()
Line
Count
Source
99
425k
  iterator end() { return End; }
100
51.3k
  const_iterator end() const { return End; }
clang::ASTVector<clang::Stmt*>::end() const
Line
Count
Source
100
1.04k
  const_iterator end() const { return End; }
clang::ASTVector<clang::DeclAccessPair>::end() const
Line
Count
Source
100
50.3k
  const_iterator end() const { return End; }
101
102
  // reverse iterator creation methods.
103
0
  reverse_iterator rbegin()            { return reverse_iterator(end()); }
104
868
  const_reverse_iterator rbegin() const{ return const_reverse_iterator(end()); }
105
0
  reverse_iterator rend()              { return reverse_iterator(begin()); }
106
868
  const_reverse_iterator rend() const { return const_reverse_iterator(begin());}
107
108
352k
  bool empty() const { return Begin == End; }
clang::ASTVector<clang::Stmt*>::empty() const
Line
Count
Source
108
352k
  bool empty() const { return Begin == End; }
Unexecuted instantiation: clang::ASTVector<clang::DeclAccessPair>::empty() const
109
8.32M
  size_type size() const { return End-Begin; }
clang::ASTVector<unsigned long long>::size() const
Line
Count
Source
109
284k
  size_type size() const { return End-Begin; }
clang::ASTVector<clang::Stmt*>::size() const
Line
Count
Source
109
7.96M
  size_type size() const { return End-Begin; }
clang::ASTVector<clang::DeclAccessPair>::size() const
Line
Count
Source
109
78.6k
  size_type size() const { return End-Begin; }
110
111
9.35M
  reference operator[](unsigned idx) {
112
9.35M
    assert(Begin + idx < End);
113
9.35M
    return Begin[idx];
114
9.35M
  }
clang::ASTVector<clang::Stmt*>::operator[](unsigned int)
Line
Count
Source
111
9.35M
  reference operator[](unsigned idx) {
112
9.35M
    assert(Begin + idx < End);
113
9.35M
    return Begin[idx];
114
9.35M
  }
Unexecuted instantiation: clang::ASTVector<clang::DeclAccessPair>::operator[](unsigned int)
115
3.32M
  const_reference operator[](unsigned idx) const {
116
3.32M
    assert(Begin + idx < End);
117
3.32M
    return Begin[idx];
118
3.32M
  }
clang::ASTVector<unsigned long long>::operator[](unsigned int) const
Line
Count
Source
115
1.99M
  const_reference operator[](unsigned idx) const {
116
1.99M
    assert(Begin + idx < End);
117
1.99M
    return Begin[idx];
118
1.99M
  }
clang::ASTVector<clang::Stmt*>::operator[](unsigned int) const
Line
Count
Source
115
1.33M
  const_reference operator[](unsigned idx) const {
116
1.33M
    assert(Begin + idx < End);
117
1.33M
    return Begin[idx];
118
1.33M
  }
Unexecuted instantiation: clang::ASTVector<clang::DeclAccessPair>::operator[](unsigned int) const
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
178k
  pointer data() {
154
178k
    return pointer(Begin);
155
178k
  }
156
157
  /// data - Return a pointer to the vector's buffer, even if empty().
158
0
  const_pointer data() const {
159
0
    return const_pointer(Begin);
160
0
  }
161
162
27.0k
  void push_back(const_reference Elt, const ASTContext &C) {
163
27.0k
    if (End < this->capacity_ptr()) {
164
27.0k
    Retry:
165
27.0k
      new (End) T(Elt);
166
27.0k
      ++End;
167
27.0k
      return;
168
26.3k
    }
169
26.3k
    grow(C);
170
26.3k
    goto Retry;
171
26.3k
  }
172
173
370k
  void reserve(const ASTContext &C, unsigned N) {
174
370k
    if (unsigned(this->capacity_ptr()-Begin) < N)
175
180k
      grow(C, N);
176
370k
  }
clang::ASTVector<clang::DeclAccessPair>::reserve(clang::ASTContext const&, unsigned int)
Line
Count
Source
173
50.1k
  void reserve(const ASTContext &C, unsigned N) {
174
50.1k
    if (unsigned(this->capacity_ptr()-Begin) < N)
175
626
      grow(C, N);
176
50.1k
  }
clang::ASTVector<clang::Stmt*>::reserve(clang::ASTContext const&, unsigned int)
Line
Count
Source
173
319k
  void reserve(const ASTContext &C, unsigned N) {
174
319k
    if (unsigned(this->capacity_ptr()-Begin) < N)
175
179k
      grow(C, N);
176
319k
  }
177
178
  /// capacity - Return the total number of elements in the currently allocated
179
  /// buffer.
180
390k
  size_t capacity() const { return this->capacity_ptr() - Begin; }
clang::ASTVector<clang::DeclAccessPair>::capacity() const
Line
Count
Source
180
27.6k
  size_t capacity() const { return this->capacity_ptr() - Begin; }
clang::ASTVector<clang::Stmt*>::capacity() const
Line
Count
Source
180
220k
  size_t capacity() const { return this->capacity_ptr() - Begin; }
clang::ASTVector<unsigned long long>::capacity() const
Line
Count
Source
180
141k
  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
426k
  void append(const ASTContext &C, in_iter in_start, in_iter in_end) {
185
426k
    size_type NumInputs = std::distance(in_start, in_end);
186
426k
187
426k
    if (NumInputs == 0)
188
183k
      return;
189
243k
190
243k
    // Grow allocated space if needed.
191
243k
    if (NumInputs > size_type(this->capacity_ptr()-this->end()))
192
142k
      this->grow(C, this->size()+NumInputs);
193
243k
194
243k
    // Copy the new elements over.
195
243k
    // TODO: NEED To compile time dispatch on whether in_iter is a random access
196
243k
    // iterator to use the fast uninitialized_copy.
197
243k
    std::uninitialized_copy(in_start, in_end, this->end());
198
243k
    this->setEnd(this->end() + NumInputs);
199
243k
  }
void clang::ASTVector<clang::DeclAccessPair>::append<clang::DeclAccessPair*>(clang::ASTContext const&, clang::DeclAccessPair*, clang::DeclAccessPair*)
Line
Count
Source
184
10.8k
  void append(const ASTContext &C, in_iter in_start, in_iter in_end) {
185
10.8k
    size_type NumInputs = std::distance(in_start, in_end);
186
10.8k
187
10.8k
    if (NumInputs == 0)
188
10.1k
      return;
189
705
190
705
    // Grow allocated space if needed.
191
705
    if (NumInputs > size_type(this->capacity_ptr()-this->end()))
192
705
      this->grow(C, this->size()+NumInputs);
193
705
194
705
    // Copy the new elements over.
195
705
    // TODO: NEED To compile time dispatch on whether in_iter is a random access
196
705
    // iterator to use the fast uninitialized_copy.
197
705
    std::uninitialized_copy(in_start, in_end, this->end());
198
705
    this->setEnd(this->end() + NumInputs);
199
705
  }
void clang::ASTVector<clang::Stmt*>::append<clang::Expr* const*>(clang::ASTContext const&, clang::Expr* const*, clang::Expr* const*)
Line
Count
Source
184
240k
  void append(const ASTContext &C, in_iter in_start, in_iter in_end) {
185
240k
    size_type NumInputs = std::distance(in_start, in_end);
186
240k
187
240k
    if (NumInputs == 0)
188
140k
      return;
189
100k
190
100k
    // 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
100k
    // Copy the new elements over.
195
100k
    // TODO: NEED To compile time dispatch on whether in_iter is a random access
196
100k
    // 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
175k
  void append(const ASTContext &C, in_iter in_start, in_iter in_end) {
185
175k
    size_type NumInputs = std::distance(in_start, in_end);
186
175k
187
175k
    if (NumInputs == 0)
188
33.2k
      return;
189
141k
190
141k
    // Grow allocated space if needed.
191
141k
    if (NumInputs > size_type(this->capacity_ptr()-this->end()))
192
141k
      this->grow(C, this->size()+NumInputs);
193
141k
194
141k
    // Copy the new elements over.
195
141k
    // TODO: NEED To compile time dispatch on whether in_iter is a random access
196
141k
    // iterator to use the fast uninitialized_copy.
197
141k
    std::uninitialized_copy(in_start, in_end, this->end());
198
141k
    this->setEnd(this->end() + NumInputs);
199
141k
  }
200
201
  /// append - Add the specified range to the end of the SmallVector.
202
1.01M
  void append(const ASTContext &C, size_type NumInputs, const T &Elt) {
203
1.01M
    // Grow allocated space if needed.
204
1.01M
    if (NumInputs > size_type(this->capacity_ptr()-this->end()))
205
37.0k
      this->grow(C, this->size()+NumInputs);
206
1.01M
207
1.01M
    // Copy the new elements over.
208
1.01M
    std::uninitialized_fill_n(this->end(), NumInputs, Elt);
209
1.01M
    this->setEnd(this->end() + NumInputs);
210
1.01M
  }
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
1.01M
                  const T &Elt) {
242
1.01M
    // Convert iterator to elt# to avoid invalidating iterator when we reserve()
243
1.01M
    size_t InsertElt = I - this->begin();
244
1.01M
245
1.01M
    if (I == this->end()) { // Important special case for empty vector.
246
1.01M
      append(C, NumToInsert, Elt);
247
1.01M
      return this->begin() + InsertElt;
248
1.01M
    }
249
0
250
0
    // Ensure there is enough space.
251
0
    reserve(C, static_cast<unsigned>(this->size() + NumToInsert));
252
0
253
0
    // Uninvalidate the iterator.
254
0
    I = this->begin()+InsertElt;
255
0
256
0
    // If there are more elements between the insertion point and the end of the
257
0
    // range than there are being inserted, we can use a simple approach to
258
0
    // insertion.  Since we already reserved space, we know that this won't
259
0
    // 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
0
      // 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
0
    // Otherwise, we're inserting more elements than exist already, and we're
272
0
    // not inserting at the end.
273
0
274
0
    // 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
0
    // Replace the overwritten part.
281
0
    std::fill_n(I, NumOverwritten, Elt);
282
0
283
0
    // 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
240k
  iterator insert(const ASTContext &C, iterator I, ItTy From, ItTy To) {
290
240k
    // Convert iterator to elt# to avoid invalidating iterator when we reserve()
291
240k
    size_t InsertElt = I - this->begin();
292
240k
293
240k
    if (I == this->end()) { // Important special case for empty vector.
294
240k
      append(C, From, To);
295
240k
      return this->begin() + InsertElt;
296
240k
    }
297
0
298
0
    size_t NumToInsert = std::distance(From, To);
299
0
300
0
    // Ensure there is enough space.
301
0
    reserve(C, static_cast<unsigned>(this->size() + NumToInsert));
302
0
303
0
    // Uninvalidate the iterator.
304
0
    I = this->begin()+InsertElt;
305
0
306
0
    // If there are more elements between the insertion point and the end of the
307
0
    // range than there are being inserted, we can use a simple approach to
308
0
    // insertion.  Since we already reserved space, we know that this won't
309
0
    // 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
0
      // 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
0
    // Otherwise, we're inserting more elements than exist already, and we're
322
0
    // not inserting at the end.
323
0
324
0
    // 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
0
    // Replace the overwritten part.
331
0
    for (; NumOverwritten > 0; --NumOverwritten) {
332
0
      *I = *From;
333
0
      ++I; ++From;
334
0
    }
335
0
336
0
    // Insert the non-overwritten middle part.
337
0
    this->uninitialized_copy(From, To, OldEnd);
338
0
    return I;
339
0
  }
340
341
4.06k
  void resize(const ASTContext &C, unsigned N, const T &NV) {
342
4.06k
    if (N < this->size()) {
343
19
      this->destroy_range(this->begin()+N, this->end());
344
19
      this->setEnd(this->begin()+N);
345
4.04k
    } else if (N > this->size()) {
346
4.01k
      if (this->capacity() < N)
347
229
        this->grow(C, N);
348
4.01k
      construct_range(this->end(), this->begin()+N, NV);
349
4.01k
      this->setEnd(this->begin()+N);
350
4.01k
    }
351
4.06k
  }
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
4.01k
  void construct_range(T *S, T *E, const T &Elt) {
359
15.1k
    for (; S != E; 
++S11.1k
)
360
11.1k
      new (S) T(Elt);
361
4.01k
  }
362
363
1.92k
  void destroy_range(T *S, T *E) {
364
4.05k
    while (S != E) {
365
2.13k
      --E;
366
2.13k
      E->~T();
367
2.13k
    }
368
1.92k
  }
clang::ASTVector<clang::DeclAccessPair>::destroy_range(clang::DeclAccessPair*, clang::DeclAccessPair*)
Line
Count
Source
363
1.90k
  void destroy_range(T *S, T *E) {
364
4.02k
    while (S != E) {
365
2.11k
      --E;
366
2.11k
      E->~T();
367
2.11k
    }
368
1.90k
  }
clang::ASTVector<clang::Stmt*>::destroy_range(clang::Stmt**, clang::Stmt**)
Line
Count
Source
363
19
  void destroy_range(T *S, T *E) {
364
38
    while (S != E) {
365
19
      --E;
366
19
      E->~T();
367
19
    }
368
19
  }
Unexecuted instantiation: clang::ASTVector<unsigned long long>::destroy_range(unsigned long long*, unsigned long long*)
369
370
protected:
371
390k
  const_iterator capacity_ptr() const {
372
390k
    return (iterator) Capacity.getPointer();
373
390k
  }
clang::ASTVector<clang::DeclAccessPair>::capacity_ptr() const
Line
Count
Source
371
27.6k
  const_iterator capacity_ptr() const {
372
27.6k
    return (iterator) Capacity.getPointer();
373
27.6k
  }
clang::ASTVector<clang::Stmt*>::capacity_ptr() const
Line
Count
Source
371
220k
  const_iterator capacity_ptr() const {
372
220k
    return (iterator) Capacity.getPointer();
373
220k
  }
clang::ASTVector<unsigned long long>::capacity_ptr() const
Line
Count
Source
371
141k
  const_iterator capacity_ptr() const {
372
141k
    return (iterator) Capacity.getPointer();
373
141k
  }
374
375
1.65M
  iterator capacity_ptr() { return (iterator)Capacity.getPointer(); }
clang::ASTVector<clang::DeclAccessPair>::capacity_ptr()
Line
Count
Source
375
77.9k
  iterator capacity_ptr() { return (iterator)Capacity.getPointer(); }
clang::ASTVector<clang::Stmt*>::capacity_ptr()
Line
Count
Source
375
1.43M
  iterator capacity_ptr() { return (iterator)Capacity.getPointer(); }
clang::ASTVector<unsigned long long>::capacity_ptr()
Line
Count
Source
375
141k
  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
386k
void ASTVector<T>::grow(const ASTContext &C, size_t MinSize) {
381
386k
  size_t CurCapacity = this->capacity();
382
386k
  size_t CurSize = size();
383
386k
  size_t NewCapacity = 2*CurCapacity;
384
386k
  if (NewCapacity < MinSize)
385
365k
    NewCapacity = MinSize;
386
386k
387
386k
  // Allocate the memory from the ASTContext.
388
386k
  T *NewElts = new (C, alignof(T)) T[NewCapacity];
389
386k
390
386k
  // Copy the elements over.
391
386k
  if (Begin != End) {
392
20.5k
    if (std::is_class<T>::value) {
393
1.89k
      std::uninitialized_copy(Begin, End, NewElts);
394
1.89k
      // Destroy the original elements.
395
1.89k
      destroy_range(Begin, End);
396
18.6k
    } else {
397
18.6k
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
398
18.6k
      memcpy(NewElts, Begin, CurSize * sizeof(T));
399
18.6k
    }
400
20.5k
  }
401
386k
402
386k
  // ASTContext never frees any memory.
403
386k
  Begin = NewElts;
404
386k
  End = NewElts+CurSize;
405
386k
  Capacity.setPointer(Begin+NewCapacity);
406
386k
}
clang::ASTVector<clang::DeclAccessPair>::grow(clang::ASTContext const&, unsigned long)
Line
Count
Source
380
27.6k
void ASTVector<T>::grow(const ASTContext &C, size_t MinSize) {
381
27.6k
  size_t CurCapacity = this->capacity();
382
27.6k
  size_t CurSize = size();
383
27.6k
  size_t NewCapacity = 2*CurCapacity;
384
27.6k
  if (NewCapacity < MinSize)
385
25.7k
    NewCapacity = MinSize;
386
27.6k
387
27.6k
  // Allocate the memory from the ASTContext.
388
27.6k
  T *NewElts = new (C, alignof(T)) T[NewCapacity];
389
27.6k
390
27.6k
  // Copy the elements over.
391
27.6k
  if (Begin != End) {
392
1.89k
    if (std::is_class<T>::value) {
393
1.89k
      std::uninitialized_copy(Begin, End, NewElts);
394
1.89k
      // Destroy the original elements.
395
1.89k
      destroy_range(Begin, End);
396
1.89k
    } else {
397
0
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
398
0
      memcpy(NewElts, Begin, CurSize * sizeof(T));
399
0
    }
400
1.89k
  }
401
27.6k
402
27.6k
  // ASTContext never frees any memory.
403
27.6k
  Begin = NewElts;
404
27.6k
  End = NewElts+CurSize;
405
27.6k
  Capacity.setPointer(Begin+NewCapacity);
406
27.6k
}
clang::ASTVector<clang::Stmt*>::grow(clang::ASTContext const&, unsigned long)
Line
Count
Source
380
216k
void ASTVector<T>::grow(const ASTContext &C, size_t MinSize) {
381
216k
  size_t CurCapacity = this->capacity();
382
216k
  size_t CurSize = size();
383
216k
  size_t NewCapacity = 2*CurCapacity;
384
216k
  if (NewCapacity < MinSize)
385
198k
    NewCapacity = MinSize;
386
216k
387
216k
  // Allocate the memory from the ASTContext.
388
216k
  T *NewElts = new (C, alignof(T)) T[NewCapacity];
389
216k
390
216k
  // Copy the elements over.
391
216k
  if (Begin != End) {
392
18.6k
    if (std::is_class<T>::value) {
393
0
      std::uninitialized_copy(Begin, End, NewElts);
394
0
      // Destroy the original elements.
395
0
      destroy_range(Begin, End);
396
18.6k
    } else {
397
18.6k
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
398
18.6k
      memcpy(NewElts, Begin, CurSize * sizeof(T));
399
18.6k
    }
400
18.6k
  }
401
216k
402
216k
  // ASTContext never frees any memory.
403
216k
  Begin = NewElts;
404
216k
  End = NewElts+CurSize;
405
216k
  Capacity.setPointer(Begin+NewCapacity);
406
216k
}
clang::ASTVector<unsigned long long>::grow(clang::ASTContext const&, unsigned long)
Line
Count
Source
380
141k
void ASTVector<T>::grow(const ASTContext &C, size_t MinSize) {
381
141k
  size_t CurCapacity = this->capacity();
382
141k
  size_t CurSize = size();
383
141k
  size_t NewCapacity = 2*CurCapacity;
384
141k
  if (NewCapacity < MinSize)
385
141k
    NewCapacity = MinSize;
386
141k
387
141k
  // Allocate the memory from the ASTContext.
388
141k
  T *NewElts = new (C, alignof(T)) T[NewCapacity];
389
141k
390
141k
  // Copy the elements over.
391
141k
  if (Begin != End) {
392
0
    if (std::is_class<T>::value) {
393
0
      std::uninitialized_copy(Begin, End, NewElts);
394
0
      // Destroy the original elements.
395
0
      destroy_range(Begin, End);
396
0
    } else {
397
0
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
398
0
      memcpy(NewElts, Begin, CurSize * sizeof(T));
399
0
    }
400
0
  }
401
141k
402
141k
  // ASTContext never frees any memory.
403
141k
  Begin = NewElts;
404
141k
  End = NewElts+CurSize;
405
141k
  Capacity.setPointer(Begin+NewCapacity);
406
141k
}
407
408
} // namespace clang
409
410
#endif // LLVM_CLANG_AST_ASTVECTOR_H