Ignore:
Timestamp:
Sep 15, 2016, 3:49:22 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
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:
3c13c03
Parents:
4ab9536 (diff), fc4a0fa (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 tuples

Conflicts:

src/Parser/parser.cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r4ab9536 r12bc63a  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Sep 11 09:24:11 2016
    13 // Update Count     : 438
     12// Last Modified On : Wed Sep 14 23:13:28 2016
     13// Update Count     : 502
    1414//
    1515
     
    3232// These must remain in the same order as the corresponding DeclarationNode enumerations.
    3333const char *DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", "NoStorageClass" };
    34 const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic" };
    35 const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary",  };
    36 const char *DeclarationNode::modifierName[]  = { "signed", "unsigned", "short", "long" };
     34const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic", "NoQualifier" };
     35const char *DeclarationNode::basicTypeName[] = { "void", "_Bool", "char", "int", "float", "double", "long double", "NoBasicType" };
     36const char *DeclarationNode::complexTypeName[] = { "_Complex", "_Imaginary", "NoComplexType" };
     37const char *DeclarationNode::signednessName[] = { "signed", "unsigned", "NoSignedness" };
     38const char *DeclarationNode::lengthName[] = { "short", "long", "long long", "NoLength" };
    3739const char *DeclarationNode::aggregateName[] = { "struct", "union", "context" };
    38 const char *DeclarationNode::typeClassName[] = { "type", "dtype", "ftype" };
     40const char *DeclarationNode::typeClassName[] = { "otype", "dtype", "ftype" };
    3941const char *DeclarationNode::builtinTypeName[] = { "__builtin_va_list" };
    4042
     
    5355                linkage( ::linkage ),
    5456                extension( false ) {
    55         variable.tyClass = DeclarationNode::Type;
     57        variable.tyClass = DeclarationNode::Otype;
    5658        variable.assertions = nullptr;
    5759
     
    188190        DeclarationNode *newnode = new DeclarationNode;
    189191        newnode->type = new TypeData( TypeData::Basic );
    190         newnode->type->basic.typeSpec.push_back( bt );
     192        newnode->type->basictype = bt;
    191193        return newnode;
    192194} // DeclarationNode::newBasicType
    193195
    194 DeclarationNode * DeclarationNode::newModifier( Modifier mod ) {
     196DeclarationNode * DeclarationNode::newComplexType( ComplexType ct ) {
    195197        DeclarationNode *newnode = new DeclarationNode;
    196198        newnode->type = new TypeData( TypeData::Basic );
    197         newnode->type->basic.modifiers.push_back( mod );
    198         return newnode;
    199 } // DeclarationNode::newModifier
     199        newnode->type->complextype = ct;
     200        return newnode;
     201} // DeclarationNode::newComplexType
     202
     203DeclarationNode * DeclarationNode::newSignedNess( Signedness sn ) {
     204        DeclarationNode *newnode = new DeclarationNode;
     205        newnode->type = new TypeData( TypeData::Basic );
     206        newnode->type->signedness = sn;
     207        return newnode;
     208} // DeclarationNode::newSignedNess
     209
     210DeclarationNode * DeclarationNode::newLength( Length lnth ) {
     211        DeclarationNode *newnode = new DeclarationNode;
     212        newnode->type = new TypeData( TypeData::Basic );
     213        newnode->type->length = lnth;
     214        return newnode;
     215} // DeclarationNode::newLength
    200216
    201217DeclarationNode * DeclarationNode::newFromTypedef( std::string *name ) {
     
    367383}
    368384
    369 static void addQualifiersToType( TypeData *&src, TypeData *dst ) {
    370         if ( src && dst ) {
    371                 if ( src->forall && dst->kind == TypeData::Function ) {
    372                         if ( dst->forall ) {
    373                                 dst->forall->appendList( src->forall );
    374                         } else {
    375                                 dst->forall = src->forall;
    376                         } // if
    377                         src->forall = 0;
    378                 } // if
    379                 if ( dst->base ) {
    380                         addQualifiersToType( src, dst->base );
    381                 } else if ( dst->kind == TypeData::Function ) {
    382                         dst->base = src;
    383                         src = 0;
    384                 } else {
    385                         dst->qualifiers |= src->qualifiers;
    386                 } // if
    387         } // if
    388 }
     385void appendError( string & dst, const string & src ) {
     386        if ( src.empty() ) return;
     387        if ( dst.empty() ) { dst = src; return; }
     388        dst += ", " + src;
     389} // appendError
    389390
    390391void DeclarationNode::checkQualifiers( const TypeData *src, const TypeData *dst ) {
     
    392393
    393394        if ( (qsrc & qdst).any() ) {                                            // common qualifier ?
    394                 for ( int i = 0; i < NoOfQualifier; i += 1 ) {  // find common qualifiers
    395                         if ( qsrc[i] & qdst[i] ) {
    396                                 if ( ! error.empty() ) error += ", ";   // separator
    397                                 error += string( "duplicate " ) + DeclarationNode::qualifierName[i];
     395                for ( int i = 0; i < NoQualifier; i += 1 ) {    // find common qualifiers
     396                        if ( qsrc[i] && qdst[i] ) {
     397                                appendError( error, string( "duplicate " ) + DeclarationNode::qualifierName[i] );
    398398                        } // if
    399399                } // for
     
    403403void DeclarationNode::checkStorageClasses( DeclarationNode *q ) {
    404404        if ( storageClass != NoStorageClass && q->storageClass != NoStorageClass ) {
    405                 if ( ! error.empty() ) error += ", ";                   // separator
    406405                if ( storageClass == q->storageClass ) {                // duplicate qualifier
    407                         error += string( "duplicate " ) + storageName[ storageClass ];
     406                        appendError( error, string( "duplicate " ) + storageName[ storageClass ] );
    408407                } else {                                                                                // only one storage class
    409                         error += string( "conflicting " ) + storageName[ storageClass ] + " & " + storageName[ q->storageClass ];
    410                         q->storageClass = storageClass;                         // FIX ERROR
    411                 } // if
    412                 if ( ! q->error.empty() ) error += ", " + q->error;     // separator
    413         } else {
    414                 if ( ! error.empty() ) {
    415                         if ( ! q->error.empty() ) error += ", " + q->error; // separator
    416                 } else if ( ! q->error.empty() ) error += q->error;
    417         } // if
     408                        appendError( error, string( "conflicting " ) + storageName[ storageClass ] + " & " + storageName[ q->storageClass ] );
     409                        q->storageClass = storageClass;                         // FIX ERROR, prevent assertions from triggering
     410                } // if
     411        } // if
     412        appendError( error, q->error );
    418413} // DeclarationNode::copyStorageClasses
    419414
    420415DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) {
    421         isInline = isInline | q->isInline;
    422         isNoreturn = isNoreturn | q->isNoreturn;
     416        isInline = isInline || q->isInline;
     417        isNoreturn = isNoreturn || q->isNoreturn;
    423418        // do not overwrite an existing value with NoStorageClass
    424419        if ( q->storageClass != NoStorageClass ) {
     
    429424} // DeclarationNode::copyStorageClasses
    430425
     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
    431445DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) {
    432         if ( q ) {
    433                 checkStorageClasses( q );
    434                 copyStorageClasses( q );
    435                 if ( q->type ) {
    436                         if ( ! type ) {
    437                                 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 );
    438470                        } else {
    439                                 checkQualifiers( q->type, type );
     471                                type->forall = q->type->forall;
    440472                        } // if
    441                         addQualifiersToType( q->type, type );
    442                         if ( q->type && q->type->forall ) {
    443                                 if ( type->forall ) {
    444                                         type->forall->appendList( q->type->forall );
    445                                 } else {
    446                                         if ( type->kind == TypeData::Aggregate ) {
    447                                                 type->aggregate.params = q->type->forall;
    448                                                 // change implicit typedef from TYPEDEFname to TYPEGENname
    449                                                 typedefTable.changeKind( type->aggregate.name, TypedefTable::TG );
    450                                         } else {
    451                                                 type->forall = q->type->forall;
    452                                         } // 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 );
    453534                                } // if
    454                                 q->type->forall = 0;
    455                         } // if
    456                 } // if
    457         } // if
    458         delete q;
    459         return this;
    460 }
    461 
    462 static void addTypeToType( TypeData *&src, TypeData *&dst ) {
    463         if ( src && dst ) {
    464                 if ( src->forall && dst->kind == TypeData::Function ) {
    465                         if ( dst->forall ) {
    466                                 dst->forall->appendList( src->forall );
    467                         } else {
    468                                 dst->forall = src->forall;
    469                         } // if
    470                         src->forall = 0;
    471                 } // if
    472                 if ( dst->base ) {
    473                         addTypeToType( src, dst->base );
    474                 } else {
    475                         switch ( dst->kind ) {
    476                           case TypeData::Unknown:
    477                                 src->qualifiers |= dst->qualifiers;
    478                                 dst = src;
     535                                dst->base->qualifiers |= src->qualifiers;
    479536                                src = 0;
    480537                                break;
    481                           case TypeData::Basic:
    482                                 dst->qualifiers |= src->qualifiers;
    483                                 if ( src->kind != TypeData::Unknown ) {
    484                                         assert( src->kind == TypeData::Basic );
    485                                         dst->basic.modifiers.splice( dst->basic.modifiers.end(), src->basic.modifiers );
    486                                         dst->basic.typeSpec.splice( dst->basic.typeSpec.end(), src->basic.typeSpec );
     538                          default:
     539                                if ( dst->forall ) {
     540                                        dst->forall->appendList( src->forall );
     541                                } else {
     542                                        dst->forall = src->forall;
    487543                                } // if
    488                                 break;
    489                           default:
    490                                 switch ( src->kind ) {
    491                                   case TypeData::Aggregate:
    492                                   case TypeData::Enum:
    493                                         dst->base = new TypeData( TypeData::AggregateInst );
    494                                         dst->base->aggInst.aggregate = src;
    495                                         if ( src->kind == TypeData::Aggregate ) {
    496                                                 dst->base->aggInst.params = maybeClone( src->aggregate.actuals );
    497                                         } // if
    498                                         dst->base->qualifiers |= src->qualifiers;
    499                                         src = 0;
    500                                         break;
    501                                   default:
    502                                         if ( dst->forall ) {
    503                                                 dst->forall->appendList( src->forall );
    504                                         } else {
    505                                                 dst->forall = src->forall;
    506                                         } // if
    507                                         src->forall = 0;
    508                                         dst->base = src;
    509                                         src = 0;
    510                                 } // switch
     544                                src->forall = 0;
     545                                dst->base = src;
     546                                src = 0;
    511547                        } // switch
    512                 } // if
     548                } // switch
    513549        } // if
    514550}
     
    875911        while ( cur ) {
    876912                try {
    877 ///       if ( DeclarationNode *extr = cur->extractAggregate() ) {
    878 ///     // handle the case where a structure declaration is contained within an object or type
    879 ///     // declaration
    880 ///     Declaration *decl = extr->build();
    881 ///     if ( decl ) {
    882 ///          *out++ = decl;
    883 ///     }
    884 ///       }
    885913                        Declaration *decl = cur->build();
    886914                        if ( decl ) {
Note: See TracChangeset for help on using the changeset viewer.