18 #ifndef LLVM_CLANG_AST_ASTVECTOR_H
19 #define LLVM_CLANG_AST_ASTVECTOR_H
22 #include "llvm/ADT/PointerIntPair.h"
23 #include "llvm/Support/Allocator.h"
24 #include "llvm/Support/type_traits.h"
36 llvm::PointerIntPair<T*, 1, bool> Capacity;
38 void setEnd(T *
P) { this->End =
P; }
43 bool getTag()
const {
return Capacity.getInt(); }
44 void setTag(
bool B) { Capacity.setInt(B); }
51 O.Begin = O.End =
nullptr;
52 O.Capacity.setPointer(
nullptr);
53 O.Capacity.setInt(
false);
57 : Begin(nullptr), End(nullptr), Capacity(nullptr,
false) {
66 swap(Capacity, O.Capacity);
71 if (std::is_class<T>::value) {
73 destroy_range(Begin, End);
103 bool empty()
const {
return Begin == End; }
107 assert(Begin + idx < End);
111 assert(Begin + idx < End);
141 if (std::is_class<T>::value) {
142 destroy_range(Begin, End);
179 template<
typename in_iter>
188 this->grow(C, this->
size()+NumInputs);
193 std::uninitialized_copy(in_start, in_end, this->
end());
194 this->setEnd(this->
end() + NumInputs);
202 this->grow(C, this->
size()+NumInputs);
205 std::uninitialized_fill_n(this->
end(), NumInputs, Elt);
206 this->setEnd(this->
end() + NumInputs);
211 template<
typename It1,
typename It2>
213 std::uninitialized_copy(I, E, Dest);
217 if (I == this->
end()) {
219 return this->
end()-1;
224 new (this->
end()) T(this->
back());
225 this->setEnd(this->
end()+1);
227 std::copy_backward(I, this->
end()-1, this->
end());
231 size_t EltNo = I-this->
begin();
233 I = this->
begin()+EltNo;
240 size_t InsertElt = I - this->
begin();
242 if (I == this->
end()) {
243 append(C, NumToInsert, Elt);
244 return this->
begin() + InsertElt;
248 reserve(C, static_cast<unsigned>(this->
size() + NumToInsert));
251 I = this->
begin()+InsertElt;
257 if (
size_t(this->
end()-I) >= NumToInsert) {
258 T *OldEnd = this->
end();
262 std::copy_backward(I, OldEnd-NumToInsert, OldEnd);
264 std::fill_n(I, NumToInsert, Elt);
272 T *OldEnd = this->
end();
273 this->setEnd(this->
end() + NumToInsert);
274 size_t NumOverwritten = OldEnd-
I;
278 std::fill_n(I, NumOverwritten, Elt);
281 std::uninitialized_fill_n(OldEnd, NumToInsert-NumOverwritten, Elt);
285 template<
typename ItTy>
288 size_t InsertElt = I - this->
begin();
290 if (I == this->
end()) {
292 return this->
begin() + InsertElt;
298 reserve(C, static_cast<unsigned>(this->
size() + NumToInsert));
301 I = this->
begin()+InsertElt;
307 if (
size_t(this->
end()-I) >= NumToInsert) {
308 T *OldEnd = this->
end();
312 std::copy_backward(I, OldEnd-NumToInsert, OldEnd);
314 std::copy(From, To, I);
322 T *OldEnd = this->
end();
323 this->setEnd(this->
end() + NumToInsert);
324 size_t NumOverwritten = OldEnd-
I;
328 for (; NumOverwritten > 0; --NumOverwritten) {
339 if (N < this->
size()) {
340 this->destroy_range(this->
begin()+N, this->
end());
341 this->setEnd(this->
begin()+N);
342 }
else if (N > this->
size()) {
345 construct_range(this->
end(), this->
begin()+N, NV);
346 this->setEnd(this->
begin()+N);
355 void construct_range(T *
S, T *
E,
const T &Elt) {
360 void destroy_range(T *S, T *E) {
369 return (
iterator) Capacity.getPointer();
375 template <
typename T>
376 void ASTVector<T>::grow(
const ASTContext &C,
size_t MinSize) {
377 size_t CurCapacity = this->capacity();
378 size_t CurSize = size();
379 size_t NewCapacity = 2*CurCapacity;
380 if (NewCapacity < MinSize)
381 NewCapacity = MinSize;
384 T *NewElts =
new (C, llvm::alignOf<T>()) T[NewCapacity];
388 if (std::is_class<T>::value) {
389 std::uninitialized_copy(Begin,
End, NewElts);
391 destroy_range(Begin,
End);
394 memcpy(NewElts, Begin, CurSize *
sizeof(T));
400 End = NewElts+CurSize;
401 Capacity.setPointer(Begin+NewCapacity);
static void uninitialized_copy(It1 I, It1 E, It2 Dest)
uninitialized_copy - Copy the range [I, E) onto the uninitialized memory starting with "Dest"...
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)
ptrdiff_t difference_type
const_reference back() const
float __ovld __cnfn distance(float p0, float p1)
Returns the distance between p0 and p1.
const T & const_reference
const_iterator end() const
std::reverse_iterator< iterator > reverse_iterator
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const_iterator capacity_ptr() const
size_t capacity() const
capacity - Return the total number of elements in the currently allocated buffer. ...
const_pointer data() const
data - Return a pointer to the vector's buffer, even if empty().
std::reverse_iterator< const_iterator > const_reverse_iterator
detail::InMemoryDirectory::const_iterator I
reference operator[](unsigned idx)
const_reference operator[](unsigned idx) const
const_reference front() const
ASTVector & operator=(ASTVector &&RHS)
The result type of a method or function.
const_iterator begin() const
ASTVector(const ASTContext &C, unsigned N)
pointer data()
data - Return a pointer to the vector's buffer, even if empty().
__PTRDIFF_TYPE__ ptrdiff_t
A signed integer type that is the result of subtracting two pointers.
void resize(const ASTContext &C, unsigned N, const T &NV)
const_reverse_iterator rend() const
detail::InMemoryDirectory::const_iterator E
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)
void push_back(const_reference Elt, const ASTContext &C)
iterator insert(const ASTContext &C, iterator I, ItTy From, ItTy To)
const_reverse_iterator rbegin() const
iterator insert(const ASTContext &C, iterator I, size_type NumToInsert, const T &Elt)