Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r44a81853 rc0aa336  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jan 14 14:36:23 2017
    13 // Update Count     : 669
     12// Last Modified On : Mon Feb  6 16:01:29 2017
     13// Update Count     : 739
    1414//
    1515
     
    8383DeclarationNode * DeclarationNode::clone() const {
    8484        DeclarationNode * newnode = new DeclarationNode;
     85        newnode->set_next( maybeClone( get_next() ) );
     86        newnode->name = name ? new string( *name ) : nullptr;
     87
    8588        newnode->type = maybeClone( type );
    86         newnode->name = name ? new string( *name ) : nullptr;
    8789        newnode->storageClass = storageClass;
     90        newnode->bitfieldWidth = maybeClone( bitfieldWidth );
    8891        newnode->isInline = isInline;
    8992        newnode->isNoreturn = isNoreturn;
    90         newnode->bitfieldWidth = maybeClone( bitfieldWidth );
     93        newnode->enumeratorValue.reset( maybeClone( enumeratorValue.get() ) );
    9194        newnode->hasEllipsis = hasEllipsis;
    92         newnode->initializer = maybeClone( initializer );
    93         newnode->set_next( maybeClone( get_next() ) );
    9495        newnode->linkage = linkage;
    9596        newnode->asmName = maybeClone( asmName );
     97        cloneAll( attributes, newnode->attributes );
     98        newnode->initializer = maybeClone( initializer );
     99        newnode->extension = extension;
     100        newnode->error = error;
    96101
    97102//      newnode->variable.name = variable.name ? new string( *variable.name ) : nullptr;
     
    159164        newnode->type->function.newStyle = newStyle;
    160165        newnode->type->function.body = body;
     166
    161167        // ignore unnamed routine declarations: void p( int (*)(int) );
    162168        if ( newnode->name ) {
     
    436442        } // if
    437443        appendError( error, q->error );
    438 } // DeclarationNode::copyStorageClasses
     444} // DeclarationNode::checkStorageClasses
    439445
    440446DeclarationNode * DeclarationNode::copyStorageClasses( DeclarationNode * q ) {
     
    446452                storageClass = q->storageClass;
    447453        } // if
    448         attributes.splice( attributes.end(), q->attributes );
     454
     455        for ( Attribute *attr: reverseIterate( q->attributes ) ) {
     456                attributes.push_front( attr->clone() );
     457        } // for
    449458        return this;
    450459} // DeclarationNode::copyStorageClasses
     
    656665}
    657666
    658 DeclarationNode * DeclarationNode::addAsmName( ConstantExpr * newname ) {
     667DeclarationNode * DeclarationNode::addAsmName( DeclarationNode * newname ) {
    659668        assert( ! asmName );
    660         asmName = newname;
    661         return this;
     669        asmName = newname ? newname->asmName : nullptr;
     670        return this->addQualifiers( newname );
    662671}
    663672
     
    690699}
    691700
    692 static void setBase( TypeData *&type, TypeData * newType ) {
     701DeclarationNode * DeclarationNode::setBase( TypeData * newType ) {
    693702        if ( type ) {
    694703                TypeData * prevBase = type;
     
    702711                type = newType;
    703712        } // if
    704 }
     713        return this;
     714}
     715
     716DeclarationNode * DeclarationNode::copyAttribute( DeclarationNode * a ) {
     717        if ( a ) {
     718                for ( Attribute *attr: reverseIterate( a->attributes ) ) {
     719                        attributes.push_front( attr );
     720                } // for
     721                a->attributes.clear();
     722        } // if
     723        return this;
     724} // copyAttribute
    705725
    706726DeclarationNode * DeclarationNode::addPointer( DeclarationNode * p ) {
    707727        if ( p ) {
    708728                assert( p->type->kind == TypeData::Pointer );
    709                 setBase( type, p->type );
     729                setBase( p->type );
    710730                p->type = nullptr;
     731                copyAttribute( p );
    711732                delete p;
    712733        } // if
     
    717738        if ( a ) {
    718739                assert( a->type->kind == TypeData::Array );
    719                 setBase( type, a->type );
     740                setBase( a->type );
    720741                a->type = nullptr;
     742                copyAttribute( a );
    721743                delete a;
    722744        } // if
     
    790812        TypeData * ftype = new TypeData( TypeData::Function );
    791813        ftype->function.params = params;
    792         setBase( type, ftype );
     814        setBase( ftype );
    793815        return this;
    794816}
     
    836858                TypeData * srcType = type;
    837859
     860                // search for the base type by scanning off pointers and array designators
    838861                while ( srcType->base ) {
    839862                        srcType = srcType->base;
     
    9861009        if ( attr.expr ) {
    9871010//              return new AttrType( buildQualifiers( type ), *attr.name, attr.expr->build() );
    988                 return new AttrType( buildQualifiers( type ), *name, attr.expr->build() );
     1011                return new AttrType( buildQualifiers( type ), *name, attr.expr->build(), attributes );
    9891012        } else if ( attr.type ) {
    9901013//              return new AttrType( buildQualifiers( type ), *attr.name, attr.type->buildType() );
    991                 return new AttrType( buildQualifiers( type ), *name, attr.type->buildType() );
     1014                return new AttrType( buildQualifiers( type ), *name, attr.type->buildType(), attributes );
    9921015        } // if
    9931016
    9941017        switch ( type->kind ) {
    995           case TypeData::Enum:
    996                 return new EnumInstType( buildQualifiers( type ), *type->enumeration.name );
     1018          case TypeData::Enum: {
     1019                  EnumDecl * typedecl = buildEnum( type, attributes );
     1020                  return new EnumInstType( buildQualifiers( type ), typedecl );
     1021          }
    9971022          case TypeData::Aggregate: {
     1023                  AggregateDecl * typedecl = buildAggregate( type, attributes );
    9981024                  ReferenceToType * ret;
    9991025                  switch ( type->aggregate.kind ) {
    10001026                        case DeclarationNode::Struct:
    1001                           ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name );
     1027                          ret = new StructInstType( buildQualifiers( type ), (StructDecl *)typedecl );
    10021028                          break;
    10031029                        case DeclarationNode::Union:
    1004                           ret = new UnionInstType( buildQualifiers( type ), *type->aggregate.name );
     1030                          ret = new UnionInstType( buildQualifiers( type ), (UnionDecl *)typedecl );
    10051031                          break;
    10061032                        case DeclarationNode::Trait:
    1007                           ret = new TraitInstType( buildQualifiers( type ), *type->aggregate.name );
     1033                          assert( false );
     1034                          //ret = new TraitInstType( buildQualifiers( type ), (TraitDecl *)typedecl );
    10081035                          break;
    10091036                        default:
     
    10141041          }
    10151042          case TypeData::Symbolic: {
    1016                   TypeInstType * ret = new TypeInstType( buildQualifiers( type ), *type->symbolic.name, false );
     1043                  TypeInstType * ret = new TypeInstType( buildQualifiers( type ), *type->symbolic.name, false, attributes );
    10171044                  buildList( type->symbolic.actuals, ret->get_parameters() );
    10181045                  return ret;
    10191046          }
    10201047          default:
    1021                 return typebuild( type );
     1048                Type * simpletypes = typebuild( type );
     1049                simpletypes->get_attributes() = attributes;             // copy because member is const
     1050                return simpletypes;
    10221051        } // switch
    10231052}
Note: See TracChangeset for help on using the changeset viewer.