Changeset 13e3b50


Ignore:
Timestamp:
Aug 16, 2016, 2:41:17 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
1f6d4624
Parents:
7880579
Message:

DeclarationNodes? and Declaration now store exactly the same data for storage classes

Location:
src
Files:
4 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: //
  • src/Parser/ParseNode.h

    r7880579 r13e3b50  
    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;
     278        // std::list< StorageClass > storageClasses;
     279        StorageClass storageClass;
     280        bool isInline, isNoreturn;
    279281        std::list< std::string > attributes;
    280282        ExpressionNode *bitfieldWidth;
     
    284286        LinkageSpec::Type linkage;
    285287        bool extension = false;
     288        std::string error;
    286289
    287290        static UniqueName anonymous;
  • src/tests/.expect/declarationErrors.txt

    r7880579 r13e3b50  
    11CFA Version 1.0.0 (debug)
    2 Error: invalid combination of storage classes in declaration of x9: static static volatile const short int
     2Error: invalid combination of storage classes in declaration of x9: static volatile const short int
    33
    4 Error: invalid combination of storage classes in declaration of x18: static static const volatile instance of struct __anonymous0
     4Error: invalid combination of storage classes in declaration of x18: 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 static const volatile volatile instance of struct __anonymous1
     10Error: invalid combination of storage classes in declaration of x19: 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 static volatile const instance of type Int
     16Error: invalid combination of storage classes in declaration of x28: static volatile const instance of type Int
    1717
    1818make: *** [declarationErrors] Error 1
  • src/tests/.expect/declarationSpecifier.txt

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