X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=include%2Fllvm%2FADT%2FImmutableList.h;h=a1d26bd97045e0ea296e216a796704093cea65dc;hp=7757c08770bd6e0e9c44bbd6d8543b953f552f39;hb=df7186636e51e63281bd318234b7d97f25efe491;hpb=4bbf4ee1491637c247e195e19e3e4a8ee5ad72fa diff --git a/include/llvm/ADT/ImmutableList.h b/include/llvm/ADT/ImmutableList.h index 7757c08770b..a1d26bd9704 100644 --- a/include/llvm/ADT/ImmutableList.h +++ b/include/llvm/ADT/ImmutableList.h @@ -11,12 +11,12 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_ADT_IMLIST_H -#define LLVM_ADT_IMLIST_H +#ifndef LLVM_ADT_IMMUTABLELIST_H +#define LLVM_ADT_IMMUTABLELIST_H -#include "llvm/Support/Allocator.h" #include "llvm/ADT/FoldingSet.h" -#include "llvm/System/DataTypes.h" +#include "llvm/Support/Allocator.h" +#include "llvm/Support/DataTypes.h" #include namespace llvm { @@ -28,14 +28,13 @@ class ImmutableListImpl : public FoldingSetNode { T Head; const ImmutableListImpl* Tail; - ImmutableListImpl(const T& head, const ImmutableListImpl* tail = 0) + ImmutableListImpl(const T& head, const ImmutableListImpl* tail = nullptr) : Head(head), Tail(tail) {} friend class ImmutableListFactory; - // Do not implement. - void operator=(const ImmutableListImpl&); - ImmutableListImpl(const ImmutableListImpl&); + void operator=(const ImmutableListImpl&) = delete; + ImmutableListImpl(const ImmutableListImpl&) = delete; public: const T& getHead() const { return Head; } @@ -73,7 +72,7 @@ public: // This constructor should normally only be called by ImmutableListFactory. // There may be cases, however, when one needs to extract the internal pointer // and reconstruct a list object from that pointer. - ImmutableList(const ImmutableListImpl* x = 0) : X(x) {} + ImmutableList(const ImmutableListImpl* x = nullptr) : X(x) {} const ImmutableListImpl* getInternalPointer() const { return X; @@ -82,7 +81,7 @@ public: class iterator { const ImmutableListImpl* L; public: - iterator() : L(0) {} + iterator() : L(nullptr) {} iterator(ImmutableList l) : L(l.getInternalPointer()) {} iterator& operator++() { L = L->getTail(); return *this; } @@ -103,6 +102,14 @@ public: /// isEmpty - Returns true if the list is empty. bool isEmpty() const { return !X; } + bool contains(const T& V) const { + for (iterator I = begin(), E = end(); I != E; ++I) { + if (*I == V) + return true; + } + return false; + } + /// isEqual - Returns true if two lists are equal. Because all lists created /// from the same ImmutableListFactory are uniqued, this has O(1) complexity /// because it the contents of the list do not need to be compared. Note @@ -121,7 +128,7 @@ public: /// getTail - Returns the tail of the list, which is another (possibly empty) /// ImmutableList. ImmutableList getTail() { - return X ? X->getTail() : 0; + return X ? X->getTail() : nullptr; } void Profile(FoldingSetNodeID& ID) const { @@ -156,7 +163,7 @@ public: if (ownsAllocator()) delete &getAllocator(); } - ImmutableList Concat(const T& Head, ImmutableList Tail) { + ImmutableList concat(const T& Head, ImmutableList Tail) { // Profile the new list to see if it already exists in our cache. FoldingSetNodeID ID; void* InsertPos; @@ -178,16 +185,16 @@ public: return L; } - ImmutableList Add(const T& D, ImmutableList L) { - return Concat(D, L); + ImmutableList add(const T& D, ImmutableList L) { + return concat(D, L); } - ImmutableList GetEmptyList() const { - return ImmutableList(0); + ImmutableList getEmptyList() const { + return ImmutableList(nullptr); } - ImmutableList Create(const T& X) { - return Concat(X, GetEmptyList()); + ImmutableList create(const T& X) { + return Concat(X, getEmptyList()); } }; @@ -219,4 +226,4 @@ struct isPodLike > { static const bool value = true; }; } // end llvm namespace -#endif +#endif // LLVM_ADT_IMMUTABLELIST_H