Changeset eba74ba for src/Parser/parser.yy
- Timestamp:
- May 25, 2018, 2:51:06 PM (6 years ago)
- Branches:
- new-env, with_gc
- Children:
- cdc4d43
- Parents:
- 3ef35bd (diff), 58e822a (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
r3ef35bd reba74ba 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri May 11 17:51:38201813 // Update Count : 3 26112 // Last Modified On : Thu May 24 18:11:59 2018 13 // Update Count : 3369 14 14 // 15 15 … … 119 119 // Does the forall bind to the struct or the routine, and how would it be possible to explicitly specify the binding. 120 120 // forall( otype T ) struct S { int T; } forall( otype W ) bar( W ) {} 121 // Currently, the forall is associated with the routine, and the generic type has to be separately defined: 122 // forall( otype T ) struct S { int T; }; 123 // forall( otype W ) bar( W ) {} 121 124 122 125 void rebindForall( DeclarationNode * declSpec, DeclarationNode * funcDecl ) { 123 if ( declSpec->type->kind == TypeData::Aggregate ) { // return isaggregate definition126 if ( declSpec->type->kind == TypeData::Aggregate ) { // ignore aggregate definition 124 127 funcDecl->type->forall = declSpec->type->aggregate.params; // move forall from aggregate to function type 125 128 declSpec->type->aggregate.params = nullptr; … … 301 304 %type<decl> exception_declaration external_definition external_definition_list external_definition_list_opt 302 305 303 %type<decl> field_declaration field_declaration_list field_declaratorfield_declaring_list306 %type<decl> field_declaration field_declaration_list_opt field_declarator_opt field_declaring_list 304 307 %type<en> field field_list field_name fraction_constants_opt 305 308 … … 361 364 362 365 // initializers 363 %type<in> initializer initializer_list initializer_opt366 %type<in> initializer initializer_list_opt initializer_opt 364 367 365 368 // designators … … 412 415 // actions during the parser update this data structure when the class of identifiers change. 413 416 // 414 // Because the Cforall language is block-scoped, there is the possibility that an identifier can change its class in a 415 // local scope; it must revert to its original class at the end of the block. Since type names can be local to a 416 // particular declaration, each declaration is itself a scope. This requires distinguishing between type names that are 417 // local to the current declaration scope and those that persist past the end of the declaration (i.e., names defined in 418 // "typedef" or "otype" declarations). 419 // 420 // The non-terminals "push" and "pop" derive the empty string; their only use is to denote the opening and closing of 421 // scopes. Every push must have a matching pop, although it is regrettable the matching pairs do not always occur 422 // within the same rule. These non-terminals may appear in more contexts than strictly necessary from a semantic point 423 // of view. Unfortunately, these extra rules are necessary to prevent parsing conflicts -- the parser may not have 424 // enough context and look-ahead information to decide whether a new scope is necessary, so the effect of these extra 425 // rules is to open a new scope unconditionally. As the grammar evolves, it may be neccesary to add or move around 426 // "push" and "pop" nonterminals to resolve conflicts of this sort. 417 // Because the Cforall language is block-scoped, an identifier can change its class in a local scope; it must revert to 418 // its original class at the end of the block. Since type names can be local to a particular declaration, each 419 // declaration is itself a scope. This requires distinguishing between type names that are local to the current 420 // declaration scope and those that persist past the end of the declaration (i.e., names defined in "typedef" or "otype" 421 // declarations). 422 // 423 // The non-terminals "push" and "pop" denote the opening and closing of scopes. Every push must have a matching pop, 424 // although it is regrettable the matching pairs do not always occur within the same rule. These non-terminals may 425 // appear in more contexts than strictly necessary from a semantic point of view. 427 426 428 427 push: … … 498 497 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); } 499 498 | type_name '.' no_attr_identifier // CFA, nested type 500 { SemanticError( yylloc, "Qualified names are currently unimplemented." ); $$ = nullptr; } 501 // { $$ = nullptr; } 502 | type_name '.' '[' push field_list pop ']' // CFA, nested type / tuple field selector 503 { SemanticError( yylloc, "Qualified names are currently unimplemented." ); $$ = nullptr; } 504 // { $$ = nullptr; } 499 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } 500 | type_name '.' '[' field_list ']' // CFA, nested type / tuple field selector 501 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } 505 502 | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11 506 503 { SemanticError( yylloc, "_Generic is currently unimplemented." ); $$ = nullptr; } … … 519 516 postfix_expression: 520 517 primary_expression 521 | postfix_expression '[' push assignment_expression pop']'518 | postfix_expression '[' assignment_expression ']' 522 519 // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a 523 520 // matrix with x[i,j] instead of x[i][j]. While this change is not backwards compatible, there seems to be 524 521 // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is 525 522 // equivalent to the old x[i,j]. 526 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $ 4) ); }523 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $3 ) ); } 527 524 | postfix_expression '{' argument_expression_list '}' // CFA, constructor call 528 525 { … … 539 536 | postfix_expression FLOATING_FRACTIONconstant // CFA, tuple index 540 537 { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant( *$2 ) ) ); } 541 | postfix_expression '.' '[' push field_list pop ']'// CFA, tuple field selector542 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $ 5) ) ); }538 | postfix_expression '.' '[' field_list ']' // CFA, tuple field selector 539 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); } 543 540 | postfix_expression ARROW no_attr_identifier 544 541 { … … 547 544 | postfix_expression ARROW INTEGERconstant // CFA, tuple index 548 545 { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger( *$3 ) ) ); } 549 | postfix_expression ARROW '[' push field_list pop ']'// CFA, tuple field selector550 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $ 5) ) ); }546 | postfix_expression ARROW '[' field_list ']' // CFA, tuple field selector 547 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); } 551 548 | postfix_expression ICR 552 549 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::IncrPost, $1 ) ); } 553 550 | postfix_expression DECR 554 551 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::DecrPost, $1 ) ); } 555 | '(' type_no_function ')' '{' initializer_list comma_opt '}' // C99, compound-literal552 | '(' type_no_function ')' '{' initializer_list_opt comma_opt '}' // C99, compound-literal 556 553 { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); } 557 | '(' type_no_function ')' '@' '{' initializer_list comma_opt '}' // CFA, explicit C compound-literal554 | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal 558 555 { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); } 559 556 | '^' primary_expression '{' argument_expression_list '}' // CFA … … 588 585 | FLOATING_DECIMALconstant field 589 586 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); } 590 | FLOATING_DECIMALconstant '[' push field_list pop']'591 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $ 4) ) ); }587 | FLOATING_DECIMALconstant '[' field_list ']' 588 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $3 ) ) ); } 592 589 | field_name '.' field 593 590 { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); } 594 | field_name '.' '[' push field_list pop']'595 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $ 5) ) ); }591 | field_name '.' '[' field_list ']' 592 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); } 596 593 | field_name ARROW field 597 594 { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); } 598 | field_name ARROW '[' push field_list pop']'599 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $ 5) ) ); }595 | field_name ARROW '[' field_list ']' 596 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); } 600 597 ; 601 598 … … 807 804 | unary_expression assignment_operator assignment_expression 808 805 { $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); } 809 | unary_expression '=' '{' initializer_list comma_opt '}'806 | unary_expression '=' '{' initializer_list_opt comma_opt '}' 810 807 { SemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; } 811 808 ; … … 869 866 labeled_statement 870 867 | compound_statement 871 | expression_statement { $$ = $1; }868 | expression_statement 872 869 | selection_statement 873 870 | iteration_statement … … 1074 1071 | RETURN comma_expression_opt ';' 1075 1072 { $$ = new StatementNode( build_return( $2 ) ); } 1076 | RETURN '{' initializer_list comma_opt '}'1073 | RETURN '{' initializer_list_opt comma_opt '}' 1077 1074 { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; } 1078 1075 | THROW assignment_expression_opt ';' // handles rethrow … … 1168 1165 1169 1166 handler_predicate_opt: 1170 // empty1167 // empty 1171 1168 { $$ = nullptr; } 1172 1169 | ';' conditional_expression { $$ = $2; } … … 1186 1183 type_specifier_nobody 1187 1184 | type_specifier_nobody declarator 1188 { 1189 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1190 $$ = $2->addType( $1 ); 1191 } 1185 { $$ = $2->addType( $1 ); } 1192 1186 | type_specifier_nobody variable_abstract_declarator 1193 1187 { $$ = $2->addType( $1 ); } 1194 1188 | cfa_abstract_declarator_tuple no_attr_identifier // CFA 1195 { 1196 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1197 $$ = $1->addName( $2 ); 1198 } 1189 { $$ = $1->addName( $2 ); } 1199 1190 | cfa_abstract_declarator_tuple // CFA 1200 1191 ; … … 1274 1265 1275 1266 declaration_list_opt: // used at beginning of switch statement 1276 pop 1267 pop // empty 1277 1268 { $$ = nullptr; } 1278 1269 | declaration_list … … 1309 1300 1310 1301 local_label_list: // GCC, local label 1311 no_attr_identifier_or_type_name {}1312 | local_label_list ',' no_attr_identifier_or_type_name {}1302 no_attr_identifier_or_type_name 1303 | local_label_list ',' no_attr_identifier_or_type_name 1313 1304 ; 1314 1305 … … 1344 1335 cfa_variable_declaration: // CFA 1345 1336 cfa_variable_specifier initializer_opt 1346 { 1347 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1348 $$ = $1->addInitializer( $2 ); 1349 } 1337 { $$ = $1->addInitializer( $2 ); } 1350 1338 | declaration_qualifier_list cfa_variable_specifier initializer_opt 1351 1339 // declaration_qualifier_list also includes type_qualifier_list, so a semantic check is necessary to preclude 1352 1340 // them as a type_qualifier cannot appear in that context. 1353 { 1354 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1355 $$ = $2->addQualifiers( $1 )->addInitializer( $3 );; 1356 } 1341 { $$ = $2->addQualifiers( $1 )->addInitializer( $3 ); } 1357 1342 | cfa_variable_declaration pop ',' push identifier_or_type_name initializer_opt 1358 { 1359 typedefTable.addToEnclosingScope( *$5, TypedefTable::ID ); 1360 $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) ); 1361 } 1343 { $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) ); } 1362 1344 ; 1363 1345 … … 1366 1348 // storage-class 1367 1349 cfa_abstract_declarator_no_tuple identifier_or_type_name asm_name_opt 1368 { 1369 typedefTable.setNextIdentifier( *$2 ); 1370 $$ = $1->addName( $2 )->addAsmName( $3 ); 1371 } 1350 { $$ = $1->addName( $2 )->addAsmName( $3 ); } 1372 1351 | cfa_abstract_tuple identifier_or_type_name asm_name_opt 1373 { 1374 typedefTable.setNextIdentifier( *$2 ); 1375 $$ = $1->addName( $2 )->addAsmName( $3 ); 1376 } 1352 { $$ = $1->addName( $2 )->addAsmName( $3 ); } 1377 1353 | type_qualifier_list cfa_abstract_tuple identifier_or_type_name asm_name_opt 1378 { 1379 typedefTable.setNextIdentifier( *$3 ); 1380 $$ = $2->addQualifiers( $1 )->addName( $3 )->addAsmName( $4 ); 1381 } 1354 { $$ = $2->addQualifiers( $1 )->addName( $3 )->addAsmName( $4 ); } 1382 1355 ; 1383 1356 1384 1357 cfa_function_declaration: // CFA 1385 1358 cfa_function_specifier 1386 { 1387 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1388 $$ = $1; 1389 } 1359 { $$ = $1; } 1390 1360 | type_qualifier_list cfa_function_specifier 1391 { 1392 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1393 $$ = $2->addQualifiers( $1 ); 1394 } 1361 { $$ = $2->addQualifiers( $1 ); } 1395 1362 | declaration_qualifier_list cfa_function_specifier 1396 { 1397 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1398 $$ = $2->addQualifiers( $1 ); 1399 } 1363 { $$ = $2->addQualifiers( $1 ); } 1400 1364 | declaration_qualifier_list type_qualifier_list cfa_function_specifier 1401 { 1402 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1403 $$ = $3->addQualifiers( $1 )->addQualifiers( $2 ); 1404 } 1405 | cfa_function_declaration pop ',' push identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')' 1365 { $$ = $3->addQualifiers( $1 )->addQualifiers( $2 ); } 1366 | cfa_function_declaration ',' identifier_or_type_name '(' cfa_parameter_type_list_opt ')' 1406 1367 { 1407 1368 // Append the return type at the start (left-hand-side) to each identifier in the list. 1408 1369 DeclarationNode * ret = new DeclarationNode; 1409 1370 ret->type = maybeClone( $1->type->base ); 1410 $$ = $1->appendList( DeclarationNode::newFunction( $ 5, ret, $8, nullptr ) );1371 $$ = $1->appendList( DeclarationNode::newFunction( $3, ret, $5, nullptr ) ); 1411 1372 } 1412 1373 ; … … 1437 1398 cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')' 1438 1399 // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator). 1439 { 1440 $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); 1441 } 1400 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); } 1442 1401 | cfa_function_return identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')' 1443 { 1444 $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); 1445 } 1402 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); } 1446 1403 ; 1447 1404 … … 1450 1407 { $$ = DeclarationNode::newTuple( $3 ); } 1451 1408 | '[' push cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ']' 1452 // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the 1453 // ']'. 1409 // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the ']'. 1454 1410 { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); } 1455 1411 ; … … 1458 1414 TYPEDEF cfa_variable_specifier 1459 1415 { 1460 typedefTable.addToEnclosingScope( TypedefTable::TD);1416 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname ); 1461 1417 $$ = $2->addTypedef(); 1462 1418 } 1463 1419 | TYPEDEF cfa_function_specifier 1464 1420 { 1465 typedefTable.addToEnclosingScope( TypedefTable::TD);1421 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname ); 1466 1422 $$ = $2->addTypedef(); 1467 1423 } 1468 1424 | cfa_typedef_declaration pop ',' push no_attr_identifier 1469 1425 { 1470 typedefTable.addToEnclosingScope( *$5, T ypedefTable::TD);1426 typedefTable.addToEnclosingScope( *$5, TYPEDEFname ); 1471 1427 $$ = $1->appendList( $1->cloneType( $5 ) ); 1472 1428 } … … 1479 1435 TYPEDEF type_specifier declarator 1480 1436 { 1481 typedefTable.addToEnclosingScope( TypedefTable::TD);1437 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname ); 1482 1438 $$ = $3->addType( $2 )->addTypedef(); 1483 1439 } 1484 1440 | typedef_declaration pop ',' push declarator 1485 1441 { 1486 typedefTable.addToEnclosingScope( TypedefTable::TD);1442 typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname ); 1487 1443 $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() ); 1488 1444 } 1489 1445 | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 ) 1490 1446 { 1491 typedefTable.addToEnclosingScope( TypedefTable::TD);1447 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname ); 1492 1448 $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef(); 1493 1449 } 1494 1450 | type_specifier TYPEDEF declarator 1495 1451 { 1496 typedefTable.addToEnclosingScope( TypedefTable::TD);1452 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname ); 1497 1453 $$ = $3->addType( $1 )->addTypedef(); 1498 1454 } 1499 1455 | type_specifier TYPEDEF type_qualifier_list declarator 1500 1456 { 1501 typedefTable.addToEnclosingScope( TypedefTable::TD);1457 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname ); 1502 1458 $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 ); 1503 1459 } … … 1508 1464 TYPEDEF no_attr_identifier '=' assignment_expression 1509 1465 { 1510 typedefTable.addToEnclosingScope( *$2, TypedefTable::TD );1511 $$ = DeclarationNode::newName( 0 ); // unimplemented1466 // $$ = DeclarationNode::newName( 0 ); // unimplemented 1467 SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr; 1512 1468 } 1513 1469 | typedef_expression pop ',' push no_attr_identifier '=' assignment_expression 1514 1470 { 1515 typedefTable.addToEnclosingScope( *$5, TypedefTable::TD );1516 $$ = DeclarationNode::newName( 0 ); // unimplemented1471 // $$ = DeclarationNode::newName( 0 ); // unimplemented 1472 SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr; 1517 1473 } 1518 1474 ; … … 1530 1486 // declarator asm_name_opt initializer_opt 1531 1487 // { 1532 // typedefTable.addToEnclosingScope( TypedefTable::ID);1488 // typedefTable.addToEnclosingScope( IDENTIFIER ); 1533 1489 // $$ = ( $2->addType( $1 ))->addAsmName( $3 )->addInitializer( $4 ); 1534 1490 // } 1535 1491 // | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt 1536 1492 // { 1537 // typedefTable.addToEnclosingScope( TypedefTable::ID);1493 // typedefTable.addToEnclosingScope( IDENTIFIER ); 1538 1494 // $$ = $1->appendList( $1->cloneBaseType( $4->addAsmName( $5 )->addInitializer( $6 ) ) ); 1539 1495 // } … … 1542 1498 c_declaration: 1543 1499 declaration_specifier declaring_list 1544 { 1545 $$ = distAttr( $1, $2 ); 1546 } 1500 { $$ = distAttr( $1, $2 ); } 1547 1501 | typedef_declaration 1548 1502 | typedef_expression // GCC, naming expression type … … 1554 1508 // storage-class 1555 1509 declarator asm_name_opt initializer_opt 1556 { 1557 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1558 $$ = $1->addAsmName( $2 )->addInitializer( $3 ); 1559 } 1510 { $$ = $1->addAsmName( $2 )->addInitializer( $3 ); } 1560 1511 | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt 1561 { 1562 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1563 $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); 1564 } 1512 { $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); } 1565 1513 ; 1566 1514 … … 1634 1582 1635 1583 forall: 1636 FORALL '(' 1637 { 1638 typedefTable.enterScope(); 1639 } 1640 type_parameter_list ')' // CFA 1641 { 1642 typedefTable.leaveScope(); 1643 $$ = DeclarationNode::newForall( $4 ); 1644 } 1584 FORALL '(' push type_parameter_list pop ')' // CFA 1585 { $$ = DeclarationNode::newForall( $4 ); } 1645 1586 ; 1646 1587 … … 1854 1795 1855 1796 aggregate_type: // struct, union 1856 aggregate_key attribute_list_opt '{' field_declaration_list '}'1797 aggregate_key attribute_list_opt '{' field_declaration_list_opt '}' 1857 1798 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); } 1858 1799 | aggregate_key attribute_list_opt no_attr_identifier_or_type_name 1859 1800 { 1860 1801 typedefTable.makeTypedef( *$3 ); // create typedef 1861 if ( forall ) typedefTable.changeKind( *$3, T ypedefTable::TG); // possibly update1802 if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update 1862 1803 forall = false; // reset 1863 1804 } 1864 '{' field_declaration_list '}'1805 '{' field_declaration_list_opt '}' 1865 1806 { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); } 1866 | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list '}' // CFA1807 | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list_opt '}' // CFA 1867 1808 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); } 1868 1809 | aggregate_type_nobody … … 1873 1814 { 1874 1815 typedefTable.makeTypedef( *$3 ); 1875 if ( forall ) typedefTable.changeKind( *$3, T ypedefTable::TG); // possibly update1816 if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update 1876 1817 forall = false; // reset 1877 1818 $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 ); … … 1909 1850 ; 1910 1851 1911 field_declaration_list :1852 field_declaration_list_opt: 1912 1853 // empty 1913 1854 { $$ = nullptr; } 1914 | field_declaration_list field_declaration1855 | field_declaration_list_opt field_declaration 1915 1856 { $$ = $1 ? $1->appendList( $2 ) : $2; } 1916 1857 ; … … 1945 1886 1946 1887 field_declaring_list: 1947 field_declarator 1948 | field_declaring_list ',' attribute_list_opt field_declarator 1888 field_declarator_opt 1889 | field_declaring_list ',' attribute_list_opt field_declarator_opt 1949 1890 { $$ = $1->appendList( $4->addQualifiers( $3 ) ); } 1950 1891 ; 1951 1892 1952 field_declarator :1893 field_declarator_opt: 1953 1894 // empty 1954 1895 { $$ = DeclarationNode::newName( 0 ); /* XXX */ } // CFA, no field name … … 2090 2031 // No SUE declaration in parameter list. 2091 2032 declaration_specifier_nobody identifier_parameter_declarator default_initialize_opt 2092 { 2093 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2094 $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); 2095 } 2033 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); } 2096 2034 | declaration_specifier_nobody type_parameter_redeclarator default_initialize_opt 2097 { 2098 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2099 $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); 2100 } 2035 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); } 2101 2036 ; 2102 2037 … … 2156 2091 initializer: 2157 2092 assignment_expression { $$ = new InitializerNode( $1 ); } 2158 | '{' initializer_list comma_opt '}'{ $$ = new InitializerNode( $2, true ); }2159 ; 2160 2161 initializer_list :2093 | '{' initializer_list_opt comma_opt '}' { $$ = new InitializerNode( $2, true ); } 2094 ; 2095 2096 initializer_list_opt: 2162 2097 // empty 2163 2098 { $$ = nullptr; } 2164 2099 | initializer 2165 2100 | designation initializer { $$ = $2->set_designators( $1 ); } 2166 | initializer_list ',' initializer{ $$ = (InitializerNode *)( $1->set_last( $3 ) ); }2167 | initializer_list ',' designation initializer2101 | initializer_list_opt ',' initializer { $$ = (InitializerNode *)( $1->set_last( $3 ) ); } 2102 | initializer_list_opt ',' designation initializer 2168 2103 { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) ) ); } 2169 2104 ; … … 2240 2175 type_parameter: // CFA 2241 2176 type_class no_attr_identifier_or_type_name 2242 { typedefTable.addToEnclosingScope( *$2, T ypedefTable::TD); }2177 { typedefTable.addToEnclosingScope( *$2, TYPEDEFname ); } 2243 2178 type_initializer_opt assertion_list_opt 2244 2179 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); } … … 2273 2208 assertion: // CFA 2274 2209 '|' no_attr_identifier_or_type_name '(' type_list ')' 2275 { 2276 typedefTable.openTrait( *$2 ); 2277 $$ = DeclarationNode::newTraitUse( $2, $4 ); 2278 } 2210 { $$ = DeclarationNode::newTraitUse( $2, $4 ); } 2279 2211 | '|' '{' push trait_declaration_list '}' 2280 2212 { $$ = $4; } 2281 2213 | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_list ')' 2282 { $$ = nullptr; }2214 { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; } 2283 2215 ; 2284 2216 … … 2312 2244 no_attr_identifier_or_type_name 2313 2245 { 2314 typedefTable.addToEnclosingScope( *$1, T ypedefTable::TD);2246 typedefTable.addToEnclosingScope( *$1, TYPEDEFname ); 2315 2247 $$ = DeclarationNode::newTypeDecl( $1, 0 ); 2316 2248 } 2317 2249 | no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' 2318 2250 { 2319 typedefTable.addToEnclosingScope( *$1, T ypedefTable::TG);2251 typedefTable.addToEnclosingScope( *$1, TYPEGENname ); 2320 2252 $$ = DeclarationNode::newTypeDecl( $1, $4 ); 2321 2253 } … … 2324 2256 trait_specifier: // CFA 2325 2257 TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' '}' 2326 { 2327 typedefTable.addToEnclosingScope( *$2, TypedefTable::ID ); 2328 $$ = DeclarationNode::newTrait( $2, $5, 0 ); 2329 } 2330 | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' 2331 { 2332 typedefTable.enterTrait( *$2 ); 2333 typedefTable.enterScope(); 2334 } 2335 trait_declaration_list '}' 2336 { 2337 typedefTable.leaveTrait(); 2338 typedefTable.addToEnclosingScope( *$2, TypedefTable::ID ); 2339 $$ = DeclarationNode::newTrait( $2, $5, $10 ); 2340 } 2258 { $$ = DeclarationNode::newTrait( $2, $5, 0 ); } 2259 | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' 2260 { $$ = DeclarationNode::newTrait( $2, $5, $10 ); } 2341 2261 ; 2342 2262 … … 2354 2274 cfa_trait_declaring_list: // CFA 2355 2275 cfa_variable_specifier 2356 {2357 typedefTable.addToEnclosingScope2( TypedefTable::ID );2358 $$ = $1;2359 }2360 2276 | cfa_function_specifier 2361 {2362 typedefTable.addToEnclosingScope2( TypedefTable::ID );2363 $$ = $1;2364 }2365 2277 | cfa_trait_declaring_list pop ',' push identifier_or_type_name 2366 { 2367 typedefTable.addToEnclosingScope2( *$5, TypedefTable::ID ); 2368 $$ = $1->appendList( $1->cloneType( $5 ) ); 2369 } 2278 { $$ = $1->appendList( $1->cloneType( $5 ) ); } 2370 2279 ; 2371 2280 2372 2281 trait_declaring_list: // CFA 2373 2282 type_specifier declarator 2374 { 2375 typedefTable.addToEnclosingScope2( TypedefTable::ID ); 2376 $$ = $2->addType( $1 ); 2377 } 2283 { $$ = $2->addType( $1 ); } 2378 2284 | trait_declaring_list pop ',' push declarator 2379 { 2380 typedefTable.addToEnclosingScope2( TypedefTable::ID ); 2381 $$ = $1->appendList( $1->cloneBaseType( $5 ) ); 2382 } 2285 { $$ = $1->appendList( $1->cloneBaseType( $5 ) ); } 2383 2286 ; 2384 2287 … … 2430 2333 } 2431 2334 | type_qualifier_list 2432 { 2433 if ( $1->type->forall ) xxx = forall = true; // remember generic type 2434 } 2335 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type 2435 2336 push '{' external_definition_list '}' // CFA, namespace 2436 2337 { … … 2445 2346 } 2446 2347 | declaration_qualifier_list 2447 { 2448 if ( $1->type->forall ) xxx = forall = true; // remember generic type 2449 } 2348 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type 2450 2349 push '{' external_definition_list '}' // CFA, namespace 2451 2350 { … … 2487 2386 // declaration must still have a type_specifier. OBSOLESCENT (see 1) 2488 2387 | function_declarator compound_statement 2489 { 2490 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2491 typedefTable.leaveScope(); 2492 $$ = $1->addFunctionBody( $2 ); 2493 } 2388 { $$ = $1->addFunctionBody( $2 ); } 2494 2389 | KR_function_declarator KR_declaration_list_opt compound_statement 2495 { 2496 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2497 typedefTable.leaveScope(); 2498 $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); 2499 } 2390 { $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); } 2500 2391 ; 2501 2392 … … 2510 2401 cfa_function_declaration with_clause_opt compound_statement // CFA 2511 2402 { 2512 typedefTable.addToEnclosingScope( TypedefTable::ID );2513 typedefTable.leaveScope();2514 2403 // Add the function body to the last identifier in the function definition list, i.e., foo3: 2515 2404 // [const double] foo1(), foo2( int ), foo3( double ) { return 3.0; } … … 2520 2409 { 2521 2410 rebindForall( $1, $2 ); 2522 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2523 typedefTable.leaveScope(); 2411 $$ = $2->addFunctionBody( $4, $3 )->addType( $1 ); 2412 } 2413 | declaration_specifier variable_type_redeclarator with_clause_opt compound_statement 2414 { 2415 rebindForall( $1, $2 ); 2524 2416 $$ = $2->addFunctionBody( $4, $3 )->addType( $1 ); 2525 2417 } 2526 2418 // handles default int return type, OBSOLESCENT (see 1) 2527 2419 | type_qualifier_list function_declarator with_clause_opt compound_statement 2528 { 2529 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2530 typedefTable.leaveScope(); 2531 $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); 2532 } 2420 { $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); } 2533 2421 // handles default int return type, OBSOLESCENT (see 1) 2534 2422 | declaration_qualifier_list function_declarator with_clause_opt compound_statement 2535 { 2536 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2537 typedefTable.leaveScope(); 2538 $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); 2539 } 2423 { $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); } 2540 2424 // handles default int return type, OBSOLESCENT (see 1) 2541 2425 | declaration_qualifier_list type_qualifier_list function_declarator with_clause_opt compound_statement 2542 { 2543 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2544 typedefTable.leaveScope(); 2545 $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 ); 2546 } 2426 { $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 ); } 2547 2427 2548 2428 // Old-style K&R function definition, OBSOLESCENT (see 4) … … 2550 2430 { 2551 2431 rebindForall( $1, $2 ); 2552 typedefTable.addToEnclosingScope( TypedefTable::ID );2553 typedefTable.leaveScope();2554 2432 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addType( $1 ); 2555 2433 } 2556 2434 // handles default int return type, OBSOLESCENT (see 1) 2557 2435 | type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement 2558 { 2559 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2560 typedefTable.leaveScope(); 2561 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); 2562 } 2436 { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); } 2563 2437 // handles default int return type, OBSOLESCENT (see 1) 2564 2438 | declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement 2565 { 2566 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2567 typedefTable.leaveScope(); 2568 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); 2569 } 2439 { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); } 2570 2440 // handles default int return type, OBSOLESCENT (see 1) 2571 2441 | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement 2572 { 2573 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2574 typedefTable.leaveScope(); 2575 $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); 2576 } 2442 { $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); } 2577 2443 ; 2578 2444 … … 2684 2550 paren_identifier: 2685 2551 identifier 2686 { 2687 typedefTable.setNextIdentifier( *$1 ); 2688 $$ = DeclarationNode::newName( $1 ); 2689 } 2552 { $$ = DeclarationNode::newName( $1 ); } 2690 2553 | '(' paren_identifier ')' // redundant parenthesis 2691 2554 { $$ = $2; } … … 2820 2683 paren_type: 2821 2684 typedef 2685 // hide type name in enclosing scope by variable name 2686 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER ); } 2822 2687 | '(' paren_type ')' 2823 2688 { $$ = $2; } … … 2922 2787 typedef: 2923 2788 TYPEDEFname 2924 { 2925 typedefTable.setNextIdentifier( *$1 ); 2926 $$ = DeclarationNode::newName( $1 ); 2927 } 2789 { $$ = DeclarationNode::newName( $1 ); } 2928 2790 | TYPEGENname 2929 { 2930 typedefTable.setNextIdentifier( *$1 ); 2931 $$ = DeclarationNode::newName( $1 ); 2932 } 2791 { $$ = DeclarationNode::newName( $1 ); } 2933 2792 ; 2934 2793
Note: See TracChangeset
for help on using the changeset viewer.