Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    rc0aa336 r44a81853  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Feb  6 16:01:29 2017
    13 // Update Count     : 739
     12// Last Modified On : Sat Jan 14 14:36:23 2017
     13// Update Count     : 669
    1414//
    1515
     
    8383DeclarationNode * DeclarationNode::clone() const {
    8484        DeclarationNode * newnode = new DeclarationNode;
    85         newnode->set_next( maybeClone( get_next() ) );
     85        newnode->type = maybeClone( type );
    8686        newnode->name = name ? new string( *name ) : nullptr;
    87 
    88         newnode->type = maybeClone( type );
    8987        newnode->storageClass = storageClass;
    90         newnode->bitfieldWidth = maybeClone( bitfieldWidth );
    9188        newnode->isInline = isInline;
    9289        newnode->isNoreturn = isNoreturn;
    93         newnode->enumeratorValue.reset( maybeClone( enumeratorValue.get() ) );
     90        newnode->bitfieldWidth = maybeClone( bitfieldWidth );
    9491        newnode->hasEllipsis = hasEllipsis;
     92        newnode->initializer = maybeClone( initializer );
     93        newnode->set_next( maybeClone( get_next() ) );
    9594        newnode->linkage = linkage;
    9695        newnode->asmName = maybeClone( asmName );
    97         cloneAll( attributes, newnode->attributes );
    98         newnode->initializer = maybeClone( initializer );
    99         newnode->extension = extension;
    100         newnode->error = error;
    10196
    10297//      newnode->variable.name = variable.name ? new string( *variable.name ) : nullptr;
     
    164159        newnode->type->function.newStyle = newStyle;
    165160        newnode->type->function.body = body;
    166 
    167161        // ignore unnamed routine declarations: void p( int (*)(int) );
    168162        if ( newnode->name ) {
     
    442436        } // if
    443437        appendError( error, q->error );
    444 } // DeclarationNode::checkStorageClasses
     438} // DeclarationNode::copyStorageClasses
    445439
    446440DeclarationNode * DeclarationNode::copyStorageClasses( DeclarationNode * q ) {
     
    452446                storageClass = q->storageClass;
    453447        } // if
    454 
    455         for ( Attribute *attr: reverseIterate( q->attributes ) ) {
    456                 attributes.push_front( attr->clone() );
    457         } // for
     448        attributes.splice( attributes.end(), q->attributes );
    458449        return this;
    459450} // DeclarationNode::copyStorageClasses
     
    665656}
    666657
    667 DeclarationNode * DeclarationNode::addAsmName( DeclarationNode * newname ) {
     658DeclarationNode * DeclarationNode::addAsmName( ConstantExpr * newname ) {
    668659        assert( ! asmName );
    669         asmName = newname ? newname->asmName : nullptr;
    670         return this->addQualifiers( newname );
     660        asmName = newname;
     661        return this;
    671662}
    672663
     
    699690}
    700691
    701 DeclarationNode * DeclarationNode::setBase( TypeData * newType ) {
     692static void setBase( TypeData *&type, TypeData * newType ) {
    702693        if ( type ) {
    703694                TypeData * prevBase = type;
     
    711702                type = newType;
    712703        } // if
    713         return this;
    714 }
    715 
    716 DeclarationNode * 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
     704}
    725705
    726706DeclarationNode * DeclarationNode::addPointer( DeclarationNode * p ) {
    727707        if ( p ) {
    728708                assert( p->type->kind == TypeData::Pointer );
    729                 setBase( p->type );
     709                setBase( type, p->type );
    730710                p->type = nullptr;
    731                 copyAttribute( p );
    732711                delete p;
    733712        } // if
     
    738717        if ( a ) {
    739718                assert( a->type->kind == TypeData::Array );
    740                 setBase( a->type );
     719                setBase( type, a->type );
    741720                a->type = nullptr;
    742                 copyAttribute( a );
    743721                delete a;
    744722        } // if
     
    812790        TypeData * ftype = new TypeData( TypeData::Function );
    813791        ftype->function.params = params;
    814         setBase( ftype );
     792        setBase( type, ftype );
    815793        return this;
    816794}
     
    858836                TypeData * srcType = type;
    859837
    860                 // search for the base type by scanning off pointers and array designators
    861838                while ( srcType->base ) {
    862839                        srcType = srcType->base;
     
    1009986        if ( attr.expr ) {
    1010987//              return new AttrType( buildQualifiers( type ), *attr.name, attr.expr->build() );
    1011                 return new AttrType( buildQualifiers( type ), *name, attr.expr->build(), attributes );
     988                return new AttrType( buildQualifiers( type ), *name, attr.expr->build() );
    1012989        } else if ( attr.type ) {
    1013990//              return new AttrType( buildQualifiers( type ), *attr.name, attr.type->buildType() );
    1014                 return new AttrType( buildQualifiers( type ), *name, attr.type->buildType(), attributes );
     991                return new AttrType( buildQualifiers( type ), *name, attr.type->buildType() );
    1015992        } // if
    1016993
    1017994        switch ( type->kind ) {
    1018           case TypeData::Enum: {
    1019                   EnumDecl * typedecl = buildEnum( type, attributes );
    1020                   return new EnumInstType( buildQualifiers( type ), typedecl );
    1021           }
     995          case TypeData::Enum:
     996                return new EnumInstType( buildQualifiers( type ), *type->enumeration.name );
    1022997          case TypeData::Aggregate: {
    1023                   AggregateDecl * typedecl = buildAggregate( type, attributes );
    1024998                  ReferenceToType * ret;
    1025999                  switch ( type->aggregate.kind ) {
    10261000                        case DeclarationNode::Struct:
    1027                           ret = new StructInstType( buildQualifiers( type ), (StructDecl *)typedecl );
     1001                          ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name );
    10281002                          break;
    10291003                        case DeclarationNode::Union:
    1030                           ret = new UnionInstType( buildQualifiers( type ), (UnionDecl *)typedecl );
     1004                          ret = new UnionInstType( buildQualifiers( type ), *type->aggregate.name );
    10311005                          break;
    10321006                        case DeclarationNode::Trait:
    1033                           assert( false );
    1034                           //ret = new TraitInstType( buildQualifiers( type ), (TraitDecl *)typedecl );
     1007                          ret = new TraitInstType( buildQualifiers( type ), *type->aggregate.name );
    10351008                          break;
    10361009                        default:
     
    10411014          }
    10421015          case TypeData::Symbolic: {
    1043                   TypeInstType * ret = new TypeInstType( buildQualifiers( type ), *type->symbolic.name, false, attributes );
     1016                  TypeInstType * ret = new TypeInstType( buildQualifiers( type ), *type->symbolic.name, false );
    10441017                  buildList( type->symbolic.actuals, ret->get_parameters() );
    10451018                  return ret;
    10461019          }
    10471020          default:
    1048                 Type * simpletypes = typebuild( type );
    1049                 simpletypes->get_attributes() = attributes;             // copy because member is const
    1050                 return simpletypes;
     1021                return typebuild( type );
    10511022        } // switch
    10521023}
Note: See TracChangeset for help on using the changeset viewer.