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