Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r7880579 r13e3b50  
    4848        newnode->type = maybeClone( type );
    4949        newnode->name = name;
    50         newnode->storageClasses = storageClasses;
     50        newnode->storageClass = storageClass;
     51        newnode->isInline = isInline;
     52        newnode->isNoreturn = isNoreturn;
    5153        newnode->bitfieldWidth = bitfieldWidth;
    5254        newnode->hasEllipsis = hasEllipsis;
     
    5759} // DeclarationNode::clone
    5860
    59 DeclarationNode::DeclarationNode() : type( 0 ), bitfieldWidth( 0 ), initializer( 0 ), hasEllipsis( false ), linkage( ::linkage ) {
     61DeclarationNode::DeclarationNode()
     62        : type( 0 )
     63        , storageClass( NoStorageClass )
     64        , isInline( false )
     65        , isNoreturn( false )
     66        , bitfieldWidth( 0 )
     67        , initializer( 0 )
     68        , hasEllipsis( false )
     69        , linkage( ::linkage )
     70        , extension( false )
     71        , error() {
    6072}
    6173
     
    8294        } // if
    8395
    84         printEnums( storageClasses.begin(), storageClasses.end(), DeclarationNode::storageName, os );
     96        if(storageClass != NoStorageClass) os << DeclarationNode::storageName[storageClass] << ' ';
     97        if(isInline) os << DeclarationNode::storageName[Inline] << ' ';
     98        if(isNoreturn) os << DeclarationNode::storageName[Noreturn] << ' ';
    8599        if ( type ) {
    86100                type->print( os, indent );
     
    143157DeclarationNode *DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) {
    144158        DeclarationNode *newnode = new DeclarationNode;
    145         newnode->storageClasses.push_back( sc );
     159        switch (sc) {
     160                case Inline: newnode->isInline = true; break;
     161                case Noreturn: newnode->isNoreturn = true; break;
     162                default: newnode->storageClass = sc; break;
     163        }
    146164        return newnode;
    147165} // DeclarationNode::newStorageClass
     
    359377DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) {
    360378        if ( q ) {
    361                 storageClasses.splice( storageClasses.end(), q->storageClasses );
     379                copyStorageClasses(q);
    362380                if ( q->type ) {
    363381                        if ( ! type ) {
     
    386404
    387405DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) {
    388         storageClasses = q->storageClasses;
     406        isInline = isInline || q->isInline;
     407        isNoreturn = isNoreturn || q->isNoreturn;
     408        if(storageClass == NoStorageClass) {
     409                storageClass = q->storageClass;
     410        }
     411        else if (q->storageClass != NoStorageClass) {
     412                q->error = "invalid combination of storage classes in declaration of ";
     413        }
     414        if(error.empty()) error = q->error;
    389415        return this;
    390416}
     
    446472DeclarationNode *DeclarationNode::addType( DeclarationNode *o ) {
    447473        if ( o ) {
    448                 storageClasses.splice( storageClasses.end(), o->storageClasses );
     474                copyStorageClasses( o );
    449475                if ( o->type ) {
    450476                        if ( ! type ) {
     
    693719        } // if
    694720        newnode->type->forall = maybeClone( type->forall );
    695         newnode->storageClasses = storageClasses;
     721        newnode->copyStorageClasses( this );
    696722        newnode->name = assign_strptr( newName );
    697723        return newnode;
     
    700726DeclarationNode *DeclarationNode::cloneBaseType( DeclarationNode *o ) {
    701727        if ( o ) {
    702                 o->storageClasses.insert( o->storageClasses.end(), storageClasses.begin(), storageClasses.end() );
     728                o->copyStorageClasses( this );
    703729                if ( type ) {
    704730                        TypeData *srcType = type;
     
    733759        DeclarationNode *newnode = new DeclarationNode;
    734760        newnode->type = maybeClone( type );
    735         newnode->storageClasses = storageClasses;
     761        newnode->copyStorageClasses( this );
    736762        newnode->name = assign_strptr( newName );
    737763        return newnode;
     
    740766DeclarationNode *DeclarationNode::cloneType( DeclarationNode *o ) {
    741767        if ( o ) {
    742                 o->storageClasses.insert( o->storageClasses.end(), storageClasses.begin(), storageClasses.end() );
     768                o->copyStorageClasses( this );
    743769                if ( type ) {
    744770                        TypeData *newType = type->clone();
     
    855881
    856882Declaration *DeclarationNode::build() const {
     883        if( !error.empty() ) throw SemanticError( error, this );
    857884        if ( type ) {
    858                 return type->buildDecl( name, buildStorageClass(), maybeBuild< Expression >( bitfieldWidth ), buildFuncSpecifier( Inline ), buildFuncSpecifier( Noreturn ), linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
    859         } // if
    860         if ( ! buildFuncSpecifier( Inline ) && ! buildFuncSpecifier( Noreturn ) ) {
    861                 return (new ObjectDecl( name, buildStorageClass(), linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ))->set_extension( extension );
     885                return type->buildDecl( name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
     886        } // if
     887        if ( ! isInline && ! isNoreturn ) {
     888                return (new ObjectDecl( name, storageClass, linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ))->set_extension( extension );
    862889        } // if
    863890        throw SemanticError( "invalid function specifier in declaration of ", this );
     
    898925}
    899926
    900 DeclarationNode::StorageClass DeclarationNode::buildStorageClass() const {
    901         DeclarationNode::StorageClass ret = DeclarationNode::NoStorageClass;
    902         for ( std::list< DeclarationNode::StorageClass >::const_iterator i = storageClasses.begin(); i != storageClasses.end(); ++i ) {
    903           if ( *i == DeclarationNode::Inline || *i == DeclarationNode::Noreturn ) continue; // ignore function specifiers
    904           if ( ret != DeclarationNode::NoStorageClass ) {       // already have a valid storage class ?
    905                         throw SemanticError( "invalid combination of storage classes in declaration of ", this );
    906                 } // if
    907                 ret = *i;
    908         } // for
    909         return ret;
    910 }
    911 
    912 bool DeclarationNode::buildFuncSpecifier( DeclarationNode::StorageClass key ) const {
    913         std::list< DeclarationNode::StorageClass >::const_iterator first = std::find( storageClasses.begin(), storageClasses.end(), key );
    914   if ( first == storageClasses.end() ) return false;    // not found
    915         first = std::find( ++first, storageClasses.end(), key ); // found
    916   if ( first == storageClasses.end() ) return true;             // not found again
    917         throw SemanticError( "duplicate function specifier in declaration of ", this );
    918 }
     927// DeclarationNode::StorageClass DeclarationNode::buildStorageClass() const {
     928//      DeclarationNode::StorageClass ret = DeclarationNode::NoStorageClass;
     929//      for ( std::list< DeclarationNode::StorageClass >::const_iterator i = storageClasses.begin(); i != storageClasses.end(); ++i ) {
     930//        if ( *i == DeclarationNode::Inline || *i == DeclarationNode::Noreturn ) continue; // ignore function specifiers
     931//        if ( ret != DeclarationNode::NoStorageClass ) {       // already have a valid storage class ?
     932//                      throw SemanticError( "invalid combination of storage classes in declaration of ", this );
     933//              } // if
     934//              ret = *i;
     935//      } // for
     936//      return ret;
     937// }
     938
     939// bool DeclarationNode::buildFuncSpecifier( DeclarationNode::StorageClass key ) const {
     940//      std::list< DeclarationNode::StorageClass >::const_iterator first = std::find( storageClasses.begin(), storageClasses.end(), key );
     941//   if ( first == storageClasses.end() ) return false; // not found
     942//      first = std::find( ++first, storageClasses.end(), key ); // found
     943//   if ( first == storageClasses.end() ) return true;          // not found again
     944//      throw SemanticError( "duplicate function specifier in declaration of ", this );
     945// }
    919946
    920947// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.