Changeset 7c1144b


Ignore:
Timestamp:
Dec 5, 2020, 8:48:32 AM (3 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
ec5d599
Parents:
a32cbac2
Message:

formatting, more switch from pointer to reference

Location:
libcfa/src/bits
Files:
8 edited

Legend:

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

    ra32cbac2 r7c1144b  
    77
    88inline {
     9        // PUBLIC
     10
    911        void ?{}( Colable & co ) with( co ) {
    1012                next = 0p;
     
    1618        }
    1719
    18         Colable * getNext( Colable & co ) with( co ) {
    19                 return next;
     20        Colable & getNext( Colable & co ) with( co ) {
     21                return *next;
    2022        }
     23
     24        // PRIVATE
    2125
    2226        Colable *& Next( Colable * cp ) {
     
    2428        }
    2529
     30        // wrappers to make Collection have T
    2631        forall( dtype T ) {
    27                 T *& Next( T * n ) {
    28                         return (T *)Next( (Colable *)n );
     32                T *& Next( T & n ) {
     33                        return (T *)Next( (Colable *)&n );
    2934                }
    3035
  • libcfa/src/bits/multi_list.cfa

    ra32cbac2 r7c1144b  
    5757
    5858        SeqIter(TaskDL) sqiter;
    59         TaskDL & dl;
     59        TaskDL & dl;                                                                            // iterator index
    6060        TaskSL & sl;
    6161
  • libcfa/src/bits/queue.hfa

    ra32cbac2 r7c1144b  
    2828
    2929                T * succ( Queue(T) & q, T * n ) with( q ) {             // pre: *n in *q
    30 #ifdef __CFA_DEBUG__
     30                        #ifdef __CFA_DEBUG__
    3131                        if ( ! listed( n ) ) abort( "(Queue &)%p.succ( %p ) : Node is not on a list.", &q, n );
    32 #endif // __CFA_DEBUG__
    33                         return (Next( n ) == n) ? 0p : Next( n );
     32                        #endif // __CFA_DEBUG__
     33                        return (Next( *n ) == n) ? 0p : Next( *n );
    3434                } // post: n == tail() & succ(n) == 0 | n != tail() & *succ(n) in *q
    3535
    3636                void addHead( Queue(T) & q, T & n ) with( q ) {
    37 #ifdef __CFA_DEBUG__
     37                        #ifdef __CFA_DEBUG__
    3838                        if ( listed( &n ) ) abort( "(Queue &)%p.addHead( %p ) : Node is already on another list.", &q, &n );
    39 #endif // __CFA_DEBUG__
     39                        #endif // __CFA_DEBUG__
    4040                        if ( last ) {
    41                                 Next( &n ) = &head( q );
     41                                Next( n ) = &head( q );
    4242                                q.root = &n;
    4343                        } else {
    4444                                root = last = &n;
    45                                 Next( &n ) = &n;                                                        // last node points to itself
     45                                Next( n ) = &n;                                                 // last node points to itself
    4646                        }
    4747                }
    4848
    4949                void addTail( Queue(T) & q, T & n ) with( q ) {
    50 #ifdef __CFA_DEBUG__
     50                        #ifdef __CFA_DEBUG__
    5151                        if ( listed( &n ) ) abort( "(Queue &)%p.addTail( %p ) : Node is already on another list.", &q, &n );
    52 #endif // __CFA_DEBUG__
    53                         if ( last ) Next( last ) = &n;
     52                        #endif // __CFA_DEBUG__
     53                        if ( last ) Next( *last ) = &n;
    5454                        else root = &n;
    5555                        last = &n;
    56                         Next( &n ) = &n;                                                                // last node points to itself
     56                        Next( n ) = &n;                                                         // last node points to itself
    5757                }
    5858
     
    6464                        T & t = head( q );
    6565                        if ( root ) {
    66                                 root = Next( root );
     66                                root = Next( *root );
    6767                                if ( &head( q ) == &t ) {
    6868                                        root = last = 0p;                                       // only one element
    6969                                }
    70                                 Next( &t ) = 0p;
     70                                Next( t ) = 0p;
    7171                        }
    7272                        return t;
     
    7878
    7979                void remove( Queue(T) & q, T & n ) with( q ) {  // O(n)
    80 #ifdef __CFA_DEBUG__
     80                        #ifdef __CFA_DEBUG__
    8181                        if ( ! listed( (Colable &)n ) ) abort( "(Queue &)%p.remove( %p ) : Node is not on a list.", &q, &n );
    82 #endif // __CFA_DEBUG__
    83                         T * prev = 0p;
    84                         T * curr = (T *)root;
     82                        #endif // __CFA_DEBUG__
     83                        T & prev = *0p;
     84                        T & curr = *(T *)root;
    8585                        for ( ;; ) {
    86                                 if ( &n == curr ) {                                             // found => remove
     86                                if ( &n == &curr ) {                                            // found => remove
    8787                                        if ( (T *)root == &n ) {
    8888                                                dropHead( q );
    8989                                        } else if ( last == &n ) {
    90                                                 last = prev;
    91                                                 Next( last ) = last;
     90                                                last = &prev;
     91                                                Next( *last ) = last;
    9292                                        } else {
    9393                                                Next( prev ) = Next( curr );
    9494                                        }
    95                                         Next( &n ) = 0p;
     95                                        Next( n ) = 0p;
    9696                                        break;
    9797                                }
    98 #ifdef __CFA_DEBUG__
    9998                                // not found => error
    100                                 if (curr == last) abort( "(Queue &)%p.remove( %p ) : Node is not in list.", &q, &n );
    101 #endif // __CFA_DEBUG__
    102                                 prev = curr;
    103                                 curr = Next( curr );
     99                                #ifdef __CFA_DEBUG__
     100                                if ( &curr == last ) abort( "(Queue &)%p.remove( %p ) : Node is not in list.", &q, &n );
     101                                #endif // __CFA_DEBUG__
     102                                &prev = &curr;
     103                                &curr = Next( curr );
    104104                        }
    105105                } // post: ! listed( n )
     
    116116                                root = from.root;
    117117                        } else {                                                                        // "to" list not empty
    118                                 Next( last ) = &head( from );
     118                                Next( *last ) = &head( from );
    119119                        }
    120120                        last = from.last;
     
    125125                // Node "n" must be in the "from" list.
    126126                void split( Queue(T) & q, Queue(T) & from, T & n ) with( q ) {
    127 #ifdef __CFA_DEBUG__
     127                        #ifdef __CFA_DEBUG__
    128128                        if ( ! listed( (Colable &)n ) ) abort( "(Queue &)%p.split( %p ) : Node is not on a list.", &q, &n );
    129 #endif // __CFA_DEBUG__
     129                        #endif // __CFA_DEBUG__
    130130                        Queue(T) to;
    131131                        to.root = from.root;                                            // start of "to" list
    132132                        to.last = &n;                                                           // end of "to" list
    133                         from.root = Next( &n );                                         // start of "from" list
     133                        from.root = Next( n );                                          // start of "from" list
    134134                        if ( &n == &head( from ) ) {                            // last node in list ?
    135135                                from.root = from.last = 0p;                             // mark "from" list empty
    136136                        } else {
    137                                 Next( &n ) = &n;                                                // fix end of "to" list
     137                                Next( n ) = &n;                                                 // fix end of "to" list
    138138                        }
    139139                        transfer( q, to );
     
    169169                        if ( curr ) {
    170170                                &tp = Curr( qi );
    171                                 T * n = Next( Curr( qi ) );
     171                                T * n = Next( *Curr( qi ) );
    172172                                curr = (n == Curr( qi ) ) ? 0p : n;
    173173                        } else &tp = 0p;
     
    177177        } // distribution
    178178} // distribution
    179 
    180 // Local Variables: //
    181 // compile-command: "cfa queue.cfa" //
    182 // End: //
  • libcfa/src/bits/queue_example.cfa

    ra32cbac2 r7c1144b  
    107107        }
    108108}
    109 
    110 // Local Variables: //
    111 // compile-command: "cfa queue_example.cfa" //
    112 // End: //
  • libcfa/src/bits/sequence.hfa

    ra32cbac2 r7c1144b  
    99
    1010inline {
     11        // PUBLIC
     12
    1113        void ?{}( Seqable & sq ) with( sq ) {
    1214                ((Colable &) sq){};
     
    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
     34                T & head( Sequence(T) & s ) with( s ) {
     35                        return *(T *)head( (Collection &)s );
     36                } // post: empty() & head() == 0 | !empty() & head() in *s
     37        } // distribution
    2338} // distribution
    2439
     
    2944
    3045        inline {
    31                 // wrappers to make Collection have T
    32                 T & head( Sequence(T) & s ) with( s ) {
    33                         return *(T *)head( (Collection &)s );
    34                 } // post: empty() & head() == 0 | !empty() & head() in *s
    35 
    36                 T *& Back( T * n ) {
    37                         return (T *)Back( (Seqable *)n );
    38                 }
    39 
    4046                void ?{}( Sequence(T) &, const Sequence(T) & ) = void; // no copy
    4147                Sequence(T) & ?=?( const Sequence(T) & ) = void; // no assignment
     
    4753                // Return a pointer to the last sequence element, without removing it. 
    4854                T & tail( Sequence(T) & s ) with( s ) {
    49                         return root ? (T &)*Back( &head( s ) ) : *0p;
     55                        return root ? (T &)*Back( head( s ) ) : *0p;
    5056                }       // post: empty() & tail() == 0 | !empty() & tail() in *s
    5157
    52                 // Return a pointer to the element after *n, or 0p if there isn't one.
     58                // Return a pointer to the element after *n, or 0p if list empty.
    5359                T * succ( Sequence(T) & s, T * n ) with( s ) {  // pre: *n in *s
    54 #ifdef __CFA_DEBUG__
     60                        #ifdef __CFA_DEBUG__
    5561                        if ( ! listed( n ) ) abort( "(Sequence &)%p.succ( %p ) : Node is not on a list.", &s, n );
    56 #endif // __CFA_DEBUG__
    57                         return Next( n ) == &head( s ) ? 0p : Next( n );
     62                        #endif // __CFA_DEBUG__
     63                        return Next( *n ) == &head( s ) ? 0p : Next( *n );
    5864                } // post: n == tail() & succ(n) == 0 | n != tail() & *succ(n) in *s
    5965
    6066                // Return a pointer to the element before *n, or 0p if there isn't one.
    6167                T * pred( Sequence(T) & s, T * n ) with( s ) {  // pre: *n in *s
    62 #ifdef __CFA_DEBUG__
     68                        #ifdef __CFA_DEBUG__
    6369                        if ( ! listed( n ) ) abort( "(Sequence &)%p.pred( %p ) : Node is not on a list.", &s, n );
    64 #endif // __CFA_DEBUG__
    65                         return n == &head( s ) ? 0p : Back( n );
     70                        #endif // __CFA_DEBUG__
     71                        return n == &head( s ) ? 0p : Back( *n );
    6672                }       // post: n == head() & head(n) == 0 | n != head() & *pred(n) in *s
    6773
     
    6975                // Insert *n into the sequence before *bef, or at the end if bef == 0.
    7076                void insertBef( Sequence(T) & s, T & n, T & bef ) with( s ) { // pre: !n->listed() & *bef in *s
    71 #ifdef __CFA_DEBUG__
     77                        #ifdef __CFA_DEBUG__
    7278                        if ( listed( &n ) ) abort( "(Sequence &)%p.insertBef( %p, %p ) : Node is already on another list.", &s, n, &bef );
    73 #endif // __CFA_DEBUG__
     79                        #endif // __CFA_DEBUG__
    7480                        if ( &bef == &head( s ) ) {                                     // must change root
    7581                                if ( root ) {
    76                                         Next( &n ) = &head( s );
    77                                         Back( &n ) = Back( &head( s ) );
     82                                        Next( n ) = &head( s );
     83                                        Back( n ) = Back( head( s ) );
    7884                                        // inserted node must be consistent before it is seen
    7985                                        asm( "" : : : "memory" );                       // prevent code movement across barrier
    80                                         Back( &head( s ) ) = &n;
    81                                         Next( Back( &n ) ) = &n;
     86                                        Back( head( s ) ) = &n;
     87                                        Next( *Back( n ) ) = &n;
    8288                                } else {
    83                                         Next( &n ) = &n;
    84                                         Back( &n ) = &n;
     89                                        Next( n ) = &n;
     90                                        Back( n ) = &n;
    8591                                } // if
    8692                                // inserted node must be consistent before it is seen
     
    8995                        } else {
    9096                                if ( ! &bef ) &bef = &head( s );
    91                                 Next( &n ) = &bef;
    92                                 Back( &n ) = Back( &bef );
     97                                Next( n ) = &bef;
     98                                Back( n ) = Back( bef );
    9399                                // inserted node must be consistent before it is seen
    94100                                asm( "" : : : "memory" );                               // prevent code movement across barrier
    95                                 Back( &bef ) = &n;
    96                                 Next( Back( &n ) ) = &n;
     101                                Back( bef ) = &n;
     102                                Next( *Back( n ) ) = &n;
    97103                        } // if
    98104                }       // post: n->listed() & *n in *s & succ(n) == bef
     
    101107                // Insert *n into the sequence after *aft, or at the beginning if aft == 0.
    102108                void insertAft( Sequence(T) & s, T & aft, T & n ) with( s ) {   // pre: !n->listed() & *aft in *s
    103 #ifdef __CFA_DEBUG__
     109                        #ifdef __CFA_DEBUG__
    104110                        if ( listed( &n ) ) abort( "(Sequence &)%p.insertAft( %p, %p ) : Node is already on another list.", &s, &aft, &n );
    105 #endif // __CFA_DEBUG__
     111                        #endif // __CFA_DEBUG__
    106112                        if ( ! &aft ) {                                                         // must change root
    107113                                if ( root ) {
    108                                         Next( &n ) = &head( s );
    109                                         Back( &n ) = Back( &head( s ) );
     114                                        Next( n ) = &head( s );
     115                                        Back( n ) = Back( head( s ) );
    110116                                        // inserted node must be consistent before it is seen
    111117                                        asm( "" : : : "memory" );                       // prevent code movement across barrier
    112                                         Back( &head( s ) ) = &n;
    113                                         Next( Back( &n ) ) = &n;
     118                                        Back( head( s ) ) = &n;
     119                                        Next( *Back( n ) ) = &n;
    114120                                } else {
    115                                         Next( &n ) = &n;
    116                                         Back( &n ) = &n;
     121                                        Next( n ) = &n;
     122                                        Back( n ) = &n;
    117123                                } // if
    118124                                asm( "" : : : "memory" );                               // prevent code movement across barrier
    119125                                root = &n;
    120126                        } else {
    121                                 Next( &n ) = Next( &aft );
    122                                 Back( &n ) = &aft;
     127                                Next( n ) = Next( aft );
     128                                Back( n ) = &aft;
    123129                                // inserted node must be consistent before it is seen
    124130                                asm( "" : : : "memory" );                               // prevent code movement across barrier
    125                                 Back( Next( &n ) ) = &n;
    126                                 Next( &aft ) = &n;
     131                                Back( *Next( n ) ) = &n;
     132                                Next( aft ) = &n;
    127133                        } // if
    128134                }         // post: n->listed() & *n in *s & succ(n) == bef
     
    130136                // pre: n->listed() & *n in *s
    131137                void remove( Sequence(T) & s, T & n ) with( s ) { // O(1)
    132 #ifdef __CFA_DEBUG__
     138                        #ifdef __CFA_DEBUG__
    133139                        if ( ! listed( &n ) ) abort( "(Sequence &)%p.remove( %p ) : Node is not on a list.", &s, &n );
    134 #endif // __CFA_DEBUG__
     140                        #endif // __CFA_DEBUG__
    135141                        if ( &n == &head( s ) ) {
    136                                 if ( Next( &head( s ) ) == &head( s ) ) root = 0p;
    137                                 else root = Next( &head( s ) );
    138                         } // if
    139                         Back( Next( &n ) ) = Back( &n );
    140                         Next( Back( &n ) ) = Next( &n );
    141                         Next( &n ) = Back( &n ) = 0p;
     142                                if ( Next( head( s ) ) == &head( s ) ) root = 0p;
     143                                else root = Next( head( s ) );
     144                        } // if
     145                        Back( *Next( n ) ) = Back( n );
     146                        Next( *Back( n ) ) = Next( n );
     147                        Next( n ) = Back( n ) = 0p;
    142148                }                                                       // post: !n->listed().
    143149
     
    175181                                root = from.root;
    176182                        } else {                                                                        // "to" list not empty
    177                                 T * toEnd = Back( &head( s ) );
    178                                 T * fromEnd = Back( &head( from ) );
    179                                 Back( root ) = fromEnd;
    180                                 Next( fromEnd ) = &head( s );
    181                                 Back( from.root ) = toEnd;
    182                                 Next( toEnd ) = &head( from );
     183                                T * toEnd = Back( head( s ) );
     184                                T * fromEnd = Back( head( from ) );
     185                                Back( *root ) = fromEnd;
     186                                Next( *fromEnd ) = &head( s );
     187                                Back( *from.root ) = toEnd;
     188                                Next( *toEnd ) = &head( from );
    183189                        } // if
    184190                        from.root = 0p;                                                         // mark "from" list empty
     
    188194                // Node "n" must be in the "from" list.
    189195                void split( Sequence(T) & s, Sequence(T) & from, T & n ) with( s ) {
    190 #ifdef __CFA_DEBUG__
     196                        #ifdef __CFA_DEBUG__
    191197                        if ( ! listed( &n ) ) abort( "(Sequence &)%p.split( %p ) : Node is not on a list.", &s, &n );
    192 #endif // __CFA_DEBUG__
     198                        #endif // __CFA_DEBUG__
    193199                        Sequence(T) to;
    194200                        to.root = from.root;                                            // start of "to" list
    195                         from.root = Next( &n );                                         // start of "from" list
     201                        from.root = Next( n );                                          // start of "from" list
    196202                        if ( to.root == from.root ) {                           // last node in list ?
    197203                                from.root = 0p;                                                 // mark "from" list empty
    198204                        } else {
    199                                 Back( &head( from ) ) = Back( &head( to ) ); // fix "from" list
    200                                 Next( Back( &head( to ) ) ) = &head( from );
    201                                 Next( &n ) = &head( to );                                       // fix "to" list
    202                                 Back( &head( to ) ) = &n;
     205                                Back( head( from ) ) = Back( head( to ) ); // fix "from" list
     206                                Next( *Back( head( to ) ) ) = &head( from );
     207                                Next( n ) = &head( to );                                // fix "to" list
     208                                Back( head( to ) ) = &n;
    203209                        } // if
    204210                        transfer( s, to );
     
    214220                // passing the sequence, traversing would require its length. Thus the iterator needs a pointer to the sequence
    215221                // to pass to succ/pred. Both stack and queue just encounter 0p since the lists are not circular.
    216                 Sequence(T) * seq;
     222                Sequence(T) * seq;                                                              // FIX ME: cannot be reference
    217223        };
    218224
     
    255261                inline ColIter;
    256262                // See above for explanation.
    257                 Sequence(T) * seq;
     263                Sequence(T) * seq;                                                              // FIX ME: cannot be reference
    258264        };
    259265
     
    291297        } // distribution
    292298} // distribution
    293 
    294 // Local Variables: //
    295 // compile-command: "cfa sequence.hfa" //
    296 // End: //
  • libcfa/src/bits/sequence_example.cfa

    ra32cbac2 r7c1144b  
    137137        }
    138138}
    139 
    140 // Local Variables: //
    141 // compile-command: "cfa sequence_example.cfa" //
    142 // End: //
  • libcfa/src/bits/stack.hfa

    ra32cbac2 r7c1144b  
    2626
    2727                void addHead( Stack(T) & s, T & n ) with( s ) {
    28 #ifdef __CFA_DEBUG__
     28                        #ifdef __CFA_DEBUG__
    2929                        if ( listed( (Colable &)(n) ) ) abort( "(Stack &)%p.addHead( %p ) : Node is already on another list.", &s, n );
    30 #endif // __CFA_DEBUG__
    31                         Next( &n ) = &head( s ) ? &head( s ) : &n;
     30                        #endif // __CFA_DEBUG__
     31                        Next( n ) = &head( s ) ? &head( s ) : &n;
    3232                        root = &n;
    3333                }
     
    4444                        T & t = head( s );
    4545                        if ( root ) {
    46                                 root = ( T *)Next(root);
     46                                root = ( T *)Next( *root );
    4747                                if ( &head( s ) == &t ) root = 0p;              // only one element ?
    48                                 Next( &t ) = 0p;
     48                                Next( t ) = 0p;
    4949                        } // if
    5050                        return t;
     
    8585                        if ( curr ) {
    8686                                &tp = Curr( si );
    87                                 T * n = Next( Curr( si ) );
     87                                T * n = Next( *Curr( si ) );
    8888                                curr = n == Curr( si ) ? 0p : n;
    8989                        } else &tp = 0p;
     
    9292        } // distribution
    9393} // distribution
    94 
    95 // Local Variables: //
    96 // compile-command: "make install" //
    97 // End: //
  • libcfa/src/bits/stack_example.cfa

    ra32cbac2 r7c1144b  
    107107        }
    108108}
    109 
    110 // Local Variables: //
    111 // compile-command: "cfa stack_example.cfa" //
    112 // End: //
Note: See TracChangeset for help on using the changeset viewer.