Changes in src/Parser/parser.yy [c744563a:f1da02c]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (29 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
rc744563a rf1da02c 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Feb 21 14:47:29 202013 // Update Count : 4 46812 // Last Modified On : Sun Aug 4 21:48:23 2019 13 // Update Count : 4364 14 14 // 15 15 … … 51 51 using namespace std; 52 52 53 #include "SynTree/Declaration.h"54 53 #include "ParseNode.h" 55 54 #include "TypedefTable.h" 56 55 #include "TypeData.h" 57 #include " SynTree/LinkageSpec.h"56 #include "LinkageSpec.h" 58 57 #include "Common/SemanticError.h" // error_str 59 58 #include "Common/utility.h" // for maybeMoveBuild, maybeBuild, CodeLo... … … 166 165 } // rebindForall 167 166 168 string * build_postfix_name( string * name ) { 169 *name = string("__postfix_func_") + *name; 170 return name; 167 NameExpr * build_postfix_name( const string * name ) { 168 NameExpr * new_name = build_varref( new string( "?`" + *name ) ); 169 delete name; 170 return new_name; 171 171 } // build_postfix_name 172 172 … … 210 210 } // if 211 211 } // forCtrl 212 212 213 213 214 bool forall = false, yyy = false; // aggregate have one or more forall qualifiers ? … … 236 237 ExpressionNode * en; 237 238 DeclarationNode * decl; 238 AggregateDecl::Aggregate aggKey;239 TypeDecl::Kindtclass;239 DeclarationNode::Aggregate aggKey; 240 DeclarationNode::TypeClass tclass; 240 241 StatementNode * sn; 241 242 WaitForStmt * wfs; … … 322 323 %type<op> ptrref_operator unary_operator assignment_operator 323 324 %type<en> primary_expression postfix_expression unary_expression 324 %type<en> cast_expression _list cast_expressionexponential_expression multiplicative_expression additive_expression325 %type<en> cast_expression exponential_expression multiplicative_expression additive_expression 325 326 %type<en> shift_expression relational_expression equality_expression 326 327 %type<en> AND_expression exclusive_OR_expression inclusive_OR_expression … … 364 365 %type<decl> abstract_parameter_declaration 365 366 366 %type<aggKey> aggregate_key aggregate_data aggregate_control367 %type<aggKey> aggregate_key 367 368 %type<decl> aggregate_type aggregate_type_nobody 368 369 … … 578 579 | '(' compound_statement ')' // GCC, lambda expression 579 580 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >($2) ) ) ); } 581 | constant '`' IDENTIFIER // CFA, postfix call 582 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), $1 ) ); } 583 | string_literal '`' IDENTIFIER // CFA, postfix call 584 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), new ExpressionNode( $1 ) ) ); } 585 | IDENTIFIER '`' IDENTIFIER // CFA, postfix call 586 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), new ExpressionNode( build_varref( $1 ) ) ) ); } 587 | tuple '`' IDENTIFIER // CFA, postfix call 588 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), $1 ) ); } 589 | '(' comma_expression ')' '`' IDENTIFIER // CFA, postfix call 590 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); } 580 591 | type_name '.' identifier // CFA, nested type 581 592 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } … … 631 642 | postfix_expression '(' argument_expression_list ')' 632 643 { $$ = new ExpressionNode( build_func( $1, $3 ) ); } 633 | postfix_expression '`' identifier // CFA, postfix call634 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), $1 ) ); }635 | constant '`' identifier // CFA, postfix call636 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), $1 ) ); }637 | string_literal '`' identifier // CFA, postfix call638 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), new ExpressionNode( $1 ) ) ); }639 644 | postfix_expression '.' identifier 640 645 { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); } … … 645 650 | postfix_expression '.' '[' field_name_list ']' // CFA, tuple field selector 646 651 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); } 647 | postfix_expression '.' aggregate_control648 { $$ = new ExpressionNode( build_keyword_cast( $3, $1 ) ); }649 652 | postfix_expression ARROW identifier 650 653 { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) ) ); } … … 661 664 | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal 662 665 { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); } 663 | '^' primary_expression '{' argument_expression_list '}' // CFA , destructor call666 | '^' primary_expression '{' argument_expression_list '}' // CFA 664 667 { 665 668 Token fn; … … 674 677 | argument_expression 675 678 | argument_expression_list ',' argument_expression 676 { $$ = (ExpressionNode *)( $1->set_last( $3 )); }679 { $$ = (ExpressionNode *)( $1->set_last( $3 )); } 677 680 ; 678 681 … … 686 689 field_name_list: // CFA, tuple field selector 687 690 field 688 | field_name_list ',' field { $$ = (ExpressionNode *) ($1->set_last( $3 )); }691 | field_name_list ',' field { $$ = (ExpressionNode *)$1->set_last( $3 ); } 689 692 ; 690 693 … … 790 793 | '(' type_no_function ')' cast_expression 791 794 { $$ = new ExpressionNode( build_cast( $2, $4 ) ); } 792 | '(' aggregate_control '&' ')' cast_expression // CFA 793 { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); } 795 // keyword cast cannot be grouped because of reduction in aggregate_key 796 | '(' GENERATOR '&' ')' cast_expression // CFA 797 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); } 798 | '(' COROUTINE '&' ')' cast_expression // CFA 799 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); } 800 | '(' THREAD '&' ')' cast_expression // CFA 801 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Thread, $5 ) ); } 802 | '(' MONITOR '&' ')' cast_expression // CFA 803 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Monitor, $5 ) ); } 794 804 // VIRTUAL cannot be opt because of look ahead issues 795 805 | '(' VIRTUAL ')' cast_expression // CFA … … 955 965 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); } 956 966 | '[' push assignment_expression pop ',' tuple_expression_list ']' 957 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *) ($3->set_last( $6 ) ) )); }967 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $6 ) ) ); } 958 968 ; 959 969 … … 961 971 assignment_expression_opt 962 972 | tuple_expression_list ',' assignment_expression_opt 963 { $$ = (ExpressionNode *) ($1->set_last( $3 )); }973 { $$ = (ExpressionNode *)$1->set_last( $3 ); } 964 974 ; 965 975 … … 1185 1195 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1186 1196 OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1187 | '=' comma_expression // CFA1188 { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),1189 OperKinds::LEThan, $2->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }1190 1197 | comma_expression inclexcl comma_expression // CFA 1191 1198 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } … … 1195 1202 { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1196 1203 OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1197 | comma_expression ';' '=' comma_expression // CFA1198 { $$ = forCtrl( $4, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),1199 OperKinds::LEThan, $4->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }1200 1204 | comma_expression ';' comma_expression inclexcl comma_expression // CFA 1201 1205 { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } … … 1302 1306 WAITFOR '(' cast_expression ')' 1303 1307 { $$ = $3; } 1304 // | WAITFOR '(' cast_expression ',' argument_expression_list ')' 1305 // { $$ = (ExpressionNode *)$3->set_last( $5 ); } 1306 | WAITFOR '(' cast_expression_list ':' argument_expression_list ')' 1307 { $$ = (ExpressionNode *)($3->set_last( $5 )); } 1308 ; 1309 1310 cast_expression_list: 1311 cast_expression 1312 | cast_expression_list ',' cast_expression 1313 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 1308 | WAITFOR '(' cast_expression ',' argument_expression_list ')' 1309 { $$ = (ExpressionNode *)$3->set_last( $5 ); } 1314 1310 ; 1315 1311 … … 1422 1418 asm_operand 1423 1419 | asm_operands_list ',' asm_operand 1424 { $$ = (ExpressionNode *) ($1->set_last( $3 )); }1420 { $$ = (ExpressionNode *)$1->set_last( $3 ); } 1425 1421 ; 1426 1422 1427 1423 asm_operand: // GCC 1428 1424 string_literal '(' constant_expression ')' 1429 { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild< Expression >( $3 ) ) ); }1430 | '[' IDENTIFIER']' string_literal '(' constant_expression ')'1431 { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild< Expression >( $6 ) ) ); }1425 { $$ = new ExpressionNode( new AsmExpr( maybeMoveBuild< Expression >( (ExpressionNode *)nullptr ), $1, maybeMoveBuild< Expression >( $3 ) ) ); } 1426 | '[' constant_expression ']' string_literal '(' constant_expression ')' 1427 { $$ = new ExpressionNode( new AsmExpr( maybeMoveBuild< Expression >( $2 ), $4, maybeMoveBuild< Expression >( $6 ) ) ); } 1432 1428 ; 1433 1429 … … 1438 1434 { $$ = new ExpressionNode( $1 ); } 1439 1435 | asm_clobbers_list_opt ',' string_literal 1440 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( $3 ) )); } 1436 // set_last returns ParseNode * 1437 { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); } 1441 1438 ; 1442 1439 … … 1589 1586 // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be 1590 1587 // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name. 1591 cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt1588 cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' 1592 1589 // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator). 1593 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ) ->addQualifiers( $8 ); }1594 | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt1595 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ) ->addQualifiers( $8 ); }1590 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); } 1591 | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' 1592 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); } 1596 1593 ; 1597 1594 … … 2062 2059 2063 2060 aggregate_key: 2064 aggregate_data2065 | aggregate_control2066 ;2067 2068 aggregate_data:2069 2061 STRUCT 2070 { yyy = true; $$ = AggregateDecl::Struct; }2062 { yyy = true; $$ = DeclarationNode::Struct; } 2071 2063 | UNION 2072 { yyy = true; $$ = AggregateDecl::Union; } 2073 | EXCEPTION // CFA 2074 { yyy = true; $$ = AggregateDecl::Exception; } 2075 ; 2076 2077 aggregate_control: // CFA 2078 GENERATOR 2079 { yyy = true; $$ = AggregateDecl::Coroutine; } 2064 { yyy = true; $$ = DeclarationNode::Union; } 2065 | EXCEPTION 2066 { yyy = true; $$ = DeclarationNode::Exception; } 2067 | GENERATOR 2068 { yyy = true; $$ = DeclarationNode::Coroutine; } 2080 2069 | COROUTINE 2081 { yyy = true; $$ = AggregateDecl::Coroutine; }2070 { yyy = true; $$ = DeclarationNode::Coroutine; } 2082 2071 | MONITOR 2083 { yyy = true; $$ = AggregateDecl::Monitor; }2072 { yyy = true; $$ = DeclarationNode::Monitor; } 2084 2073 | THREAD 2085 { yyy = true; $$ = AggregateDecl::Thread; }2074 { yyy = true; $$ = DeclarationNode::Thread; } 2086 2075 ; 2087 2076 … … 2107 2096 distInl( $3 ); 2108 2097 } 2109 | INLINE aggregate_control ';' // CFA2110 { SemanticError( yylloc, "INLINE aggregate control currently unimplemented." ); $$ = nullptr; }2111 2098 | typedef_declaration ';' // CFA 2112 2099 | cfa_field_declaring_list ';' // CFA, new style field declaration … … 2361 2348 | initializer_list_opt ',' initializer { $$ = (InitializerNode *)( $1->set_last( $3 ) ); } 2362 2349 | initializer_list_opt ',' designation initializer 2363 { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) )); }2350 { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) ) ); } 2364 2351 ; 2365 2352 … … 2383 2370 designator 2384 2371 | designator_list designator 2385 { $$ = (ExpressionNode *)( $1->set_last( $2 )); }2372 { $$ = (ExpressionNode *)( $1->set_last( $2 ) ); } 2386 2373 //| designator_list designator { $$ = new ExpressionNode( $1, $2 ); } 2387 2374 ; … … 2439 2426 | type_specifier identifier_parameter_declarator 2440 2427 | assertion_list 2441 { $$ = DeclarationNode::newTypeParam( TypeDecl::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }2428 { $$ = DeclarationNode::newTypeParam( DeclarationNode::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); } 2442 2429 ; 2443 2430 2444 2431 type_class: // CFA 2445 2432 OTYPE 2446 { $$ = TypeDecl::Otype; }2433 { $$ = DeclarationNode::Otype; } 2447 2434 | DTYPE 2448 { $$ = TypeDecl::Dtype; }2435 { $$ = DeclarationNode::Dtype; } 2449 2436 | FTYPE 2450 { $$ = TypeDecl::Ftype; }2437 { $$ = DeclarationNode::Ftype; } 2451 2438 | TTYPE 2452 { $$ = TypeDecl::Ttype; }2439 { $$ = DeclarationNode::Ttype; } 2453 2440 ; 2454 2441 … … 2480 2467 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $1->build()) ); $$ = nullptr; } 2481 2468 | type_list ',' type 2482 { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) )); }2469 { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) ) ); } 2483 2470 | type_list ',' assignment_expression 2484 2471 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $3->build()) ); $$ = nullptr; } … … 2591 2578 { 2592 2579 linkageStack.push( linkage ); // handle nested extern "C"/"Cforall" 2593 linkage = LinkageSpec:: update( yylloc, linkage, $2 );2580 linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 ); 2594 2581 } 2595 2582 '{' up external_definition_list_opt down '}'
Note:
See TracChangeset
for help on using the changeset viewer.