Changeset eef8dfb for src/Parser/parser.yy
- Timestamp:
- Jan 7, 2021, 2:55:57 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 58fe85a
- Parents:
- bdfc032 (diff), 44e37ef (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
rbdfc032 reef8dfb 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Feb 1 10:04:40202013 // Update Count : 4 44012 // Last Modified On : Sat Oct 24 08:21:14 2020 13 // Update Count : 4624 14 14 // 15 15 … … 166 166 } // rebindForall 167 167 168 NameExpr * build_postfix_name( const string * name ) { 169 NameExpr * new_name = build_varref( new string( "?`" + *name ) ); 170 delete name; 171 return new_name; 168 string * build_postfix_name( string * name ) { 169 *name = string("__postfix_func_") + *name; 170 return name; 172 171 } // build_postfix_name 173 172 … … 205 204 return forCtrl( type, new string( identifier->name ), start, compop, comp, inc ); 206 205 } else { 207 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed " ); return nullptr;206 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed." ); return nullptr; 208 207 } // if 209 208 } else { 210 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed " ); return nullptr;209 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed." ); return nullptr; 211 210 } // if 212 211 } // forCtrl … … 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 … … 329 329 %type<en> conditional_expression constant_expression assignment_expression assignment_expression_opt 330 330 %type<en> comma_expression comma_expression_opt 331 %type<en> argument_expression_list 331 %type<en> argument_expression_list_opt argument_expression default_initialize_opt 332 332 %type<ifctl> if_control_expression 333 333 %type<fctl> for_control_expression for_control_expression_list … … 370 370 %type<decl> assertion assertion_list assertion_list_opt 371 371 372 %type<en> 372 %type<en> bit_subrange_size_opt bit_subrange_size 373 373 374 374 %type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type indirect_type … … 624 624 // equivalent to the old x[i,j]. 625 625 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $3 ) ); } 626 | postfix_expression '{' argument_expression_list '}' // CFA, constructor call626 | postfix_expression '{' argument_expression_list_opt '}' // CFA, constructor call 627 627 { 628 628 Token fn; … … 630 630 $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) ); 631 631 } 632 | postfix_expression '(' argument_expression_list ')'632 | postfix_expression '(' argument_expression_list_opt ')' 633 633 { $$ = new ExpressionNode( build_func( $1, $3 ) ); } 634 634 | postfix_expression '`' identifier // CFA, postfix call 635 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_ postfix_name( $3) ), $1 ) ); }635 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), $1 ) ); } 636 636 | constant '`' identifier // CFA, postfix call 637 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_ postfix_name( $3) ), $1 ) ); }637 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), $1 ) ); } 638 638 | string_literal '`' identifier // CFA, postfix call 639 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_ postfix_name( $3) ), new ExpressionNode( $1 ) ) ); }639 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), new ExpressionNode( $1 ) ) ); } 640 640 | postfix_expression '.' identifier 641 641 { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); } … … 662 662 | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal 663 663 { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); } 664 | '^' primary_expression '{' argument_expression_list '}' // CFA, destructor call664 | '^' primary_expression '{' argument_expression_list_opt '}' // CFA, destructor call 665 665 { 666 666 Token fn; … … 670 670 ; 671 671 672 argument_expression_list :672 argument_expression_list_opt: 673 673 // empty 674 674 { $$ = nullptr; } 675 675 | argument_expression 676 | argument_expression_list ',' argument_expression676 | argument_expression_list_opt ',' argument_expression 677 677 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 678 678 ; … … 793 793 | '(' aggregate_control '&' ')' cast_expression // CFA 794 794 { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); } 795 // VIRTUAL cannot be opt because of look ahead issues796 795 | '(' VIRTUAL ')' cast_expression // CFA 797 796 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $4 ), maybeMoveBuildType( nullptr ) ) ); } … … 919 918 conditional_expression 920 919 | unary_expression assignment_operator assignment_expression 921 { $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); } 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 } 922 927 | unary_expression '=' '{' initializer_list_opt comma_opt '}' 923 928 { SemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; } … … 960 965 961 966 tuple_expression_list: 962 assignment_expression_opt 963 | tuple_expression_list ',' assignment_expression_opt 967 assignment_expression 968 | '@' // CFA 969 { SemanticError( yylloc, "Eliding tuple element with '@' is currently unimplemented." ); $$ = nullptr; } 970 | tuple_expression_list ',' assignment_expression 964 971 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 972 | tuple_expression_list ',' '@' 973 { SemanticError( yylloc, "Eliding tuple element with '@' is currently unimplemented." ); $$ = nullptr; } 965 974 ; 966 975 … … 1071 1080 IF '(' if_control_expression ')' statement %prec THEN 1072 1081 // explicitly deal with the shift/reduce conflict on if/else 1073 { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); }1082 { $$ = new StatementNode( build_if( $3, maybe_build_compound( $5 ), nullptr ) ); } 1074 1083 | IF '(' if_control_expression ')' statement ELSE statement 1075 { $$ = new StatementNode( build_if( $3, $5, $7) ); }1084 { $$ = new StatementNode( build_if( $3, maybe_build_compound( $5 ), maybe_build_compound( $7 ) ) ); } 1076 1085 ; 1077 1086 … … 1121 1130 1122 1131 case_clause: // CFA 1123 case_label_list statement { $$ = $1->append_last_case( new StatementNode( build_compound( $2 )) ); }1132 case_label_list statement { $$ = $1->append_last_case( maybe_build_compound( $2 ) ); } 1124 1133 ; 1125 1134 … … 1139 1148 iteration_statement: 1140 1149 WHILE '(' push if_control_expression ')' statement pop 1141 { $$ = new StatementNode( build_while( $4, $6) ); }1150 { $$ = new StatementNode( build_while( $4, maybe_build_compound( $6 ) ) ); } 1142 1151 | WHILE '(' ')' statement // CFA => while ( 1 ) 1143 { $$ = new StatementNode( build_while( new IfCtrl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), $4) ); }1152 { $$ = new StatementNode( build_while( new IfCtrl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), maybe_build_compound( $4 ) ) ); } 1144 1153 | DO statement WHILE '(' comma_expression ')' ';' 1145 { $$ = new StatementNode( build_do_while( $5, $2) ); }1154 { $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 ) ) ); } 1146 1155 | DO statement WHILE '(' ')' ';' // CFA => do while( 1 ) 1147 { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), $2) ); }1156 { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), maybe_build_compound( $2 ) ) ); } 1148 1157 | FOR '(' push for_control_expression_list ')' statement pop 1149 { $$ = new StatementNode( build_for( $4, $6) ); }1158 { $$ = new StatementNode( build_for( $4, maybe_build_compound( $6 ) ) ); } 1150 1159 | FOR '(' ')' statement // CFA => for ( ;; ) 1151 { $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), $4) ); }1160 { $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), maybe_build_compound( $4 ) ) ); } 1152 1161 ; 1153 1162 … … 1186 1195 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1187 1196 OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1188 | '=' comma_expression 1197 | '=' comma_expression // CFA 1189 1198 { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1190 1199 OperKinds::LEThan, $2->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } … … 1193 1202 | comma_expression inclexcl comma_expression '~' comma_expression // CFA 1194 1203 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, $5 ); } 1204 | comma_expression ';' // CFA 1205 { $$ = forCtrl( new ExpressionNode( build_constantInteger( *new string( "0u" ) ) ), $1, nullptr, OperKinds::LThan, nullptr, nullptr ); } 1195 1206 | comma_expression ';' comma_expression // CFA 1196 1207 { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1197 1208 OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1198 | comma_expression ';' '=' comma_expression 1209 | comma_expression ';' '=' comma_expression // CFA 1199 1210 { $$ = forCtrl( $4, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1200 1211 OperKinds::LEThan, $4->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } … … 1260 1271 | RETURN '{' initializer_list_opt comma_opt '}' ';' 1261 1272 { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; } 1262 // | SUSPEND ';' 1263 // { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; } 1264 // | SUSPEND compound_statement ';' 1265 // { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; } 1273 | SUSPEND ';' 1274 { $$ = new StatementNode( build_suspend( nullptr ) ); } 1275 | SUSPEND compound_statement 1276 { $$ = new StatementNode( build_suspend( $2 ) ); } 1277 | SUSPEND COROUTINE ';' 1278 { $$ = new StatementNode( build_suspend( nullptr, SuspendStmt::Coroutine ) ); } 1279 | SUSPEND COROUTINE compound_statement 1280 { $$ = new StatementNode( build_suspend( $3, SuspendStmt::Coroutine ) ); } 1281 | SUSPEND GENERATOR ';' 1282 { $$ = new StatementNode( build_suspend( nullptr, SuspendStmt::Generator ) ); } 1283 | SUSPEND GENERATOR compound_statement 1284 { $$ = new StatementNode( build_suspend( $3, SuspendStmt::Generator ) ); } 1266 1285 | THROW assignment_expression_opt ';' // handles rethrow 1267 1286 { $$ = new StatementNode( build_throw( $2 ) ); } … … 1286 1305 // If MUTEX becomes a general qualifier, there are shift/reduce conflicts, so change syntax to "with mutex". 1287 1306 mutex_statement: 1288 MUTEX '(' argument_expression_list ')' statement1307 MUTEX '(' argument_expression_list_opt ')' statement 1289 1308 { SemanticError( yylloc, "Mutex statement is currently unimplemented." ); $$ = nullptr; } 1290 1309 ; … … 1303 1322 WAITFOR '(' cast_expression ')' 1304 1323 { $$ = $3; } 1305 // | WAITFOR '(' cast_expression ',' argument_expression_list ')'1324 // | WAITFOR '(' cast_expression ',' argument_expression_list_opt ')' 1306 1325 // { $$ = (ExpressionNode *)$3->set_last( $5 ); } 1307 | WAITFOR '(' cast_expression_list ':' argument_expression_list ')'1326 | WAITFOR '(' cast_expression_list ':' argument_expression_list_opt ')' 1308 1327 { $$ = (ExpressionNode *)($3->set_last( $5 )); } 1309 1328 ; … … 1312 1331 cast_expression 1313 1332 | cast_expression_list ',' cast_expression 1314 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 1333 // { $$ = (ExpressionNode *)($1->set_last( $3 )); } 1334 { SemanticError( yylloc, "List of mutex member is currently unimplemented." ); $$ = nullptr; } 1315 1335 ; 1316 1336 … … 1321 1341 waitfor_clause: 1322 1342 when_clause_opt waitfor statement %prec THEN 1323 { $$ = build_waitfor( $2, $3, $1 ); }1343 { $$ = build_waitfor( $2, maybe_build_compound( $3 ), $1 ); } 1324 1344 | when_clause_opt waitfor statement WOR waitfor_clause 1325 { $$ = build_waitfor( $2, $3, $1, $5 ); }1345 { $$ = build_waitfor( $2, maybe_build_compound( $3 ), $1, $5 ); } 1326 1346 | when_clause_opt timeout statement %prec THEN 1327 { $$ = build_waitfor_timeout( $2, $3, $1 ); }1347 { $$ = build_waitfor_timeout( $2, maybe_build_compound( $3 ), $1 ); } 1328 1348 | when_clause_opt ELSE statement 1329 { $$ = build_waitfor_timeout( nullptr, $3, $1 ); }1349 { $$ = build_waitfor_timeout( nullptr, maybe_build_compound( $3 ), $1 ); } 1330 1350 // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless) 1331 1351 | when_clause_opt timeout statement WOR ELSE statement 1332 1352 { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; } 1333 1353 | when_clause_opt timeout statement WOR when_clause ELSE statement 1334 { $$ = build_waitfor_timeout( $2, $3, $1, $7, $5 ); }1354 { $$ = build_waitfor_timeout( $2, maybe_build_compound( $3 ), $1, maybe_build_compound( $7 ), $5 ); } 1335 1355 ; 1336 1356 … … 1590 1610 // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be 1591 1611 // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name. 1592 cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' 1612 cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt 1593 1613 // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator). 1594 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ) ; }1595 | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' 1596 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ) ; }1614 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 )->addQualifiers( $8 ); } 1615 | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt 1616 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 )->addQualifiers( $8 ); } 1597 1617 ; 1598 1618 … … 1655 1675 1656 1676 typedef_expression: 1657 // GCC, naming expression type: typedef name = exp; gives a name to the type of an expression1677 // deprecated GCC, naming expression type: typedef name = exp; gives a name to the type of an expression 1658 1678 TYPEDEF identifier '=' assignment_expression 1659 1679 { 1660 // $$ = DeclarationNode::newName( 0 ); // unimplemented 1661 SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr; 1680 SemanticError( yylloc, "Typedef expression is deprecated, use typeof(...) instead." ); $$ = nullptr; 1662 1681 } 1663 1682 | typedef_expression pop ',' push identifier '=' assignment_expression 1664 1683 { 1665 // $$ = DeclarationNode::newName( 0 ); // unimplemented 1666 SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr; 1667 } 1668 ; 1669 1670 //c_declaration: 1671 // declaring_list pop ';' 1672 // | typedef_declaration pop ';' 1673 // | typedef_expression pop ';' // GCC, naming expression type 1674 // | sue_declaration_specifier pop ';' 1675 // ; 1676 // 1677 //declaring_list: 1678 // // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static 1679 // // storage-class 1680 // declarator asm_name_opt initializer_opt 1681 // { 1682 // typedefTable.addToEnclosingScope( IDENTIFIER ); 1683 // $$ = ( $2->addType( $1 ))->addAsmName( $3 )->addInitializer( $4 ); 1684 // } 1685 // | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt 1686 // { 1687 // typedefTable.addToEnclosingScope( IDENTIFIER ); 1688 // $$ = $1->appendList( $1->cloneBaseType( $4->addAsmName( $5 )->addInitializer( $6 ) ) ); 1689 // } 1690 // ; 1684 SemanticError( yylloc, "Typedef expression is deprecated, use typeof(...) instead." ); $$ = nullptr; 1685 } 1686 ; 1691 1687 1692 1688 c_declaration: … … 1694 1690 { $$ = distAttr( $1, $2 ); } 1695 1691 | typedef_declaration 1696 | typedef_expression // GCC, naming expression type1692 | typedef_expression // deprecated GCC, naming expression type 1697 1693 | sue_declaration_specifier 1698 1694 ; … … 2073 2069 { yyy = true; $$ = AggregateDecl::Union; } 2074 2070 | EXCEPTION // CFA 2075 { yyy = true; $$ = AggregateDecl::Exception; } 2071 // { yyy = true; $$ = AggregateDecl::Exception; } 2072 { SemanticError( yylloc, "exception aggregate is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2076 2073 ; 2077 2074 2078 2075 aggregate_control: // CFA 2079 GENERATOR 2080 { yyy = true; $$ = AggregateDecl::Coroutine; } 2076 MONITOR 2077 { yyy = true; $$ = AggregateDecl::Monitor; } 2078 | MUTEX STRUCT 2079 { yyy = true; $$ = AggregateDecl::Monitor; } 2080 | GENERATOR 2081 { yyy = true; $$ = AggregateDecl::Generator; } 2082 | MUTEX GENERATOR 2083 { SemanticError( yylloc, "monitor generator is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2081 2084 | COROUTINE 2082 2085 { yyy = true; $$ = AggregateDecl::Coroutine; } 2083 | M ONITOR2084 { yyy = true; $$ = AggregateDecl::Monitor; }2086 | MUTEX COROUTINE 2087 { SemanticError( yylloc, "monitor coroutine is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2085 2088 | THREAD 2086 2089 { yyy = true; $$ = AggregateDecl::Thread; } 2090 | MUTEX THREAD 2091 { SemanticError( yylloc, "monitor thread is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2087 2092 ; 2088 2093 … … 2407 2412 // Overloading: function, data, and operator identifiers may be overloaded. 2408 2413 // 2409 // Type declarations: " type" is used to generate new types for declaring objects. Similarly, "dtype" is used for object2414 // Type declarations: "otype" is used to generate new types for declaring objects. Similarly, "dtype" is used for object 2410 2415 // and incomplete types, and "ftype" is used for function types. Type declarations with initializers provide 2411 2416 // definitions of new types. Type declarations with storage class "extern" provide opaque types. … … 2436 2441 type_class identifier_or_type_name 2437 2442 { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); } 2438 2443 type_initializer_opt assertion_list_opt 2439 2444 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); } 2440 2445 | type_specifier identifier_parameter_declarator … … 2463 2468 assertion 2464 2469 | assertion_list assertion 2465 { $$ = $1 ? $1->appendList( $2 ) : $2; }2470 { $$ = $1->appendList( $2 ); } 2466 2471 ; 2467 2472 … … 2750 2755 | attr_name 2751 2756 { $$ = DeclarationNode::newAttribute( $1 ); } 2752 | attr_name '(' argument_expression_list ')'2757 | attr_name '(' argument_expression_list_opt ')' 2753 2758 { $$ = DeclarationNode::newAttribute( $1, $3 ); } 2754 2759 ;
Note:
See TracChangeset
for help on using the changeset viewer.