Ignore:
Timestamp:
Apr 28, 2021, 4:56:50 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
8d66610
Parents:
feacef9 (diff), b7fd2db6 (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/iostream.hfa

    rfeacef9 r5407cdc  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Aug 11 22:16:14 2020
    13 // Update Count     : 350
     12// Last Modified On : Tue Apr 27 17:59:21 2021
     13// Update Count     : 398
    1414//
    1515
     
    2222
    2323
    24 trait ostream( ostype & ) {
     24trait basic_ostream( ostype & ) {
    2525        // private
    26         bool $sepPrt( ostype & );                                                       // get separator state (on/off)
    27         void $sepReset( ostype & );                                                     // set separator state to default state
    28         void $sepReset( ostype &, bool );                                       // set separator and default state
    29         const char * $sepGetCur( ostype & );                            // get current separator string
    30         void $sepSetCur( ostype &, const char [] );                     // set current separator string
    31         bool $getNL( ostype & );                                                        // check newline
    32         void $setNL( ostype &, bool );                                          // saw newline
    33         bool $getANL( ostype & );                                                       // get auto newline (on/off)
    34         bool $getPrt( ostype & );                                                       // get fmt called in output cascade
    35         void $setPrt( ostype &, bool );                                         // set fmt called in output cascade
     26        bool sepPrt$( ostype & );                                                       // get separator state (on/off)
     27        void sepReset$( ostype & );                                                     // set separator state to default state
     28        void sepReset$( ostype &, bool );                                       // set separator and default state
     29        const char * sepGetCur$( ostype & );                            // get current separator string
     30        void sepSetCur$( ostype &, const char [] );                     // set current separator string
     31        bool getNL$( ostype & );                                                        // check newline
     32        void setNL$( ostype &, bool );                                          // saw newline
     33        bool getANL$( ostype & );                                                       // get auto newline (on/off)
     34        bool getPrt$( ostype & );                                                       // get fmt called in output cascade
     35        void setPrt$( ostype &, bool );                                         // set fmt called in output cascade
    3636        // public
    3737        void sepOn( ostype & );                                                         // turn separator state on
     
    4747        void sepSetTuple( ostype &, const char [] );            // set tuple separator to string (15 character maximum)
    4848
    49         void ends( ostype & os );                                                       // end of output statement
    50         int fail( ostype & );
     49        void ends( ostype & );                                                          // end of output statement
     50        int fmt( ostype &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
     51}; // basic_ostream
     52       
     53trait ostream( ostype & | basic_ostream( ostype ) ) {
    5154        int flush( ostype & );
    52         void open( ostype & os, const char name[], const char mode[] );
    53         void close( ostype & os );
     55        bool fail( ostype & );                                                          // operation failed?
     56        void open( ostype &, const char name[], const char mode[] );
     57        void close( ostype & );
    5458        ostype & write( ostype &, const char [], size_t );
    55         int fmt( ostype &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
     59        void acquire( ostype & );                                                       // concurrent access
    5660}; // ostream
    5761
     
    6670// implement writable for intrinsic types
    6771
    68 forall( ostype & | ostream( ostype ) ) {
     72forall( ostype & | basic_ostream( ostype ) ) {
    6973        ostype & ?|?( ostype &, bool );
    7074        void ?|?( ostype &, bool );
     
    9397        ostype & ?|?( ostype &, unsigned long long int );
    9498        void ?|?( ostype &, unsigned long long int );
    95 #if defined( __SIZEOF_INT128__ )
     99        #if defined( __SIZEOF_INT128__ )
    96100        ostype & ?|?( ostype &, int128 );
    97101        void ?|?( ostype &, int128 );
    98102        ostype & ?|?( ostype &, unsigned int128 );
    99103        void ?|?( ostype &, unsigned int128 );
    100 #endif // __SIZEOF_INT128__
     104        #endif // __SIZEOF_INT128__
    101105
    102106        ostype & ?|?( ostype &, float );
     
    117121        void ?|?( ostype &, const char [] );
    118122        // ostype & ?|?( ostype &, const char16_t * );
    119 #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous
     123        #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous
    120124        // ostype & ?|?( ostype &, const char32_t * );
    121 #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 )
     125        #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 )
    122126        // ostype & ?|?( ostype &, const wchar_t * );
    123127        ostype & ?|?( ostype &, const void * );
     
    139143} // distribution
    140144
     145forall( ostype & | ostream( ostype ) ) {
     146        ostype & acquire( ostype & );
     147} // distribution
     148
    141149// tuples
    142150forall( ostype &, T, Params... | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) {
     
    156164struct _Ostream_Manip {
    157165        T val;                                                                                          // polymorphic base-type
    158         unsigned int wd, pc;                                                            // width, precision
     166        int wd, pc;                                                                                     // width, precision: signed for computations
    159167        char base;                                                                                      // numeric base / floating-point style
    160168        union {
    161169                unsigned char all;
    162170                struct {
     171                        unsigned char eng:1;                                            // engineering notation
    163172                        unsigned char neg:1;                                            // val is negative
    164173                        unsigned char pc:1;                                                     // precision specified
     
    183192        _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'x', { .all : 0 } }; } \
    184193        _Ostream_Manip(T) wd( unsigned int w, T val ) { return (_Ostream_Manip(T))@{ val, w, 0, CODE, { .all : 0 } }; } \
    185         _Ostream_Manip(T) wd( unsigned int w, unsigned char pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, CODE, { .flags.pc : true } }; } \
     194        _Ostream_Manip(T) wd( unsigned int w, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, CODE, { .flags.pc : true } }; } \
    186195        _Ostream_Manip(T) & wd( unsigned int w, _Ostream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \
    187         _Ostream_Manip(T) & wd( unsigned int w, unsigned char pc, _Ostream_Manip(T) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \
     196        _Ostream_Manip(T) & wd( unsigned int w, unsigned int pc, _Ostream_Manip(T) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \
    188197        _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \
    189198        _Ostream_Manip(T) & upcase( _Ostream_Manip(T) & fmt ) { if ( fmt.base == 'x' || fmt.base == 'b' ) fmt.base -= 32; /* upper case */ return fmt; } \
     
    193202        _Ostream_Manip(T) & sign( _Ostream_Manip(T) & fmt ) { fmt.flags.sign = true; return fmt; } \
    194203} /* distribution */ \
    195 forall( ostype & | ostream( ostype ) ) { \
     204forall( ostype & | basic_ostream( ostype ) ) { \
    196205        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \
    197206        void ?|?( ostype & os, _Ostream_Manip(T) f ); \
     
    220229        _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'a', { .all : 0 } }; } \
    221230        _Ostream_Manip(T) sci( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'e', { .all : 0 } }; } \
    222         _Ostream_Manip(T) wd( unsigned int w, T val ) { return (_Ostream_Manip(T))@{ val, w, 0, 'f', { .all : 0 } }; } \
    223         _Ostream_Manip(T) wd( unsigned int w, unsigned char pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'f', { .flags.pc : true } }; } \
    224         _Ostream_Manip(T) ws( unsigned int w, unsigned char pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'g', { .flags.pc : true } }; } \
    225         _Ostream_Manip(T) & wd( unsigned int w, _Ostream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \
    226         _Ostream_Manip(T) & wd( unsigned int w, unsigned char pc, _Ostream_Manip(T) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \
     231        _Ostream_Manip(T) eng( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.eng : true } }; } \
     232        _Ostream_Manip(T) wd( unsigned int w, T val ) { return (_Ostream_Manip(T))@{ val, w, 0, 'g', { .all : 0 } }; } \
     233        _Ostream_Manip(T) wd( unsigned int w, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'f', { .flags.pc : true } }; } \
     234        _Ostream_Manip(T) ws( unsigned int w, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'g', { .flags.pc : true } }; } \
     235        _Ostream_Manip(T) & wd( unsigned int w, _Ostream_Manip(T) & fmt ) { if ( fmt.flags.eng ) fmt.base = 'f'; fmt.wd = w; return fmt; } \
     236        _Ostream_Manip(T) & wd( unsigned int w, unsigned int pc, _Ostream_Manip(T) & fmt ) { if ( fmt.flags.eng ) fmt.base = 'f'; fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \
     237        _Ostream_Manip(T) & ws( unsigned int w, unsigned int pc, _Ostream_Manip(T) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \
    227238        _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \
    228239        _Ostream_Manip(T) upcase( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'G', { .all : 0 } }; } \
     
    233244        _Ostream_Manip(T) nodp( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.nobsdp : true } }; } \
    234245        _Ostream_Manip(T) & nodp( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \
     246        _Ostream_Manip(T) unit( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.nobsdp : true } }; } \
     247        _Ostream_Manip(T) & unit( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \
    235248} /* distribution */ \
    236 forall( ostype & | ostream( ostype ) ) { \
     249forall( ostype & | basic_ostream( ostype ) ) { \
    237250        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ); \
    238251        void ?|?( ostype & os, _Ostream_Manip(T) f ); \
     
    254267        _Ostream_Manip(char) & nobase( _Ostream_Manip(char) & fmt ) { fmt.flags.nobsdp = true; return fmt; }
    255268} // distribution
    256 forall( ostype & | ostream( ostype ) ) {
     269forall( ostype & | basic_ostream( ostype ) ) {
    257270        ostype & ?|?( ostype & os, _Ostream_Manip(char) f );
    258271        void ?|?( ostype & os, _Ostream_Manip(char) f );
     
    266279        _Ostream_Manip(const char *) hex( const char s[] ) { return (_Ostream_Manip(const char *))@{ s, 1, 0, 'x', { .all : 0 } }; }
    267280        _Ostream_Manip(const char *) wd( unsigned int w, const char s[] ) { return (_Ostream_Manip(const char *))@{ s, w, 0, 's', { .all : 0 } }; }
    268         _Ostream_Manip(const char *) wd( unsigned int w, unsigned char pc, const char s[] ) { return (_Ostream_Manip(const char *))@{ s, w, pc, 's', { .flags.pc : true } }; }
     281        _Ostream_Manip(const char *) wd( unsigned int w, unsigned int pc, const char s[] ) { return (_Ostream_Manip(const char *))@{ s, w, pc, 's', { .flags.pc : true } }; }
    269282        _Ostream_Manip(const char *) & wd( unsigned int w, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; return fmt; }
    270         _Ostream_Manip(const char *) & wd( unsigned int w, unsigned char pc, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; }
     283        _Ostream_Manip(const char *) & wd( unsigned int w, unsigned int pc, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; }
    271284        _Ostream_Manip(const char *) & left( _Ostream_Manip(const char *) & fmt ) { fmt.flags.left = true; return fmt; }
    272285        _Ostream_Manip(const char *) & nobase( _Ostream_Manip(const char *) & fmt ) { fmt.flags.nobsdp = true; return fmt; }
    273286} // distribution
    274 forall( ostype & | ostream( ostype ) ) {
     287forall( ostype & | basic_ostream( ostype ) ) {
    275288        ostype & ?|?( ostype & os, _Ostream_Manip(const char *) f );
    276289        void ?|?( ostype & os, _Ostream_Manip(const char *) f );
     
    281294
    282295
    283 trait istream( istype & ) {
     296trait basic_istream( istype & ) {
     297        bool getANL( istype & );                                                        // get scan newline (on/off)
    284298        void nlOn( istype & );                                                          // read newline
    285299        void nlOff( istype & );                                                         // scan newline
    286         bool getANL( istype & );                                                        // get scan newline (on/off)
    287         int fail( istype & );
     300
     301        void ends( istype & os );                                                       // end of output statement
     302        int fmt( istype &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
     303        istype & ungetc( istype &, char );
    288304        int eof( istype & );
     305}; // basic_istream
     306
     307trait istream( istype & | basic_istream( istype ) ) {
     308        bool fail( istype & );
    289309        void open( istype & is, const char name[] );
    290310        void close( istype & is );
    291311        istype & read( istype &, char *, size_t );
    292         istype & ungetc( istype &, char );
    293         int fmt( istype &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
     312        void acquire( istype & );                                                       // concurrent access
    294313}; // istream
    295314
     
    298317}; // readable
    299318
    300 forall( istype & | istream( istype ) ) {
     319forall( istype & | basic_istream( istype ) ) {
    301320        istype & ?|?( istype &, bool & );
     321        void ?|?( istype &, bool & );
    302322
    303323        istype & ?|?( istype &, char & );
     324        void ?|?( istype &, char & );
    304325        istype & ?|?( istype &, signed char & );
     326        void ?|?( istype &, signed char & );
    305327        istype & ?|?( istype &, unsigned char & );
     328        void ?|?( istype &, unsigned char & );
    306329
    307330        istype & ?|?( istype &, short int & );
     331        void ?|?( istype &, short int & );
    308332        istype & ?|?( istype &, unsigned short int & );
     333        void ?|?( istype &, unsigned short int & );
    309334        istype & ?|?( istype &, int & );
     335        void ?|?( istype &, int & );
    310336        istype & ?|?( istype &, unsigned int & );
     337        void ?|?( istype &, unsigned int & );
    311338        istype & ?|?( istype &, long int & );
     339        void ?|?( istype &, long int & );
    312340        istype & ?|?( istype &, unsigned long int & );
     341        void ?|?( istype &, unsigned long int & );
    313342        istype & ?|?( istype &, long long int & );
     343        void ?|?( istype &, long long int & );
    314344        istype & ?|?( istype &, unsigned long long int & );
    315 #if defined( __SIZEOF_INT128__ )
     345        void ?|?( istype &, unsigned long long int & );
     346        #if defined( __SIZEOF_INT128__ )
    316347        istype & ?|?( istype &, int128 & );
     348        void ?|?( istype &, int128 & );
    317349        istype & ?|?( istype &, unsigned int128 & );
    318 #endif // __SIZEOF_INT128__
     350        void ?|?( istype &, unsigned int128 & );
     351        #endif // __SIZEOF_INT128__
    319352
    320353        istype & ?|?( istype &, float & );
     354        void ?|?( istype &, float & );
    321355        istype & ?|?( istype &, double & );
     356        void ?|?( istype &, double & );
    322357        istype & ?|?( istype &, long double & );
     358        void ?|?( istype &, long double & );
    323359
    324360        istype & ?|?( istype &, float _Complex & );
     361        void ?|?( istype &, float _Complex & );
    325362        istype & ?|?( istype &, double _Complex & );
     363        void ?|?( istype &, double _Complex & );
    326364        istype & ?|?( istype &, long double _Complex & );
     365        void ?|?( istype &, long double _Complex & );
    327366
    328367//      istype & ?|?( istype &, const char [] );
    329         istype & ?|?( istype &, char * );
     368        istype & ?|?( istype &, char [] );
     369        void ?|?( istype &, char [] );
    330370
    331371        // manipulators
    332372        istype & ?|?( istype &, istype & (*)( istype & ) );
     373        void ?|?( istype &, istype & (*)( istype & ) );
    333374        istype & nl( istype & is );
    334375        istype & nlOn( istype & );
    335376        istype & nlOff( istype & );
     377} // distribution
     378
     379forall( istype & | istream( istype ) ) {
     380        istype & acquire( istype & );
    336381} // distribution
    337382
     
    352397
    353398static inline {
     399        _Istream_Cstr skip( const char scanset[] ) { return (_Istream_Cstr){ 0p, scanset, -1, { .all : 0 } }; }
    354400        _Istream_Cstr skip( unsigned int n ) { return (_Istream_Cstr){ 0p, 0p, n, { .all : 0 } }; }
    355         _Istream_Cstr skip( const char scanset[] ) { return (_Istream_Cstr){ 0p, scanset, -1, { .all : 0 } }; }
    356401        _Istream_Cstr incl( const char scanset[], char * s ) { return (_Istream_Cstr){ s, scanset, -1, { .flags.inex : false } }; }
    357402        _Istream_Cstr & incl( const char scanset[], _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = false; return fmt; }
     
    363408        _Istream_Cstr & wdi( unsigned int w, _Istream_Cstr & fmt ) { fmt.wd = w; return fmt; }
    364409} // distribution
    365 forall( istype & | istream( istype ) ) istype & ?|?( istype & is, _Istream_Cstr f );
     410forall( istype & | basic_istream( istype ) ) {
     411        istype & ?|?( istype & is, _Istream_Cstr f );
     412        void ?|?( istype & is, _Istream_Cstr f );
     413}
    366414
    367415struct _Istream_Char {
     
    373421        _Istream_Char & ignore( _Istream_Char & fmt ) { fmt.ignore = true; return fmt; }
    374422} // distribution
    375 forall( istype & | istream( istype ) ) istype & ?|?( istype & is, _Istream_Char f );
     423forall( istype & | basic_istream( istype ) ) {
     424        istype & ?|?( istype & is, _Istream_Char f );
     425        void ?|?( istype & is, _Istream_Char f );
     426}
    376427
    377428forall( T & | sized( T ) )
     
    389440        _Istream_Manip(T) & wdi( unsigned int w, _Istream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \
    390441} /* distribution */ \
    391 forall( istype & | istream( istype ) ) { \
     442forall( istype & | basic_istream( istype ) ) { \
    392443        istype & ?|?( istype & is, _Istream_Manip(T) f ); \
     444        void ?|?( istype & is, _Istream_Manip(T) f ); \
    393445} // ?|?
    394446
Note: See TracChangeset for help on using the changeset viewer.