Changeset 92d8cda


Ignore:
Timestamp:
Sep 6, 2023, 11:49:02 AM (8 months ago)
Author:
caparsons <caparson@…>
Branches:
master
Children:
4a40fca7, 79b05224, 9d47c1f
Parents:
1f10959 (diff), 1fc111c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Files:
7 edited

Legend:

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

    r1f10959 r92d8cda  
    129129
    130130void ?|?( ifstream & in, string & this ) {
    131     (ifstream &)(in | this); ends( in );
     131    in | (*this.inner);
    132132}
    133133
    134134ifstream & ?|?( ifstream & is, _Istream_Sstr f ) {
    135         // .---------------,
    136         // | | | | |...|0|0| null terminator and guard if missing
    137         // `---------------'
    138         enum { gwd = 128 + 1, wd = gwd - 1 };                           // guard and unguard width
    139         char cstr[gwd];                                                                         // read in chunks
    140         bool cont = false;
    141 
    142         _Istream_Cstr cf = { cstr, (_Istream_str_base)f };
    143         if ( ! cf.flags.rwd ) cf.wd = wd;
    144 
    145         cstr[wd] = '\0';                                                                        // guard null terminate string
    146         try {
    147                 is | cf;
    148         } catch( cstring_length * ) {
    149                 cont = true;
    150         } finally {
    151         if ( ! cf.flags.ignore ) f.s = cstr;                    // ok to initialize string
    152         } // try
    153         for ( ; cont; )  {                                                                      // overflow read ?
    154                 cont = false;
    155                 try {
    156                         is | cf;
    157                 } catch( cstring_length * ) {
    158                         cont = true;                                                            // continue not allowed
    159                 } finally {
    160                         if ( ! cf.flags.ignore ) f.s += cstr;           // build string chunk at a time
    161                 } // try
    162         } // for
    163         return is;
     135        _Istream_Rstr f2 = {f.s.inner, (_Istream_str_base)f};
     136    return is | f2;
    164137} // ?|?
    165138
  • libcfa/src/collections/string_res.cfa

    r1f10959 r92d8cda  
    245245    s = temp;
    246246    return in;
     247}
     248
     249void ?|?( ifstream & in, string_res & this ) {
     250    (ifstream &)(in | this); ends( in );
     251}
     252
     253ifstream & ?|?( ifstream & is, _Istream_Rstr f ) {
     254        // .---------------,
     255        // | | | | |...|0|0| null terminator and guard if missing
     256        // `---------------'
     257        enum { gwd = 128 + 1, wd = gwd - 1 };                           // guard and unguard width
     258        char cstr[gwd];                                                                         // read in chunks
     259        bool cont = false;
     260
     261        _Istream_Cstr cf = { cstr, (_Istream_str_base)f };
     262        if ( ! cf.flags.rwd ) cf.wd = wd;
     263
     264        cstr[wd] = '\0';                                                                        // guard null terminate string
     265        try {
     266                is | cf;
     267        } catch( cstring_length * ) {
     268                cont = true;
     269        } finally {
     270        if ( ! cf.flags.ignore ) *(f.s) = cstr;                 // ok to initialize string
     271        } // try
     272        for ( ; cont; )  {                                                                      // overflow read ?
     273                cont = false;
     274                try {
     275                        is | cf;
     276                } catch( cstring_length * ) {
     277                        cont = true;                                                            // continue not allowed
     278                } finally {
     279                        if ( ! cf.flags.ignore ) *(f.s) += cstr;        // build string chunk at a time
     280                } // try
     281        } // for
     282        return is;
     283} // ?|?
     284
     285void ?|?( ifstream & in, _Istream_Rstr f ) {
     286    (ifstream &)(in | f); ends( in );
    247287}
    248288
  • libcfa/src/collections/string_res.hfa

    r1f10959 r92d8cda  
    102102void ?|?(ofstream &out, const string_res &s);
    103103ifstream & ?|?(ifstream &in, string_res &s);
     104void ?|?( ifstream & in, string_res & this );
     105
     106struct _Istream_Rstr {
     107        string_res * s;
     108        inline _Istream_str_base;
     109}; // _Istream_Rstr
     110
     111static inline {
     112        // read width does not include null terminator
     113        _Istream_Rstr wdi( unsigned int rwd, string_res & s ) { return (_Istream_Rstr)@{ &s, {{0p}, rwd, {.flags.rwd : true}} }; }
     114        _Istream_Rstr getline( string_res & s, const char delimiter = '\n' ) {
     115                return (_Istream_Rstr)@{ &s, {{.delimiter : { delimiter, '\0' } }, -1, {.flags.delimiter : true, .flags.inex : true}} };
     116        }
     117        _Istream_Rstr & getline( _Istream_Rstr & fmt, const char delimiter = '\n' ) {
     118                fmt.delimiter[0] = delimiter; fmt.delimiter[1] = '\0'; fmt.flags.delimiter = true; fmt.flags.inex = true; return fmt;
     119        }
     120        _Istream_Rstr incl( const char scanset[], string_res & s ) { return (_Istream_Rstr)@{ &s, {{scanset}, -1, {.flags.inex : false}} }; }
     121        _Istream_Rstr & incl( const char scanset[], _Istream_Rstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = false; return fmt; }
     122        _Istream_Rstr excl( const char scanset[], string_res & s ) { return (_Istream_Rstr)@{ &s, {{scanset}, -1, {.flags.inex : true}} }; }
     123        _Istream_Rstr & excl( const char scanset[], _Istream_Rstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = true; return fmt; }
     124        _Istream_Rstr ignore( string_res & s ) { return (_Istream_Rstr)@{ &s, {{0p}, -1, {.flags.ignore : true}} }; }
     125        _Istream_Rstr & ignore( _Istream_Rstr & fmt ) { fmt.flags.ignore = true; return fmt; }
     126} // distribution
     127ifstream & ?|?( ifstream & is, _Istream_Rstr f );
     128void ?|?( ifstream & is, _Istream_Rstr t );
    104129
    105130// Concatenation
  • src/ResolvExpr/ResolveTypeof.cc

    r1f10959 r92d8cda  
    253253                            const ast::ObjectDecl * mem = baseEnum->members.at(m).as<const ast::ObjectDecl>();
    254254                            assert(mem);
    255                             if ( mem->init ) {
    256                                 const ast::SingleInit * memInit = mem->init.as<const ast::SingleInit>();
    257                                 ast::Expr * initValue = shallowCopy( memInit->value.get() );
    258                                 newDesination->designators.push_back( initValue );
    259                             } else {
    260                                 SemanticError(des->location, "TODO: Enum Array Designation with no explicit value is not implemented");
    261                             }
     255                            const ast::ConstantExpr * enumAsInit = ast::ConstantExpr::from_int(newDesination->location, m);
     256                            newDesination->designators.push_back( enumAsInit );
    262257                        }
    263258                    }
  • tests/collections/.expect/string-istream-manip.txt

    r1f10959 r92d8cda  
    121212 wwwwwwww
    131313 wwwwwwww
     141 yyyyyyyyyyyyyyyyyyyy
     152 abcxxx
     163 abcxxx
     174 aaaaaaaa
     185 aaaaaaaa
     196 aabbccbb
     207 dddwww
     218 dddwww
     229 dddwww
     2310 aaaaaaaa
     2411 wwwwwwww
     2512 wwwwwwww
     2613 wwwwwwww
  • tests/collections/.in/string-istream-manip.txt

    r1f10959 r92d8cda  
    55abcyyy
    66aaaaaaaaxxxxxxxxaabbccbbdddwwwbbbbbbbbwwwwwwwwaaaaaaaawwwwwwww
     7abc
     8abc
     9xx
     10abcxxx
     11abcyyy
     12aaaaaaaaxxxxxxxxaabbccbbdddwwwbbbbbbbbwwwwwwwwaaaaaaaawwwwwwww
  • tests/collections/string-istream-manip.cfa

    r1f10959 r92d8cda  
    22#include <fstream.hfa>
    33#include <collections/string.hfa>
     4#include <collections/string_res.hfa>
    45
    56int main() {
     
    1112        sin | s;                                        sout | "2" | s;
    1213        sin | ignore( s );                              sout | "3" | s;
    13          sin | wdi( 8, s );                             sout | "4" | s;
     14        sin | wdi( 8, s );                              sout | "4" | s;
     15        sin | ignore( wdi( 8, s ) );                    sout | "5" | s;
     16
     17        sin | incl( "abc", s );                         sout | "6" | s;
     18        sin | excl( "abc", s );                         sout | "7" | s;
     19        sin | ignore( incl( "abc", s ) );               sout | "8" | s;
     20        sin | ignore( excl( "abc", s ) );               sout | "9" | s;
     21        sin | incl( "abc", wdi( 8, s ) );               sout | "10" | s;
     22        sin | excl( "abc", wdi( 8, s ) );               sout | "11" | s;
     23        sin | ignore( incl( "abc", wdi( 8, s ) ) );     sout | "12" | s;
     24        sin | ignore( excl( "abc", wdi( 8, s ) ) );     sout | "13" | s;
     25    }
     26    {
     27        string_res s = "yyyyyyyyyyyyyyyyyyyy";
     28        char sk[] = "abc";
     29        sin | "abc " | skip( sk ) | skip( 5 );          sout | "1" | s;
     30        sin | s;                                        sout | "2" | s;
     31        sin | ignore( s );                              sout | "3" | s;
     32        sin | wdi( 8, s );                              sout | "4" | s;
    1433        sin | ignore( wdi( 8, s ) );                    sout | "5" | s;
    1534
Note: See TracChangeset for help on using the changeset viewer.