Changes in / [89bef959:8d96dee]


Ignore:
Files:
4 added
1 deleted
11 edited

Legend:

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

    r89bef959 r8d96dee  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug  7 10:07:26 2023
    13 // Update Count     : 2
     12// Last Modified On : Sat Aug 12 15:24:18 2023
     13// Update Count     : 6
    1414//
    1515
     
    100100
    101101////////////////////////////////////////////////////////
    102 // Output
    103 
    104 ofstream & ?|?( ofstream & fs, const string & this ) {
    105     return fs | (*this.inner);
    106 }
    107 
    108 void ?|?( ofstream & fs, const string & this ) {
    109     fs | (*this.inner);
    110 }
     102// Input-Output
     103
     104ofstream & ?|?( ofstream & out, const string & this ) {
     105    return out | (*this.inner); // print internal string_res
     106}
     107
     108void ?|?( ofstream & out, const string & this ) {
     109    (ofstream &)(out | (*this.inner)); ends( out );
     110}
     111
     112ifstream & ?|?(ifstream &in, string &this) {
     113    return in | (*this.inner); // read to internal string_res
     114}
     115
    111116
    112117////////////////////////////////////////////////////////
  • libcfa/src/containers/string.hfa

    r89bef959 r8d96dee  
    5555ofstream & ?|?(ofstream &out, const string &s);
    5656void ?|?(ofstream &out, const string &s);
     57ifstream & ?|?(ifstream &in, string &s);
    5758
    5859// Concatenation
  • libcfa/src/containers/string_res.cfa

    r89bef959 r8d96dee  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun 29 09:29:06 2023
    13 // Update Count     : 2
     12// Last Modified On : Sat Aug 12 15:37:47 2023
     13// Update Count     : 10
    1414//
    1515
     
    1717#include "string_sharectx.hfa"
    1818#include "stdlib.hfa"
     19#include <ctype.h>
    1920
    2021// Workaround for observed performance penalty from calling CFA's alloc.
     
    134135        serr | nlOff;
    135136        serr | " lnth:" | lnth | " s:" | (void *)s | ",\"";
    136         for ( int i = 0; i < lnth; i += 1 ) {
     137        for ( i; lnth ) {
    137138            serr | s[i];
    138139        } // for
     
    198199// Output operator
    199200ofstream & ?|?(ofstream &out, const string_res &s) {
    200     // Store auto-newline state so it can be restored
    201     bool anl = getANL$(out);
    202     nlOff(out);
    203     for (size_t i = 0; i < s.Handle.lnth; i++) {
    204         out | s[i];
    205     }
    206     out | sepVal;
    207     // Re-apply newlines after done, for chaining version
    208     if (anl) nlOn(out);
     201        // CFA string is NOT null terminated, so print exactly lnth characters in a minimum width of 0.
     202        out | wd( 0, s.Handle.lnth, s.Handle.s ) | nonl;
    209203    return out;
    210204}
    211205
    212206void ?|?(ofstream &out, const string_res &s) {
    213     // Store auto-newline state so it can be restored
    214     bool anl = getANL$(out);
    215     if( s.Handle.lnth == 0 ) {
    216         sout | "";
    217     } else {
    218         nlOff(out);
    219         for (size_t i = 0; i < s.Handle.lnth; i++) {
    220             // Need to re-apply on the last output operator, for whole-statement version
    221             if (anl && i == s.Handle.lnth-1) nlOn(out);
    222             out | s[i];
    223         }
    224     }
    225 }
     207        (ofstream &)(out | s); ends( out );
     208}
     209
     210// Input operator
     211ifstream & ?|?(ifstream &in, string_res &s) {
     212
     213    // Reading into a temp before assigning to s is near zero overhead in typical cases because of sharing.
     214    // If s is a substring of something larger, simple assignment takes care of that case correctly.
     215    // But directly reading a variable amount of text into the middle of a larger context is not practical.
     216    string_res temp;
     217
     218    // Read in chunks.  Often, one chunk is enough.  Keep the string that accumulates chunks last in the heap,
     219    // so available room is rest of heap.  When a chunk fills the heap, force growth then take the next chunk.
     220    for (;;) {
     221        // Append dummy content to temp, forcing expansion when applicable (occurs always on subsequent loops)
     222        // length 2 ensures room for at least one real char, plus scanf/pipe-cstr's null terminator
     223        temp += "--";
     224        assert( temp.Handle.ulink->EndVbyte == temp.Handle.s + temp.Handle.lnth );    // last in heap
     225
     226        // reset, to overwrite the appended "--"
     227        temp.Handle.lnth -= 2;
     228        temp.Handle.ulink->EndVbyte -= 2;
     229
     230        // rest of heap, less 1 byte for null terminator, is available to read into
     231        int lenReadable = (char*)temp.Handle.ulink->ExtVbyte - temp.Handle.ulink->EndVbyte - 1;
     232        assert (lenReadable >= 1);
     233
     234        // get bytes
     235        in | wdi( lenReadable, temp.Handle.ulink->EndVbyte );
     236        int lenWasRead = strlen(temp.Handle.ulink->EndVbyte);
     237
     238        // update metadata
     239        temp.Handle.lnth += lenWasRead;
     240        temp.Handle.ulink->EndVbyte += lenWasRead;
     241
     242      if (lenWasRead < lenReadable) break;
     243    }
     244
     245    s = temp;
     246    return in;
     247}
     248
    226249
    227250// Empty constructor
     
    338361    // adjust all substring string and handle locations, and check if any substring strings are outside the new base string
    339362    char *limit = resultSesStart + resultSesLnth;
    340     for (string_res * p = this.shareEditSet_next; p != &this; p = p->shareEditSet_next) {
     363    for ( string_res * p = this.shareEditSet_next; p != &this; p = p->shareEditSet_next ) {
    341364        verify (p->Handle.s >= beforeBegin);
    342365        if ( p->Handle.s >= afterBegin ) {
     
    391414}
    392415
    393 static string_res & assign_(string_res &this, const char* buffer, size_t bsize, const string_res & valSrc) {
    394 
    395     // traverse the incumbent share-edit set (SES) to recover the range of a base string to which `this` belongs
    396     string_res * shareEditSetStartPeer = & this;
    397     string_res * shareEditSetEndPeer = & this;
     416// traverse the share-edit set (SES) to recover the range of a base string to which `this` belongs
     417static void locateInShareEditSet( string_res &this, string_res *&shareEditSetStartPeer, string_res *&shareEditSetEndPeer ) {
     418    shareEditSetStartPeer = & this;
     419    shareEditSetEndPeer = & this;
    398420    for (string_res * editPeer = this.shareEditSet_next; editPeer != &this; editPeer = editPeer->shareEditSet_next) {
    399421        if ( editPeer->Handle.s < shareEditSetStartPeer->Handle.s ) {
     
    404426        }
    405427    }
     428}
     429
     430static string_res & assign_(string_res &this, const char* buffer, size_t bsize, const string_res & valSrc) {
     431
     432    string_res * shareEditSetStartPeer;
     433    string_res * shareEditSetEndPeer;
     434    locateInShareEditSet( this, shareEditSetStartPeer, shareEditSetEndPeer );
    406435
    407436    verify( shareEditSetEndPeer->Handle.s >= shareEditSetStartPeer->Handle.s );
     
    589618
    590619bool contains(const string_res &s, char ch) {
    591     for (i; size(s)) {
     620    for ( i; size(s) ) {
    592621        if (s[i] == ch) return true;
    593622    }
     
    643672    }
    644673
    645     for (size_t i = fromPos; i < s.Handle.lnth; i++) {
     674    for ( i; fromPos ~ s.Handle.lnth ) {
    646675        size_t remaining = s.Handle.lnth - i;
    647676        // Never going to find the search string if the remaining string is
     
    652681
    653682        bool matched = true;
    654         for (size_t j = 0; j < searchsize; j++) {
     683        for ( j; searchsize ) {
    655684            if (search[j] != s.Handle.s[i + j]) {
    656685                matched = false;
     
    740769
    741770int exclude(const string_res &s, const charclass_res &mask) {
    742     for (int i = 0; i < size(s); i++) {
     771    for ( i; size(s) ) {
    743772        if ( test(mask, s[i]) ) return i;
    744773    }
     
    747776
    748777int include(const string_res &s, const charclass_res &mask) {
    749     for (int i = 0; i < size(s); i++) {
     778    for ( i; size(s) ) {
    750779        if ( ! test(mask, s[i]) ) return i;
    751780    }
     
    775804                for ( HandleNode *ni = HeaderPtr->flink; ni != HeaderPtr; ni = ni->flink ) {
    776805                        serr | "\tnode:" | ni | " lnth:" | ni->lnth | " s:" | (void *)ni->s | ",\"";
    777                         for ( int i = 0; i < ni->lnth; i += 1 ) {
     806                        for ( i; ni->lnth ) {
    778807                                serr | ni->s[i];
    779808                        } // for
     
    881910        for ( HandleNode *n = HeaderPtr->flink; n != HeaderPtr; n = n->flink ) {
    882911            serr | "\tnode:" | n | " lnth:" | n->lnth | " s:" | (void *)n->s | ",\"";
    883             for ( int i = 0; i < n->lnth; i += 1 ) {
    884                 serr | n->s[i];
     912            for ( i; n->lnth ) {
     913                        serr | n->s[i];
    885914            } // for
    886915            serr | "\" flink:" | n->flink | " blink:" | n->blink | nl;
     
    960989    EndVbyte = StartVbyte;
    961990    h = Header.flink;                                   // ignore header node
    962     for (;;) {
     991    for () {
    963992                memmove( EndVbyte, h->s, h->lnth );
    964993                obase = h->s;
     
    9711000                // check if any substrings are allocated within a string
    9721001               
    973                 for (;;) {
     1002                for () {
    9741003                        if ( h == &Header ) break;                      // end of header list ?
    9751004                        if ( h->s >= limit ) break;                     // outside of current string ?
     
    10011030                        serr | nlOff;
    10021031                        serr | "\tnode:" | n | " lnth:" | n->lnth | " s:" | (void *)n->s | ",\"";
    1003                         for ( int i = 0; i < n->lnth; i += 1 ) {
     1032                        for ( i; n->lnth ) {
    10041033                                serr | n->s[i];
    10051034                        } // for
     
    10361065                        serr | nlOff;
    10371066                        serr | "\tnode:" | n | " lnth:" | n->lnth | " s:" | (void *)n->s | ",\"";
    1038                         for ( int i = 0; i < n->lnth; i += 1 ) {
     1067                        for ( i; n->lnth ) {
    10391068                                serr | n->s[i];
    10401069                        } // for
  • libcfa/src/containers/string_res.hfa

    r89bef959 r8d96dee  
    99// Author           : Michael L. Brooks
    1010// Created On       : Fri Sep 03 11:00:00 2021
    11 // Last Modified By : Michael L. Brooks
    12 // Last Modified On : Fri Sep 03 11:00:00 2021
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat Aug 12 15:45:47 2023
     13// Update Count     : 2
    1414//
    1515
     
    3030    VbyteHeap *ulink;                   // upward link
    3131
    32     char *s;                                            // pointer to byte string
     32    char *s;                                                    // pointer to byte string
    3333    unsigned int lnth;                                  // length of byte string
    3434}; // HandleNode
     
    101101ofstream & ?|?(ofstream &out, const string_res &s);
    102102void ?|?(ofstream &out, const string_res &s);
     103ifstream & ?|?(ifstream &in, string_res &s);
    103104
    104105// Concatenation
  • src/ControlStruct/ExceptDeclNew.cpp

    r89bef959 r8d96dee  
    242242}
    243243
    244 static ast::ObjectDecl * createExternVTable(
     244ast::ObjectDecl * createExternVTable(
    245245                CodeLocation const & location,
    246246                std::string const & exceptionName,
     
    453453        std::string const & tableName = decl->name;
    454454
    455     ast::ObjectDecl * retDecl;
     455        ast::ObjectDecl * retDecl;
    456456        if ( decl->storage.is_extern ) {
    457457                // Unique type-ids are only needed for polymorphic instances.
     
    475475        }
    476476
    477     for ( ast::ptr<ast::Attribute> const & attr : decl->attributes ) {
    478         retDecl->attributes.push_back( attr );
    479     }
    480 
    481     return retDecl;
     477        for ( ast::ptr<ast::Attribute> const & attr : decl->attributes ) {
     478                retDecl->attributes.push_back( attr );
     479        }
     480
     481        return retDecl;
    482482}
    483483
     
    485485        ast::StructInstType const * postvisit( ast::VTableType const * type ) {
    486486                auto inst = type->base.as<ast::BaseInstType>();
    487        
     487
    488488                std::string vtableName = Virtual::vtableTypeName( inst->name );
    489489
  • src/Parser/StatementNode.cc

    r89bef959 r8d96dee  
    1010// Author           : Rodolfo G. Esteves
    1111// Created On       : Sat May 16 14:59:41 2015
    12 // Last Modified By : Andrew Beach
    13 // Last Modified On : Tue Apr 11 10:16:00 2023
    14 // Update Count     : 428
     12// Last Modified By : Peter A. Buhr
     13// Last Modified On : Fri Aug 11 11:44:15 2023
     14// Update Count     : 429
    1515//
    1616
     
    374374}
    375375
    376 ast::WaitUntilStmt::ClauseNode * build_waituntil_timeout( const CodeLocation & loc, ExpressionNode * when, ExpressionNode * timeout, StatementNode * stmt ) {
    377         ast::WhenClause * clause = new ast::WhenClause( loc );
    378         clause->when_cond = notZeroExpr( maybeMoveBuild( when ) );
    379         clause->stmt = maybeMoveBuild( stmt );
    380         clause->target = maybeMoveBuild( timeout );
    381         return new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::TIMEOUT, clause );
    382 }
    383 
    384376ast::WaitUntilStmt * build_waituntil_stmt( const CodeLocation & loc, ast::WaitUntilStmt::ClauseNode * root ) {
    385377        ast::WaitUntilStmt * retStmt = new ast::WaitUntilStmt( loc );
  • src/Parser/StatementNode.h

    r89bef959 r8d96dee  
    99// Author           : Andrew Beach
    1010// Created On       : Wed Apr  5 11:42:00 2023
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Apr 11  9:43:00 2023
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Aug 11 11:44:07 2023
     13// Update Count     : 2
    1414//
    1515
     
    102102ast::WaitUntilStmt::ClauseNode * build_waituntil_clause( const CodeLocation &, ExpressionNode * when, ExpressionNode * targetExpr, StatementNode * stmt );
    103103ast::WaitUntilStmt::ClauseNode * build_waituntil_else( const CodeLocation &, ExpressionNode * when, StatementNode * stmt );
    104 ast::WaitUntilStmt::ClauseNode * build_waituntil_timeout( const CodeLocation &, ExpressionNode * when, ExpressionNode * timeout, StatementNode * stmt );
    105104ast::WaitUntilStmt * build_waituntil_stmt( const CodeLocation &, ast::WaitUntilStmt::ClauseNode * root );
    106105ast::Stmt * build_with( const CodeLocation &, ExpressionNode * exprs, StatementNode * stmt );
  • src/Parser/parser.yy

    r89bef959 r8d96dee  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jul 12 23:06:44 2023
    13 // Update Count     : 6389
     12// Last Modified On : Tue Jul 18 22:51:30 2023
     13// Update Count     : 6391
    1414//
    1515
     
    17081708        | wor_waituntil_clause wor when_clause_opt ELSE statement
    17091709                { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1, build_waituntil_else( yylloc, $3, maybe_build_compound( yylloc, $5 ) ) ); }
    1710         | wor_waituntil_clause wor when_clause_opt timeout statement    %prec THEN
    1711                 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1, build_waituntil_timeout( yylloc, $3, $4, maybe_build_compound( yylloc, $5 ) ) ); }
    1712         // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
    1713         | wor_waituntil_clause wor when_clause_opt timeout statement wor ELSE statement // invalid syntax rule
    1714                 { SemanticError( yylloc, "syntax error, else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
    1715         | wor_waituntil_clause wor when_clause_opt timeout statement wor when_clause ELSE statement
    1716                 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1,
    1717                                 new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::OR,
    1718                                         build_waituntil_timeout( yylloc, $3, $4, maybe_build_compound( yylloc, $5 ) ),
    1719                                         build_waituntil_else( yylloc, $7, maybe_build_compound( yylloc, $9 ) ) ) ); }
    17201710        ;
    17211711
    17221712waituntil_statement:
    17231713        wor_waituntil_clause                                                            %prec THEN
    1724                 // SKULLDUGGERY: create an empty compound statement to test parsing of waituntil statement.
    1725                 {
    1726                         $$ = new StatementNode( build_waituntil_stmt( yylloc, $1 ) );
    1727                         // $$ = new StatementNode( build_compound( yylloc, nullptr ) );
    1728                 }
     1714                { $$ = new StatementNode( build_waituntil_stmt( yylloc, $1 ) ); }
    17291715        ;
    17301716
  • tests/io/.expect/manipulatorsOutput2.arm64.txt

    r89bef959 r8d96dee  
    440 033 033 033 033
    550345 0177745 037777777745 01777777777777777777745
    6 0 0x1b 0x1b 0x1b 0x1b
     60x0 0x1b 0x1b 0x1b 0x1b
    770xe5 0xffe5 0xffffffe5 0xffffffffffffffe5
    8 0x0p+0. 0x1.b8p+4 0x1.b8p+4 0x1.b8p+4
     80x0p+0 0x1.b8p+4 0x1.b8p+4 0x1.b8p+4
    99-0x1.b8p+4 -0x1.b8p+4 -0x1.b8p+4
    10100.000000e+00 2.750000e+01 -2.750000e+01
  • tests/io/.expect/manipulatorsOutput2.x86.txt

    r89bef959 r8d96dee  
    440 033 033 033 033
    550345 0177745 037777777745 037777777745
    6 0 0x1b 0x1b 0x1b 0x1b
     60x0 0x1b 0x1b 0x1b 0x1b
    770xe5 0xffe5 0xffffffe5 0xffffffe5
    8 0x0p+0. 0x1.b8p+4 0x1.b8p+4 0xd.cp+1
     80x0p+0 0x1.b8p+4 0x1.b8p+4 0xd.cp+1
    99-0x1.b8p+4 -0x1.b8p+4 -0xd.cp+1
    10100.000000e+00 2.750000e+01 -2.750000e+01
  • tests/io/.expect/manipulatorsOutput3.arm64.txt

    r89bef959 r8d96dee  
    246246-1                   0xffffffffffffffffffffffffffffffff 03777777777777777777777777777777777777777777
    2472470b11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
    248 +0                   0                    0                   
     248+0                   0x0                  0                   
    2492490b0                 
    250250+1                   0x1                  01                 
Note: See TracChangeset for help on using the changeset viewer.