Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    rf39096c rc1c1112  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 18 23:48:23 2016
    13 // Update Count     : 182
     12// Last Modified On : Thu Aug 25 20:42:25 2016
     13// Update Count     : 232
    1414//
    1515
     
    5050        newnode->isInline = isInline;
    5151        newnode->isNoreturn = isNoreturn;
    52         newnode->bitfieldWidth = maybeClone( bitfieldWidth );
     52        newnode->bitfieldWidth = bitfieldWidth;
    5353        newnode->hasEllipsis = hasEllipsis;
    54         newnode->initializer = maybeClone( initializer );
     54        newnode->initializer = initializer;
    5555        newnode->set_next( maybeClone( get_next() ) );
    5656        newnode->linkage = linkage;
     
    9393        } // if
    9494
    95         if(storageClass != NoStorageClass) os << DeclarationNode::storageName[storageClass] << ' ';
    96         if(isInline) os << DeclarationNode::storageName[Inline] << ' ';
    97         if(isNoreturn) os << DeclarationNode::storageName[Noreturn] << ' ';
     95        if ( storageClass != NoStorageClass ) os << DeclarationNode::storageName[storageClass] << ' ';
     96        if ( isInline ) os << DeclarationNode::storageName[Inline] << ' ';
     97        if ( isNoreturn ) os << DeclarationNode::storageName[Noreturn] << ' ';
    9898        if ( type ) {
    9999                type->print( os, indent );
     
    147147} // DeclarationNode::newFunction
    148148
    149 DeclarationNode *DeclarationNode::newQualifier( Qualifier q ) {
     149DeclarationNode * DeclarationNode::newQualifier( Qualifier q ) {
    150150        DeclarationNode *newnode = new DeclarationNode;
    151151        newnode->type = new TypeData();
    152         newnode->type->qualifiers.push_back( q );
     152        newnode->type->qualifiers[ q ] = 1;
    153153        return newnode;
    154154} // DeclarationNode::newQualifier
    155155
    156 DeclarationNode *DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) {
    157         DeclarationNode *newnode = new DeclarationNode;
    158         switch (sc) {
    159                 case Inline: newnode->isInline = true; break;
    160                 case Noreturn: newnode->isNoreturn = true; break;
    161                 default: newnode->storageClass = sc; break;
    162         }
     156DeclarationNode * DeclarationNode::newForall( DeclarationNode *forall ) {
     157        DeclarationNode *newnode = new DeclarationNode;
     158        newnode->type = new TypeData( TypeData::Unknown );
     159        newnode->type->forall = forall;
     160        return newnode;
     161} // DeclarationNode::newForall
     162
     163DeclarationNode * DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) {
     164        DeclarationNode *newnode = new DeclarationNode;
     165        //switch (sc) {
     166        //      case Inline: newnode->isInline = true; break;
     167        //      case Noreturn: newnode->isNoreturn = true; break;
     168        //      default: newnode->storageClass = sc; break;
     169        //}
     170        newnode->storageClass = sc;
    163171        return newnode;
    164172} // DeclarationNode::newStorageClass
    165173
    166 DeclarationNode *DeclarationNode::newBasicType( BasicType bt ) {
     174DeclarationNode * DeclarationNode::newBasicType( BasicType bt ) {
    167175        DeclarationNode *newnode = new DeclarationNode;
    168176        newnode->type = new TypeData( TypeData::Basic );
     
    171179} // DeclarationNode::newBasicType
    172180
    173 DeclarationNode *DeclarationNode::newBuiltinType( BuiltinType bt ) {
     181DeclarationNode * DeclarationNode::newModifier( Modifier mod ) {
     182        DeclarationNode *newnode = new DeclarationNode;
     183        newnode->type = new TypeData( TypeData::Basic );
     184        newnode->type->basic->modifiers.push_back( mod );
     185        return newnode;
     186} // DeclarationNode::newModifier
     187
     188DeclarationNode * DeclarationNode::newBuiltinType( BuiltinType bt ) {
    174189        DeclarationNode *newnode = new DeclarationNode;
    175190        newnode->type = new TypeData( TypeData::Builtin );
     
    178193} // DeclarationNode::newBuiltinType
    179194
    180 DeclarationNode *DeclarationNode::newModifier( Modifier mod ) {
    181         DeclarationNode *newnode = new DeclarationNode;
    182         newnode->type = new TypeData( TypeData::Basic );
    183         newnode->type->basic->modifiers.push_back( mod );
    184         return newnode;
    185 } // DeclarationNode::newModifier
    186 
    187 DeclarationNode *DeclarationNode::newForall( DeclarationNode *forall ) {
    188         DeclarationNode *newnode = new DeclarationNode;
    189         newnode->type = new TypeData( TypeData::Unknown );
    190         newnode->type->forall = forall;
    191         return newnode;
    192 } // DeclarationNode::newForall
    193 
    194 DeclarationNode *DeclarationNode::newFromTypedef( std::string *name ) {
     195DeclarationNode * DeclarationNode::newFromTypedef( std::string *name ) {
    195196        DeclarationNode *newnode = new DeclarationNode;
    196197        newnode->type = new TypeData( TypeData::SymbolicInst );
     
    201202} // DeclarationNode::newFromTypedef
    202203
    203 DeclarationNode *DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields, bool body ) {
     204DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields, bool body ) {
    204205        DeclarationNode *newnode = new DeclarationNode;
    205206        newnode->type = new TypeData( TypeData::Aggregate );
     
    369370                        src = 0;
    370371                } else {
    371                         dst->qualifiers.splice( dst->qualifiers.end(), src->qualifiers );
    372                 } // if
    373         } // if
    374 }
     372                        dst->qualifiers |= src->qualifiers;
     373                } // if
     374        } // if
     375}
     376
     377void DeclarationNode::checkQualifiers( TypeData *src, TypeData *dst ) {
     378        TypeData::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers;
     379
     380        if ( (qsrc & qdst).any() ) {                                            // common bits between qualifier masks ?
     381                error = "duplicate qualifier ";
     382                int j = 0;                                                                              // separator detector
     383                for ( int i = 0; i < DeclarationNode::NoOfQualifier; i += 1 ) {
     384                        if ( qsrc[i] & qdst[i] ) {                                      // find specific qualifiers in common
     385                                if ( j > 0 ) error += ", ";
     386                                error += DeclarationNode::qualifierName[i];
     387                                j += 1;
     388                        } // if
     389                } // for
     390                error += " in declaration of ";
     391        } // if
     392} // DeclarationNode::checkQualifiers
    375393
    376394DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) {
     
    380398                        if ( ! type ) {
    381399                                type = new TypeData;
     400                        } else {
     401                                checkQualifiers( q->type, type );
    382402                        } // if
    383403                        addQualifiersToType( q->type, type );
     
    405425        isInline = isInline || q->isInline;
    406426        isNoreturn = isNoreturn || q->isNoreturn;
    407         if(storageClass == NoStorageClass) {
     427        if ( storageClass == NoStorageClass ) {
    408428                storageClass = q->storageClass;
    409         }
    410         else if (q->storageClass != NoStorageClass) {
     429        } else if ( q->storageClass != NoStorageClass ) {
    411430                q->error = "invalid combination of storage classes in declaration of ";
    412         }
    413         if(error.empty()) error = q->error;
     431        } // if
     432        if ( error.empty() ) error = q->error;
    414433        return this;
    415434}
     
    430449                        switch ( dst->kind ) {
    431450                          case TypeData::Unknown:
    432                                 src->qualifiers.splice( src->qualifiers.end(), dst->qualifiers );
     451                                src->qualifiers |= dst->qualifiers;
    433452                                dst = src;
    434453                                src = 0;
    435454                                break;
    436455                          case TypeData::Basic:
    437                                 dst->qualifiers.splice( dst->qualifiers.end(), src->qualifiers );
     456                                dst->qualifiers |= src->qualifiers;
    438457                                if ( src->kind != TypeData::Unknown ) {
    439458                                        assert( src->kind == TypeData::Basic );
     
    451470                                                dst->base->aggInst->params = maybeClone( src->aggregate->actuals );
    452471                                        } // if
    453                                         dst->base->qualifiers.splice( dst->base->qualifiers.end(), src->qualifiers );
     472                                        dst->base->qualifiers |= src->qualifiers;
    454473                                        src = 0;
    455474                                        break;
     
    480499                                                type->aggInst->params = maybeClone( o->type->aggregate->actuals );
    481500                                        } // if
    482                                         type->qualifiers.splice( type->qualifiers.end(), o->type->qualifiers );
     501                                        type->qualifiers |= o->type->qualifiers;
    483502                                } else {
    484503                                        type = o->type;
     
    615634                                        p->type->base->aggInst->params = maybeClone( type->aggregate->actuals );
    616635                                } // if
    617                                 p->type->base->qualifiers.splice( p->type->base->qualifiers.end(), type->qualifiers );
     636                                p->type->base->qualifiers |= type->qualifiers;
    618637                                break;
    619638
     
    652671                                        lastArray->base->aggInst->params = maybeClone( type->aggregate->actuals );
    653672                                } // if
    654                                 lastArray->base->qualifiers.splice( lastArray->base->qualifiers.end(), type->qualifiers );
     673                                lastArray->base->qualifiers |= type->qualifiers;
    655674                                break;
    656675                          default:
     
    804823                                        *out++ = decl;
    805824                                } // if
    806                                 delete extr;
    807825                        } // if
    808826                        Declaration *decl = cur->build();
     
    875893
    876894Declaration *DeclarationNode::build() const {
    877         if( !error.empty() ) throw SemanticError( error, this );
     895        if ( ! error.empty() ) throw SemanticError( error, this );
    878896        if ( type ) {
    879897                return type->buildDecl( name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
Note: See TracChangeset for help on using the changeset viewer.