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