Changes in / [1f6d4624:7527e63]


Ignore:
Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r1f6d4624 r7527e63  
    4848        newnode->type = maybeClone( type );
    4949        newnode->name = name;
    50         newnode->storageClass = storageClass;
    51         newnode->isInline = isInline;
    52         newnode->isNoreturn = isNoreturn;
     50        newnode->storageClasses = storageClasses;
    5351        newnode->bitfieldWidth = bitfieldWidth;
    5452        newnode->hasEllipsis = hasEllipsis;
     
    5957} // DeclarationNode::clone
    6058
    61 DeclarationNode::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() {
     59DeclarationNode::DeclarationNode() : type( 0 ), bitfieldWidth( 0 ), initializer( 0 ), hasEllipsis( false ), linkage( ::linkage ) {
    7260}
    7361
     
    9482        } // if
    9583
    96         if(storageClass != NoStorageClass) os << DeclarationNode::storageName[storageClass] << ' ';
    97         if(isInline) os << DeclarationNode::storageName[Inline] << ' ';
    98         if(isNoreturn) os << DeclarationNode::storageName[Noreturn] << ' ';
     84        printEnums( storageClasses.begin(), storageClasses.end(), DeclarationNode::storageName, os );
    9985        if ( type ) {
    10086                type->print( os, indent );
     
    157143DeclarationNode *DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) {
    158144        DeclarationNode *newnode = new DeclarationNode;
    159         switch (sc) {
    160                 case Inline: newnode->isInline = true; break;
    161                 case Noreturn: newnode->isNoreturn = true; break;
    162                 default: newnode->storageClass = sc; break;
    163         }
     145        newnode->storageClasses.push_back( sc );
    164146        return newnode;
    165147} // DeclarationNode::newStorageClass
     
    377359DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) {
    378360        if ( q ) {
    379                 copyStorageClasses(q);
     361                storageClasses.splice( storageClasses.end(), q->storageClasses );
    380362                if ( q->type ) {
    381363                        if ( ! type ) {
     
    404386
    405387DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) {
    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;
     388        storageClasses = q->storageClasses;
    415389        return this;
    416390}
     
    472446DeclarationNode *DeclarationNode::addType( DeclarationNode *o ) {
    473447        if ( o ) {
    474                 copyStorageClasses( o );
     448                storageClasses.splice( storageClasses.end(), o->storageClasses );
    475449                if ( o->type ) {
    476450                        if ( ! type ) {
     
    719693        } // if
    720694        newnode->type->forall = maybeClone( type->forall );
    721         newnode->copyStorageClasses( this );
     695        newnode->storageClasses = storageClasses;
    722696        newnode->name = assign_strptr( newName );
    723697        return newnode;
     
    726700DeclarationNode *DeclarationNode::cloneBaseType( DeclarationNode *o ) {
    727701        if ( o ) {
    728                 o->copyStorageClasses( this );
     702                o->storageClasses.insert( o->storageClasses.end(), storageClasses.begin(), storageClasses.end() );
    729703                if ( type ) {
    730704                        TypeData *srcType = type;
     
    759733        DeclarationNode *newnode = new DeclarationNode;
    760734        newnode->type = maybeClone( type );
    761         newnode->copyStorageClasses( this );
     735        newnode->storageClasses = storageClasses;
    762736        newnode->name = assign_strptr( newName );
    763737        return newnode;
     
    766740DeclarationNode *DeclarationNode::cloneType( DeclarationNode *o ) {
    767741        if ( o ) {
    768                 o->copyStorageClasses( this );
     742                o->storageClasses.insert( o->storageClasses.end(), storageClasses.begin(), storageClasses.end() );
    769743                if ( type ) {
    770744                        TypeData *newType = type->clone();
     
    881855
    882856Declaration *DeclarationNode::build() const {
    883         if( !error.empty() ) throw SemanticError( error, this );
    884857        if ( type ) {
    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 );
     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 );
    889862        } // if
    890863        throw SemanticError( "invalid function specifier in declaration of ", this );
     
    925898}
    926899
    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 // }
     900DeclarationNode::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
     912bool 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}
    946919
    947920// Local Variables: //
  • src/Parser/ParseNode.h

    r1f6d4624 r7527e63  
    271271        DeclarationNode *set_extension( bool exten ) { extension = exten; return this; }
    272272  private:
    273         // StorageClass buildStorageClass() const;
    274         // bool buildFuncSpecifier( StorageClass key ) const;
     273        StorageClass buildStorageClass() const;
     274        bool buildFuncSpecifier( StorageClass key ) const;
    275275
    276276        TypeData *type;
    277277        std::string name;
    278         // std::list< StorageClass > storageClasses;
    279         StorageClass storageClass;
    280         bool isInline, isNoreturn;
     278        std::list< StorageClass > storageClasses;
    281279        std::list< std::string > attributes;
    282280        ExpressionNode *bitfieldWidth;
     
    286284        LinkageSpec::Type linkage;
    287285        bool extension = false;
    288         std::string error;
    289286
    290287        static UniqueName anonymous;
  • src/tests/.expect/declarationErrors.txt

    r1f6d4624 r7527e63  
    11CFA Version 1.0.0 (debug)
    2 Error: invalid combination of storage classes in declaration of x9: static volatile const short int
     2Error: invalid combination of storage classes in declaration of x9: static static volatile const short int
    33
    4 Error: invalid combination of storage classes in declaration of x18: static const volatile instance of struct __anonymous0
     4Error: invalid combination of storage classes in declaration of x18: static static const volatile instance of struct __anonymous0
    55  with members
    66    i: int
     
    88
    99
    10 Error: invalid combination of storage classes in declaration of x19: static const volatile volatile instance of struct __anonymous1
     10Error: invalid combination of storage classes in declaration of x19: static static const volatile volatile instance of struct __anonymous1
    1111  with members
    1212    i: int
     
    1414
    1515
    16 Error: invalid combination of storage classes in declaration of x28: static volatile const instance of type Int
     16Error: invalid combination of storage classes in declaration of x28: static static volatile const instance of type Int
    1717
    1818make: *** [declarationErrors] Error 1
Note: See TracChangeset for help on using the changeset viewer.