Changeset 67467a3 for src/Parser/TypeData.cc
- Timestamp:
- Mar 26, 2024, 3:17:51 PM (4 months ago)
- Branches:
- master
- Children:
- 544b799
- Parents:
- 84886499
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/TypeData.cc
r84886499 r67467a3 75 75 function.withExprs = nullptr; 76 76 break; 77 case Enum:78 enumeration.name = nullptr;79 enumeration.constants = nullptr;80 enumeration.body = false;81 enumeration.anon = false;82 break;83 77 case Aggregate: 84 78 aggregate.kind = ast::AggregateDecl::NoAggregate; … … 89 83 aggregate.body = false; 90 84 aggregate.anon = false; 85 aggregate.typed = false; 86 aggregate.hiding = EnumHiding::Visible; 91 87 break; 92 88 case AggregateInst: … … 153 149 delete aggInst.aggregate; 154 150 delete aggInst.params; 155 break;156 case Enum:157 delete enumeration.name;158 delete enumeration.constants;159 151 break; 160 152 case Symbolic: … … 231 223 newtype->aggInst.hoistType = aggInst.hoistType; 232 224 break; 233 case Enum:234 newtype->enumeration.name = enumeration.name ? new string( *enumeration.name ) : nullptr;235 newtype->enumeration.constants = maybeCopy( enumeration.constants );236 newtype->enumeration.body = enumeration.body;237 newtype->enumeration.anon = enumeration.anon;238 break;239 225 case Symbolic: 240 226 case SymbolicInst: … … 375 361 os << string( indent + 2, ' ' ) << "with parameters" << endl; 376 362 aggInst.params->printList( os, indent + 2 ); 377 } // if378 break;379 case Enum:380 os << "enumeration " << *enumeration.name << endl;;381 if ( enumeration.constants ) {382 os << "with constants" << endl;383 enumeration.constants->printList( os, indent + 2 );384 } // if385 if ( enumeration.body ) {386 os << string( indent + 2, ' ' ) << "with body" << endl;387 } // if388 if ( base ) {389 os << "for ";390 base->print( os, indent + 2 );391 363 } // if 392 364 break; … … 483 455 case Aggregate: 484 456 return aggregate.name; 485 case Enum:486 return enumeration.name;487 457 case Symbolic: 488 458 case SymbolicInst: … … 673 643 switch ( src->kind ) { 674 644 case TypeData::Aggregate: 675 case TypeData::Enum:676 645 dst->base = new TypeData( TypeData::AggregateInst ); 677 646 dst->base->aggInst.aggregate = src; … … 701 670 return rtype; 702 671 } else { 703 if ( ltype->kind == TypeData::Aggregate || ltype->kind == TypeData::Enum) {672 if ( ltype->kind == TypeData::Aggregate ) { 704 673 // Hide type information aggregate instances. 705 674 rtype = new TypeData( TypeData::AggregateInst ); 706 675 rtype->aggInst.aggregate = ltype; 707 676 rtype->aggInst.aggregate->aggregate.attributes.swap( attributes ); // change ownership 708 if ( ltype->kind == TypeData::Aggregate ) { 709 rtype->aggInst.hoistType = ltype->aggregate.body; 710 rtype->aggInst.params = maybeCopy( ltype->aggregate.actuals ); 711 } else { 712 rtype->aggInst.hoistType = ltype->enumeration.body; 713 } // if 677 rtype->aggInst.hoistType = ltype->aggregate.body; 678 rtype->aggInst.params = maybeCopy( ltype->aggregate.actuals ); 714 679 rtype->qualifiers |= ltype->qualifiers; 715 680 } else { … … 730 695 if ( newType->kind == TypeData::AggregateInst ) { 731 696 // don't duplicate members 732 if ( newType->aggInst.aggregate->kind == TypeData::Enum ) { 733 delete newType->aggInst.aggregate->enumeration.constants; 734 newType->aggInst.aggregate->enumeration.constants = nullptr; 735 newType->aggInst.aggregate->enumeration.body = false; 736 } else { 737 assert( newType->aggInst.aggregate->kind == TypeData::Aggregate ); 738 delete newType->aggInst.aggregate->aggregate.fields; 739 newType->aggInst.aggregate->aggregate.fields = nullptr; 740 newType->aggInst.aggregate->aggregate.body = false; 741 } // if 697 assert( newType->aggInst.aggregate->kind == TypeData::Aggregate ); 698 delete newType->aggInst.aggregate->aggregate.fields; 699 newType->aggInst.aggregate->aggregate.fields = nullptr; 700 newType->aggInst.aggregate->aggregate.body = false; 742 701 // don't hoist twice 743 702 newType->aggInst.hoistType = false; … … 755 714 TypeData * makeNewBase( TypeData * type ) { 756 715 switch ( type->kind ) { 757 case TypeData::Aggregate: 758 case TypeData::Enum: { 716 case TypeData::Aggregate: { 759 717 TypeData * out = new TypeData( TypeData::AggregateInst ); 760 718 out->aggInst.aggregate = type; … … 1123 1081 ); 1124 1082 case TypeData::Symbolic: 1125 case TypeData::Enum:1126 1083 case TypeData::Aggregate: 1127 1084 assert( false ); … … 1138 1095 case TypeData::Aggregate: 1139 1096 if ( ! toplevel && td->aggregate.body ) { 1140 ret = td->clone();1141 } // if1142 break;1143 case TypeData::Enum:1144 if ( ! toplevel && td->enumeration.body ) {1145 1097 ret = td->clone(); 1146 1098 } // if … … 1345 1297 buildForall( td->aggregate.params, at->params ); 1346 1298 break; 1299 case ast::AggregateDecl::Enum: 1300 return buildEnum( td, std::move( attributes ), linkage ); 1347 1301 case ast::AggregateDecl::Trait: 1348 1302 at = new ast::TraitDecl( td->location, … … 1369 1323 ast::Linkage::Spec linkage ) { 1370 1324 switch ( td->kind ) { 1371 case TypeData::Enum:1372 if ( td->enumeration.body ) {1373 ast::EnumDecl * typedecl =1374 buildEnum( td, std::move( attributes ), linkage );1375 return new ast::EnumInstType(1376 typedecl,1377 buildQualifiers( td )1378 );1379 } else {1380 return new ast::EnumInstType(1381 *td->enumeration.name,1382 buildQualifiers( td )1383 );1384 } // if1385 break;1386 1325 case TypeData::Aggregate: 1387 1326 if ( td->aggregate.body ) { … … 1400 1339 return new ast::UnionInstType( 1401 1340 strict_dynamic_cast<ast::UnionDecl *>( typedecl ), 1341 buildQualifiers( td ) 1342 ); 1343 case ast::AggregateDecl::Enum: 1344 return new ast::EnumInstType( 1345 strict_dynamic_cast<ast::EnumDecl *>( typedecl ), 1402 1346 buildQualifiers( td ) 1403 1347 ); … … 1423 1367 buildQualifiers( td ) 1424 1368 ); 1369 case ast::AggregateDecl::Enum: 1370 return new ast::EnumInstType( 1371 *td->aggregate.name, 1372 buildQualifiers( td ) 1373 ); 1425 1374 case ast::AggregateDecl::Trait: 1426 1375 return new ast::TraitInstType( … … 1447 1396 TypeData * type = td->aggInst.aggregate; 1448 1397 switch ( type->kind ) { 1449 case TypeData::Enum:1450 return new ast::EnumInstType(1451 *type->enumeration.name,1452 buildQualifiers( type )1453 );1454 1398 case TypeData::Aggregate: 1455 1399 switch ( type->aggregate.kind ) { … … 1465 1409 case ast::AggregateDecl::Union: 1466 1410 ret = new ast::UnionInstType( 1411 *type->aggregate.name, 1412 buildQualifiers( type ) 1413 ); 1414 break; 1415 case ast::AggregateDecl::Enum: 1416 ret = new ast::EnumInstType( 1467 1417 *type->aggregate.name, 1468 1418 buildQualifiers( type ) … … 1526 1476 std::vector<ast::ptr<ast::Attribute>> && attributes, 1527 1477 ast::Linkage::Spec linkage ) { 1528 assert( td->kind == TypeData::Enum ); 1478 assert( td->kind == TypeData::Aggregate ); 1479 assert( td->aggregate.kind == ast::AggregateDecl::Enum ); 1529 1480 ast::Type * baseType = td->base ? typebuild(td->base) : nullptr; 1530 1481 ast::EnumDecl * ret = new ast::EnumDecl( 1531 1482 td->location, 1532 *td-> enumeration.name,1533 td-> enumeration.typed,1483 *td->aggregate.name, 1484 td->aggregate.typed, 1534 1485 std::move( attributes ), 1535 1486 linkage, 1536 1487 baseType 1537 1488 ); 1538 buildList( td-> enumeration.constants, ret->members );1489 buildList( td->aggregate.fields, ret->members ); 1539 1490 auto members = ret->members.begin(); 1540 ret->hide = td-> enumeration.hiding == EnumHiding::Hide ? ast::EnumDecl::EnumHiding::Hide : ast::EnumDecl::EnumHiding::Visible;1541 for ( const DeclarationNode * cur = td-> enumeration.constants; cur != nullptr; cur = cur->next, ++members ) {1491 ret->hide = td->aggregate.hiding == EnumHiding::Hide ? ast::EnumDecl::EnumHiding::Hide : ast::EnumDecl::EnumHiding::Visible; 1492 for ( const DeclarationNode * cur = td->aggregate.fields ; cur != nullptr ; cur = cur->next, ++members ) { 1542 1493 if ( cur->enumInLine ) { 1543 1494 // Do Nothing … … 1560 1511 // if 1561 1512 } // for 1562 ret->body = td-> enumeration.body;1513 ret->body = td->aggregate.body; 1563 1514 return ret; 1564 1515 } // buildEnum … … 1704 1655 } else if ( td->kind == TypeData::Aggregate ) { 1705 1656 return buildAggregate( td, std::move( attributes ), linkage ); 1706 } else if ( td->kind == TypeData::Enum ) {1707 return buildEnum( td, std::move( attributes ), linkage );1708 1657 } else if ( td->kind == TypeData::Symbolic ) { 1709 1658 return buildSymbolic( td, std::move( attributes ), name, scs, linkage );
Note: See TracChangeset
for help on using the changeset viewer.