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