llvm.org GIT mirror llvm / 6193e5b
Use C++, not C++-standard-library-internals-ese. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101245 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 10 years ago
1 changed file(s) with 39 addition(s) and 39 deletion(s). Raw diff Collapse all Expand all
2424 // BasicBlock pred_iterator definition
2525 //===----------------------------------------------------------------------===//
2626
27 template _Ptr, class _USE_iterator> // Predecessor Iterator
27 template Ptr, class USE_iterator> // Predecessor Iterator
2828 class PredIterator : public std::iterator
29 _Ptr, ptrdiff_t> {
30 typedef std::iterator super;
31 typedef PredIterator<_Ptr,_USE_iterator> _Self;
32 _USE_iterator It;
29 Ptr, ptrdiff_t> {
30 typedef std::iterator super;
31 typedef PredIterator Self;
32 USE_iterator It;
3333
3434 inline void advancePastNonTerminators() {
3535 // Loop to ignore non terminator uses (for example PHI nodes)...
4040 public:
4141 typedef typename super::pointer pointer;
4242
43 inline PredIterator(_Ptr *bb) : It(bb->use_begin()) {
43 inline PredIterator(Ptr *bb) : It(bb->use_begin()) {
4444 advancePastNonTerminators();
4545 }
46 inline PredIterator(_Ptr *bb, bool) : It(bb->use_end()) {}
47
48 inline bool operator==(const _Self& x) const { return It == x.It; }
49 inline bool operator!=(const _Self& x) const { return !operator==(x); }
46 inline PredIterator(Ptr *bb, bool) : It(bb->use_end()) {}
47
48 inline bool operator==(const Self& x) const { return It == x.It; }
49 inline bool operator!=(const Self& x) const { return !operator==(x); }
5050
5151 inline pointer operator*() const {
5252 assert(!It.atEnd() && "pred_iterator out of range!");
5454 }
5555 inline pointer *operator->() const { return &(operator*()); }
5656
57 inline _Self& operator++() { // Preincrement
57 inline Self& operator++() { // Preincrement
5858 assert(!It.atEnd() && "pred_iterator out of range!");
5959 ++It; advancePastNonTerminators();
6060 return *this;
6161 }
6262
63 inline _Self operator++(int) { // Postincrement
64 _Self tmp = *this; ++*this; return tmp;
63 inline Self operator++(int) { // Postincrement
64 Self tmp = *this; ++*this; return tmp;
6565 }
6666 };
6767
9090 const Term_ Term;
9191 unsigned idx;
9292 typedef std::iterator super;
93 typedef SuccIterator _Self;
93 typedef SuccIterator Self;
9494
9595 inline bool index_is_valid(int idx) {
9696 return idx >= 0 && (unsigned) idx < Term->getNumSuccessors();
108108 assert(T && "getTerminator returned null!");
109109 }
110110
111 inline const _Self &operator=(const _Self &I) {
111 inline const Self &operator=(const Self &I) {
112112 assert(Term == I.Term &&"Cannot assign iterators to two different blocks!");
113113 idx = I.idx;
114114 return *this;
118118 /// operate on terminator instructions directly.
119119 unsigned getSuccessorIndex() const { return idx; }
120120
121 inline bool operator==(const _Self& x) const { return idx == x.idx; }
122 inline bool operator!=(const _Self& x) const { return !operator==(x); }
121 inline bool operator==(const Self& x) const { return idx == x.idx; }
122 inline bool operator!=(const Self& x) const { return !operator==(x); }
123123
124124 inline pointer operator*() const { return Term->getSuccessor(idx); }
125125 inline pointer operator->() const { return operator*(); }
126126
127 inline _Self& operator++() { ++idx; return *this; } // Preincrement
128
129 inline _Self operator++(int) { // Postincrement
130 _Self tmp = *this; ++*this; return tmp;
131 }
132
133 inline _Self& operator--() { --idx; return *this; } // Predecrement
134 inline _Self operator--(int) { // Postdecrement
135 _Self tmp = *this; --*this; return tmp;
136 }
137
138 inline bool operator<(const _Self& x) const {
127 inline Self& operator++() { ++idx; return *this; } // Preincrement
128
129 inline Self operator++(int) { // Postincrement
130 Self tmp = *this; ++*this; return tmp;
131 }
132
133 inline Self& operator--() { --idx; return *this; } // Predecrement
134 inline Self operator--(int) { // Postdecrement
135 Self tmp = *this; --*this; return tmp;
136 }
137
138 inline bool operator<(const Self& x) const {
139139 assert(Term == x.Term && "Cannot compare iterators of different blocks!");
140140 return idx < x.idx;
141141 }
142142
143 inline bool operator<=(const _Self& x) const {
143 inline bool operator<=(const Self& x) const {
144144 assert(Term == x.Term && "Cannot compare iterators of different blocks!");
145145 return idx <= x.idx;
146146 }
147 inline bool operator>=(const _Self& x) const {
147 inline bool operator>=(const Self& x) const {
148148 assert(Term == x.Term && "Cannot compare iterators of different blocks!");
149149 return idx >= x.idx;
150150 }
151151
152 inline bool operator>(const _Self& x) const {
152 inline bool operator>(const Self& x) const {
153153 assert(Term == x.Term && "Cannot compare iterators of different blocks!");
154154 return idx > x.idx;
155155 }
156156
157 inline _Self& operator+=(int Right) {
157 inline Self& operator+=(int Right) {
158158 unsigned new_idx = idx + Right;
159159 assert(index_is_valid(new_idx) && "Iterator index out of bound");
160160 idx = new_idx;
161161 return *this;
162162 }
163163
164 inline _Self operator+(int Right) {
165 _Self tmp = *this;
164 inline Self operator+(int Right) {
165 Self tmp = *this;
166166 tmp += Right;
167167 return tmp;
168168 }
169169
170 inline _Self& operator-=(int Right) {
170 inline Self& operator-=(int Right) {
171171 return operator+=(-Right);
172172 }
173173
174 inline _Self operator-(int Right) {
174 inline Self operator-(int Right) {
175175 return operator+(-Right);
176176 }
177177
178 inline int operator-(const _Self& x) {
178 inline int operator-(const Self& x) {
179179 assert(Term == x.Term && "Cannot work on iterators of different blocks!");
180180 int distance = idx - x.idx;
181181 return distance;
186186 // be modified are not available.
187187 //
188188 // inline pointer operator[](int offset) {
189 // _Self tmp = *this;
189 // Self tmp = *this;
190190 // tmp += offset;
191191 // return tmp.operator*();
192192 // }