Ignore:
Timestamp:
Mar 26, 2024, 3:17:51 PM (4 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
544b799
Parents:
84886499
Message:

Fused TypeData::Enum and TypeData::Aggregate, an enumeration is a kind of aggregate after all. There will always be some unused fields in Aggregate_t (but less in TypeData? overall) but the code is almost always simpler.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/TypeData.cc

    r84886499 r67467a3  
    7575                function.withExprs = nullptr;
    7676                break;
    77         case Enum:
    78                 enumeration.name = nullptr;
    79                 enumeration.constants = nullptr;
    80                 enumeration.body = false;
    81                 enumeration.anon = false;
    82                 break;
    8377        case Aggregate:
    8478                aggregate.kind = ast::AggregateDecl::NoAggregate;
     
    8983                aggregate.body = false;
    9084                aggregate.anon = false;
     85                aggregate.typed = false;
     86                aggregate.hiding = EnumHiding::Visible;
    9187                break;
    9288        case AggregateInst:
     
    153149                delete aggInst.aggregate;
    154150                delete aggInst.params;
    155                 break;
    156         case Enum:
    157                 delete enumeration.name;
    158                 delete enumeration.constants;
    159151                break;
    160152        case Symbolic:
     
    231223                newtype->aggInst.hoistType = aggInst.hoistType;
    232224                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;
    239225        case Symbolic:
    240226        case SymbolicInst:
     
    375361                        os << string( indent + 2, ' ' ) << "with parameters" << endl;
    376362                        aggInst.params->printList( os, indent + 2 );
    377                 } // if
    378                 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                 } // if
    385                 if ( enumeration.body ) {
    386                         os << string( indent + 2, ' ' ) << "with body" << endl;
    387                 } // if
    388                 if ( base ) {
    389                         os << "for ";
    390                         base->print( os, indent + 2 );
    391363                } // if
    392364                break;
     
    483455        case Aggregate:
    484456                return aggregate.name;
    485         case Enum:
    486                 return enumeration.name;
    487457        case Symbolic:
    488458        case SymbolicInst:
     
    673643                switch ( src->kind ) {
    674644                case TypeData::Aggregate:
    675                 case TypeData::Enum:
    676645                        dst->base = new TypeData( TypeData::AggregateInst );
    677646                        dst->base->aggInst.aggregate = src;
     
    701670                return rtype;
    702671        } else {
    703                 if ( ltype->kind == TypeData::Aggregate || ltype->kind == TypeData::Enum ) {
     672                if ( ltype->kind == TypeData::Aggregate ) {
    704673                        // Hide type information aggregate instances.
    705674                        rtype = new TypeData( TypeData::AggregateInst );
    706675                        rtype->aggInst.aggregate = ltype;
    707676                        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 );
    714679                        rtype->qualifiers |= ltype->qualifiers;
    715680                } else {
     
    730695        if ( newType->kind == TypeData::AggregateInst ) {
    731696                // 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;
    742701                // don't hoist twice
    743702                newType->aggInst.hoistType = false;
     
    755714TypeData * makeNewBase( TypeData * type ) {
    756715        switch ( type->kind ) {
    757         case TypeData::Aggregate:
    758         case TypeData::Enum: {
     716        case TypeData::Aggregate: {
    759717                TypeData * out = new TypeData( TypeData::AggregateInst );
    760718                out->aggInst.aggregate = type;
     
    11231081                );
    11241082        case TypeData::Symbolic:
    1125         case TypeData::Enum:
    11261083        case TypeData::Aggregate:
    11271084                assert( false );
     
    11381095        case TypeData::Aggregate:
    11391096                if ( ! toplevel && td->aggregate.body ) {
    1140                         ret = td->clone();
    1141                 } // if
    1142                 break;
    1143         case TypeData::Enum:
    1144                 if ( ! toplevel && td->enumeration.body ) {
    11451097                        ret = td->clone();
    11461098                } // if
     
    13451297                buildForall( td->aggregate.params, at->params );
    13461298                break;
     1299        case ast::AggregateDecl::Enum:
     1300                return buildEnum( td, std::move( attributes ), linkage );
    13471301        case ast::AggregateDecl::Trait:
    13481302                at = new ast::TraitDecl( td->location,
     
    13691323                ast::Linkage::Spec linkage ) {
    13701324        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                 } // if
    1385                 break;
    13861325        case TypeData::Aggregate:
    13871326                if ( td->aggregate.body ) {
     
    14001339                                return new ast::UnionInstType(
    14011340                                        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 ),
    14021346                                        buildQualifiers( td )
    14031347                                );
     
    14231367                                        buildQualifiers( td )
    14241368                                );
     1369                        case ast::AggregateDecl::Enum:
     1370                                return new ast::EnumInstType(
     1371                                        *td->aggregate.name,
     1372                                        buildQualifiers( td )
     1373                                );
    14251374                        case ast::AggregateDecl::Trait:
    14261375                                return new ast::TraitInstType(
     
    14471396        TypeData * type = td->aggInst.aggregate;
    14481397        switch ( type->kind ) {
    1449         case TypeData::Enum:
    1450                 return new ast::EnumInstType(
    1451                         *type->enumeration.name,
    1452                         buildQualifiers( type )
    1453                 );
    14541398        case TypeData::Aggregate:
    14551399                switch ( type->aggregate.kind ) {
     
    14651409                case ast::AggregateDecl::Union:
    14661410                        ret = new ast::UnionInstType(
     1411                                *type->aggregate.name,
     1412                                buildQualifiers( type )
     1413                        );
     1414                        break;
     1415                case ast::AggregateDecl::Enum:
     1416                        ret = new ast::EnumInstType(
    14671417                                *type->aggregate.name,
    14681418                                buildQualifiers( type )
     
    15261476                std::vector<ast::ptr<ast::Attribute>> && attributes,
    15271477                ast::Linkage::Spec linkage ) {
    1528         assert( td->kind == TypeData::Enum );
     1478        assert( td->kind == TypeData::Aggregate );
     1479        assert( td->aggregate.kind == ast::AggregateDecl::Enum );
    15291480        ast::Type * baseType = td->base ? typebuild(td->base) : nullptr;
    15301481        ast::EnumDecl * ret = new ast::EnumDecl(
    15311482                td->location,
    1532                 *td->enumeration.name,
    1533                 td->enumeration.typed,
     1483                *td->aggregate.name,
     1484                td->aggregate.typed,
    15341485                std::move( attributes ),
    15351486                linkage,
    15361487                baseType
    15371488        );
    1538         buildList( td->enumeration.constants, ret->members );
     1489        buildList( td->aggregate.fields, ret->members );
    15391490        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 ) {
    15421493                if ( cur->enumInLine ) {
    15431494                        // Do Nothing
     
    15601511                // if
    15611512        } // for
    1562         ret->body = td->enumeration.body;
     1513        ret->body = td->aggregate.body;
    15631514        return ret;
    15641515} // buildEnum
     
    17041655        } else if ( td->kind == TypeData::Aggregate ) {
    17051656                return buildAggregate( td, std::move( attributes ), linkage );
    1706         } else if ( td->kind == TypeData::Enum ) {
    1707                 return buildEnum( td, std::move( attributes ), linkage );
    17081657        } else if ( td->kind == TypeData::Symbolic ) {
    17091658                return buildSymbolic( td, std::move( attributes ), name, scs, linkage );
Note: See TracChangeset for help on using the changeset viewer.