Ignore:
Timestamp:
Dec 10, 2020, 4:00:29 PM (3 years ago)
Author:
Fangren Yu <f37yu@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
97aca3d, b3a0df6
Parents:
6a45bd78 (diff), 297cf18 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/bits/sequence.hfa

    r6a45bd78 r3e3f236  
    11#pragma once
    22
    3 #include "collection.hfa"
     3#include "bits/collection.hfa"
    44
    55struct Seqable {
     
    99
    1010inline {
     11        // PUBLIC
     12
    1113        void ?{}( Seqable & sq ) with( sq ) {
    12                 ((Colable &) sq){};
     14                ((Colable &)sq){};
    1315                back = 0p;
    1416        } // post: ! listed()
     
    1820        }
    1921
     22        // PRIVATE
     23
    2024        Seqable *& Back( Seqable * sq ) {
    2125                return sq->back;
    2226        }
     27
     28        // wrappers to make Collection have T
     29        forall( dtype T ) {
     30                T *& Back( T * n ) {
     31                        return (T *)Back( (Seqable *)n );
     32                }
     33        } // distribution
    2334} // distribution
    2435
     
    3445                } // post: empty() & head() == 0 | !empty() & head() in *s
    3546
    36                 T *& Back( T * n ) {
    37                         return (T *)Back( (Seqable *)n );
    38                 }
    39 
    4047                void ?{}( Sequence(T) &, const Sequence(T) & ) = void; // no copy
    4148                Sequence(T) & ?=?( const Sequence(T) & ) = void; // no assignment
    4249
    4350                void ?{}( Sequence(T) & s ) with( s ) {
    44                         ((Collection &) s){};
     51                        ((Collection &)s){};
    4552                }       // post: isEmpty().
    4653
     
    5057                }       // post: empty() & tail() == 0 | !empty() & tail() in *s
    5158
    52                 // Return a pointer to the element after *n, or 0p if there isn't one.
     59                // Return a pointer to the element after *n, or 0p if list empty.
    5360                T * succ( Sequence(T) & s, T * n ) with( s ) {  // pre: *n in *s
    54 #ifdef __CFA_DEBUG__
     61                        #ifdef __CFA_DEBUG__
    5562                        if ( ! listed( n ) ) abort( "(Sequence &)%p.succ( %p ) : Node is not on a list.", &s, n );
    56 #endif // __CFA_DEBUG__
     63                        #endif // __CFA_DEBUG__
    5764                        return Next( n ) == &head( s ) ? 0p : Next( n );
    5865                } // post: n == tail() & succ(n) == 0 | n != tail() & *succ(n) in *s
     
    6067                // Return a pointer to the element before *n, or 0p if there isn't one.
    6168                T * pred( Sequence(T) & s, T * n ) with( s ) {  // pre: *n in *s
    62 #ifdef __CFA_DEBUG__
     69                        #ifdef __CFA_DEBUG__
    6370                        if ( ! listed( n ) ) abort( "(Sequence &)%p.pred( %p ) : Node is not on a list.", &s, n );
    64 #endif // __CFA_DEBUG__
     71                        #endif // __CFA_DEBUG__
    6572                        return n == &head( s ) ? 0p : Back( n );
    6673                }       // post: n == head() & head(n) == 0 | n != head() & *pred(n) in *s
     
    6976                // Insert *n into the sequence before *bef, or at the end if bef == 0.
    7077                void insertBef( Sequence(T) & s, T & n, T & bef ) with( s ) { // pre: !n->listed() & *bef in *s
    71 #ifdef __CFA_DEBUG__
     78                        #ifdef __CFA_DEBUG__
    7279                        if ( listed( &n ) ) abort( "(Sequence &)%p.insertBef( %p, %p ) : Node is already on another list.", &s, n, &bef );
    73 #endif // __CFA_DEBUG__
     80                        #endif // __CFA_DEBUG__
    7481                        if ( &bef == &head( s ) ) {                                     // must change root
    7582                                if ( root ) {
     
    101108                // Insert *n into the sequence after *aft, or at the beginning if aft == 0.
    102109                void insertAft( Sequence(T) & s, T & aft, T & n ) with( s ) {   // pre: !n->listed() & *aft in *s
    103 #ifdef __CFA_DEBUG__
     110                        #ifdef __CFA_DEBUG__
    104111                        if ( listed( &n ) ) abort( "(Sequence &)%p.insertAft( %p, %p ) : Node is already on another list.", &s, &aft, &n );
    105 #endif // __CFA_DEBUG__
     112                        #endif // __CFA_DEBUG__
    106113                        if ( ! &aft ) {                                                         // must change root
    107114                                if ( root ) {
     
    130137                // pre: n->listed() & *n in *s
    131138                void remove( Sequence(T) & s, T & n ) with( s ) { // O(1)
    132 #ifdef __CFA_DEBUG__
     139                        #ifdef __CFA_DEBUG__
    133140                        if ( ! listed( &n ) ) abort( "(Sequence &)%p.remove( %p ) : Node is not on a list.", &s, &n );
    134 #endif // __CFA_DEBUG__
     141                        #endif // __CFA_DEBUG__
    135142                        if ( &n == &head( s ) ) {
    136143                                if ( Next( &head( s ) ) == &head( s ) ) root = 0p;
     
    188195                // Node "n" must be in the "from" list.
    189196                void split( Sequence(T) & s, Sequence(T) & from, T & n ) with( s ) {
    190 #ifdef __CFA_DEBUG__
     197                        #ifdef __CFA_DEBUG__
    191198                        if ( ! listed( &n ) ) abort( "(Sequence &)%p.split( %p ) : Node is not on a list.", &s, &n );
    192 #endif // __CFA_DEBUG__
     199                        #endif // __CFA_DEBUG__
    193200                        Sequence(T) to;
    194201                        to.root = from.root;                                            // start of "to" list
     
    199206                                Back( &head( from ) ) = Back( &head( to ) ); // fix "from" list
    200207                                Next( Back( &head( to ) ) ) = &head( from );
    201                                 Next( &n ) = &head( to );                                       // fix "to" list
     208                                Next( &n ) = &head( to );                               // fix "to" list
    202209                                Back( &head( to ) ) = &n;
    203210                        } // if
     
    214221                // passing the sequence, traversing would require its length. Thus the iterator needs a pointer to the sequence
    215222                // to pass to succ/pred. Both stack and queue just encounter 0p since the lists are not circular.
    216                 Sequence(T) * seq;
     223                Sequence(T) * seq;                                                              // FIX ME: cannot be reference
    217224        };
    218225
     
    224231
    225232                void ?{}( SeqIter(T) & si, Sequence(T) & s ) with( si ) {
    226                         ((ColIter &) si){};
     233                        ((ColIter &)si){};
    227234                        seq = &s;
    228235                        curr = &head( s );
     
    230237
    231238                void ?{}( SeqIter(T) & si, Sequence(T) & s, T & start ) with( si ) {
    232                         ((ColIter &) si){};
     239                        ((ColIter &)si){};
    233240                        seq = &s;
    234241                        curr = &start;
     
    255262                inline ColIter;
    256263                // See above for explanation.
    257                 Sequence(T) * seq;
     264                Sequence(T) * seq;                                                              // FIX ME: cannot be reference
    258265        };
    259266
    260267        inline {
    261268                void ?{}( SeqIterRev(T) & si ) with( si ) {     
    262                         ((ColIter &) si){};
     269                        ((ColIter &)si){};
    263270                        seq = 0p;
    264271                } // post: elts = null.
    265272
    266273                void ?{}( SeqIterRev(T) & si, Sequence(T) & s ) with( si ) {   
    267                         ((ColIter &) si){};
     274                        ((ColIter &)si){};
    268275                        seq = &s;
    269276                        curr = &tail( s );
     
    271278
    272279                void ?{}( SeqIterRev(T) & si, Sequence(T) & s, T & start ) with( si ) {
    273                         ((ColIter &) si){};
     280                        ((ColIter &)si){};
    274281                        seq = &s;
    275282                        curr = &start;
     
    291298        } // distribution
    292299} // distribution
    293 
    294 // Local Variables: //
    295 // compile-command: "cfa sequence.hfa" //
    296 // End: //
Note: See TracChangeset for help on using the changeset viewer.