Coverage Report

Created: 2019-02-23 12:57

/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
// 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
1.30M
  void setEnd(T *P) { this->End = P; }
clang::ASTVector<clang::DeclAccessPair>::setEnd(clang::DeclAccessPair*)
Line
Count
Source
42
857
  void setEnd(T *P) { this->End = P; }
clang::ASTVector<clang::Stmt*>::setEnd(clang::Stmt**)
Line
Count
Source
42
1.16M
  void setEnd(T *P) { this->End = P; }
clang::ASTVector<unsigned long long>::setEnd(unsigned long long*)
Line
Count
Source
42
145k
  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.3M
  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.55M
  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.36M
  ASTVector() : Capacity(nullptr, false) {}
clang::ASTVector<unsigned long long>::ASTVector()
Line
Count
Source
52
182k
  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
266k
  ASTVector(const ASTContext &C, unsigned N) : Capacity(nullptr, false) {
61
266k
    reserve(C, N);
62
266k
  }
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
67.2k
  ~ASTVector() {
76
67.2k
    if (std::is_class<T>::value) {
77
12
      // Destroy the constructed elements in the vector.
78
12
      destroy_range(Begin, End);
79
12
    }
80
67.2k
  }
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.3k
  ~ASTVector() {
76
26.3k
    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.3k
  }
clang::ASTVector<unsigned long long>::~ASTVector()
Line
Count
Source
75
40.8k
  ~ASTVector() {
76
40.8k
    if (std::is_class<T>::value) {
77
0
      // Destroy the constructed elements in the vector.
78
0
      destroy_range(Begin, End);
79
0
    }
80
40.8k
  }
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.89M
  iterator begin() { return Begin; }
clang::ASTVector<clang::DeclAccessPair>::begin()
Line
Count
Source
97
7.26M
  iterator begin() { return Begin; }
clang::ASTVector<clang::Stmt*>::begin()
Line
Count
Source
97
2.63M
  iterator begin() { return Begin; }
98
52.3k
  const_iterator begin() const { return Begin; }
clang::ASTVector<clang::DeclAccessPair>::begin() const
Line
Count
Source
98
51.2k
  const_iterator begin() const { return Begin; }
clang::ASTVector<clang::Stmt*>::begin() const
Line
Count
Source
98
1.07k
  const_iterator begin() const { return Begin; }
99
13.8M
  iterator end() { return End; }
clang::ASTVector<clang::DeclAccessPair>::end()
Line
Count
Source
99
7.26M
  iterator end() { return End; }
clang::ASTVector<clang::Stmt*>::end()
Line
Count
Source
99
6.11M
  iterator end() { return End; }
clang::ASTVector<unsigned long long>::end()
Line
Count
Source
99
435k
  iterator end() { return End; }
100
52.2k
  const_iterator end() const { return End; }
clang::ASTVector<clang::DeclAccessPair>::end() const
Line
Count
Source
100
51.2k
  const_iterator end() const { return End; }
clang::ASTVector<clang::Stmt*>::end() const
Line
Count
Source
100
1.07k
  const_iterator end() const { return End; }
101
102
  // reverse iterator creation methods.
103
0
  reverse_iterator rbegin()            { return reverse_iterator(end()); }
104
895
  const_reverse_iterator rbegin() const{ return const_reverse_iterator(end()); }
105
0
  reverse_iterator rend()              { return reverse_iterator(begin()); }
106
895
  const_reverse_iterator rend() const { return const_reverse_iterator(begin());}
107
108
379k
  bool empty() const { return Begin == End; }
clang::ASTVector<clang::Stmt*>::empty() const
Line
Count
Source
108
379k
  bool empty() const { return Begin == End; }
Unexecuted instantiation: clang::ASTVector<clang::DeclAccessPair>::empty() const
109
8.74M
  size_type size() const { return End-Begin; }
clang::ASTVector<unsigned long long>::size() const
Line
Count
Source
109
291k
  size_type size() const { return End-Begin; }
clang::ASTVector<clang::Stmt*>::size() const
Line
Count
Source
109
8.36M
  size_type size() const { return End-Begin; }
