Changeset ae0c1c3 for libcfa/src


Ignore:
Timestamp:
Apr 25, 2025, 7:08:53 PM (6 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
7d02d35, ecfa58be
Parents:
65bd3c2
Message:

Rewrote the iostream traits to have a single assertion each, a table containing function pointers. This is just an experiment right now. It seems that it does cause significant speed up of assertion resolution, but for some reason also seems to add a flat overhead that mostly eats up that saving.

Location:
libcfa/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/collections/string.cfa

    r65bd3c2 rae0c1c3  
    216216        }
    217217
    218         void ?|?( ostype & out, string s ) {
     218        void ?|?( ostype & out, string s ) with ( basic_ostream_table ) {
    219219                (ostype &)(out | (*s.inner)); ends( out );
    220220        }
     
    229229        } // ?|?
    230230
    231         void ?|?( ostype & os, _Ostream_Manip(string) f ) {
     231        void ?|?( ostype & os, _Ostream_Manip(string) f ) with ( basic_ostream_table ) {
    232232                (ostype &)(os | f); ends( os );
    233233        }
  • libcfa/src/collections/string_res.cfa

    r65bd3c2 rae0c1c3  
    201201forall( ostype & | basic_ostream( ostype ) )
    202202void ?|?( ostype & out, const string_res & s ) {
    203         (ostype &)(out | s); ends( out );
     203        (ostype &)(out | s);
     204        basic_ostream_table.ends( out );
    204205}
    205206
     
    249250
    250251forall( istype & | basic_istream( istype ) )
    251 istype & ?|?( istype & is, _Istream_Rquote f ) with( f.rstr ) {
     252istype & ?|?( istype & is, _Istream_Rquote f ) with( basic_istream_table, f.rstr ) {
    252253        if ( eof( is ) ) throwResume ExceptionInst( end_of_file );
    253254        int args;
  • libcfa/src/fstream.cfa

    r65bd3c2 rae0c1c3  
    202202} // nl
    203203
     204static basic_ostream_data(ofstream) ofstream_basic_data = {
     205        sepPrt$,
     206        sepReset$,
     207        sepReset$,
     208        sepGetCur$,
     209        sepSetCur$,
     210        getNL$,
     211        setNL$,
     212        getANL$,
     213        setANL$,
     214        getPrt$,
     215        setPrt$,
     216        nlOn,
     217        nlOff,
     218        sep,
     219        nosep,
     220        sepOn,
     221        sepOff,
     222        sepGet,
     223        sepSet,
     224        sepGetTuple,
     225        sepSetTuple,
     226        ends,
     227        fmt,
     228};
     229
     230basic_ostream_data(ofstream) const & basic_ostream_table = ofstream_basic_data;
     231
     232static ostream_data(ofstream) ofstream_data;
     233
     234// This should be an initializer like for the basic table.
     235// But, initialization of a structure with an inline structure doesn't work.
     236__attribute__((constructor(200)))
     237static void __ofstream_data_init__() {
     238        basic_ostream_data(ofstream) & basic = ofstream_data;
     239        basic.sepPrt$ = sepPrt$;
     240        basic.sepReset$ = (void(*)(ofstream&))sepReset$;
     241        basic.sepReset$ = (void(*)(ofstream&, bool))sepReset$;
     242        basic.sepGetCur$ = sepGetCur$;
     243        basic.sepSetCur$ = sepSetCur$;
     244        basic.getNL$ = getNL$;
     245        basic.setNL$ = setNL$;
     246        basic.getANL$ = getANL$;
     247        basic.setANL$ = setANL$;
     248        basic.getPrt$ = getPrt$;
     249        basic.setPrt$ = setPrt$;
     250        basic.nlOn = nlOn;
     251        basic.nlOff = nlOff;
     252        basic.sep = sep;
     253        basic.nosep = nosep;
     254        basic.sepOn = sepOn;
     255        basic.sepOff = sepOff;
     256        basic.sepGet = sepGet;
     257        basic.sepSet = sepSet;
     258        basic.sepGetTuple = sepGetTuple;
     259        basic.sepSetTuple = sepSetTuple;
     260        basic.ends = ends;
     261        basic.fmt = fmt;
     262        ofstream_data.fail = fail;
     263        ofstream_data.clearerr = clearerr;
     264        ofstream_data.flush = flush;
     265        ofstream_data.open = open;
     266        ofstream_data.close = close;
     267        ofstream_data.write = write;
     268}
     269
     270ostream_data(ofstream) const & ostream_table = ofstream_data;
    204271
    205272// *********************************** ifstream ***********************************
     
    211278        nlOnOff$ = false;                                                                       // => skip newlines when reading single characters
    212279} // ?{}
     280
     281static basic_istream_data(ifstream) ifstream_basic_data = {
     282        getANL$,
     283        setANL$,
     284        nlOn,
     285        nlOff,
     286        fmt,
     287        ungetc,
     288        eof,
     289        clearerr,
     290};
     291
     292basic_istream_data(ifstream) const & basic_istream_table = ifstream_basic_data;
     293
     294static istream_data(ifstream) ifstream_data;
     295
     296// This should be an initializer like for the basic table.
     297// But, initialization of a structure with an inline structure doesn't work.
     298__attribute__((constructor(200)))
     299static void __ifstream_data_init__() {
     300        basic_istream_data(ifstream) & basic = ifstream_data;
     301        basic.getANL$ = getANL$;
     302        basic.setANL$ = setANL$;
     303        basic.nlOn = nlOn;
     304        basic.nlOff = nlOff;
     305        basic.fmt = fmt;
     306        basic.ungetc = ungetc;
     307        basic.eof = eof;
     308        basic.clearerr = clearerr;
     309        ifstream_data.fail = fail;
     310        ifstream_data.open = (void(*)(ifstream &, const char *, const char *))open;
     311        ifstream_data.open = (void(*)(ifstream &, const char *))open;
     312        ifstream_data.close = close;
     313        ifstream_data.read = read;
     314}
     315
     316istream_data(ifstream) const & istream_table = ifstream_data;
    213317
    214318bool getANL$( ifstream & os ) { return os.nlOnOff$; }
  • libcfa/src/fstream.hfa

    r65bd3c2 rae0c1c3  
    3838
    3939// Satisfies ostream
     40extern basic_ostream_data(ofstream) const & basic_ostream_table;
     41extern ostream_data(ofstream) const & ostream_table;
    4042
    4143// private
     
    106108
    107109// Satisfies istream
     110extern basic_istream_data(ifstream) const & basic_istream_table;
     111extern istream_data(ifstream) const & istream_table;
    108112
    109113// private
  • libcfa/src/gmp.hfa

    r65bd3c2 rae0c1c3  
    263263        forall( ostype & | ostream( ostype ) ) {
    264264                ostype & ?|?( ostype & os, Int mp ) {
    265                         if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
     265                        ostream_data(ostype) const & table = ostream_table;
     266                        if ( table.sepPrt$( os ) ) table.fmt( os, "%s", table.sepGetCur$( os ) );
    266267                        gmp_printf( "%Zd", mp.mpz );
    267                         sep( os );
     268                        table.sep( os );
    268269                        return os;
    269270                } // ?|?
  • libcfa/src/iostream.cfa

    r65bd3c2 rae0c1c3  
    4242
    4343forall( ostype & | basic_ostream( ostype ) ) {
    44         ostype & ?|?( ostype & os, bool b ) {
     44        ostype & ?|?( ostype & os, bool b ) with ( basic_ostream_table ) {
    4545                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    4646                fmt( os, "%s", b ? "true" : "false" );
     
    4949        OSTYPE_VOID_IMPL( os, bool )
    5050
    51         ostype & ?|?( ostype & os, char c ) {
     51        ostype & ?|?( ostype & os, char c ) with ( basic_ostream_table ) {
    5252                fmt( os, "%c", c );
    5353                if ( c == '\n' ) setNL$( os, true );
     
    5656        OSTYPE_VOID_IMPL( os, char )
    5757
    58         ostype & ?|?( ostype & os, signed char sc ) {
     58        ostype & ?|?( ostype & os, signed char sc ) with ( basic_ostream_table ) {
    5959                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    6060                fmt( os, "%'hhd", sc );
     
    6363        OSTYPE_VOID_IMPL( os, signed char )
    6464
    65         ostype & ?|?( ostype & os, unsigned char usc ) {
     65        ostype & ?|?( ostype & os, unsigned char usc ) with ( basic_ostream_table ) {
    6666                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    6767                fmt( os, "%'hhu", usc );
     
    7070        OSTYPE_VOID_IMPL( os, unsigned char )
    7171
    72         ostype & ?|?( ostype & os, short int si ) {
     72        ostype & ?|?( ostype & os, short int si ) with ( basic_ostream_table ) {
    7373                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    7474                fmt( os, "%'hd", si );
     
    7777        OSTYPE_VOID_IMPL( os, short int )
    7878
    79         ostype & ?|?( ostype & os, unsigned short int usi ) {
     79        ostype & ?|?( ostype & os, unsigned short int usi ) with ( basic_ostream_table ) {
    8080                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    8181                fmt( os, "%'hu", usi );
     
    8484        OSTYPE_VOID_IMPL( os, unsigned short int )
    8585
    86         ostype & ?|?( ostype & os, int i ) {
     86        ostype & ?|?( ostype & os, int i ) with ( basic_ostream_table ) {
    8787                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    8888                fmt( os, "%'d", i );
     
    9191        OSTYPE_VOID_IMPL( os, int )
    9292
    93         ostype & ?|?( ostype & os, unsigned int ui ) {
     93        ostype & ?|?( ostype & os, unsigned int ui ) with ( basic_ostream_table ) {
    9494                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    9595                fmt( os, "%'u", ui );
     
    9898        OSTYPE_VOID_IMPL( os, unsigned int )
    9999
    100         ostype & ?|?( ostype & os, long int li ) {
     100        ostype & ?|?( ostype & os, long int li ) with ( basic_ostream_table ) {
    101101                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    102102                fmt( os, "%'ld", li );
     
    105105        OSTYPE_VOID_IMPL( os, long int )
    106106
    107         ostype & ?|?( ostype & os, unsigned long int uli ) {
     107        ostype & ?|?( ostype & os, unsigned long int uli ) with ( basic_ostream_table ) {
    108108                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    109109                fmt( os, "%'lu", uli );
     
    112112        OSTYPE_VOID_IMPL( os, unsigned long int )
    113113
    114         ostype & ?|?( ostype & os, long long int lli ) {
     114        ostype & ?|?( ostype & os, long long int lli ) with ( basic_ostream_table ) {
    115115                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    116116                fmt( os, "%'lld", lli );
     
    119119        OSTYPE_VOID_IMPL( os, long long int )
    120120
    121         ostype & ?|?( ostype & os, unsigned long long int ulli ) {
     121        ostype & ?|?( ostype & os, unsigned long long int ulli ) with ( basic_ostream_table ) {
    122122                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    123123                fmt( os, "%'llu", ulli );
     
    130130        #define P10_UINT64 10_000_000_000_000_000_000_ULL       // 19 zeroes
    131131
    132         static inline void base10_128( ostype & os, unsigned int128 val ) {
     132        static inline void base10_128( ostype & os, unsigned int128 val ) with ( basic_ostream_table ) {
    133133                #if defined(__GNUC__) && __GNUC_PREREQ(7,0)             // gcc version >= 7
    134134                if ( val > P10_UINT64 ) {
     
    143143        } // base10_128
    144144
    145         static inline void base10_128( ostype & os, int128 val ) {
     145        static inline void base10_128( ostype & os, int128 val ) with ( basic_ostream_table ) {
    146146                if ( val < 0 ) {
    147147                        fmt( os, "-" );                                                         // leading negative sign
     
    151151        } // base10_128
    152152
    153         ostype & ?|?( ostype & os, int128 llli ) {
     153        ostype & ?|?( ostype & os, int128 llli ) with ( basic_ostream_table ) {
    154154                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    155155                base10_128( os, llli );
     
    158158        OSTYPE_VOID_IMPL( os, int128 )
    159159
    160         ostype & ?|?( ostype & os, unsigned int128 ullli ) {
     160        ostype & ?|?( ostype & os, unsigned int128 ullli ) with ( basic_ostream_table ) {
    161161                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    162162                base10_128( os, ullli );
     
    181181                }
    182182
    183         ostype & ?|?( ostype & os, float f ) {
     183        ostype & ?|?( ostype & os, float f ) with ( basic_ostream_table ) {
    184184                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    185185                PRINT_WITH_DP( os, "%'g", f );
     
    188188        OSTYPE_VOID_IMPL( os, float )
    189189
    190         ostype & ?|?( ostype & os, double d ) {
     190        ostype & ?|?( ostype & os, double d ) with ( basic_ostream_table ) {
    191191                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    192192                PRINT_WITH_DP( os, "%'.*lg", d, DBL_DIG );
     
    195195        OSTYPE_VOID_IMPL( os, double )
    196196
    197         ostype & ?|?( ostype & os, long double ld ) {
     197        ostype & ?|?( ostype & os, long double ld ) with ( basic_ostream_table ) {
    198198                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    199199                PRINT_WITH_DP( os, "%'.*Lg", ld, LDBL_DIG );
     
    202202        OSTYPE_VOID_IMPL( os, long double )
    203203
    204         ostype & ?|?( ostype & os, float _Complex fc ) {
     204        ostype & ?|?( ostype & os, float _Complex fc ) with ( basic_ostream_table ) {
    205205                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    206206//              os | crealf( fc ) | nonl;
     
    212212        OSTYPE_VOID_IMPL( os, float _Complex )
    213213
    214         ostype & ?|?( ostype & os, double _Complex dc ) {
     214        ostype & ?|?( ostype & os, double _Complex dc ) with ( basic_ostream_table ) {
    215215                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    216216//              os | creal( dc ) | nonl;
     
    222222        OSTYPE_VOID_IMPL( os, double _Complex )
    223223
    224         ostype & ?|?( ostype & os, long double _Complex ldc ) {
     224        ostype & ?|?( ostype & os, long double _Complex ldc ) with ( basic_ostream_table ) {
    225225                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    226226//              os | creall( ldc ) || nonl;
     
    232232        OSTYPE_VOID_IMPL( os, long double _Complex )
    233233
    234         ostype & ?|?( ostype & os, const char s[] ) {
     234        ostype & ?|?( ostype & os, const char s[] ) with ( basic_ostream_table ) {
    235235                enum { Open = 1, Close, OpenClose };
    236236                static const unsigned char mask[256] @= {               // 256 covers all Latin-1 characters
     
    295295//      } // ?|?
    296296
    297         ostype & ?|?( ostype & os, const void * p ) {
     297        ostype & ?|?( ostype & os, const void * p ) with ( basic_ostream_table ) {
    298298                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) );
    299299                fmt( os, "%p", p );
     
    306306                return manip( os );
    307307        } // ?|?
    308         void ?|?( ostype & os, ostype & (* manip)( ostype & ) ) {
     308        void ?|?( ostype & os, ostype & (* manip)( ostype & ) ) with ( basic_ostream_table ) {
    309309                manip( os );
    310310                if ( getPrt$( os ) ) ends( os );                                // something printed ?
     
    312312        } // ?|?
    313313
    314         ostype & nl( ostype & os ) {
     314        ostype & nl( ostype & os ) with ( basic_ostream_table ) {
    315315                (ostype &)(os | '\n');
    316316                setPrt$( os, false );                                                   // turn off
     
    319319        } // nl
    320320
    321         ostype & nonl( ostype & os ) {
     321        ostype & nonl( ostype & os ) with ( basic_ostream_table ) {
    322322                setPrt$( os, false );                                                   // turn off
    323323                return os;
    324324        } // nonl
    325325
    326         ostype & nlOn( ostype & os ) {
     326        ostype & nlOn( ostype & os ) with ( basic_ostream_table ) {
    327327                nlOn( os );                                                                             // call void returning
    328328                return os;
    329329        } // nlOn
    330330
    331         ostype & nlOff( ostype & os ) {
     331        ostype & nlOff( ostype & os ) with ( basic_ostream_table ) {
    332332                nlOff( os );                                                                    // call void returning
    333333                return os;
    334334        } // nlOff
    335335
    336         ostype & sepVal( ostype & os ) {
     336        ostype & sepVal( ostype & os ) with ( basic_ostream_table ) {
    337337                return (ostype &)(os | sepGet( os ));
    338338        } // sepVal
    339339
    340         ostype & sepTupleVal( ostype & os ) {
     340        ostype & sepTupleVal( ostype & os ) with ( basic_ostream_table ) {
    341341                return os | sepGetTuple( os );
    342342        } // sepTupleVal
    343343
    344         ostype & sep( ostype & os ) {
     344        ostype & sep( ostype & os ) with ( basic_ostream_table ) {
    345345                sep( os );                                                                              // call void returning
    346346                return os;
    347347        } // sep
    348348
    349         ostype & nosep( ostype & os ) {
     349        ostype & nosep( ostype & os ) with ( basic_ostream_table ) {
    350350                nosep( os );                                                                    // call void returning
    351351                return os;
    352352        } // nosep
    353353
    354         ostype & sepOn( ostype & os ) {
     354        ostype & sepOn( ostype & os ) with ( basic_ostream_table ) {
    355355                sepOn( os );                                                                    // call void returning
    356356                return os;
    357357        } // sepOn
    358358
    359         ostype & sepOff( ostype & os ) {
     359        ostype & sepOff( ostype & os ) with ( basic_ostream_table ) {
    360360                sepOff( os );                                                                   // call void returning
    361361                return os;
     
    365365// tuples
    366366forall( ostype &, T, Params... | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) {
    367         ostype & ?|?( ostype & os, T arg, Params rest ) {
     367        ostype & ?|?( ostype & os, T arg, Params rest ) with ( basic_ostream_table ) {
    368368                (ostype &)(os | arg);                                                   // print first argument
    369369                sepSetCur$( os, sepGetTuple( os ) );                    // switch to tuple separator
     
    372372                return os;
    373373        } // ?|?
    374         void ?|?( ostype & os, T arg, Params rest ) {
     374        void ?|?( ostype & os, T arg, Params rest ) with ( basic_ostream_table ) {
    375375                // (ostype &)(?|?( os, arg, rest )); ends( os );
    376376                (ostype &)(os | arg);                                                   // print first argument
     
    405405#define INTEGRAL_FMT_IMPL( T, IFMTNP, IFMTP ) \
    406406forall( ostype & | basic_ostream( ostype ) ) { \
    407         ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \
     407        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) with ( basic_ostream_table ) { \
    408408                if ( sepPrt$( os ) ) fmt( os, "%s", sepGetCur$( os ) ); \
    409409\
     
    653653        } /* eng */ \
    654654\
    655         ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) { \
     655        ostype & ?|?( ostype & os, _Ostream_Manip(T) f ) with ( basic_ostream_table ) { \
    656656                enum { size = 48 }; \
    657657                char buf[size]; \
     
    692692
    693693forall( ostype & | basic_ostream( ostype ) ) {
    694         ostype & ?|?( ostype & os, _Ostream_Manip(char) f ) {
     694        ostype & ?|?( ostype & os, _Ostream_Manip(char) f ) with ( basic_ostream_table ) {
    695695                if ( f.base != 'c' ) {                                                  // bespoke binary/octal/hex format
    696696                        _Ostream_Manip(unsigned char) fmtuc @= { f.val, f.wd, f.pc, f.base, {'\0'} };
     
    724724
    725725forall( ostype & | basic_ostream( ostype ) ) {
    726         ostype & ?|?( ostype & os, _Ostream_Manip(const char *) f ) {
     726        ostype & ?|?( ostype & os, _Ostream_Manip(const char *) f ) with ( basic_ostream_table ) {
    727727                if ( ! f.val ) return os;                                               // null pointer ?
    728728
     
    776776
    777777forall( istype & | basic_istream( istype ) ) {
    778         istype & ?|?( istype & is, bool & b ) {
     778        istype & ?|?( istype & is, bool & b ) with ( basic_istream_table ) {
    779779                int len = -1;                                                                   // len not set if no match
    780780                fmt( is, " " );                                                                 // remove leading whitespace
     
    792792        } // ?|?
    793793
    794         istype & ?|?( istype & is, char & c ) {
     794        istype & ?|?( istype & is, char & c ) with ( basic_istream_table ) {
    795795                char temp;
    796796                for () {
     
    804804        } // ?|?
    805805
    806         istype & ?|?( istype & is, signed char & sc ) {
     806        istype & ?|?( istype & is, signed char & sc ) with ( basic_istream_table ) {
    807807                int args = fmt( is, "%hhi", &sc );                              // can be multiple characters (100)
    808808                if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     
    811811        } // ?|?
    812812
    813         istype & ?|?( istype & is, unsigned char & usc ) {
     813        istype & ?|?( istype & is, unsigned char & usc ) with ( basic_istream_table ) {
    814814                int args = fmt( is, "%hhi", &usc );                             // can be multiple characters (-100)
    815815                if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     
    818818        } // ?|?
    819819
    820         istype & ?|?( istype & is, short int & si ) {
     820        istype & ?|?( istype & is, short int & si ) with ( basic_istream_table ) {
    821821                int args = fmt( is, "%hi", &si );                               // can be called with EOF on
    822822                if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     
    825825        } // ?|?
    826826
    827         istype & ?|?( istype & is, unsigned short int & usi ) {
     827        istype & ?|?( istype & is, unsigned short int & usi ) with ( basic_istream_table ) {
    828828                int args = fmt( is, "%hi", &usi );                              // can be called with EOF on
    829829                if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     
    832832        } // ?|?
    833833
    834         istype & ?|?( istype & is, int & i ) {
     834        istype & ?|?( istype & is, int & i ) with ( basic_istream_table ) {
    835835                int args = fmt( is, "%i", &i );                                 // can be called with EOF on
    836836                if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     
    839839        } // ?|?
    840840
    841         istype & ?|?( istype & is, unsigned int & ui ) {
     841        istype & ?|?( istype & is, unsigned int & ui ) with ( basic_istream_table ) {
    842842                int args = fmt( is, "%i", &ui );                                // can be called with EOF on
    843843                if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     
    846846        } // ?|?
    847847
    848         istype & ?|?( istype & is, long int & li ) {
     848        istype & ?|?( istype & is, long int & li ) with ( basic_istream_table ) {
    849849                int args = fmt( is, "%li", &li );                               // can be called with EOF on
    850850                if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     
    853853        } // ?|?
    854854
    855         istype & ?|?( istype & is, unsigned long int & ulli ) {
     855        istype & ?|?( istype & is, unsigned long int & ulli ) with ( basic_istream_table ) {
    856856                int args = fmt( is, "%li", &ulli );                             // can be called with EOF on
    857857                if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     
    860860        } // ?|?
    861861
    862         istype & ?|?( istype & is, long long int & lli ) {
     862        istype & ?|?( istype & is, long long int & lli ) with ( basic_istream_table ) {
    863863                int args = fmt( is, "%lli", &lli );                             // can be called with EOF on
    864864                if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     
    867867        } // ?|?
    868868
    869         istype & ?|?( istype & is, unsigned long long int & ulli ) {
     869        istype & ?|?( istype & is, unsigned long long int & ulli ) with ( basic_istream_table ) {
    870870                int args = fmt( is, "%lli", &ulli );                    // can be called with EOF on
    871871                if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     
    879879        } // ?|?
    880880
    881         istype & ?|?( istype & is, unsigned int128 & ullli ) {
     881        istype & ?|?( istype & is, unsigned int128 & ullli ) with ( basic_istream_table ) {
    882882                char s[40];
    883883                bool sign = false;
     
    896896        #endif // __SIZEOF_INT128__
    897897
    898         istype & ?|?( istype & is, float & f ) {
     898        istype & ?|?( istype & is, float & f ) with ( basic_istream_table ) {
    899899                int args = fmt( is, "%f", &f );                                 // can be called with EOF on
    900900                if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     
    903903        } // ?|?
    904904
    905         istype & ?|?( istype & is, double & d ) {
     905        istype & ?|?( istype & is, double & d ) with ( basic_istream_table ) {
    906906                int args = fmt( is, "%lf", &d );                                // can be called with EOF on
    907907                if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     
    910910        } // ?|?
    911911
    912         istype & ?|?( istype & is, long double & ld ) {
     912        istype & ?|?( istype & is, long double & ld ) with ( basic_istream_table ) {
    913913                int args = fmt( is, "%Lf", &ld );                               // can be called with EOF on
    914914                if ( ! eof( is ) && args != 1 ) throwResume ExceptionInst( missing_data );
     
    917917        } // ?|?
    918918
    919         istype & ?|?( istype & is, float _Complex & fc ) {
     919        istype & ?|?( istype & is, float _Complex & fc ) with ( basic_istream_table ) {
    920920                float re, im;
    921921                int args = fmt( is, "%f%fi", &re, &im );                // can be called with EOF on
     
    926926        } // ?|?
    927927
    928         istype & ?|?( istype & is, double _Complex & dc ) {
     928        istype & ?|?( istype & is, double _Complex & dc ) with ( basic_istream_table ) {
    929929                double re, im;
    930930                int args = fmt( is, "%lf%lfi", &re, &im );              // can be called with EOF on
     
    935935        } // ?|?
    936936
    937         istype & ?|?( istype & is, long double _Complex & ldc ) {
     937        istype & ?|?( istype & is, long double _Complex & ldc ) with ( basic_istream_table ) {
    938938                long double re, im;
    939939                int args = fmt( is, "%Lf%Lfi", &re, &im );              // can be called with EOF on
     
    944944        } // ?|?
    945945
    946         istype & ?|?( istype & is, const char fmt[] ) {         // match text
     946        istype & ?|?( istype & is, const char fmt[] ) with ( basic_istream_table ) {            // match text
    947947                size_t len = strlen( fmt );
    948948                char fmtstr[len + 16];
     
    966966        } // ?|?
    967967
    968         istype & nl( istype & is ) {
     968        istype & nl( istype & is ) with ( basic_istream_table ) {
    969969                fmt( is, "%*[^\n]" );                                                   // ignore characters to newline
    970970                if ( ! eof( is ) ) fmt( is, "%*c" );                    // read newline
     
    972972        } // nl
    973973
    974         istype & nlOn( istype & is ) {
     974        istype & nlOn( istype & is ) with ( basic_istream_table ) {
    975975                nlOn( is );                                                                             // call void returning
    976976                return is;
    977977        } // nlOn
    978978
    979         istype & nlOff( istype & is ) {
     979        istype & nlOff( istype & is ) with ( basic_istream_table ) {
    980980                nlOff( is );                                                                    // call void returning
    981981                return is;
     
    986986
    987987forall( istype & | basic_istream( istype ) ) {
    988         istype & ?|?( istype & is, _Istream_Cskip f ) {
     988        istype & ?|?( istype & is, _Istream_Cskip f ) with ( basic_istream_table ) {
    989989                if ( eof( is ) ) throwResume ExceptionInst( end_of_file );
    990990                if ( f.scanset ) {
     
    10061006        }
    10071007
    1008         istype & ?|?( istype & is, _Istream_Cquote f ) with( f.cstr ) {
     1008        istype & ?|?( istype & is, _Istream_Cquote f ) with( basic_istream_table, f.cstr ) {
    10091009                if ( eof( is ) ) throwResume ExceptionInst( end_of_file );
    10101010                int args;
     
    10311031        }
    10321032
    1033         istype & ?|?( istype & is, _Istream_Cstr f ) with( f.cstr ) {
     1033        istype & ?|?( istype & is, _Istream_Cstr f ) with( basic_istream_table, f.cstr ) {
     1034                assert(eof);
    10341035                if ( eof( is ) ) throwResume ExceptionInst( end_of_file );
    10351036                const char * scanset;
     
    11391140#define INPUT_FMT_IMPL( T, CODE ) \
    11401141forall( istype & | basic_istream( istype ) ) { \
    1141         istype & ?|?( istype & is, _Istream_Manip(T) f ) { \
     1142        istype & ?|?( istype & is, _Istream_Manip(T) f ) with ( basic_istream_table ) { \
    11421143                enum { size = 16 }; \
    11431144                char fmtstr[size]; \
     
    12031204
    12041205forall( istype & | istream( istype ), E | CfaEnum( E ) | Serial( E ) )
    1205 istype & ?|?( istype & is, E & e ) {
     1206istype & ?|?( istype & is, E & e ) with ( basic_istream_table ) {
    12061207//      if ( eof( is ) ) throwResume ExceptionInst( end_of_file );
    12071208
  • libcfa/src/iostream.hfa

    r65bd3c2 rae0c1c3  
    2222
    2323forall( ostype & )
     24struct basic_ostream_data {
     25        // 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 & );                                                     // get newline
     32        bool (*setNL$)( ostype &, bool );                                               // set newline
     33        bool (*getANL$)( ostype & );                                                    // get auto newline (on/off)
     34        bool (*setANL$)( ostype &, bool );                                              // set auto newline (on/off), and return previous state
     35        bool (*getPrt$)( ostype & );                                                    // get fmt called in output cascade
     36        bool (*setPrt$)( ostype &, bool );                                              // set fmt called in output cascade
     37        // public
     38        void (*nlOn)( ostype & );                                                               // turn auto-newline state on
     39        void (*nlOff)( ostype & );                                                              // turn auto-newline state off
     40
     41        void (*sep)( ostype & );                                                                // turn separator state on
     42        void (*nosep)( ostype & );                                                              // turn separator state off
     43        bool (*sepOn)( ostype & );                                                              // set default state to on, and return previous state
     44        bool (*sepOff)( ostype & );                                                     // set default state to off, and return previous state
     45        const char * (*sepGet)( ostype & );                                     // get separator string
     46        void (*sepSet)( ostype &, const char [] );                              // set separator to string (15 character maximum)
     47        const char * (*sepGetTuple)( ostype & );                                // get tuple separator string
     48        void (*sepSetTuple)( ostype &, const char [] );         // set tuple separator to string (15 character maximum)
     49
     50        void (*ends)( ostype & );                                                               // end of output statement
     51        int (*fmt)( ostype &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
     52}; // basic_ostream
     53
     54forall( ostype & )
     55struct ostream_data {
     56        inline basic_ostream_data( ostype );
     57        bool (*fail)( ostype & );                                                               // operation failed?
     58        void (*clearerr)( ostype & );
     59        int (*flush)( ostype & );
     60        void (*open)( ostype &, const char name[], const char mode[] );
     61        void (*close)( ostype & );
     62        ostype & (*write)( ostype &, const char [], size_t );
     63}; // ostream
     64
     65forall( ostype & )
    2466trait basic_ostream {
    25         // 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 & );                                                        // get newline
    32         bool setNL$( ostype &, bool );                                          // set newline
    33         bool getANL$( ostype & );                                                       // get auto newline (on/off)
    34         bool setANL$( ostype &, bool );                                         // set auto newline (on/off), and return previous state
    35         bool getPrt$( ostype & );                                                       // get fmt called in output cascade
    36         bool setPrt$( ostype &, bool );                                         // set fmt called in output cascade
    37         // public
    38         void nlOn( ostype & );                                                          // turn auto-newline state on
    39         void nlOff( ostype & );                                                         // turn auto-newline state off
    40 
    41         void sep( ostype & );                                                           // turn separator state on
    42         void nosep( ostype & );                                                         // turn separator state off
    43         bool sepOn( ostype & );                                                         // set default state to on, and return previous state
    44         bool sepOff( ostype & );                                                        // set default state to off, and return previous state
    45         const char * sepGet( ostype & );                                        // get separator string
    46         void sepSet( ostype &, const char [] );                         // set separator to string (15 character maximum)
    47         const char * sepGetTuple( ostype & );                           // get tuple separator string
    48         void sepSetTuple( ostype &, const char [] );            // set tuple separator to string (15 character maximum)
    49 
    50         void ends( ostype & );                                                          // end of output statement
    51         int fmt( ostype &, const char format[], ... ) __attribute__(( format(printf, 2, 3) ));
    52 }; // basic_ostream
     67        basic_ostream_data(ostype) const & basic_ostream_table;
     68};
    5369
    5470forall( ostype & | basic_ostream( ostype ) )
    5571trait ostream {
    56         bool fail( ostype & );                                                          // operation failed?
    57         void clearerr( ostype & );
    58         int flush( ostype & );
    59         void open( ostype &, const char name[], const char mode[] );
    60         void close( ostype & );
    61         ostype & write( ostype &, const char [], size_t );
    62 }; // ostream
     72        ostream_data(ostype) const & ostream_table;
     73};
    6374
    6475// forall( T )
     
    7788#define OSTYPE_VOID_IMPL( os, T ) \
    7889        void ?|?( ostype & os, T t ) { \
    79                 (ostype &)(os | t); ends( os ); \
     90                (ostype &)(os | t); \
     91                basic_ostream_table.ends( os ); \
    8092        } // ?|?
    8193
     
    308320
    309321forall( istype & )
     322struct basic_istream_data {
     323        // private
     324        bool (*getANL$)( istype & );                                                    // get scan newline (on/off)
     325        bool (*setANL$)( istype &, bool );                                              // set scan newline (on/off)
     326        // public
     327        void (*nlOn)( istype & );                                                               // read newline
     328        void (*nlOff)( istype & );                                                              // scan newline
     329        int (*fmt)( istype &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
     330        istype & (*ungetc)( char, istype & );
     331        bool (*eof)( istype & );
     332        void (*clearerr)( istype & );
     333}; // basic_istream
     334
     335forall( istype & )
     336struct istream_data {
     337        inline basic_istream_data( istype );
     338        bool (*fail)( istype & );
     339        void (*open)( istype & is, const char name[], const char mode[] );
     340        void (*open)( istype & is, const char name[] );
     341        void (*close)( istype & is );
     342        istype & (*read)( istype &, char [], size_t );
     343}; // istream
     344
     345forall( istype & )
    310346trait basic_istream {
    311         // private
    312         bool getANL$( istype & );                                                       // get scan newline (on/off)
    313         bool setANL$( istype &, bool );                                         // set scan newline (on/off)
    314         // public
    315         void nlOn( istype & );                                                          // read newline
    316         void nlOff( istype & );                                                         // scan newline
    317         int fmt( istype &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
    318         istype & ungetc( char, istype & );
    319         bool eof( istype & );
    320         void clearerr( istype & );
    321 }; // basic_istream
     347        basic_istream_data(istype) const & basic_istream_table;
     348};
    322349
    323350forall( istype & | basic_istream( istype ) )
    324351trait istream {
    325         bool fail( istype & );
    326         void open( istype & is, const char name[], const char mode[] );
    327         void open( istype & is, const char name[] );
    328         void close( istype & is );
    329         istype & read( istype &, char [], size_t );
    330 }; // istream
     352        istream_data(istype) const & istream_table;
     353};
    331354
    332355forall( T )
  • libcfa/src/strstream.cfa

    r65bd3c2 rae0c1c3  
    2828// *********************************** strstream ***********************************
    2929
     30static basic_ostream_data(ostrstream) ostrstream_basic_data = {
     31        sepPrt$,
     32        sepReset$,
     33        sepReset$,
     34        sepGetCur$,
     35        sepSetCur$,
     36        getNL$,
     37        setNL$,
     38        getANL$,
     39        setANL$,
     40        getPrt$,
     41        setPrt$,
     42        nlOn,
     43        nlOff,
     44        sep,
     45        nosep,
     46        sepOn,
     47        sepOff,
     48        sepGet,
     49        sepSet,
     50        sepGetTuple,
     51        sepSetTuple,
     52        ends,
     53        fmt,
     54};
     55
     56basic_ostream_data(ostrstream) const & basic_ostream_table = ostrstream_basic_data;
    3057
    3158#define IO_MSG "I/O error: "
     
    130157
    131158// *********************************** istrstream ***********************************
     159
     160static basic_istream_data(istrstream) istrstream_basic_data = {
     161        getANL$,
     162        setANL$,
     163        nlOn,
     164        nlOff,
     165        fmt,
     166        ungetc,
     167        eof,
     168        clearerr,
     169};
     170
     171basic_istream_data(istrstream) const & basic_istream_data = istrstream_basic_data;
    132172
    133173// private
  • libcfa/src/strstream.hfa

    r65bd3c2 rae0c1c3  
    3939
    4040// Satisfies basic_ostream
     41extern basic_ostream_data(ostrstream) const & basic_ostream_table;
    4142
    4243// private
     
    9091
    9192// Satisfies basic_istream
     93extern basic_istream_data(istrstream) const & basic_istream_table;
    9294
    9395// private
Note: See TracChangeset for help on using the changeset viewer.