Changeset adaee12 for libcfa/src


Ignore:
Timestamp:
Apr 28, 2021, 1:06:13 PM (4 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:
b7fd2db6
Parents:
e9c0b4c (diff), c7015e6b (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:
12 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/coroutine.cfa

    re9c0b4c radaee12  
    6161forall(T & | is_coroutine(T))
    6262void __cfaehm_cancelled_coroutine(
    63                 T & cor, $coroutine * desc, _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable ) {
     63                T & cor, $coroutine * desc, EHM_DEFAULT_VTABLE(CoroutineCancelled, (T)) ) {
    6464        verify( desc->cancellation );
    6565        desc->state = Cancelled;
     
    145145// Part of the Public API
    146146// Not inline since only ever called once per coroutine
    147 forall(T & | is_coroutine(T) | { _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable; })
     147forall(T & | is_coroutine(T) | { EHM_DEFAULT_VTABLE(CoroutineCancelled, (T)); })
    148148void prime(T& cor) {
    149149        $coroutine* this = get_coroutine(cor);
  • libcfa/src/concurrency/coroutine.hfa

    re9c0b4c radaee12  
    6060//-----------------------------------------------------------------------------
    6161// Public coroutine API
    62 forall(T & | is_coroutine(T) | { _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable; })
     62forall(T & | is_coroutine(T) | { EHM_DEFAULT_VTABLE(CoroutineCancelled, (T)); })
    6363void prime(T & cor);
    6464
     
    131131forall(T & | is_coroutine(T))
    132132void __cfaehm_cancelled_coroutine(
    133         T & cor, $coroutine * desc, _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable );
     133        T & cor, $coroutine * desc, EHM_DEFAULT_VTABLE(CoroutineCancelled, (T)) );
    134134
    135135// Resume implementation inlined for performance
    136 forall(T & | is_coroutine(T) | { _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable; })
     136forall(T & | is_coroutine(T) | { EHM_DEFAULT_VTABLE(CoroutineCancelled, (T)); })
    137137static inline T & resume(T & cor) {
    138138        // optimization : read TLS once and reuse it
  • libcfa/src/concurrency/stats.cfa

    re9c0b4c radaee12  
    126126
    127127                char buf[1024];
    128                 strstream sstr = { buf, 1024 };
     128                ostrstream sstr = { buf, 1024 };
    129129
    130130                if( flags & CFA_STATS_READY_Q ) {
  • libcfa/src/concurrency/thread.cfa

    re9c0b4c radaee12  
    8282
    8383forall(T & | is_thread(T) | IS_EXCEPTION(ThreadCancelled, (T))
    84     | { _EHM_VTABLE_TYPE(ThreadCancelled)(T) & const _default_vtable; })
     84    | { EHM_DEFAULT_VTABLE(ThreadCancelled, (T)); })
    8585void ?{}( thread_dtor_guard_t & this,
    8686                T & thrd, void(*cancelHandler)(ThreadCancelled(T) &)) {
     
    161161//-----------------------------------------------------------------------------
    162162forall(T & | is_thread(T) | IS_RESUMPTION_EXCEPTION(ThreadCancelled, (T))
    163     | { _EHM_VTABLE_TYPE(ThreadCancelled)(T) & const _default_vtable; })
     163    | { EHM_DEFAULT_VTABLE(ThreadCancelled, (T)); })
    164164T & join( T & this ) {
    165165        thread_dtor_guard_t guard = { this, defaultResumptionHandler };
  • libcfa/src/concurrency/thread.hfa

    re9c0b4c radaee12  
    8080
    8181forall( T & | is_thread(T) | IS_EXCEPTION(ThreadCancelled, (T))
    82     | { _EHM_VTABLE_TYPE(ThreadCancelled)(T) & const _default_vtable; } )
     82    | { EHM_DEFAULT_VTABLE(ThreadCancelled, (T)); })
    8383void ?{}( thread_dtor_guard_t & this, T & thrd, void(*)(ThreadCancelled(T) &) );
    8484void ^?{}( thread_dtor_guard_t & this );
     
    127127// join
    128128forall( T & | is_thread(T) | IS_RESUMPTION_EXCEPTION(ThreadCancelled, (T))
    129     | { _EHM_VTABLE_TYPE(ThreadCancelled)(T) & const _default_vtable; } )
     129    | { EHM_DEFAULT_VTABLE(ThreadCancelled, (T)); })
    130130T & join( T & this );
    131131
  • libcfa/src/exception.hfa

    re9c0b4c radaee12  
    6464        _EHM_VIRTUAL_TABLE(exception_name, arguments, table_name)
    6565
    66 #define EHM_TYPE_ID(exception_name) _EHM_TYPE_ID_TYPE(exception_name)
    67 
    68 #define EHM_MATCH_ALL __cfa__parent_vtable
     66// EHM_DEFAULT_VTABLE(exception_name, (arguments))
     67// Create a declaration for a (possibly polymorphic) default vtable.
     68#define EHM_DEFAULT_VTABLE(exception_name, arguments) \
     69        _EHM_VTABLE_TYPE(exception_name) arguments & const _default_vtable
    6970
    7071// IS_EXCEPTION(exception_name [, (...parameters)])
  • libcfa/src/fstream.cfa

    re9c0b4c radaee12  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Apr 24 09:05:16 2021
    13 // Update Count     : 426
    14 //
    15 
    16 #include "fstream.hfa"
     12// Last Modified On : Tue Apr 27 22:08:57 2021
     13// Update Count     : 442
     14//
     15
     16#include "fstream.hfa"                                                                  // also includes iostream.hfa
    1717
    1818#include <stdio.h>                                                                              // vfprintf, vfscanf
     
    196196ofstream & abort = abortFile;
    197197
     198ofstream & nl( ofstream & os ) {
     199        nl$( os );                                                                                      // call basic_ostream nl
     200        flush( os );
     201        return os;
     202        // (ofstream &)(os | '\n');
     203        // setPrt$( os, false );                                                        // turn off
     204        // setNL$( os, true );
     205        // flush( os );
     206        // return sepOff( os );                                                 // prepare for next line
     207} // nl
    198208
    199209// *********************************** ifstream ***********************************
  • libcfa/src/fstream.hfa

    re9c0b4c radaee12  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Apr 24 09:04:03 2021
    13 // Update Count     : 219
     12// Last Modified On : Tue Apr 27 22:00:30 2021
     13// Update Count     : 226
    1414//
    1515
     
    7171bool fail( ofstream & );
    7272int flush( ofstream & );
    73 void open( ofstream &, const char name[], const char mode[] );
     73void open( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w"
    7474void open( ofstream &, const char name[] );
    7575void close( ofstream & );
     
    8686
    8787void ?{}( ofstream & );
    88 void ?{}( ofstream &, const char name[], const char mode[] );
     88void ?{}( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w"
    8989void ?{}( ofstream &, const char name[] );
    9090void ^?{}( ofstream & );
     91
     92// private
     93static inline ofstream & nl$( ofstream & os ) { return nl( os ); } // remember basic_ostream nl
     94// public
     95ofstream & nl( ofstream & os );                                                 // override basic_ostream nl
    9196
    9297extern ofstream & sout, & stdout, & serr, & stderr;             // aliases
     
    111116bool getANL( ifstream & );
    112117void ends( ifstream & );
     118int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
     119
    113120bool fail( ifstream & is );
    114121int eof( ifstream & is );
    115 void open( ifstream & is, const char name[], const char mode[] );
     122void open( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r"
    116123void open( ifstream & is, const char name[] );
    117124void close( ifstream & is );
    118125ifstream & read( ifstream & is, char * data, size_t size );
    119126ifstream & ungetc( ifstream & is, char c );
    120 int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
     127
    121128void acquire( ifstream & is );
    122129void release( ifstream & is );
     
    129136
    130137void ?{}( ifstream & is );
    131 void ?{}( ifstream & is, const char name[], const char mode[] );
     138void ?{}( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r"
    132139void ?{}( ifstream & is, const char name[] );
    133140void ^?{}( ifstream & is );
  • libcfa/src/iostream.cfa

    re9c0b4c radaee12  
    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

    re9c0b4c radaee12  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Apr 24 09:28:56 2021
    13 // Update Count     : 393
     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 * );
     
    164164struct _Ostream_Manip {
    165165        T val;                                                                                          // polymorphic base-type
    166         int wd, pc;                                                                                     // width, precision
     166        int wd, pc;                                                                                     // width, precision: signed for computations
    167167        char base;                                                                                      // numeric base / floating-point style
    168168        union {
     
    192192        _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'x', { .all : 0 } }; } \
    193193        _Ostream_Manip(T) wd( unsigned int w, T val ) { return (_Ostream_Manip(T))@{ val, w, 0, CODE, { .all : 0 } }; } \
    194         _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 } }; } \
    195195        _Ostream_Manip(T) & wd( unsigned int w, _Ostream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \
    196         _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; } \
    197197        _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \
    198198        _Ostream_Manip(T) & upcase( _Ostream_Manip(T) & fmt ) { if ( fmt.base == 'x' || fmt.base == 'b' ) fmt.base -= 32; /* upper case */ return fmt; } \
     
    231231        _Ostream_Manip(T) eng( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.eng : true } }; } \
    232232        _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 char pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'f', { .flags.pc : true } }; } \
    234         _Ostream_Manip(T) ws( unsigned int w, unsigned char pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'g', { .flags.pc : true } }; } \
     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 } }; } \
    235235        _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 char 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 char pc, _Ostream_Manip(T) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; 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; } \
    238238        _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \
    239239        _Ostream_Manip(T) upcase( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'G', { .all : 0 } }; } \
     
    279279        _Ostream_Manip(const char *) hex( const char s[] ) { return (_Ostream_Manip(const char *))@{ s, 1, 0, 'x', { .all : 0 } }; }
    280280        _Ostream_Manip(const char *) wd( unsigned int w, const char s[] ) { return (_Ostream_Manip(const char *))@{ s, w, 0, 's', { .all : 0 } }; }
    281         _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 } }; }
    282282        _Ostream_Manip(const char *) & wd( unsigned int w, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; return fmt; }
    283         _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; }
    284284        _Ostream_Manip(const char *) & left( _Ostream_Manip(const char *) & fmt ) { fmt.flags.left = true; return fmt; }
    285285        _Ostream_Manip(const char *) & nobase( _Ostream_Manip(const char *) & fmt ) { fmt.flags.nobsdp = true; return fmt; }
     
    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
     
    391397
    392398static inline {
     399        _Istream_Cstr skip( const char scanset[] ) { return (_Istream_Cstr){ 0p, scanset, -1, { .all : 0 } }; }
    393400        _Istream_Cstr skip( unsigned int n ) { return (_Istream_Cstr){ 0p, 0p, n, { .all : 0 } }; }
    394         _Istream_Cstr skip( const char scanset[] ) { return (_Istream_Cstr){ 0p, scanset, -1, { .all : 0 } }; }
    395401        _Istream_Cstr incl( const char scanset[], char * s ) { return (_Istream_Cstr){ s, scanset, -1, { .flags.inex : false } }; }
    396402        _Istream_Cstr & incl( const char scanset[], _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = false; return fmt; }
     
    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 ); \
  • libcfa/src/strstream.cfa

    re9c0b4c radaee12  
    1010// Created On       : Thu Apr 22 22:24:35 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Apr 24 11:15:47 2021
    13 // Update Count     : 73
     12// Last Modified On : Tue Apr 27 20:59:53 2021
     13// Update Count     : 78
    1414//
    1515
     
    2323#include <unistd.h>                                                                             // sbrk, sysconf
    2424
     25
    2526// *********************************** strstream ***********************************
    2627
     
    2930
    3031// private
    31 bool sepPrt$( strstream & os ) { setNL$( os, false ); return os.sepOnOff$; }
    32 void sepReset$( strstream & os ) { os.sepOnOff$ = os.sepDefault$; }
    33 void sepReset$( strstream & os, bool reset ) { os.sepDefault$ = reset; os.sepOnOff$ = os.sepDefault$; }
    34 const char * sepGetCur$( strstream & os ) { return os.sepCur$; }
    35 void sepSetCur$( strstream & os, const char sepCur[] ) { os.sepCur$ = sepCur; }
    36 bool getNL$( strstream & os ) { return os.sawNL$; }
    37 void setNL$( strstream & os, bool state ) { os.sawNL$ = state; }
    38 bool getANL$( strstream & os ) { return os.nlOnOff$; }
    39 bool getPrt$( strstream & os ) { return os.prt$; }
    40 void setPrt$( strstream & os, bool state ) { os.prt$ = state; }
     32bool sepPrt$( ostrstream & os ) { setNL$( os, false ); return os.sepOnOff$; }
     33void sepReset$( ostrstream & os ) { os.sepOnOff$ = os.sepDefault$; }
     34void sepReset$( ostrstream & os, bool reset ) { os.sepDefault$ = reset; os.sepOnOff$ = os.sepDefault$; }
     35const char * sepGetCur$( ostrstream & os ) { return os.sepCur$; }
     36void sepSetCur$( ostrstream & os, const char sepCur[] ) { os.sepCur$ = sepCur; }
     37bool getNL$( ostrstream & os ) { return os.sawNL$; }
     38void setNL$( ostrstream & os, bool state ) { os.sawNL$ = state; }
     39bool getANL$( ostrstream & os ) { return os.nlOnOff$; }
     40bool getPrt$( ostrstream & os ) { return os.prt$; }
     41void setPrt$( ostrstream & os, bool state ) { os.prt$ = state; }
    4142
    4243// public
    43 void ?{}( strstream & os, char buf[], size_t size ) {
     44void ?{}( ostrstream & os, char buf[], size_t size ) {
    4445        os.buf$ = buf;
    4546        os.size$ = size;
     
    5556} // ?{}
    5657
    57 void sepOn( strstream & os ) { os.sepOnOff$ = ! getNL$( os ); }
    58 void sepOff( strstream & os ) { os.sepOnOff$ = false; }
     58void sepOn( ostrstream & os ) { os.sepOnOff$ = ! getNL$( os ); }
     59void sepOff( ostrstream & os ) { os.sepOnOff$ = false; }
    5960
    60 bool sepDisable( strstream & os ) {
     61bool sepDisable( ostrstream & os ) {
    6162        bool temp = os.sepDefault$;
    6263        os.sepDefault$ = false;
     
    6566} // sepDisable
    6667
    67 bool sepEnable( strstream & os ) {
     68bool sepEnable( ostrstream & os ) {
    6869        bool temp = os.sepDefault$;
    6970        os.sepDefault$ = true;
     
    7273} // sepEnable
    7374
    74 void nlOn( strstream & os ) { os.nlOnOff$ = true; }
    75 void nlOff( strstream & os ) { os.nlOnOff$ = false; }
     75void nlOn( ostrstream & os ) { os.nlOnOff$ = true; }
     76void nlOff( ostrstream & os ) { os.nlOnOff$ = false; }
    7677
    77 const char * sepGet( strstream & os ) { return os.separator$; }
    78 void sepSet( strstream & os, const char s[] ) {
     78const char * sepGet( ostrstream & os ) { return os.separator$; }
     79void sepSet( ostrstream & os, const char s[] ) {
    7980        assert( s );
    80         strncpy( os.separator$, s, strstream_sepSize - 1 );
    81         os.separator$[strstream_sepSize - 1] = '\0';
     81        strncpy( os.separator$, s, ostrstream_sepSize - 1 );
     82        os.separator$[ostrstream_sepSize - 1] = '\0';
    8283} // sepSet
    8384
    84 const char * sepGetTuple( strstream & os ) { return os.tupleSeparator$; }
    85 void sepSetTuple( strstream & os, const char s[] ) {
     85const char * sepGetTuple( ostrstream & os ) { return os.tupleSeparator$; }
     86void sepSetTuple( ostrstream & os, const char s[] ) {
    8687        assert( s );
    87         strncpy( os.tupleSeparator$, s, strstream_sepSize - 1 );
    88         os.tupleSeparator$[strstream_sepSize - 1] = '\0';
     88        strncpy( os.tupleSeparator$, s, ostrstream_sepSize - 1 );
     89        os.tupleSeparator$[ostrstream_sepSize - 1] = '\0';
    8990} // sepSet
    9091
    91 void ends( strstream & os ) {
     92void ends( ostrstream & os ) {
    9293        if ( getANL$( os ) ) nl( os );
    9394        else setPrt$( os, false );                                                      // turn off
    9495} // ends
    9596
    96 int fmt( strstream & os, const char format[], ... ) {
     97int fmt( ostrstream & os, const char format[], ... ) {
    9798        va_list args;
    9899        va_start( args, format );
    99100        int len = vsnprintf( os.buf$ + os.cursor$, os.size$ - os.cursor$, format, args );
     101        va_end( args );
    100102        os.cursor$ += len;
    101103        if ( os.cursor$ >= os.size$ ) {                                         // cursor exceeded buffer size?
    102                 #define fmtmsg IO_MSG "strstream truncated write, buffer too small.\n"
     104                #define fmtmsg IO_MSG "ostrstream truncated write, buffer too small.\n"
    103105                write( STDERR_FILENO, fmtmsg, sizeof(fmtmsg) - 1 );
    104106                abort();
    105107        } // if
    106         va_end( args );
    107108
    108109        setPrt$( os, true );                                                            // called in output cascade
     
    111112} // fmt
    112113
    113 int flush( strstream & ) {                                                              // match trait, not used
    114         return 0;
    115 } // flush
    116 
    117 strstream & write( strstream & os ) {
    118         return write( os, stdout );
    119 } // write
    120 strstream & write( strstream & os, FILE * stream ) {
     114ostrstream & write( ostrstream & os, FILE * stream ) {
    121115        if ( fwrite( os.buf$, 1, os.cursor$, stream ) != os.cursor$ ) {
    122                 #define writemsg IO_MSG "strstream write error.\n"
    123                 write( STDERR_FILENO, writemsg, sizeof(writemsg) - 1 );
     116                #define ostrwritemsg IO_MSG "ostrstream write error.\n"
     117                write( STDERR_FILENO, ostrwritemsg, sizeof(ostrwritemsg) - 1 );
    124118                abort();
    125119        } // if
     
    127121} // write
    128122
    129 strstream & sstr;
     123ostrstream & write( ostrstream & os ) {
     124        return write( os, stdout );
     125} // write
     126
     127
     128// *********************************** istrstream ***********************************
     129
     130
     131// public
     132void ?{}( istrstream & is, char buf[] ) {
     133        is.buf$ = buf;
     134        is.cursor$ = 0;
     135        is.nlOnOff$ = false;
     136} // ?{}
     137
     138bool getANL( istrstream & is ) { return is.nlOnOff$; }
     139void nlOn( istrstream & is ) { is.nlOnOff$ = true; }
     140void nlOff( istrstream & is ) { is.nlOnOff$ = false; }
     141
     142void ends( istrstream & is ) {
     143} // ends
     144
     145int eof( istrstream & is ) {
     146        return 0;
     147} // eof
     148
     149istrstream &ungetc( istrstream & is, char c ) {
     150        // if ( ungetc( c, (FILE *)(is.file$) ) == EOF ) {
     151        //      abort | IO_MSG "ungetc" | nl | strerror( errno );
     152        // } // if
     153        return is;
     154} // ungetc
     155
     156int fmt( istrstream & is, const char format[], ... ) {
     157        va_list args;
     158        va_start( args, format );
     159        // This does not work because vsscanf does not return buffer position.
     160        int len = vsscanf( is.buf$ + is.cursor$, format, args );
     161        va_end( args );
     162        if ( len == EOF ) {
     163                int j;
     164                printf( "X %d%n\n", len, &j );
     165        } // if
     166        is.cursor$ += len;
     167        return len;
     168} // fmt
    130169
    131170// Local Variables: //
  • libcfa/src/strstream.hfa

    re9c0b4c radaee12  
    1010// Created On       : Thu Apr 22 22:20:59 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Apr 24 11:17:33 2021
    13 // Update Count     : 37
     12// Last Modified On : Tue Apr 27 20:58:50 2021
     13// Update Count     : 41
    1414//
    1515
     
    2020
    2121
    22 // *********************************** strstream ***********************************
     22// *********************************** ostrstream ***********************************
    2323
    2424
    25 enum { strstream_sepSize = 16 };
    26 struct strstream {                                                                              // satisfied basic_ostream
     25enum { ostrstream_sepSize = 16 };
     26struct ostrstream {                                                                             // satisfied basic_ostream
    2727        char * buf$;
    2828        size_t size$;
     
    3434        bool sawNL$;
    3535        const char * sepCur$;
    36         char separator$[strstream_sepSize];
    37         char tupleSeparator$[strstream_sepSize];
    38 }; // strstream
     36        char separator$[ostrstream_sepSize];
     37        char tupleSeparator$[ostrstream_sepSize];
     38}; // ostrstream
    3939
    4040// Satisfies basic_ostream
    4141
    4242// private
    43 bool sepPrt$( strstream & );
    44 void sepReset$( strstream & );
    45 void sepReset$( strstream &, bool );
    46 const char * sepGetCur$( strstream & );
    47 void sepSetCur$( strstream &, const char [] );
    48 bool getNL$( strstream & );
    49 void setNL$( strstream &, bool );
    50 bool getANL$( strstream & );
    51 bool getPrt$( strstream & );
    52 void setPrt$( strstream &, bool );
     43bool sepPrt$( ostrstream & );
     44void sepReset$( ostrstream & );
     45void sepReset$( ostrstream &, bool );
     46const char * sepGetCur$( ostrstream & );
     47void sepSetCur$( ostrstream &, const char [] );
     48bool getNL$( ostrstream & );
     49void setNL$( ostrstream &, bool );
     50bool getANL$( ostrstream & );
     51bool getPrt$( ostrstream & );
     52void setPrt$( ostrstream &, bool );
    5353
    5454// public
    55 void sepOn( strstream & );
    56 void sepOff( strstream & );
    57 bool sepDisable( strstream & );
    58 bool sepEnable( strstream & );
    59 void nlOn( strstream & );
    60 void nlOff( strstream & );
     55void sepOn( ostrstream & );
     56void sepOff( ostrstream & );
     57bool sepDisable( ostrstream & );
     58bool sepEnable( ostrstream & );
     59void nlOn( ostrstream & );
     60void nlOff( ostrstream & );
    6161
    62 const char * sepGet( strstream & );
    63 void sepSet( strstream &, const char [] );
    64 const char * sepGetTuple( strstream & );
    65 void sepSetTuple( strstream &, const char [] );
     62const char * sepGet( ostrstream & );
     63void sepSet( ostrstream &, const char [] );
     64const char * sepGetTuple( ostrstream & );
     65void sepSetTuple( ostrstream &, const char [] );
    6666
    67 void ends( strstream & );
    68 int fmt( strstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
    69 int flush( strstream & );
     67void ends( ostrstream & );
     68int fmt( ostrstream &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
    7069
    71 strstream & write( strstream & os );                                    // use stdout, default value not working
    72 strstream & write( strstream & os, FILE * stream = stdout );
     70ostrstream & write( ostrstream & os, FILE * stream ); // FIX ME: use default = stdout
     71ostrstream & write( ostrstream & os );
    7372
    74 void ?{}( strstream &, char buf[], size_t size );
     73void ?{}( ostrstream &, char buf[], size_t size );
    7574
    76 extern strstream & sstr;
     75
     76// *********************************** istrstream ***********************************
     77
     78
     79struct istrstream {
     80        char * buf$;
     81        size_t cursor$;
     82        bool nlOnOff$;
     83}; // istrstream
     84
     85// Satisfies basic_istream
     86
     87// public
     88bool getANL( istrstream & );
     89void nlOn( istrstream & );
     90void nlOff( istrstream & );
     91void ends( istrstream & );
     92int fmt( istrstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
     93istrstream & ungetc( istrstream & is, char c );
     94int eof( istrstream & is );
     95
     96void ?{}( istrstream & is, char buf[] );
    7797
    7898// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.