Add a helper class (APSInt) which can represent an APInt along with sign
[oota-llvm.git] / include / llvm / ADT / ilist
index 9d9fdf0fdb8ea67ac3b6b87ac8d89a14280f6db5..1d01b63fe73647e4ca28172658bdcba6f1ab0520 100644 (file)
@@ -1,4 +1,4 @@
-//===-- Support/ilist - Intrusive Linked List Template ----------*- C++ -*-===//
+//===-- llvm/ADT/ilist - Intrusive Linked List Template ---------*- C++ -*-===//
 // 
 //                     The LLVM Compiler Infrastructure
 //
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef SUPPORT_ILIST
-#define SUPPORT_ILIST
+#ifndef LLVM_ADT_ILIST
+#define LLVM_ADT_ILIST
 
-#include <Support/iterator>
+#include "llvm/ADT/iterator"
 #include <cassert>
 
 namespace llvm {
@@ -58,9 +58,10 @@ struct ilist_traits {
   static void setPrev(NodeTy *N, NodeTy *Prev) { N->setPrev(Prev); }
   static void setNext(NodeTy *N, NodeTy *Next) { N->setNext(Next); }
 
-  static NodeTy *createNode() { return new NodeTy(); }
   static NodeTy *createNode(const NodeTy &V) { return new NodeTy(V); }
 
+  static NodeTy *createSentinel() { return new NodeTy(); }
+  static void destroySentinel(NodeTy *N) { delete N; }
 
   void addNodeToList(NodeTy *NTy) {}
   void removeNodeFromList(NodeTy *NTy) {}
@@ -168,91 +169,24 @@ void operator+(int, ilist_iterator<T>);
 template<typename T>
 void operator+(ilist_iterator<T>,int);
 
-//===----------------------------------------------------------------------===//
-// ilist_compat_iterator<Node> - Compatibility iterator for intrusive list.
-// This makes an ilist<X> act like an std::list<X*>, where you have to
-// dereference stuff multiple times.  This should only be used for temporary
-// migration purposes.  Because we don't support "changing the pointer", we only
-// expose constant pointers.
-//
-template<typename NodeTy>
-class ilist_compat_iterator
-  : public bidirectional_iterator<NodeTy* const, ptrdiff_t> {
-  typedef ilist_traits<NodeTy> Traits;
-  typedef bidirectional_iterator<NodeTy* const, ptrdiff_t> super;
-
-public:
-  typedef size_t size_type;
-  typedef typename super::pointer pointer;
-  typedef typename super::reference reference;
-private:
-  NodeTy *NodePtr;
-public:
-
-  ilist_compat_iterator(NodeTy *NP) : NodePtr(NP) {}
-  ilist_compat_iterator() : NodePtr(0) {}
-
-  // This is templated so that we can allow constructing a const iterator from
-  // a nonconst iterator...
-  template<class node_ty>
-  ilist_compat_iterator(const ilist_compat_iterator<node_ty> &RHS)
-    : NodePtr(RHS.getNodePtrUnchecked()) {}
-
-  // This is templated so that we can allow assigning to a const iterator from
-  // a nonconst iterator...
-  template<class node_ty>
-  const ilist_compat_iterator &operator=(const 
-                                         ilist_compat_iterator<node_ty> &RHS) {
-    NodePtr = RHS.getNodePtrUnchecked();
-    return *this;
-  }
-
-  // Accessors...
-  operator pointer() const {
-    assert(Traits::getNext(NodePtr) != 0 && "Dereferencing end()!");
-    return &NodePtr;
-  }
-
-  reference operator*() const {
-    assert(Traits::getNext(NodePtr) != 0 && "Dereferencing end()!");
-    return NodePtr;
-  }
-  pointer operator->() { return &operator*(); }
-  const pointer operator->() const { return &operator*(); }
-
-  // Comparison operators
-  bool operator==(const ilist_compat_iterator &RHS) const {
-    return NodePtr == RHS.NodePtr;
-  }
-  bool operator!=(const ilist_compat_iterator &RHS) const {
-    return NodePtr != RHS.NodePtr;
-  }
-
-  // Increment and decrement operators...
-  ilist_compat_iterator &operator--() {      // predecrement - Back up
-    NodePtr = Traits::getPrev(NodePtr);
-    assert(NodePtr && "--'d off the beginning of an ilist!");
-    return *this;
-  }
-  ilist_compat_iterator &operator++() {      // preincrement - Advance
-    NodePtr = Traits::getNext(NodePtr);
-    assert(NodePtr && "++'d off the end of an ilist!");
-    return *this;
-  }
-  ilist_compat_iterator operator--(int) {    // postdecrement operators...
-    ilist_compat_iterator tmp = *this;
-    --*this;
-    return tmp;
-  }
-  ilist_compat_iterator operator++(int) {    // postincrement operators...
-    ilist_compat_iterator tmp = *this;
-    ++*this;
-    return tmp;
-  }
-
-  // Internal interface, do not use...
-  pointer getNodePtrUnchecked() const { return NodePtr; }
-};
+// operator!=/operator== - Allow mixed comparisons without dereferencing
+// the iterator, which could very likely be pointing to end().
+template<typename T>
+bool operator!=(const T* LHS, const ilist_iterator<const T> &RHS) {
+  return LHS != RHS.getNodePtrUnchecked();
+}
+template<typename T>
+bool operator==(const T* LHS, const ilist_iterator<const T> &RHS) {
+  return LHS == RHS.getNodePtrUnchecked();
+}
+template<typename T>
+bool operator!=(T* LHS, const ilist_iterator<T> &RHS) {
+  return LHS != RHS.getNodePtrUnchecked();
+}
+template<typename T>
+bool operator==(T* LHS, const ilist_iterator<T> &RHS) {
+  return LHS == RHS.getNodePtrUnchecked();
+}
 
 
 // Allow ilist_iterators to convert into pointers to a node automatically when
@@ -301,11 +235,11 @@ public:
   typedef std::reverse_iterator<const_iterator>  const_reverse_iterator;
   typedef std::reverse_iterator<iterator>  reverse_iterator;
 
-  iplist() : Head(Traits::createNode()), Tail(Head) {
+  iplist() : Head(Traits::createSentinel()), Tail(Head) {
     setNext(Head, 0);
     setPrev(Head, 0);
   }
-  ~iplist() { clear(); delete Tail; }
+  ~iplist() { clear(); Traits::destroySentinel(Tail); }
 
   // Iterator creation methods.
   iterator begin()             { return iterator(Head); }
@@ -320,11 +254,6 @@ public:
   const_reverse_iterator rend() const  {return const_reverse_iterator(begin());}
 
 
-  // "compatibility" iterator creation methods.
-  typedef ilist_compat_iterator<NodeTy> compat_iterator;
-  compat_iterator compat_begin() const { return compat_iterator(Head); }
-  compat_iterator compat_end()   const { return compat_iterator(Tail); }
-
   // Miscellaneous inspection routines.
   size_type max_size() const { return size_type(-1); }
   bool empty() const { return Head == Tail; }