X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FADT%2FTinyPtrVector.h;h=5014517c9e05bae4a433bb402b165f8edc85e596;hb=005874056e536324cba9fa253d7e14a6f9dcf4fa;hp=e1dc3df56169b27eabffc3e530bd2309e053ffd3;hpb=9d69d4aadd4a58aba5634d5c3d2c2a6d8d284134;p=oota-llvm.git diff --git a/include/llvm/ADT/TinyPtrVector.h b/include/llvm/ADT/TinyPtrVector.h index e1dc3df5616..5014517c9e0 100644 --- a/include/llvm/ADT/TinyPtrVector.h +++ b/include/llvm/ADT/TinyPtrVector.h @@ -6,10 +6,6 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -// -// This file defines the Type class. -// -//===----------------------------------------------------------------------===// #ifndef LLVM_ADT_TINYPTRVECTOR_H #define LLVM_ADT_TINYPTRVECTOR_H @@ -41,9 +37,18 @@ public: delete V; } - /// empty() - This vector can be empty if it contains no element, or if it - /// contains a pointer to an empty vector. + // implicit conversion operator to ArrayRef. + operator ArrayRef() const { + if (Val.isNull()) + return ArrayRef(); + if (Val.template is()) + return *Val.getAddrOfPtr1(); + return *Val.template get(); + } + bool empty() const { + // This vector can be empty if it contains no element, or if it + // contains a pointer to an empty vector. if (Val.isNull()) return true; if (VecTy *Vec = Val.template dyn_cast()) return Vec->empty(); @@ -53,11 +58,42 @@ public: unsigned size() const { if (empty()) return 0; - if (Val. template is()) + if (Val.template is()) return 1; - return Val. template get()->size(); + return Val.template get()->size(); } + typedef const EltTy *const_iterator; + typedef EltTy *iterator; + + iterator begin() { + if (empty()) + return 0; + + if (Val.template is()) + return Val.getAddrOfPtr1(); + + return Val.template get()->begin(); + + } + iterator end() { + if (empty()) + return 0; + + if (Val.template is()) + return begin() + 1; + + 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()) { @@ -65,9 +101,9 @@ public: return V; } - assert(i < Val. template get()->size() && + assert(i < Val.template get()->size() && "tinyvector index out of range"); - return (*Val. template get())[i]; + return (*Val.template get())[i]; } EltTy front() const { @@ -87,7 +123,7 @@ public: } // If we have a single value, convert to a vector. - if (EltTy V = Val.template dyn_cast()) { + if (EltTy V = Val.template dyn_cast()) { Val = new VecTy(); Val.template get()->push_back(V); } @@ -98,7 +134,7 @@ public: void clear() { // If we have a single value, convert to empty. - if (EltTy V = Val.template dyn_cast()) { + if (Val.template is()) { Val = (EltTy)0; } else if (VecTy *Vec = Val.template dyn_cast()) { // If we have a vector form, just clear it. @@ -106,6 +142,20 @@ 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.