Coverage Report

Created: 2018-11-16 02:38

/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.28M
  void setEnd(T *P) { this->End = P; }
clang::ASTVector<clang::DeclAccessPair>::setEnd(clang::DeclAccessPair*)
Line
Count
Source
42
833
  void setEnd(T *P) { this->End = P; }
clang::ASTVector<clang::Stmt*>::setEnd(clang::Stmt**)
Line
Count
Source
42
1.13M
  void setEnd(T *P) { this->End = P; }
clang::ASTVector<unsigned long long>::setEnd(unsigned long long*)
Line
Count
Source
42
147k
  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
11.1M
  bool getTag() const { return Capacity.getInt(); }
48
709
  void setTag(bool B) { Capacity.setInt(B); }
49
50
public:
51
  // Default ctor - Initialize to empty.
52
4.49M
  ASTVector() : Capacity(nullptr, false) {}
clang::ASTVector<clang::Stmt*>::ASTVector()
Line
Count
Source
52
1.73k
  ASTVector() : Capacity(nullptr, false) {}
clang::ASTVector<clang::DeclAccessPair>::ASTVector()
Line
Count
Source
52
4.30M
  ASTVector() : Capacity(nullptr, false) {}
clang::ASTVector<unsigned long long>::ASTVector()
Line
Count
Source
52
183k
  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
66.3k
  ~ASTVector() {
76
66.3k
    if (std::is_class<T>::value) {
77
12
      // Destroy the constructed elements in the vector.
78
12
      destroy_range(Begin, End);
79
12
    }
80
66.3k
  }
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
26.4k
  ~ASTVector() {
76
26.4k
    if (std::is_class<T>::value) {
77
0
      // Destroy the constructed elements in the vector.
78
0
      destroy_range(Begin, End);
79
0
    }
80
26.4k
  }
