Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    rc1c1112 rf39096c  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 25 20:42:25 2016
    13 // Update Count     : 232
     12// Last Modified On : Thu Aug 18 23:48:23 2016
     13// Update Count     : 182
    1414//
    1515
     
    5050        newnode->isInline = isInline;
    5151        newnode->isNoreturn = isNoreturn;
    52         newnode->bitfieldWidth = bitfieldWidth;
     52        newnode->bitfieldWidth = maybeClone( bitfieldWidth );
    5353        newnode->hasEllipsis = hasEllipsis;
    54         newnode->initializer = initializer;
     54        newnode->initializer = maybeClone( 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[ q ] = 1;
     152        newnode->type->qualifiers.push_back( q );
    153153        return newnode;
    154154} // DeclarationNode::newQualifier
    155155
    156 DeclarationNode * DeclarationNode::newForall( DeclarationNode *forall ) {
     156DeclarationNode *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        }
     163        return newnode;
     164} // DeclarationNode::newStorageClass
     165
     166DeclarationNode *DeclarationNode::newBasicType( BasicType bt ) {
     167        DeclarationNode *newnode = new DeclarationNode;
     168        newnode->type = new TypeData( TypeData::Basic );
     169        newnode->type->basic->typeSpec.push_back( bt );
     170        return newnode;
     171} // DeclarationNode::newBasicType
     172
     173DeclarationNode *DeclarationNode::newBuiltinType( BuiltinType bt ) {
     174        DeclarationNode *newnode = new DeclarationNode;
     175        newnode->type = new TypeData( TypeData::Builtin );
     176        newnode->type->builtin->type = bt;
     177        return newnode;
     178} // DeclarationNode::newBuiltinType
     179
     180DeclarationNode *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
     187DeclarationNode *DeclarationNode::newForall( DeclarationNode *forall ) {
    157188        DeclarationNode *newnode = new DeclarationNode;
    158189        newnode->type = new TypeData( TypeData::Unknown );
     
    161192} // DeclarationNode::newForall
    162193
    163 DeclarationNode * 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;
    171         return newnode;
    172 } // DeclarationNode::newStorageClass
    173 
    174 DeclarationNode * DeclarationNode::newBasicType( BasicType bt ) {
    175         DeclarationNode *newnode = new DeclarationNode;
    176         newnode->type = new TypeData( TypeData::Basic );
    177         newnode->type->basic->typeSpec.push_back( bt );
    178         return newnode;
    179 } // DeclarationNode::newBasicType
    180 
    181 DeclarationNode * 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 
    188 DeclarationNode * DeclarationNode::newBuiltinType( BuiltinType bt ) {
    189         DeclarationNode *newnode = new DeclarationNode;
    190         newnode->type = new TypeData( TypeData::Builtin );
    191         newnode->type->builtin->type = bt;
    192         return newnode;
    193 } // DeclarationNode::newBuiltinType
    194 
    195 DeclarationNode * DeclarationNode::newFromTypedef( std::string *name ) {
     194DeclarationNode *DeclarationNode::newFromTypedef( std::string *name ) {
    196195        DeclarationNode *newnode = new DeclarationNode;
    197196        newnode->type = new TypeData( TypeData::SymbolicInst );
     
    202201} // DeclarationNode::newFromTypedef
    203202
    204 DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields, bool body ) {
     203DeclarationNode *DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields, bool body ) {
    205204        DeclarationNode *newnode = new DeclarationNode;
    206205        newnode->type = new TypeData( TypeData::Aggregate );
     
    370369                        src = 0;
    371370                } else {
    372                         dst->qualifiers |= src->qualifiers;
    373                 } // if
    374         } // if
    375 }
    376 
    377 void 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
     371                        dst->qualifiers.splice( dst->qualifiers.end(), src->qualifiers );
     372                } // if
     373        } // if
     374}
    393375
    394376DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) {
     
    398380                        if ( ! type ) {
    399381                                type = new TypeData;
    400                         } else {
    401                                 checkQualifiers( q->type, type );
    402382                        } // if
    403383                        addQualifiersToType( q->type, type );
     
    425405        isInline = isInline || q->isInline;
    426406        isNoreturn = isNoreturn || q->isNoreturn;
    427         if ( storageClass == NoStorageClass ) {
     407        if(storageClass == NoStorageClass) {
    428408                storageClass = q->storageClass;
    429         } else if ( q->storageClass != NoStorageClass ) {
     409        }
     410        else if (q->storageClass != NoStorageClass) {
    430411                q->error = "invalid combination of storage classes in declaration of ";
    431         } // if
    432         if ( error.empty() ) error = q->error;
     412        }
     413        if(error.empty()) error = q->error;
    433414        return this;
    434415}
     
    449430                        switch ( dst->kind ) {
    450431                          case TypeData::Unknown:
    451                                 src->qualifiers |= dst->qualifiers;
     432                                src->qualifiers.splice( src->qualifiers.end(), dst->qualifiers );
    452433                                dst = src;
    453434                                src = 0;
    454435                                break;
    455436                          case TypeData::Basic:
    456                                 dst->qualifiers |= src->qualifiers;
     437                                dst->qualifiers.splice( dst->qualifiers.end(), src->qualifiers );
    457438                                if ( src->kind != TypeData::Unknown ) {
    458439                                        assert( src->kind == TypeData::Basic );
     
    470451                                                dst->base->aggInst->params = maybeClone( src->aggregate->actuals );
    471452                                        } // if
    472                                         dst->base->qualifiers |= src->qualifiers;
     453                                        dst->base->qualifiers.splice( dst->base->qualifiers.end(), src->qualifiers );
    473454                                        src = 0;
    474455                                        break;
     
    499480                                                type->aggInst->params = maybeClone( o->type->aggregate->actuals );
    500481                                        } // if
    501                                         type->qualifiers |= o->type->qualifiers;
     482                                        type->qualifiers.splice( type->qualifiers.end(), o->type->qualifiers );
    502483                                } else {
    503484                                        type = o->type;
     
    634615                                        p->type->base->aggInst->params = maybeClone( type->aggregate->actuals );
    635616                                } // if
    636                                 p->type->base->qualifiers |= type->qualifiers;
     617                                p->type->base->qualifiers.splice( p->type->base->qualifiers.end(), type->qualifiers );
    637618                                break;
    638619
     
    671652                                        lastArray->base->aggInst->params = maybeClone( type->aggregate->actuals );
    672653                                } // if
    673                                 lastArray->base->qualifiers |= type->qualifiers;
     654                                lastArray->base->qualifiers.splice( lastArray->base->qualifiers.end(), type->qualifiers );
    674655                                break;
    675656                          default:
     
    823804                                        *out++ = decl;
    824805                                } // if
     806                                delete extr;
    825807                        } // if
    826808                        Declaration *decl = cur->build();
     
    893875
    894876Declaration *DeclarationNode::build() const {
    895         if ( ! error.empty() ) throw SemanticError( error, this );
     877        if( !error.empty() ) throw SemanticError( error, this );
    896878        if ( type ) {
    897879                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.