clang: include/clang/AST/ASTVector.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#ifndef LLVM_CLANG_AST_ASTVECTOR_H
18#define LLVM_CLANG_AST_ASTVECTOR_H
19
21#include "llvm/ADT/PointerIntPair.h"
22#include
23#include
24#include
25#include
26#include
27#include
28#include <type_traits>
29#include
30
32
34
35template
37private:
38 T *Begin = nullptr;
39 T *End = nullptr;
40 llvm::PointerIntPair<T *, 1, bool> Capacity;
41
42 void setEnd(T *P) { this->End = P; }
43
44protected:
45
46
47 bool getTag() const { return Capacity.getInt(); }
48 void setTag(bool B) { Capacity.setInt(B); }
49
50public:
51
53
55 O.Begin = O.End = nullptr;
56 O.Capacity.setPointer(nullptr);
57 O.Capacity.setInt(false);
58 }
59
63
66
67 using std::swap;
68
69 swap(Begin, O.Begin);
70 swap(End, O.End);
71 swap(Capacity, O.Capacity);
72 return *this;
73 }
74
76 if (std::is_class::value) {
77
78 destroy_range(Begin, End);
79 }
80 }
81
87
90
95
96
101
102
107
108 bool empty() const { return Begin == End; }
110
112 assert(Begin + idx < End);
113 return Begin[idx];
114 }
116 assert(Begin + idx < End);
117 return Begin[idx];
118 }
119
121 return begin()[0];
122 }
124 return begin()[0];
125 }
126
128 return end()[-1];
129 }
131 return end()[-1];
132 }
133
135 --End;
136 End->~T();
137 }
138
144
146 if (std::is_class::value) {
147 destroy_range(Begin, End);
148 }
149 End = Begin;
150 }
151
152
156
157
161
164 Retry:
165 new (End) T(Elt);
166 ++End;
167 return;
168 }
169 grow(C);
170 goto Retry;
171 }
172
174 if (unsigned(this->capacity_ptr()-Begin) < N)
175 grow(C, N);
176 }
177
178
179
181
182
183 template<typename in_iter>
185 size_type NumInputs = std::distance(in_start, in_end);
186
187 if (NumInputs == 0)
188 return;
189
190
192 this->grow(C, this->size()+NumInputs);
193
194
195
196
197 std::uninitialized_copy(in_start, in_end, this->end());
198 this->setEnd(this->end() + NumInputs);
199 }
200
201
203
205 this->grow(C, this->size()+NumInputs);
206
207
208 std::uninitialized_fill_n(this->end(), NumInputs, Elt);
209 this->setEnd(this->end() + NumInputs);
210 }
211
212
213
214 template<typename It1, typename It2>
216 std::uninitialized_copy(I, E, Dest);
217 }
218
220 if (I == this->end()) {
222 return this->end()-1;
223 }
224
226 Retry:
227 new (this->end()) T(this->back());
228 this->setEnd(this->end()+1);
229
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
241 const T &Elt) {
242
243 size_t InsertElt = I - this->begin();
244
245 if (I == this->end()) {
246 append(C, NumToInsert, Elt);
247 return this->begin() + InsertElt;
248 }
249
250
251 reserve(C, static_cast<unsigned>(this->size() + NumToInsert));
252
253
254 I = this->begin()+InsertElt;
255
256
257
258
259
260 if (size_t(this->end()-I) >= NumToInsert) {
262 append(C, this->end()-NumToInsert, this->end());
263
264
265 std::copy_backward(I, OldEnd-NumToInsert, OldEnd);
266
267 std::fill_n(I, NumToInsert, Elt);
268 return I;
269 }
270
271
272
273
274
276 this->setEnd(this->end() + NumToInsert);
277 size_t NumOverwritten = OldEnd-I;
279
280
281 std::fill_n(I, NumOverwritten, Elt);
282
283
284 std::uninitialized_fill_n(OldEnd, NumToInsert-NumOverwritten, Elt);
285 return I;
286 }
287
288 template
290
291 size_t InsertElt = I - this->begin();
292
293 if (I == this->end()) {
295 return this->begin() + InsertElt;
296 }
297
298 size_t NumToInsert = std::distance(From, To);
299
300
301 reserve(C, static_cast<unsigned>(this->size() + NumToInsert));
302
303
304 I = this->begin()+InsertElt;
305
306
307
308
309
310 if (size_t(this->end()-I) >= NumToInsert) {
312 append(C, this->end()-NumToInsert, this->end());
313
314
315 std::copy_backward(I, OldEnd-NumToInsert, OldEnd);
316
317 std::copy(From, To, I);
318 return I;
319 }
320
321
322
323
324
326 this->setEnd(this->end() + NumToInsert);
327 size_t NumOverwritten = OldEnd-I;
329
330
331 for (; NumOverwritten > 0; --NumOverwritten) {
332 *I = *From;
333 ++I; ++From;
334 }
335
336
338 return I;
339 }
340
342 if (N < this->size()) {
343 this->destroy_range(this->begin()+N, this->end());
344 this->setEnd(this->begin()+N);
345 } else if (N > this->size()) {
347 this->grow(C, N);
348 construct_range(this->end(), this->begin()+N, NV);
349 this->setEnd(this->begin()+N);
350 }
351 }
352
353private:
354
355
356 void grow(const ASTContext &C, size_type MinSize = 1);
357
358 void construct_range(T *S, T *E, const T &Elt) {
359 for (; S != E; ++S)
360 new (S) T(Elt);
361 }
362
363 void destroy_range(T *S, T *E) {
364 while (S != E) {
365 --E;
366 E->~T();
367 }
368 }
369
370protected:
372 return (iterator) Capacity.getPointer();
373 }
374
376};
377
378
379template
380void ASTVector::grow(const ASTContext &C, size_t MinSize) {
381 size_t CurCapacity = this->capacity();
382 size_t CurSize = size();
383 size_t NewCapacity = 2*CurCapacity;
384 if (NewCapacity < MinSize)
385 NewCapacity = MinSize;
386
387
388 T *NewElts = new (C, alignof(T)) T[NewCapacity];
389
390
391 if (Begin != End) {
392 if (std::is_class::value) {
393 std::uninitialized_copy(Begin, End, NewElts);
394
395 destroy_range(Begin, End);
396 } else {
397
398 memcpy(NewElts, Begin, CurSize * sizeof(T));
399 }
400 }
401
402
403 Begin = NewElts;
404 End = NewElts+CurSize;
405 Capacity.setPointer(Begin+NewCapacity);
406}
407
408}
409
410#endif
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
__PTRDIFF_TYPE__ ptrdiff_t
A signed integer type that is the result of subtracting two pointers.
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const_reference operator[](unsigned idx) const
Definition ASTVector.h:115
size_type size() const
Definition ASTVector.h:109
const_iterator begin() const
Definition ASTVector.h:98
T value_type
Definition ASTVector.h:84
~ASTVector()
Definition ASTVector.h:75
void resize(const ASTContext &C, unsigned N, const T &NV)
Definition ASTVector.h:341
std::reverse_iterator< iterator > reverse_iterator
Definition ASTVector.h:89
T * iterator
Definition ASTVector.h:85
void pop_back()
Definition ASTVector.h:134
iterator begin()
Definition ASTVector.h:97
bool getTag() const
Definition ASTVector.h:47
reverse_iterator rbegin()
Definition ASTVector.h:103
iterator insert(const ASTContext &C, iterator I, size_type NumToInsert, const T &Elt)
Definition ASTVector.h:240
iterator insert(const ASTContext &C, iterator I, const T &Elt)
Definition ASTVector.h:219
const_reverse_iterator rend() const
Definition ASTVector.h:106
const_iterator capacity_ptr() const
Definition ASTVector.h:371
void setTag(bool B)
Definition ASTVector.h:48
void reserve(const ASTContext &C, unsigned N)
Definition ASTVector.h:173
reverse_iterator rend()
Definition ASTVector.h:105
reference front()
Definition ASTVector.h:120
void append(const ASTContext &C, size_type NumInputs, const T &Elt)
append - Add the specified range to the end of the SmallVector.
Definition ASTVector.h:202
T pop_back_val()
Definition ASTVector.h:139
void clear()
Definition ASTVector.h:145
size_t capacity() const
capacity - Return the total number of elements in the currently allocated buffer.
Definition ASTVector.h:180
static void uninitialized_copy(It1 I, It1 E, It2 Dest)
uninitialized_copy - Copy the range [I, E) onto the uninitialized memory starting with "Dest",...
Definition ASTVector.h:215
ASTVector(ASTVector &&O)
Definition ASTVector.h:54
ASTVector()
Definition ASTVector.h:52
T * pointer
Definition ASTVector.h:93
const_iterator end() const
Definition ASTVector.h:100
pointer data()
data - Return a pointer to the vector's buffer, even if empty().
Definition ASTVector.h:153
T & reference
Definition ASTVector.h:91
void push_back(const_reference Elt, const ASTContext &C)
Definition ASTVector.h:162
bool empty() const
Definition ASTVector.h:108
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition ASTVector.h:88
iterator end()
Definition ASTVector.h:99
const T * const_pointer
Definition ASTVector.h:94
const_reverse_iterator rbegin() const
Definition ASTVector.h:104
void append(const ASTContext &C, in_iter in_start, in_iter in_end)
append - Add the specified range to the end of the SmallVector.
Definition ASTVector.h:184
const T * const_iterator
Definition ASTVector.h:86
const_pointer data() const
data - Return a pointer to the vector's buffer, even if empty().
Definition ASTVector.h:158
const_reference back() const
Definition ASTVector.h:130
reference back()
Definition ASTVector.h:127
const_reference front() const
Definition ASTVector.h:123
const T & const_reference
Definition ASTVector.h:92
ASTVector & operator=(ASTVector &&RHS)
Definition ASTVector.h:64
reference operator[](unsigned idx)
Definition ASTVector.h:111
ptrdiff_t difference_type
Definition ASTVector.h:83
size_t size_type
Definition ASTVector.h:82
iterator insert(const ASTContext &C, iterator I, ItTy From, ItTy To)
Definition ASTVector.h:289
iterator capacity_ptr()
Definition ASTVector.h:375
ASTVector(const ASTContext &C, unsigned N)
Definition ASTVector.h:60
The JSON file list parser is used to communicate input to InstallAPI.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
@ Result
The result type of a method or function.
const FunctionProtoType * T