Changeset e82aa9df for src/Parser/parser.yy
- Timestamp:
- Aug 15, 2016, 4:13:38 PM (8 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
r797347f re82aa9df 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 14 11:03:22201613 // Update Count : 18 7912 // Last Modified On : Mon Aug 15 15:18:19 2016 13 // Update Count : 1891 14 14 // 15 15 … … 664 664 Token fn; 665 665 fn.str = new std::string( "^?{}" ); // location undefined 666 $$ = new StatementNode 2( 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 ) ) ) ) ); 667 667 } 668 668 ; … … 678 678 compound_statement: 679 679 '{' '}' 680 { $$ = new CompoundStmtNode( (StatementNode *)0); }680 { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); } 681 681 | '{' 682 682 // Two scopes are necessary because the block itself has a scope, but every declaration within the block also … … 685 685 local_label_declaration_opt // GCC, local labels 686 686 block_item_list pop '}' // C99, intermix declarations and statements 687 { $$ = new CompoundStmtNode( $5); }687 { $$ = new StatementNode( build_compound( $5 ) ); } 688 688 ; 689 689 … … 696 696 block_item: 697 697 declaration // CFA, new & old style declarations 698 { $$ = new StatementNode 2( $1 ); }698 { $$ = new StatementNode( $1 ); } 699 699 | EXTENSION declaration // GCC 700 700 { // mark all fields in list 701 701 for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_next() ) 702 702 iter->set_extension( true ); 703 $$ = new StatementNode 2( $2 );703 $$ = new StatementNode( $2 ); 704 704 } 705 705 | function_definition 706 { $$ = new StatementNode 2( $1 ); }706 { $$ = new StatementNode( $1 ); } 707 707 | statement pop 708 708 ; … … 716 716 expression_statement: 717 717 comma_expression_opt ';' 718 { $$ = new StatementNode 2( build_expr( $1 ) ); }718 { $$ = new StatementNode( build_expr( $1 ) ); } 719 719 ; 720 720 … … 722 722 IF '(' comma_expression ')' statement %prec THEN 723 723 // explicitly deal with the shift/reduce conflict on if/else 724 { $$ = new StatementNode 2( build_if( $3, $5, nullptr ) ); }724 { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); } 725 725 | IF '(' comma_expression ')' statement ELSE statement 726 { $$ = new StatementNode 2( build_if( $3, $5, $7 ) ); }726 { $$ = new StatementNode( build_if( $3, $5, $7 ) ); } 727 727 | SWITCH '(' comma_expression ')' case_clause // CFA 728 { $$ = new StatementNode 2( build_switch( $3, $5 ) ); }728 { $$ = new StatementNode( build_switch( $3, $5 ) ); } 729 729 | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA 730 730 { 731 StatementNode *sw = new StatementNode 2( build_switch( $3, $8 ) );731 StatementNode *sw = new StatementNode( build_switch( $3, $8 ) ); 732 732 // The semantics of the declaration list is changed to include associated initialization, which is performed 733 733 // *before* the transfer to the appropriate case clause by hoisting the declarations into a compound … … 735 735 // therefore, are removed from the grammar even though C allows it. The change also applies to choose 736 736 // 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; 738 738 } 739 739 | CHOOSE '(' comma_expression ')' case_clause // CFA 740 { $$ = new StatementNode 2( build_switch( $3, $5 ) ); }740 { $$ = new StatementNode( build_switch( $3, $5 ) ); } 741 741 | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt choose_clause_list_opt '}' // CFA 742 742 { 743 StatementNode *sw = new StatementNode 2( 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; 745 745 } 746 746 ; … … 757 757 758 758 case_value_list: // CFA 759 case_value { $$ = new StatementNode 2( build_case( $1 ) ); }759 case_value { $$ = new StatementNode( build_case( $1 ) ); } 760 760 // 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 StatementNode 2( build_case( $3 ) ) ) ); }761 | case_value_list ',' case_value { $$ = (StatementNode *)($1->set_last( new StatementNode( build_case( $3 ) ) ) ); } 762 762 ; 763 763 764 764 case_label: // CFA 765 765 CASE case_value_list ':' { $$ = $2; } 766 | DEFAULT ':' { $$ = new StatementNode 2( build_default() ); }766 | DEFAULT ':' { $$ = new StatementNode( build_default() ); } 767 767 // A semantic check is required to ensure only one default clause per switch/choose statement. 768 768 ; … … 774 774 775 775 case_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 ) ) ); } 777 777 ; 778 778 … … 785 785 switch_clause_list: // CFA 786 786 case_label_list statement_list 787 { $$ = $1->append_last_case( new CompoundStmtNode( $2) ); }787 { $$ = $1->append_last_case( new StatementNode( build_compound( $2 ) ) ); } 788 788 | 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 ) ) ) ) ); } 790 790 ; 791 791 … … 800 800 { $$ = $1->append_last_case( $2 ); } 801 801 | 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 ) ) ) ); } 803 803 | choose_clause_list case_label_list fall_through 804 804 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( $3 ))); } 805 805 | 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 ) ) ) ) ) ); } 807 807 ; 808 808 809 809 fall_through_opt: // CFA 810 810 // empty 811 { $$ = new StatementNode 2( build_branch( "", BranchStmt::Break ) ); } // insert implicit break811 { $$ = new StatementNode( build_branch( "", BranchStmt::Break ) ); } // insert implicit break 812 812 | fall_through 813 813 ; … … 822 822 iteration_statement: 823 823 WHILE '(' comma_expression ')' statement 824 { $$ = new StatementNode 2( build_while( $3, $5 ) ); }824 { $$ = new StatementNode( build_while( $3, $5 ) ); } 825 825 | DO statement WHILE '(' comma_expression ')' ';' 826 { $$ = new StatementNode 2( build_while( $5, $2 ) ); }826 { $$ = new StatementNode( build_while( $5, $2 ) ); } 827 827 | FOR '(' push for_control_expression ')' statement 828 { $$ = new StatementNode 2( build_for( $4, $6 ) ); }828 { $$ = new StatementNode( build_for( $4, $6 ) ); } 829 829 ; 830 830 … … 838 838 jump_statement: 839 839 GOTO IDENTIFIER ';' 840 { $$ = new StatementNode 2( build_branch( *$2, BranchStmt::Goto ) ); }840 { $$ = new StatementNode( build_branch( *$2, BranchStmt::Goto ) ); } 841 841 | GOTO '*' comma_expression ';' // GCC, computed goto 842 842 // The syntax for the GCC computed goto violates normal expression precedence, e.g., goto *i+3; => goto *(i+3); 843 843 // whereas normal operator precedence yields goto (*i)+3; 844 { $$ = new StatementNode 2( build_computedgoto( $3 ) ); }844 { $$ = new StatementNode( build_computedgoto( $3 ) ); } 845 845 | CONTINUE ';' 846 846 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. 847 { $$ = new StatementNode 2( build_branch( "", BranchStmt::Continue ) ); }847 { $$ = new StatementNode( build_branch( "", BranchStmt::Continue ) ); } 848 848 | CONTINUE IDENTIFIER ';' // CFA, multi-level continue 849 849 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and 850 850 // the target of the transfer appears only at the start of an iteration statement. 851 { $$ = new StatementNode 2( build_branch( *$2, BranchStmt::Continue ) ); delete $2; }851 { $$ = new StatementNode( build_branch( *$2, BranchStmt::Continue ) ); delete $2; } 852 852 | BREAK ';' 853 853 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. 854 { $$ = new StatementNode 2( build_branch( "", BranchStmt::Break ) ); }854 { $$ = new StatementNode( build_branch( "", BranchStmt::Break ) ); } 855 855 | BREAK IDENTIFIER ';' // CFA, multi-level exit 856 856 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and 857 857 // the target of the transfer appears only at the start of an iteration statement. 858 { $$ = new StatementNode 2( build_branch( *$2, BranchStmt::Break ) ); delete $2; }858 { $$ = new StatementNode( build_branch( *$2, BranchStmt::Break ) ); delete $2; } 859 859 | RETURN comma_expression_opt ';' 860 { $$ = new StatementNode 2( build_return( $2 ) ); }860 { $$ = new StatementNode( build_return( $2 ) ); } 861 861 | THROW assignment_expression_opt ';' // handles rethrow 862 { $$ = new StatementNode 2( build_throw( $2 ) ); }862 { $$ = new StatementNode( build_throw( $2 ) ); } 863 863 | THROWRESUME assignment_expression_opt ';' // handles reresume 864 { $$ = new StatementNode 2( build_throw( $2 ) ); }864 { $$ = new StatementNode( build_throw( $2 ) ); } 865 865 | THROWRESUME assignment_expression_opt AT assignment_expression ';' // handles reresume 866 { $$ = new StatementNode 2( build_throw( $2 ) ); }866 { $$ = new StatementNode( build_throw( $2 ) ); } 867 867 ; 868 868 869 869 exception_statement: 870 870 TRY compound_statement handler_list 871 { $$ = new StatementNode 2( build_try( $2, $3, 0 ) ); }871 { $$ = new StatementNode( build_try( $2, $3, 0 ) ); } 872 872 | TRY compound_statement finally_clause 873 { $$ = new StatementNode 2( build_try( $2, 0, $3 ) ); }873 { $$ = new StatementNode( build_try( $2, 0, $3 ) ); } 874 874 | TRY compound_statement handler_list finally_clause 875 { $$ = new StatementNode 2( build_try( $2, $3, $4 ) ); }875 { $$ = new StatementNode( build_try( $2, $3, $4 ) ); } 876 876 ; 877 877 … … 880 880 // ISO/IEC 9899:1999 Section 15.3(6 ) If present, a "..." handler shall be the last handler for its try block. 881 881 | CATCH '(' ELLIPSIS ')' compound_statement 882 { $$ = new StatementNode 2( build_catch( 0, $5, true ) ); }882 { $$ = new StatementNode( build_catch( 0, $5, true ) ); } 883 883 | handler_clause CATCH '(' ELLIPSIS ')' compound_statement 884 { $$ = (StatementNode *)$1->set_last( new StatementNode 2( build_catch( 0, $6, true ) ) ); }884 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true ) ) ); } 885 885 | CATCHRESUME '(' ELLIPSIS ')' compound_statement 886 { $$ = new StatementNode 2( build_catch( 0, $5, true ) ); }886 { $$ = new StatementNode( build_catch( 0, $5, true ) ); } 887 887 | handler_clause CATCHRESUME '(' ELLIPSIS ')' compound_statement 888 { $$ = (StatementNode *)$1->set_last( new StatementNode 2( build_catch( 0, $6, true ) ) ); }888 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true ) ) ); } 889 889 ; 890 890 891 891 handler_clause: 892 892 CATCH '(' push push exception_declaration pop ')' compound_statement pop 893 { $$ = new StatementNode 2( build_catch( $5, $8 ) ); }893 { $$ = new StatementNode( build_catch( $5, $8 ) ); } 894 894 | handler_clause CATCH '(' push push exception_declaration pop ')' compound_statement pop 895 { $$ = (StatementNode *)$1->set_last( new StatementNode 2( build_catch( $6, $9 ) ) ); }895 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 ) ) ); } 896 896 | CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop 897 { $$ = new StatementNode 2( build_catch( $5, $8 ) ); }897 { $$ = new StatementNode( build_catch( $5, $8 ) ); } 898 898 | handler_clause CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop 899 { $$ = (StatementNode *)$1->set_last( new StatementNode 2( build_catch( $6, $9 ) ) ); }899 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 ) ) ); } 900 900 ; 901 901 … … 903 903 FINALLY compound_statement 904 904 { 905 $$ = new StatementNode 2( build_finally( $2 ) );905 $$ = new StatementNode( build_finally( $2 ) ); 906 906 } 907 907 ; … … 931 931 asm_statement: 932 932 ASM asm_volatile_opt '(' string_literal_list ')' ';' 933 { $$ = new AsmStmtNode( $2, $4, 0); }933 { $$ = new StatementNode( build_asmstmt( $2, $4, 0 ) ); } 934 934 | 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 ) ); } 936 936 | 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 ) ); } 938 938 | 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 ) ); } 940 940 | 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 ) ); } 942 942 ; 943 943 … … 963 963 asm_operand: // GCC 964 964 string_literal_list '(' constant_expression ')' 965 { $$ = new ExpressionNode( build_asm ( 0, $1, $3 ) ); }965 { $$ = new ExpressionNode( build_asmexpr( 0, $1, $3 ) ); } 966 966 | '[' constant_expression ']' string_literal_list '(' constant_expression ')' 967 { $$ = new ExpressionNode( build_asm ( $2, $4, $6 ) ); }967 { $$ = new ExpressionNode( build_asmexpr( $2, $4, $6 ) ); } 968 968 ; 969 969 … … 974 974 { $$ = new ExpressionNode( $1 ); } 975 975 | asm_clobbers_list_opt ',' string_literal_list 976 { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); }976 { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); } 977 977 ; 978 978 979 979 label_list: 980 980 no_attr_identifier 981 { $$ = new LabelNode(); $$-> append_label($1 ); }981 { $$ = new LabelNode(); $$->labels.push_back( *$1 ); } 982 982 | label_list ',' no_attr_identifier 983 { $$ = $1; $1-> append_label($3 ); }983 { $$ = $1; $1->labels.push_back( *$3 ); } 984 984 ; 985 985
Note: See TracChangeset
for help on using the changeset viewer.