Changeset 6a276a0 for src


Ignore:
Timestamp:
Mar 14, 2018, 1:19:39 PM (6 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, with_gc
Children:
720a007
Parents:
e2c70ab
Message:

Update parser for new fallthrough semantics

Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ParseNode.h

    re2c70ab r6a276a0  
    392392
    393393Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt );
    394 Statement * build_switch( ExpressionNode * ctl, StatementNode * stmt );
     394Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt );
    395395Statement * build_case( ExpressionNode * ctl );
    396396Statement * build_default();
  • src/Parser/StatementNode.cc

    re2c70ab r6a276a0  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Sep  1 23:25:23 2017
    13 // Update Count     : 346
     12// Last Modified On : Thu Mar  8 14:31:32 2018
     13// Update Count     : 348
    1414//
    1515
     
    116116}
    117117
    118 Statement *build_switch( ExpressionNode *ctl, StatementNode *stmt ) {
     118Statement *build_switch( bool isSwitch, ExpressionNode *ctl, StatementNode *stmt ) {
    119119        std::list< Statement * > branches;
    120120        buildMoveList< Statement, StatementNode >( stmt, branches );
     121        if ( ! isSwitch ) {                                                                             // choose statement
     122                for ( Statement * stmt : branches ) {
     123                        CaseStmt * caseStmt = strict_dynamic_cast< CaseStmt * >( stmt );
     124                        if ( ! caseStmt->stmts.empty() ) {                      // code after "case" => end of case list
     125                                CompoundStmt * block = strict_dynamic_cast< CompoundStmt * >( caseStmt->stmts.front() );
     126                                block->kids.push_back( new BranchStmt( "", BranchStmt::Break ) );
     127                        } // if
     128                } // for
     129        } // if
    121130        // branches.size() == 0 for switch (...) {}, i.e., no declaration or statements
    122131        return new SwitchStmt( maybeMoveBuild< Expression >(ctl), branches );
  • src/Parser/parser.yy

    re2c70ab r6a276a0  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Feb 22 17:48:54 2018
    13 // Update Count     : 3028
     12// Last Modified On : Fri Mar  9 11:37:35 2018
     13// Update Count     : 3075
    1414//
    1515
     
    254254%type<sn> statement_decl                                statement_decl_list                     statement_list_nodecl
    255255%type<sn> selection_statement
    256 %type<sn> switch_clause_list_opt                switch_clause_list                      choose_clause_list_opt          choose_clause_list
     256%type<sn> switch_clause_list_opt                switch_clause_list
    257257%type<en> case_value
    258258%type<sn> case_clause                                   case_value_list                         case_label                                      case_label_list
    259 %type<sn> fall_through                                  fall_through_opt
    260259%type<sn> iteration_statement                   jump_statement
    261260%type<sn> expression_statement                  asm_statement
     
    917916                { $$ = new StatementNode( build_if( $4, $6, $8 ) ); }
    918917        | SWITCH '(' comma_expression ')' case_clause
    919                 { $$ = new StatementNode( build_switch( $3, $5 ) ); }
     918                { $$ = new StatementNode( build_switch( true, $3, $5 ) ); }
    920919        | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
    921920                {
    922                         StatementNode *sw = new StatementNode( build_switch( $3, $8 ) );
     921                        StatementNode *sw = new StatementNode( build_switch( true, $3, $8 ) );
    923922                        // The semantics of the declaration list is changed to include associated initialization, which is performed
    924923                        // *before* the transfer to the appropriate case clause by hoisting the declarations into a compound
     
    929928                }
    930929        | CHOOSE '(' comma_expression ')' case_clause           // CFA
    931                 { $$ = new StatementNode( build_switch( $3, $5 ) ); }
    932         | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt choose_clause_list_opt '}' // CFA
    933                 {
    934                         StatementNode *sw = new StatementNode( build_switch( $3, $8 ) );
     930                { $$ = new StatementNode( build_switch( false, $3, $5 ) ); }
     931        | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
     932                {
     933                        StatementNode *sw = new StatementNode( build_switch( false, $3, $8 ) );
    935934                        $$ = $7 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
    936935                }
     
    970969        ;
    971970
     971//label_list_opt:
     972//      // empty
     973//      | identifier_or_type_name ':'
     974//      | label_list_opt identifier_or_type_name ':'
     975//      ;
     976
    972977case_label_list:                                                                                // CFA
    973978        case_label
     
    990995        | switch_clause_list case_label_list statement_list_nodecl
    991996                { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( $3 ) ) ) ) ); }
    992         ;
    993 
    994 choose_clause_list_opt:                                                                 // CFA
    995         // empty
    996                 { $$ = nullptr; }
    997         | choose_clause_list
    998         ;
    999 
    1000 choose_clause_list:                                                                             // CFA
    1001         case_label_list fall_through
    1002                 { $$ = $1->append_last_case( $2 ); }
    1003         | case_label_list statement_list_nodecl fall_through_opt
    1004                 { $$ = $1->append_last_case( new StatementNode( build_compound( (StatementNode *)$2->set_last( $3 ) ) ) ); }
    1005         | choose_clause_list case_label_list fall_through
    1006                 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( $3 ))); }
    1007         | choose_clause_list case_label_list statement_list_nodecl fall_through_opt
    1008                 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( (StatementNode *)$3->set_last( $4 ) ) ) ) ) ); }
    1009         ;
    1010 
    1011 fall_through_opt:                                                                               // CFA
    1012         // empty
    1013                 { $$ = new StatementNode( build_branch( BranchStmt::Break ) ); } // insert implicit break
    1014         | fall_through
    1015         ;
    1016 
    1017 fall_through_name:                                                                              // CFA
    1018         FALLTHRU
    1019         | FALLTHROUGH
    1020         ;
    1021 
    1022 fall_through:                                                                                   // CFA
    1023         fall_through_name
    1024                 { $$ = nullptr; }
    1025         | fall_through_name ';'
    1026                 { $$ = nullptr; }
    1027997        ;
    1028998
     
    10501020                // whereas normal operator precedence yields goto (*i)+3;
    10511021                { $$ = new StatementNode( build_computedgoto( $3 ) ); }
     1022                // A semantic check is required to ensure fallthru appears only in the body of a choose statement.
     1023    | fall_through_name ';'                                                             // CFA
     1024                { $$ = new StatementNode( build_branch( BranchStmt::FallThrough ) ); }
     1025    | fall_through_name identifier_or_type_name ';'             // CFA
     1026                { $$ = new StatementNode( build_branch( $2, BranchStmt::FallThrough ) ); }
     1027        | fall_through_name DEFAULT ';'                                         // CFA
     1028                { $$ = new StatementNode( build_branch( BranchStmt::FallThroughDefault ) ); }
    10521029        | CONTINUE ';'
    10531030                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
     
    10761053        ;
    10771054
     1055fall_through_name:                                                                              // CFA
     1056        FALLTHRU
     1057        | FALLTHROUGH
     1058        ;
     1059
    10781060with_statement:
    10791061        WITH '(' tuple_expression_list ')' statement
     
    10901072
    10911073when_clause:
    1092         WHEN '(' comma_expression ')'
    1093                 { $$ = $3; }
     1074        WHEN '(' comma_expression ')'                           { $$ = $3; }
    10941075        ;
    10951076
     
    11151096
    11161097timeout:
    1117         TIMEOUT '(' comma_expression ')'
    1118                 { $$ = $3; }
     1098        TIMEOUT '(' comma_expression ')'                        { $$ = $3; }
    11191099        ;
    11201100
     
    11591139        //empty
    11601140                { $$ = nullptr; }
    1161         | ';' conditional_expression
    1162                 { $$ = $2; }
     1141        | ';' conditional_expression                            { $$ = $2; }
    11631142        ;
    11641143
    11651144handler_key:
    1166         CATCH
    1167                 { $$ = CatchStmt::Terminate; }
    1168         | CATCHRESUME
    1169                 { $$ = CatchStmt::Resume; }
     1145        CATCH                                                                           { $$ = CatchStmt::Terminate; }
     1146        | CATCHRESUME                                                           { $$ = CatchStmt::Resume; }
    11701147        ;
    11711148
    11721149finally_clause:
    1173         FINALLY compound_statement
    1174                 {
    1175                         $$ = new StatementNode( build_finally( $2 ) );
    1176                 }
     1150        FINALLY compound_statement                                      { $$ = new StatementNode( build_finally( $2 ) ); }
    11771151        ;
    11781152
     
    24132387                        $$ = $2;
    24142388                }
    2415         | forall '{' external_definition_list '}'                       // CFA, namespace
     2389        | type_qualifier_list '{' external_definition_list '}'                  // CFA, namespace
    24162390        ;
    24172391
  • src/SynTree/Statement.cc

    re2c70ab r6a276a0  
    3434Statement::Statement( const std::list<Label> & labels ) : labels( labels ) {}
    3535
    36 void Statement::print( std::ostream & os, Indenter ) const {
     36void Statement::print( std::ostream & os, Indenter indent ) const {
    3737        if ( ! labels.empty() ) {
    38                 os << "Labels: {";
     38                os << indent << "... Labels: {";
    3939                for ( const Label & l : labels ) {
    4040                        os << l << ",";
     
    223223
    224224void CaseStmt::print( std::ostream &os, Indenter indent ) const {
    225         if ( isDefault() ) os << "Default ";
     225        if ( isDefault() ) os << indent << "Default ";
    226226        else {
    227                 os << "Case ";
     227                os << indent << "Case ";
    228228                condition->print( os, indent );
    229229        } // if
     
    231231
    232232        for ( Statement * stmt : stmts ) {
     233                os << indent+1;
    233234                stmt->print( os, indent+1 );
    234235        }
     
    478479}
    479480
    480 void NullStmt::print( std::ostream &os, Indenter ) const {
     481void NullStmt::print( std::ostream &os, Indenter indent ) const {
    481482        os << "Null Statement" << endl;
     483        Statement::print( os, indent );
    482484}
    483485
  • src/SynTree/Statement.h

    re2c70ab r6a276a0  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Sep  3 20:46:46 2017
    13 // Update Count     : 77
     12// Last Modified On : Thu Mar  8 14:53:02 2018
     13// Update Count     : 78
    1414//
    1515
     
    255255class BranchStmt : public Statement {
    256256  public:
    257         enum Type { Goto = 0, Break, Continue };
     257        enum Type { Goto = 0, Break, Continue, FallThrough, FallThroughDefault };
    258258
    259259        // originalTarget kept for error messages.
Note: See TracChangeset for help on using the changeset viewer.