Changeset 58870e6b
- Timestamp:
- Dec 7, 2020, 3:51:50 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- d6089ad
- Parents:
- e91a255
- Location:
- libcfa/src/bits
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/collection.hfa
re91a255 r58870e6b 30 30 // wrappers to make Collection have T 31 31 forall( dtype T ) { 32 T *& Next( T &n ) {33 return (T *)Next( (Colable *) &n );32 T *& Next( T * n ) { 33 return (T *)Next( (Colable *)n ); 34 34 } 35 35 -
libcfa/src/bits/queue.hfa
re91a255 r58870e6b 31 31 if ( ! listed( n ) ) abort( "(Queue &)%p.succ( %p ) : Node is not on a list.", &q, n ); 32 32 #endif // __CFA_DEBUG__ 33 return (Next( *n ) == n) ? 0p : Next( *n );33 return (Next( n ) == n) ? 0p : Next( n ); 34 34 } // post: n == tail() & succ(n) == 0 | n != tail() & *succ(n) in *q 35 35 … … 39 39 #endif // __CFA_DEBUG__ 40 40 if ( last ) { 41 Next( n ) = &head( q );41 Next( &n ) = &head( q ); 42 42 q.root = &n; 43 43 } else { 44 44 root = last = &n; 45 Next( n ) = &n;// last node points to itself45 Next( &n ) = &n; // last node points to itself 46 46 } 47 47 } … … 51 51 if ( listed( &n ) ) abort( "(Queue &)%p.addTail( %p ) : Node is already on another list.", &q, &n ); 52 52 #endif // __CFA_DEBUG__ 53 if ( last ) Next( *last ) = &n;53 if ( last ) Next( last ) = &n; 54 54 else root = &n; 55 55 last = &n; 56 Next( n ) = &n;// last node points to itself56 Next( &n ) = &n; // last node points to itself 57 57 } 58 58 … … 64 64 T & t = head( q ); 65 65 if ( root ) { 66 root = Next( *root );66 root = Next( root ); 67 67 if ( &head( q ) == &t ) { 68 68 root = last = 0p; // only one element 69 69 } 70 Next( t ) = 0p;70 Next( &t ) = 0p; 71 71 } 72 72 return t; … … 81 81 if ( ! listed( (Colable &)n ) ) abort( "(Queue &)%p.remove( %p ) : Node is not on a list.", &q, &n ); 82 82 #endif // __CFA_DEBUG__ 83 T & prev = *0p;84 T & curr = *(T *)root;83 T * prev = 0p; 84 T * curr = (T *)root; 85 85 for ( ;; ) { 86 if ( &n == &curr ) { // found => remove86 if ( &n == curr ) { // found => remove 87 87 if ( (T *)root == &n ) { 88 88 dropHead( q ); 89 89 } else if ( last == &n ) { 90 last = &prev;91 Next( *last ) = last;90 last = prev; 91 Next( last ) = last; 92 92 } else { 93 93 Next( prev ) = Next( curr ); 94 94 } 95 Next( n ) = 0p;95 Next( &n ) = 0p; 96 96 break; 97 97 } 98 98 // not found => error 99 99 #ifdef __CFA_DEBUG__ 100 if ( &curr == last ) abort( "(Queue &)%p.remove( %p ) : Node is not in list.", &q, &n );100 if ( curr == last ) abort( "(Queue &)%p.remove( %p ) : Node is not in list.", &q, &n ); 101 101 #endif // __CFA_DEBUG__ 102 &prev = &curr;103 &curr = Next( curr );102 prev = curr; 103 curr = Next( curr ); 104 104 } 105 105 } // post: ! listed( n ) … … 116 116 root = from.root; 117 117 } else { // "to" list not empty 118 Next( *last ) = &head( from );118 Next( last ) = &head( from ); 119 119 } 120 120 last = from.last; … … 131 131 to.root = from.root; // start of "to" list 132 132 to.last = &n; // end of "to" list 133 from.root = Next( n ); // start of "from" list133 from.root = Next( &n ); // start of "from" list 134 134 if ( &n == &head( from ) ) { // last node in list ? 135 135 from.root = from.last = 0p; // mark "from" list empty 136 136 } else { 137 Next( n ) = &n;// fix end of "to" list137 Next( &n ) = &n; // fix end of "to" list 138 138 } 139 139 transfer( q, to ); … … 169 169 if ( curr ) { 170 170 &tp = Curr( qi ); 171 T * n = Next( *Curr( qi ) );171 T * n = Next( Curr( qi ) ); 172 172 curr = (n == Curr( qi ) ) ? 0p : n; 173 173 } else &tp = 0p; -
libcfa/src/bits/sequence.hfa
re91a255 r58870e6b 12 12 13 13 void ?{}( Seqable & sq ) with( sq ) { 14 ((Colable &) 14 ((Colable &)sq){}; 15 15 back = 0p; 16 16 } // post: ! listed() … … 28 28 // wrappers to make Collection have T 29 29 forall( dtype T ) { 30 T *& Back( T &n ) {31 return (T *)Back( (Seqable *) &n );30 T *& Back( T * n ) { 31 return (T *)Back( (Seqable *)n ); 32 32 } 33 33 } // distribution … … 49 49 50 50 void ?{}( Sequence(T) & s ) with( s ) { 51 ((Collection &) 51 ((Collection &)s){}; 52 52 } // post: isEmpty(). 53 53 54 54 // Return a pointer to the last sequence element, without removing it. 55 55 T & tail( Sequence(T) & s ) with( s ) { 56 return root ? (T &)*Back( head( s ) ) : *0p;56 return root ? (T &)*Back( &head( s ) ) : *0p; 57 57 } // post: empty() & tail() == 0 | !empty() & tail() in *s 58 58 … … 62 62 if ( ! listed( n ) ) abort( "(Sequence &)%p.succ( %p ) : Node is not on a list.", &s, n ); 63 63 #endif // __CFA_DEBUG__ 64 return Next( *n ) == &head( s ) ? 0p : Next( *n );64 return Next( n ) == &head( s ) ? 0p : Next( n ); 65 65 } // post: n == tail() & succ(n) == 0 | n != tail() & *succ(n) in *s 66 66 … … 70 70 if ( ! listed( n ) ) abort( "(Sequence &)%p.pred( %p ) : Node is not on a list.", &s, n ); 71 71 #endif // __CFA_DEBUG__ 72 return n == &head( s ) ? 0p : Back( *n );72 return n == &head( s ) ? 0p : Back( n ); 73 73 } // post: n == head() & head(n) == 0 | n != head() & *pred(n) in *s 74 74 … … 81 81 if ( &bef == &head( s ) ) { // must change root 82 82 if ( root ) { 83 Next( n ) = &head( s );84 Back( n ) = Back(head( s ) );83 Next( &n ) = &head( s ); 84 Back( &n ) = Back( &head( s ) ); 85 85 // inserted node must be consistent before it is seen 86 86 asm( "" : : : "memory" ); // prevent code movement across barrier 87 Back( head( s ) ) = &n;88 Next( *Back(n ) ) = &n;87 Back( &head( s ) ) = &n; 88 Next( Back( &n ) ) = &n; 89 89 } else { 90 Next( n ) = &n;91 Back( n ) = &n;90 Next( &n ) = &n; 91 Back( &n ) = &n; 92 92 } // if 93 93 // inserted node must be consistent before it is seen … … 96 96 } else { 97 97 if ( ! &bef ) &bef = &head( s ); 98 Next( n ) = &bef;99 Back( n ) = Back(bef );98 Next( &n ) = &bef; 99 Back( &n ) = Back( &bef ); 100 100 // inserted node must be consistent before it is seen 101 101 asm( "" : : : "memory" ); // prevent code movement across barrier 102 Back( bef ) = &n;103 Next( *Back(n ) ) = &n;102 Back( &bef ) = &n; 103 Next( Back( &n ) ) = &n; 104 104 } // if 105 105 } // post: n->listed() & *n in *s & succ(n) == bef … … 113 113 if ( ! &aft ) { // must change root 114 114 if ( root ) { 115 Next( n ) = &head( s );116 Back( n ) = Back(head( s ) );115 Next( &n ) = &head( s ); 116 Back( &n ) = Back( &head( s ) ); 117 117 // inserted node must be consistent before it is seen 118 118 asm( "" : : : "memory" ); // prevent code movement across barrier 119 Back( head( s ) ) = &n;120 Next( *Back(n ) ) = &n;119 Back( &head( s ) ) = &n; 120 Next( Back( &n ) ) = &n; 121 121 } else { 122 Next( n ) = &n;123 Back( n ) = &n;122 Next( &n ) = &n; 123 Back( &n ) = &n; 124 124 } // if 125 125 asm( "" : : : "memory" ); // prevent code movement across barrier 126 126 root = &n; 127 127 } else { 128 Next( n ) = Next(aft );129 Back( n ) = &aft;128 Next( &n ) = Next( &aft ); 129 Back( &n ) = &aft; 130 130 // inserted node must be consistent before it is seen 131 131 asm( "" : : : "memory" ); // prevent code movement across barrier 132 Back( *Next(n ) ) = &n;133 Next( aft ) = &n;132 Back( Next( &n ) ) = &n; 133 Next( &aft ) = &n; 134 134 } // if 135 135 } // post: n->listed() & *n in *s & succ(n) == bef … … 141 141 #endif // __CFA_DEBUG__ 142 142 if ( &n == &head( s ) ) { 143 if ( Next( head( s ) ) == &head( s ) ) root = 0p;144 else root = Next( head( s ) );145 } // if 146 Back( *Next( n ) ) = Back(n );147 Next( *Back( n ) ) = Next(n );148 Next( n ) = Back(n ) = 0p;143 if ( Next( &head( s ) ) == &head( s ) ) root = 0p; 144 else root = Next( &head( s ) ); 145 } // if 146 Back( Next( &n ) ) = Back( &n ); 147 Next( Back( &n ) ) = Next( &n ); 148 Next( &n ) = Back( &n ) = 0p; 149 149 } // post: !n->listed(). 150 150 … … 182 182 root = from.root; 183 183 } else { // "to" list not empty 184 T * toEnd = Back( head( s ) );185 T * fromEnd = Back( head( from ) );186 Back( *root ) = fromEnd;187 Next( *fromEnd ) = &head( s );188 Back( *from.root ) = toEnd;189 Next( *toEnd ) = &head( from );184 T * toEnd = Back( &head( s ) ); 185 T * fromEnd = Back( &head( from ) ); 186 Back( root ) = fromEnd; 187 Next( fromEnd ) = &head( s ); 188 Back( from.root ) = toEnd; 189 Next( toEnd ) = &head( from ); 190 190 } // if 191 191 from.root = 0p; // mark "from" list empty … … 200 200 Sequence(T) to; 201 201 to.root = from.root; // start of "to" list 202 from.root = Next( n ); // start of "from" list202 from.root = Next( &n ); // start of "from" list 203 203 if ( to.root == from.root ) { // last node in list ? 204 204 from.root = 0p; // mark "from" list empty 205 205 } else { 206 Back( head( from ) ) = Back(head( to ) ); // fix "from" list207 Next( *Back(head( to ) ) ) = &head( from );208 Next( n ) = &head( to ); // fix "to" list209 Back( head( to ) ) = &n;206 Back( &head( from ) ) = Back( &head( to ) ); // fix "from" list 207 Next( Back( &head( to ) ) ) = &head( from ); 208 Next( &n ) = &head( to ); // fix "to" list 209 Back( &head( to ) ) = &n; 210 210 } // if 211 211 transfer( s, to ); … … 231 231 232 232 void ?{}( SeqIter(T) & si, Sequence(T) & s ) with( si ) { 233 ((ColIter &) 233 ((ColIter &)si){}; 234 234 seq = &s; 235 235 curr = &head( s ); … … 237 237 238 238 void ?{}( SeqIter(T) & si, Sequence(T) & s, T & start ) with( si ) { 239 ((ColIter &) 239 ((ColIter &)si){}; 240 240 seq = &s; 241 241 curr = &start; … … 267 267 inline { 268 268 void ?{}( SeqIterRev(T) & si ) with( si ) { 269 ((ColIter &) 269 ((ColIter &)si){}; 270 270 seq = 0p; 271 271 } // post: elts = null. 272 272 273 273 void ?{}( SeqIterRev(T) & si, Sequence(T) & s ) with( si ) { 274 ((ColIter &) 274 ((ColIter &)si){}; 275 275 seq = &s; 276 276 curr = &tail( s ); … … 278 278 279 279 void ?{}( SeqIterRev(T) & si, Sequence(T) & s, T & start ) with( si ) { 280 ((ColIter &) 280 ((ColIter &)si){}; 281 281 seq = &s; 282 282 curr = &start; -
libcfa/src/bits/stack.hfa
re91a255 r58870e6b 29 29 if ( listed( (Colable &)(n) ) ) abort( "(Stack &)%p.addHead( %p ) : Node is already on another list.", &s, n ); 30 30 #endif // __CFA_DEBUG__ 31 Next( n ) = &head( s ) ? &head( s ) : &n;31 Next( &n ) = &head( s ) ? &head( s ) : &n; 32 32 root = &n; 33 33 } … … 44 44 T & t = head( s ); 45 45 if ( root ) { 46 root = ( T *)Next( *root );46 root = ( T *)Next( root ); 47 47 if ( &head( s ) == &t ) root = 0p; // only one element ? 48 Next( t ) = 0p;48 Next( &t ) = 0p; 49 49 } // if 50 50 return t; … … 85 85 if ( curr ) { 86 86 &tp = Curr( si ); 87 T * n = Next( *Curr( si ) );87 T * n = Next( Curr( si ) ); 88 88 curr = n == Curr( si ) ? 0p : n; 89 89 } else &tp = 0p;
Note: See TracChangeset
for help on using the changeset viewer.