Ignore:
Timestamp:
Aug 30, 2016, 4:25:55 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, 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:
90e2334, fa463f1
Parents:
a2a8d2a6 (diff), ced2e989 (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' of plg.uwaterloo.ca:/u/cforall/software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    ra2a8d2a6 r32a2a99  
    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 : Sun Aug 28 22:12:44 2016
     13// Update Count     : 278
    1414//
    1515
     
    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( const TypeData *src, const 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:
     
    782801DeclarationNode *DeclarationNode::extractAggregate() const {
    783802        if ( type ) {
    784                 TypeData *ret = type->extractAggregate();
     803                TypeData *ret = typeextractAggregate( type );
    785804                if ( ret ) {
    786805                        DeclarationNode *newnode = new DeclarationNode;
     
    875894
    876895Declaration *DeclarationNode::build() const {
    877         if( !error.empty() ) throw SemanticError( error, this );
     896        if ( ! error.empty() ) throw SemanticError( error, this );
    878897        if ( type ) {
    879                 return type->buildDecl( name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
     898                return buildDecl( type, name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
    880899        } // if
    881900        if ( ! isInline && ! isNoreturn ) {
     
    890909        switch ( type->kind ) {
    891910          case TypeData::Enum:
    892                 return new EnumInstType( type->buildQualifiers(), type->enumeration->name );
     911                return new EnumInstType( buildQualifiers( type ), type->enumeration->name );
    893912          case TypeData::Aggregate: {
    894913                  ReferenceToType *ret;
    895914                  switch ( type->aggregate->kind ) {
    896915                        case DeclarationNode::Struct:
    897                           ret = new StructInstType( type->buildQualifiers(), type->aggregate->name );
     916                          ret = new StructInstType( buildQualifiers( type ), type->aggregate->name );
    898917                          break;
    899918                        case DeclarationNode::Union:
    900                           ret = new UnionInstType( type->buildQualifiers(), type->aggregate->name );
     919                          ret = new UnionInstType( buildQualifiers( type ), type->aggregate->name );
    901920                          break;
    902921                        case DeclarationNode::Trait:
    903                           ret = new TraitInstType( type->buildQualifiers(), type->aggregate->name );
     922                          ret = new TraitInstType( buildQualifiers( type ), type->aggregate->name );
    904923                          break;
    905924                        default:
     
    910929          }
    911930          case TypeData::Symbolic: {
    912                   TypeInstType *ret = new TypeInstType( type->buildQualifiers(), type->symbolic->name, false );
     931                  TypeInstType *ret = new TypeInstType( buildQualifiers( type ), type->symbolic->name, false );
    913932                  buildList( type->symbolic->actuals, ret->get_parameters() );
    914933                  return ret;
    915934          }
    916935          default:
    917                 return type->build();
     936                return typebuild( type );
    918937        } // switch
    919938}
Note: See TracChangeset for help on using the changeset viewer.