Ignore:
Timestamp:
Apr 8, 2024, 11:57:37 AM (21 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
485cf59, dd37afa
Parents:
d3a49864 (diff), d9bad51 (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/TypeData.cc

    rd3a49864 rcb98d9d  
    475475
    476476
     477// Wrap an aggregate up in an instance. Takes and gives ownership.
     478static TypeData * makeInstance( TypeData * type ) {
     479        assert( TypeData::Aggregate == type->kind );
     480        TypeData * out = new TypeData( TypeData::AggregateInst );
     481        out->aggInst.aggregate = type;
     482        out->aggInst.params = maybeCopy( type->aggregate.actuals );
     483        out->aggInst.hoistType = type->aggregate.body;
     484        out->qualifiers |= type->qualifiers;
     485        return out;
     486}
     487
     488
    477489TypeData * build_type_qualifier( ast::CV::Qualifiers tq ) {
    478490        TypeData * type = new TypeData;
     
    564576
    565577// Takes ownership of all arguments, gives ownership of return value.
    566 TypeData * addQualifiers( TypeData * ltype, TypeData * rtype ) {
    567         if ( ltype->forall ) {
    568                 if ( rtype->forall ) {
    569                         rtype->forall->set_last( ltype->forall );
    570                 } else if ( TypeData::Aggregate != rtype->kind ) {
    571                         rtype->forall = ltype->forall;
    572                 } else if ( rtype->aggregate.params ) {
    573                         rtype->aggregate.params->set_last( ltype->forall );
     578TypeData * addQualifiers( TypeData * dst, TypeData * src ) {
     579        if ( src->forall ) {
     580                if ( dst->forall || TypeData::Aggregate != dst->kind ) {
     581                        extend( dst->forall, src->forall );
    574582                } else {
    575                         rtype->aggregate.params = ltype->forall;
     583                        extend( dst->aggregate.params, src->forall );
    576584                }
    577                 ltype->forall = nullptr;
     585                src->forall = nullptr;
    578586        }
    579587
    580         addQualifiersToType( rtype, ltype );
    581         return rtype;
     588        addQualifiersToType( dst, src );
     589        return dst;
    582590}
    583591
     
    585593static void addTypeToType( TypeData *& dst, TypeData *& src ) {
    586594        if ( src->forall && dst->kind == TypeData::Function ) {
    587                 if ( dst->forall ) {
    588                         dst->forall->set_last( src->forall );
    589                 } else {
    590                         dst->forall = src->forall;
    591                 } // if
     595                extend( dst->forall, src->forall );
    592596                src->forall = nullptr;
    593597        } // if
     
    641645                break;
    642646        default:
    643                 switch ( src->kind ) {
    644                 case TypeData::Aggregate:
    645                         dst->base = new TypeData( TypeData::AggregateInst );
    646                         dst->base->aggInst.aggregate = src;
    647                         if ( src->kind == TypeData::Aggregate ) {
    648                                 dst->base->aggInst.params = maybeCopy( src->aggregate.actuals );
    649                         } // if
    650                         dst->base->qualifiers |= src->qualifiers;
    651                         src = nullptr;
    652                         break;
    653                 default:
    654                         if ( dst->forall ) {
    655                                 dst->forall->set_last( src->forall );
    656                         } else {
    657                                 dst->forall = src->forall;
    658                         } // if
     647                if ( TypeData::Aggregate == src->kind ) {
     648                        dst->base = makeInstance( src );
     649                } else {
     650                        extend( dst->forall, src->forall );
    659651                        src->forall = nullptr;
    660652                        dst->base = src;
    661                         src = nullptr;
    662                 } // switch
     653                }
     654                src = nullptr;
    663655        } // switch
    664656}
    665657
    666658// Takes ownership of all arguments, gives ownership of return value.
    667 TypeData * addType( TypeData * ltype, TypeData * rtype, std::vector<ast::ptr<ast::Attribute>> & attributes ) {
    668         if ( rtype ) {
    669                 addTypeToType( rtype, ltype );
    670                 return rtype;
     659TypeData * addType( TypeData * dst, TypeData * src, std::vector<ast::ptr<ast::Attribute>> & attributes ) {
     660        if ( dst ) {
     661                addTypeToType( dst, src );
     662        } else if ( src->kind == TypeData::Aggregate ) {
     663                // Hide type information aggregate instances.
     664                dst = makeInstance( src );
     665                dst->aggInst.aggregate->aggregate.attributes.swap( attributes );
    671666        } else {
    672                 if ( ltype->kind == TypeData::Aggregate ) {
    673                         // Hide type information aggregate instances.
    674                         rtype = new TypeData( TypeData::AggregateInst );
    675                         rtype->aggInst.aggregate = ltype;
    676                         rtype->aggInst.aggregate->aggregate.attributes.swap( attributes ); // change ownership
    677                         rtype->aggInst.hoistType = ltype->aggregate.body;
    678                         rtype->aggInst.params = maybeCopy( ltype->aggregate.actuals );
    679                         rtype->qualifiers |= ltype->qualifiers;
    680                 } else {
    681                         rtype = ltype;
    682                 } // if
    683                 return rtype;
     667                dst = src;
    684668        } // if
    685 }
    686 
    687 TypeData * addType( TypeData * ltype, TypeData * rtype ) {
     669        return dst;
     670}
     671
     672TypeData * addType( TypeData * dst, TypeData * src ) {
    688673        std::vector<ast::ptr<ast::Attribute>> attributes;
    689         return addType( ltype, rtype, attributes );
     674        return addType( dst, src, attributes );
    690675}
    691676
     
    713698
    714699TypeData * makeNewBase( TypeData * type ) {
    715         switch ( type->kind ) {
    716         case TypeData::Aggregate: {
    717                 TypeData * out = new TypeData( TypeData::AggregateInst );
    718                 out->aggInst.aggregate = type;
    719                 if ( TypeData::Aggregate == type->kind ) {
    720                         out->aggInst.params = maybeCopy( type->aggregate.actuals );
    721                 }
    722                 out->qualifiers |= type->qualifiers;
    723                 return out;
    724         }
    725         default:
    726                 return type;
    727         } // switch
     700        return ( TypeData::Aggregate == type->kind ) ? makeInstance( type ) : type;
    728701}
    729702
Note: See TracChangeset for help on using the changeset viewer.