- // TODO: This can be random access iterator, need operator+ and stuff tho
-
- inline SuccIterator(_Term T) : Term(T), idx(0) { // begin iterator
- assert(T && "getTerminator returned null!");
- }
- inline SuccIterator(_Term T, bool) // end iterator
- : Term(T), idx(Term->getNumSuccessors()) {
- assert(T && "getTerminator returned null!");
- }
-
- inline bool operator==(const _Self& x) const { return idx == x.idx; }
- inline bool operator!=(const _Self& x) const { return !operator==(x); }
-
- inline pointer operator*() const { return Term->getSuccessor(idx); }
+ typedef typename super::reference reference;
+ // TODO: This can be random access iterator, only operator[] missing.
+
+ explicit inline SuccIterator(Term_ T) : Term(T), idx(0) {// begin iterator
+ }
+ inline SuccIterator(Term_ T, bool) // end iterator
+ : Term(T) {
+ if (Term)
+ idx = Term->getNumSuccessors();
+ else
+ // Term == NULL happens, if a basic block is not fully constructed and
+ // consequently getTerminator() returns NULL. In this case we construct a
+ // SuccIterator which describes a basic block that has zero successors.
+ // Defining SuccIterator for incomplete and malformed CFGs is especially
+ // useful for debugging.
+ idx = 0;
+ }
+
+ inline const Self &operator=(const Self &I) {
+ assert(Term == I.Term &&"Cannot assign iterators to two different blocks!");
+ idx = I.idx;
+ return *this;
+ }
+
+ /// getSuccessorIndex - This is used to interface between code that wants to
+ /// operate on terminator instructions directly.
+ unsigned getSuccessorIndex() const { return idx; }
+
+ inline bool operator==(const Self& x) const { return idx == x.idx; }
+ inline bool operator!=(const Self& x) const { return !operator==(x); }
+
+ inline reference operator*() const { return Term->getSuccessor(idx); }