Changeset ef3ac46


Ignore:
Timestamp:
Apr 27, 2021, 10:07:25 PM (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:
f451177
Parents:
8840228
Message:

move flush from basic_ostream to ostream, refactor istream into basic_istream and istream

Location:
libcfa/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/iostream.cfa

    r8840228 ref3ac46  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Apr 24 10:03:54 2021
    13 // Update Count     : 1329
     12// Last Modified On : Tue Apr 27 18:01:03 2021
     13// Update Count     : 1330
    1414//
    1515
     
    145145        } // ?|?
    146146
    147 #if defined( __SIZEOF_INT128__ )
     147        #if defined( __SIZEOF_INT128__ )
    148148        //      UINT64_MAX 18_446_744_073_709_551_615_ULL
    149149        #define P10_UINT64 10_000_000_000_000_000_000_ULL       // 19 zeroes
    150150
    151151        static inline void base10_128( ostype & os, unsigned int128 val ) {
    152 #if defined(__GNUC__) && __GNUC_PREREQ(7,0)                             // gcc version >= 7
     152                #if defined(__GNUC__) && __GNUC_PREREQ(7,0)             // gcc version >= 7
    153153                if ( val > P10_UINT64 ) {
    154 #else
     154                #else
    155155                if ( (uint64_t)(val >> 64) != 0 || (uint64_t)val > P10_UINT64 ) { // patch gcc 5 & 6 -O3 bug
    156 #endif // __GNUC_PREREQ(7,0)
     156                #endif // __GNUC_PREREQ(7,0)
    157157                        base10_128( os, val / P10_UINT64 );                     // recursive
    158158                        fmt( os, "%.19lu", (uint64_t)(val % P10_UINT64) );
     
    187187                (ostype &)(os | ullli); ends( os );
    188188        } // ?|?
    189 #endif // __SIZEOF_INT128__
     189        #endif // __SIZEOF_INT128__
    190190
    191191        #define PrintWithDP( os, format, val, ... ) \
     
    361361                setPrt$( os, false );                                                   // turn off
    362362                setNL$( os, true );
    363                 flush( os );
    364363                return sepOff( os );                                                    // prepare for next line
    365364        } // nl
     
    808807
    809808
    810 forall( istype & | istream( istype ) ) {
     809forall( istype & | basic_istream( istype ) ) {
    811810        istype & ?|?( istype & is, bool & b ) {
    812811                char val[6];
     
    918917        } // ?|?
    919918
    920 #if defined( __SIZEOF_INT128__ )
     919        #if defined( __SIZEOF_INT128__ )
    921920        istype & ?|?( istype & is, int128 & llli ) {
    922921                return (istype &)(is | (unsigned int128 &)llli);
     
    944943                (istype &)(is | ullli); ends( is );
    945944        } // ?|?
    946 #endif // __SIZEOF_INT128__
     945        #endif // __SIZEOF_INT128__
    947946
    948947        istype & ?|?( istype & is, float & f ) {
     
    10351034                return is;
    10361035        } // nlOff
    1037 
     1036} // distribution
     1037
     1038forall( istype & | istream( istype ) ) {
    10381039        istype & acquire( istype & is ) {
    10391040                acquire( is );                                                                  // call void returning
     
    10441045// *********************************** manipulators ***********************************
    10451046
    1046 forall( istype & | istream( istype ) ) {
     1047forall( istype & | basic_istream( istype ) ) {
    10471048        istype & ?|?( istype & is, _Istream_Cstr f ) {
    10481049                // skip xxx
     
    10921093
    10931094#define InputFMTImpl( T, CODE ) \
    1094 forall( istype & | istream( istype ) ) { \
     1095forall( istype & | basic_istream( istype ) ) { \
    10951096        istype & ?|?( istype & is, _Istream_Manip(T) f ) { \
    10961097                enum { size = 16 }; \
     
    11251126InputFMTImpl( long double, "Lf" )
    11261127
    1127 forall( istype & | istream( istype ) ) {
     1128forall( istype & | basic_istream( istype ) ) {
    11281129        istype & ?|?( istype & is, _Istream_Manip(float _Complex) fc ) {
    11291130                float re, im;
  • libcfa/src/iostream.hfa

    r8840228 ref3ac46  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Apr 25 11:22:03 2021
    13 // Update Count     : 397
     12// Last Modified On : Tue Apr 27 17:59:21 2021
     13// Update Count     : 398
    1414//
    1515
     
    4949        void ends( ostype & );                                                          // end of output statement
    5050        int fmt( ostype &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
    51         int flush( ostype & );
    5251}; // basic_ostream
    5352       
    5453trait ostream( ostype & | basic_ostream( ostype ) ) {
     54        int flush( ostype & );
    5555        bool fail( ostype & );                                                          // operation failed?
    5656        void open( ostype &, const char name[], const char mode[] );
     
    9797        ostype & ?|?( ostype &, unsigned long long int );
    9898        void ?|?( ostype &, unsigned long long int );
    99 #if defined( __SIZEOF_INT128__ )
     99        #if defined( __SIZEOF_INT128__ )
    100100        ostype & ?|?( ostype &, int128 );
    101101        void ?|?( ostype &, int128 );
    102102        ostype & ?|?( ostype &, unsigned int128 );
    103103        void ?|?( ostype &, unsigned int128 );
    104 #endif // __SIZEOF_INT128__
     104        #endif // __SIZEOF_INT128__
    105105
    106106        ostype & ?|?( ostype &, float );
     
    121121        void ?|?( ostype &, const char [] );
    122122        // ostype & ?|?( ostype &, const char16_t * );
    123 #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
    124124        // ostype & ?|?( ostype &, const char32_t * );
    125 #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 )
     125        #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 )
    126126        // ostype & ?|?( ostype &, const wchar_t * );
    127127        ostype & ?|?( ostype &, const void * );
     
    294294
    295295
    296 trait istream( istype & ) {
     296trait basic_istream( istype & ) {
     297        bool getANL( istype & );                                                        // get scan newline (on/off)
    297298        void nlOn( istype & );                                                          // read newline
    298299        void nlOff( istype & );                                                         // scan newline
    299         bool getANL( istype & );                                                        // get scan newline (on/off)
    300300
    301301        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 );
     304        int eof( istype & );
     305}; // basic_istream
     306
     307trait istream( istype & | basic_istream( istype ) ) {
    302308        bool fail( istype & );
    303         int eof( istype & );
    304309        void open( istype & is, const char name[] );
    305310        void close( istype & is );
    306311        istype & read( istype &, char *, size_t );
    307         istype & ungetc( istype &, char );
    308         int fmt( istype &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
    309         void acquire( istype & );
     312        void acquire( istype & );                                                       // concurrent access
    310313}; // istream
    311314
     
    314317}; // readable
    315318
    316 forall( istype & | istream( istype ) ) {
     319forall( istype & | basic_istream( istype ) ) {
    317320        istype & ?|?( istype &, bool & );
    318321        void ?|?( istype &, bool & );
     
    341344        istype & ?|?( istype &, unsigned long long int & );
    342345        void ?|?( istype &, unsigned long long int & );
    343 #if defined( __SIZEOF_INT128__ )
     346        #if defined( __SIZEOF_INT128__ )
    344347        istype & ?|?( istype &, int128 & );
    345348        void ?|?( istype &, int128 & );
    346349        istype & ?|?( istype &, unsigned int128 & );
    347350        void ?|?( istype &, unsigned int128 & );
    348 #endif // __SIZEOF_INT128__
     351        #endif // __SIZEOF_INT128__
    349352
    350353        istype & ?|?( istype &, float & );
     
    372375        istype & nlOn( istype & );
    373376        istype & nlOff( istype & );
     377} // distribution
     378
     379forall( istype & | istream( istype ) ) {
    374380        istype & acquire( istype & );
    375381} // distribution
     
    402408        _Istream_Cstr & wdi( unsigned int w, _Istream_Cstr & fmt ) { fmt.wd = w; return fmt; }
    403409} // distribution
    404 forall( istype & | istream( istype ) ) {
     410forall( istype & | basic_istream( istype ) ) {
    405411        istype & ?|?( istype & is, _Istream_Cstr f );
    406412        void ?|?( istype & is, _Istream_Cstr f );
     
    415421        _Istream_Char & ignore( _Istream_Char & fmt ) { fmt.ignore = true; return fmt; }
    416422} // distribution
    417 forall( istype & | istream( istype ) ) {
     423forall( istype & | basic_istream( istype ) ) {
    418424        istype & ?|?( istype & is, _Istream_Char f );
    419425        void ?|?( istype & is, _Istream_Char f );
     
    434440        _Istream_Manip(T) & wdi( unsigned int w, _Istream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \
    435441} /* distribution */ \
    436 forall( istype & | istream( istype ) ) { \
     442forall( istype & | basic_istream( istype ) ) { \
    437443        istype & ?|?( istype & is, _Istream_Manip(T) f ); \
    438444        void ?|?( istype & is, _Istream_Manip(T) f ); \
Note: See TracChangeset for help on using the changeset viewer.