Changeset 135b431 for src/Parser


Ignore:
Timestamp:
Aug 25, 2017, 11:09:02 AM (8 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, resolv-new, with_gc
Children:
6b224a52
Parents:
3eab0ef6
Message:

First step for waitfor statments, does nothing but is there

Location:
src/Parser
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ParseNode.h

    r3eab0ef6 r135b431  
    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

    r3eab0ef6 r135b431  
    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

    r3eab0ef6 r135b431  
    9797        DeclarationNode::TypeClass tclass;
    9898        StatementNode * sn;
     99        WaitForStmt * wfs;
    99100        ConstantExpr * constant;
    100101        IfCtl * ifctl;
     
    187188%type<flag> asm_volatile_opt
    188189%type<en> handler_predicate_opt
     190%type<en> when_clause_opt timeout
    189191
    190192// statements
     
    192194%type<sn> iteration_statement                   jump_statement
    193195%type<sn> with_statement                                exception_statement                     asm_statement
    194 %type<sn> when_clause_opt                               waitfor_statement                       waitfor_clause                          waitfor                         timeout
     196%type<sn> waitfor_statement
    195197%type<sn> fall_through_opt                              fall_through
    196198%type<sn> statement                                             statement_list
     
    202204%type<sn> handler_clause                                finally_clause
    203205%type<catch_kind> handler_key
     206%type<wfs> waitfor_clause
     207%type<en> waitfor
    204208
    205209// declarations
     
    979983when_clause_opt:
    980984        // empty
    981                 { $$ = nullptr; }                                                               // FIX ME
     985                { $$ = nullptr; }
    982986        | WHEN '(' comma_expression ')'
    983                 { $$ = nullptr; }                                                               // FIX ME
     987                { $$ = $3; }
    984988        ;
    985989
    986990waitfor:
    987991        WAITFOR '(' identifier ')'
    988                 { $$ = nullptr; }                                                               // FIX ME
     992                {
     993                        $$ = new ExpressionNode( new NameExpr( *$3 ) );
     994                        delete $3;
     995                }
    989996        | WAITFOR '(' identifier ',' argument_expression_list ')'
    990                 { $$ = nullptr; }                                                               // FIX ME
     997                {
     998                        $$ = new ExpressionNode( new NameExpr( *$3 ) );
     999                        $$->set_last( $5 );
     1000                        delete $3;
     1001                }
    9911002        ;
    9921003
    9931004timeout:
    9941005        TIMEOUT '(' comma_expression ')'
    995                 { $$ = nullptr; }                                                               // FIX ME
     1006                { $$ = $3; }
    9961007        ;
    9971008
    9981009waitfor_clause:
    9991010        when_clause_opt waitfor statement %prec THEN
    1000                 { $$ = nullptr; }                                                               // FIX ME
     1011                { $$ = build_waitfor( $2, $3, $1 ); }
    10011012        | when_clause_opt waitfor statement WOR waitfor_clause
    1002                 { $$ = nullptr; }                                                               // FIX ME
     1013                { $$ = build_waitfor( $2, $3, $1, $5 ); }
    10031014        | when_clause_opt timeout statement %prec THEN
    1004                 { $$ = nullptr; }                                                               // FIX ME
     1015                { $$ = build_waitfor_timeout( $2, $3, $1 ); }
    10051016        | when_clause_opt ELSE statement
    1006                 { $$ = nullptr; }                                                               // FIX ME
     1017                { $$ = build_waitfor_timeout( nullptr, $3, $1 ); }
    10071018        | when_clause_opt timeout statement WOR when_clause_opt ELSE statement
    1008                 { $$ = nullptr; }                                                               // FIX ME
     1019                { $$ = build_waitfor_timeout( $2, $3, $1, $7, $5 ); }
    10091020        ;
    10101021
    10111022waitfor_statement:
    10121023        when_clause_opt waitfor statement %prec THEN
    1013                 { $$ = nullptr; }                                                               // FIX ME
     1024                { $$ = new StatementNode( build_waitfor( $2, $3, $1 ) ); }
    10141025        | when_clause_opt waitfor statement WOR waitfor_clause
    1015                 { $$ = nullptr; }                                                               // FIX ME
     1026                { $$ = new StatementNode( build_waitfor( $2, $3, $1, $5 ) ); }
    10161027        ;
    10171028
Note: See TracChangeset for help on using the changeset viewer.