Changeset 4783ff6 for libcfa


Ignore:
Timestamp:
Feb 20, 2020, 4:00:54 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
2cbfe92
Parents:
5b2b42e (diff), 46b11e2 (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

Location:
libcfa/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/fstream.hfa

    r5b2b42e r4783ff6  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Feb  7 19:00:51 2020
    13 // Update Count     : 174
     12// Last Modified On : Mon Feb 17 08:29:23 2020
     13// Update Count     : 175
    1414//
    1515
     
    6767void close( ofstream & );
    6868ofstream & write( ofstream &, const char data[], size_t size );
    69 int fmt( ofstream &, const char format[], ... );
     69int fmt( ofstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
    7070
    7171void ?{}( ofstream & os );
     
    9797ifstream & read( ifstream & is, char * data, size_t size );
    9898ifstream & ungetc( ifstream & is, char c );
    99 int fmt( ifstream &, const char format[], ... );
     99int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
    100100
    101101void ?{}( ifstream & is );
  • libcfa/src/iostream.cfa

    r5b2b42e r4783ff6  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Feb  7 18:48:38 2020
    13 // Update Count     : 825
     12// Last Modified On : Thu Feb 20 15:30:58 2020
     13// Update Count     : 827
    1414//
    1515
     
    159159                (ostype &)(os | ulli); ends( os );
    160160        } // ?|?
     161
     162#if defined( __SIZEOF_INT128__ )
     163        //      UINT64_MAX 18_446_744_073_709_551_615_ULL
     164        #define P10_UINT64 10_000_000_000_000_000_000_ULL       // 19 zeroes
     165
     166        static void base10_128( ostype & os, unsigned int128 val ) {
     167                if ( val > UINT64_MAX ) {
     168                        base10_128( os, val / P10_UINT64 );                     // recursive
     169                        fmt( os, "%.19lu", (uint64_t)(val % P10_UINT64) );
     170                } else {
     171                        fmt( os, "%lu", (uint64_t)val );
     172                } // if
     173        } // base10_128
     174
     175        static void base10_128( ostype & os, int128 val ) {
     176                if ( val < 0 ) {
     177                        fmt( os, "-" );                                                         // leading negative sign
     178                        val = -val;
     179                } // if
     180                base10_128( os, (unsigned int128)val );                 // print zero/positive value
     181        } // base10_128
     182
     183        ostype & ?|?( ostype & os, int128 llli ) {
     184                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     185                base10_128( os, llli );
     186                return os;
     187        } // ?|?
     188        void & ?|?( ostype & os, int128 llli ) {
     189                (ostype &)(os | llli); ends( os );
     190        } // ?|?
     191
     192        ostype & ?|?( ostype & os, unsigned int128 ullli ) {
     193                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
     194                base10_128( os, ullli );
     195                return os;
     196        } // ?|?
     197        void & ?|?( ostype & os, unsigned int128 ullli ) {
     198                (ostype &)(os | ullli); ends( os );
     199        } // ?|?
     200#endif // __SIZEOF_INT128__
    161201
    162202        #define PrintWithDP( os, format, val, ... ) \
     
    464504\
    465505                if ( ! f.flags.pc ) {                                                   /* no precision */ \
    466                         /* printf( "%s\n", &fmtstr[star] ); */ \
    467506                        fmtstr[sizeof(IFMTNP)-2] = f.base;                      /* sizeof includes '\0' */ \
     507                        /* printf( "%s %c %c\n", &fmtstr[star], f.base, CODE ); */ \
    468508                        fmt( os, &fmtstr[star], f.wd, f.val ); \
    469509                } else {                                                                                /* precision */ \
    470510                        fmtstr[sizeof(IFMTP)-2] = f.base;                       /* sizeof includes '\0' */ \
    471                         /* printf( "%s\n", &fmtstr[star] ); */ \
     511                        /* printf( "%s %c %c\n", &fmtstr[star], f.base, CODE ); */ \
    472512                        fmt( os, &fmtstr[star], f.wd, f.pc, f.val ); \
    473513                } /* if */ \
     
    487527IntegralFMTImpl( signed long long int, 'd', "%    *ll ", "%    *.*ll " )
    488528IntegralFMTImpl( unsigned long long int, 'u', "%    *ll ", "%    *.*ll " )
     529
     530
     531#if defined( __SIZEOF_INT128__ )
     532// Default prefix for non-decimal prints is 0b, 0, 0x.
     533#define IntegralFMTImpl128( T, SIGNED, CODE, IFMTNP, IFMTP ) \
     534forall( dtype ostype | ostream( ostype ) ) \
     535static void base10_128( ostype & os, _Ostream_Manip(T) fmt ) { \
     536        if ( fmt.val > UINT64_MAX ) { \
     537                fmt.val /= P10_UINT64; \
     538                base10_128( os, fmt ); /* recursive */ \
     539                _Ostream_Manip(unsigned long long int) fmt2 @= { (uint64_t)(fmt.val % P10_UINT64), 0, 19, 'u', { .all : 0 } }; \
     540                fmt2.flags.nobsdp = true; \
     541                printf( "fmt2 %c %lld %d\n", fmt2.base, fmt2.val, fmt2.all );   \
     542                sepOff( os ); \
     543                (ostype &)(os | fmt2); \
     544        } else { \
     545                printf( "fmt %c %lld %d\n", fmt.base, fmt.val, fmt.all ); \
     546                (ostype &)(os | fmt); \
     547        } /* if */ \
     548} /* base10_128 */                                                 \
     549forall( dtype ostype | ostream( ostype ) ) { \
     550        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \
     551                if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) ); \
     552\
     553                if ( f.base == 'b' | f.base == 'o' | f.base == 'x' | f.base == 'X' ) { \
     554                        unsigned long long int msig = (unsigned long long int)(f.val >> 64); \
     555                        unsigned long long int lsig = (unsigned long long int)(f.val); \
     556                        _Ostream_Manip(SIGNED long long int) fmt @= { msig, f.wd, f.pc, f.base, { .all : f.all } }; \
     557                        _Ostream_Manip(unsigned long long int) fmt2 @= { lsig, 0, 0, f.base, { .all : 0 } }; \
     558                        if ( msig == 0 ) { \
     559                                fmt.val = lsig; \
     560                                (ostype &)(os | fmt); \
     561                        } else { \
     562                                fmt2.flags.pad0 = fmt2.flags.nobsdp = true;     \
     563                                if ( f.base == 'b' ) { \
     564                                        if ( f.wd > 64 ) fmt.wd = f.wd - 64; \
     565                                        fmt2.wd = 64; \
     566                                        (ostype &)(os | fmt | "" | fmt2); \
     567                                } else if ( f.base == 'o' ) { \
     568                                        fmt.val = (unsigned long long int)fmt.val >> 2; \
     569                                        if ( f.wd > 21 ) fmt.wd = f.wd - 21; \
     570                                        fmt2.wd = 1; \
     571                                        fmt2.val = ((msig & 0x3) << 1) + 1; \
     572                                        (ostype &)(os | fmt | "" | fmt2); \
     573                                        sepOff( os ); \
     574                                        fmt2.wd = 21; \
     575                                        fmt2.val = lsig & 0x7fffffffffffffff; \
     576                                        (ostype &)(os | fmt2); \
     577                                } else { \
     578                                        if ( f.flags.left ) { \
     579                                                if ( f.wd > 16 ) fmt2.wd = f.wd - 16;   \
     580                                                fmt.wd = 16;                                                    \
     581                                        } else { \
     582                                                if ( f.wd > 16 ) fmt.wd = f.wd - 16;    \
     583                                                fmt2.wd = 16;                                                   \
     584                                        } /* if */ \
     585                                        (ostype &)(os | fmt | "" | fmt2); \
     586                                } /* if */ \
     587                        } /* if */ \
     588                } else { \
     589                        base10_128( os, f ); \
     590                } /* if */ \
     591                return os; \
     592        } /* ?|? */ \
     593        void ?|?( ostype & os, _Ostream_Manip(T) f ) { (ostype &)(os | f); ends( os ); } \
     594} // distribution
     595
     596IntegralFMTImpl128( int128, signed, 'd', "%    *ll ", "%    *.*ll " )
     597IntegralFMTImpl128( unsigned int128, unsigned, 'u', "%    *ll ", "%    *.*ll " )
     598#endif // __SIZEOF_INT128__
    489599
    490600//*********************************** floating point ***********************************
  • libcfa/src/iostream.hfa

    r5b2b42e r4783ff6  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Feb  7 17:53:52 2020
    13 // Update Count     : 336
     12// Last Modified On : Thu Feb 20 15:30:56 2020
     13// Update Count     : 337
    1414//
    1515
     
    9898        ostype & ?|?( ostype &, unsigned long long int );
    9999        void ?|?( ostype &, unsigned long long int );
     100#if defined( __SIZEOF_INT128__ )
     101        ostype & ?|?( ostype &, int128 );
     102        void ?|?( ostype &, int128 );
     103        ostype & ?|?( ostype &, unsigned int128 );
     104        void ?|?( ostype &, unsigned int128 );
     105#endif // __SIZEOF_INT128__
    100106
    101107        ostype & ?|?( ostype &, float );
     
    206212IntegralFMTDecl( signed long long int, 'd' )
    207213IntegralFMTDecl( unsigned long long int, 'u' )
     214#if defined( __SIZEOF_INT128__ )
     215IntegralFMTDecl( int128, 'd' )
     216IntegralFMTDecl( unsigned int128, 'u' )
     217#endif
    208218
    209219//*********************************** floating point ***********************************
Note: See TracChangeset for help on using the changeset viewer.