clang::ASTVector<clang::DeclAccessPair>::size() const
Line
Count
Source
109
82.3k
  size_type size() const { return End-Begin; }
110
111
9.64M
  reference operator[](unsigned idx) {
112
9.64M
    assert(Begin + idx < End);
113
9.64M
    return Begin[idx];
114
9.64M
  }
clang::ASTVector<clang::Stmt*>::operator[](unsigned int)
Line
Count
Source
111
9.64M
  reference operator[](unsigned idx) {
112
9.64M
    assert(Begin + idx < End);
113
9.64M
    return Begin[idx];
114
9.64M
  }
Unexecuted instantiation: clang::ASTVector<clang::DeclAccessPair>::operator[](unsigned int)
115
3.09M
  const_reference operator[](unsigned idx) const {
116
3.09M
    assert(Begin + idx < End);
117
3.09M
    return Begin[idx];
118
3.09M
  }
clang::ASTVector<unsigned long long>::operator[](unsigned int) const
Line
Count
Source
115
1.67M
  const_reference operator[](unsigned idx) const {
116
1.67M
    assert(Begin + idx < End);
117
1.67M
    return Begin[idx];
118
1.67M
  }
clang::ASTVector<clang::Stmt*>::operator[](unsigned int) const
Line
Count
Source
115
1.41M
  const_reference operator[](unsigned idx) const {
116
1.41M
    assert(Begin + idx < End);
117
1.41M
    return Begin[idx];
118
1.41M
  }
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
191k
  pointer data() {
154
191k
    return pointer(Begin);
155
191k
  }
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.4k
  void push_back(const_reference Elt, const ASTContext &C) {
163
29.4k
    if (End < this->capacity_ptr()) {
164
29.4k
    Retry:
165
29.4k
      new (End) T(Elt);
166
29.4k
      ++End;
167
29.4k
      return;
168
28.7k
    }
169
28.7k
    grow(C);
170
28.7k
    goto Retry;
171
28.7k
  }
172
173
402k
  void reserve(const ASTContext &C, unsigned N) {
174
402k
    if (unsigned(this->capacity_ptr()-Begin) < N)
175
197k
      grow(C, N);
176
402k
  }
clang::ASTVector<clang::DeclAccessPair>::reserve(clang::ASTContext const&, unsigned int)
Line
Count
Source
173
51.1k
  void reserve(const ASTContext &C, unsigned N) {
174
51.1k
    if (unsigned(this->capacity_ptr()-Begin) < N)
175
627
      grow(C, N);
176
51.1k
  }
clang::ASTVector<clang::Stmt*>::reserve(clang::ASTContext const&, unsigned int)
Line
Count
Source
173
351k
  void reserve(const ASTContext &C, unsigned N) {
174
351k
    if (unsigned(this->capacity_ptr()-Begin) < N)
175
196k
      grow(C, N);
176
351k
  }
177
178
  /// capacity - Return the total number of elements in the currently allocated
179
  /// buffer.
180
416k
  size_t capacity() const { return this->capacity_ptr() - Begin; }
clang::ASTVector<clang::DeclAccessPair>::capacity() const
Line
Count
Source
180
30.2k
  size_t capacity() const { return this->capacity_ptr() - Begin; }
clang::ASTVector<clang::Stmt*>::capacity() const
Line
Count
Source
180
241k
  size_t capacity() const { return this->capacity_ptr() - Begin; }
clang::ASTVector<unsigned long long>::capacity() const
Line
Count
Source
180
145k
  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
461k
  void append(const ASTContext &C, in_iter in_start, in_iter in_end) {
185
461k
    size_type NumInputs = std::distance(in_start, in_end);
186
461k
187
461k
    if (NumInputs == 0)
188
204k
      return;
189
257k
190
257k
    // Grow allocated space if needed.
191
257k
    if (NumInputs > size_type(this->capacity_ptr()-this->end()))
192
145k
      this->grow(C, this->size()+NumInputs);
193
257k
194
257k
    // Copy the new elements over.
195
257k
    // TODO: NEED To compile time dispatch on whether in_iter is a random access
196
257k
    // iterator to use the fast uninitialized_copy.
197
257k
    std::uninitialized_copy(in_start, in_end, this->end());
198
257k
    this->setEnd(this->end() + NumInputs);
199
257k
  }
