Ignore:
Timestamp:
Feb 21, 2023, 4:24:34 PM (3 years ago)
Author:
caparson <caparson@…>
Branches:
ADT, ast-experimental, master
Children:
257a8f5, ce44c5f
Parents:
1180175 (diff), 9a533ba (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/DeclarationNode.cc

    r1180175 r640b3df  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug  8 17:07:00 2022
    13 // Update Count     : 1185
     12// Last Modified On : Thu Feb 16 14:12:03 2023
     13// Update Count     : 1388
    1414//
    1515
     
    6161        variable.initializer = nullptr;
    6262
    63 //      attr.name = nullptr;
    64         attr.expr = nullptr;
    65         attr.type = nullptr;
    66 
    6763        assert.condition = nullptr;
    6864        assert.message = nullptr;
     
    7066
    7167DeclarationNode::~DeclarationNode() {
    72 //      delete attr.name;
    73         delete attr.expr;
    74         delete attr.type;
    75 
    7668//      delete variable.name;
    7769        delete variable.assertions;
     
    115107        newnode->variable.initializer = maybeClone( variable.initializer );
    116108
    117 //      newnode->attr.name = attr.name ? new string( *attr.name ) : nullptr;
    118         newnode->attr.expr = maybeClone( attr.expr );
    119         newnode->attr.type = maybeClone( attr.type );
    120 
    121109        newnode->assert.condition = maybeClone( assert.condition );
    122110        newnode->assert.message = maybeClone( assert.message );
     
    154142        } // if
    155143
    156         for ( Attribute * attr: reverseIterate( attributes ) ) {
    157                 os << string( indent + 2, ' ' ) << "attr " << attr->name.c_str();
    158         } // for
     144        if ( ! attributes.empty() ) {
     145                os << string( indent + 2, ' ' ) << "with attributes " << endl;
     146                for ( Attribute * attr: reverseIterate( attributes ) ) {
     147                        os << string( indent + 4, ' ' ) << attr->name.c_str() << endl;
     148                } // for
     149        } // if
    159150
    160151        os << endl;
     
    244235        newnode->type = new TypeData( TypeData::Aggregate );
    245236        newnode->type->aggregate.kind = kind;
    246         newnode->type->aggregate.name = name == nullptr ? new string( DeclarationNode::anonymous.newName() ) : name;
     237        newnode->type->aggregate.anon = name == nullptr;
     238        newnode->type->aggregate.name = newnode->type->aggregate.anon ? new string( DeclarationNode::anonymous.newName() ) : name;
    247239        newnode->type->aggregate.actuals = actuals;
    248240        newnode->type->aggregate.fields = fields;
     
    250242        newnode->type->aggregate.tagged = false;
    251243        newnode->type->aggregate.parent = nullptr;
    252         newnode->type->aggregate.anon = name == nullptr;
    253244        return newnode;
    254245} // DeclarationNode::newAggregate
     
    257248        DeclarationNode * newnode = new DeclarationNode;
    258249        newnode->type = new TypeData( TypeData::Enum );
    259         newnode->type->enumeration.name = name == nullptr ? new string( DeclarationNode::anonymous.newName() ) : name;
     250        newnode->type->enumeration.anon = name == nullptr;
     251        newnode->type->enumeration.name = newnode->type->enumeration.anon ? new string( DeclarationNode::anonymous.newName() ) : name;
    260252        newnode->type->enumeration.constants = constants;
    261253        newnode->type->enumeration.body = body;
    262         newnode->type->enumeration.anon = name == nullptr;
    263254        newnode->type->enumeration.typed = typed;
    264255        newnode->type->enumeration.hiding = hiding;
     
    989980        for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
    990981                try {
    991                         bool extracted = false;
    992                         bool anon = false;
     982                        bool extracted = false, anon = false;
     983                        AggregateDecl * unionDecl = nullptr;
     984
    993985                        if ( DeclarationNode * extr = cur->extractAggregate() ) {
    994986                                // handle the case where a structure declaration is contained within an object or type declaration
     987
    995988                                Declaration * decl = extr->build();
    996989                                if ( decl ) {
    997                                         // hoist the structure declaration
     990                                        // Remember the declaration if it is a union aggregate ?
     991                                        unionDecl = dynamic_cast<UnionDecl *>( decl );
     992
    998993                                        decl->location = cur->location;
    999                                         * out++ = decl;
     994                                        *out++ = decl;
    1000995
    1001996                                        // need to remember the cases where a declaration contains an anonymous aggregate definition
     
    1003998                                        assert( extr->type );
    1004999                                        if ( extr->type->kind == TypeData::Aggregate ) {
     1000                                                // typedef struct { int A } B is the only case?
    10051001                                                anon = extr->type->aggregate.anon;
    10061002                                        } else if ( extr->type->kind == TypeData::Enum ) {
    1007                                                 // xxx - is it useful to have an implicit anonymous enum member?
     1003                                                // typedef enum { A } B is the only case?
    10081004                                                anon = extr->type->enumeration.anon;
    10091005                                        }
     
    10141010                        Declaration * decl = cur->build();
    10151011                        if ( decl ) {
     1012                                if ( TypedefDecl * typedefDecl = dynamic_cast<TypedefDecl *>( decl ) ) {
     1013                                        if ( unionDecl ) {                                      // is the typedef alias a union aggregate ?
     1014                                                // This code handles a special issue with the attribute transparent_union.
     1015                                                //
     1016                                                //    typedef union U { int i; } typedef_name __attribute__(( aligned(16) )) __attribute__(( transparent_union ))
     1017                                                //
     1018                                                // Here the attribute aligned goes with the typedef_name, so variables declared of this type are
     1019                                                // aligned.  However, the attribute transparent_union must be moved from the typedef_name to
     1020                                                // alias union U.  Currently, this is the only know attribute that must be moved from typedef to
     1021                                                // alias.
     1022
     1023                                                // If typedef is an alias for a union, then its alias type was hoisted above and remembered.
     1024                                                if ( UnionInstType * unionInstType = dynamic_cast<UnionInstType *>( typedefDecl->base ) ) {
     1025                                                        // Remove all transparent_union attributes from typedef and move to alias union.
     1026                                                        list<Attribute *>::iterator attr;
     1027                                                        for ( attr = unionInstType->attributes.begin(); attr != unionInstType->attributes.end(); ) { // forward order
     1028                                                                if ( (*attr)->name == "transparent_union" || (*attr)->name == "__transparent_union__" ) {
     1029                                                                        list<Attribute *>::iterator cur = attr; // remember current node
     1030                                                                        attr++;                         // advance iterator
     1031                                                                        unionDecl->attributes.emplace_back( *cur ); // move current
     1032                                                                        unionInstType->attributes.erase( cur ); // remove current
     1033                                                                } else {
     1034                                                                        attr++;                         // advance iterator
     1035                                                                } // if
     1036                                                        } // for
     1037                                                } // if
     1038                                        } // if
     1039                                } // if
     1040
    10161041                                // don't include anonymous declaration for named aggregates, but do include them for anonymous aggregates, e.g.:
    10171042                                // struct S {
     
    11761201        assert( type );
    11771202
    1178         if ( attr.expr ) {
    1179                 return new AttrType( buildQualifiers( type ), *name, attr.expr->build(), attributes );
    1180         } else if ( attr.type ) {
    1181                 return new AttrType( buildQualifiers( type ), *name, attr.type->buildType(), attributes );
    1182         } // if
    1183 
    11841203        switch ( type->kind ) {
    11851204          case TypeData::Enum:
Note: See TracChangeset for help on using the changeset viewer.