18 #ifndef LLVM_CLANG_AST_ASTVECTOR_H 19 #define LLVM_CLANG_AST_ASTVECTOR_H 22 #include "llvm/ADT/PointerIntPair.h" 29 #include <type_traits> 41 llvm::PointerIntPair<T *, 1, bool> Capacity;
43 void setEnd(T *
P) { this->End =
P; }
48 bool getTag()
const {
return Capacity.getInt(); }
49 void setTag(
bool B) { Capacity.setInt(B); }
56 O.Begin = O.End =
nullptr;
57 O.Capacity.setPointer(
nullptr);
58 O.Capacity.setInt(
false);
72 swap(Capacity, O.Capacity);
77 if (std::is_class<T>::value) {
79 destroy_range(Begin, End);
109 bool empty()
const {
return Begin == End; }
113 assert(Begin + idx < End);
117 assert(Begin + idx < End);
147 if (std::is_class<T>::value) {
148 destroy_range(Begin, End);
184 template<
typename in_iter>
193 this->grow(C, this->
size()+NumInputs);
198 std::uninitialized_copy(in_start, in_end, this->
end());
199 this->setEnd(this->
end() + NumInputs);
206 this->grow(C, this->
size()+NumInputs);
209 std::uninitialized_fill_n(this->
end(), NumInputs, Elt);
210 this->setEnd(this->
end() + NumInputs);
215 template<
typename It1,
typename It2>
217 std::uninitialized_copy(I, E, Dest);
221 if (I == this->
end()) {
223 return this->
end()-1;
228 new (this->
end()) T(this->
back());
229 this->setEnd(this->
end()+1);
231 std::copy_backward(I, this->
end()-1, this->
end());
235 size_t EltNo = I-this->
begin();
237 I = this->
begin()+EltNo;
244 size_t InsertElt = I - this->
begin();
246 if (I == this->
end()) {
247 append(C, NumToInsert, Elt);
248 return this->
begin() + InsertElt;
252 reserve(C, static_cast<unsigned>(this->
size() + NumToInsert));
255 I = this->
begin()+InsertElt;
261 if (
size_t(this->
end()-I) >= NumToInsert) {
262 T *OldEnd = this->
end();
266 std::copy_backward(I, OldEnd-NumToInsert, OldEnd);
268 std::fill_n(I, NumToInsert, Elt);
276 T *OldEnd = this->
end();
277 this->setEnd(this->
end() + NumToInsert);
278 size_t NumOverwritten = OldEnd-I;
282 std::fill_n(I, NumOverwritten, Elt);
285 std::uninitialized_fill_n(OldEnd, NumToInsert-NumOverwritten, Elt);
289 template<
typename ItTy>
292 size_t InsertElt = I - this->
begin();
294 if (I == this->
end()) {
296 return this->
begin() + InsertElt;
302 reserve(C, static_cast<unsigned>(this->
size() + NumToInsert));
305 I = this->
begin()+InsertElt;
311 if (
size_t(this->
end()-I) >= NumToInsert) {
312 T *OldEnd = this->
end();
316 std::copy_backward(I, OldEnd-NumToInsert, OldEnd);
318 std::copy(From, To, I);
326 T *OldEnd = this->
end();
327 this->setEnd(this->
end() + NumToInsert);
328 size_t NumOverwritten = OldEnd-I;
332 for (; NumOverwritten > 0; --NumOverwritten) {
343 if (N < this->
size()) {
344 this->destroy_range(this->
begin()+N, this->
end());
345 this->setEnd(this->
begin()+N);
346 }
else if (N > this->
size()) {
349 construct_range(this->
end(), this->
begin()+N, NV);
350 this->setEnd(this->
begin()+N);
359 void construct_range(T *S, T *E,
const T &Elt) {
364 void destroy_range(T *S, T *E) {
373 return (
iterator) Capacity.getPointer();
380 template <
typename T>
382 size_t CurCapacity = this->
capacity();
383 size_t CurSize =
size();
384 size_t NewCapacity = 2*CurCapacity;
385 if (NewCapacity < MinSize)
386 NewCapacity = MinSize;
389 T *NewElts =
new (
C,
alignof(T)) T[NewCapacity];
393 if (std::is_class<T>::value) {
394 std::uninitialized_copy(Begin, End, NewElts);
396 destroy_range(Begin, End);
399 memcpy(NewElts, Begin, CurSize *
sizeof(T));
405 End = NewElts+CurSize;
406 Capacity.setPointer(Begin+NewCapacity);
411 #endif // LLVM_CLANG_AST_ASTVECTOR_H static void uninitialized_copy(It1 I, It1 E, It2 Dest)
uninitialized_copy - Copy the range [I, E) onto the uninitialized memory starting with "Dest"...
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
void append(const ASTContext &C, in_iter in_start, in_iter in_end)
append - Add the specified range to the end of the SmallVector.
reverse_iterator rbegin()
iterator insert(const ASTContext &C, iterator I, const T &Elt)
const_reverse_iterator rbegin() const
float __ovld __cnfn distance(float p0, float p1)
Returns the distance between p0 and p1.
const_iterator capacity_ptr() const
const_iterator end() const
size_t capacity() const
capacity - Return the total number of elements in the currently allocated buffer. ...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const_iterator begin() const
const uint64_t * const_pointer
reference operator[](unsigned idx)
ASTVector & operator=(ASTVector &&RHS)
const uint64_t & const_reference
The result type of a method or function.
ASTVector(const ASTContext &C, unsigned N)
pointer data()
data - Return a pointer to the vector's buffer, even if empty().
ptrdiff_t difference_type
__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.
Dataflow Directional Tag Classes.
std::reverse_iterator< iterator > reverse_iterator
const_reverse_iterator rend() const
void resize(const ASTContext &C, unsigned N, const T &NV)
const uint64_t * const_iterator
const_reference front() const
const_reference back() const
void append(const ASTContext &C, size_type NumInputs, const T &Elt)
append - Add the specified range to the end of the SmallVector.
void reserve(const ASTContext &C, unsigned N)
const_pointer data() const
data - Return a pointer to the vector's buffer, even if empty().
void push_back(const_reference Elt, const ASTContext &C)
iterator insert(const ASTContext &C, iterator I, ItTy From, ItTy To)
std::reverse_iterator< const_iterator > const_reverse_iterator
const_reference operator[](unsigned idx) const
iterator insert(const ASTContext &C, iterator I, size_type NumToInsert, const T &Elt)