Changeset dafdbe7 for src


Ignore:
Timestamp:
Jun 5, 2018, 3:32:50 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
Children:
174845e, 214e8da
Parents:
5510027 (diff), 401e61f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

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

Location:
src
Files:
5 edited
2 moved

Legend:

Unmodified
Added
Removed
  • src/Parser/ExpressionNode.cc

    r5510027 rdafdbe7  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 22 11:57:39 2018
    13 // Update Count     : 801
     12// Last Modified On : Mon Jun  4 21:24:45 2018
     13// Update Count     : 802
    1414//
    1515
     
    314314
    315315Expression * build_constantStr( string & str ) {
     316        assert( str.length() > 0 );
    316317        string units;                                                                           // units
    317318        sepString( str, units, '"' );                                           // separate constant from units
  • src/Parser/ParseNode.h

    r5510027 rdafdbe7  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Apr 30 09:19:17 2018
    13 // Update Count     : 831
     12// Last Modified On : Mon Jun  4 22:21:04 2018
     13// Update Count     : 832
    1414//
    1515
     
    408408Statement * build_case( ExpressionNode * ctl );
    409409Statement * build_default();
    410 Statement * build_while( ExpressionNode * ctl, StatementNode * stmt, bool kind = false );
     410Statement * build_while( IfCtl * ctl, StatementNode * stmt );
     411Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt );
    411412Statement * build_for( ForCtl * forctl, StatementNode * stmt );
    412413Statement * build_branch( BranchStmt::Type kind );
  • src/Parser/StatementNode.cc

    r5510027 rdafdbe7  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Apr 30 09:21:16 2018
    13 // Update Count     : 354
     12// Last Modified On : Tue Jun  5 08:58:34 2018
     13// Update Count     : 362
    1414//
    1515
     
    6969        caseStmt->get_statements().splice( caseStmt->get_statements().end(), stmts );
    7070        return this;
    71 }
     71} // StatementNode::append_last_case
    7272
    7373Statement * build_expr( ExpressionNode * ctl ) {
    7474        Expression * e = maybeMoveBuild< Expression >( ctl );
    7575
    76         if ( e )
    77                 return new ExprStmt( e );
    78         else
    79                 return new NullStmt();
    80 }
     76        if ( e ) return new ExprStmt( e );
     77        else return new NullStmt();
     78} // build_expr
    8179
    8280Expression * build_if_control( IfCtl * ctl, std::list< Statement * > & init ) {
     
    10098        delete ctl;
    10199        return cond;
    102 }
     100} // build_if_control
    103101
    104102Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ) {
    105         Statement * thenb, * elseb = 0;
     103        Statement * thenb, * elseb = nullptr;
    106104        std::list< Statement * > branches;
    107105        buildMoveList< Statement, StatementNode >( then_stmt, branches );
     
    119117        Expression * cond = build_if_control( ctl, init );
    120118        return new IfStmt( cond, thenb, elseb, init );
    121 }
     119} // build_if
    122120
    123121Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt ) {
     
    135133        // branches.size() == 0 for switch (...) {}, i.e., no declaration or statements
    136134        return new SwitchStmt( maybeMoveBuild< Expression >(ctl), branches );
    137 }
     135} // build_switch
     136
    138137Statement * build_case( ExpressionNode * ctl ) {
    139138        std::list< Statement * > branches;
    140139        return new CaseStmt( maybeMoveBuild< Expression >(ctl), branches );
    141 }
     140} // build_case
     141
    142142Statement * build_default() {
    143143        std::list< Statement * > branches;
    144144        return new CaseStmt( nullptr, branches, true );
    145 }
    146 
    147 Statement * build_while( ExpressionNode * ctl, StatementNode * stmt, bool kind ) {
     145} // build_default
     146
     147Statement * build_while( IfCtl * ctl, StatementNode * stmt ) {
    148148        std::list< Statement * > branches;
    149149        buildMoveList< Statement, StatementNode >( stmt, branches );
     
    151151
    152152        std::list< Statement * > init;
    153         return new WhileStmt( notZeroExpr( maybeMoveBuild< Expression >(ctl) ), branches.front(), init, kind );
    154 }
     153        Expression * cond = build_if_control( ctl, init );
     154        return new WhileStmt( cond, branches.front(), init, false );
     155} // build_while
     156
     157Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt ) {
     158        std::list< Statement * > branches;
     159        buildMoveList< Statement, StatementNode >( stmt, branches );
     160        assert( branches.size() == 1 );
     161
     162        std::list< Statement * > init;
     163        return new WhileStmt( notZeroExpr( maybeMoveBuild< Expression >(ctl) ), branches.front(), init, true );
     164} // build_do_while
    155165
    156166Statement * build_for( ForCtl * forctl, StatementNode * stmt ) {
     
    174184        delete forctl;
    175185        return new ForStmt( init, cond, incr, branches.front() );
    176 }
     186} // build_for
    177187
    178188Statement * build_branch( BranchStmt::Type kind ) {
    179189        Statement * ret = new BranchStmt( "", kind );
    180190        return ret;
    181 }
     191} // build_branch
     192
    182193Statement * build_branch( std::string * identifier, BranchStmt::Type kind ) {
    183194        Statement * ret = new BranchStmt( * identifier, kind );
    184195        delete identifier;                                                                      // allocated by lexer
    185196        return ret;
    186 }
     197} // build_branch
     198
    187199Statement * build_computedgoto( ExpressionNode * ctl ) {
    188200        return new BranchStmt( maybeMoveBuild< Expression >(ctl), BranchStmt::Goto );
    189 }
     201} // build_computedgoto
    190202
    191203Statement * build_return( ExpressionNode * ctl ) {
     
    193205        buildMoveList( ctl, exps );
    194206        return new ReturnStmt( exps.size() > 0 ? exps.back() : nullptr );
    195 }
     207} // build_return
    196208
    197209Statement * build_throw( ExpressionNode * ctl ) {
     
    200212        assertf( exps.size() < 2, "This means we are leaking memory");
    201213        return new ThrowStmt( ThrowStmt::Terminate, !exps.empty() ? exps.back() : nullptr );
    202 }
     214} // build_throw
    203215
    204216Statement * build_resume( ExpressionNode * ctl ) {
     
    207219        assertf( exps.size() < 2, "This means we are leaking memory");
    208220        return new ThrowStmt( ThrowStmt::Resume, !exps.empty() ? exps.back() : nullptr );
    209 }
     221} // build_resume
    210222
    211223Statement * build_resume_at( ExpressionNode * ctl, ExpressionNode * target ) {
     
    213225        (void)target;
    214226        assertf( false, "resume at (non-local throw) is not yet supported," );
    215 }
     227} // build_resume_at
    216228
    217229Statement * build_try( StatementNode * try_stmt, StatementNode * catch_stmt, StatementNode * finally_stmt ) {
     
    221233        FinallyStmt * finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) );
    222234        return new TryStmt( tryBlock, branches, finallyBlock );
    223 }
     235} // build_try
     236
    224237Statement * build_catch( CatchStmt::Kind kind, DeclarationNode * decl, ExpressionNode * cond, StatementNode * body ) {
    225238        std::list< Statement * > branches;
     
    227240        assert( branches.size() == 1 );
    228241        return new CatchStmt( kind, maybeMoveBuild< Declaration >(decl), maybeMoveBuild< Expression >(cond), branches.front() );
    229 }
     242} // build_catch
     243
    230244Statement * build_finally( StatementNode * stmt ) {
    231245        std::list< Statement * > branches;
     
    233247        assert( branches.size() == 1 );
    234248        return new FinallyStmt( dynamic_cast< CompoundStmt * >( branches.front() ) );
    235 }
     249} // build_finally
    236250
    237251WaitForStmt * build_waitfor( ExpressionNode * targetExpr, StatementNode * stmt, ExpressionNode * when ) {
     
    254268
    255269        return node;
    256 }
     270} // build_waitfor
    257271
    258272WaitForStmt * build_waitfor( ExpressionNode * targetExpr, StatementNode * stmt, ExpressionNode * when, WaitForStmt * node ) {
     
    273287
    274288        return node;
    275 }
     289} // build_waitfor
    276290
    277291WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when ) {
     
    282296                node->timeout.statement = maybeMoveBuild<Statement >( stmt    );
    283297                node->timeout.condition = notZeroExpr( maybeMoveBuild<Expression>( when ) );
    284         }
    285         else {
     298        } else {
    286299                node->orelse.statement  = maybeMoveBuild<Statement >( stmt );
    287300                node->orelse.condition  = notZeroExpr( maybeMoveBuild<Expression>( when ) );
    288         }
     301        } // if
    289302
    290303        return node;
    291 }
     304} // build_waitfor_timeout
    292305
    293306WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when,  StatementNode * else_stmt, ExpressionNode * else_when ) {
     
    302315
    303316        return node;
    304 }
     317} // build_waitfor_timeout
    305318
    306319WithStmt * build_with( ExpressionNode * exprs, StatementNode * stmt ) {
     
    309322        Statement * s = maybeMoveBuild<Statement>( stmt );
    310323        return new WithStmt( e, s );
    311 }
     324} // build_with
    312325
    313326Statement * build_compound( StatementNode * first ) {
     
    315328        buildMoveList( first, cs->get_kids() );
    316329        return cs;
    317 }
     330} // build_compound
    318331
    319332Statement * build_asm( bool voltile, Expression * instruction, ExpressionNode * output, ExpressionNode * input, ExpressionNode * clobber, LabelNode * gotolabels ) {
     
    325338        buildMoveList( clobber, clob );
    326339        return new AsmStmt( voltile, instruction, out, in, clob, gotolabels ? gotolabels->labels : noLabels );
    327 }
     340} // build_asm
    328341
    329342Statement * build_directive( string * directive ) {
    330343        return new DirectiveStmt( *directive );
    331 }
     344} // build_directive
    332345
    333346// Local Variables: //
  • src/Parser/parser.yy

    r5510027 rdafdbe7  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jun  1 17:59:57 2018
    13 // Update Count     : 3476
     12// Last Modified On : Mon Jun  4 22:22:04 2018
     13// Update Count     : 3492
    1414//
    1515
     
    10501050
    10511051iteration_statement:
    1052         WHILE '(' comma_expression ')' statement
    1053                 { $$ = new StatementNode( build_while( $3, $5 ) ); }
     1052        WHILE '(' push if_control_expression ')' statement pop
     1053                { $$ = new StatementNode( build_while( $4, $6 ) ); }
    10541054        | DO statement WHILE '(' comma_expression ')' ';'
    1055                 { $$ = new StatementNode( build_while( $5, $2, true ) ); }
     1055                { $$ = new StatementNode( build_do_while( $5, $2 ) ); }
    10561056        | FOR '(' push for_control_expression ')' statement pop
    10571057                { $$ = new StatementNode( build_for( $4, $6 ) ); }
     
    13311331        c_declaration ';'
    13321332        | cfa_declaration ';'                                                           // CFA
    1333         | static_assert
     1333        | static_assert                                                                         // C11
    13341334        ;
    13351335
     
    13371337        STATICASSERT '(' constant_expression ',' string_literal ')' ';' // C11
    13381338                { $$ = DeclarationNode::newStaticAssert( $3, $5 ); }
     1339        | STATICASSERT '(' constant_expression ')' ';'          // CFA
     1340                { $$ = DeclarationNode::newStaticAssert( $3, build_constantStr( *new string( "\"\"" ) ) ); }
    13391341
    13401342// C declaration syntax is notoriously confusing and error prone. Cforall provides its own type, variable and function
     
    18811883
    18821884field_declaration:
    1883         cfa_field_declaring_list ';'                                            // CFA, new style field declaration
     1885        type_specifier field_declaring_list ';'
     1886                { $$ = distAttr( $1, $2 ); }
     1887        | EXTENSION type_specifier field_declaring_list ';'     // GCC
     1888                { distExt( $3 ); $$ = distAttr( $2, $3 ); }             // mark all fields in list
     1889        | typedef_declaration ';'                                                       // CFA
     1890                { SemanticError( yylloc, "Typedef in aggregate is currently unimplemented." ); $$ = nullptr; }
     1891        | cfa_field_declaring_list ';'                                          // CFA, new style field declaration
    18841892        | EXTENSION cfa_field_declaring_list ';'                        // GCC
    1885                 {
    1886                         distExt( $2 );                                                          // mark all fields in list
    1887                         $$ = $2;
    1888                 }
    1889         | type_specifier field_declaring_list ';'
    1890                 {
    1891                         $$ = distAttr( $1, $2 ); }
    1892         | EXTENSION type_specifier field_declaring_list ';'     // GCC
    1893                 {
    1894                         distExt( $3 );                                                          // mark all fields in list
    1895                         $$ = distAttr( $2, $3 );
    1896                 }
    1897         | static_assert
     1893                { distExt( $2 ); $$ = $2; }                                             // mark all fields in list
     1894        | cfa_typedef_declaration ';'                                           // CFA
     1895                { SemanticError( yylloc, "Typedef in aggregate is currently unimplemented." ); $$ = nullptr; }
     1896        | static_assert                                                                         // C11
    18981897        ;
    18991898
  • src/tests/.expect/ifwhileCtl.txt

    r5510027 rdafdbe7  
    33x == y correct
    44s.i < 4 correct
     5x != 0 correct
     6x == y correct
     7s.i < 4 correct
  • src/tests/ifwhileCtl.c

    r5510027 rdafdbe7  
    1010// Created On       : Sat Aug 26 10:13:11 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jun  2 09:55:02 2018
    13 // Update Count     : 15
     12// Last Modified On : Mon Jun  4 22:46:48 2018
     13// Update Count     : 19
    1414//
    1515
     
    4242
    4343        if ( struct S { int i; } s = { 3 }; s.i < 4 ) {
     44                S s1;
    4445                sout | "s.i < 4 correct" | endl;
    4546        } else {
     47                S s1;
    4648                sout | "s.i >= 4 incorrect" | endl;
    4749        } // if
     50
     51        while ( int x = 1 ) {
     52                sout | "x != 0 correct" | endl;
     53                break;
     54        } // while
     55
     56        while ( int x = 4, y = 0 ) {
     57                sout | "x != 0 && y != 0 incorrect" | endl;
     58        } // while
     59
     60        while ( int x = 5, y = f( x ); x == y ) {
     61                sout | "x == y correct" | endl;
     62                break;
     63        } // while
     64
     65        while ( struct S { int i; } s = { 3 }; s.i < 4 ) {
     66                S s1;
     67                sout | "s.i < 4 correct" | endl;
     68                break;
     69        } // while
    4870} // main
    4971
  • src/tests/sum.c

    r5510027 rdafdbe7  
    1111// Created On       : Wed May 27 17:56:53 2015
    1212// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Sat Feb 17 11:49:17 2018
    14 // Update Count     : 273
     13// Last Modified On : Sun Jun  3 19:23:41 2018
     14// Update Count     : 278
    1515//
    1616
     
    1818#include <stdlib>
    1919
    20 void ?{}( int & c, zero_t ) { c = 0; }
     20void ?{}( int & c, zero_t ) { c = 0; }                                  // not in prelude
    2121
    2222trait sumable( otype T ) {
    23         void ?{}( T &, zero_t );                                                        // constructor from 0 literal
     23        void ?{}( T &, zero_t );                                                        // 0 literal constructor
    2424        T ?+?( T, T );                                                                          // assortment of additions
    2525        T ?+=?( T &, T );
     
    2929
    3030forall( otype T | sumable( T ) )                                                // use trait
    31 T sum( unsigned int size, T a[] ) {
    32         T total = 0;                                                                            // instantiate T from 0 by calling constructor
    33         for ( unsigned int i = 0; i < size; i += 1 )
     31T sum( size_t size, T a[] ) {
     32        T total = 0;                                                                            // initialize by 0 constructor
     33        for ( size_t i = 0; i < size; i += 1 )
    3434                total += a[i];                                                                  // select appropriate +
    3535        return total;
     
    111111        for ( int i = 0; i < size; i += 1, v += 1 ) {
    112112                s += (int)v;
    113                 gs.x[i] = (int)v;                                                               // set filed array in generic type
     113                gs.x[i] = (int)v;                                                               // set field array in generic type
    114114        } // for
    115115        sout | "sum from" | low | "to" | High | "is"
    116                  | sum( size, gs.x ) | ", check" | (int)s | endl; // add filed array in generic type
     116                 | sum( size, gs.x ) | ", check" | (int)s | endl; // add field array in generic type
    117117} // main
    118118
Note: See TracChangeset for help on using the changeset viewer.