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