17#ifndef LLVM_CLANG_AST_ASTVECTOR_H
18#define LLVM_CLANG_AST_ASTVECTOR_H
21#include "llvm/ADT/PointerIntPair.h"
40 llvm::PointerIntPair<T *, 1, bool> Capacity;
42 void setEnd(
T *
P) { this->End =
P; }
47 bool getTag()
const {
return Capacity.getInt(); }
48 void setTag(
bool B) { Capacity.setInt(B); }
55 O.Begin = O.End =
nullptr;
56 O.Capacity.setPointer(
nullptr);
57 O.Capacity.setInt(
false);
71 swap(Capacity, O.Capacity);
76 if (std::is_class<T>::value) {
78 destroy_range(
Begin, End);
112 assert(
Begin + idx < End);
116 assert(
Begin + idx < End);
146 if (std::is_class<T>::value) {
147 destroy_range(
Begin, End);
183 template<
typename in_iter>
185 size_type NumInputs = std::distance(in_start, in_end);
192 this->grow(
C, this->
size()+NumInputs);
197 std::uninitialized_copy(in_start, in_end, this->
end());
198 this->setEnd(this->
end() + NumInputs);
205 this->grow(
C, this->
size()+NumInputs);
208 std::uninitialized_fill_n(this->
end(), NumInputs, Elt);
209 this->setEnd(this->
end() + NumInputs);
214 template<
typename It1,
typename It2>
216 std::uninitialized_copy(I,
E, Dest);
220 if (I == this->
end()) {
222 return this->
end()-1;
228 this->setEnd(this->
end()+1);
230 std::copy_backward(I, this->
end()-1, this->
end());
234 size_t EltNo = I-this->
begin();
236 I = this->
begin()+EltNo;
243 size_t InsertElt = I - this->
begin();
245 if (I == this->
end()) {
246 append(C, NumToInsert, Elt);
247 return this->
begin() + InsertElt;
251 reserve(
C,
static_cast<unsigned>(this->
size() + NumToInsert));
254 I = this->
begin()+InsertElt;
260 if (
size_t(this->
end()-I) >= NumToInsert) {
261 T *OldEnd = this->
end();
265 std::copy_backward(I, OldEnd-NumToInsert, OldEnd);
267 std::fill_n(I, NumToInsert, Elt);
275 T *OldEnd = this->
end();
276 this->setEnd(this->
end() + NumToInsert);
277 size_t NumOverwritten = OldEnd-I;
281 std::fill_n(I, NumOverwritten, Elt);
284 std::uninitialized_fill_n(OldEnd, NumToInsert-NumOverwritten, Elt);
288 template<
typename ItTy>
291 size_t InsertElt = I - this->
begin();
293 if (I == this->
end()) {
295 return this->
begin() + InsertElt;
298 size_t NumToInsert = std::distance(From, To);
301 reserve(
C,
static_cast<unsigned>(this->
size() + NumToInsert));
304 I = this->
begin()+InsertElt;
310 if (
size_t(this->
end()-I) >= NumToInsert) {
311 T *OldEnd = this->
end();
315 std::copy_backward(I, OldEnd-NumToInsert, OldEnd);
317 std::copy(From, To, I);
325 T *OldEnd = this->
end();
326 this->setEnd(this->
end() + NumToInsert);
327 size_t NumOverwritten = OldEnd-I;
331 for (; NumOverwritten > 0; --NumOverwritten) {
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()) {
348 construct_range(this->
end(), this->
begin()+N, NV);
349 this->setEnd(this->
begin()+N);
358 void construct_range(
T *S,
T *
E,
const T &Elt) {
363 void destroy_range(
T *S,
T *
E) {
372 return (
iterator) Capacity.getPointer();
380void ASTVector<T>::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;
388 T *NewElts =
new (
C,
alignof(
T))
T[NewCapacity];
392 if (std::is_class<T>::value) {
393 std::uninitialized_copy(
Begin, End, NewElts);
395 destroy_range(
Begin, End);
404 End = NewElts+CurSize;
405 Capacity.setPointer(
Begin+NewCapacity);
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
__PTRDIFF_TYPE__ ptrdiff_t
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const_reference operator[](unsigned idx) const
const_iterator begin() const
void resize(const ASTContext &C, unsigned N, const T &NV)
std::reverse_iterator< iterator > reverse_iterator
reverse_iterator rbegin()
iterator insert(const ASTContext &C, iterator I, size_type NumToInsert, const T &Elt)
iterator insert(const ASTContext &C, iterator I, const T &Elt)
const_reverse_iterator rend() const
const_iterator capacity_ptr() const
void reserve(const ASTContext &C, unsigned N)
void append(const ASTContext &C, size_type NumInputs, const T &Elt)
append - Add the specified range to the end of the SmallVector.
size_t capacity() const
capacity - Return the total number of elements in the currently allocated buffer.
static void uninitialized_copy(It1 I, It1 E, It2 Dest)
uninitialized_copy - Copy the range [I, E) onto the uninitialized memory starting with "Dest",...
const_iterator end() const
pointer data()
data - Return a pointer to the vector's buffer, even if empty().
void push_back(const_reference Elt, const ASTContext &C)
std::reverse_iterator< const_iterator > const_reverse_iterator
const_reverse_iterator rbegin() const
void append(const ASTContext &C, in_iter in_start, in_iter in_end)
append - Add the specified range to the end of the SmallVector.
const_pointer data() const
data - Return a pointer to the vector's buffer, even if empty().
const_reference back() const
const_reference front() const
const T & const_reference
ASTVector & operator=(ASTVector &&RHS)
reference operator[](unsigned idx)
ptrdiff_t difference_type
iterator insert(const ASTContext &C, iterator I, ItTy From, ItTy To)
ASTVector(const ASTContext &C, unsigned N)
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
const FunctionProtoType * T