Changeset 7030dab for src/Parser/parser.yy
- Timestamp:
- Apr 6, 2020, 4:46:28 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- e3bc51c
- Parents:
- 71d6bd8 (diff), 057298e (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
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
r71d6bd8 r7030dab 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 Mar 6 17:26:45 2020 13 // Update Count : 4474 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; … … 279 278 %token OTYPE FTYPE DTYPE TTYPE TRAIT // CFA 280 279 %token SIZEOF OFFSETOF 281 // %token SUSPEND RESUME // CFA 280 // %token RESUME // CFA 281 %token SUSPEND // CFA 282 282 %token ATTRIBUTE EXTENSION // GCC 283 283 %token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN … … 323 323 %type<op> ptrref_operator unary_operator assignment_operator 324 324 %type<en> primary_expression postfix_expression unary_expression 325 %type<en> cast_expression exponential_expression multiplicative_expression additive_expression325 %type<en> cast_expression_list cast_expression exponential_expression multiplicative_expression additive_expression 326 326 %type<en> shift_expression relational_expression equality_expression 327 327 %type<en> AND_expression exclusive_OR_expression inclusive_OR_expression … … 365 365 %type<decl> abstract_parameter_declaration 366 366 367 %type<aggKey> aggregate_key 367 %type<aggKey> aggregate_key aggregate_data aggregate_control 368 368 %type<decl> aggregate_type aggregate_type_nobody 369 369 … … 579 579 | '(' compound_statement ')' // GCC, lambda expression 580 580 { $$ = 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 581 | type_name '.' identifier // CFA, nested type 592 582 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } … … 642 632 | postfix_expression '(' argument_expression_list ')' 643 633 { $$ = new ExpressionNode( build_func( $1, $3 ) ); } 634 | postfix_expression '`' identifier // CFA, postfix call 635 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), $1 ) ); } 636 | constant '`' identifier // CFA, postfix call 637 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), $1 ) ); } 638 | string_literal '`' identifier // CFA, postfix call 639 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), new ExpressionNode( $1 ) ) ); } 644 640 | postfix_expression '.' identifier 645 641 { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); } … … 650 646 | postfix_expression '.' '[' field_name_list ']' // CFA, tuple field selector 651 647 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); } 648 | postfix_expression '.' aggregate_control 649 { $$ = new ExpressionNode( build_keyword_cast( $3, $1 ) ); } 652 650 | postfix_expression ARROW identifier 653 651 { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) ) ); } … … 664 662 | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal 665 663 { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); } 666 | '^' primary_expression '{' argument_expression_list '}' // CFA 664 | '^' primary_expression '{' argument_expression_list '}' // CFA, destructor call 667 665 { 668 666 Token fn; … … 677 675 | argument_expression 678 676 | argument_expression_list ',' argument_expression 679 { $$ = (ExpressionNode *)( 677 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 680 678 ; 681 679 … … 689 687 field_name_list: // CFA, tuple field selector 690 688 field 691 | field_name_list ',' field { $$ = (ExpressionNode *) $1->set_last( $3); }689 | field_name_list ',' field { $$ = (ExpressionNode *)($1->set_last( $3 )); } 692 690 ; 693 691 … … 793 791 | '(' type_no_function ')' cast_expression 794 792 { $$ = 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 ) ); } 793 | '(' aggregate_control '&' ')' cast_expression // CFA 794 { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); } 804 795 // VIRTUAL cannot be opt because of look ahead issues 805 796 | '(' VIRTUAL ')' cast_expression // CFA … … 928 919 conditional_expression 929 920 | unary_expression assignment_operator assignment_expression 930 { $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); } 921 { 922 if ( $2 == OperKinds::AtAssn ) { 923 SemanticError( yylloc, "C @= assignment is currently unimplemented." ); $$ = nullptr; 924 } else { 925 $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); 926 } // if 927 } 931 928 | unary_expression '=' '{' initializer_list_opt comma_opt '}' 932 929 { SemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; } … … 965 962 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); } 966 963 | '[' push assignment_expression pop ',' tuple_expression_list ']' 967 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *) $3->set_last( $6 ) )); }964 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)($3->set_last( $6 ) ) )); } 968 965 ; 969 966 … … 971 968 assignment_expression_opt 972 969 | tuple_expression_list ',' assignment_expression_opt 973 { $$ = (ExpressionNode *) $1->set_last( $3); }970 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 974 971 ; 975 972 … … 1195 1192 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1196 1193 OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1194 | '=' comma_expression // CFA 1195 { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1196 OperKinds::LEThan, $2->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1197 1197 | comma_expression inclexcl comma_expression // CFA 1198 1198 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } … … 1202 1202 { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1203 1203 OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1204 | comma_expression ';' '=' comma_expression // CFA 1205 { $$ = forCtrl( $4, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1206 OperKinds::LEThan, $4->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1204 1207 | comma_expression ';' comma_expression inclexcl comma_expression // CFA 1205 1208 { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } … … 1263 1266 | RETURN '{' initializer_list_opt comma_opt '}' ';' 1264 1267 { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; } 1265 // | SUSPEND ';' 1266 // { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; } 1267 // | SUSPEND compound_statement ';' 1268 // { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; } 1268 | SUSPEND ';' 1269 { $$ = new StatementNode( build_suspend( nullptr ) ); } 1270 | SUSPEND compound_statement 1271 { $$ = new StatementNode( build_suspend( $2 ) ); } 1272 | SUSPEND COROUTINE ';' 1273 { $$ = new StatementNode( build_suspend( nullptr, SuspendStmt::Coroutine ) ); } 1274 | SUSPEND COROUTINE compound_statement 1275 { $$ = new StatementNode( build_suspend( $3, SuspendStmt::Coroutine ) ); } 1276 | SUSPEND GENERATOR ';' 1277 { $$ = new StatementNode( build_suspend( nullptr, SuspendStmt::Generator ) ); } 1278 | SUSPEND GENERATOR compound_statement 1279 { $$ = new StatementNode( build_suspend( $3, SuspendStmt::Generator ) ); } 1269 1280 | THROW assignment_expression_opt ';' // handles rethrow 1270 1281 { $$ = new StatementNode( build_throw( $2 ) ); } … … 1306 1317 WAITFOR '(' cast_expression ')' 1307 1318 { $$ = $3; } 1308 | WAITFOR '(' cast_expression ',' argument_expression_list ')' 1309 { $$ = (ExpressionNode *)$3->set_last( $5 ); } 1319 // | WAITFOR '(' cast_expression ',' argument_expression_list ')' 1320 // { $$ = (ExpressionNode *)$3->set_last( $5 ); } 1321 | WAITFOR '(' cast_expression_list ':' argument_expression_list ')' 1322 { $$ = (ExpressionNode *)($3->set_last( $5 )); } 1323 ; 1324 1325 cast_expression_list: 1326 cast_expression 1327 | cast_expression_list ',' cast_expression 1328 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 1310 1329 ; 1311 1330 … … 1418 1437 asm_operand 1419 1438 | asm_operands_list ',' asm_operand 1420 { $$ = (ExpressionNode *) $1->set_last( $3); }1439 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 1421 1440 ; 1422 1441 … … 1434 1453 { $$ = new ExpressionNode( $1 ); } 1435 1454 | asm_clobbers_list_opt ',' string_literal 1436 // set_last returns ParseNode * 1437 { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); } 1455 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( $3 ) )); } 1438 1456 ; 1439 1457 … … 1586 1604 // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be 1587 1605 // 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 ')' 1606 cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt 1589 1607 // 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 ) ; }1608 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 )->addQualifiers( $8 ); } 1609 | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt 1610 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 )->addQualifiers( $8 ); } 1593 1611 ; 1594 1612 … … 2059 2077 2060 2078 aggregate_key: 2079 aggregate_data 2080 | aggregate_control 2081 ; 2082 2083 aggregate_data: 2061 2084 STRUCT 2062 { yyy = true; $$ = DeclarationNode::Struct; }2085 { yyy = true; $$ = AggregateDecl::Struct; } 2063 2086 | UNION 2064 { yyy = true; $$ = DeclarationNode::Union; } 2065 | EXCEPTION 2066 { yyy = true; $$ = DeclarationNode::Exception; } 2067 | GENERATOR 2068 { yyy = true; $$ = DeclarationNode::Coroutine; } 2087 { yyy = true; $$ = AggregateDecl::Union; } 2088 | EXCEPTION // CFA 2089 { yyy = true; $$ = AggregateDecl::Exception; } 2090 ; 2091 2092 aggregate_control: // CFA 2093 GENERATOR 2094 { yyy = true; $$ = AggregateDecl::Generator; } 2095 | MONITOR GENERATOR 2096 { SemanticError( yylloc, "monitor generator is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2069 2097 | COROUTINE 2070 { yyy = true; $$ = DeclarationNode::Coroutine; }2098 { yyy = true; $$ = AggregateDecl::Coroutine; } 2071 2099 | MONITOR 2072 { yyy = true; $$ = DeclarationNode::Monitor; } 2100 { yyy = true; $$ = AggregateDecl::Monitor; } 2101 | MONITOR COROUTINE 2102 { SemanticError( yylloc, "monitor coroutine is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2073 2103 | THREAD 2074 { yyy = true; $$ = DeclarationNode::Thread; } 2104 { yyy = true; $$ = AggregateDecl::Thread; } 2105 | MONITOR THREAD 2106 { SemanticError( yylloc, "monitor thread is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2075 2107 ; 2076 2108 … … 2096 2128 distInl( $3 ); 2097 2129 } 2130 | INLINE aggregate_control ';' // CFA 2131 { SemanticError( yylloc, "INLINE aggregate control currently unimplemented." ); $$ = nullptr; } 2098 2132 | typedef_declaration ';' // CFA 2099 2133 | cfa_field_declaring_list ';' // CFA, new style field declaration … … 2348 2382 | initializer_list_opt ',' initializer { $$ = (InitializerNode *)( $1->set_last( $3 ) ); } 2349 2383 | initializer_list_opt ',' designation initializer 2350 { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) )); }2384 { $$ = (InitializerNode *)($1->set_last( $4->set_designators( $3 ) )); } 2351 2385 ; 2352 2386 … … 2370 2404 designator 2371 2405 | designator_list designator 2372 { $$ = (ExpressionNode *)( $1->set_last( $2 )); }2406 { $$ = (ExpressionNode *)($1->set_last( $2 )); } 2373 2407 //| designator_list designator { $$ = new ExpressionNode( $1, $2 ); } 2374 2408 ; … … 2426 2460 | type_specifier identifier_parameter_declarator 2427 2461 | assertion_list 2428 { $$ = DeclarationNode::newTypeParam( DeclarationNode::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }2462 { $$ = DeclarationNode::newTypeParam( TypeDecl::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); } 2429 2463 ; 2430 2464 2431 2465 type_class: // CFA 2432 2466 OTYPE 2433 { $$ = DeclarationNode::Otype; }2467 { $$ = TypeDecl::Otype; } 2434 2468 | DTYPE 2435 { $$ = DeclarationNode::Dtype; }2469 { $$ = TypeDecl::Dtype; } 2436 2470 | FTYPE 2437 { $$ = DeclarationNode::Ftype; }2471 { $$ = TypeDecl::Ftype; } 2438 2472 | TTYPE 2439 { $$ = DeclarationNode::Ttype; }2473 { $$ = TypeDecl::Ttype; } 2440 2474 ; 2441 2475 … … 2467 2501 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $1->build()) ); $$ = nullptr; } 2468 2502 | type_list ',' type 2469 { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) )); }2503 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) )); } 2470 2504 | type_list ',' assignment_expression 2471 2505 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $3->build()) ); $$ = nullptr; } … … 2578 2612 { 2579 2613 linkageStack.push( linkage ); // handle nested extern "C"/"Cforall" 2580 linkage = LinkageSpec:: linkageUpdate( yylloc, linkage, $2 );2614 linkage = LinkageSpec::update( yylloc, linkage, $2 ); 2581 2615 } 2582 2616 '{' up external_definition_list_opt down '}'
Note:
See TracChangeset
for help on using the changeset viewer.