Changes in src/Parser/parser.yy [c86b08d:561354f]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (30 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
rc86b08d r561354f 48 48 using namespace std; 49 49 50 #include "SynTree/Declaration.h" 51 #include "ParseNode.h" 50 #include "SynTree/Type.h" // for Type 51 #include "DeclarationNode.h" // for DeclarationNode, ... 52 #include "ExpressionNode.h" // for ExpressionNode, ... 53 #include "InitializerNode.h" // for InitializerNode, ... 54 #include "ParserTypes.h" 55 #include "StatementNode.h" // for build_... 52 56 #include "TypedefTable.h" 53 57 #include "TypeData.h" 54 #include "SynTree/LinkageSpec.h"55 58 #include "Common/SemanticError.h" // error_str 56 59 #include "Common/utility.h" // for maybeMoveBuild, maybeBuild, CodeLo... … … 297 300 %union { 298 301 Token tok; 299 ParseNode * pn; 300 ExpressionNode * en; 302 ExpressionNode * expr; 301 303 DeclarationNode * decl; 302 304 ast::AggregateDecl::Aggregate aggKey; 303 305 ast::TypeDecl::Kind tclass; 304 StatementNode * sn; 306 StatementNode * stmt; 307 ClauseNode * clause; 305 308 ast::WaitForStmt * wfs; 306 ast::WaitUntilStmt::ClauseNode * wuscn;307 ast::Expr * constant;308 309 CondCtl * ifctl; 309 ForCtrl * fctl; 310 OperKinds compop; 311 LabelNode * label; 312 InitializerNode * in; 313 OperKinds op; 310 ForCtrl * forctl; 311 LabelNode * labels; 312 InitializerNode * init; 313 OperKinds oper; 314 314 std::string * str; 315 bool flag;316 EnumHiding hide;317 ast::ExceptionKind catch_kind;315 bool is_volatile; 316 EnumHiding enum_hiding; 317 ast::ExceptionKind except_kind; 318 318 ast::GenericExpr * genexpr; 319 319 } … … 339 339 %token SIZEOF TYPEOF VA_LIST VA_ARG AUTO_TYPE // GCC 340 340 %token OFFSETOF BASETYPEOF TYPEID // CFA 341 %token ENUM STRUCT UNION 341 %token ENUM STRUCT UNION DATA 342 342 %token EXCEPTION // CFA 343 343 %token GENERATOR COROUTINE MONITOR THREAD // CFA … … 381 381 %type<tok> identifier identifier_at identifier_or_type_name attr_name 382 382 %type<tok> quasi_keyword 383 %type< constant> string_literal383 %type<expr> string_literal 384 384 %type<str> string_literal_list 385 385 386 %type< hide> hide_opt visible_hide_opt386 %type<enum_hiding> hide_opt visible_hide_opt 387 387 388 388 // expressions 389 %type<e n> constant390 %type<e n> tuple tuple_expression_list391 %type<op > ptrref_operator unary_operator assignment_operator simple_assignment_operator compound_assignment_operator392 %type<e n> primary_expression postfix_expression unary_expression393 %type<e n> cast_expression_list cast_expression exponential_expression multiplicative_expression additive_expression394 %type<e n> shift_expression relational_expression equality_expression395 %type<e n> AND_expression exclusive_OR_expression inclusive_OR_expression396 %type<e n> logical_AND_expression logical_OR_expression397 %type<e n> conditional_expression constant_expression assignment_expression assignment_expression_opt398 %type<e n> comma_expression comma_expression_opt399 %type<e n> argument_expression_list_opt argument_expression_list argument_expression default_initializer_opt389 %type<expr> constant 390 %type<expr> tuple tuple_expression_list 391 %type<oper> ptrref_operator unary_operator assignment_operator simple_assignment_operator compound_assignment_operator 392 %type<expr> primary_expression postfix_expression unary_expression 393 %type<expr> cast_expression_list cast_expression exponential_expression multiplicative_expression additive_expression 394 %type<expr> shift_expression relational_expression equality_expression 395 %type<expr> AND_expression exclusive_OR_expression inclusive_OR_expression 396 %type<expr> logical_AND_expression logical_OR_expression 397 %type<expr> conditional_expression constant_expression assignment_expression assignment_expression_opt 398 %type<expr> comma_expression comma_expression_opt 399 %type<expr> argument_expression_list_opt argument_expression_list argument_expression default_initializer_opt 400 400 %type<ifctl> conditional_declaration 401 %type<f ctl> for_control_expression for_control_expression_list402 %type< compop> upupeq updown updowneq downupdowneq403 %type<e n> subrange401 %type<forctl> for_control_expression for_control_expression_list 402 %type<oper> upupeq updown updowneq downupdowneq 403 %type<expr> subrange 404 404 %type<decl> asm_name_opt 405 %type<e n> asm_operands_opt asm_operands_list asm_operand406 %type<label > label_list407 %type<e n> asm_clobbers_list_opt408 %type< flag> asm_volatile_opt409 %type<e n> handler_predicate_opt405 %type<expr> asm_operands_opt asm_operands_list asm_operand 406 %type<labels> label_list 407 %type<expr> asm_clobbers_list_opt 408 %type<is_volatile> asm_volatile_opt 409 %type<expr> handler_predicate_opt 410 410 %type<genexpr> generic_association generic_assoc_list 411 411 412 412 // statements 413 %type<s n> statement labeled_statement compound_statement414 %type<s n> statement_decl statement_decl_list statement_list_nodecl415 %type<s n> selection_statement if_statement416 %type< sn> switch_clause_list_opt switch_clause_list417 %type<e n> case_value418 %type< sn> case_clausecase_value_list case_label case_label_list419 %type<s n> iteration_statement jump_statement420 %type<s n> expression_statement asm_statement421 %type<s n> with_statement422 %type<e n> with_clause_opt423 %type<s n> exception_statement handler_clause finally_clause424 %type<c atch_kind> handler_key425 %type< sn> mutex_statement426 %type< en> when_clause when_clause_opt waitfor waituntil timeout427 %type< sn> waitfor_statement waituntil_statement428 %type< wfs> wor_waitfor_clause429 %type<w uscn> waituntil_clause wand_waituntil_clausewor_waituntil_clause413 %type<stmt> statement labeled_statement compound_statement 414 %type<stmt> statement_decl statement_decl_list statement_list_nodecl 415 %type<stmt> selection_statement if_statement 416 %type<clause> switch_clause_list_opt switch_clause_list 417 %type<expr> case_value 418 %type<clause> case_clause case_value_list case_label case_label_list 419 %type<stmt> iteration_statement jump_statement 420 %type<stmt> expression_statement asm_statement 421 %type<stmt> with_statement 422 %type<expr> with_clause_opt 423 %type<stmt> exception_statement 424 %type<clause> handler_clause finally_clause 425 %type<except_kind> handler_key 426 %type<stmt> mutex_statement 427 %type<expr> when_clause when_clause_opt waitfor waituntil timeout 428 %type<stmt> waitfor_statement waituntil_statement 429 %type<wfs> wor_waitfor_clause waituntil_clause wand_waituntil_clause wor_waituntil_clause 430 430 431 431 // declarations … … 439 439 %type<decl> assertion assertion_list assertion_list_opt 440 440 441 %type<e n> bit_subrange_size_opt bit_subrange_size441 %type<expr> bit_subrange_size_opt bit_subrange_size 442 442 443 443 %type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type indirect_type … … 452 452 453 453 %type<decl> enumerator_list enum_type enum_type_nobody 454 %type<in> enumerator_value_opt 454 %type<init> enumerator_value_opt 455 456 %type<decl> value_list 457 %type<decl> data_constructor type_specifier_list 455 458 456 459 %type<decl> external_definition external_definition_list external_definition_list_opt … … 459 462 460 463 %type<decl> field_declaration_list_opt field_declaration field_declaring_list_opt field_declarator field_abstract_list_opt field_abstract 461 %type<e n> field field_name_list field_name fraction_constants_opt464 %type<expr> field field_name_list field_name fraction_constants_opt 462 465 463 466 %type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr … … 508 511 %type<decl> type_parameter type_parameter_list type_initializer_opt 509 512 510 %type<e n> type_parameters_opt type_list array_type_list513 %type<expr> type_parameters_opt type_list array_type_list 511 514 512 515 %type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list … … 519 522 520 523 // initializers 521 %type<in > initializer initializer_list_opt initializer_opt524 %type<init> initializer initializer_list_opt initializer_opt 522 525 523 526 // designators 524 %type<e n> designator designator_list designation527 %type<expr> designator designator_list designation 525 528 526 529 … … 644 647 645 648 string_literal: 646 string_literal_list { $$ = build_constantStr( yylloc, *$1); }649 string_literal_list { $$ = new ExpressionNode( build_constantStr( yylloc, *$1 ) ); } 647 650 ; 648 651 … … 739 742 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, $3 ) ); } 740 743 | string_literal '[' assignment_expression ']' // "abc"[3], 3["abc"] 741 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, new ExpressionNode( $1 ), $3 ) ); }744 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, $3 ) ); } 742 745 | postfix_expression '{' argument_expression_list_opt '}' // CFA, constructor call 743 746 { … … 757 760 { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), $1 ) ); } 758 761 | string_literal '`' identifier // CFA, postfix call 759 { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), new ExpressionNode( $1 )) ); }762 { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), $1 ) ); } 760 763 | postfix_expression '.' identifier 761 764 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); } … … 857 860 | constant 858 861 | string_literal 859 { $$ = new ExpressionNode( $1 ); }862 { $$ = $1; } 860 863 | EXTENSION cast_expression // GCC 861 864 { $$ = $2->set_extension( true ); } … … 1260 1263 1261 1264 case_value_list: // CFA 1262 case_value { $$ = new StatementNode( build_case($1 ) ); }1265 case_value { $$ = new ClauseNode( build_case( yylloc, $1 ) ); } 1263 1266 // convert case list, e.g., "case 1, 3, 5:" into "case 1: case 3: case 5" 1264 | case_value_list ',' case_value { $$ = (StatementNode *)($1->set_last( new StatementNode( build_case( $3 )) ) ); }1267 | case_value_list ',' case_value { $$ = $1->set_last( new ClauseNode( build_case( yylloc, $3 ) ) ); } 1265 1268 ; 1266 1269 … … 1271 1274 | CASE case_value_list error // syntax error 1272 1275 { SemanticError( yylloc, "Missing colon after case list." ); $$ = nullptr; } 1273 | DEFAULT ':' { $$ = new StatementNode( build_default( yylloc ) ); }1276 | DEFAULT ':' { $$ = new ClauseNode( build_default( yylloc ) ); } 1274 1277 // A semantic check is required to ensure only one default clause per switch/choose statement. 1275 1278 | DEFAULT error // syntax error … … 1279 1282 case_label_list: // CFA 1280 1283 case_label 1281 | case_label_list case_label { $$ = (StatementNode *)( $1->set_last( $2 )); }1284 | case_label_list case_label { $$ = $1->set_last( $2 ); } 1282 1285 ; 1283 1286 … … 1296 1299 { $$ = $1->append_last_case( new StatementNode( build_compound( yylloc, $2 ) ) ); } 1297 1300 | switch_clause_list case_label_list statement_list_nodecl 1298 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( yylloc, $3 )) ) ) ); }1301 { $$ = $1->set_last( $2->append_last_case( new StatementNode( build_compound( yylloc, $3 ) ) ) ); } 1299 1302 ; 1300 1303 … … 1685 1688 waituntil_clause: 1686 1689 when_clause_opt waituntil statement 1687 { $$ = build_waituntil_clause( yylloc, $1, $2, maybe_build_compound( yylloc, $3 ) ); }1690 { printf( "waituntil_clause 1\n" ); $$ = nullptr; } 1688 1691 | '(' wor_waituntil_clause ')' 1689 { $$ = $2; }1692 { printf( "waituntil_clause 2\n" ); $$ = nullptr; } 1690 1693 ; 1691 1694 1692 1695 wand_waituntil_clause: 1693 1696 waituntil_clause %prec THEN 1694 { $$ = $1; }1697 { printf( "wand_waituntil_clause 1\n" ); $$ = nullptr; } 1695 1698 | waituntil_clause wand wand_waituntil_clause 1696 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::AND, $1, $3 ); }1699 { printf( "wand_waituntil_clause 2\n" ); $$ = nullptr; } 1697 1700 ; 1698 1701 1699 1702 wor_waituntil_clause: 1700 1703 wand_waituntil_clause 1701 { $$ = $1; }1704 { printf( "wor_waituntil_clause 1\n" ); $$ = nullptr; } 1702 1705 | wor_waituntil_clause wor wand_waituntil_clause 1703 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::OR, $1, $3 ); }1706 { printf( "wor_waituntil_clause 2\n" ); $$ = nullptr; } 1704 1707 | wor_waituntil_clause wor when_clause_opt ELSE statement 1705 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1, build_waituntil_else( yylloc, $3, maybe_build_compound( yylloc, $5 ) ) ); }1708 { printf( "wor_waituntil_clause 3\n" ); $$ = nullptr; } 1706 1709 | wor_waituntil_clause wor when_clause_opt timeout statement %prec THEN 1707 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1, build_waituntil_timeout( yylloc, $3, $4, maybe_build_compound( yylloc, $5 ) ) ); }1710 { printf( "wor_waituntil_clause 4\n" ); $$ = nullptr; } 1708 1711 // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless) 1709 1712 | wor_waituntil_clause wor when_clause_opt timeout statement wor ELSE statement // syntax error 1710 1713 { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; } 1711 1714 | wor_waituntil_clause wor when_clause_opt timeout statement wor when_clause ELSE statement 1712 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1, 1713 new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::OR, 1714 build_waituntil_timeout( yylloc, $3, $4, maybe_build_compound( yylloc, $5 ) ), 1715 build_waituntil_else( yylloc, $7, maybe_build_compound( yylloc, $9 ) ) ) ); } 1715 { printf( "wor_waituntil_clause 6\n" ); $$ = nullptr; } 1716 1716 ; 1717 1717 … … 1719 1719 wor_waituntil_clause %prec THEN 1720 1720 // SKULLDUGGERY: create an empty compound statement to test parsing of waituntil statement. 1721 { 1722 $$ = new StatementNode( build_waituntil_stmt( yylloc, $1 ) ); 1723 // $$ = new StatementNode( build_compound( yylloc, nullptr ) ); 1724 } 1721 { $$ = new StatementNode( build_compound( yylloc, nullptr ) ); } 1725 1722 ; 1726 1723 … … 1736 1733 handler_clause: 1737 1734 handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement 1738 { $$ = new StatementNode( build_catch( yylloc, $1, $4, $6, $8 ) ); }1735 { $$ = new ClauseNode( build_catch( yylloc, $1, $4, $6, $8 ) ); } 1739 1736 | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement 1740 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( yylloc, $2, $5, $7, $9 ) ) ); }1737 { $$ = $1->set_last( new ClauseNode( build_catch( yylloc, $2, $5, $7, $9 ) ) ); } 1741 1738 ; 1742 1739 … … 1755 1752 1756 1753 finally_clause: 1757 FINALLY compound_statement { $$ = new StatementNode( build_finally( yylloc, $2 ) ); }1754 FINALLY compound_statement { $$ = new ClauseNode( build_finally( yylloc, $2 ) ); } 1758 1755 ; 1759 1756 … … 1813 1810 asm_operand: // GCC 1814 1811 string_literal '(' constant_expression ')' 1815 { $$ = new ExpressionNode( new ast::AsmExpr( yylloc, "", $1, maybeMoveBuild( $3 ) ) ); }1812 { $$ = new ExpressionNode( new ast::AsmExpr( yylloc, "", maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); } 1816 1813 | '[' IDENTIFIER ']' string_literal '(' constant_expression ')' 1817 1814 { 1818 $$ = new ExpressionNode( new ast::AsmExpr( yylloc, *$2.str, $4, maybeMoveBuild( $6 ) ) );1815 $$ = new ExpressionNode( new ast::AsmExpr( yylloc, *$2.str, maybeMoveBuild( $4 ), maybeMoveBuild( $6 ) ) ); 1819 1816 delete $2.str; 1820 1817 } … … 1825 1822 { $$ = nullptr; } // use default argument 1826 1823 | string_literal 1827 { $$ = new ExpressionNode( $1 ); }1824 { $$ = $1; } 1828 1825 | asm_clobbers_list_opt ',' string_literal 1829 { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( $3 ) )); }1826 { $$ = (ExpressionNode *)( $1->set_last( $3 ) ); } 1830 1827 ; 1831 1828 … … 1899 1896 static_assert: 1900 1897 STATICASSERT '(' constant_expression ',' string_literal ')' ';' // C11 1901 { $$ = DeclarationNode::newStaticAssert( $3, $5); }1898 { $$ = DeclarationNode::newStaticAssert( $3, maybeMoveBuild( $5 ) ); } 1902 1899 | STATICASSERT '(' constant_expression ')' ';' // CFA 1903 1900 { $$ = DeclarationNode::newStaticAssert( $3, build_constantStr( yylloc, *new string( "\"\"" ) ) ); } … … 2447 2444 } 2448 2445 | enum_type 2446 /* | algebric_data_type */ 2449 2447 ; 2450 2448 … … 2685 2683 $$ = DeclarationNode::newEnum( nullptr, $7, true, true, $3 )->addQualifiers( $5 ); 2686 2684 } 2687 | ENUM '(' ')' attribute_list_opt '{' enumerator_list comma_opt '}'2688 {2689 $$ = DeclarationNode::newEnum( nullptr, $6, true, true )->addQualifiers( $4 );2690 }2691 2685 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt 2692 2686 { … … 2698 2692 $$ = DeclarationNode::newEnum( $6, $11, true, true, $3, $9 )->addQualifiers( $5 )->addQualifiers( $7 ); 2699 2693 } 2700 | ENUM '(' ')' attribute_list_opt identifier attribute_list_opt2701 hide_opt '{' enumerator_list comma_opt '}'2702 {2703 $$ = DeclarationNode::newEnum( $5, $9, true, true, nullptr, $7 )->addQualifiers( $4 )->addQualifiers( $6 );2704 }2705 2694 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt 2706 2695 hide_opt '{' enumerator_list comma_opt '}' … … 2708 2697 $$ = DeclarationNode::newEnum( $6->name, $10, true, true, $3, $8 )->addQualifiers( $5 )->addQualifiers( $7 ); 2709 2698 } 2710 | ENUM '(' ')' attribute_list_opt typedef_name attribute_list_opt2711 hide_opt '{' enumerator_list comma_opt '}'2712 {2713 $$ = DeclarationNode::newEnum( $5->name, $9, true, true, nullptr, $7 )->addQualifiers( $4 )->addQualifiers( $6 );2714 }2715 2699 | enum_type_nobody 2716 ; 2700 | DATA identifier 2701 { typedefTable.makeTypedef( *$2 ); } 2702 '{' value_list '}' 2703 { 2704 $$ = DeclarationNode::newAdt( $2, $5 ); 2705 } 2706 ; 2707 2708 value_list: 2709 data_constructor 2710 { 2711 $$ = $1; 2712 } 2713 /* | identifier_or_type_name '(' type_specifier ')' 2714 { 2715 $$ = DeclarationNode::newEnumValueGeneric( $1, nullptr ); 2716 } */ 2717 /* | data_constructor '|' value_list */ 2718 | value_list '|' data_constructor 2719 { 2720 { $$ = $1->appendList( $3 ); } 2721 } 2722 ; 2723 2724 data_constructor: 2725 identifier_or_type_name 2726 { 2727 typedefTable.makeTypedef( *$1 ); 2728 $$ = DeclarationNode::newTypeDecl( $1, nullptr );; 2729 } 2730 | identifier_or_type_name '(' type_specifier_list ')' 2731 { 2732 typedefTable.makeTypedef( *$1 ); 2733 $$ = DeclarationNode::newTypeDecl( $1, $3 ); 2734 } 2735 2736 type_specifier_list: 2737 type_specifier 2738 /* | type_specifier ',' type_specifier_list */ 2739 | type_specifier_list ',' type_specifier 2740 { 2741 $$ = $1->appendList($3); 2742 } 2743 ; 2744 2717 2745 2718 2746 hide_opt: … … 2824 2852 2825 2853 cfa_abstract_parameter_declaration: // CFA, new & old style parameter declaration 2826 abstract_parameter_declaration 2854 // empty 2855 { $$ = nullptr; } 2856 | abstract_parameter_declaration 2827 2857 | cfa_identifier_parameter_declarator_no_tuple 2828 2858 | cfa_abstract_tuple … … 3329 3359 { 3330 3360 DeclarationNode * name = new DeclarationNode(); 3331 name->asmName = $3;3361 name->asmName = maybeMoveBuild( $3 ); 3332 3362 $$ = name->addQualifiers( $5 ); 3333 3363 }
Note:
See TracChangeset
for help on using the changeset viewer.