clang::ASTVector<unsigned long long>::~ASTVector()
Line
Count
Source
75
39.9k
  ~ASTVector() {
76
39.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
39.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
9.73M
  iterator begin() { return Begin; }
clang::ASTVector<clang::Stmt*>::begin()
Line
Count
Source
97
2.58M
  iterator begin() { return Begin; }
clang::ASTVector<clang::DeclAccessPair>::begin()
Line
Count
Source
97
7.15M
  iterator begin() { return Begin; }
98
51.7k
  const_iterator begin() const { return Begin; }
clang::ASTVector<clang::Stmt*>::begin() const
Line
Count
Source
98
1.06k
  const_iterator begin() const { return Begin; }
clang::ASTVector<clang::DeclAccessPair>::begin() const
Line
Count
Source
98
50.7k
  const_iterator begin() const { return Begin; }
99
13.5M
  iterator end() { return End; }
clang::ASTVector<clang::Stmt*>::end()
Line
Count
Source
99
5.98M
  iterator end() { return End; }
clang::ASTVector<clang::DeclAccessPair>::end()
Line
Count
Source
99
7.16M
  iterator end() { return End; }
clang::ASTVector<unsigned long long>::end()
Line
Count
Source
99
441k
  iterator end() { return End; }
100
51.7k
  const_iterator end() const { return End; }
clang::ASTVector<clang::Stmt*>::end() const
Line
Count
Source
100
1.05k
  const_iterator end() const { return End; }
clang::ASTVector<clang::DeclAccessPair>::end() const
Line
Count
Source
100
50.7k
  const_iterator end() const { return End; }
101
102
  // reverse iterator creation methods.
103
0
  reverse_iterator rbegin()            { return reverse_iterator(end()); }
104
879
  const_reverse_iterator rbegin() const{ return const_reverse_iterator(end()); }
105
0
  reverse_iterator rend()              { return reverse_iterator(begin()); }
106
879
  const_reverse_iterator rend() const { return const_reverse_iterator(begin());}
107
108
371k
  bool empty() const { return Begin == End; }
clang::ASTVector<clang::Stmt*>::empty() const
Line
Count
Source
108
371k
  bool empty() const { return Begin == End; }
Unexecuted instantiation: clang::ASTVector<clang::DeclAccessPair>::empty() const
109
8.56M
  size_type size() const { return End-Begin; }
clang::ASTVector<unsigned long long>::size() const
Line
Count
Source
109
295k
  size_type size() const { return End-Begin; }
clang::ASTVector<clang::Stmt*>::size() const
Line
Count
Source
109
8.18M
  size_type size() const { return End-Begin; }
clang::ASTVector<clang::DeclAccessPair>::size() const
Line
Count
Source
109
81.3k
  size_type size() const { return End-Begin; }
110
111
9.46M
  reference operator[](unsigned idx) {
112
9.46M
    assert(Begin + idx < End);
113
9.46M
    return Begin[idx];
114
9.46M
  }
clang::ASTVector<clang::Stmt*>::operator[](unsigned int)
Line
Count
Source
111
9.46M
  reference operator[](unsigned idx) {
112
9.46M
    assert(Begin + idx < End);
113
9.46M
    return Begin[idx];
114
9.46M
  }
Unexecuted instantiation: clang::ASTVector<clang::DeclAccessPair>::operator[](unsigned int)
115
3.47M
  const_reference operator[](unsigned idx) const {
116
3.47M
    assert(Begin + idx < End);
117
3.47M
    return Begin[idx];
118
3.47M
  }
clang::ASTVector<unsigned long long>::operator[](unsigned int) const
Line
Count
Source
115
2.07M
  const_reference operator[](unsigned idx) const {
116
2.07M
    assert(Begin + idx < End);
117
2.07M
    return Begin[idx];
118
2.07M
  }
clang::ASTVector<clang::Stmt*>::operator[](unsigned int) const
Line
Count
Source
115
1.39M
  const_reference operator[](unsigned idx) const {
116
1.39M
    assert(Begin + idx < End);
117
1.39M
    return Begin[idx];
118
1.39M
  }
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
190k
  pointer data() {
154
190k
    return pointer(Begin);
155
190k
  }
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
29.0k
  void push_back(const_reference Elt, const ASTContext &C) {
163
29.0k
    if (End < this->capacity_ptr()) {
164
29.0k
    Retry:
165
29.0k
      new (End) T(Elt);
166
29.0k
      ++End;
167
29.0k
      return;
168
28.3k
    }
169
28.3k
    grow(C);
170
28.3k
    goto Retry;
171
28.3k
  }
172
173
392k
  void reserve(const ASTContext &C, unsigned N) {
174
392k
    if (unsigned(this->capacity_ptr()-Begin) < N)
175
190k
      grow(C, N);
176
392k
  }
clang::ASTVector<clang::DeclAccessPair>::reserve(clang::ASTContext const&, unsigned int)
Line
Count
Source
173
50.5k
  void reserve(const ASTContext &C, unsigned N) {
174
50.5k
    if (unsigned(this->capacity_ptr()-Begin) < N)
175
627
      grow(C, N);
176
50.5k
  }
clang::ASTVector<clang::Stmt*>::reserve(clang::ASTContext const&, unsigned int)
Line
Count
Source
173
341k
  void reserve(const ASTContext &C, unsigned N) {
174
341k
    if (unsigned(this->capacity_ptr()-Begin) < N)
175
190k
      grow(C, N);
176
341k
  }
177
178
  /// capacity - Return the total number of elements in the currently allocated
179
  /// buffer.
180
411k
  size_t capacity() const { return this->capacity_ptr() - Begin; }
clang::ASTVector<clang::DeclAccessPair>::capacity() const
Line
Count
Source
180
29.7k
  size_t capacity() const { return this->capacity_ptr() - Begin; }
clang::ASTVector<clang::Stmt*>::capacity() const
Line
Count
Source
180
234k
  size_t capacity() const { return this->capacity_ptr() - Begin; }
clang::ASTVector<unsigned long long>::capacity() const
Line
Count
Source
180
147k
  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
455k
  void append(const ASTContext &C, in_iter in_start, in_iter in_end) {
185
455k
    size_type NumInputs = std::distance(in_start, in_end);
186
455k
187
455k
    if (NumInputs == 0)
188
199k
      return;
189
255k
190
255k
    // Grow allocated space if needed.
191
255k
    if (NumInputs > size_type(this->capacity_ptr()-this->end()))
192
147k
      this->grow(C, this->size()+NumInputs);
193
255k
194
255k
    // Copy the new elements over.
195
255k
    // TODO: NEED To compile time dispatch on whether in_iter is a random access
196
255k
    // iterator to use the fast uninitialized_copy.
197
255k
    std::uninitialized_copy(in_start, in_end, this->end());
198
255k
    this->setEnd(this->end() + NumInputs);
199
255k
  }
void clang::ASTVector<clang::DeclAccessPair>::append<clang::DeclAccessPair*>(clang::ASTContext const&, clang::DeclAccessPair*, clang::DeclAccessPair*)
Line
Count
Source
184
12.1k
  void append(const ASTContext &C, in_iter in_start, in_iter in_end) {
185
12.1k
    size_type NumInputs = std::distance(in_start, in_end);
186
12.1k
187
12.1k
    if (NumInputs == 0)
188
11.3k
      return;
189
833
190
833
    // Grow allocated space if needed.
191
833
    if (NumInputs > size_type(this->capacity_ptr()-this->end()))
192
833
      this->grow(C, this->size()+NumInputs);
193
833
194
833
    // Copy the new elements over.
195
833
    // TODO: NEED To compile time dispatch on whether in_iter is a random access
196
833
    // iterator to use the fast uninitialized_copy.
197
833
    std::uninitialized_copy(in_start, in_end, this->end());
198
833
    this->setEnd(this->end() + NumInputs);
199
833
  }
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
151k
      return;
189
107k
190
107k
    // Grow allocated space if needed.
191
107k
    if (NumInputs > size_type(this->capacity_ptr()-this->end()))
192
0
      this->grow(C, this->size()+NumInputs);
193
107k
194
107k
    // Copy the new elements over.
195
107k
    // TODO: NEED To compile time dispatch on whether in_iter is a random access
196
107k
    // iterator to use the fast uninitialized_copy.
197
107k
    std::uninitialized_copy(in_start, in_end, this->end());
198
107k
    this->setEnd(this->end() + NumInputs);
199
107k
  }
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
183k
  void append(const ASTContext &C, in_iter in_start, in_iter in_end) {
185
183k
    size_type NumInputs = std::distance(in_start, in_end);
186
183k
187
183k
    if (NumInputs == 0)
188
36.6k
      return;
189
147k
190
147k
    // Grow allocated space if needed.
191
147k
    if (NumInputs > size_type(this->capacity_ptr()-this->end()))
192
147k
      this->grow(C, this->size()+NumInputs);
193
147k
194
147k
    // Copy the new elements over.
195
147k
    // TODO: NEED To compile time dispatch on whether in_iter is a random access
196
147k
    // iterator to use the fast uninitialized_copy.
197
147k
    std::uninitialized_copy(in_start, in_end, this->end());
198
147k
    this->setEnd(this->end() + NumInputs);
199
147k
  }
