From: Chris Lattner Date: Sun, 31 Aug 2003 19:34:27 +0000 (+0000) Subject: * Cleanups X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=b55cae23cb9bd6661093e8c2822be4fd721587e1;p=oota-llvm.git * Cleanups * operator* now returns a reference to the current SCC, instead of a possibly null pointer git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8261 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/Support/SCCIterator.h b/include/Support/SCCIterator.h index 580a7cbfd42..bb78fb21c10 100644 --- a/include/Support/SCCIterator.h +++ b/include/Support/SCCIterator.h @@ -16,17 +16,16 @@ #define SUPPORT_TARJANSCCITERATOR_H #include "Support/GraphTraits.h" -#include "Support/Debug.h" #include "Support/iterator" #include #include //-------------------------------------------------------------------------- -// class SCC : A simple representation of an SCC in a generic Graph. +// class SCC - A simple representation of an SCC in a generic Graph. //-------------------------------------------------------------------------- template > -struct SCC: public std::vector { +struct SCC : public std::vector { typedef typename GT::NodeType NodeType; typedef typename GT::ChildIteratorType ChildItTy; @@ -43,7 +42,7 @@ struct SCC: public std::vector { bool HasLoop() const { if (size() > 1) return true; NodeType* N = front(); - for (ChildItTy CI=GT::child_begin(N), CE=GT::child_end(N); CI != CE; ++CI) + for (ChildItTy CI = GT::child_begin(N), CE=GT::child_end(N); CI != CE; ++CI) if (*CI == N) return true; return false; @@ -56,8 +55,7 @@ struct SCC: public std::vector { //-------------------------------------------------------------------------- template > -class TarjanSCC_iterator : public forward_iterator, ptrdiff_t> -{ +class TarjanSCC_iterator : public forward_iterator, ptrdiff_t> { typedef SCC SccTy; typedef forward_iterator super; typedef typename super::reference reference; @@ -185,32 +183,27 @@ public: _Self tmp = *this; ++*this; return tmp; } - // Retrieve a pointer to the current SCC. Returns NULL when done. - inline const SccTy* operator*() const { - assert(!CurrentSCC.empty() || VisitStack.empty()); - return CurrentSCC.empty()? NULL : &CurrentSCC; + // Retrieve a reference to the current SCC + inline const SccTy &operator*() const { + assert(!CurrentSCC.empty() && "Dereferencing END SCC iterator!"); + return CurrentSCC; } - inline SccTy* operator*() { - assert(!CurrentSCC.empty() || VisitStack.empty()); - return CurrentSCC.empty()? NULL : &CurrentSCC; + inline SccTy &operator*() { + assert(!CurrentSCC.empty() && "Dereferencing END SCC iterator!"); + return CurrentSCC; } }; -// Global constructor for the Tarjan SCC iterator. Use *I == NULL or I.fini() -// to test termination efficiently, instead of I == the "end" iterator. +// Global constructor for the Tarjan SCC iterator. template -TarjanSCC_iterator tarj_begin(T G) -{ +TarjanSCC_iterator tarj_begin(T G) { return TarjanSCC_iterator::begin(G); } template -TarjanSCC_iterator tarj_end(T G) -{ +TarjanSCC_iterator tarj_end(T G) { return TarjanSCC_iterator::end(G); } -//===----------------------------------------------------------------------===// - #endif diff --git a/include/llvm/ADT/SCCIterator.h b/include/llvm/ADT/SCCIterator.h index 580a7cbfd42..bb78fb21c10 100644 --- a/include/llvm/ADT/SCCIterator.h +++ b/include/llvm/ADT/SCCIterator.h @@ -16,17 +16,16 @@ #define SUPPORT_TARJANSCCITERATOR_H #include "Support/GraphTraits.h" -#include "Support/Debug.h" #include "Support/iterator" #include #include //-------------------------------------------------------------------------- -// class SCC : A simple representation of an SCC in a generic Graph. +// class SCC - A simple representation of an SCC in a generic Graph. //-------------------------------------------------------------------------- template > -struct SCC: public std::vector { +struct SCC : public std::vector { typedef typename GT::NodeType NodeType; typedef typename GT::ChildIteratorType ChildItTy; @@ -43,7 +42,7 @@ struct SCC: public std::vector { bool HasLoop() const { if (size() > 1) return true; NodeType* N = front(); - for (ChildItTy CI=GT::child_begin(N), CE=GT::child_end(N); CI != CE; ++CI) + for (ChildItTy CI = GT::child_begin(N), CE=GT::child_end(N); CI != CE; ++CI) if (*CI == N) return true; return false; @@ -56,8 +55,7 @@ struct SCC: public std::vector { //-------------------------------------------------------------------------- template > -class TarjanSCC_iterator : public forward_iterator, ptrdiff_t> -{ +class TarjanSCC_iterator : public forward_iterator, ptrdiff_t> { typedef SCC SccTy; typedef forward_iterator super; typedef typename super::reference reference; @@ -185,32 +183,27 @@ public: _Self tmp = *this; ++*this; return tmp; } - // Retrieve a pointer to the current SCC. Returns NULL when done. - inline const SccTy* operator*() const { - assert(!CurrentSCC.empty() || VisitStack.empty()); - return CurrentSCC.empty()? NULL : &CurrentSCC; + // Retrieve a reference to the current SCC + inline const SccTy &operator*() const { + assert(!CurrentSCC.empty() && "Dereferencing END SCC iterator!"); + return CurrentSCC; } - inline SccTy* operator*() { - assert(!CurrentSCC.empty() || VisitStack.empty()); - return CurrentSCC.empty()? NULL : &CurrentSCC; + inline SccTy &operator*() { + assert(!CurrentSCC.empty() && "Dereferencing END SCC iterator!"); + return CurrentSCC; } }; -// Global constructor for the Tarjan SCC iterator. Use *I == NULL or I.fini() -// to test termination efficiently, instead of I == the "end" iterator. +// Global constructor for the Tarjan SCC iterator. template -TarjanSCC_iterator tarj_begin(T G) -{ +TarjanSCC_iterator tarj_begin(T G) { return TarjanSCC_iterator::begin(G); } template -TarjanSCC_iterator tarj_end(T G) -{ +TarjanSCC_iterator tarj_end(T G) { return TarjanSCC_iterator::end(G); } -//===----------------------------------------------------------------------===// - #endif