void clang::ASTVector<clang::DeclAccessPair>::append<clang::DeclAccessPair*>(clang::ASTContext const&, clang::DeclAccessPair*, clang::DeclAccessPair*)
Line
Count
Source
184
12.4k
  void append(const ASTContext &C, in_iter in_start, in_iter in_end) {
185
12.4k
    size_type NumInputs = std::distance(in_start, in_end);
186
12.4k
187
12.4k
    if (NumInputs == 0)
188
11.5k
      return;
189
857
190
857
    // Grow allocated space if needed.
191
857
    if (NumInputs > size_type(this->capacity_ptr()-this->end()))
192
857
      this->grow(C, this->size()+NumInputs);
193
857
194
857
    // Copy the new elements over.
195
857
    // TODO: NEED To compile time dispatch on whether in_iter is a random access
196
857
    // iterator to use the fast uninitialized_copy.
197
857
    std::uninitialized_copy(in_start, in_end, this->end());
198
857
    this->setEnd(this->end() + NumInputs);
199
857
  }
void clang::ASTVector<clang::Stmt*>::append<clang::Expr* const*>(clang::ASTContext const&, clang::Expr* const*, clang::Expr* const*)
Line
Count
Source
184
266k
  void append(const ASTContext &C, in_iter in_start, in_iter in_end) {
185
266k
    size_type NumInputs = std::distance(in_start, in_end);
186
266k
187
266k
    if (NumInputs == 0)
188
155k
      return;
189
111k
190
111k
    // Grow allocated space if needed.
191
111k
    if (NumInputs > size_type(this->capacity_ptr()-this->end()))
192
0
      this->grow(C, this->size()+NumInputs);
193
111k
194
111k
    // Copy the new elements over.
195
111k
    // TODO: NEED To compile time dispatch on whether in_iter is a random access
196
111k
    // iterator to use the fast uninitialized_copy.
197
111k
    std::uninitialized_copy(in_start, in_end, this->end());
198
111k
    this->setEnd(this->end() + NumInputs);
199
111k
  }
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
182k
  void append(const ASTContext &C, in_iter in_start, in_iter in_end) {
185
182k
    size_type NumInputs = std::distance(in_start, in_end);
186
182k
187
182k
    if (NumInputs == 0)
188
37.5k
      return;
189
145k
190
145k
    // Grow allocated space if needed.
191
145k
    if (NumInputs > size_type(this->capacity_ptr()-this->end()))
192
145k
      this->grow(C, this->size()+NumInputs);
193
145k
194
145k
    // Copy the new elements over.
195
145k
    // TODO: NEED To compile time dispatch on whether in_iter is a random access
196
145k
    // iterator to use the fast uninitialized_copy.
197
145k
    std::uninitialized_copy(in_start, in_end, this->end());
198
145k
    this->setEnd(this->end() + NumInputs);
199
145k
  }
200
201
  /// append - Add the specified range to the end of the SmallVector.
