Ignore:
Timestamp:
Aug 19, 2016, 2:42:04 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
e85a8631
Parents:
03da511 (diff), ac71a86 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into ctor

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r03da511 r04cdd9b  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug  7 08:01:55 2016
    13 // Update Count     : 165
     12// Last Modified On : Thu Aug 18 23:48:23 2016
     13// Update Count     : 182
    1414//
    1515
     
    2525#include "SynTree/Expression.h"
    2626
    27 #include "Parser.h"
    2827#include "TypedefTable.h"
    2928extern TypedefTable typedefTable;
     
    4241UniqueName DeclarationNode::anonymous( "__anonymous" );
    4342
    44 extern LinkageSpec::Type linkage;                                               // defined in parser.yy
     43extern LinkageSpec::Spec linkage;                                               // defined in parser.yy
    4544
    4645DeclarationNode *DeclarationNode::clone() const {
     
    4847        newnode->type = maybeClone( type );
    4948        newnode->name = name;
    50         newnode->storageClasses = storageClasses;
    51 //PAB   newnode->bitfieldWidth = maybeClone( bitfieldWidth );
     49        newnode->storageClass = storageClass;
     50        newnode->isInline = isInline;
     51        newnode->isNoreturn = isNoreturn;
    5252        newnode->bitfieldWidth = bitfieldWidth;
    5353        newnode->hasEllipsis = hasEllipsis;
    5454        newnode->initializer = initializer;
    55         newnode->next = maybeClone( next );
     55        newnode->set_next( maybeClone( get_next() ) );
    5656        newnode->linkage = linkage;
    5757        return newnode;
    5858} // DeclarationNode::clone
    5959
    60 DeclarationNode::DeclarationNode() : type( 0 ), bitfieldWidth( 0 ), initializer( 0 ), hasEllipsis( false ), linkage( ::linkage ) {
     60DeclarationNode::DeclarationNode()
     61        : type( 0 )
     62        , storageClass( NoStorageClass )
     63        , isInline( false )
     64        , isNoreturn( false )
     65        , bitfieldWidth( 0 )
     66        , initializer( 0 )
     67        , hasEllipsis( false )
     68        , linkage( ::linkage )
     69        , extension( false )
     70        , error() {
    6171}
    6272
     
    8393        } // if
    8494
    85         printEnums( storageClasses.begin(), storageClasses.end(), DeclarationNode::storageName, os );
     95        if(storageClass != NoStorageClass) os << DeclarationNode::storageName[storageClass] << ' ';
     96        if(isInline) os << DeclarationNode::storageName[Inline] << ' ';
     97        if(isNoreturn) os << DeclarationNode::storageName[Noreturn] << ' ';
    8698        if ( type ) {
    8799                type->print( os, indent );
     
    144156DeclarationNode *DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) {
    145157        DeclarationNode *newnode = new DeclarationNode;
    146         newnode->storageClasses.push_back( sc );
     158        switch (sc) {
     159                case Inline: newnode->isInline = true; break;
     160                case Noreturn: newnode->isNoreturn = true; break;
     161                default: newnode->storageClass = sc; break;
     162        }
    147163        return newnode;
    148164} // DeclarationNode::newStorageClass
     
    284300        newnode->type->array->dimension = size;
    285301        newnode->type->array->isStatic = isStatic;
    286         if ( newnode->type->array->dimension == 0 || dynamic_cast<ConstantNode *>( newnode->type->array->dimension ) ) {
     302        if ( newnode->type->array->dimension == 0 || newnode->type->array->dimension->isExpressionType<ConstantExpr *>() ) {
    287303                newnode->type->array->isVarLen = false;
    288304        } else {
     
    360376DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) {
    361377        if ( q ) {
    362                 storageClasses.splice( storageClasses.end(), q->storageClasses );
     378                copyStorageClasses(q);
    363379                if ( q->type ) {
    364380                        if ( ! type ) {
     
    387403
    388404DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) {
    389         storageClasses = q->storageClasses;
     405        isInline = isInline || q->isInline;
     406        isNoreturn = isNoreturn || q->isNoreturn;
     407        if(storageClass == NoStorageClass) {
     408                storageClass = q->storageClass;
     409        }
     410        else if (q->storageClass != NoStorageClass) {
     411                q->error = "invalid combination of storage classes in declaration of ";
     412        }
     413        if(error.empty()) error = q->error;
    390414        return this;
    391415}
     
    447471DeclarationNode *DeclarationNode::addType( DeclarationNode *o ) {
    448472        if ( o ) {
    449                 storageClasses.splice( storageClasses.end(), o->storageClasses );
     473                copyStorageClasses( o );
    450474                if ( o->type ) {
    451475                        if ( ! type ) {
     
    470494
    471495                // there may be typedefs chained onto the type
    472                 if ( o->get_link() ) {
    473                         set_link( o->get_link()->clone() );
     496                if ( o->get_next() ) {
     497                        set_last( o->get_next()->clone() );
    474498                } // if
    475499        } // if
     
    694718        } // if
    695719        newnode->type->forall = maybeClone( type->forall );
    696         newnode->storageClasses = storageClasses;
     720        newnode->copyStorageClasses( this );
    697721        newnode->name = assign_strptr( newName );
    698722        return newnode;
     
    701725DeclarationNode *DeclarationNode::cloneBaseType( DeclarationNode *o ) {
    702726        if ( o ) {
    703                 o->storageClasses.insert( o->storageClasses.end(), storageClasses.begin(), storageClasses.end() );
     727                o->copyStorageClasses( this );
    704728                if ( type ) {
    705729                        TypeData *srcType = type;
     
    734758        DeclarationNode *newnode = new DeclarationNode;
    735759        newnode->type = maybeClone( type );
    736         newnode->storageClasses = storageClasses;
     760        newnode->copyStorageClasses( this );
    737761        newnode->name = assign_strptr( newName );
    738762        return newnode;
     
    741765DeclarationNode *DeclarationNode::cloneType( DeclarationNode *o ) {
    742766        if ( o ) {
    743                 o->storageClasses.insert( o->storageClasses.end(), storageClasses.begin(), storageClasses.end() );
     767                o->copyStorageClasses( this );
    744768                if ( type ) {
    745769                        TypeData *newType = type->clone();
     
    755779}
    756780
    757 DeclarationNode *DeclarationNode::appendList( DeclarationNode *node ) {
    758         if ( node != 0 ) {
    759                 set_link( node );
    760         } // if
    761         return this;
    762 }
    763 
    764781DeclarationNode *DeclarationNode::extractAggregate() const {
    765782        if ( type ) {
     
    776793void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList ) {
    777794        SemanticError errors;
    778         std::back_insert_iterator< std::list< Declaration *> > out( outputList );
     795        std::back_insert_iterator< std::list< Declaration * > > out( outputList );
    779796        const DeclarationNode *cur = firstNode;
    780797        while ( cur ) {
     
    794811                        errors.append( e );
    795812                } // try
    796                 cur = dynamic_cast<DeclarationNode *>( cur->get_link() );
     813                cur = dynamic_cast< DeclarationNode * >( cur->get_next() );
    797814        } // while
    798815        if ( ! errors.isEmpty() ) {
     
    801818}
    802819
    803 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType *> &outputList ) {
     820void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList ) {
    804821        SemanticError errors;
    805         std::back_insert_iterator< std::list< DeclarationWithType *> > out( outputList );
     822        std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList );
    806823        const DeclarationNode *cur = firstNode;
    807824        while ( cur ) {
     
    817834                        Declaration *decl = cur->build();
    818835                        if ( decl ) {
    819                                 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType *>( decl ) ) {
     836                                if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
    820837                                        *out++ = dwt;
    821                                 } else if ( StructDecl *agg = dynamic_cast< StructDecl *>( decl ) ) {
     838                                } else if ( StructDecl *agg = dynamic_cast< StructDecl * >( decl ) ) {
    822839                                        StructInstType *inst = new StructInstType( Type::Qualifiers(), agg->get_name() );
    823840                                        *out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 );
    824841                                        delete agg;
    825                                 } else if ( UnionDecl *agg = dynamic_cast< UnionDecl *>( decl ) ) {
     842                                } else if ( UnionDecl *agg = dynamic_cast< UnionDecl * >( decl ) ) {
    826843                                        UnionInstType *inst = new UnionInstType( Type::Qualifiers(), agg->get_name() );
    827844                                        *out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 );
     
    831848                        errors.append( e );
    832849                } // try
    833                 cur = dynamic_cast< DeclarationNode *>( cur->get_link() );
     850                cur = dynamic_cast< DeclarationNode * >( cur->get_next() );
    834851        } // while
    835852        if ( ! errors.isEmpty() ) {
     
    838855}
    839856
    840 void buildTypeList( const DeclarationNode *firstNode, std::list< Type *> &outputList ) {
     857void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList ) {
    841858        SemanticError errors;
    842         std::back_insert_iterator< std::list< Type *> > out( outputList );
     859        std::back_insert_iterator< std::list< Type * > > out( outputList );
    843860        const DeclarationNode *cur = firstNode;
    844861        while ( cur ) {
     
    848865                        errors.append( e );
    849866                } // try
    850                 cur = dynamic_cast< DeclarationNode *>( cur->get_link() );
     867                cur = dynamic_cast< DeclarationNode * >( cur->get_next() );
    851868        } // while
    852869        if ( ! errors.isEmpty() ) {
     
    856873
    857874Declaration *DeclarationNode::build() const {
     875        if( !error.empty() ) throw SemanticError( error, this );
    858876        if ( type ) {
    859                 return type->buildDecl( name, buildStorageClass(), maybeBuild< Expression >( bitfieldWidth ), buildFuncSpecifier( Inline ), buildFuncSpecifier( Noreturn ), linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
    860         } // if
    861         if ( ! buildFuncSpecifier( Inline ) && ! buildFuncSpecifier( Noreturn ) ) {
    862                 return (new ObjectDecl( name, buildStorageClass(), linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ))->set_extension( extension );
     877                return type->buildDecl( name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
     878        } // if
     879        if ( ! isInline && ! isNoreturn ) {
     880                return (new ObjectDecl( name, storageClass, linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ))->set_extension( extension );
    863881        } // if
    864882        throw SemanticError( "invalid function specifier in declaration of ", this );
     
    899917}
    900918
    901 DeclarationNode::StorageClass DeclarationNode::buildStorageClass() const {
    902         DeclarationNode::StorageClass ret = DeclarationNode::NoStorageClass;
    903         for ( std::list< DeclarationNode::StorageClass >::const_iterator i = storageClasses.begin(); i != storageClasses.end(); ++i ) {
    904           if ( *i == DeclarationNode::Inline || *i == DeclarationNode::Noreturn ) continue; // ignore function specifiers
    905           if ( ret != DeclarationNode::NoStorageClass ) {       // already have a valid storage class ?
    906                         throw SemanticError( "invalid combination of storage classes in declaration of ", this );
    907                 } // if
    908                 ret = *i;
    909         } // for
    910         return ret;
    911 }
    912 
    913 bool DeclarationNode::buildFuncSpecifier( DeclarationNode::StorageClass key ) const {
    914         std::list< DeclarationNode::StorageClass >::const_iterator first = std::find( storageClasses.begin(), storageClasses.end(), key );
    915   if ( first == storageClasses.end() ) return false;    // not found
    916         first = std::find( ++first, storageClasses.end(), key ); // found
    917   if ( first == storageClasses.end() ) return true;             // not found again
    918         throw SemanticError( "duplicate function specifier in declaration of ", this );
    919 }
     919// DeclarationNode::StorageClass DeclarationNode::buildStorageClass() const {
     920//      DeclarationNode::StorageClass ret = DeclarationNode::NoStorageClass;
     921//      for ( std::list< DeclarationNode::StorageClass >::const_iterator i = storageClasses.begin(); i != storageClasses.end(); ++i ) {
     922//        if ( *i == DeclarationNode::Inline || *i == DeclarationNode::Noreturn ) continue; // ignore function specifiers
     923//        if ( ret != DeclarationNode::NoStorageClass ) {       // already have a valid storage class ?
     924//                      throw SemanticError( "invalid combination of storage classes in declaration of ", this );
     925//              } // if
     926//              ret = *i;
     927//      } // for
     928//      return ret;
     929// }
     930
     931// bool DeclarationNode::buildFuncSpecifier( DeclarationNode::StorageClass key ) const {
     932//      std::list< DeclarationNode::StorageClass >::const_iterator first = std::find( storageClasses.begin(), storageClasses.end(), key );
     933//   if ( first == storageClasses.end() ) return false; // not found
     934//      first = std::find( ++first, storageClasses.end(), key ); // found
     935//   if ( first == storageClasses.end() ) return true;          // not found again
     936//      throw SemanticError( "duplicate function specifier in declaration of ", this );
     937// }
    920938
    921939// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.