Remove references to `bugpoint' from the now-generic system utilities.
[oota-llvm.git] / include / Support / ilist
index 04cf596698d639eae8e51d68c41038a8906242f4..afd858d5590af09a30fb94289e9a1130033d6f52 100644 (file)
@@ -12,7 +12,7 @@
 // The ilist class itself, should be a plug in replacement for list, assuming
 // that the nodes contain next/prev pointers.  This list replacement does not
 // provides a constant time size() method, so be careful to use empty() when you
-// really want to know if I'm empty.
+// really want to know if it's empty.
 //
 // The ilist class is implemented by allocating a 'tail' node when the list is
 // created (using ilist_traits<>::createEndMarker()).  This tail node is
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef INCLUDED_SUPPORT_ILIST
-#define INCLUDED_SUPPORT_ILIST
+#ifndef SUPPORT_ILIST
+#define SUPPORT_ILIST
 
-#include <assert.h>
-#include <iterator>
+#include <algorithm>
+#include <Support/iterator>
 
 template<typename NodeTy, typename Traits> class iplist;
 template<typename NodeTy> class ilist_iterator;
@@ -69,13 +69,21 @@ struct ilist_traits<const Ty> : public ilist_traits<Ty> {};
 // ilist_iterator<Node> - Iterator for intrusive list.
 //
 template<typename NodeTy>
-class ilist_iterator : public std::bidirectional_iterator<NodeTy, ptrdiff_t> {
+class ilist_iterator
+  : public bidirectional_iterator<NodeTy, ptrdiff_t> {
   typedef ilist_traits<NodeTy> Traits;
-  pointer NodePtr;
+  typedef bidirectional_iterator<NodeTy, ptrdiff_t> super;
+
 public:
   typedef size_t size_type;
+  typedef typename super::pointer pointer;
+  typedef typename super::reference reference;
+private:
+  pointer NodePtr;
+public:
 
   ilist_iterator(pointer NP) : NodePtr(NP) {}
+  ilist_iterator(reference NR) : NodePtr(&NR) {}
   ilist_iterator() : NodePtr(0) {}
 
   // This is templated so that we can allow constructing a const iterator from
@@ -144,6 +152,26 @@ public:
   pointer getNodePtrUnchecked() const { return NodePtr; }
 };
 
+// Allow ilist_iterators to convert into pointers to a node automatically when
+// used by the dyn_cast, cast, isa mechanisms...
+
+template<typename From> struct simplify_type;
+
+template<typename NodeTy> struct simplify_type<ilist_iterator<NodeTy> > {
+  typedef NodeTy* SimpleType;
+  
+  static SimpleType getSimplifiedValue(const ilist_iterator<NodeTy> &Node) {
+    return &*Node;
+  }
+};
+template<typename NodeTy> struct simplify_type<const ilist_iterator<NodeTy> > {
+  typedef NodeTy* SimpleType;
+  
+  static SimpleType getSimplifiedValue(const ilist_iterator<NodeTy> &Node) {
+    return &*Node;
+  }
+};
+
 
 //===----------------------------------------------------------------------===//
 //
@@ -167,8 +195,8 @@ public:
   typedef ilist_iterator<const NodeTy> const_iterator;
   typedef size_t size_type;
   typedef ptrdiff_t difference_type;
-  typedef reverse_iterator<const_iterator>  const_reverse_iterator;
-  typedef reverse_iterator<iterator>  reverse_iterator;
+  typedef std::reverse_iterator<const_iterator>  const_reverse_iterator;
+  typedef std::reverse_iterator<iterator>  reverse_iterator;
 
   iplist() : Head(createNode()), Tail(Head) {
     setNext(Head, 0);
@@ -301,8 +329,12 @@ public:
   //
 
   size_type size() const {
+#if __GNUC__ == 3
+    size_type Result = std::distance(begin(), end());
+#else
     size_type Result = 0;
     std::distance(begin(), end(), Result);
+#endif
     return Result;
   }
 
@@ -404,6 +436,9 @@ public:
 
 template<typename NodeTy>
 struct ilist : public iplist<NodeTy> {
+  typedef typename iplist<NodeTy>::size_type size_type;
+  typedef typename iplist<NodeTy>::iterator iterator;
+
   ilist() {}
   ilist(const ilist &right) {
     insert(begin(), right.begin(), right.end());
@@ -478,7 +513,6 @@ struct ilist : public iplist<NodeTy> {
       insert(end(), newsize - len, val);
   }
   void resize(size_type newsize) { resize(newsize, NodeTy()); }
-
 };
 
 namespace std {