Ignore:
Timestamp:
Sep 15, 2016, 2:57:03 PM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, 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:
ba7aa2d, fc4a0fa
Parents:
5b639ee (diff), 50c5cf3 (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:

more refactoring of parser code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r5b639ee r101e0bd  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Sep 12 21:03:18 2016
    13 // Update Count     : 491
     12// Last Modified On : Wed Sep 14 23:13:28 2016
     13// Update Count     : 502
    1414//
    1515
     
    383383}
    384384
    385 static void addQualifiersToType( TypeData *&src, TypeData *dst ) {
    386         if ( src && dst ) {
    387                 if ( src->forall && dst->kind == TypeData::Function ) {
    388                         if ( dst->forall ) {
    389                                 dst->forall->appendList( src->forall );
    390                         } else {
    391                                 dst->forall = src->forall;
    392                         } // if
    393                         src->forall = 0;
    394                 } // if
    395                 if ( dst->base ) {
    396                         addQualifiersToType( src, dst->base );
    397                 } else if ( dst->kind == TypeData::Function ) {
    398                         dst->base = src;
    399                         src = 0;
    400                 } else {
    401                         dst->qualifiers |= src->qualifiers;
    402                 } // if
    403         } // if
    404 }
    405 
    406385void appendError( string & dst, const string & src ) {
    407386        if ( src.empty() ) return;
     
    445424} // DeclarationNode::copyStorageClasses
    446425
     426static void addQualifiersToType( TypeData *&src, TypeData *dst ) {
     427        if ( src->forall && dst->kind == TypeData::Function ) {
     428                if ( dst->forall ) {
     429                        dst->forall->appendList( src->forall );
     430                } else {
     431                        dst->forall = src->forall;
     432                } // if
     433                src->forall = 0;
     434        } // if
     435        if ( dst->base ) {
     436                addQualifiersToType( src, dst->base );
     437        } else if ( dst->kind == TypeData::Function ) {
     438                dst->base = src;
     439                src = 0;
     440        } else {
     441                dst->qualifiers |= src->qualifiers;
     442        } // if
     443} // addQualifiersToType
     444
    447445DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) {
    448         if ( q ) {
    449                 checkStorageClasses( q );
    450                 copyStorageClasses( q );
    451                 if ( q->type ) {
    452                         if ( ! type ) {
    453                                 type = new TypeData;
     446        if ( ! q ) return this;
     447
     448        checkStorageClasses( q );
     449        copyStorageClasses( q );
     450
     451        if ( ! q->type ) { delete q; return this; }
     452
     453        if ( ! type ) {
     454//              type = new TypeData;
     455                type = q->type;
     456                return this;
     457        } // if
     458
     459        checkQualifiers( q->type, type );
     460        addQualifiersToType( q->type, type );
     461
     462        if ( q->type->forall ) {
     463                if ( type->forall ) {
     464                        type->forall->appendList( q->type->forall );
     465                } else {
     466                        if ( type->kind == TypeData::Aggregate ) {
     467                                type->aggregate.params = q->type->forall;
     468                                // change implicit typedef from TYPEDEFname to TYPEGENname
     469                                typedefTable.changeKind( type->aggregate.name, TypedefTable::TG );
    454470                        } else {
    455                                 checkQualifiers( q->type, type );
     471                                type->forall = q->type->forall;
    456472                        } // if
    457                         addQualifiersToType( q->type, type );
    458                         if ( q->type && q->type->forall ) {
    459                                 if ( type->forall ) {
    460                                         type->forall->appendList( q->type->forall );
    461                                 } else {
    462                                         if ( type->kind == TypeData::Aggregate ) {
    463                                                 type->aggregate.params = q->type->forall;
    464                                                 // change implicit typedef from TYPEDEFname to TYPEGENname
    465                                                 typedefTable.changeKind( type->aggregate.name, TypedefTable::TG );
    466                                         } else {
    467                                                 type->forall = q->type->forall;
    468                                         } // if
     473                } // if
     474                q->type->forall = 0;
     475        } // if
     476        delete q;
     477        return this;
     478} // addQualifiers
     479
     480static void addTypeToType( TypeData *&src, TypeData *&dst ) {
     481        if ( src->forall && dst->kind == TypeData::Function ) {
     482                if ( dst->forall ) {
     483                        dst->forall->appendList( src->forall );
     484                } else {
     485                        dst->forall = src->forall;
     486                } // if
     487                src->forall = 0;
     488        } // if
     489        if ( dst->base ) {
     490                addTypeToType( src, dst->base );
     491        } else {
     492                switch ( dst->kind ) {
     493                  case TypeData::Unknown:
     494                        src->qualifiers |= dst->qualifiers;
     495                        dst = src;
     496                        src = 0;
     497                        break;
     498                  case TypeData::Basic:
     499                        dst->qualifiers |= src->qualifiers;
     500                        if ( src->kind != TypeData::Unknown ) {
     501                                assert( src->kind == TypeData::Basic );
     502
     503                                if ( dst->basictype == DeclarationNode::NoBasicType ) {
     504                                        dst->basictype = src->basictype;
     505                                } else if ( src->basictype != DeclarationNode::NoBasicType )
     506                                        throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::basicTypeName[ src->basictype ] + " in type: ", src );
     507
     508                                if ( dst->complextype == DeclarationNode::NoComplexType ) {
     509                                        dst->complextype = src->complextype;
     510                                } else if ( src->complextype != DeclarationNode::NoComplexType )
     511                                        throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::complexTypeName[ src->complextype ] + " in type: ", src );
     512
     513                                if ( dst->signedness == DeclarationNode::NoSignedness ) {
     514                                        dst->signedness = src->signedness;
     515                                } else if ( src->signedness != DeclarationNode::NoSignedness )
     516                                        throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::signednessName[ src->signedness ] + " in type: ", src );
     517
     518                                if ( dst->length == DeclarationNode::NoLength ) {
     519                                        dst->length = src->length;
     520                                } else if ( dst->length == DeclarationNode::Long && src->length == DeclarationNode::Long ) {
     521                                        dst->length = DeclarationNode::LongLong;
     522                                } else if ( src->length != DeclarationNode::NoLength )
     523                                        throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::lengthName[ src->length ] + " in type: ", src );
     524                        } // if
     525                        break;
     526                  default:
     527                        switch ( src->kind ) {
     528                          case TypeData::Aggregate:
     529                          case TypeData::Enum:
     530                                dst->base = new TypeData( TypeData::AggregateInst );
     531                                dst->base->aggInst.aggregate = src;
     532                                if ( src->kind == TypeData::Aggregate ) {
     533                                        dst->base->aggInst.params = maybeClone( src->aggregate.actuals );
    469534                                } // if
    470                                 q->type->forall = 0;
    471                         } // if
    472                 } // if
    473         } // if
    474         delete q;
    475         return this;
    476 }
    477 
    478 static void addTypeToType( TypeData *&src, TypeData *&dst ) {
    479         if ( src && dst ) {
    480                 if ( src->forall && dst->kind == TypeData::Function ) {
    481                         if ( dst->forall ) {
    482                                 dst->forall->appendList( src->forall );
    483                         } else {
    484                                 dst->forall = src->forall;
    485                         } // if
    486                         src->forall = 0;
    487                 } // if
    488                 if ( dst->base ) {
    489                         addTypeToType( src, dst->base );
    490                 } else {
    491                         switch ( dst->kind ) {
    492                           case TypeData::Unknown:
    493                                 src->qualifiers |= dst->qualifiers;
    494                                 dst = src;
     535                                dst->base->qualifiers |= src->qualifiers;
    495536                                src = 0;
    496537                                break;
    497                           case TypeData::Basic:
    498                                 dst->qualifiers |= src->qualifiers;
    499                                 if ( src->kind != TypeData::Unknown ) {
    500                                         assert( src->kind == TypeData::Basic );
    501 
    502                                         if ( dst->basictype == DeclarationNode::NoBasicType ) {
    503                                                 dst->basictype = src->basictype;
    504                                         } else if ( src->basictype != DeclarationNode::NoBasicType )
    505                                                 throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::basicTypeName[ src->basictype ] + " in type: ", src );
    506 
    507                                         if ( dst->complextype == DeclarationNode::NoComplexType ) {
    508                                                 dst->complextype = src->complextype;
    509                                         } else if ( src->complextype != DeclarationNode::NoComplexType )
    510                                                 throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::complexTypeName[ src->complextype ] + " in type: ", src );
    511 
    512                                         if ( dst->signedness == DeclarationNode::NoSignedness ) {
    513                                                 dst->signedness = src->signedness;
    514                                         } else if ( src->signedness != DeclarationNode::NoSignedness )
    515                                                 throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::signednessName[ src->signedness ] + " in type: ", src );
    516 
    517                                         if ( dst->length == DeclarationNode::NoLength ) {
    518                                                 dst->length = src->length;
    519                                         } else if ( dst->length == DeclarationNode::Long && src->length == DeclarationNode::Long ) {
    520                                                 dst->length = DeclarationNode::LongLong;
    521                                         } else if ( src->length != DeclarationNode::NoLength )
    522                                                 throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::lengthName[ src->length ] + " in type: ", src );
     538                          default:
     539                                if ( dst->forall ) {
     540                                        dst->forall->appendList( src->forall );
     541                                } else {
     542                                        dst->forall = src->forall;
    523543                                } // if
    524                                 break;
    525                           default:
    526                                 switch ( src->kind ) {
    527                                   case TypeData::Aggregate:
    528                                   case TypeData::Enum:
    529                                         dst->base = new TypeData( TypeData::AggregateInst );
    530                                         dst->base->aggInst.aggregate = src;
    531                                         if ( src->kind == TypeData::Aggregate ) {
    532                                                 dst->base->aggInst.params = maybeClone( src->aggregate.actuals );
    533                                         } // if
    534                                         dst->base->qualifiers |= src->qualifiers;
    535                                         src = 0;
    536                                         break;
    537                                   default:
    538                                         if ( dst->forall ) {
    539                                                 dst->forall->appendList( src->forall );
    540                                         } else {
    541                                                 dst->forall = src->forall;
    542                                         } // if
    543                                         src->forall = 0;
    544                                         dst->base = src;
    545                                         src = 0;
    546                                 } // switch
     544                                src->forall = 0;
     545                                dst->base = src;
     546                                src = 0;
    547547                        } // switch
    548                 } // if
     548                } // switch
    549549        } // if
    550550}
Note: See TracChangeset for help on using the changeset viewer.