Ignore:
Timestamp:
Feb 23, 2024, 6:52:33 PM (6 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
3d5a8cb
Parents:
624ba3a5
Message:

first attempt at correct distribution of attributes for aggregates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r624ba3a5 r4eb3a7c5  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Dec 14 19:05:17 2023
    13 // Update Count     : 1407
     12// Last Modified On : Fri Feb 23 18:25:57 2024
     13// Update Count     : 1533
    1414//
    1515
     
    159159
    160160        if ( ! attributes.empty() ) {
    161                 os << string( indent + 2, ' ' ) << "with attributes " << endl;
     161                os << string( indent + 2, ' ' ) << "with attributes" << endl;
    162162                for ( ast::ptr<ast::Attribute> const & attr : reverseIterate( attributes ) ) {
    163                         os << string( indent + 4, ' ' ) << attr->name.c_str() << endl;
     163                        os << string( indent + 4, ' ' );
     164                        ast::print( os, attr, indent + 2 );
    164165                } // for
    165166        } // if
     
    537538} // DeclarationNode::checkSpecifiers
    538539
    539 DeclarationNode * DeclarationNode::copySpecifiers( DeclarationNode * q ) {
     540DeclarationNode * DeclarationNode::copySpecifiers( DeclarationNode * q, bool copyattr ) {
    540541        funcSpecs |= q->funcSpecs;
    541542        storageClasses |= q->storageClasses;
    542543
    543         std::vector<ast::ptr<ast::Attribute>> tmp;
    544         tmp.reserve( q->attributes.size() );
    545         for ( auto const & attr : q->attributes ) {
    546                 tmp.emplace_back( ast::shallowCopy( attr.get() ) );
    547         }
    548         spliceBegin( attributes, tmp );
     544        if ( copyattr ) {
     545                std::vector<ast::ptr<ast::Attribute>> tmp;
     546                tmp.reserve( q->attributes.size() );
     547                for ( auto const & attr : q->attributes ) {
     548                        tmp.emplace_back( ast::shallowCopy( attr.get() ) );
     549                } // for
     550                spliceBegin( attributes, tmp );
     551        } // if
    549552
    550553        return this;
     
    681684}
    682685
    683 DeclarationNode * DeclarationNode::addType( DeclarationNode * o ) {
     686DeclarationNode * DeclarationNode::addType( DeclarationNode * o, bool copyattr ) {
    684687        if ( o ) {
    685688                checkSpecifiers( o );
    686                 copySpecifiers( o );
     689                copySpecifiers( o, copyattr );
    687690                if ( o->type ) {
    688691                        if ( ! type ) {
    689692                                if ( o->type->kind == TypeData::Aggregate || o->type->kind == TypeData::Enum ) {
     693                                        // Hide type information aggregate instances.
    690694                                        type = new TypeData( TypeData::AggregateInst );
    691                                         type->aggInst.aggregate = o->type;
     695                                        type->aggInst.aggregate = o->type;      // change ownership
     696                                        type->aggInst.aggregate->aggregate.attributes.swap( o->attributes ); // change ownership                                       
    692697                                        if ( o->type->kind == TypeData::Aggregate ) {
    693698                                                type->aggInst.hoistType = o->type->aggregate.body;
     
    700705                                        type = o->type;
    701706                                } // if
    702                                 o->type = nullptr;
     707                                o->type = nullptr;                                              // change ownership
    703708                        } else {
    704709                                addTypeToType( o->type, type );
     
    953958}
    954959
    955 DeclarationNode * DeclarationNode::cloneBaseType( DeclarationNode * o ) {
     960DeclarationNode * DeclarationNode::cloneBaseType( DeclarationNode * o, bool copyattr ) {
    956961        if ( ! o ) return nullptr;
    957962
    958         o->copySpecifiers( this );
     963        o->copySpecifiers( this, copyattr );
    959964        if ( type ) {
    960965                TypeData * srcType = type;
     
    9991004                        DeclarationNode * newnode = new DeclarationNode;
    10001005                        newnode->type = ret;
     1006                        if ( ret->kind == TypeData::Aggregate ) {
     1007                                newnode->attributes.swap( ret->aggregate.attributes );
     1008                        } // if
    10011009                        return newnode;
    10021010                } // if
     
    11101118                                        if ( extr->type->kind == TypeData::Aggregate ) {
    11111119                                                // typedef struct { int A } B is the only case?
    1112                                                 extracted_named = !extr->type->aggregate.anon;
     1120                                                extracted_named = ! extr->type->aggregate.anon;
    11131121                                        } else if ( extr->type->kind == TypeData::Enum ) {
    11141122                                                // typedef enum { A } B is the only case?
    1115                                                 extracted_named = !extr->type->enumeration.anon;
     1123                                                extracted_named = ! extr->type->enumeration.anon;
    11161124                                        } else {
    11171125                                                extracted_named = true;
Note: See TracChangeset for help on using the changeset viewer.