Changes in / [4d2d7e27:278e162]


Ignore:
Files:
21 edited

Legend:

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

    r4d2d7e27 r278e162  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Sep  2 12:05:57 2023
    13 // Update Count     : 206
     12// Last Modified On : Wed Oct 18 21:52:09 2023
     13// Update Count     : 208
    1414//
    1515
     
    138138
    139139void ?|?( ifstream & in, _Istream_Sstr f ) {
    140     (ifstream &)(in | f); ends( in );
     140    (ifstream &)(in | f);
    141141}
    142142
  • libcfa/src/collections/string_res.cfa

    r4d2d7e27 r278e162  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 14 18:06:01 2023
    13 // Update Count     : 12
     12// Last Modified On : Wed Oct 18 21:54:54 2023
     13// Update Count     : 15
    1414//
    1515
     
    236236        // get bytes
    237237        try {
     238                        *(temp.Handle.ulink->EndVbyte) = '\0';   // pre-assign empty cstring
    238239            in | wdi( lenReadable, temp.Handle.ulink->EndVbyte );
    239240        } catch (cstring_length*) {
     
    247248    }
    248249
    249     s = temp;
     250        if ( temp.Handle.lnth > 0 ) s = temp;
    250251    return in;
    251252}
    252253
    253254void ?|?( ifstream & in, string_res & this ) {
    254     (ifstream &)(in | this); ends( in );
     255    (ifstream &)(in | this);
    255256}
    256257
     
    268269        cstr[wd] = '\0';                                                                        // guard null terminate string
    269270        try {
     271                cstr[0] = '\0';                                                                 // pre-assign as empty cstring
    270272                is | cf;
    271273        } catch( cstring_length * ) {
    272274                cont = true;
    273275        } finally {
    274         if ( ! cf.flags.ignore ) *(f.s) = cstr;                 // ok to initialize string
     276                if ( ! cf.flags.ignore &&                                               // ok to initialize string
     277                                cstr[0] != '\0' ) {                                             // something was read
     278                        *(f.s) = cstr;
     279                }
    275280        } // try
    276281        for ( ; cont; )  {                                                                      // overflow read ?
    277282                cont = false;
    278283                try {
     284                        cstr[0] = '\0';                                                         // pre-assign as empty cstring
    279285                        is | cf;
    280286                } catch( cstring_length * ) {
    281287                        cont = true;                                                            // continue not allowed
    282288                } finally {
    283                         if ( ! cf.flags.ignore ) *(f.s) += cstr;        // build string chunk at a time
     289                        if ( ! cf.flags.ignore &&
     290                                        cstr[0] != '\0' ) {                                     // something was read
     291                                *(f.s) += cstr;                                                 // build string chunk at a time
     292                        }
    284293                } // try
    285294        } // for
     
    288297
    289298void ?|?( ifstream & in, _Istream_Rstr f ) {
    290     (ifstream &)(in | f); ends( in );
     299    (ifstream &)(in | f);
    291300}
    292301
  • libcfa/src/concurrency/channel.hfa

    r4d2d7e27 r278e162  
    2828    unlock( lock );
    2929    park();
     30    __atomic_thread_fence( __ATOMIC_SEQ_CST );
    3031    return sn.extra == 0p;
    3132}
  • libcfa/src/fstream.cfa

    r4d2d7e27 r278e162  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Aug 18 10:41:17 2023
    13 // Update Count     : 541
     12// Last Modified On : Wed Oct 18 22:05:54 2023
     13// Update Count     : 549
    1414//
    1515
     
    230230void nlOff( ifstream & os ) { os.nlOnOff$ = false; }
    231231
    232 void ends( ifstream & is ) {}
    233 
    234232bool eof( ifstream & is ) { return feof( (FILE *)(is.file$) ) != 0; }
    235233
     
    311309        } // if
    312310        va_end( args );
     311//      if ( len == 0 ) throw ExceptionInst( missing_data );
    313312        return len;
    314313} // fmt
  • libcfa/src/fstream.hfa

    r4d2d7e27 r278e162  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Aug 18 10:41:15 2023
    13 // Update Count     : 258
     12// Last Modified On : Wed Oct 18 20:30:12 2023
     13// Update Count     : 261
    1414//
    1515
     
    117117void nlOn( ifstream & );
    118118void nlOff( ifstream & );
    119 void ends( ifstream & );
    120119int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
     120ifstream & ungetc( ifstream & is, char c );
     121bool eof( ifstream & is );
    121122
    122123bool fail( ifstream & is );
    123124void clear( ifstream & );
    124 bool eof( ifstream & is );
    125125void open( ifstream & is, const char name[], const char mode[] ); // FIX ME: use default = "r"
    126126void open( ifstream & is, const char name[] );
    127127void close( ifstream & is );
    128 
    129128ifstream & read( ifstream & is, char data[], size_t size );
    130 ifstream & ungetc( ifstream & is, char c );
    131129
    132130void ?{}( ifstream & is );
  • libcfa/src/iostream.cfa

    r4d2d7e27 r278e162  
    1 
    21//
    32// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     
    1110// Created On       : Wed May 27 17:56:53 2015
    1211// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Sun Oct  8 12:10:21 2023
    14 // Update Count     : 1564
     12// Last Modified On : Thu Oct 19 21:10:10 2023
     13// Update Count     : 1801
    1514//
    1615
     
    785784                return is;
    786785        } // ?|?
    787         ISTYPE_VOID_IMPL( bool & )
    788786
    789787        istype & ?|?( istype & is, char & c ) {
     
    797795                return is;
    798796        } // ?|?
    799         ISTYPE_VOID_IMPL( char & )
    800797
    801798        istype & ?|?( istype & is, signed char & sc ) {
     
    803800                return is;
    804801        } // ?|?
    805         ISTYPE_VOID_IMPL( signed char & )
    806802
    807803        istype & ?|?( istype & is, unsigned char & usc ) {
     
    809805                return is;
    810806        } // ?|?
    811         ISTYPE_VOID_IMPL( unsigned char & )
    812807
    813808        istype & ?|?( istype & is, short int & si ) {
     
    815810                return is;
    816811        } // ?|?
    817         ISTYPE_VOID_IMPL( short int & )
    818812
    819813        istype & ?|?( istype & is, unsigned short int & usi ) {
     
    821815                return is;
    822816        } // ?|?
    823         ISTYPE_VOID_IMPL( unsigned short int & )
    824817
    825818        istype & ?|?( istype & is, int & i ) {
     
    827820                return is;
    828821        } // ?|?
    829         ISTYPE_VOID_IMPL( int & )
    830822
    831823        istype & ?|?( istype & is, unsigned int & ui ) {
     
    833825                return is;
    834826        } // ?|?
    835         ISTYPE_VOID_IMPL( unsigned int & )
    836827
    837828        istype & ?|?( istype & is, long int & li ) {
     
    839830                return is;
    840831        } // ?|?
    841         ISTYPE_VOID_IMPL( long int & )
    842832
    843833        istype & ?|?( istype & is, unsigned long int & ulli ) {
     
    845835                return is;
    846836        } // ?|?
    847         ISTYPE_VOID_IMPL( unsigned long int & )
    848837
    849838        istype & ?|?( istype & is, long long int & lli ) {
     
    851840                return is;
    852841        } // ?|?
    853         ISTYPE_VOID_IMPL( long long int & )
    854842
    855843        istype & ?|?( istype & is, unsigned long long int & ulli ) {
     
    857845                return is;
    858846        } // ?|?
    859         ISTYPE_VOID_IMPL( unsigned long long int & )
    860847
    861848        #if defined( __SIZEOF_INT128__ )
     
    863850                return (istype &)(is | (unsigned int128 &)llli);
    864851        } // ?|?
    865         ISTYPE_VOID_IMPL( int128 & )
    866852
    867853        istype & ?|?( istype & is, unsigned int128 & ullli ) {
     
    880866                return is;
    881867        } // ?|?
    882         ISTYPE_VOID_IMPL( unsigned int128 & )
    883868        #endif // __SIZEOF_INT128__
    884869
     
    887872                return is;
    888873        } // ?|?
    889         ISTYPE_VOID_IMPL( float & )
    890874
    891875        istype & ?|?( istype & is, double & d ) {
     
    893877                return is;
    894878        } // ?|?
    895         ISTYPE_VOID_IMPL( double & )
    896879
    897880        istype & ?|?( istype & is, long double & ld ) {
     
    899882                return is;
    900883        } // ?|?
    901         ISTYPE_VOID_IMPL( long double & )
    902884
    903885        istype & ?|?( istype & is, float _Complex & fc ) {
     
    907889                return is;
    908890        } // ?|?
    909         ISTYPE_VOID_IMPL( float _Complex & )
    910891
    911892        istype & ?|?( istype & is, double _Complex & dc ) {
     
    915896                return is;
    916897        } // ?|?
    917         ISTYPE_VOID_IMPL( double _Complex & )
    918898
    919899        istype & ?|?( istype & is, long double _Complex & ldc ) {
     
    923903                return is;
    924904        } // ?|?
    925         ISTYPE_VOID_IMPL( long double _Complex & )
    926905
    927906        istype & ?|?( istype & is, const char fmt[] ) {
     
    929908                return is;
    930909        } // ?|?
    931         ISTYPE_VOID_IMPL( const char * )
    932910
    933911        // manipulators
     
    937915
    938916        void ?|?( istype & is, istype & (* manip)( istype & ) ) {
    939                 manip( is ); ends( is );
     917                manip( is );
    940918        } // ?|?
    941919
     
    966944                        char fmtstr[ sizeof("%*[]") + nscanset ];
    967945                        int pos = 0;
    968                         fmtstr[pos] = '%';                  pos += 1;
    969                         fmtstr[pos] = '*';                  pos += 1;
    970                         fmtstr[pos] = '[';                  pos += 1;
     946                        strcpy( &fmtstr[pos], "%*[" );  pos += 3;
    971947                        strcpy( &fmtstr[pos], f.scanset );  pos += nscanset;
    972                         fmtstr[pos] = ']';                  pos += 1;
    973                         fmtstr[pos] = '\0';
    974                         fmt( is, fmtstr, (void*)0 );  // last arg is dummy: suppress gcc warning
    975                 }
    976                 else for ( f.wd ) fmt( is, "%*c" );
     948                        strcpy( &fmtstr[pos], "]" );
     949                        fmt( is, fmtstr, "" );                                          // skip scanset
     950                } else {
     951                        char ch;
     952//                      fprintf( stderr, "skip " );
     953                        for ( f.wd ) {                                                          // skip N characters
     954                          if ( eof( is ) ) break;
     955                                fmt( is, "%c", &ch );
     956//                              fprintf( stderr, "`%c' ", ch );
     957                        } // for
     958                } // if
    977959                return is;
    978960        }
    979         ISTYPE_VOID_IMPL( _Istream_Cskip )
    980961
    981962        istype & ?|?( istype & is, _Istream_Cstr f ) {
    982                 const char * scanset = f.scanset;
     963                const char * scanset;
     964                size_t nscanset = 0;
    983965                if ( f.flags.delimiter ) scanset = f.delimiter; // getline ?
    984 
    985                 size_t len = 0;
    986                 if ( scanset ) len = strlen( scanset );
    987                 char fmtstr[len + 16];
    988                 int start = 1;
     966                else scanset = f.scanset;
     967                if ( scanset ) nscanset = strlen( scanset );
     968
     969                char fmtstr[nscanset + 32];                                             // storage for scanset and format codes
    989970                fmtstr[0] = '%';
    990                 if ( f.flags.ignore ) { fmtstr[1] = '*'; start += 1; }
    991                 // no maximum width necessary because text ignored => width is read width
    992                 if ( f.wd != -1 ) {
     971
     972                int pos = 1;
     973                int args;
     974                bool check = true;
     975
     976                if ( f.flags.ignore ) { check = false; fmtstr[1] = '*'; pos += 1; }
     977                int rwd = f.wd;
     978                if ( f.wd != -1 ) {                                                             // => just ignore versus ignore with width
    993979                        // wd is buffer bytes available (for input chars + null terminator)
    994980                        // rwd is count of input chars
    995                         int rwd;
    996                         if (f.flags.rwd) {
    997                                 verify (f.wd >= 0);
    998                                 rwd = f.wd;
     981                        // no maximum width necessary because text ignored => width is read width
     982                        if ( f.flags.rwd ) check = false;
     983                        else rwd = f.wd - 1;
     984                        pos += sprintf( &fmtstr[pos], "%d", rwd );
     985                } // if
     986
     987                if ( ! scanset ) {                                                              // %s, %*s, %ws, %*ws
     988//                      fprintf( stderr, "cstr %s\n", f.s );
     989                        strcpy( &fmtstr[pos], "s%n" );
     990                        int len = 0;                                                            // may not be set in fmt
     991                        if ( f.flags.ignore ) args = fmt( is, fmtstr, &len ); // no string argument for '*'
     992                        else args = fmt( is, fmtstr, f.s, &len );
     993//                      fprintf( stderr, "cstr %s %d %d %d %s\n", fmtstr, args, len, f.wd, f.s );
     994                        if ( check && len >= rwd && ! eof( is ) ) {     // might not fit
     995                                char peek;
     996                                fmt( is, "%c", &peek );                                 // check for whitespace terminator
     997//                              fprintf( stderr, "peek %d '%c'\n", args, peek );
     998                                if ( ! eof( is ) ) {
     999                                        ungetc( is, peek );
     1000                                        if ( ! isspace( peek ) ) throw ExceptionInst( cstring_length );
     1001                                } // if
     1002                        } // if
     1003                } else {
     1004                        if ( f.flags.delimiter ) {                                      // getline
     1005//                              fprintf( stderr, "getline\n" );
     1006                                sprintf( &fmtstr[pos], "[%s%s]%%n", f.flags.inex ? "^" : "", scanset );
     1007//                              fprintf( stderr, "getline %s %d\n", fmtstr, f.wd );
     1008                                int len = 0;                                                    // may not be set in fmt
     1009                                if ( f.flags.ignore ) args = fmt( is, fmtstr, &len ); // no string argument for '*'
     1010                                else args = fmt( is, fmtstr, f.s, &len );
     1011//                              fprintf( stderr, "getline %s %d %d %d\n", fmtstr, args, f.wd, eof( is ) );
     1012                                if ( check && len == rwd && ! eof( is ) ) {     // might not fit
     1013                                        char peek;
     1014                                        fmt( is, "%c", &peek );                         // check for delimiter
     1015//                                      fprintf( stderr, "peek %d '%c'\n", args, peek );
     1016                                        if ( ! eof( is ) ) {
     1017                                                if ( peek != f.delimiter[0] ) {
     1018                                                        ungetc( is, peek );
     1019                                                        throw ExceptionInst( cstring_length );
     1020                                                } // if
     1021                                        } // if
     1022                                } else fmt( is, "%*c" );                                //  remove delimiter
    9991023                        } else {
    1000                                 verify (f.wd >= 1);
    1001                                 rwd = f.wd - 1;
     1024                                // incl %[xxx],  %*[xxx],  %w[xxx],  %*w[xxx]
     1025                                // excl %[^xxx], %*[^xxx], %w[^xxx], %*w[^xxx]
     1026                                sprintf( &fmtstr[pos], "[%s%s]%%n", f.flags.inex ? "^" : "", scanset );
     1027//                              fprintf( stderr, "incl/excl %s %d\n", fmtstr, f.wd );
     1028                                int len = 0;                                                    // may not be set in fmt
     1029                                if ( f.flags.ignore ) args = fmt( is, fmtstr, &len ); // no string argument for '*'
     1030                                else args = fmt( is, fmtstr, f.s, &len );
     1031//                              fprintf( stderr, "incl/excl %s \"%s\" %d %d %d %d %d %c\n", fmtstr, f.s, args, f.wd, len, eof( is ), check, f.s[f.wd] );
     1032                                if ( check && len == rwd && ! eof( is ) ) {     // might not fit
     1033//                                      fprintf( stderr, "overflow\n" );
     1034                                        char peek;
     1035                                        fmt( is, "%c", &peek );                         // check for whitespace terminator
     1036//                                      fprintf( stderr, "peek %d '%c'\n", args, peek );
     1037                                        if ( ! eof( is ) ) {
     1038                                                ungetc( is, peek );
     1039                                                if ( f.flags.inex ^ strchr( f.scanset, peek ) != 0p ) throw ExceptionInst( cstring_length );
     1040                                        } // if
     1041                                } // if
    10021042                        } // if
    1003                         start += sprintf( &fmtstr[start], "%d", rwd );
    1004                 }
    1005 
    1006                 if ( ! scanset ) {
    1007                         // %s, %*s, %ws, %*ws
    1008                         fmtstr[start] = 's'; fmtstr[start + 1] = '\0';
    1009                         // printf( "cstr %s\n", fmtstr );
    1010                 } else {
    1011                         // incl %[xxx],  %*[xxx],  %w[xxx],  %*w[xxx]
    1012                         // excl %[^xxx], %*[^xxx], %w[^xxx], %*w[^xxx]
    1013                         fmtstr[start] = '['; start += 1;
    1014                         if ( f.flags.inex ) { fmtstr[start] = '^'; start += 1; }
    1015                         strcpy( &fmtstr[start], scanset );                      // copy includes '\0'
    1016                         len += start;
    1017                         fmtstr[len] = ']'; fmtstr[len + 1] = '\0';
    1018                         // printf( "incl/excl %s\n", fmtstr );
    1019                 } // if
    1020 
    1021                 int check = f.wd - 2;
    1022                 if (! f.flags.ignore ) {
    1023                         f.s[0] = '\0';
    1024                         if ( ! f.flags.rwd ) f.s[check] = '\0';         // insert sentinel
    1025                 }
    1026                 len = fmt( is, fmtstr, f.s );
    1027                 //fprintf( stderr, "KK %s %zd %d %c %s\n", fmtstr, len, check, f.s[check], f.s );
    1028 
    1029                 if ( ! f.flags.ignore && ! f.flags.rwd && f.s[check] != '\0' ) { // sentinel overwritten ?
    1030                         // buffer filled, but would we have kept going?
    1031                         if ( ! eof( is ) ) {
    1032                                 char peek;
    1033                                 fmt( is, "%c", &peek );
    1034                                 ungetc( is, peek );
    1035                                 bool hasMore;
    1036                                 if (f.flags.delimiter) { // getline
    1037                                         hasMore = (peek != f.delimiter[0]);
    1038                                 } else if (f.scanset) { // incl/excl
    1039                                         bool peekMatch = strchr(f.scanset, peek) != 0p;
    1040                                         hasMore = f.flags.inex ? (!peekMatch) : (peekMatch);
    1041                                 } else { // %s
    1042                                         hasMore = !isspace(peek);
    1043                                 }
    1044                                 if (hasMore) throw (cstring_length){ &cstring_length_vt };
    1045                         } // if
    1046                 } // if
    1047 
    1048                 if ( f.flags.delimiter ) {                                              // getline ?
    1049                         if ( len == 0 ) f.s[0] = '\0';                          // empty read => argument unchanged => set empty
    1050                         if ( ! eof( is ) ) {                                            // ignore delimiter, may not be present because of width
    1051                                 char delimiter;
    1052                                 fmt( is, "%c", &delimiter );
    1053                                 if ( delimiter != f.delimiter[0] ) ungetc( is, delimiter );
    1054                         } // if
    1055                 } //if
    1056                 return is;
    1057         } // ?|?
    1058         ISTYPE_VOID_IMPL( _Istream_Cstr )
     1043                } // if
     1044                if ( args == 1 && eof( is ) ) {                                 // data but scan ended at EOF
     1045//                      fprintf( stderr, "clear\n" );
     1046                        clear( is );                                                            // => reset EOF => detect again on next read
     1047                } // if
     1048                return is;
     1049        } // ?|?
    10591050
    10601051        istype & ?|?( istype & is, _Istream_Char f ) {
     
    10621053                return is;
    10631054        } // ?|?
    1064         ISTYPE_VOID_IMPL( _Istream_Char )
    10651055} // distribution
    10661056
     
    10791069                return is; \
    10801070        } /* ?|? */ \
    1081         ISTYPE_VOID_IMPL( _Istream_Manip(T) ) \
    10821071} // distribution
    10831072
     
    11071096                return is;
    11081097        } // ?|?
    1109         ISTYPE_VOID_IMPL( _Istream_Manip(float _Complex) )
    11101098
    11111099        istype & ?|?( istype & is, _Istream_Manip(double _Complex) dc ) {
     
    11181106                return is;
    11191107        } // ?|?
    1120         ISTYPE_VOID_IMPL( _Istream_Manip(double _Complex) )
    11211108
    11221109        istype & ?|?( istype & is, _Istream_Manip(long double _Complex) ldc ) {
     
    11291116                return is;
    11301117        } // ?|?
    1131         ISTYPE_VOID_IMPL( _Istream_Manip(long double _Complex) )
    11321118} // distribution
    11331119
  • libcfa/src/iostream.hfa

    r4d2d7e27 r278e162  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Oct  8 12:02:55 2023
    13 // Update Count     : 568
     12// Last Modified On : Wed Oct 18 21:21:20 2023
     13// Update Count     : 583
    1414//
    1515
     
    306306// *********************************** istream ***********************************
    307307
    308 #define ISTYPE_VOID( T ) void ?|?( istype &, T )
    309 #define ISTYPE_VOID_IMPL( T ) \
    310         void ?|?( istype & is, T t ) { \
    311                 (istype &)(is | t); ends( is ); \
    312         } // ?|?
    313 
    314308forall( istype & )
    315309trait basic_istream {
     
    320314        void nlOn( istype & );                                                          // read newline
    321315        void nlOff( istype & );                                                         // scan newline
    322         void ends( istype & os );                                                       // end of output statement
    323316        int fmt( istype &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
    324317        istype & ungetc( istype &, char );
    325318        bool eof( istype & );
     319        void clear( istype & );
    326320}; // basic_istream
    327321
     
    329323trait istream {
    330324        bool fail( istype & );
    331         void clear( istype & );
     325        void open( istype & is, const char name[], const char mode[] );
    332326        void open( istype & is, const char name[] );
    333327        void close( istype & is );
     
    342336forall( istype & | basic_istream( istype ) ) {
    343337        istype & ?|?( istype &, bool & );
    344         ISTYPE_VOID( bool & );
    345338
    346339        istype & ?|?( istype &, char & );
    347         ISTYPE_VOID( char & );
    348340        istype & ?|?( istype &, signed char & );
    349         ISTYPE_VOID( signed char & );
    350341        istype & ?|?( istype &, unsigned char & );
    351         ISTYPE_VOID( unsigned char & );
    352342
    353343        istype & ?|?( istype &, short int & );
    354         ISTYPE_VOID( short int & );
    355344        istype & ?|?( istype &, unsigned short int & );
    356         ISTYPE_VOID( unsigned short int & );
    357345        istype & ?|?( istype &, int & );
    358         ISTYPE_VOID( int & );
    359346        istype & ?|?( istype &, unsigned int & );
    360         ISTYPE_VOID( unsigned int & );
    361347        istype & ?|?( istype &, long int & );
    362         ISTYPE_VOID( long int & );
    363348        istype & ?|?( istype &, unsigned long int & );
    364         ISTYPE_VOID( unsigned long int & );
    365349        istype & ?|?( istype &, long long int & );
    366         ISTYPE_VOID( long long int & );
    367350        istype & ?|?( istype &, unsigned long long int & );
    368         ISTYPE_VOID( unsigned long long int & );
    369351        #if defined( __SIZEOF_INT128__ )
    370352        istype & ?|?( istype &, int128 & );
    371         ISTYPE_VOID( int128 & );
    372353        istype & ?|?( istype &, unsigned int128 & );
    373         ISTYPE_VOID( unsigned int128 & );
    374354        #endif // __SIZEOF_INT128__
    375355
    376356        istype & ?|?( istype &, float & );
    377         ISTYPE_VOID( float & );
    378357        istype & ?|?( istype &, double & );
    379         ISTYPE_VOID( double & );
    380358        istype & ?|?( istype &, long double & );
    381         ISTYPE_VOID( long double & );
    382359
    383360        istype & ?|?( istype &, float _Complex & );
    384         ISTYPE_VOID( float _Complex & );
    385361        istype & ?|?( istype &, double _Complex & );
    386         ISTYPE_VOID( double _Complex & );
    387362        istype & ?|?( istype &, long double _Complex & );
    388         ISTYPE_VOID( long double _Complex & );
    389363
    390364        istype & ?|?( istype &, const char [] );
    391         ISTYPE_VOID( const char [] );
    392365
    393366        // manipulators
    394367        istype & ?|?( istype &, istype & (*)( istype & ) );
    395         ISTYPE_VOID( istype & (*)( istype & ) );
    396368        istype & nl( istype & is );
    397369        istype & nlOn( istype & );
     
    402374
    403375ExceptionDecl( cstring_length );
     376ExceptionDecl( missing_data );
    404377
    405378// *********************************** manipulators ***********************************
    406379
     380// skip does not compose with other C string manipulators.
    407381struct _Istream_Cskip {
    408382        const char * scanset;
     
    416390forall( istype & | basic_istream( istype ) ) {
    417391        istype & ?|?( istype & is, _Istream_Cskip f );
    418         ISTYPE_VOID( _Istream_Cskip );
    419392}
    420393
     
    458431forall( istype & | basic_istream( istype ) ) {
    459432        istype & ?|?( istype & is, _Istream_Cstr f );
    460         ISTYPE_VOID( _Istream_Cstr );
    461433}
    462434
     
    471443forall( istype & | basic_istream( istype ) ) {
    472444        istype & ?|?( istype & is, _Istream_Char f );
    473         ISTYPE_VOID( _Istream_Char );
    474445}
    475446
     
    490461forall( istype & | basic_istream( istype ) ) { \
    491462        istype & ?|?( istype & is, _Istream_Manip(T) f ); \
    492         ISTYPE_VOID( _Istream_Manip(T) ); \
    493463} // ?|?
    494464
  • src/CodeTools/DeclStats.cc

    r4d2d7e27 r278e162  
    2525#include "Common/PassVisitor.h"
    2626#include "Common/VectorMap.h"      // for VectorMap
    27 #include "GenPoly/GenPoly.h"       // for hasPolyBase
    2827#include "SynTree/LinkageSpec.h"   // for ::NoOfSpecs, Spec
    2928#include "SynTree/Declaration.h"   // for FunctionDecl, TypeDecl, Declaration
  • src/GenPoly/BoxNew.cpp

    r4d2d7e27 r278e162  
    3939
    4040namespace {
    41 
    42 /// Common field of several sub-passes of box.
    43 struct BoxPass {
    44         TypeVarMap scopeTypeVars;
    45         BoxPass() : scopeTypeVars( ast::TypeData() ) {}
    46 };
    47 
    48 // TODO: Could this be a common helper somewhere?
    49 ast::FunctionType * makeFunctionType( ast::FunctionDecl const * decl ) {
    50         ast::FunctionType * type = new ast::FunctionType(
    51                 decl->type->isVarArgs, decl->type->qualifiers
    52         );
    53         for ( auto type_param : decl->type_params ) {
    54                 type->forall.emplace_back( new ast::TypeInstType( type_param ) );
    55         }
    56         for ( auto assertion : decl->assertions ) {
    57                 type->assertions.emplace_back( new ast::VariableExpr(
    58                         assertion->location, assertion ) );
    59         }
    60         for ( auto param : decl->params ) {
    61                 type->params.emplace_back( param->get_type() );
    62         }
    63         for ( auto retval : decl->returns ) {
    64                 type->returns.emplace_back( retval->get_type() );
    65         }
    66         return type;
    67 }
    6841
    6942// --------------------------------------------------------------------------
     
    359332/// * Adds appropriate type variables to the function calls.
    360333struct CallAdapter final :
    361                 public BoxPass,
    362334                public ast::WithConstTypeSubstitution,
    363335                public ast::WithGuards,
     
    438410                CodeLocation const & location, ast::Type const * type );
    439411
    440         /// Set of adapter functions in the current scope.
     412        TypeVarMap scopeTypeVars;
    441413        ScopedMap< std::string, ast::DeclWithType const * > adapters;
    442414        std::map< ast::ApplicationExpr const *, ast::Expr const * > retVals;
     
    659631        ptrdiff_t initArgCount = mutExpr->args.size();
    660632
    661         TypeVarMap exprTypeVars = { ast::TypeData() };
     633        TypeVarMap exprTypeVars;
    662634        // TODO: Should this take into account the variables already bound in
    663635        // scopeTypeVars ([ex] remove them from exprTypeVars)?
     
    14101382
    14111383ast::FunctionDecl const * DeclAdapter::previsit( ast::FunctionDecl const * decl ) {
    1412         TypeVarMap localTypeVars = { ast::TypeData() };
     1384        TypeVarMap localTypeVars;
    14131385        makeTypeVarMap( decl, localTypeVars );
    14141386
     
    14411413                        layoutParams.emplace_back( alignParam );
    14421414                }
    1443                 // TODO: These should possibly all be gone.
    1444                 // More all assertions into parameter list.
    1445                 for ( ast::ptr<ast::DeclWithType> & assert : mutParam->assertions ) {
    1446                         // Assertion parameters may not be used in body,
    1447                         // pass along with unused attribute.
    1448                         assert.get_and_mutate()->attributes.push_back(
    1449                                 new ast::Attribute( "unused" ) );
    1450                         inferredParams.push_back( assert );
    1451                 }
    1452                 mutParam->assertions.clear();
     1415                // Assertions should be stored in the main list.
     1416                assert( mutParam->assertions.empty() );
    14531417                typeParam = mutParam;
    14541418        }
    1455         // TODO: New version of inner loop.
    14561419        for ( ast::ptr<ast::DeclWithType> & assert : mutDecl->assertions ) {
    14571420                // Assertion parameters may not be used in body,
     
    14681431        spliceBegin( mutDecl->params, layoutParams );
    14691432        addAdapters( mutDecl, localTypeVars );
     1433
     1434        // Now have to update the type to match the declaration.
     1435        ast::FunctionType * type = new ast::FunctionType(
     1436                mutDecl->type->isVarArgs, mutDecl->type->qualifiers );
     1437        for ( auto type_param : mutDecl->type_params ) {
     1438                type->forall.emplace_back( new ast::TypeInstType( type_param ) );
     1439        }
     1440        for ( auto param : mutDecl->params ) {
     1441                type->params.emplace_back( param->get_type() );
     1442        }
     1443        for ( auto retval : mutDecl->returns ) {
     1444                type->returns.emplace_back( retval->get_type() );
     1445        }
     1446        mutDecl->type = type;
    14701447
    14711448        return mutDecl;
     
    15011478                }
    15021479        }
    1503         // TODO: Can this be updated as we go along?
    1504         mutDecl->type = makeFunctionType( mutDecl );
    15051480        return mutDecl;
    15061481}
     
    15581533        assertf( it != adapters.end(), "Could not correct floating node." );
    15591534        return ast::mutate_field( expr, &ast::VariableExpr::var, it->second );
    1560 
    15611535}
    15621536
     
    15701544/// * Inserts dynamic calculation of polymorphic type layouts where needed.
    15711545struct PolyGenericCalculator final :
    1572                 public BoxPass,
    15731546                public ast::WithConstTypeSubstitution,
    15741547                public ast::WithDeclsToAdd<>,
     
    16151588        /// C sizeof().
    16161589        ast::Expr const * genSizeof( CodeLocation const &, ast::Type const * );
    1617 
    16181590        /// Enters a new scope for type-variables,
    16191591        /// adding the type variables from the provided type.
    16201592        void beginTypeScope( ast::Type const * );
    16211593
     1594        /// The type variables and polymorphic parameters currently in scope.
     1595        TypeVarMap scopeTypeVars;
    16221596        /// Set of generic type layouts known in the current scope,
    16231597        /// indexed by sizeofName.
     
    16681642                ast::TypeDecl const * decl ) {
    16691643        ast::Type const * base = decl->base;
    1670         if ( nullptr == base) return decl;
     1644        if ( nullptr == base ) return decl;
    16711645
    16721646        // Add size/align variables for opaque type declarations.
     
    16931667        alignDecl->accept( *visitor );
    16941668
    1695         // Can't use [makeVar], because it inserts into stmtsToAdd and TypeDecls
    1696         // can occur at global scope.
     1669        // A little trick to replace this with two declarations.
     1670        // Adding after makes sure that there is no conflict with adding stmts.
    16971671        declsToAddAfter.push_back( alignDecl );
    1698         // replace with sizeDecl.
    16991672        return sizeDecl;
    17001673}
     
    17211694
    17221695        // Change initialization of a polymorphic value object to allocate via a
    1723         // variable-length-array (alloca was previouly used, but it cannot be
    1724         // safely used in loops).
     1696        // variable-length-array (alloca cannot be safely used in loops).
    17251697        ast::ObjectDecl * newBuf = new ast::ObjectDecl( decl->location,
    17261698                bufNamer.newName(),
     
    22102182/// * Strips fields from generic structure declarations.
    22112183struct Eraser final :
    2212                 public BoxPass,
    22132184                public ast::WithGuards {
    22142185        void guardTypeVarMap( ast::Type const * type ) {
     
    22252196        void previsit( ast::PointerType const * type );
    22262197        void previsit( ast::FunctionType const * type );
     2198public:
     2199        TypeVarMap scopeTypeVars;
    22272200};
    22282201
  • src/GenPoly/GenPoly.cc

    r4d2d7e27 r278e162  
    273273        if ( func->returns.empty() ) return nullptr;
    274274
    275         TypeVarMap forallTypes = { ast::TypeData() };
     275        TypeVarMap forallTypes;
    276276        makeTypeVarMap( func, forallTypes );
    277277        return isDynType( func->returns.front(), forallTypes );
     
    801801        const ast::FunctionType * function = getFunctionType( expr->func->result );
    802802        assertf( function, "ApplicationExpr has non-function type: %s", toString( expr->func->result ).c_str() );
    803         TypeVarMap exprTyVars = { ast::TypeData() };
     803        TypeVarMap exprTyVars;
    804804        makeTypeVarMap( function, exprTyVars );
    805805        return needsBoxing( param, arg, exprTyVars, subst );
  • src/GenPoly/GenPoly.h

    r4d2d7e27 r278e162  
    3333
    3434        typedef ErasableScopedMap< std::string, TypeDecl::Data > TyVarMap;
    35         using TypeVarMap = ErasableScopedMap< ast::TypeEnvKey, ast::TypeData >;
     35        struct TypeVarMap : public ErasableScopedMap<ast::TypeEnvKey, ast::TypeData> {
     36                TypeVarMap() : ErasableScopedMap( ast::TypeData() ) {}
     37        };
    3638
    3739        /// Replaces a TypeInstType by its referrent in the environment, if applicable
  • src/GenPoly/SpecializeNew.cpp

    r4d2d7e27 r278e162  
    8181}
    8282
    83 // The number of elements in a type if it is a flattened tuple.
    84 size_t flatTupleSize( const ast::Type * type ) {
    85         if ( auto tuple = dynamic_cast<const ast::TupleType *>( type ) ) {
    86                 size_t sum = 0;
    87                 for ( auto t : *tuple ) {
    88                         sum += flatTupleSize( t );
    89                 }
    90                 return sum;
    91         } else {
    92                 return 1;
    93         }
     83// The number of elements in a list, if all tuples had been flattened.
     84size_t flatTypeListSize( const std::vector<ast::ptr<ast::Type>> & types ) {
     85        size_t sum = 0;
     86        for ( const ast::ptr<ast::Type> & type : types ) {
     87                if ( const ast::TupleType * tuple = type.as<ast::TupleType>() ) {
     88                        sum += flatTypeListSize( tuple->types );
     89                } else {
     90                        sum += 1;
     91                }
     92        }
     93        return sum;
    9494}
    9595
    9696// Find the total number of components in a parameter list.
    9797size_t functionParameterSize( const ast::FunctionType * type ) {
    98         size_t sum = 0;
    99         for ( auto param : type->params ) {
    100                 sum += flatTupleSize( param );
    101         }
    102         return sum;
     98        return flatTypeListSize( type->params );
    10399}
    104100
  • tests/collections/.expect/string-istream-manip.txt

    r4d2d7e27 r278e162  
    696913 wwwwwwww
    707014 cccc
    71 15
     7115 q
    72721 yyyyyyyyyyyyyyyyyyyy
    73732 abcxxx
     
    848413 wwwwwwww
    858514 cccc
    86 15
     8615 q
  • tests/collections/string-istream-manip.cfa

    r4d2d7e27 r278e162  
    3838        void echoTillX(const char * casename) {
    3939            string s;
    40             do {
     40            // loop assumes behaviour not tested until main-case #15:
     41            // on reading nothing, the prior string value is left alone
     42            do {
     43                s = "";
    4144                forceStringHeapFreeSpaceTo(9);
    4245                sin | s;
     
    5457            string s;
    5558            do {
     59                s = "";
    5660                sin | plainjane( s );
    5761                sout | casename | s;
     
    6872            string_res s;
    6973            do {
     74                s = "";
    7075                sin | plainjane( s );
    7176                sout | casename | s;
     
    8287            string s;
    8388            do {
     89                s = "";
    8490                sin | skip("-\n");
    8591                sin | incl( ".:|# x", s );
     
    97103            string s;
    98104            do {
     105                s = "";
    99106                sin | skip("-\n");
    100107                sin | excl( "-\n", s );
     
    113120            string s;
    114121            do {
     122                s = "";
    115123                sin | getline( s );
    116124                sout | casename | s;
     
    127135            string s;
    128136            do {
     137                s = "";
    129138                sin | getline( s, '@' );
    130139                sout | casename | s;
  • tests/concurrency/waituntil/channel_close.cfa

    r4d2d7e27 r278e162  
    2626        for( ;; ) {
    2727            if ( useAnd ) {
    28                 waituntil( (in << A) ) { assert( A_removes == in ); A_removes++; removes++; }
    29                 and waituntil( (in2 << B) ) { assert( B_removes == in2 ); B_removes++; removes++; }
     28                waituntil( (in << A) ) { __atomic_thread_fence( __ATOMIC_SEQ_CST ); assert( A_removes == in ); A_removes++; removes++; }
     29                and waituntil( (in2 << B) ) { __atomic_thread_fence( __ATOMIC_SEQ_CST ); assert( B_removes == in2 ); B_removes++; removes++; }
    3030                continue;
    3131            }
    32             waituntil( (in << A) ) { assert( A_removes == in ); A_removes++; removes++; }
    33             or waituntil( (in << B) ) { assert( B_removes == in ); B_removes++; removes++; }
     32            waituntil( (in << A) ) { __atomic_thread_fence( __ATOMIC_SEQ_CST ); assert( A_removes == in ); A_removes++; removes++; }
     33            or waituntil( (in << B) ) { __atomic_thread_fence( __ATOMIC_SEQ_CST ); ( B_removes == in ); B_removes++; removes++; }
    3434        }
    3535    } catchResume ( channel_closed * e ) {} // continue to remove until would block
     
    3737    try {
    3838        for( ;; )
    39             waituntil( (in << A) ) { assert( A_removes == in ); A_removes++; removes++; }
     39            waituntil( (in << A) ) { __atomic_thread_fence( __ATOMIC_SEQ_CST ); assert( A_removes == in ); A_removes++; removes++; }
    4040    } catchResume ( channel_closed * e ) {} // continue to remove until would block
    4141    catch ( channel_closed * e ) {}
    4242    try {
    4343        for( ;; )
    44             waituntil( (in << B) ) { assert( B_removes == in ); B_removes++; removes++; }
     44            waituntil( (in << B) ) { __atomic_thread_fence( __ATOMIC_SEQ_CST ); assert( B_removes == in ); B_removes++; removes++; }
    4545    } catchResume ( channel_closed * e ) {} // continue to remove until would block
    4646    catch ( channel_closed * e ) {}
  • tests/genericUnion.cfa

    r4d2d7e27 r278e162  
    1010// Created On       : Tue Dec 25 14:42:46 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec 25 14:46:33 2018
    13 // Update Count     : 2
     12// Last Modified On : Fri Oct 20 09:13:26 2023
     13// Update Count     : 15
    1414//
    1515
     16#include <fstream.hfa>
    1617#include <limits.hfa>
    1718
    18 forall(T)
     19forall( T )
    1920union ByteView {
    2021        T val;
     
    2324
    2425forall(T)
    25 void print(ByteView(T) x) {
    26         for (int i = 0; i < sizeof(int); i++) {                         // want to change to sizeof(T)
    27                 printf("%02x", x.bytes[i] & 0xff);
     26void print( ByteView(T) x ) {
     27        for ( i; sizeof(int) ) {                                                        // want to change to sizeof(T)
     28                sout | nobase( pad0( wd( 2, hex( x.bytes[i] & 0xff ) ) ) ) | nosep;
    2829        }
    2930}
    3031
    3132forall(T)
    32 void f(ByteView(T) x, T val) {
    33         print(x);
    34         printf(" ");
     33void f( ByteView(T) x, T val ) {
     34        print( x );
     35        sout | " ";
    3536        x.val = val;
    36         print(x);
    37         printf("\n");
     37        print( x );
     38        sout | nl;
    3839}
    3940
    4041int main() {
     42        sout | nlOff;
    4143        ByteView(unsigned) u = { 0 };
    4244        ByteView(int) i = { 0 };
    43         f(u, MAX);
    44         f(i, -1);
     45        f( u, MAX );
     46        f( i, -1 );
    4547}
    4648
  • tests/io/.expect/manipulatorsInput.arm64.txt

    r4d2d7e27 r278e162  
    343413 wwwwwwww
    353514 cccc
    36 15
     3615 q
    3737a
    3838a
  • tests/io/.expect/manipulatorsInput.x64.txt

    r4d2d7e27 r278e162  
    343413 wwwwwwww
    353514 cccc
    36 15
     3615 q
    3737a
    3838a
  • tests/io/.expect/manipulatorsInput.x86.txt

    r4d2d7e27 r278e162  
    343413 wwwwwwww
    353514 cccc
    36 15
     3615 q
    3737a
    3838a
  • tests/io/.expect/manipulatorsOutput4.txt

    r4d2d7e27 r278e162  
    225225-1.55051464826854e+28 -15.5051e27 -15.5051e27   -15.505e27   -15.505e27 -15.50515e27 -15.50515e27 -0015.505e27 -0015.505e27 -15.50515e27 -15.50515e27 -15.505e27   -15.505e27   -15.50515e27 -15.50515e27 -15.505e27   -15.505e27   -15.50515e27 -15.50515e27
    226226-6.51216152272788e+29 -651.216e27 -651.216e27   -651.22e27   -651.22e27 -651.21615e27 -651.21615e27 -00651.22e27 -00651.22e27 -651.21615e27 -651.21615e27 -651.22e27   -651.22e27   -651.21615e27 -651.21615e27 -651.22e27   -651.22e27   -651.21615e27 -651.21615e27
     2270 1 1 1.0 1
     2281 2 2 2.0 2
     2292 4 4 4.0 4
     2303 8 8 8.0 8
     2314 16 16 16.0 16
     2325 32 32 32.0 32
     2336 64 64 64.0 64
     2347 128 128 128.0 128
     2358 256 256 256.0 256
     2369 512 512 512.0 512
     23710 1024 1.024K 1.0K 1K
     23811 2048 2.048K 2.0K 2K
     23912 4096 4.096K 4.1K 4K
     24013 8192 8.192K 8.2K 8K
     24114 16384 16.384K 16.4K 16K
     24215 32768 32.768K 32.8K 33K
     24316 65536 65.536K 65.5K 66K
     24417 131072 131.072K 131.1K 131K
     24518 262144 262.144K 262.1K 262K
     24619 524288 524.288K 524.3K 524K
     24720 1048576 1.04858M 1.0M 1M
     24821 2097152 2.09715M 2.1M 2M
     24922 4194304 4.1943M 4.2M 4M
     25023 8388608 8.38861M 8.4M 8M
     25124 16777216 16.7772M 16.8M 17M
     25225 33554432 33.5544M 33.6M 34M
     25326 67108864 67.1089M 67.1M 67M
     25427 134217728 134.218M 134.2M 134M
     25528 268435456 268.435M 268.4M 268M
     25629 536870912 536.871M 536.9M 537M
     25730 1073741824 1.07374G 1.1G 1G
     25831 2147483648 2.14748G 2.1G 2G
  • tests/io/manipulatorsOutput4.cfa

    r4d2d7e27 r278e162  
    77// Created On       : Tue Apr 13 17:55:02 2021
    88// Last Modified By : Peter A. Buhr
    9 // Last Modified On : Tue Apr 13 18:00:33 2021
    10 // Update Count     : 4
     9// Last Modified On : Tue Oct 17 08:37:42 2023
     10// Update Count     : 5
    1111//
    1212
     
    4242                         | left(ws(12,5, eng(w) )) | left(sign(ws(12,5, eng(w) ))) | left(wd(12,5, eng(w) )) | left(sign(wd(12,5, eng(w) ))) | left(pad0(ws(12,5, eng(w) ))) | left(pad0(sign(ws(12,5, eng(w) )))) | left(pad0(wd(12,5, eng(w) ))) | left(pad0(sign(wd(12,5, eng(w) ))));
    4343        } // for
     44
     45        for ( exp; sizeof(int) * 8 ) {
     46                size_t pow2 = 1z << exp;
     47                sout | exp | pow2 | unit(eng(pow2)) | wd(0,1, unit(eng( pow2 ))) | wd(0,0, unit(eng(pow2)));
     48        } // for
    4449} // main
    4550
Note: See TracChangeset for help on using the changeset viewer.