Changeset 8a81b09
- Timestamp:
- Dec 16, 2020, 3:47:12 PM (2 years ago)
- Branches:
- ADT, arm-eh, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- accc5dbb
- Parents:
- d25b2d6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/sequence.hfa
rd25b2d6 r8a81b09 216 216 } // distribution 217 217 218 // forall( dtype T) {219 //// SeqIter(T) is used to iterate over a Sequence(T) in head-to-tail order.220 //struct SeqIter {221 //inline ColIter;222 //// The Sequence must be passed to pred and succ to check for the end of the Sequence and return 0p. Without223 //// passing the sequence, traversing would require its length. Thus the iterator needs a pointer to the sequence224 //// to pass to succ/pred. Both stack and queue just encounter 0p since the lists are not circular.225 //Sequence(T) * seq; // FIX ME: cannot be reference226 //};227 228 //static inline {229 //void ?{}( SeqIter(T) & si ) with( si ) {230 //((ColIter &)si){};231 //seq = 0p;232 //} // post: elts = null.233 234 //void ?{}( SeqIter(T) & si, Sequence(T) & s ) with( si ) {235 //((ColIter &)si){};236 //seq = &s;237 //curr = &head( s );238 //} // post: elts = null.239 240 //void ?{}( SeqIter(T) & si, Sequence(T) & s, T & start ) with( si ) {241 //((ColIter &)si){};242 //seq = &s;243 //curr = &start;244 //} // post: elts = null.245 246 //void over( SeqIter(T) & si, Sequence(T) & s ) with( si ) {247 //seq = &s;248 //curr = &head( s );249 //} // post: elts = {e in s}.250 251 //bool ?>>?( SeqIter(T) & si, T && tp ) with( si ) {252 //if ( curr ) {253 //&tp = Curr( si );254 //T * n = succ( *seq, Curr( si ) );255 //curr = n == &head( *seq ) ? 0p : n;256 //} else &tp = 0p;257 //return &tp != 0p;258 //}259 //} // distribution260 261 262 //// A SeqIterRev(T) is used to iterate over a Sequence(T) in tail-to-head order.263 //struct SeqIterRev {264 //inline ColIter;265 //// See above for explanation.266 //Sequence(T) * seq; // FIX ME: cannot be reference267 //};268 269 //static inline {270 //void ?{}( SeqIterRev(T) & si ) with( si ) {271 //((ColIter &)si){};272 //seq = 0p;273 //} // post: elts = null.274 275 //void ?{}( SeqIterRev(T) & si, Sequence(T) & s ) with( si ) {276 //((ColIter &)si){};277 //seq = &s;278 //curr = &tail( s );279 //} // post: elts = null.280 281 //void ?{}( SeqIterRev(T) & si, Sequence(T) & s, T & start ) with( si ) {282 //((ColIter &)si){};283 //seq = &s;284 //curr = &start;285 //} // post: elts = null.286 287 //void over( SeqIterRev(T) & si, Sequence(T) & s ) with( si ) {288 //seq = &s;289 //curr = &tail( s );290 //} // post: elts = {e in s}.291 292 //bool ?>>?( SeqIterRev(T) & si, T && tp ) with( si ) {293 //if ( curr ) {294 //&tp = Curr( si );295 //T * n = pred( *seq, Curr( si ) );296 //curr = n == &tail( *seq ) ? 0p : n;297 //} else &tp = 0p;298 //return &tp != 0p;299 //}300 //} // distribution301 //} // distribution218 forall( dtype T | { T *& Back ( T * ); T *& Next ( T * ); bool listed ( T * ); } ) { 219 // SeqIter(T) is used to iterate over a Sequence(T) in head-to-tail order. 220 struct SeqIter { 221 inline ColIter; 222 // The Sequence must be passed to pred and succ to check for the end of the Sequence and return 0p. Without 223 // passing the sequence, traversing would require its length. Thus the iterator needs a pointer to the sequence 224 // to pass to succ/pred. Both stack and queue just encounter 0p since the lists are not circular. 225 Sequence(T) * seq; // FIX ME: cannot be reference 226 }; 227 228 static inline { 229 void ?{}( SeqIter(T) & si ) with( si ) { 230 ((ColIter &)si){}; 231 seq = 0p; 232 } // post: elts = null. 233 234 void ?{}( SeqIter(T) & si, Sequence(T) & s ) with( si ) { 235 ((ColIter &)si){}; 236 seq = &s; 237 curr = &head( s ); 238 } // post: elts = null. 239 240 void ?{}( SeqIter(T) & si, Sequence(T) & s, T & start ) with( si ) { 241 ((ColIter &)si){}; 242 seq = &s; 243 curr = &start; 244 } // post: elts = null. 245 246 void over( SeqIter(T) & si, Sequence(T) & s ) with( si ) { 247 seq = &s; 248 curr = &head( s ); 249 } // post: elts = {e in s}. 250 251 bool ?>>?( SeqIter(T) & si, T && tp ) with( si ) { 252 if ( curr ) { 253 &tp = Curr( si ); 254 T * n = succ( *seq, Curr( si ) ); 255 curr = n == &head( *seq ) ? 0p : n; 256 } else &tp = 0p; 257 return &tp != 0p; 258 } 259 } // distribution 260 261 262 // A SeqIterRev(T) is used to iterate over a Sequence(T) in tail-to-head order. 263 struct SeqIterRev { 264 inline ColIter; 265 // See above for explanation. 266 Sequence(T) * seq; // FIX ME: cannot be reference 267 }; 268 269 static inline { 270 void ?{}( SeqIterRev(T) & si ) with( si ) { 271 ((ColIter &)si){}; 272 seq = 0p; 273 } // post: elts = null. 274 275 void ?{}( SeqIterRev(T) & si, Sequence(T) & s ) with( si ) { 276 ((ColIter &)si){}; 277 seq = &s; 278 curr = &tail( s ); 279 } // post: elts = null. 280 281 void ?{}( SeqIterRev(T) & si, Sequence(T) & s, T & start ) with( si ) { 282 ((ColIter &)si){}; 283 seq = &s; 284 curr = &start; 285 } // post: elts = null. 286 287 void over( SeqIterRev(T) & si, Sequence(T) & s ) with( si ) { 288 seq = &s; 289 curr = &tail( s ); 290 } // post: elts = {e in s}. 291 292 bool ?>>?( SeqIterRev(T) & si, T && tp ) with( si ) { 293 if ( curr ) { 294 &tp = Curr( si ); 295 T * n = pred( *seq, Curr( si ) ); 296 curr = n == &tail( *seq ) ? 0p : n; 297 } else &tp = 0p; 298 return &tp != 0p; 299 } 300 } // distribution 301 } // distribution 302 302 303 303 #endif
Note: See TracChangeset
for help on using the changeset viewer.