Ignore:
Timestamp:
Aug 15, 2016, 4:13:38 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:
b1848a0
Parents:
797347f
Message:

more refactoring of parser code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r797347f re82aa9df  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug 14 11:03:22 2016
    13 // Update Count     : 1879
     12// Last Modified On : Mon Aug 15 15:18:19 2016
     13// Update Count     : 1891
    1414//
    1515
     
    664664                        Token fn;
    665665                        fn.str = new std::string( "^?{}" ); // location undefined
    666                         $$ = new StatementNode2( build_expr( new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) ) ) );
     666                        $$ = new StatementNode( build_expr( new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) ) ) );
    667667                }
    668668        ;
     
    678678compound_statement:
    679679        '{' '}'
    680                 { $$ = new CompoundStmtNode( (StatementNode *)0 ); }
     680                { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); }
    681681        | '{'
    682682                // Two scopes are necessary because the block itself has a scope, but every declaration within the block also
     
    685685          local_label_declaration_opt                                           // GCC, local labels
    686686          block_item_list pop '}'                                                       // C99, intermix declarations and statements
    687                 { $$ = new CompoundStmtNode( $5 ); }
     687                { $$ = new StatementNode( build_compound( $5 ) ); }
    688688        ;
    689689
     
    696696block_item:
    697697        declaration                                                                                     // CFA, new & old style declarations
    698                 { $$ = new StatementNode2( $1 ); }
     698                { $$ = new StatementNode( $1 ); }
    699699        | EXTENSION declaration                                                         // GCC
    700700                {       // mark all fields in list
    701701                        for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_next() )
    702702                                iter->set_extension( true );
    703                         $$ = new StatementNode2( $2 );
     703                        $$ = new StatementNode( $2 );
    704704                }
    705705        | function_definition
    706                 { $$ = new StatementNode2( $1 ); }
     706                { $$ = new StatementNode( $1 ); }
    707707        | statement pop
    708708        ;
     
    716716expression_statement:
    717717        comma_expression_opt ';'
    718                 { $$ = new StatementNode2( build_expr( $1 ) ); }
     718                { $$ = new StatementNode( build_expr( $1 ) ); }
    719719        ;
    720720
     
    722722        IF '(' comma_expression ')' statement                           %prec THEN
    723723                // explicitly deal with the shift/reduce conflict on if/else
    724                 { $$ = new StatementNode2( build_if( $3, $5, nullptr ) ); }
     724                { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); }
    725725        | IF '(' comma_expression ')' statement ELSE statement
    726                 { $$ = new StatementNode2( build_if( $3, $5, $7 ) ); }
     726                { $$ = new StatementNode( build_if( $3, $5, $7 ) ); }
    727727        | SWITCH '(' comma_expression ')' case_clause           // CFA
    728                 { $$ = new StatementNode2( build_switch( $3, $5 ) ); }
     728                { $$ = new StatementNode( build_switch( $3, $5 ) ); }
    729729        | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
    730730                {
    731                         StatementNode *sw = new StatementNode2( build_switch( $3, $8 ) );
     731                        StatementNode *sw = new StatementNode( build_switch( $3, $8 ) );
    732732                        // The semantics of the declaration list is changed to include associated initialization, which is performed
    733733                        // *before* the transfer to the appropriate case clause by hoisting the declarations into a compound
     
    735735                        // therefore, are removed from the grammar even though C allows it. The change also applies to choose
    736736                        // statement.
    737                         $$ = $7 != 0 ? new CompoundStmtNode( (StatementNode *)((new StatementNode2( $7 ))->set_last( sw )) ) : sw;
     737                        $$ = $7 != 0 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
    738738                }
    739739        | CHOOSE '(' comma_expression ')' case_clause           // CFA
    740                 { $$ = new StatementNode2( build_switch( $3, $5 ) ); }
     740                { $$ = new StatementNode( build_switch( $3, $5 ) ); }
    741741        | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt choose_clause_list_opt '}' // CFA
    742742                {
    743                         StatementNode *sw = new StatementNode2( build_switch( $3, $8 ) );
    744                         $$ = $7 != 0 ? new CompoundStmtNode( (StatementNode *)((new StatementNode2( $7 ))->set_last( sw )) ) : sw;
     743                        StatementNode *sw = new StatementNode( build_switch( $3, $8 ) );
     744                        $$ = $7 != 0 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
    745745                }
    746746        ;
     
    757757
    758758case_value_list:                                                                                // CFA
    759         case_value                                                                      { $$ = new StatementNode2( build_case( $1 ) ); }
     759        case_value                                                                      { $$ = new StatementNode( build_case( $1 ) ); }
    760760                // convert case list, e.g., "case 1, 3, 5:" into "case 1: case 3: case 5"
    761         | case_value_list ',' case_value                        { $$ = (StatementNode *)($1->set_last( new StatementNode2( build_case( $3 ) ) ) ); }
     761        | case_value_list ',' case_value                        { $$ = (StatementNode *)($1->set_last( new StatementNode( build_case( $3 ) ) ) ); }
    762762        ;
    763763
    764764case_label:                                                                                             // CFA
    765765        CASE case_value_list ':'                                        { $$ = $2; }
    766         | DEFAULT ':'                                                           { $$ = new StatementNode2( build_default() ); }
     766        | DEFAULT ':'                                                           { $$ = new StatementNode( build_default() ); }
    767767                // A semantic check is required to ensure only one default clause per switch/choose statement.
    768768        ;
     
    774774
    775775case_clause:                                                                                    // CFA
    776         case_label_list statement                                       { $$ = $1->append_last_case( new CompoundStmtNode( $2 ) ); }
     776        case_label_list statement                                       { $$ = $1->append_last_case( new StatementNode( build_compound( $2 ) ) ); }
    777777        ;
    778778
     
    785785switch_clause_list:                                                                             // CFA
    786786        case_label_list statement_list
    787                 { $$ = $1->append_last_case( new CompoundStmtNode( $2 ) ); }
     787                { $$ = $1->append_last_case( new StatementNode( build_compound( $2 ) ) ); }
    788788        | switch_clause_list case_label_list statement_list
    789                 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new CompoundStmtNode( $3 ) ) ) ); }
     789                { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( $3 ) ) ) ) ); }
    790790        ;
    791791
     
    800800                { $$ = $1->append_last_case( $2 ); }
    801801        | case_label_list statement_list fall_through_opt
    802                 { $$ = $1->append_last_case( new CompoundStmtNode( (StatementNode *)mkList( (*$2, *$3 ) ) ) ); }
     802                { $$ = $1->append_last_case( new StatementNode( build_compound( (StatementNode *)$2->set_last( $3 ) ) ) ); }
    803803        | choose_clause_list case_label_list fall_through
    804804                { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( $3 ))); }
    805805        | choose_clause_list case_label_list statement_list fall_through_opt
    806                 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new CompoundStmtNode( (StatementNode *)mkList( (*$3, *$4 ) ) ) ) ) ); }
     806                { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( (StatementNode *)$3->set_last( $4 ) ) ) ) ) ); }
    807807        ;
    808808
    809809fall_through_opt:                                                                               // CFA
    810810        // empty
    811                 { $$ = new StatementNode2( build_branch( "", BranchStmt::Break ) ); } // insert implicit break
     811                { $$ = new StatementNode( build_branch( "", BranchStmt::Break ) ); } // insert implicit break
    812812        | fall_through
    813813        ;
     
    822822iteration_statement:
    823823        WHILE '(' comma_expression ')' statement
    824                 { $$ = new StatementNode2( build_while( $3, $5 ) ); }
     824                { $$ = new StatementNode( build_while( $3, $5 ) ); }
    825825        | DO statement WHILE '(' comma_expression ')' ';'
    826                 { $$ = new StatementNode2( build_while( $5, $2 ) ); }
     826                { $$ = new StatementNode( build_while( $5, $2 ) ); }
    827827        | FOR '(' push for_control_expression ')' statement
    828                 { $$ = new StatementNode2( build_for( $4, $6 ) ); }
     828                { $$ = new StatementNode( build_for( $4, $6 ) ); }
    829829        ;
    830830
     
    838838jump_statement:
    839839        GOTO IDENTIFIER ';'
    840                 { $$ = new StatementNode2( build_branch( *$2, BranchStmt::Goto ) ); }
     840                { $$ = new StatementNode( build_branch( *$2, BranchStmt::Goto ) ); }
    841841        | GOTO '*' comma_expression ';'                                         // GCC, computed goto
    842842                // The syntax for the GCC computed goto violates normal expression precedence, e.g., goto *i+3; => goto *(i+3);
    843843                // whereas normal operator precedence yields goto (*i)+3;
    844                 { $$ = new StatementNode2( build_computedgoto( $3 ) ); }
     844                { $$ = new StatementNode( build_computedgoto( $3 ) ); }
    845845        | CONTINUE ';'
    846846                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
    847                 { $$ = new StatementNode2( build_branch( "", BranchStmt::Continue ) ); }
     847                { $$ = new StatementNode( build_branch( "", BranchStmt::Continue ) ); }
    848848        | CONTINUE IDENTIFIER ';'                                                       // CFA, multi-level continue
    849849                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
    850850                // the target of the transfer appears only at the start of an iteration statement.
    851                 { $$ = new StatementNode2( build_branch( *$2, BranchStmt::Continue ) ); delete $2; }
     851                { $$ = new StatementNode( build_branch( *$2, BranchStmt::Continue ) ); delete $2; }
    852852        | BREAK ';'
    853853                // A semantic check is required to ensure this statement appears only in the body of an iteration statement.
    854                 { $$ = new StatementNode2( build_branch( "", BranchStmt::Break ) ); }
     854                { $$ = new StatementNode( build_branch( "", BranchStmt::Break ) ); }
    855855        | BREAK IDENTIFIER ';'                                                          // CFA, multi-level exit
    856856                // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and
    857857                // the target of the transfer appears only at the start of an iteration statement.
    858                 { $$ = new StatementNode2( build_branch( *$2, BranchStmt::Break ) ); delete $2; }
     858                { $$ = new StatementNode( build_branch( *$2, BranchStmt::Break ) ); delete $2; }
    859859        | RETURN comma_expression_opt ';'
    860                 { $$ = new StatementNode2( build_return( $2 ) ); }
     860                { $$ = new StatementNode( build_return( $2 ) ); }
    861861        | THROW assignment_expression_opt ';'                           // handles rethrow
    862                 { $$ = new StatementNode2( build_throw( $2 ) ); }
     862                { $$ = new StatementNode( build_throw( $2 ) ); }
    863863        | THROWRESUME assignment_expression_opt ';'                     // handles reresume
    864                 { $$ = new StatementNode2( build_throw( $2 ) ); }
     864                { $$ = new StatementNode( build_throw( $2 ) ); }
    865865        | THROWRESUME assignment_expression_opt AT assignment_expression ';' // handles reresume
    866                 { $$ = new StatementNode2( build_throw( $2 ) ); }
     866                { $$ = new StatementNode( build_throw( $2 ) ); }
    867867        ;
    868868
    869869exception_statement:
    870870        TRY compound_statement handler_list
    871                 { $$ = new StatementNode2( build_try( $2, $3, 0 ) ); }
     871                { $$ = new StatementNode( build_try( $2, $3, 0 ) ); }
    872872        | TRY compound_statement finally_clause
    873                 { $$ = new StatementNode2( build_try( $2, 0, $3 ) ); }
     873                { $$ = new StatementNode( build_try( $2, 0, $3 ) ); }
    874874        | TRY compound_statement handler_list finally_clause
    875                 { $$ = new StatementNode2( build_try( $2, $3, $4 ) ); }
     875                { $$ = new StatementNode( build_try( $2, $3, $4 ) ); }
    876876        ;
    877877
     
    880880                // ISO/IEC 9899:1999 Section 15.3(6 ) If present, a "..." handler shall be the last handler for its try block.
    881881        | CATCH '(' ELLIPSIS ')' compound_statement
    882                 { $$ = new StatementNode2( build_catch( 0, $5, true ) ); }
     882                { $$ = new StatementNode( build_catch( 0, $5, true ) ); }
    883883        | handler_clause CATCH '(' ELLIPSIS ')' compound_statement
    884                 { $$ = (StatementNode *)$1->set_last( new StatementNode2( build_catch( 0, $6, true ) ) ); }
     884                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true ) ) ); }
    885885        | CATCHRESUME '(' ELLIPSIS ')' compound_statement
    886                 { $$ = new StatementNode2( build_catch( 0, $5, true ) ); }
     886                { $$ = new StatementNode( build_catch( 0, $5, true ) ); }
    887887        | handler_clause CATCHRESUME '(' ELLIPSIS ')' compound_statement
    888                 { $$ = (StatementNode *)$1->set_last( new StatementNode2( build_catch( 0, $6, true ) ) ); }
     888                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true ) ) ); }
    889889        ;
    890890
    891891handler_clause:
    892892        CATCH '(' push push exception_declaration pop ')' compound_statement pop
    893                 { $$ = new StatementNode2( build_catch( $5, $8 ) ); }
     893                { $$ = new StatementNode( build_catch( $5, $8 ) ); }
    894894        | handler_clause CATCH '(' push push exception_declaration pop ')' compound_statement pop
    895         { $$ = (StatementNode *)$1->set_last( new StatementNode2( build_catch( $6, $9 ) ) ); }
     895        { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 ) ) ); }
    896896        | CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop
    897                 { $$ = new StatementNode2( build_catch( $5, $8 ) ); }
     897                { $$ = new StatementNode( build_catch( $5, $8 ) ); }
    898898        | handler_clause CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop
    899                 { $$ = (StatementNode *)$1->set_last( new StatementNode2( build_catch( $6, $9 ) ) ); }
     899                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 ) ) ); }
    900900        ;
    901901
     
    903903        FINALLY compound_statement
    904904                {
    905                         $$ = new StatementNode2( build_finally( $2 ) );
     905                        $$ = new StatementNode( build_finally( $2 ) );
    906906                }
    907907        ;
     
    931931asm_statement:
    932932        ASM asm_volatile_opt '(' string_literal_list ')' ';'
    933                 { $$ = new AsmStmtNode( $2, $4, 0 ); }
     933                { $$ = new StatementNode( build_asmstmt( $2, $4, 0 ) ); }
    934934        | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ')' ';' // remaining GCC
    935                 { $$ = new AsmStmtNode( $2, $4, $6 ); }
     935                { $$ = new StatementNode( build_asmstmt( $2, $4, $6 ) ); }
    936936        | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ')' ';'
    937                 { $$ = new AsmStmtNode( $2, $4, $6, $8 ); }
     937                { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8 ) ); }
    938938        | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';'
    939                 { $$ = new AsmStmtNode( $2, $4, $6, $8, $10 ); }
     939                { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8, $10 ) ); }
    940940        | ASM asm_volatile_opt GOTO '(' string_literal_list ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';'
    941                 { $$ = new AsmStmtNode( $2, $5, 0, $8, $10, $12 ); }
     941                { $$ = new StatementNode( build_asmstmt( $2, $5, 0, $8, $10, $12 ) ); }
    942942        ;
    943943
     
    963963asm_operand:                                                                                    // GCC
    964964        string_literal_list '(' constant_expression ')'
    965                 { $$ = new ExpressionNode( build_asm( 0, $1, $3 ) ); }
     965                { $$ = new ExpressionNode( build_asmexpr( 0, $1, $3 ) ); }
    966966        | '[' constant_expression ']' string_literal_list '(' constant_expression ')'
    967         { $$ = new ExpressionNode( build_asm( $2, $4, $6 ) ); }
     967        { $$ = new ExpressionNode( build_asmexpr( $2, $4, $6 ) ); }
    968968        ;
    969969
     
    974974                { $$ = new ExpressionNode( $1 ); }
    975975        | asm_clobbers_list_opt ',' string_literal_list
    976         { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); }
     976                { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); }
    977977        ;
    978978
    979979label_list:
    980980        no_attr_identifier
    981                 { $$ = new LabelNode(); $$->append_label( $1 ); }
     981                { $$ = new LabelNode(); $$->labels.push_back( *$1 ); }
    982982        | label_list ',' no_attr_identifier
    983                 { $$ = $1; $1->append_label( $3 ); }
     983                { $$ = $1; $1->labels.push_back( *$3 ); }
    984984        ;
    985985
Note: See TracChangeset for help on using the changeset viewer.