Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r5b639ee rb6424d9  
    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 : Sun Sep 11 09:24:11 2016
     13// Update Count     : 438
    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", "NoQualifier" };
    35 const char *DeclarationNode::basicTypeName[] = { "void", "_Bool", "char", "int", "float", "double", "long double", "NoBasicType" };
    36 const char *DeclarationNode::complexTypeName[] = { "_Complex", "_Imaginary", "NoComplexType" };
    37 const char *DeclarationNode::signednessName[] = { "signed", "unsigned", "NoSignedness" };
    38 const char *DeclarationNode::lengthName[] = { "short", "long", "long long", "NoLength" };
     34const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic" };
     35const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary",  };
     36const char *DeclarationNode::modifierName[]  = { "signed", "unsigned", "short", "long" };
    3937const char *DeclarationNode::aggregateName[] = { "struct", "union", "context" };
    40 const char *DeclarationNode::typeClassName[] = { "otype", "dtype", "ftype" };
     38const char *DeclarationNode::typeClassName[] = { "type", "dtype", "ftype" };
    4139const char *DeclarationNode::builtinTypeName[] = { "__builtin_va_list" };
    4240
     
    5553                linkage( ::linkage ),
    5654                extension( false ) {
    57         variable.tyClass = DeclarationNode::Otype;
     55        variable.tyClass = DeclarationNode::Type;
    5856        variable.assertions = nullptr;
    5957
     
    190188        DeclarationNode *newnode = new DeclarationNode;
    191189        newnode->type = new TypeData( TypeData::Basic );
    192         newnode->type->basictype = bt;
     190        newnode->type->basic.typeSpec.push_back( bt );
    193191        return newnode;
    194192} // DeclarationNode::newBasicType
    195193
    196 DeclarationNode * DeclarationNode::newComplexType( ComplexType ct ) {
     194DeclarationNode * DeclarationNode::newModifier( Modifier mod ) {
    197195        DeclarationNode *newnode = new DeclarationNode;
    198196        newnode->type = new TypeData( TypeData::Basic );
    199         newnode->type->complextype = ct;
    200         return newnode;
    201 } // DeclarationNode::newComplexType
    202 
    203 DeclarationNode * 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 
    210 DeclarationNode * 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
     197        newnode->type->basic.modifiers.push_back( mod );
     198        return newnode;
     199} // DeclarationNode::newModifier
    216200
    217201DeclarationNode * DeclarationNode::newFromTypedef( std::string *name ) {
     
    404388}
    405389
    406 void appendError( string & dst, const string & src ) {
    407         if ( src.empty() ) return;
    408         if ( dst.empty() ) { dst = src; return; }
    409         dst += ", " + src;
    410 } // appendError
    411 
    412390void DeclarationNode::checkQualifiers( const TypeData *src, const TypeData *dst ) {
    413391        TypeData::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization
    414392
    415393        if ( (qsrc & qdst).any() ) {                                            // common qualifier ?
    416                 for ( int i = 0; i < NoQualifier; i += 1 ) {    // find common qualifiers
    417                         if ( qsrc[i] && qdst[i] ) {
    418                                 appendError( error, string( "duplicate " ) + DeclarationNode::qualifierName[i] );
     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];
    419398                        } // if
    420399                } // for
     
    424403void DeclarationNode::checkStorageClasses( DeclarationNode *q ) {
    425404        if ( storageClass != NoStorageClass && q->storageClass != NoStorageClass ) {
     405                if ( ! error.empty() ) error += ", ";                   // separator
    426406                if ( storageClass == q->storageClass ) {                // duplicate qualifier
    427                         appendError( error, string( "duplicate " ) + storageName[ storageClass ] );
     407                        error += string( "duplicate " ) + storageName[ storageClass ];
    428408                } else {                                                                                // only one storage class
    429                         appendError( error, string( "conflicting " ) + storageName[ storageClass ] + " & " + storageName[ q->storageClass ] );
    430                         q->storageClass = storageClass;                         // FIX ERROR, prevent assertions from triggering
    431                 } // if
    432         } // if
    433         appendError( error, q->error );
     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
    434418} // DeclarationNode::copyStorageClasses
    435419
    436420DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) {
    437         isInline = isInline || q->isInline;
    438         isNoreturn = isNoreturn || q->isNoreturn;
     421        isInline = isInline | q->isInline;
     422        isNoreturn = isNoreturn | q->isNoreturn;
    439423        // do not overwrite an existing value with NoStorageClass
    440424        if ( q->storageClass != NoStorageClass ) {
     
    499483                                if ( src->kind != TypeData::Unknown ) {
    500484                                        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 );
     485                                        dst->basic.modifiers.splice( dst->basic.modifiers.end(), src->basic.modifiers );
     486                                        dst->basic.typeSpec.splice( dst->basic.typeSpec.end(), src->basic.typeSpec );
    523487                                } // if
    524488                                break;
     
    911875        while ( cur ) {
    912876                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///       }
    913885                        Declaration *decl = cur->build();
    914886                        if ( decl ) {
Note: See TracChangeset for help on using the changeset viewer.