Changeset 1cb758f2 for src/Parser


Ignore:
Timestamp:
Aug 27, 2017, 11:26:26 AM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
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, resolv-new, with_gc
Children:
111a8af8, 26238c1, 7ee1e2f6
Parents:
0c6596f (diff), eca3d10a (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:/u/cforall/software/cfa/cfa-cc

Location:
src/Parser
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ParseNode.h

    r0c6596f r1cb758f2  
    414414Statement * build_compound( StatementNode * first );
    415415Statement * build_asmstmt( bool voltile, ConstantExpr * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr );
     416WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when );
     417WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when, WaitForStmt * existing );
     418WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when );
     419WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when, StatementNode * else_stmt, ExpressionNode * else_when );
    416420
    417421//##############################################################################
  • src/Parser/StatementNode.cc

    r0c6596f r1cb758f2  
    9393                elseb = branches.front();
    9494        } // if
    95        
     95
    9696        std::list< Statement * > init;
    9797        if ( ctl->init != 0 ) {
     
    207207}
    208208
     209WaitForStmt * build_waitfor( ExpressionNode * targetExpr, StatementNode * stmt, ExpressionNode * when ) {
     210        auto node = new WaitForStmt();
     211
     212        WaitForStmt::Target target;
     213        target.function = maybeBuild<Expression>( targetExpr );
     214        buildMoveList< Expression >( targetExpr, target.arguments );
     215        delete targetExpr;
     216
     217        node->clauses.push_back( WaitForStmt::Clause{
     218                target,
     219                maybeMoveBuild<Statement >( stmt ),
     220                maybeMoveBuild<Expression>( when )
     221        });
     222
     223        return node;
     224}
     225
     226WaitForStmt * build_waitfor( ExpressionNode * targetExpr, StatementNode * stmt, ExpressionNode * when, WaitForStmt * node ) {
     227        WaitForStmt::Target target;
     228
     229        target.function = maybeBuild<Expression>( targetExpr );
     230        buildMoveList< Expression >( targetExpr, target.arguments );
     231        delete targetExpr;
     232
     233        node->clauses.push_back( WaitForStmt::Clause{
     234                std::move( target ),
     235                maybeMoveBuild<Statement >( stmt ),
     236                maybeMoveBuild<Expression>( when )
     237        });
     238
     239        return node;
     240}
     241
     242WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when ) {
     243        auto node = new WaitForStmt();
     244
     245        if( timeout ) {
     246                node->timeout.time      = maybeMoveBuild<Expression>( timeout );
     247                node->timeout.statement = maybeMoveBuild<Statement >( stmt    );
     248                node->timeout.condition = maybeMoveBuild<Expression>( when    );
     249        }
     250        else {
     251                node->orelse.statement  = maybeMoveBuild<Statement >( stmt    );
     252                node->orelse.condition  = maybeMoveBuild<Expression>( when    );
     253        }
     254
     255        return node;
     256}
     257
     258WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when,  StatementNode * else_stmt, ExpressionNode * else_when ) {
     259        auto node = new WaitForStmt();
     260
     261        node->timeout.time      = maybeMoveBuild<Expression>( timeout );
     262        node->timeout.statement = maybeMoveBuild<Statement >( stmt    );
     263        node->timeout.condition = maybeMoveBuild<Expression>( when    );
     264
     265        node->orelse.statement = maybeMoveBuild<Statement >( else_stmt );
     266        node->orelse.condition = maybeMoveBuild<Expression>( else_when );
     267
     268        return node;
     269}
     270
     271// WaitForStmt::Target build_waitfor( const std::string * name, ExpressionNode * arguments ) {
     272//       return WaitForStmt::Clause{
     273
     274//       };
     275// }
     276
    209277Statement *build_compound( StatementNode *first ) {
    210278        CompoundStmt *cs = new CompoundStmt( noLabels );
  • src/Parser/parser.yy

    r0c6596f r1cb758f2  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug 23 21:08:08 2017
    13 // Update Count     : 2704
     12// Last Modified On : Sat Aug 26 17:50:19 2017
     13// Update Count     : 2712
    1414//
    1515
     
    9797        DeclarationNode::TypeClass tclass;
    9898        StatementNode * sn;
     99        WaitForStmt * wfs;
    99100        ConstantExpr * constant;
    100101        IfCtl * ifctl;
     
    119120%token RESTRICT                                                                                 // C99
    120121%token ATOMIC                                                                                   // C11
    121 %token FORALL MUTEX VIRTUAL                                             // CFA
     122%token FORALL MUTEX VIRTUAL                                                             // CFA
    122123%token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED
    123124%token BOOL COMPLEX IMAGINARY                                                   // C99
     
    189190
    190191// statements
    191 %type<sn> labeled_statement                             compound_statement                      expression_statement            selection_statement
    192 %type<sn> iteration_statement                   jump_statement
    193 %type<sn> with_statement                                exception_statement                     asm_statement
    194 %type<sn> when_clause_opt                               waitfor_statement                       waitfor_clause                          waitfor                         timeout
    195 %type<sn> fall_through_opt                              fall_through
    196 %type<sn> statement                                             statement_list
    197 %type<sn> block_item_list                               block_item
    198 %type<sn> with_clause_opt
     192%type<sn> statement                                             labeled_statement                       compound_statement
     193%type<sn> statement_decl                                statement_decl_list                     statement_list_nodecl
     194%type<sn> selection_statement
     195%type<sn> switch_clause_list_opt                switch_clause_list                      choose_clause_list_opt          choose_clause_list
    199196%type<en> case_value
    200197%type<sn> case_clause                                   case_value_list                         case_label                                      case_label_list
    201 %type<sn> switch_clause_list_opt                switch_clause_list                      choose_clause_list_opt          choose_clause_list
    202 %type<sn> handler_clause                                finally_clause
     198%type<sn> fall_through                                  fall_through_opt
     199%type<sn> iteration_statement                   jump_statement
     200%type<sn> expression_statement                  asm_statement
     201%type<sn> with_statement                                with_clause_opt
     202%type<sn> exception_statement                   handler_clause                          finally_clause
    203203%type<catch_kind> handler_key
     204%type<en> when_clause                                   when_clause_opt                         waitfor                                         timeout
     205%type<sn> waitfor_statement
     206%type<wfs> waitfor_clause
    204207
    205208// declarations
     
    773776          push push
    774777          local_label_declaration_opt                                           // GCC, local labels
    775           block_item_list                                                                       // C99, intermix declarations and statements
     778          statement_decl_list                                                           // C99, intermix declarations and statements
    776779          pop '}'
    777780                { $$ = new StatementNode( build_compound( $5 ) ); }
    778781        ;
    779782
    780 block_item_list:                                                                                // C99
    781         block_item
    782         | block_item_list push block_item
     783statement_decl_list:                                                                    // C99
     784        statement_decl
     785        | statement_decl_list push statement_decl
    783786                { if ( $1 != 0 ) { $1->set_last( $3 ); $$ = $1; } }
    784787        ;
    785788
    786 block_item:
     789statement_decl:
    787790        declaration                                                                                     // CFA, new & old style declarations
    788791                { $$ = new StatementNode( $1 ); }
     
    802805        ;
    803806
    804 statement_list:
     807statement_list_nodecl:
    805808        statement
    806         | statement_list statement
     809        | statement_list_nodecl statement
    807810                { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
    808811        ;
     
    814817
    815818selection_statement:
    816         IF '(' push if_control_expression ')' statement                         %prec THEN
     819        IF '(' push if_control_expression ')' statement         %prec THEN
    817820                // explicitly deal with the shift/reduce conflict on if/else
    818821                { $$ = new StatementNode( build_if( $4, $6, nullptr ) ); }
     
    889892
    890893switch_clause_list:                                                                             // CFA
    891         case_label_list statement_list
     894        case_label_list statement_list_nodecl
    892895                { $$ = $1->append_last_case( new StatementNode( build_compound( $2 ) ) ); }
    893         | switch_clause_list case_label_list statement_list
     896        | switch_clause_list case_label_list statement_list_nodecl
    894897                { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( $3 ) ) ) ) ); }
    895898        ;
     
    904907        case_label_list fall_through
    905908                { $$ = $1->append_last_case( $2 ); }
    906         | case_label_list statement_list fall_through_opt
     909        | case_label_list statement_list_nodecl fall_through_opt
    907910                { $$ = $1->append_last_case( new StatementNode( build_compound( (StatementNode *)$2->set_last( $3 ) ) ) ); }
    908911        | choose_clause_list case_label_list fall_through
    909912                { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( $3 ))); }
    910         | choose_clause_list case_label_list statement_list fall_through_opt
     913        | choose_clause_list case_label_list statement_list_nodecl fall_through_opt
    911914                { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( (StatementNode *)$3->set_last( $4 ) ) ) ) ) ); }
    912915        ;
     
    977980        ;
    978981
     982when_clause:
     983        WHEN '(' comma_expression ')'
     984                { $$ = $3; }
     985        ;
     986
    979987when_clause_opt:
    980988        // empty
    981                 { $$ = nullptr; }                                                               // FIX ME
    982         | WHEN '(' comma_expression ')'
    983                 { $$ = nullptr; }                                                               // FIX ME
     989                { $$ = nullptr; }
     990        | when_clause
    984991        ;
    985992
    986993waitfor:
    987994        WAITFOR '(' identifier ')'
    988                 { $$ = nullptr; }                                                               // FIX ME
     995                {
     996                        $$ = new ExpressionNode( new NameExpr( *$3 ) );
     997                        delete $3;
     998                }
    989999        | WAITFOR '(' identifier ',' argument_expression_list ')'
    990                 { $$ = nullptr; }                                                               // FIX ME
     1000                {
     1001                        $$ = new ExpressionNode( new NameExpr( *$3 ) );
     1002                        $$->set_last( $5 );
     1003                        delete $3;
     1004                }
    9911005        ;
    9921006
    9931007timeout:
    9941008        TIMEOUT '(' comma_expression ')'
    995                 { $$ = nullptr; }                                                               // FIX ME
     1009                { $$ = $3; }
    9961010        ;
    9971011
    9981012waitfor_clause:
    999         when_clause_opt waitfor statement %prec THEN
    1000                 { $$ = nullptr; }                                                               // FIX ME
     1013        when_clause_opt waitfor statement                                       %prec THEN
     1014                { $$ = build_waitfor( $2, $3, $1 ); }
    10011015        | when_clause_opt waitfor statement WOR waitfor_clause
    1002                 { $$ = nullptr; }                                                               // FIX ME
    1003         | when_clause_opt timeout statement %prec THEN
    1004                 { $$ = nullptr; }                                                               // FIX ME
     1016                { $$ = build_waitfor( $2, $3, $1, $5 ); }
     1017        | when_clause_opt timeout statement                                     %prec THEN
     1018                { $$ = build_waitfor_timeout( $2, $3, $1 ); }
    10051019        | when_clause_opt ELSE statement
    1006                 { $$ = nullptr; }                                                               // FIX ME
    1007         | when_clause_opt timeout statement WOR when_clause_opt ELSE statement
    1008                 { $$ = nullptr; }                                                               // FIX ME
     1020                { $$ = build_waitfor_timeout( nullptr, $3, $1 ); }
     1021                // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
     1022        | when_clause_opt timeout statement WOR when_clause ELSE statement
     1023                { $$ = build_waitfor_timeout( $2, $3, $1, $7, $5 ); }
    10091024        ;
    10101025
    10111026waitfor_statement:
    1012         when_clause_opt waitfor statement %prec THEN
    1013                 { $$ = nullptr; }                                                               // FIX ME
     1027        when_clause_opt waitfor statement                                       %prec THEN
     1028                { $$ = new StatementNode( build_waitfor( $2, $3, $1 ) ); }
    10141029        | when_clause_opt waitfor statement WOR waitfor_clause
    1015                 { $$ = nullptr; }                                                               // FIX ME
     1030                { $$ = new StatementNode( build_waitfor( $2, $3, $1, $5 ) ); }
    10161031        ;
    10171032
Note: See TracChangeset for help on using the changeset viewer.