202
1.04M
  void append(const ASTContext &C, size_type NumInputs, const T &Elt) {
203
1.04M
    // Grow allocated space if needed.
204
1.04M
    if (NumInputs > size_type(this->capacity_ptr()-this->end()))
205
40.2k
      this->grow(C, this->size()+NumInputs);
206
1.04M
207
1.04M
    // Copy the new elements over.
208
1.04M
    std::uninitialized_fill_n(this->end(), NumInputs, Elt);
209
1.04M
    this->setEnd(this->end() + NumInputs);
210
1.04M
  }
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.04M
                  const T &Elt) {
242
1.04M
    // Convert iterator to elt# to avoid invalidating iterator when we reserve()
243
1.04M
    size_t InsertElt = I - this->begin();
244
1.04M
245
1.04M
    if (I == this->end()) { // Important special case for empty vector.
246
1.04M
      append(C, NumToInsert, Elt);
247
1.04M
      return this->begin() + InsertElt;
248
1.04M
    }
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
266k
  iterator insert(const ASTContext &C, iterator I, ItTy From, ItTy To) {
290
266k
    // Convert iterator to elt# to avoid invalidating iterator when we reserve()
291
266k
    size_t InsertElt = I - this->begin();
292
266k
293
266k
    if (I == this->end()) { // Important special case for empty vector.
294
266k
      append(C, From, To);
295
266k
      return this->begin() + InsertElt;
296
266k
    }
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.26k
  void resize(const ASTContext &C, unsigned N, const T &NV) {
342
4.26k
    if (N < this->size()) {
343
19
      this->destroy_range(this->begin()+N, this->end());
344
19
      this->setEnd(this->begin()+N);
345
4.24k
    } else if (N > this->size()) {
346
4.20k
      if (this->capacity() < N)
347
233
        this->grow(C, N);
348
4.20k
      construct_range(this->end(), this->begin()+N, NV);
349
4.20k
      this->setEnd(this->begin()+N);
350
4.20k
    }
351
4.26k
  }
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.20k
  void construct_range(T *S, T *E, const T &Elt) {
359
15.6k
    for (; S != E; 
++S11.4k
)
360
11.4k
      new (S) T(Elt);
361
4.20k
  }
362
363
1.98k
  void destroy_range(T *S, T *E) {
364
4.19k
    while (S != E) {
365
2.20k
      --E;
366
2.20k
      E->~T();
367
2.20k
    }
368
1.98k
  }
clang::ASTVector<clang::DeclAccessPair>::destroy_range(clang::DeclAccessPair*, clang::DeclAccessPair*)
Line
Count
Source
363
1.96k
  void destroy_range(T *S, T *E) {
364
4.15k
    while (S != E) {
365
2.18k
      --E;
366
2.18k
      E->~T();
367
2.18k
    }
368
1.96k
  }
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
416k
  const_iterator capacity_ptr() const {
372
416k
    return (iterator) Capacity.getPointer();
373
416k
  }
clang::ASTVector<clang::DeclAccessPair>::capacity_ptr() const
Line
Count
Source
371
30.2k
  const_iterator capacity_ptr() const {
372
30.2k
    return (iterator) Capacity.getPointer();
373
30.2k
  }
clang::ASTVector<clang::Stmt*>::capacity_ptr() const
Line
Count
Source
371
241k
  const_iterator capacity_ptr() const {
372
241k
    return (iterator) Capacity.getPointer();
373
241k
  }
clang::ASTVector<unsigned long long>::capacity_ptr() const
Line
Count
Source
371
145k
  const_iterator capacity_ptr() const {
372
145k
    return (iterator) Capacity.getPointer();
373
145k
  }
374
375
1.73M
  iterator capacity_ptr() { return (iterator)Capacity.getPointer(); }
clang::ASTVector<clang::DeclAccessPair>::capacity_ptr()
Line
Count
Source
375
81.4k
  iterator capacity_ptr() { return (iterator)Capacity.getPointer(); }
clang::ASTVector<clang::Stmt*>::capacity_ptr()
Line
Count
Source
375
1.51M
  iterator capacity_ptr() { return (iterator)Capacity.getPointer(); }
clang::ASTVector<unsigned long long>::capacity_ptr()
Line
Count
Source
375
145k
  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
412k
void ASTVector<T>::grow(const ASTContext &C, size_t MinSize) {
381
412k
  size_t CurCapacity = this->capacity();
382
412k
  size_t CurSize = size();
383
412k
  size_t NewCapacity = 2*CurCapacity;
384
412k
  if (NewCapacity < MinSize)
385
391k
    NewCapacity = MinSize;
386
412k
387
412k
  // Allocate the memory from the ASTContext.
388
412k
  T *NewElts = new (C, alignof(T)) T[NewCapacity];
389
412k
390
412k
  // Copy the elements over.
391
412k
  if (Begin != End) {
392
21.0k
    if (std::is_class<T>::value) {
393
1.95k
      std::uninitialized_copy(Begin, End, NewElts);
394
1.95k
      // Destroy the original elements.
395
1.95k
      destroy_range(Begin, End);
396
19.0k
    } else {
397
19.0k
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
398
19.0k
      memcpy(NewElts, Begin, CurSize * sizeof(T));
399
19.0k
    }
400
21.0k
  }
401
412k
402
412k
  // ASTContext never frees any memory.
403
412k
  Begin = NewElts;
404
412k
  End = NewElts+CurSize;
405
412k
  Capacity.setPointer(Begin+NewCapacity);
406
412k
}
clang::ASTVector<clang::DeclAccessPair>::grow(clang::ASTContext const&, unsigned long)
Line
Count
Source
380
30.2k
void ASTVector<T>::grow(const ASTContext &C, size_t MinSize) {
381
30.2k
  size_t CurCapacity = this->capacity();
382
30.2k
  size_t CurSize = size();
383
30.2k
  size_t NewCapacity = 2*CurCapacity;
384
30.2k
  if (NewCapacity < MinSize)
385
28.2k
    NewCapacity = MinSize;
386
30.2k
387
30.2k
  // Allocate the memory from the ASTContext.
388
30.2k
  T *NewElts = new (C, alignof(T)) T[NewCapacity];
389
30.2k
390
30.2k
  // Copy the elements over.
391
30.2k
  if (Begin != End) {
392
1.95k
    if (std::is_class<T>::value) {
393
1.95k
      std::uninitialized_copy(Begin, End, NewElts);
394
1.95k
      // Destroy the original elements.
395
1.95k
      destroy_range(Begin, End);
396
1.95k
    } 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.95k
  }
401
30.2k
402
30.2k
  // ASTContext never frees any memory.
403
30.2k
  Begin = NewElts;
404
30.2k
  End = NewElts+CurSize;
405
30.2k
  Capacity.setPointer(Begin+NewCapacity);
406
30.2k
}
clang::ASTVector<clang::Stmt*>::grow(clang::ASTContext const&, unsigned long)
Line
Count
Source
380
237k
void ASTVector<T>::grow(const ASTContext &C, size_t MinSize) {
381
237k
  size_t CurCapacity = this->capacity();
382
237k
  size_t CurSize = size();
383
237k
  size_t NewCapacity = 2*CurCapacity;
384
237k
  if (NewCapacity < MinSize)
385
217k
    NewCapacity = MinSize;
386
237k
387
237k
  // Allocate the memory from the ASTContext.
388
237k
  T *NewElts = new (C, alignof(T)) T[NewCapacity];
389
237k
390
237k
  // Copy the elements over.
391
237k
  if (Begin != End) {
392
19.0k
    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
19.0k
    } else {
397
19.0k
      // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
398
19.0k
      memcpy(NewElts, Begin, CurSize * sizeof(T));
399
19.0k
    }
400
19.0k
  }
401
237k
402
237k
  // ASTContext never frees any memory.
403
237k
  Begin = NewElts;
404
237k
  End = NewElts+CurSize;
405
237k
  Capacity.setPointer(Begin+NewCapacity);
406
237k
}
clang::ASTVector<unsigned long long>::grow(clang::ASTContext const&, unsigned long)
Line
Count
Source
380
145k
void ASTVector<T>::grow(const ASTContext &C, size_t MinSize) {
381
145k
  size_t CurCapacity = this->capacity();
382
145k
  size_t CurSize = size();
383
145k
  size_t NewCapacity = 2*CurCapacity;
384
145k
  if (NewCapacity < MinSize)
385
145k
    NewCapacity = MinSize;
386
145k
387
145k
  // Allocate the memory from the ASTContext.
388
145k
  T *NewElts = new (C, alignof(T)) T[NewCapacity];
389
145k
390
145k
  // Copy the elements over.
391
145k
  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
145k
402
145k
  // ASTContext never frees any memory.
403
145k
  Begin = NewElts;
404
145k
  End = NewElts+CurSize;
405
145k
  Capacity.setPointer(Begin+NewCapacity);
406
145k
}
407
408
} // namespace clang
409
410
#endif // LLVM_CLANG_AST_ASTVECTOR_H