X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FADT%2FTinyPtrVector.h;h=8f3925c9c55414b47dac1b7175d944ca949f50bb;hb=1cacae0f297b7330c4cd2b4f0a1f95ab2615bd65;hp=374357d9c6b7d2099ced4d2eca64ee0454012877;hpb=0db235a2b0ed6ae5c3c870012061906054b6dbc4;p=oota-llvm.git diff --git a/include/llvm/ADT/TinyPtrVector.h b/include/llvm/ADT/TinyPtrVector.h index 374357d9c6b..8f3925c9c55 100644 --- a/include/llvm/ADT/TinyPtrVector.h +++ b/include/llvm/ADT/TinyPtrVector.h @@ -10,8 +10,10 @@ #ifndef LLVM_ADT_TINYPTRVECTOR_H #define LLVM_ADT_TINYPTRVECTOR_H +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/PointerUnion.h" +#include "llvm/Support/Compiler.h" namespace llvm { @@ -32,6 +34,11 @@ public: if (VecTy *V = Val.template dyn_cast()) Val = new VecTy(*V); } +#if LLVM_USE_RVALUE_REFERENCES + TinyPtrVector(TinyPtrVector &&RHS) : Val(RHS.Val) { + RHS.Val = (EltTy)0; + } +#endif ~TinyPtrVector() { if (VecTy *V = Val.template dyn_cast()) delete V; @@ -42,7 +49,7 @@ public: if (Val.isNull()) return ArrayRef(); if (Val.template is()) - return *Val.template getAddrOf(); + return *Val.getAddrOfPtr1(); return *Val.template get(); } @@ -63,8 +70,10 @@ public: return Val.template get()->size(); } - typedef const EltTy *iterator; - iterator begin() const { + typedef const EltTy *const_iterator; + typedef EltTy *iterator; + + iterator begin() { if (empty()) return 0; @@ -74,7 +83,7 @@ public: return Val.template get()->begin(); } - iterator end() const { + iterator end() { if (empty()) return 0; @@ -84,7 +93,14 @@ public: return Val.template get()->end(); } - + const_iterator begin() const { + return (const_iterator)const_cast(this)->begin(); + } + + const_iterator end() const { + return (const_iterator)const_cast(this)->end(); + } + EltTy operator[](unsigned i) const { assert(!Val.isNull() && "can't index into an empty vector"); if (EltTy V = Val.template dyn_cast()) { @@ -104,6 +120,14 @@ public: return Val.template get()->front(); } + EltTy back() const { + assert(!empty() && "vector empty"); + if (EltTy V = Val.template dyn_cast()) + return V; + return Val.template get()->back(); + } + + void push_back(EltTy NewVal) { assert(NewVal != 0 && "Can't add a null value"); @@ -123,6 +147,15 @@ public: Val.template get()->push_back(NewVal); } + void pop_back() { + // If we have a single value, convert to empty. + if (Val.template is()) + Val = (EltTy)0; + else if (VecTy *Vec = Val.template get()) + Vec->pop_back(); + } + + void clear() { // If we have a single value, convert to empty. if (Val.template is()) { @@ -133,9 +166,26 @@ public: } // Otherwise, we're already empty. } + + iterator erase(iterator I) { + // If we have a single value, convert to empty. + if (Val.template is()) { + if (I == begin()) + Val = (EltTy)0; + } else if (VecTy *Vec = Val.template dyn_cast()) { + // multiple items in a vector; just do the erase, there is no + // benefit to collapsing back to a pointer + return Vec->erase(I); + } + + return 0; + } private: void operator=(const TinyPtrVector&); // NOT IMPLEMENTED YET. +#if LLVM_USE_RVALUE_REFERENCES + void operator=(TinyPtrVector&&); // NOT IMPLEMENTED YET. +#endif }; } // end namespace llvm