Changes in src/Parser/parser.yy [413ad05:8cc5cb0]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (52 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
r413ad05 r8cc5cb0 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Aug 26 16:45:44201613 // Update Count : 1 96412 // Last Modified On : Thu Aug 11 18:02:57 2016 13 // Update Count : 1861 14 14 // 15 15 … … 43 43 #define YYDEBUG_LEXER_TEXT (yylval) // lexer loads this up each time 44 44 #define YYDEBUG 1 // get the pretty debugging code to compile 45 extern char *yytext; 45 46 46 47 #undef __GNUC_MINOR__ … … 55 56 #include "LinkageSpec.h" 56 57 57 extern DeclarationNode * parseTree; 58 extern LinkageSpec::Spec linkage; 59 extern TypedefTable typedefTable; 60 61 std::stack< LinkageSpec::Spec > linkageStack; 62 63 void appendStr( std::string *to, std::string *from ) { 58 DeclarationNode *theTree = 0; // the resulting parse tree 59 LinkageSpec::Type linkage = LinkageSpec::Cforall; 60 std::stack< LinkageSpec::Type > linkageStack; 61 TypedefTable typedefTable; 62 63 void appendStr( std::string &to, std::string *from ) { 64 64 // "abc" "def" "ghi" => "abcdefghi", remove new text from quotes and insert before last quote in old string. 65 to ->insert( to->length() - 1, from->substr( 1, from->length() - 2 ) );65 to.insert( to.length() - 1, from->substr( 1, from->length() - 2 ) ); 66 66 } // appendStr 67 67 %} … … 126 126 InitializerNode *in; 127 127 OperKinds op; 128 std::string *str;129 128 bool flag; 130 129 } … … 132 131 %type<tok> identifier no_01_identifier no_attr_identifier zero_one 133 132 %type<tok> identifier_or_type_name no_attr_identifier_or_type_name no_01_identifier_or_type_name 134 %type<constant> string_literal 135 %type<str> string_literal_list 133 %type<constant> string_literal_list 136 134 137 135 // expressions … … 145 143 %type<en> constant_expression assignment_expression assignment_expression_opt 146 144 %type<en> comma_expression comma_expression_opt 145 //%type<en> argument_expression_list argument_expression for_control_expression assignment_opt 147 146 %type<en> argument_expression_list argument_expression assignment_opt 148 147 %type<fctl> for_control_expression … … 163 162 %type<sn> case_value_list case_label case_label_list 164 163 %type<sn> switch_clause_list_opt switch_clause_list choose_clause_list_opt choose_clause_list 165 %type< sn> handler_list handler_clause finally_clause164 %type<pn> handler_list handler_clause finally_clause 166 165 167 166 // declarations … … 225 224 %type<decl> paren_identifier paren_type 226 225 227 %type<decl> storage_class storage_class_ list226 %type<decl> storage_class storage_class_name storage_class_list 228 227 229 228 %type<decl> sue_declaration_specifier sue_type_specifier … … 298 297 299 298 push: 300 { typedefTable.enterScope(); } 299 { 300 typedefTable.enterScope(); 301 } 301 302 ; 302 303 303 304 pop: 304 { typedefTable.leaveScope(); } 305 { 306 typedefTable.leaveScope(); 307 } 305 308 ; 306 309 … … 309 312 constant: 310 313 // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant". 311 INTEGERconstant{ $$ = new ExpressionNode( build_constantInteger( *$1 ) ); }314 INTEGERconstant { $$ = new ExpressionNode( build_constantInteger( *$1 ) ); } 312 315 | FLOATINGconstant { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); } 313 316 | CHARACTERconstant { $$ = new ExpressionNode( build_constantChar( *$1 ) ); } … … 335 338 ; 336 339 337 string_literal:338 string_literal_list { $$ = build_constantStr( *$1 ); }339 ;340 341 340 string_literal_list: // juxtaposed strings are concatenated 342 STRINGliteral { $$ = $1; } // conversion from tok to str341 STRINGliteral { $$ = build_constantStr( *$1 ); } 343 342 | string_literal_list STRINGliteral 344 343 { 345 appendStr( $1 , $2 ); // append 2nd juxtaposed string to 1st344 appendStr( $1->get_constant()->get_value(), $2 ); 346 345 delete $2; // allocated by lexer 347 $$ = $1; // conversion from tok to str346 $$ = $1; 348 347 } 349 348 ; … … 372 371 | postfix_expression '(' argument_expression_list ')' 373 372 { $$ = new ExpressionNode( build_func( $1, $3 ) ); } 374 // ambiguity with .0 so space required after field-selection, e.g.373 // ambiguity with .0 so space required after field-selection, e.g. 375 374 // struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1; 376 375 | postfix_expression '.' no_attr_identifier … … 390 389 Token fn; 391 390 fn.str = new std::string( "?{}" ); // location undefined 392 $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_l ast( $3 ) ) );391 $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_link( $3 ) ) ); 393 392 } 394 393 ; … … 397 396 argument_expression 398 397 | argument_expression_list ',' argument_expression 399 { $$ = (ExpressionNode *)( $1->set_l ast( $3 )); }398 { $$ = (ExpressionNode *)( $1->set_link( $3 )); } 400 399 ; 401 400 … … 408 407 field_list: // CFA, tuple field selector 409 408 field 410 | field_list ',' field { $$ = (ExpressionNode *)$1->set_l ast( $3 ); }409 | field_list ',' field { $$ = (ExpressionNode *)$1->set_link( $3 ); } 411 410 ; 412 411 … … 414 413 no_attr_identifier 415 414 { $$ = new ExpressionNode( build_varref( $1 ) ); } 416 // ambiguity with .0 so space required after field-selection, e.g.415 // ambiguity with .0 so space required after field-selection, e.g. 417 416 // struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1; 418 417 | no_attr_identifier '.' field … … 432 431 | constant 433 432 { $$ = $1; } 434 | string_literal 433 | string_literal_list 435 434 { $$ = new ExpressionNode( $1 ); } 436 435 | EXTENSION cast_expression // GCC … … 608 607 assignment_operator: 609 608 '=' { $$ = OperKinds::Assign; } 610 | ATassign { $$ = OperKinds::AtAssn; }611 609 | MULTassign { $$ = OperKinds::MulAssn; } 612 610 | DIVassign { $$ = OperKinds::DivAssn; } … … 629 627 { $$ = new ExpressionNode( build_tuple( $3 ) ); } 630 628 | '[' push ',' tuple_expression_list pop ']' 631 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_l ast( $4 ) ) ); }629 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_link( $4 ) ) ); } 632 630 | '[' push assignment_expression ',' tuple_expression_list pop ']' 633 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_l ast( $5 ) ) ); }631 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_link( $5 ) ) ); } 634 632 ; 635 633 … … 637 635 assignment_expression_opt 638 636 | tuple_expression_list ',' assignment_expression_opt 639 { $$ = (ExpressionNode *)$1->set_l ast( $3 ); }637 { $$ = (ExpressionNode *)$1->set_link( $3 ); } 640 638 ; 641 639 … … 667 665 Token fn; 668 666 fn.str = new std::string( "^?{}" ); // location undefined 669 $$ = new StatementNode ( build_expr( new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) ) ) );667 $$ = new StatementNode2( build_expr( new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_link( $4 ) ) ) ) ); 670 668 } 671 669 ; … … 681 679 compound_statement: 682 680 '{' '}' 683 { $$ = new StatementNode( build_compound( (StatementNode *)0 )); }681 { $$ = new CompoundStmtNode( (StatementNode *)0 ); } 684 682 | '{' 685 683 // Two scopes are necessary because the block itself has a scope, but every declaration within the block also … … 688 686 local_label_declaration_opt // GCC, local labels 689 687 block_item_list pop '}' // C99, intermix declarations and statements 690 { $$ = new StatementNode( build_compound( $5 )); }688 { $$ = new CompoundStmtNode( $5 ); } 691 689 ; 692 690 … … 694 692 block_item 695 693 | block_item_list push block_item 696 { if ( $1 != 0 ) { $1->set_l ast( $3 ); $$ = $1; } }694 { if ( $1 != 0 ) { $1->set_link( $3 ); $$ = $1; } } 697 695 ; 698 696 … … 702 700 | EXTENSION declaration // GCC 703 701 { // mark all fields in list 704 for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() )702 for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_link() ) 705 703 iter->set_extension( true ); 706 704 $$ = new StatementNode( $2 ); … … 714 712 statement 715 713 | statement_list statement 716 { if ( $1 != 0 ) { $1->set_l ast( $2 ); $$ = $1; } }714 { if ( $1 != 0 ) { $1->set_link( $2 ); $$ = $1; } } 717 715 ; 718 716 719 717 expression_statement: 720 718 comma_expression_opt ';' 721 { $$ = new StatementNode ( build_expr( $1 ) ); }719 { $$ = new StatementNode2( build_expr( $1 ) ); } 722 720 ; 723 721 … … 725 723 IF '(' comma_expression ')' statement %prec THEN 726 724 // explicitly deal with the shift/reduce conflict on if/else 727 { $$ = new StatementNode ( build_if( $3, $5, nullptr ) ); }725 { $$ = new StatementNode2( build_if( $3, $5, nullptr ) ); } 728 726 | IF '(' comma_expression ')' statement ELSE statement 729 { $$ = new StatementNode ( build_if( $3, $5, $7 ) ); }727 { $$ = new StatementNode2( build_if( $3, $5, $7 ) ); } 730 728 | SWITCH '(' comma_expression ')' case_clause // CFA 731 { $$ = new StatementNode ( build_switch( $3, $5 ) ); }729 { $$ = new StatementNode2( build_switch( $3, $5 ) ); } 732 730 | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA 733 731 { 734 StatementNode *sw = new StatementNode ( build_switch( $3, $8 ) );732 StatementNode *sw = new StatementNode2( build_switch( $3, $8 ) ); 735 733 // The semantics of the declaration list is changed to include associated initialization, which is performed 736 734 // *before* the transfer to the appropriate case clause by hoisting the declarations into a compound … … 738 736 // therefore, are removed from the grammar even though C allows it. The change also applies to choose 739 737 // statement. 740 $$ = $7 != 0 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw ))) ) : sw;738 $$ = $7 != 0 ? new CompoundStmtNode( (StatementNode *)((new StatementNode( $7 ))->set_link( sw )) ) : sw; 741 739 } 742 740 | CHOOSE '(' comma_expression ')' case_clause // CFA 743 { $$ = new StatementNode ( build_switch( $3, $5 ) ); }741 { $$ = new StatementNode2( build_switch( $3, $5 ) ); } 744 742 | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt choose_clause_list_opt '}' // CFA 745 743 { 746 StatementNode *sw = new StatementNode ( build_switch( $3, $8 ) );747 $$ = $7 != 0 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw ))) ) : sw;744 StatementNode *sw = new StatementNode2( build_switch( $3, $8 ) ); 745 $$ = $7 != 0 ? new CompoundStmtNode( (StatementNode *)((new StatementNode( $7 ))->set_link( sw )) ) : sw; 748 746 } 749 747 ; … … 760 758 761 759 case_value_list: // CFA 762 case_value { $$ = new StatementNode( build_case( $1 ) ); } 760 //case_value { $$ = new StatementNode( StatementNode::Case, $1, 0 ); } 761 case_value { $$ = new StatementNode2( build_case( $1 ) ); } 763 762 // convert case list, e.g., "case 1, 3, 5:" into "case 1: case 3: case 5" 764 | case_value_list ',' case_value { $$ = (StatementNode *)($1->set_l ast( new StatementNode( build_case( $3 ) ) ) ); }763 | case_value_list ',' case_value { $$ = (StatementNode *)($1->set_link( new StatementNode2( build_case( $3 ) ) ) ); } 765 764 ; 766 765 767 766 case_label: // CFA 768 767 CASE case_value_list ':' { $$ = $2; } 769 | DEFAULT ':' { $$ = new StatementNode ( build_default() ); }768 | DEFAULT ':' { $$ = new StatementNode2( build_default() ); } 770 769 // A semantic check is required to ensure only one default clause per switch/choose statement. 771 770 ; … … 773 772 case_label_list: // CFA 774 773 case_label 775 | case_label_list case_label { $$ = (StatementNode *)( $1->set_l ast( $2 )); }774 | case_label_list case_label { $$ = (StatementNode *)( $1->set_link( $2 )); } 776 775 ; 777 776 778 777 case_clause: // CFA 779 case_label_list statement { $$ = $1->append_last_case( new StatementNode( build_compound( $2 )) ); }778 case_label_list statement { $$ = $1->append_last_case( new CompoundStmtNode( $2 ) ); } 780 779 ; 781 780 … … 788 787 switch_clause_list: // CFA 789 788 case_label_list statement_list 790 { $$ = $1->append_last_case( new StatementNode( build_compound( $2 )) ); }789 { $$ = $1->append_last_case( new CompoundStmtNode( $2 ) ); } 791 790 | switch_clause_list case_label_list statement_list 792 { $$ = (StatementNode *)( $1->set_l ast( $2->append_last_case( new StatementNode( build_compound( $3 )) ) ) ); }791 { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( new CompoundStmtNode( $3 ) ) ) ); } 793 792 ; 794 793 … … 803 802 { $$ = $1->append_last_case( $2 ); } 804 803 | case_label_list statement_list fall_through_opt 805 { $$ = $1->append_last_case( new StatementNode( build_compound( (StatementNode *)$2->set_last($3 ) ) ) ); }804 { $$ = $1->append_last_case( new CompoundStmtNode( (StatementNode *)mkList( (*$2, *$3 ) ) ) ); } 806 805 | choose_clause_list case_label_list fall_through 807 { $$ = (StatementNode *)( $1->set_l ast( $2->append_last_case( $3 ))); }806 { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( $3 ))); } 808 807 | choose_clause_list case_label_list statement_list fall_through_opt 809 { $$ = (StatementNode *)( $1->set_l ast( $2->append_last_case( new StatementNode( build_compound( (StatementNode *)$3->set_last($4 ) ) ) ) ) ); }808 { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( new CompoundStmtNode( (StatementNode *)mkList( (*$3, *$4 ) ) ) ) ) ); } 810 809 ; 811 810 812 811 fall_through_opt: // CFA 813 812 // empty 814 { $$ = new StatementNode ( build_branch(BranchStmt::Break ) ); } // insert implicit break813 { $$ = new StatementNode2( build_branch( "", BranchStmt::Break ) ); } // insert implicit break 815 814 | fall_through 816 815 ; … … 825 824 iteration_statement: 826 825 WHILE '(' comma_expression ')' statement 827 { $$ = new StatementNode ( build_while( $3, $5 ) ); }826 { $$ = new StatementNode2( build_while( $3, $5 ) ); } 828 827 | DO statement WHILE '(' comma_expression ')' ';' 829 { $$ = new StatementNode ( build_while( $5, $2 ) ); }828 { $$ = new StatementNode2( build_while( $5, $2 ) ); } 830 829 | FOR '(' push for_control_expression ')' statement 831 { $$ = new StatementNode ( build_for( $4, $6 ) ); }830 { $$ = new StatementNode2( build_for( $4, $6 ) ); } 832 831 ; 833 832 … … 841 840 jump_statement: 842 841 GOTO IDENTIFIER ';' 843 { $$ = new StatementNode ( build_branch($2, BranchStmt::Goto ) ); }842 { $$ = new StatementNode2( build_branch( *$2, BranchStmt::Goto ) ); } 844 843 | GOTO '*' comma_expression ';' // GCC, computed goto 845 844 // The syntax for the GCC computed goto violates normal expression precedence, e.g., goto *i+3; => goto *(i+3); 846 845 // whereas normal operator precedence yields goto (*i)+3; 847 { $$ = new StatementNode ( build_computedgoto( $3 ) ); }846 { $$ = new StatementNode2( build_computedgoto( $3 ) ); } 848 847 | CONTINUE ';' 849 848 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. 850 { $$ = new StatementNode ( build_branch(BranchStmt::Continue ) ); }849 { $$ = new StatementNode2( build_branch( "", BranchStmt::Continue ) ); } 851 850 | CONTINUE IDENTIFIER ';' // CFA, multi-level continue 852 851 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and 853 852 // the target of the transfer appears only at the start of an iteration statement. 854 { $$ = new StatementNode ( build_branch( $2, BranchStmt::Continue ) ); }853 { $$ = new StatementNode2( build_branch( *$2, BranchStmt::Continue ) ); delete $2; } 855 854 | BREAK ';' 856 855 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. 857 { $$ = new StatementNode ( build_branch(BranchStmt::Break ) ); }856 { $$ = new StatementNode2( build_branch( "", BranchStmt::Break ) ); } 858 857 | BREAK IDENTIFIER ';' // CFA, multi-level exit 859 858 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and 860 859 // the target of the transfer appears only at the start of an iteration statement. 861 { $$ = new StatementNode ( build_branch( $2, BranchStmt::Break ) ); }860 { $$ = new StatementNode2( build_branch( *$2, BranchStmt::Break ) ); delete $2; } 862 861 | RETURN comma_expression_opt ';' 863 { $$ = new StatementNode ( build_return( $2 ) ); }862 { $$ = new StatementNode2( build_return( $2 ) ); } 864 863 | THROW assignment_expression_opt ';' // handles rethrow 865 { $$ = new StatementNode ( build_throw( $2 ) ); }864 { $$ = new StatementNode2( build_throw( $2 ) ); } 866 865 | THROWRESUME assignment_expression_opt ';' // handles reresume 867 { $$ = new StatementNode ( build_throw( $2 ) ); }866 { $$ = new StatementNode2( build_throw( $2 ) ); } 868 867 | THROWRESUME assignment_expression_opt AT assignment_expression ';' // handles reresume 869 { $$ = new StatementNode ( build_throw( $2 ) ); }868 { $$ = new StatementNode2( build_throw( $2 ) ); } 870 869 ; 871 870 872 871 exception_statement: 873 872 TRY compound_statement handler_list 874 { $$ = new StatementNode( build_try( $2, $3, 0 )); }873 { $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 )))); } 875 874 | TRY compound_statement finally_clause 876 { $$ = new StatementNode( build_try( $2, 0, $3 )); }875 { $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 )))); } 877 876 | TRY compound_statement handler_list finally_clause 878 { $$ = new StatementNode( build_try( $2, $3, $4 ) ); } 877 { 878 $3->set_link( $4 ); 879 $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 )))); 880 } 879 881 ; 880 882 881 883 handler_list: 884 // There must be at least one catch clause 882 885 handler_clause 883 886 // ISO/IEC 9899:1999 Section 15.3(6 ) If present, a "..." handler shall be the last handler for its try block. 884 887 | CATCH '(' ELLIPSIS ')' compound_statement 885 { $$ = new StatementNode( build_catch( 0, $5, true )); }888 { $$ = StatementNode::newCatchStmt( 0, $5, true ); } 886 889 | handler_clause CATCH '(' ELLIPSIS ')' compound_statement 887 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true )) ); }890 { $$ = $1->set_link( StatementNode::newCatchStmt( 0, $6, true ) ); } 888 891 | CATCHRESUME '(' ELLIPSIS ')' compound_statement 889 { $$ = new StatementNode( build_catch( 0, $5, true )); }892 { $$ = StatementNode::newCatchStmt( 0, $5, true ); } 890 893 | handler_clause CATCHRESUME '(' ELLIPSIS ')' compound_statement 891 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true )) ); }894 { $$ = $1->set_link( StatementNode::newCatchStmt( 0, $6, true ) ); } 892 895 ; 893 896 894 897 handler_clause: 895 898 CATCH '(' push push exception_declaration pop ')' compound_statement pop 896 { $$ = new StatementNode( build_catch( $5, $8 )); }899 { $$ = StatementNode::newCatchStmt( $5, $8 ); } 897 900 | handler_clause CATCH '(' push push exception_declaration pop ')' compound_statement pop 898 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 )) ); }901 { $$ = $1->set_link( StatementNode::newCatchStmt( $6, $9 ) ); } 899 902 | CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop 900 { $$ = new StatementNode( build_catch( $5, $8 )); }903 { $$ = StatementNode::newCatchStmt( $5, $8 ); } 901 904 | handler_clause CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop 902 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 )) ); }905 { $$ = $1->set_link( StatementNode::newCatchStmt( $6, $9 ) ); } 903 906 ; 904 907 … … 906 909 FINALLY compound_statement 907 910 { 908 $$ = new StatementNode( build_finally( $2 ) ); 911 $$ = new StatementNode( StatementNode::Finally, 0, $2 ); 912 std::cout << "Just created a finally node" << std::endl; 909 913 } 910 914 ; … … 933 937 934 938 asm_statement: 935 ASM asm_volatile_opt '(' string_literal ')' ';'936 { $$ = new StatementNode( build_asmstmt( $2, $4, 0 )); }937 | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ')' ';' // remaining GCC938 { $$ = new StatementNode( build_asmstmt( $2, $4, $6 )); }939 | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ')' ';'940 { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8 )); }941 | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';'942 { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8, $10 )); }943 | ASM asm_volatile_opt GOTO '(' string_literal ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';'944 { $$ = new StatementNode( build_asmstmt( $2, $5, 0, $8, $10, $12 )); }939 ASM asm_volatile_opt '(' string_literal_list ')' ';' 940 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, 0 ); } 941 | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ')' ';' // remaining GCC 942 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6 ); } 943 | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ')' ';' 944 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6, $8 ); } 945 | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';' 946 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6, $8, $10 ); } 947 | ASM asm_volatile_opt GOTO '(' string_literal_list ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';' 948 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $5, 0, $8, $10, $12 ); } 945 949 ; 946 950 … … 961 965 asm_operand 962 966 | asm_operands_list ',' asm_operand 963 { $$ = (ExpressionNode *)$1->set_l ast( $3 ); }967 { $$ = (ExpressionNode *)$1->set_link( $3 ); } 964 968 ; 965 969 966 970 asm_operand: // GCC 967 string_literal '(' constant_expression ')'968 { $$ = new ExpressionNode( build_asm expr( 0, $1, $3 ) ); }969 | '[' constant_expression ']' string_literal '(' constant_expression ')'970 { $$ = new ExpressionNode( build_asm expr( $2, $4, $6 ) ); }971 string_literal_list '(' constant_expression ')' 972 { $$ = new ExpressionNode( build_asm( 0, $1, $3 ) ); } 973 | '[' constant_expression ']' string_literal_list '(' constant_expression ')' 974 { $$ = new ExpressionNode( build_asm( $2, $4, $6 ) ); } 971 975 ; 972 976 … … 974 978 // empty 975 979 { $$ = 0; } // use default argument 976 | string_literal 980 | string_literal_list 977 981 { $$ = new ExpressionNode( $1 ); } 978 | asm_clobbers_list_opt ',' string_literal 979 { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); }982 | asm_clobbers_list_opt ',' string_literal_list 983 { $$ = (ExpressionNode *)$1->set_link( new ExpressionNode( $3 ) ); } 980 984 ; 981 985 982 986 label_list: 983 987 no_attr_identifier 984 { 985 $$ = new LabelNode(); $$->labels.push_back( *$1 ); 986 delete $1; // allocated by lexer 987 } 988 { $$ = new LabelNode(); $$->append_label( $1 ); } 988 989 | label_list ',' no_attr_identifier 989 { 990 $$ = $1; $1->labels.push_back( *$3 ); 991 delete $3; // allocated by lexer 992 } 990 { $$ = $1; $1->append_label( $3 ); } 993 991 ; 994 992 … … 1288 1286 type_qualifier_name 1289 1287 | attribute 1290 //{ $$ = DeclarationNode::newQualifier( DeclarationNode::Attribute ); }1288 //{ $$ = DeclarationNode::newQualifier( DeclarationNode::Attribute ); } 1291 1289 ; 1292 1290 … … 1333 1331 1334 1332 storage_class: 1333 storage_class_name 1334 ; 1335 1336 storage_class_name: 1335 1337 EXTERN 1336 1338 { $$ = DeclarationNode::newStorageClass( DeclarationNode::Extern ); } … … 1342 1344 { $$ = DeclarationNode::newStorageClass( DeclarationNode::Register ); } 1343 1345 | INLINE // C99 1344 //{ $$ = DeclarationNode::newStorageClass( DeclarationNode::Inline ); } 1345 { $$ = new DeclarationNode; $$->isInline = true; } 1346 { $$ = DeclarationNode::newStorageClass( DeclarationNode::Inline ); } 1346 1347 | FORTRAN // C99 1347 1348 { $$ = DeclarationNode::newStorageClass( DeclarationNode::Fortran ); } 1348 1349 | NORETURN // C11 1349 //{ $$ = DeclarationNode::newStorageClass( DeclarationNode::Noreturn ); } 1350 { $$ = new DeclarationNode; $$->isNoreturn = true; } 1350 { $$ = DeclarationNode::newStorageClass( DeclarationNode::Noreturn ); } 1351 1351 | THREADLOCAL // C11 1352 1352 { $$ = DeclarationNode::newStorageClass( DeclarationNode::Threadlocal ); } … … 1504 1504 | EXTENSION field_declaring_list ';' // GCC 1505 1505 { // mark all fields in list 1506 for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() )1506 for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_link() ) 1507 1507 iter->set_extension( true ); 1508 1508 $$ = $2; … … 1750 1750 | initializer 1751 1751 | designation initializer { $$ = $2->set_designators( $1 ); } 1752 | initializer_list ',' initializer { $$ = (InitializerNode *)( $1->set_l ast( $3 ) ); }1752 | initializer_list ',' initializer { $$ = (InitializerNode *)( $1->set_link( $3 ) ); } 1753 1753 | initializer_list ',' designation initializer 1754 { $$ = (InitializerNode *)( $1->set_l ast( $4->set_designators( $3 ) ) ); }1754 { $$ = (InitializerNode *)( $1->set_link( $4->set_designators( $3 ) ) ); } 1755 1755 ; 1756 1756 … … 1774 1774 designator 1775 1775 | designator_list designator 1776 { $$ = (ExpressionNode *)( $1->set_l ast( $2 ) ); }1776 { $$ = (ExpressionNode *)( $1->set_link( $2 ) ); } 1777 1777 //| designator_list designator { $$ = new ExpressionNode( $1, $2 ); } 1778 1778 ; … … 1880 1880 | assignment_expression 1881 1881 | type_name_list ',' type_name 1882 { $$ = (ExpressionNode *)( $1->set_l ast( new ExpressionNode( build_typevalue( $3 ) ) ) ); }1882 { $$ = (ExpressionNode *)( $1->set_link( new ExpressionNode( build_typevalue( $3 ) ) ) ); } 1883 1883 | type_name_list ',' assignment_expression 1884 { $$ = (ExpressionNode *)( $1->set_l ast( $3 )); }1884 { $$ = (ExpressionNode *)( $1->set_link( $3 )); } 1885 1885 ; 1886 1886 … … 1981 1981 {} // empty input file 1982 1982 | external_definition_list 1983 { parseTree = parseTree != nullptr ? parseTree->appendList( $1 ) : $1; } 1983 { 1984 if ( theTree ) { 1985 theTree->appendList( $1 ); 1986 } else { 1987 theTree = $1; 1988 } 1989 } 1984 1990 ; 1985 1991 … … 1987 1993 external_definition 1988 1994 | external_definition_list push external_definition 1989 { $$ = $1 != nullptr? $1->appendList( $3 ) : $3; }1995 { $$ = ( $1 != NULL ) ? $1->appendList( $3 ) : $3; } 1990 1996 ; 1991 1997 … … 2003 2009 | EXTERN STRINGliteral 2004 2010 { 2005 linkageStack.push( linkage ); // handle nested extern "C"/"Cforall"2011 linkageStack.push( linkage ); 2006 2012 linkage = LinkageSpec::fromString( *$2 ); 2007 2013 } … … 2014 2020 | EXTENSION external_definition 2015 2021 { // mark all fields in list 2016 for ( DeclarationNode *iter = $2; iter != nullptr; iter = (DeclarationNode *)iter->get_next() )2022 for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_link() ) 2017 2023 iter->set_extension( true ); 2018 2024 $$ = $2; … … 2115 2121 asm_name_opt: // GCC 2116 2122 // empty 2117 | ASM '(' string_literal_list ')' attribute_list_opt { delete $3; } // FIX ME: unimplemented2123 | ASM '(' string_literal_list ')' attribute_list_opt 2118 2124 ; 2119 2125 … … 2144 2150 // empty 2145 2151 | any_word 2146 | any_word '(' comma_expression_opt ')' { delete $3; } // FIX ME: unimplemented2152 | any_word '(' comma_expression_opt ')' 2147 2153 ; 2148 2154 2149 2155 any_word: // GCC 2150 identifier_or_type_name { delete $1; } // FIX ME: unimplemented2151 | storage_class { delete $1; } // FIX ME: unimplemented2152 | basic_type_name { delete $1; } // FIX ME: unimplemented2153 | type_qualifier { delete $1; } // FIX ME: unimplemented2156 identifier_or_type_name {} 2157 | storage_class_name {} 2158 | basic_type_name {} 2159 | type_qualifier {} 2154 2160 ; 2155 2161 … … 2849 2855 // ----end of grammar---- 2850 2856 2851 extern char *yytext;2852 2853 2857 void yyerror( const char * ) { 2854 2858 std::cout << "Error ";
Note:
See TracChangeset
for help on using the changeset viewer.