llvm.org GIT mirror llvm / b55cae2
* 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 Chris Lattner 16 years ago
2 changed file(s) with 30 addition(s) and 44 deletion(s). Raw diff Collapse all Expand all
1515 #define SUPPORT_TARJANSCCITERATOR_H
1616
1717 #include "Support/GraphTraits.h"
18 #include "Support/Debug.h"
1918 #include "Support/iterator"
2019 #include
2120 #include
2221
2322 //--------------------------------------------------------------------------
24 // class SCC : A simple representation of an SCC in a generic Graph.
23 // class SCC - A simple representation of an SCC in a generic Graph.
2524 //--------------------------------------------------------------------------
2625
2726 template >
28 struct SCC: public std::vector {
27 struct SCC : public std::vector {
2928
3029 typedef typename GT::NodeType NodeType;
3130 typedef typename GT::ChildIteratorType ChildItTy;
4241 bool HasLoop() const {
4342 if (size() > 1) return true;
4443 NodeType* N = front();
45 for (ChildItTy CI=GT::child_begin(N), CE=GT::child_end(N); CI != CE; ++CI)
44 for (ChildItTy CI = GT::child_begin(N), CE=GT::child_end(N); CI != CE; ++CI)
4645 if (*CI == N)
4746 return true;
4847 return false;
5554 //--------------------------------------------------------------------------
5655
5756 template >
58 class TarjanSCC_iterator : public forward_iterator, ptrdiff_t>
59 {
57 class TarjanSCC_iterator : public forward_iterator, ptrdiff_t> {
6058 typedef SCC SccTy;
6159 typedef forward_iterator super;
6260 typedef typename super::reference reference;
184182 _Self tmp = *this; ++*this; return tmp;
185183 }
186184
187 // Retrieve a pointer to the current SCC. Returns NULL when done.
188 inline const SccTy* operator*() const {
189 assert(!CurrentSCC.empty() || VisitStack.empty());
190 return CurrentSCC.empty()? NULL : &CurrentSCC;
191 }
192 inline SccTy* operator*() {
193 assert(!CurrentSCC.empty() || VisitStack.empty());
194 return CurrentSCC.empty()? NULL : &CurrentSCC;
185 // Retrieve a reference to the current SCC
186 inline const SccTy &operator*() const {
187 assert(!CurrentSCC.empty() && "Dereferencing END SCC iterator!");
188 return CurrentSCC;
189 }
190 inline SccTy &operator*() {
191 assert(!CurrentSCC.empty() && "Dereferencing END SCC iterator!");
192 return CurrentSCC;
195193 }
196194 };
197195
198196
199 // Global constructor for the Tarjan SCC iterator. Use *I == NULL or I.fini()
200 // to test termination efficiently, instead of I == the "end" iterator.
197 // Global constructor for the Tarjan SCC iterator.
201198 template
202 TarjanSCC_iterator tarj_begin(T G)
203 {
199 TarjanSCC_iterator tarj_begin(T G) {
204200 return TarjanSCC_iterator::begin(G);
205201 }
206202
207203 template
208 TarjanSCC_iterator tarj_end(T G)
209 {
204 TarjanSCC_iterator tarj_end(T G) {
210205 return TarjanSCC_iterator::end(G);
211206 }
212207
213 //===----------------------------------------------------------------------===//
214
215208 #endif
1515 #define SUPPORT_TARJANSCCITERATOR_H
1616
1717 #include "Support/GraphTraits.h"
18 #include "Support/Debug.h"
1918 #include "Support/iterator"
2019 #include
2120 #include
2221
2322 //--------------------------------------------------------------------------
24 // class SCC : A simple representation of an SCC in a generic Graph.
23 // class SCC - A simple representation of an SCC in a generic Graph.
2524 //--------------------------------------------------------------------------
2625
2726 template >
28 struct SCC: public std::vector {
27 struct SCC : public std::vector {
2928
3029 typedef typename GT::NodeType NodeType;
3130 typedef typename GT::ChildIteratorType ChildItTy;
4241 bool HasLoop() const {
4342 if (size() > 1) return true;
4443 NodeType* N = front();
45 for (ChildItTy CI=GT::child_begin(N), CE=GT::child_end(N); CI != CE; ++CI)
44 for (ChildItTy CI = GT::child_begin(N), CE=GT::child_end(N); CI != CE; ++CI)
4645 if (*CI == N)
4746 return true;
4847 return false;
5554 //--------------------------------------------------------------------------
5655
5756 template >
58 class TarjanSCC_iterator : public forward_iterator, ptrdiff_t>
59 {
57 class TarjanSCC_iterator : public forward_iterator, ptrdiff_t> {
6058 typedef SCC SccTy;
6159 typedef forward_iterator super;
6260 typedef typename super::reference reference;
184182 _Self tmp = *this; ++*this; return tmp;
185183 }
186184
187 // Retrieve a pointer to the current SCC. Returns NULL when done.
188 inline const SccTy* operator*() const {
189 assert(!CurrentSCC.empty() || VisitStack.empty());
190 return CurrentSCC.empty()? NULL : &CurrentSCC;
191 }
192 inline SccTy* operator*() {
193 assert(!CurrentSCC.empty() || VisitStack.empty());
194 return CurrentSCC.empty()? NULL : &CurrentSCC;
185 // Retrieve a reference to the current SCC
186 inline const SccTy &operator*() const {
187 assert(!CurrentSCC.empty() && "Dereferencing END SCC iterator!");
188 return CurrentSCC;
189 }
190 inline SccTy &operator*() {
191 assert(!CurrentSCC.empty() && "Dereferencing END SCC iterator!");
192 return CurrentSCC;
195193 }
196194 };
197195
198196
199 // Global constructor for the Tarjan SCC iterator. Use *I == NULL or I.fini()
200 // to test termination efficiently, instead of I == the "end" iterator.
197 // Global constructor for the Tarjan SCC iterator.
201198 template
202 TarjanSCC_iterator tarj_begin(T G)
203 {
199 TarjanSCC_iterator tarj_begin(T G) {
204200 return TarjanSCC_iterator::begin(G);
205201 }
206202
207203 template
208 TarjanSCC_iterator tarj_end(T G)
209 {
204 TarjanSCC_iterator tarj_end(T G) {
210205 return TarjanSCC_iterator::end(G);
211206 }
212207
213 //===----------------------------------------------------------------------===//
214
215208 #endif