Changes in src/Parser/parser.yy [51b1202:2871210]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (29 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
r51b1202 r2871210 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Aug 11 16:01:49201513 // Update Count : 1 35012 // Last Modified On : Fri Jul 3 13:53:45 2015 13 // Update Count : 1220 14 14 // 15 15 … … 54 54 #include "lex.h" 55 55 #include "ParseNode.h" 56 #include "TypeData.h"57 56 #include "LinkageSpec.h" 58 57 … … 115 114 StatementNode *sn; 116 115 ConstantNode *constant; 117 LabelNode *label;118 116 InitializerNode *in; 119 bool flag;120 117 } 121 118 … … 136 133 %type<en> argument_expression_list argument_expression for_control_expression assignment_opt 137 134 %type<en> subrange 138 %type<en> asm_operands_opt asm_operands_list asm_operand139 %type<label> label_list140 %type<constant> asm_clobbers_list_opt141 %type<flag> asm_volatile_opt142 135 143 136 // statements … … 235 228 %type<decl> variable_abstract_ptr variable_array variable_declarator variable_function variable_ptr 236 229 237 %type<decl> attribute_list_opt attribute_list attribute238 239 230 // initializers 240 231 %type<in> initializer initializer_list initializer_opt … … 338 329 | zero_one 339 330 { $$ = new VarRefNode( $1 ); } 331 | constant 332 { $$ = $1; } 333 | string_literal_list 334 { $$ = $1; } 340 335 | '(' comma_expression ')' 341 336 { $$ = $2; } … … 380 375 | assignment_expression 381 376 | no_attr_identifier ':' assignment_expression 382 { $$ = $3->set_a rgName( $1 ); }377 { $$ = $3->set_asArgName( $1 ); } 383 378 // Only a list of no_attr_identifier_or_type_name is allowed in this context. However, there is insufficient 384 379 // look ahead to distinguish between this list of parameter names and a tuple, so the tuple form must be used 385 380 // with an appropriate semantic check. 386 381 | '[' push assignment_expression pop ']' ':' assignment_expression 387 { $$ = $7->set_a rgName( $3 ); }382 { $$ = $7->set_asArgName( $3 ); } 388 383 | '[' push assignment_expression ',' tuple_expression_list pop ']' ':' assignment_expression 389 { $$ = $9->set_a rgName( new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)$3->set_link( flattenCommas( $5 )))); }384 { $$ = $9->set_asArgName( new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)$3->set_link( flattenCommas( $5 )))); } 390 385 ; 391 386 … … 410 405 unary_expression: 411 406 postfix_expression 412 // first location where constant/string can have operator applied: sizeof 3/sizeof "abc"413 // still requires semantics checks, e.g., ++3, 3--, *3, &&3414 | constant415 { $$ = $1; }416 | string_literal_list417 { $$ = $1; }418 407 | ICR unary_expression 419 408 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Incr ), $2 ); } … … 631 620 labeled_statement: 632 621 no_attr_identifier ':' attribute_list_opt statement 633 { 634 $$ = $4->add_label( $1 ); 635 } 622 { $$ = $4->add_label( $1 );} 636 623 ; 637 624 … … 643 630 // requires its own scope 644 631 push push 645 l ocal_label_declaration_opt// GCC, local labels632 label_declaration_opt // GCC, local labels 646 633 block_item_list pop '}' // C99, intermix declarations and statements 647 634 { $$ = new CompoundStmtNode( $5 ); } … … 762 749 763 750 fall_through: // CFA 764 FALLTHRU { $$ = new StatementNode( StatementNode::Fallthru ); }765 | FALLTHRU ';' { $$ = new StatementNode( StatementNode::Fallthru ); }751 FALLTHRU { $$ = new StatementNode( StatementNode::Fallthru, 0, 0 ); } 752 | FALLTHRU ';' { $$ = new StatementNode( StatementNode::Fallthru, 0, 0 ); } 766 753 ; 767 754 … … 791 778 | CONTINUE ';' 792 779 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. 793 { $$ = new StatementNode( StatementNode::Continue ); }780 { $$ = new StatementNode( StatementNode::Continue, 0, 0 ); } 794 781 | CONTINUE no_attr_identifier ';' // CFA, multi-level continue 795 782 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and … … 798 785 | BREAK ';' 799 786 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. 800 { $$ = new StatementNode( StatementNode::Break ); }787 { $$ = new StatementNode( StatementNode::Break, 0, 0 ); } 801 788 | BREAK no_attr_identifier ';' // CFA, multi-level exit 802 789 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and … … 808 795 { $$ = new StatementNode( StatementNode::Throw, $2, 0 ); } 809 796 | THROW ';' 810 { $$ = new StatementNode( StatementNode::Throw ); }797 { $$ = new StatementNode( StatementNode::Throw, 0, 0 ); } 811 798 ; 812 799 … … 871 858 872 859 asm_statement: 873 ASM asm_volatile_opt '(' string_literal_list ')' ';' 874 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, 0 ); } 875 | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ')' ';' // remaining GCC 876 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6 ); } 877 | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ')' ';' 878 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6, $8 ); } 879 | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';' 880 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6, $8, $10 ); } 881 | ASM asm_volatile_opt GOTO '(' string_literal_list ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';' 882 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $5, 0, $8, $10, $12 ); } 883 ; 884 885 asm_volatile_opt: // GCC 886 // empty 887 { $$ = false; } 888 | VOLATILE 889 { $$ = true; } 860 ASM type_qualifier_list_opt '(' constant_expression ')' ';' 861 { $$ = new StatementNode( StatementNode::Asm, 0, 0 ); } 862 | ASM type_qualifier_list_opt '(' constant_expression ':' asm_operands_opt ')' ';' // remaining GCC 863 { $$ = new StatementNode( StatementNode::Asm, 0, 0 ); } 864 | ASM type_qualifier_list_opt '(' constant_expression ':' asm_operands_opt ':' asm_operands_opt ')' ';' 865 { $$ = new StatementNode( StatementNode::Asm, 0, 0 ); } 866 | ASM type_qualifier_list_opt '(' constant_expression ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list ')' ';' 867 { $$ = new StatementNode( StatementNode::Asm, 0, 0 ); } 890 868 ; 891 869 892 870 asm_operands_opt: // GCC 893 871 // empty 894 { $$ = 0; } // use default argument895 872 | asm_operands_list 896 873 ; … … 899 876 asm_operand 900 877 | asm_operands_list ',' asm_operand 901 { $$ = (ExpressionNode *)$1->set_link( $3 ); }902 878 ; 903 879 904 880 asm_operand: // GCC 905 string_literal_list '(' constant_expression ')' 906 { $$ = new AsmExprNode( 0, $1, $3 ); } 907 | '[' constant_expression ']' string_literal_list '(' constant_expression ')' 908 { $$ = new AsmExprNode( $2, $4, $6 ); } 909 ; 910 911 asm_clobbers_list_opt: // GCC 912 // empty 913 { $$ = 0; } // use default argument 914 | string_literal_list 915 { $$ = $1; } 916 | asm_clobbers_list_opt ',' string_literal_list 917 { $$ = (ConstantNode *)$1->set_link( $3 ); } 918 ; 919 920 label_list: 921 no_attr_identifier 922 { $$ = new LabelNode(); $$->append_label( $1 ); } 923 | label_list ',' no_attr_identifier 924 { $$ = $1; $1->append_label( $3 ); } 881 STRINGliteral '(' constant_expression ')' {} 882 ; 883 884 asm_clobbers_list: // GCC 885 STRINGliteral {} 886 | asm_clobbers_list ',' STRINGliteral 925 887 ; 926 888 … … 951 913 ; 952 914 953 l ocal_label_declaration_opt:// GCC, local label915 label_declaration_opt: // GCC, local label 954 916 // empty 955 | l ocal_label_declaration_list956 ; 957 958 l ocal_label_declaration_list:// GCC, local label959 LABEL l ocal_label_list ';'960 | l ocal_label_declaration_list LABEL local_label_list ';'961 ; 962 963 l ocal_label_list:// GCC, local label964 no_attr_identifier_or_type_name {}965 | l ocal_label_list ',' no_attr_identifier_or_type_name {}917 | label_declaration_list 918 ; 919 920 label_declaration_list: // GCC, local label 921 LABEL label_list ';' 922 | label_declaration_list LABEL label_list ';' 923 ; 924 925 label_list: // GCC, local label 926 no_attr_identifier_or_type_name {} 927 | label_list ',' no_attr_identifier_or_type_name {} 966 928 ; 967 929 … … 1220 1182 type_qualifier_name 1221 1183 | attribute 1222 //{ $$ = DeclarationNode::newQualifier( DeclarationNode::Attribute ); }1184 { $$ = DeclarationNode::newQualifier( DeclarationNode::Attribute ); } 1223 1185 ; 1224 1186 … … 1693 1655 1694 1656 designator: 1695 // only ".0" and ".1" allowed => semantic check 1696 FLOATINGconstant 1697 { $$ = new DesignatorNode( new VarRefNode( $1 ) ); } 1698 | '.' no_attr_identifier_or_type_name // C99, field name 1699 { $$ = new DesignatorNode( new VarRefNode( $2 ) ); } 1657 '.' no_attr_identifier_or_type_name // C99, field name 1658 { $$ = new VarRefNode( $2 ); } 1700 1659 | '[' push assignment_expression pop ']' // C99, single array element 1701 1660 // assignment_expression used instead of constant_expression because of shift/reduce conflicts with tuple. 1702 { $$ = new DesignatorNode( $3, true ); }1661 { $$ = $3; } 1703 1662 | '[' push subrange pop ']' // CFA, multiple array elements 1704 { $$ = new DesignatorNode( $3, true ); }1663 { $$ = $3; } 1705 1664 | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements 1706 { $$ = new DesignatorNode( new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $3, $5 ), true); }1665 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $3, $5 ); } 1707 1666 | '.' '[' push field_list pop ']' // CFA, tuple field selector 1708 { $$ = new DesignatorNode( $4 ); }1667 { $$ = $4; } 1709 1668 ; 1710 1669 … … 2038 1997 attribute_list_opt: // GCC 2039 1998 // empty 2040 { $$ = 0; }2041 1999 | attribute_list 2042 2000 ; … … 2045 2003 attribute 2046 2004 | attribute_list attribute 2047 { $$ = $2->addQualifiers( $1 ); }2048 2005 ; 2049 2006 2050 2007 attribute: // GCC 2051 2008 ATTRIBUTE '(' '(' attribute_parameter_list ')' ')' 2052 // { $$ = DeclarationNode::newQualifier( DeclarationNode::Attribute ); }2053 { $$ = 0; }2054 2009 ; 2055 2010 … … 2104 2059 variable_declarator: 2105 2060 paren_identifier attribute_list_opt 2106 { $$ = $1->addQualifiers( $2 ); }2107 2061 | variable_ptr 2108 2062 | variable_array attribute_list_opt 2109 { $$ = $1->addQualifiers( $2 ); }2110 2063 | variable_function attribute_list_opt 2111 { $$ = $1->addQualifiers( $2 ); }2112 2064 ; 2113 2065 … … 2156 2108 function_declarator: 2157 2109 function_no_ptr attribute_list_opt 2158 { $$ = $1->addQualifiers( $2 ); }2159 2110 | function_ptr 2160 2111 | function_array attribute_list_opt 2161 { $$ = $1->addQualifiers( $2 ); }2162 2112 ; 2163 2113 … … 2238 2188 type_redeclarator: 2239 2189 paren_type attribute_list_opt 2240 { $$ = $1->addQualifiers( $2 ); }2241 2190 | type_ptr 2242 2191 | type_array attribute_list_opt 2243 { $$ = $1->addQualifiers( $2 ); }2244 2192 | type_function attribute_list_opt 2245 { $$ = $1->addQualifiers( $2 ); }2246 2193 ; 2247 2194 … … 2288 2235 identifier_parameter_declarator: 2289 2236 paren_identifier attribute_list_opt 2290 { $$ = $1->addQualifiers( $2 ); }2291 2237 | identifier_parameter_ptr 2292 2238 | identifier_parameter_array attribute_list_opt 2293 { $$ = $1->addQualifiers( $2 ); }2294 2239 | identifier_parameter_function attribute_list_opt 2295 { $$ = $1->addQualifiers( $2 ); }2296 2240 ; 2297 2241 … … 2353 2297 type_parameter_redeclarator: 2354 2298 typedef attribute_list_opt 2355 { $$ = $1->addQualifiers( $2 ); }2356 2299 | type_parameter_ptr 2357 2300 | type_parameter_array attribute_list_opt 2358 { $$ = $1->addQualifiers( $2 ); }2359 2301 | type_parameter_function attribute_list_opt 2360 { $$ = $1->addQualifiers( $2 ); }2361 2302 ; 2362 2303 … … 2409 2350 abstract_ptr 2410 2351 | abstract_array attribute_list_opt 2411 { $$ = $1->addQualifiers( $2 ); }2412 2352 | abstract_function attribute_list_opt 2413 { $$ = $1->addQualifiers( $2 ); }2414 2353 ; 2415 2354 … … 2478 2417 abstract_parameter_ptr 2479 2418 | abstract_parameter_array attribute_list_opt 2480 { $$ = $1->addQualifiers( $2 ); }2481 2419 | abstract_parameter_function attribute_list_opt 2482 { $$ = $1->addQualifiers( $2 ); }2483 2420 ; 2484 2421 … … 2556 2493 variable_abstract_ptr 2557 2494 | variable_abstract_array attribute_list_opt 2558 { $$ = $1->addQualifiers( $2 ); }2559 2495 | variable_abstract_function attribute_list_opt 2560 { $$ = $1->addQualifiers( $2 ); }2561 2496 ; 2562 2497
Note:
See TracChangeset
for help on using the changeset viewer.