Ignore:
Timestamp:
Jan 15, 2019, 4:16:15 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
c802eb88
Parents:
5e49e47 (diff), c9aba81 (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' into jenkins-sandbox

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/iostream.cfa

    r5e49e47 rd0c91a6  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Nov  2 07:17:05 2018
    13 // Update Count     : 474
     12// Last Modified On : Mon Dec 24 18:33:40 2018
     13// Update Count     : 589
    1414//
    1515
     
    1919#include <stdio.h>
    2020#include <stdbool.h>                                                                    // true/false
    21 //#include <string.h>                                                                           // strlen, strcmp
     21//#include <string.h>                                                                   // strlen, strcmp
    2222extern int strcmp (const char *__s1, const char *__s2) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
    2323extern size_t strlen (const char *__s) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
     
    3232                return os;
    3333        } // ?|?
    34 
    35         ostype & ?|?( ostype & os, char ch ) {
    36                 fmt( os, "%c", ch );
    37                 if ( ch == '\n' ) setNL( os, true );
    38                 sepOff( os );
    39                 return os;
    40         } // ?|?
    41 
    42         ostype & ?|?( ostype & os, signed char c ) {
    43                 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    44                 fmt( os, "%hhd", c );
    45                 return os;
    46         } // ?|?
    47 
    48         ostype & ?|?( ostype & os, unsigned char c ) {
    49                 if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
    50                 fmt( os, "%hhu", c );
    51                 return os;
     34        void ?|?( ostype & os, bool b ) {
     35                (ostype &)(os | b); nl( os );
     36        } // ?|?
     37
     38        ostype & ?|?( ostype & os, char c ) {
     39                fmt( os, "%c", c );
     40                if ( c == '\n' ) setNL( os, true );
     41                return sepOff( os );
     42        } // ?|?
     43        void ?|?( ostype & os, char c ) {
     44                (ostype &)(os | c); nl( os );
     45        } // ?|?
     46
     47        ostype & ?|?( ostype & os, signed char sc ) {
     48                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     49                fmt( os, "%hhd", sc );
     50                return os;
     51        } // ?|?
     52        void ?|?( ostype & os, signed char sc ) {
     53                (ostype &)(os | sc); nl( os );
     54        } // ?|?
     55
     56        ostype & ?|?( ostype & os, unsigned char usc ) {
     57                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     58                fmt( os, "%hhu", usc );
     59                return os;
     60        } // ?|?
     61        void ?|?( ostype & os, unsigned char usc ) {
     62                (ostype &)(os | usc); nl( os );
    5263        } // ?|?
    5364
     
    5768                return os;
    5869        } // ?|?
     70        void & ?|?( ostype & os, short int si ) {
     71                (ostype &)(os | si); nl( os );
     72        } // ?|?
    5973
    6074        ostype & ?|?( ostype & os, unsigned short int usi ) {
     
    6377                return os;
    6478        } // ?|?
     79        void & ?|?( ostype & os, unsigned short int usi ) {
     80                (ostype &)(os | usi); nl( os );
     81        } // ?|?
    6582
    6683        ostype & ?|?( ostype & os, int i ) {
     
    6986                return os;
    7087        } // ?|?
     88        void & ?|?( ostype & os, int i ) {
     89                (ostype &)(os | i); nl( os );
     90        } // ?|?
    7191
    7292        ostype & ?|?( ostype & os, unsigned int ui ) {
     
    7595                return os;
    7696        } // ?|?
     97        void & ?|?( ostype & os, unsigned int ui ) {
     98                (ostype &)(os | ui); nl( os );
     99        } // ?|?
    77100
    78101        ostype & ?|?( ostype & os, long int li ) {
     
    81104                return os;
    82105        } // ?|?
     106        void & ?|?( ostype & os, long int li ) {
     107                (ostype &)(os | li); nl( os );
     108        } // ?|?
    83109
    84110        ostype & ?|?( ostype & os, unsigned long int uli ) {
     
    87113                return os;
    88114        } // ?|?
     115        void & ?|?( ostype & os, unsigned long int uli ) {
     116                (ostype &)(os | uli); nl( os );
     117        } // ?|?
    89118
    90119        ostype & ?|?( ostype & os, long long int lli ) {
     
    93122                return os;
    94123        } // ?|?
     124        void & ?|?( ostype & os, long long int lli ) {
     125                (ostype &)(os | lli); nl( os );
     126        } // ?|?
    95127
    96128        ostype & ?|?( ostype & os, unsigned long long int ulli ) {
     
    99131                return os;
    100132        } // ?|?
     133        void & ?|?( ostype & os, unsigned long long int ulli ) {
     134                (ostype &)(os | ulli); nl( os );
     135        } // ?|?
    101136
    102137        ostype & ?|?( ostype & os, float f ) {
     
    105140                return os;
    106141        } // ?|?
     142        void & ?|?( ostype & os, float f ) {
     143                (ostype &)(os | f); nl( os );
     144        } // ?|?
    107145
    108146        ostype & ?|?( ostype & os, double d ) {
     
    111149                return os;
    112150        } // ?|?
     151        void & ?|?( ostype & os, double d ) {
     152                (ostype &)(os | d); nl( os );
     153        } // ?|?
    113154
    114155        ostype & ?|?( ostype & os, long double ld ) {
     
    117158                return os;
    118159        } // ?|?
     160        void & ?|?( ostype & os, long double ld ) {
     161                (ostype &)(os | ld); nl( os );
     162        } // ?|?
    119163
    120164        ostype & ?|?( ostype & os, float _Complex fc ) {
     
    123167                return os;
    124168        } // ?|?
     169        void & ?|?( ostype & os, float _Complex fc ) {
     170                (ostype &)(os | fc); nl( os );
     171        } // ?|?
    125172
    126173        ostype & ?|?( ostype & os, double _Complex dc ) {
     
    129176                return os;
    130177        } // ?|?
     178        void & ?|?( ostype & os, double _Complex dc ) {
     179                (ostype &)(os | dc); nl( os );
     180        } // ?|?
    131181
    132182        ostype & ?|?( ostype & os, long double _Complex ldc ) {
     
    134184                fmt( os, "%.*Lg%+.*Lgi", LDBL_DIG, creall( ldc ), LDBL_DIG, cimagl( ldc ) );
    135185                return os;
     186        } // ?|?
     187        void & ?|?( ostype & os, long double _Complex ldc ) {
     188                (ostype &)(os | ldc); nl( os );
    136189        } // ?|?
    137190
     
    174227                return write( os, str, len );
    175228        } // ?|?
     229        void ?|?( ostype & os, const char * str ) {
     230                (ostype &)(os | str); nl( os );
     231        } // ?|?
    176232
    177233//      ostype & ?|?( ostype & os, const char16_t * str ) {
     
    200256                return os;
    201257        } // ?|?
    202 
     258        void ?|?( ostype & os, const void * p ) {
     259                (ostype &)(os | p); nl( os );
     260        } // ?|?
    203261
    204262        // manipulators
    205263        ostype & ?|?( ostype & os, ostype & (* manip)( ostype & ) ) {
    206                 return manip( os );
     264                (ostype &)(manip( os ));
     265                return os;
     266        } // ?|?
     267        void ?|?( ostype & os, ostype & (* manip)( ostype & ) ) {
     268                (ostype &)(manip( os ));
     269                if ( getPrt( os ) ) nl( os );                                   // something printed ?
     270                setPrt( os, false );                                                    // turn off
    207271        } // ?|?
    208272
    209273        ostype & sep( ostype & os ) {
    210                 os | sepGet( os );
    211                 return os;
     274                return (ostype &)(os | sepGet( os ));
    212275        } // sep
    213276
    214277        ostype & sepTuple( ostype & os ) {
    215                 os | sepGetTuple( os );
    216                 return os;
     278                return os | sepGetTuple( os );
    217279        } // sepTuple
    218280
    219         ostype & endl( ostype & os ) {
    220                 os | '\n';
     281        ostype & nl( ostype & os ) {
     282                (ostype &)(os | '\n');
     283                setPrt( os, false );                                                    // turn off
    221284                setNL( os, true );
    222285                flush( os );
    223                 sepOff( os );                                                                   // prepare for next line
    224                 return os;
    225         } // endl
     286                return sepOff( os );                                                    // prepare for next line
     287        } // nl
     288
     289        void nl( ostype & os ) {
     290                if ( getANL( os ) ) (ostype &)(nl( os ));               // implementation only
     291                else setPrt( os, false );                                               // turn off
     292        } // nl
     293
     294        ostype & nonl( ostype & os ) {
     295                setPrt( os, false );                                                    // turn off
     296                return os;
     297        } // nonl
    226298
    227299        ostype & sepOn( ostype & os ) {
    228                 sepOn( os );
     300                sepOn( os );                                                                    // call void returning
    229301                return os;
    230302        } // sepOn
    231303
    232304        ostype & sepOff( ostype & os ) {
    233                 sepOff( os );
     305                sepOff( os );                                                                   // call void returning
    234306                return os;
    235307        } // sepOff
    236308
    237309        ostype & sepEnable( ostype & os ) {
    238                 sepEnable( os );
     310                sepEnable( os );                                                                // call void returning
    239311                return os;
    240312        } // sepEnable
    241313
    242314        ostype & sepDisable( ostype & os ) {
    243                 sepDisable( os );
     315                sepDisable( os );                                                               // call void returning
    244316                return os;
    245317        } // sepDisable
     318
     319        ostype & nlOn( ostype & os ) {
     320                nlOn( os );                                                                             // call void returning
     321                return os;
     322        } // nlOn
     323
     324        ostype & nlOff( ostype & os ) {
     325                nlOff( os );                                                                    // call void returning
     326                return os;
     327        } // nlOff
    246328} // distribution
    247329
    248 
    249330// tuples
    250 forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } )
    251 ostype & ?|?( ostype & os, T arg, Params rest ) {
    252         os | arg;                                                                                       // print first argument
    253         sepSetCur( os, sepGetTuple( os ) );                                     // switch to tuple separator
    254         os | rest;                                                                                      // print remaining arguments
    255         sepSetCur( os, sepGet( os ) );                                          // switch to regular separator
    256         return os;
    257 } // ?|?
     331forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) {
     332        ostype & ?|?( ostype & os, T arg, Params rest ) {
     333                (ostype &)(os | arg);                                                   // print first argument
     334                sepSetCur( os, sepGetTuple( os ) );                             // switch to tuple separator
     335                (ostype &)(os | rest);                                                  // print remaining arguments
     336                sepSetCur( os, sepGet( os ) );                                  // switch to regular separator
     337                return os;
     338        } // ?|?
     339        void ?|?( ostype & os, T arg, Params rest ) {
     340                // (ostype &)(?|?( os, arg, rest )); nl( os );
     341                (ostype &)(os | arg);                                                   // print first argument
     342                sepSetCur( os, sepGetTuple( os ) );                             // switch to tuple separator
     343                (ostype &)(os | rest);                                                  // print remaining arguments
     344                sepSetCur( os, sepGet( os ) );                                  // switch to regular separator
     345                nl( os );
     346        } // ?|?
     347} // distribution
    258348
    259349//---------------------------------------
    260350
    261351// writes the range [begin, end) to the given stream
    262 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) )
    263 void write( iterator_type begin, iterator_type end, ostype & os ) {
    264         void print( elt_type i ) { os | i; }
    265         for_each( begin, end, print );
    266 } // ?|?
    267 
    268 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) )
    269 void write_reverse( iterator_type begin, iterator_type end, ostype & os ) {
    270         void print( elt_type i ) { os | i; }
    271         for_each_reverse( begin, end, print );
    272 } // ?|?
     352forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) {
     353        void write( iterator_type begin, iterator_type end, ostype & os ) {
     354                void print( elt_type i ) { os | i; }
     355                for_each( begin, end, print );
     356        } // ?|?
     357
     358        void write_reverse( iterator_type begin, iterator_type end, ostype & os ) {
     359                void print( elt_type i ) { os | i; }
     360                for_each_reverse( begin, end, print );
     361        } // ?|?
     362} // distribution
    273363
    274364//---------------------------------------
     
    386476        } // ?|?
    387477
    388         istype & endl( istype & is ) {
     478        istype & nl( istype & is ) {
    389479                fmt( is, "%*[ \t\f\n\r\v]" );                                   // ignore whitespace
    390480                return is;
    391         } // endl
     481        } // nl
    392482} // distribution
    393483
Note: See TracChangeset for help on using the changeset viewer.