200
201
  /// append - Add the specified range to the end of the SmallVector.
202
1.02M
  void append(const ASTContext &C, size_type NumInputs, const T &Elt) {
203
1.02M
    // Grow allocated space if needed.
204
1.02M
    if (NumInputs > size_type(this->capacity_ptr()-this->end()))
205
39.8k
      this->grow(C, this->size()+NumInputs);
206
1.02M
207
1.02M
    // Copy the new elements over.
208
1.02M
    std::uninitialized_fill_n(this->end(), NumInputs, Elt);
209
1.02M
    this->setEnd(this->end() + NumInputs);
210
1.02M
  }
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.02M
                  const T &Elt) {
242
1.02M
    // Convert iterator to elt# to avoid invalidating iterator when we reserve()
243
1.02M
    size_t InsertElt = I - this->begin();
244
1.02M
245
1.02M
    if (I == this->end()) { // Important special case for empty vector.
246
1.02M
      append(C, NumToInsert, Elt);
247
1.02M
      return this->begin() + InsertElt;
248
1.02M
    }
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
259k
  iterator insert(const ASTContext &C, iterator I, ItTy From, ItTy To) {
290
259k
    // 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
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.33k
  void resize(const ASTContext &C, unsigned N, const T &NV) {
342
4.33k
    if (N < this->size()) {
343
19
      this->destroy_range(this->begin()+N, this->end());
344
19
      this->setEnd(this->begin()+N);
345
4.31k
    } else if (N > this->size()) {
346
4.28k
      if (this->capacity() < N)
347
233
        this->grow(C, N);
348
4.28k
      construct_range(this->end(), this->begin()+N, NV);
349
4.28k
      this->setEnd(this->begin()+N);
350
4.28k
    }
351
4.33k
  }
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.28k
  void construct_range(T *S, T *E, const T &Elt) {
359
15.7k
    for (; S != E; 
++S11.4k
)
360
11.4k
      new (S) T(Elt);
361
4.28k
  }
362
363
1.97k
  void destroy_range(T *S, T *E) {
364
4.17k
    while (S != E) {
365
2.19k
      --E;
366
2.19k
      E->~T();
367
2.19k
    }
368
1.97k
  }
clang::ASTVector<clang::DeclAccessPair>::destroy_range(clang::DeclAccessPair*, clang::DeclAccessPair*)
Line
Count
Source
363
1.95k
  void destroy_range(T *S, T *E) {
364
4.13k
    while (S != E) {
365
2.17k
      --E;
366
2.17k
      E->~T();
367
2.17k
    }
368
1.95k
  }
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
411k
  const_iterator capacity_ptr() const {
372
411k
    return (iterator) Capacity.getPointer();
373
411k
  }
clang::ASTVector<clang::DeclAccessPair>::capacity_ptr() const
Line
Count
Source
371
29.7k
  const_iterator capacity_ptr() const {
372
29.7k
    return (iterator) Capacity.getPointer();
373
29.7k
  }
clang::ASTVector<clang::Stmt*>::capacity_ptr() const
Line
Count
Source
371
234k
  const_iterator capacity_ptr() const {
372
234k
    return (iterator) Capacity.getPointer();
373
234k
  }
clang::ASTVector<unsigned long long>::capacity_ptr() const
Line
Count
Source
371
147k
  const_iterator capacity_ptr() const {
372
147k
    return (iterator) Capacity.getPointer();
373
147k
  }
374
375
1.70M
  iterator capacity_ptr() { return (iterator)Capacity.getPointer(); }
clang::ASTVector<clang::DeclAccessPair>::capacity_ptr()
Line
Count
Source
375
80.5k
  iterator capacity_ptr() { return (iterator)Capacity.getPointer(); }
clang::ASTVector<clang::Stmt*>::capacity_ptr()
Line
Count
Source
375
1.47M
  iterator capacity_ptr() { return (iterator)Capacity.getPointer(); }
clang::ASTVector<unsigned long long>::capacity_ptr()
Line
Count
Source
375
147k
  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
407k
void ASTVector<T>::grow(const ASTContext &C, size_t MinSize) {
381
407k
  size_t CurCapacity = this->capacity();
382
407k
  size_t CurSize = size();
383
407k
  size_t NewCapacity = 2*CurCapacity;
384
407k
  if (NewCapacity < MinSize)
385
386k
    NewCapacity = MinSize;
386
407k
387
407k
  // Allocate the memory from the ASTContext.
388
407k
  T *NewElts = new (C, alignof(T)) T[NewCapacity];
389
407k
390
407k
  // Copy the elements over.
391
407k
  if (Begin != End) {
392
20.7k
    if (std::is_class<T>::value) {
393
1.94k
      std::uninitialized_copy(Begin, End, NewElts);
394
1.94k
      // Destroy the original elements.
395
1.94k
      destroy_range(Begin, End);
396
18.8k
    } else {
397
18.8k
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
398
18.8k
      memcpy(NewElts, Begin, CurSize * sizeof(T));
399
18.8k
    }
400
20.7k
  }
401
407k
402
407k
  // ASTContext never frees any memory.
403
407k
  Begin = NewElts;
404
407k
  End = NewElts+CurSize;
405
407k
  Capacity.setPointer(Begin+NewCapacity);
406
407k
}
clang::ASTVector<clang::DeclAccessPair>::grow(clang::ASTContext const&, unsigned long)
Line
Count
Source
380
29.7k
void ASTVector<T>::grow(const ASTContext &C, size_t MinSize) {
381
29.7k
  size_t CurCapacity = this->capacity();
382
29.7k
  size_t CurSize = size();
383
29.7k
  size_t NewCapacity = 2*CurCapacity;
384
29.7k
  if (NewCapacity < MinSize)
385
27.8k
    NewCapacity = MinSize;
386
29.7k
387
29.7k
  // Allocate the memory from the ASTContext.
388
29.7k
  T *NewElts = new (C, alignof(T)) T[NewCapacity];
389
29.7k
390
29.7k
  // Copy the elements over.
391
29.7k
  if (Begin != End) {
392
1.94k
    if (std::is_class<T>::value) {
393
1.94k
      std::uninitialized_copy(Begin, End, NewElts);
394
1.94k
      // Destroy the original elements.
395
1.94k
      destroy_range(Begin, End);
396
1.94k
    } 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.94k
  }
401
29.7k
402
29.7k
  // ASTContext never frees any memory.
403
29.7k
  Begin = NewElts;
404
29.7k
  End = NewElts+CurSize;
405
29.7k
  Capacity.setPointer(Begin+NewCapacity);
406
29.7k
}
clang::ASTVector<clang::Stmt*>::grow(clang::ASTContext const&, unsigned long)
Line
Count
Source
380
230k
void ASTVector<T>::grow(const ASTContext &C, size_t MinSize) {
381
230k
  size_t CurCapacity = this->capacity();
382
230k
  size_t CurSize = size();
383
230k
  size_t NewCapacity = 2*CurCapacity;
384
230k
  if (NewCapacity < MinSize)
385
211k
    NewCapacity = MinSize;
386
230k
387
230k
  // Allocate the memory from the ASTContext.
388
230k
  T *NewElts = new (C, alignof(T)) T[NewCapacity];
389
230k
390
230k
  // Copy the elements over.
391
230k
  if (Begin != End) {
392
18.8k
    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.8k
    } else {
397
18.8k
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
398
18.8k
      memcpy(NewElts, Begin, CurSize * sizeof(T));
399
18.8k
    }
400
18.8k
  }
401
230k
402
230k
  // ASTContext never frees any memory.
403
230k
  Begin = NewElts;
404
230k
  End = NewElts+CurSize;
405
230k
  Capacity.setPointer(Begin+NewCapacity);
406
230k
}
clang::ASTVector<unsigned long long>::grow(clang::ASTContext const&, unsigned long)
Line
Count
Source
380
147k
void ASTVector<T>::grow(const ASTContext &C, size_t MinSize) {
381
147k
  size_t CurCapacity = this->capacity();
382
147k
  size_t CurSize = size();
383
147k
  size_t NewCapacity = 2*CurCapacity;
384
147k
  if (NewCapacity < MinSize)
385
147k
    NewCapacity = MinSize;
386
147k
387
147k
  // Allocate the memory from the ASTContext.
388
147k
  T *NewElts = new (C, alignof(T)) T[NewCapacity];
389
147k
390
147k
  // Copy the elements over.
391
147k
  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
147k
402
147k
  // ASTContext never frees any memory.
403
147k
  Begin = NewElts;
404
147k
  End = NewElts+CurSize;
405
147k
  Capacity.setPointer(Begin+NewCapacity);
406
147k
}
407
408
} // namespace clang
409
410
#endif // LLVM_CLANG_AST_ASTVECTOR_H