Ignore:
Timestamp:
Jul 12, 2016, 6:34:10 PM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
e4d3ceb
Parents:
6e4b913
Message:

changes for switch and choose statements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r6e4b913 r4e06c1e  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jun 30 21:15:54 2016
    13 // Update Count     : 1657
     12// Last Modified On : Tue Jul 12 17:26:32 2016
     13// Update Count     : 1659
    1414//
    1515
     
    712712                { $$ = new StatementNode( StatementNode::Switch, $3, $5 ); }
    713713        | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
    714                 { $$ = new StatementNode( StatementNode::Switch, $3, $8 ); /* xxx */ }
    715                 // The semantics of the declaration list is changed to include any associated initialization, which is performed
    716                 // *before* the transfer to the appropriate case clause.  Statements after the initial declaration list can
    717                 // never be executed, and therefore, are removed from the grammar even though C allows it.
     714                {
     715                        StatementNode *sw = new StatementNode( StatementNode::Switch, $3, $8 );
     716                        // The semantics of the declaration list is changed to include associated initialization, which is performed
     717                        // *before* the transfer to the appropriate case clause by hoisting the declarations into a compound
     718                        // statement around the switch.  Statements after the initial declaration list can never be executed, and
     719                        // therefore, are removed from the grammar even though C allows it. Change also applies to choose statement.
     720                        $$ = $7 != 0 ? new CompoundStmtNode( (StatementNode *)((new StatementNode( $7 ))->set_link( sw )) ) : sw;
     721                }
    718722        | CHOOSE '(' comma_expression ')' case_clause           // CFA
    719                 { $$ = new StatementNode( StatementNode::Choose, $3, $5 ); }
     723                { $$ = new StatementNode( StatementNode::Switch, $3, $5 ); }
    720724        | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt choose_clause_list_opt '}' // CFA
    721                 { $$ = new StatementNode( StatementNode::Choose, $3, $8 ); }
     725                {
     726                        StatementNode *sw = new StatementNode( StatementNode::Switch, $3, $8 );
     727                        $$ = $7 != 0 ? new CompoundStmtNode( (StatementNode *)((new StatementNode( $7 ))->set_link( sw )) ) : sw;
     728                }
    722729        ;
    723730
     
    750757
    751758case_clause:                                                                                    // CFA
    752         case_label_list statement                                       { $$ = $1->append_last_case( $2 ); }
     759        case_label_list statement                                       { $$ = $1->append_last_case( new CompoundStmtNode( $2 ) ); }
    753760        ;
    754761
     
    761768switch_clause_list:                                                                             // CFA
    762769        case_label_list statement_list
    763                 { $$ = $1->append_last_case( $2 ); }
     770                { $$ = $1->append_last_case( new CompoundStmtNode( $2 ) ); }
    764771        | switch_clause_list case_label_list statement_list
    765                 { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( $3 ))); }
     772                { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( new CompoundStmtNode( $3 ) ) ) ); }
    766773        ;
    767774
     
    776783                { $$ = $1->append_last_case( $2 ); }
    777784        | case_label_list statement_list fall_through_opt
    778                 { $$ = $1->append_last_case((StatementNode *)mkList((*$2,*$3 ))); }
     785                { $$ = $1->append_last_case( new CompoundStmtNode( (StatementNode *)mkList( (*$2, *$3 ) ) ) ); }
    779786        | choose_clause_list case_label_list fall_through
    780787                { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( $3 ))); }
    781788        | choose_clause_list case_label_list statement_list fall_through_opt
    782                 { $$ = (StatementNode *)( $1->set_link( $2->append_last_case((StatementNode *)mkList((*$3,*$4 ))))); }
     789                { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( new CompoundStmtNode( (StatementNode *)mkList( (*$3, *$4 ) ) ) ) ) ); }
    783790        ;
    784791
    785792fall_through_opt:                                                                               // CFA
    786793        // empty
     794                { $$ = new StatementNode( StatementNode::Break ); }     // insert implicit break
     795        | fall_through
     796        ;
     797
     798fall_through:                                                                                   // CFA
     799        FALLTHRU
    787800                { $$ = 0; }
    788         | fall_through
    789         ;
    790 
    791 fall_through:                                                                                   // CFA
    792         FALLTHRU                                                                        { $$ = new StatementNode( StatementNode::Fallthru ); }
    793         | FALLTHRU ';'                                                          { $$ = new StatementNode( StatementNode::Fallthru ); }
     801        | FALLTHRU ';'
     802                { $$ = 0; }
    794803        ;
    795804
     
    814823                { $$ = new StatementNode( StatementNode::Goto, $2 ); }
    815824        | GOTO '*' comma_expression ';'                                         // GCC, computed goto
    816                 // The syntax for the GCC computed goto violates normal expression precedence, e.g., goto *i+3; => goto *(i+3 );
     825                // The syntax for the GCC computed goto violates normal expression precedence, e.g., goto *i+3; => goto *(i+3);
    817826                // whereas normal operator precedence yields goto (*i)+3;
    818827                { $$ = new StatementNode( StatementNode::Goto, $3 ); }
     
    820829                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
    821830                { $$ = new StatementNode( StatementNode::Continue ); }
    822         | CONTINUE IDENTIFIER ';'                                       // CFA, multi-level continue
     831        | CONTINUE IDENTIFIER ';'                                                       // CFA, multi-level continue
    823832                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
    824833                // the target of the transfer appears only at the start of an iteration statement.
     
    827836                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
    828837                { $$ = new StatementNode( StatementNode::Break ); }
    829         | BREAK IDENTIFIER ';'                                          // CFA, multi-level exit
     838        | BREAK IDENTIFIER ';'                                                          // CFA, multi-level exit
    830839                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
    831840                // the target of the transfer appears only at the start of an iteration statement.
     
    951960        ;
    952961
    953 asm_clobbers_list_opt:                                                                          // GCC
     962asm_clobbers_list_opt:                                                                  // GCC
    954963        // empty
    955964                { $$ = 0; }                                                                             // use default argument
     
    14521461                { typedefTable.makeTypedef( *$2 ); }
    14531462                '{' field_declaration_list '}'
    1454                 { $$ = DeclarationNode::newAggregate( $1, $2, 0, $5); }
     1463                { $$ = DeclarationNode::newAggregate( $1, $2, 0, $5 ); }
    14551464        | aggregate_key '(' type_name_list ')' '{' field_declaration_list '}' // CFA
    14561465                { $$ = DeclarationNode::newAggregate( $1, 0, $3, $6 ); }
     
    18401849                { $$ = 0; }
    18411850        | assertion_list_opt assertion
    1842                 { $$ = $1 == 0 ? $2 : $1->appendList( $2 ); }
     1851                { $$ = $1 != 0 ? $1->appendList( $2 ) : $2; }
    18431852        ;
    18441853
Note: See TracChangeset for help on using the changeset viewer.