18 #ifndef LLVM_CLANG_AST_ASTVECTOR_H 19 #define LLVM_CLANG_AST_ASTVECTOR_H 21 #include "llvm/ADT/PointerIntPair.h" 28 #include <type_traits> 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);
108 bool empty()
const {
return 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>
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;
227 new (this->
end()) T(this->
back());
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;
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();
379 template <
typename T>
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);
398 memcpy(NewElts, Begin, CurSize *
sizeof(T));
404 End = NewElts+CurSize;
405 Capacity.setPointer(Begin+NewCapacity);
410 #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)