Changes in src/Parser/parser.yy [9867cdb:665f432]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
r9867cdb r665f432 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 6 17:26:45 202013 // Update Count : 4 47412 // 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 … … 918 928 conditional_expression 919 929 | unary_expression assignment_operator assignment_expression 920 { 921 if ( $2 == OperKinds::AtAssn ) { 922 SemanticError( yylloc, "C @= assignment is currently unimplemented." ); $$ = nullptr; 923 } else { 924 $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); 925 } // if 926 } 930 { $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); } 927 931 | unary_expression '=' '{' initializer_list_opt comma_opt '}' 928 932 { SemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; } … … 961 965 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); } 962 966 | '[' push assignment_expression pop ',' tuple_expression_list ']' 963 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *) ($3->set_last( $6 ) ) )); }967 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $6 ) ) ); } 964 968 ; 965 969 … … 967 971 assignment_expression_opt 968 972 | tuple_expression_list ',' assignment_expression_opt 969 { $$ = (ExpressionNode *) ($1->set_last( $3 )); }973 { $$ = (ExpressionNode *)$1->set_last( $3 ); } 970 974 ; 971 975 … … 1191 1195 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1192 1196 OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1193 | '=' comma_expression // CFA1194 { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),1195 OperKinds::LEThan, $2->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }1196 1197 | comma_expression inclexcl comma_expression // CFA 1197 1198 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } … … 1201 1202 { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1202 1203 OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1203 | comma_expression ';' '=' comma_expression // CFA1204 { $$ = forCtrl( $4, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),1205 OperKinds::LEThan, $4->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }1206 1204 | comma_expression ';' comma_expression inclexcl comma_expression // CFA 1207 1205 { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } … … 1308 1306 WAITFOR '(' cast_expression ')' 1309 1307 { $$ = $3; } 1310 // | WAITFOR '(' cast_expression ',' argument_expression_list ')' 1311 // { $$ = (ExpressionNode *)$3->set_last( $5 ); } 1312 | WAITFOR '(' cast_expression_list ':' argument_expression_list ')' 1313 { $$ = (ExpressionNode *)($3->set_last( $5 )); } 1314 ; 1315 1316 cast_expression_list: 1317 cast_expression 1318 | cast_expression_list ',' cast_expression 1319 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 1308 | WAITFOR '(' cast_expression ',' argument_expression_list ')' 1309 { $$ = (ExpressionNode *)$3->set_last( $5 ); } 1320 1310 ; 1321 1311 … … 1428 1418 asm_operand 1429 1419 | asm_operands_list ',' asm_operand 1430 { $$ = (ExpressionNode *) ($1->set_last( $3 )); }1420 { $$ = (ExpressionNode *)$1->set_last( $3 ); } 1431 1421 ; 1432 1422 … … 1444 1434 { $$ = new ExpressionNode( $1 ); } 1445 1435 | asm_clobbers_list_opt ',' string_literal 1446 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( $3 ) )); } 1436 // set_last returns ParseNode * 1437 { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); } 1447 1438 ; 1448 1439 … … 1595 1586 // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be 1596 1587 // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name. 1597 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 ')' 1598 1589 // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator). 1599 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ) ->addQualifiers( $8 ); }1600 | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt1601 { $$ = 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 ); } 1602 1593 ; 1603 1594 … … 2068 2059 2069 2060 aggregate_key: 2070 aggregate_data2071 | aggregate_control2072 ;2073 2074 aggregate_data:2075 2061 STRUCT 2076 { yyy = true; $$ = AggregateDecl::Struct; }2062 { yyy = true; $$ = DeclarationNode::Struct; } 2077 2063 | UNION 2078 { yyy = true; $$ = AggregateDecl::Union; } 2079 | EXCEPTION // CFA 2080 { yyy = true; $$ = AggregateDecl::Exception; } 2081 ; 2082 2083 aggregate_control: // CFA 2084 GENERATOR 2085 { SemanticError( yylloc, "generator is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2086 | MONITOR GENERATOR 2087 { SemanticError( yylloc, "monitor generator is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2064 { yyy = true; $$ = DeclarationNode::Union; } 2065 | EXCEPTION 2066 { yyy = true; $$ = DeclarationNode::Exception; } 2067 | GENERATOR 2068 { yyy = true; $$ = DeclarationNode::Coroutine; } 2088 2069 | COROUTINE 2089 { yyy = true; $$ = AggregateDecl::Coroutine; }2070 { yyy = true; $$ = DeclarationNode::Coroutine; } 2090 2071 | MONITOR 2091 { yyy = true; $$ = AggregateDecl::Monitor; } 2092 | MONITOR COROUTINE 2093 { SemanticError( yylloc, "monitor coroutine is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2072 { yyy = true; $$ = DeclarationNode::Monitor; } 2094 2073 | THREAD 2095 { yyy = true; $$ = AggregateDecl::Thread; } 2096 | MONITOR THREAD 2097 { SemanticError( yylloc, "monitor thread is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2074 { yyy = true; $$ = DeclarationNode::Thread; } 2098 2075 ; 2099 2076 … … 2119 2096 distInl( $3 ); 2120 2097 } 2121 | INLINE aggregate_control ';' // CFA2122 { SemanticError( yylloc, "INLINE aggregate control currently unimplemented." ); $$ = nullptr; }2123 2098 | typedef_declaration ';' // CFA 2124 2099 | cfa_field_declaring_list ';' // CFA, new style field declaration … … 2373 2348 | initializer_list_opt ',' initializer { $$ = (InitializerNode *)( $1->set_last( $3 ) ); } 2374 2349 | initializer_list_opt ',' designation initializer 2375 { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) )); }2350 { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) ) ); } 2376 2351 ; 2377 2352 … … 2395 2370 designator 2396 2371 | designator_list designator 2397 { $$ = (ExpressionNode *)( $1->set_last( $2 )); }2372 { $$ = (ExpressionNode *)( $1->set_last( $2 ) ); } 2398 2373 //| designator_list designator { $$ = new ExpressionNode( $1, $2 ); } 2399 2374 ; … … 2451 2426 | type_specifier identifier_parameter_declarator 2452 2427 | assertion_list 2453 { $$ = DeclarationNode::newTypeParam( TypeDecl::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }2428 { $$ = DeclarationNode::newTypeParam( DeclarationNode::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); } 2454 2429 ; 2455 2430 2456 2431 type_class: // CFA 2457 2432 OTYPE 2458 { $$ = TypeDecl::Otype; }2433 { $$ = DeclarationNode::Otype; } 2459 2434 | DTYPE 2460 { $$ = TypeDecl::Dtype; }2435 { $$ = DeclarationNode::Dtype; } 2461 2436 | FTYPE 2462 { $$ = TypeDecl::Ftype; }2437 { $$ = DeclarationNode::Ftype; } 2463 2438 | TTYPE 2464 { $$ = TypeDecl::Ttype; }2439 { $$ = DeclarationNode::Ttype; } 2465 2440 ; 2466 2441 … … 2492 2467 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $1->build()) ); $$ = nullptr; } 2493 2468 | type_list ',' type 2494 { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) )); }2469 { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) ) ); } 2495 2470 | type_list ',' assignment_expression 2496 2471 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $3->build()) ); $$ = nullptr; } … … 2603 2578 { 2604 2579 linkageStack.push( linkage ); // handle nested extern "C"/"Cforall" 2605 linkage = LinkageSpec:: update( yylloc, linkage, $2 );2580 linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 ); 2606 2581 } 2607 2582 '{' up external_definition_list_opt down '}'
Note:
See TracChangeset
for help on using the changeset viewer.