Changeset d60ccbf for src/Parser/parser.yy
- Timestamp:
- Aug 12, 2015, 2:27:31 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- f32c7f4
- Parents:
- e45215c (diff), e869d663 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
re45215c rd60ccbf 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 3 13:53:45201513 // Update Count : 1 22012 // Last Modified On : Tue Aug 11 16:01:49 2015 13 // Update Count : 1350 14 14 // 15 15 … … 54 54 #include "lex.h" 55 55 #include "ParseNode.h" 56 #include "TypeData.h" 56 57 #include "LinkageSpec.h" 57 58 … … 114 115 StatementNode *sn; 115 116 ConstantNode *constant; 117 LabelNode *label; 116 118 InitializerNode *in; 119 bool flag; 117 120 } 118 121 … … 133 136 %type<en> argument_expression_list argument_expression for_control_expression assignment_opt 134 137 %type<en> subrange 138 %type<en> asm_operands_opt asm_operands_list asm_operand 139 %type<label> label_list 140 %type<constant> asm_clobbers_list_opt 141 %type<flag> asm_volatile_opt 135 142 136 143 // statements … … 228 235 %type<decl> variable_abstract_ptr variable_array variable_declarator variable_function variable_ptr 229 236 237 %type<decl> attribute_list_opt attribute_list attribute 238 230 239 // initializers 231 240 %type<in> initializer initializer_list initializer_opt … … 329 338 | zero_one 330 339 { $$ = new VarRefNode( $1 ); } 331 | constant332 { $$ = $1; }333 | string_literal_list334 { $$ = $1; }335 340 | '(' comma_expression ')' 336 341 { $$ = $2; } … … 375 380 | assignment_expression 376 381 | no_attr_identifier ':' assignment_expression 377 { $$ = $3->set_a sArgName( $1 ); }382 { $$ = $3->set_argName( $1 ); } 378 383 // Only a list of no_attr_identifier_or_type_name is allowed in this context. However, there is insufficient 379 384 // look ahead to distinguish between this list of parameter names and a tuple, so the tuple form must be used 380 385 // with an appropriate semantic check. 381 386 | '[' push assignment_expression pop ']' ':' assignment_expression 382 { $$ = $7->set_a sArgName( $3 ); }387 { $$ = $7->set_argName( $3 ); } 383 388 | '[' push assignment_expression ',' tuple_expression_list pop ']' ':' assignment_expression 384 { $$ = $9->set_a sArgName( new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)$3->set_link( flattenCommas( $5 )))); }389 { $$ = $9->set_argName( new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)$3->set_link( flattenCommas( $5 )))); } 385 390 ; 386 391 … … 405 410 unary_expression: 406 411 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, &&3 414 | constant 415 { $$ = $1; } 416 | string_literal_list 417 { $$ = $1; } 407 418 | ICR unary_expression 408 419 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Incr ), $2 ); } … … 620 631 labeled_statement: 621 632 no_attr_identifier ':' attribute_list_opt statement 622 { $$ = $4->add_label( $1 );} 633 { 634 $$ = $4->add_label( $1 ); 635 } 623 636 ; 624 637 … … 630 643 // requires its own scope 631 644 push push 632 l abel_declaration_opt// GCC, local labels645 local_label_declaration_opt // GCC, local labels 633 646 block_item_list pop '}' // C99, intermix declarations and statements 634 647 { $$ = new CompoundStmtNode( $5 ); } … … 749 762 750 763 fall_through: // CFA 751 FALLTHRU { $$ = new StatementNode( StatementNode::Fallthru , 0, 0); }752 | FALLTHRU ';' { $$ = new StatementNode( StatementNode::Fallthru , 0, 0); }764 FALLTHRU { $$ = new StatementNode( StatementNode::Fallthru ); } 765 | FALLTHRU ';' { $$ = new StatementNode( StatementNode::Fallthru ); } 753 766 ; 754 767 … … 778 791 | CONTINUE ';' 779 792 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. 780 { $$ = new StatementNode( StatementNode::Continue , 0, 0); }793 { $$ = new StatementNode( StatementNode::Continue ); } 781 794 | CONTINUE no_attr_identifier ';' // CFA, multi-level continue 782 795 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and … … 785 798 | BREAK ';' 786 799 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. 787 { $$ = new StatementNode( StatementNode::Break , 0, 0); }800 { $$ = new StatementNode( StatementNode::Break ); } 788 801 | BREAK no_attr_identifier ';' // CFA, multi-level exit 789 802 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and … … 795 808 { $$ = new StatementNode( StatementNode::Throw, $2, 0 ); } 796 809 | THROW ';' 797 { $$ = new StatementNode( StatementNode::Throw , 0, 0); }810 { $$ = new StatementNode( StatementNode::Throw ); } 798 811 ; 799 812 … … 858 871 859 872 asm_statement: 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 ); } 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; } 868 890 ; 869 891 870 892 asm_operands_opt: // GCC 871 893 // empty 894 { $$ = 0; } // use default argument 872 895 | asm_operands_list 873 896 ; … … 876 899 asm_operand 877 900 | asm_operands_list ',' asm_operand 901 { $$ = (ExpressionNode *)$1->set_link( $3 ); } 878 902 ; 879 903 880 904 asm_operand: // GCC 881 STRINGliteral '(' constant_expression ')' {} 882 ; 883 884 asm_clobbers_list: // GCC 885 STRINGliteral {} 886 | asm_clobbers_list ',' STRINGliteral 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 ); } 887 925 ; 888 926 … … 913 951 ; 914 952 915 l abel_declaration_opt:// GCC, local label953 local_label_declaration_opt: // GCC, local label 916 954 // empty 917 | l abel_declaration_list918 ; 919 920 l abel_declaration_list:// GCC, local label921 LABEL l abel_list ';'922 | l abel_declaration_list LABELlabel_list ';'923 ; 924 925 l abel_list:// GCC, local label926 no_attr_identifier_or_type_name {}927 | l abel_list ',' no_attr_identifier_or_type_name {}955 | local_label_declaration_list 956 ; 957 958 local_label_declaration_list: // GCC, local label 959 LABEL local_label_list ';' 960 | local_label_declaration_list LABEL local_label_list ';' 961 ; 962 963 local_label_list: // GCC, local label 964 no_attr_identifier_or_type_name {} 965 | local_label_list ',' no_attr_identifier_or_type_name {} 928 966 ; 929 967 … … 1182 1220 type_qualifier_name 1183 1221 | attribute 1184 1222 //{ $$ = DeclarationNode::newQualifier( DeclarationNode::Attribute ); } 1185 1223 ; 1186 1224 … … 1655 1693 1656 1694 designator: 1657 '.' no_attr_identifier_or_type_name // C99, field name 1658 { $$ = new VarRefNode( $2 ); } 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 ) ); } 1659 1700 | '[' push assignment_expression pop ']' // C99, single array element 1660 1701 // assignment_expression used instead of constant_expression because of shift/reduce conflicts with tuple. 1661 { $$ = $3; }1702 { $$ = new DesignatorNode( $3, true ); } 1662 1703 | '[' push subrange pop ']' // CFA, multiple array elements 1663 { $$ = $3; }1704 { $$ = new DesignatorNode( $3, true ); } 1664 1705 | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements 1665 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $3, $5); }1706 { $$ = new DesignatorNode( new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $3, $5 ), true ); } 1666 1707 | '.' '[' push field_list pop ']' // CFA, tuple field selector 1667 { $$ = $4; }1708 { $$ = new DesignatorNode( $4 ); } 1668 1709 ; 1669 1710 … … 1997 2038 attribute_list_opt: // GCC 1998 2039 // empty 2040 { $$ = 0; } 1999 2041 | attribute_list 2000 2042 ; … … 2003 2045 attribute 2004 2046 | attribute_list attribute 2047 { $$ = $2->addQualifiers( $1 ); } 2005 2048 ; 2006 2049 2007 2050 attribute: // GCC 2008 2051 ATTRIBUTE '(' '(' attribute_parameter_list ')' ')' 2052 // { $$ = DeclarationNode::newQualifier( DeclarationNode::Attribute ); } 2053 { $$ = 0; } 2009 2054 ; 2010 2055 … … 2059 2104 variable_declarator: 2060 2105 paren_identifier attribute_list_opt 2106 { $$ = $1->addQualifiers( $2 ); } 2061 2107 | variable_ptr 2062 2108 | variable_array attribute_list_opt 2109 { $$ = $1->addQualifiers( $2 ); } 2063 2110 | variable_function attribute_list_opt 2111 { $$ = $1->addQualifiers( $2 ); } 2064 2112 ; 2065 2113 … … 2108 2156 function_declarator: 2109 2157 function_no_ptr attribute_list_opt 2158 { $$ = $1->addQualifiers( $2 ); } 2110 2159 | function_ptr 2111 2160 | function_array attribute_list_opt 2161 { $$ = $1->addQualifiers( $2 ); } 2112 2162 ; 2113 2163 … … 2188 2238 type_redeclarator: 2189 2239 paren_type attribute_list_opt 2240 { $$ = $1->addQualifiers( $2 ); } 2190 2241 | type_ptr 2191 2242 | type_array attribute_list_opt 2243 { $$ = $1->addQualifiers( $2 ); } 2192 2244 | type_function attribute_list_opt 2245 { $$ = $1->addQualifiers( $2 ); } 2193 2246 ; 2194 2247 … … 2235 2288 identifier_parameter_declarator: 2236 2289 paren_identifier attribute_list_opt 2290 { $$ = $1->addQualifiers( $2 ); } 2237 2291 | identifier_parameter_ptr 2238 2292 | identifier_parameter_array attribute_list_opt 2293 { $$ = $1->addQualifiers( $2 ); } 2239 2294 | identifier_parameter_function attribute_list_opt 2295 { $$ = $1->addQualifiers( $2 ); } 2240 2296 ; 2241 2297 … … 2297 2353 type_parameter_redeclarator: 2298 2354 typedef attribute_list_opt 2355 { $$ = $1->addQualifiers( $2 ); } 2299 2356 | type_parameter_ptr 2300 2357 | type_parameter_array attribute_list_opt 2358 { $$ = $1->addQualifiers( $2 ); } 2301 2359 | type_parameter_function attribute_list_opt 2360 { $$ = $1->addQualifiers( $2 ); } 2302 2361 ; 2303 2362 … … 2350 2409 abstract_ptr 2351 2410 | abstract_array attribute_list_opt 2411 { $$ = $1->addQualifiers( $2 ); } 2352 2412 | abstract_function attribute_list_opt 2413 { $$ = $1->addQualifiers( $2 ); } 2353 2414 ; 2354 2415 … … 2417 2478 abstract_parameter_ptr 2418 2479 | abstract_parameter_array attribute_list_opt 2480 { $$ = $1->addQualifiers( $2 ); } 2419 2481 | abstract_parameter_function attribute_list_opt 2482 { $$ = $1->addQualifiers( $2 ); } 2420 2483 ; 2421 2484 … … 2493 2556 variable_abstract_ptr 2494 2557 | variable_abstract_array attribute_list_opt 2558 { $$ = $1->addQualifiers( $2 ); } 2495 2559 | variable_abstract_function attribute_list_opt 2560 { $$ = $1->addQualifiers( $2 ); } 2496 2561 ; 2497 2562
Note:
See TracChangeset
for help on using the changeset viewer.