Changeset be8bd88 for src/Parser


Ignore:
Timestamp:
Mar 8, 2017, 3:22:50 PM (9 years ago)
Author:
Aaron Moss <a3moss@…>
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:
031a2c95, 0e7ea335
Parents:
87c3bef (diff), 6363ad1 (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:software/cfa/cfa-cc

Location:
src/Parser
Files:
3 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r87c3bef rbe8bd88  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Feb 23 22:21:06 2017
    13 // Update Count     : 775
     12// Last Modified On : Tue Mar  7 08:02:09 2017
     13// Update Count     : 936
    1414//
    1515
     
    1919#include <algorithm>
    2020#include <cassert>
     21#include <strings.h>                                                                    // ffs
    2122
    2223#include "TypeData.h"
     
    3233
    3334// These must remain in the same order as the corresponding DeclarationNode enumerations.
    34 const char * DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", "NoStorageClass" };
    35 const char * DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic", "NoQualifier" };
    36 const char * DeclarationNode::basicTypeName[] = { "void", "_Bool", "char", "int", "float", "double", "long double", "NoBasicType" };
    37 const char * DeclarationNode::complexTypeName[] = { "_Complex", "_Imaginary", "NoComplexType" };
    38 const char * DeclarationNode::signednessName[] = { "signed", "unsigned", "NoSignedness" };
    39 const char * DeclarationNode::lengthName[] = { "short", "long", "long long", "NoLength" };
    40 const char * DeclarationNode::aggregateName[] = { "struct", "union", "context" };
    41 const char * DeclarationNode::typeClassName[] = { "otype", "dtype", "ftype" };
    42 const char * DeclarationNode::builtinTypeName[] = { "__builtin_va_list" };
     35const char * DeclarationNode::storageClassNames[] = { "extern", "static", "auto", "register", "_Thread_local", "NoStorageClassNames" };
     36const char * DeclarationNode::funcSpecifierNames[] = { "inline", "fortran", "_Noreturn", "NoFunctionSpecifierNames" };
     37const char * DeclarationNode::typeQualifierNames[] = { "const", "restrict", "volatile", "lvalue", "mutex", "_Atomic", "NoTypeQualifierNames" };
     38const char * DeclarationNode::basicTypeNames[] = { "void", "_Bool", "char", "int", "float", "double", "long double", "NoBasicTypeNames" };
     39const char * DeclarationNode::complexTypeNames[] = { "_Complex", "_Imaginary", "NoComplexTypeNames" };
     40const char * DeclarationNode::signednessNames[] = { "signed", "unsigned", "NoSignednessNames" };
     41const char * DeclarationNode::lengthNames[] = { "short", "long", "long long", "NoLengthNames" };
     42const char * DeclarationNode::aggregateNames[] = { "struct", "union", "context", "NoAggregateNames" };
     43const char * DeclarationNode::typeClassNames[] = { "otype", "dtype", "ftype", "NoTypeClassNames" };
     44const char * DeclarationNode::builtinTypeNames[] = { "__builtin_va_list", "NoBuiltinTypeNames" };
    4345
    4446UniqueName DeclarationNode::anonymous( "__anonymous" );
     
    4850DeclarationNode::DeclarationNode() :
    4951                type( nullptr ),
    50                 storageClass( NoStorageClass ),
    5152                bitfieldWidth( nullptr ),
    52                 isInline( false ),
    53                 isNoreturn( false ),
    5453                hasEllipsis( false ),
    5554                linkage( ::linkage ),
     
    9089
    9190        newnode->type = maybeClone( type );
    92         newnode->storageClass = storageClass;
     91        newnode->storageClasses = storageClasses;
    9392        newnode->bitfieldWidth = maybeClone( bitfieldWidth );
    94         newnode->isInline = isInline;
    95         newnode->isNoreturn = isNoreturn;
     93        newnode->funcSpecs = funcSpecs;
    9694        newnode->enumeratorValue.reset( maybeClone( enumeratorValue.get() ) );
    9795        newnode->hasEllipsis = hasEllipsis;
     
    118116}
    119117
     118void DeclarationNode::print_StorageClass( std::ostream & output, StorageClasses storageClasses ) {
     119        if ( storageClasses.any() ) {                                                           // function specifiers?
     120                for ( unsigned int i = 0; i < DeclarationNode::NoStorageClass; i += 1 ) {
     121                        if ( storageClasses[i] ) {
     122                                output << DeclarationNode::storageClassNames[i] << ' ';
     123                        } // if
     124                } // for
     125        } // if
     126} // print_StorageClass
     127
     128void DeclarationNode::print_FuncSpec( std::ostream & output, DeclarationNode::FuncSpecifiers funcSpec ) {
     129        if ( funcSpec.any() ) {                                                         // function specifiers?
     130                for ( unsigned int i = 0; i < DeclarationNode::NoFuncSpecifier; i += 1 ) {
     131                        if ( funcSpec[i] ) {
     132                                output << DeclarationNode::funcSpecifierNames[i] << ' ';
     133                        } // if
     134                } // for
     135        } // if
     136} // print_FuncSpec
     137
    120138void DeclarationNode::print( std::ostream &os, int indent ) const {
    121139        os << string( indent, ' ' );
     
    130148        } // if
    131149
    132         if ( storageClass != NoStorageClass ) os << DeclarationNode::storageName[storageClass] << ' ';
    133         if ( isInline ) os << DeclarationNode::storageName[Inline] << ' ';
    134         if ( isNoreturn ) os << DeclarationNode::storageName[Noreturn] << ' ';
     150        print_StorageClass( os, storageClasses );
     151        print_FuncSpec( os, funcSpecs );
     152
    135153        if ( type ) {
    136154                type->print( os, indent );
     
    183201} // DeclarationNode::newFunction
    184202
    185 DeclarationNode * DeclarationNode::newQualifier( Qualifier q ) {
     203
     204DeclarationNode * DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) {
     205        DeclarationNode * newnode = new DeclarationNode;
     206        newnode->storageClasses[ sc ] = true;
     207        return newnode;
     208} // DeclarationNode::newStorageClass
     209
     210DeclarationNode * DeclarationNode::newFuncSpecifier( DeclarationNode::FuncSpecifier fs ) {
     211        DeclarationNode * newnode = new DeclarationNode;
     212        newnode->funcSpecs[ fs ] = true;
     213        return newnode;
     214} // DeclarationNode::newFuncSpecifier
     215
     216DeclarationNode * DeclarationNode::newTypeQualifier( TypeQualifier tq ) {
    186217        DeclarationNode * newnode = new DeclarationNode;
    187218        newnode->type = new TypeData();
    188         newnode->type->qualifiers[ q ] = 1;
     219        newnode->type->typeQualifiers[ tq ] = true;
    189220        return newnode;
    190221} // DeclarationNode::newQualifier
     222
     223DeclarationNode * DeclarationNode::newBasicType( BasicType bt ) {
     224        DeclarationNode * newnode = new DeclarationNode;
     225        newnode->type = new TypeData( TypeData::Basic );
     226        newnode->type->basictype = bt;
     227        return newnode;
     228} // DeclarationNode::newBasicType
     229
     230DeclarationNode * DeclarationNode::newComplexType( ComplexType ct ) {
     231        DeclarationNode * newnode = new DeclarationNode;
     232        newnode->type = new TypeData( TypeData::Basic );
     233        newnode->type->complextype = ct;
     234        return newnode;
     235} // DeclarationNode::newComplexType
     236
     237DeclarationNode * DeclarationNode::newSignedNess( Signedness sn ) {
     238        DeclarationNode * newnode = new DeclarationNode;
     239        newnode->type = new TypeData( TypeData::Basic );
     240        newnode->type->signedness = sn;
     241        return newnode;
     242} // DeclarationNode::newSignedNess
     243
     244DeclarationNode * DeclarationNode::newLength( Length lnth ) {
     245        DeclarationNode * newnode = new DeclarationNode;
     246        newnode->type = new TypeData( TypeData::Basic );
     247        newnode->type->length = lnth;
     248        return newnode;
     249} // DeclarationNode::newLength
    191250
    192251DeclarationNode * DeclarationNode::newForall( DeclarationNode * forall ) {
     
    196255        return newnode;
    197256} // DeclarationNode::newForall
    198 
    199 DeclarationNode * DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) {
    200         DeclarationNode * newnode = new DeclarationNode;
    201         newnode->storageClass = sc;
    202         return newnode;
    203 } // DeclarationNode::newStorageClass
    204 
    205 DeclarationNode * DeclarationNode::newBasicType( BasicType bt ) {
    206         DeclarationNode * newnode = new DeclarationNode;
    207         newnode->type = new TypeData( TypeData::Basic );
    208         newnode->type->basictype = bt;
    209         return newnode;
    210 } // DeclarationNode::newBasicType
    211 
    212 DeclarationNode * DeclarationNode::newComplexType( ComplexType ct ) {
    213         DeclarationNode * newnode = new DeclarationNode;
    214         newnode->type = new TypeData( TypeData::Basic );
    215         newnode->type->complextype = ct;
    216         return newnode;
    217 } // DeclarationNode::newComplexType
    218 
    219 DeclarationNode * DeclarationNode::newSignedNess( Signedness sn ) {
    220         DeclarationNode * newnode = new DeclarationNode;
    221         newnode->type = new TypeData( TypeData::Basic );
    222         newnode->type->signedness = sn;
    223         return newnode;
    224 } // DeclarationNode::newSignedNess
    225 
    226 DeclarationNode * DeclarationNode::newLength( Length lnth ) {
    227         DeclarationNode * newnode = new DeclarationNode;
    228         newnode->type = new TypeData( TypeData::Basic );
    229         newnode->type->length = lnth;
    230         return newnode;
    231 } // DeclarationNode::newLength
    232257
    233258DeclarationNode * DeclarationNode::newFromTypedef( string * name ) {
     
    428453
    429454void DeclarationNode::checkQualifiers( const TypeData * src, const TypeData * dst ) {
    430         TypeData::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization
     455        const TypeData::TypeQualifiers qsrc = src->typeQualifiers, qdst = dst->typeQualifiers; // optimization
    431456
    432457        if ( (qsrc & qdst).any() ) {                                            // common qualifier ?
    433                 for ( int i = 0; i < NoQualifier; i += 1 ) {    // find common qualifiers
     458                for ( unsigned int i = 0; i < NoTypeQualifier; i += 1 ) { // find common qualifiers
    434459                        if ( qsrc[i] && qdst[i] ) {
    435                                 appendError( error, string( "duplicate " ) + DeclarationNode::qualifierName[i] );
     460                                appendError( error, string( "duplicate " ) + DeclarationNode::typeQualifierNames[i] );
    436461                        } // if
    437462                } // for
    438         } // if
     463        } // for
    439464} // DeclarationNode::checkQualifiers
    440465
    441 void DeclarationNode::checkStorageClasses( DeclarationNode * q ) {
    442         if ( storageClass != NoStorageClass && q->storageClass != NoStorageClass ) {
    443                 if ( storageClass == q->storageClass ) {                // duplicate qualifier
    444                         appendError( error, string( "duplicate " ) + storageName[ storageClass ] );
    445                 } else {                                                                                // only one storage class
    446                         appendError( error, string( "conflicting " ) + storageName[ storageClass ] + " & " + storageName[ q->storageClass ] );
    447                         q->storageClass = storageClass;                         // FIX ERROR, prevent assertions from triggering
    448                 } // if
    449         } // if
    450         appendError( error, q->error );
    451 } // DeclarationNode::checkStorageClasses
    452 
    453 DeclarationNode * DeclarationNode::copyStorageClasses( DeclarationNode * q ) {
    454         isInline = isInline || q->isInline;
    455         isNoreturn = isNoreturn || q->isNoreturn;
    456         // do not overwrite an existing value with NoStorageClass
    457         if ( q->storageClass != NoStorageClass ) {
    458                 assert( storageClass == NoStorageClass || storageClass == q->storageClass );
    459                 storageClass = q->storageClass;
    460         } // if
     466void DeclarationNode::checkSpecifiers( DeclarationNode * src ) {
     467        if ( (funcSpecs & src->funcSpecs).any() ) {                     // common specifier ?
     468                for ( unsigned int i = 0; i < NoFuncSpecifier; i += 1 ) { // find common specifier
     469                        if ( funcSpecs[i] && src->funcSpecs[i] ) {
     470                                appendError( error, string( "duplicate " ) + DeclarationNode::funcSpecifierNames[i] );
     471                        } // if
     472                } // for
     473        } // if
     474
     475        if ( storageClasses != 0 && src->storageClasses != 0 ) { // any reason to check ?
     476                if ( (storageClasses & src->storageClasses).any() ) { // duplicates ?
     477                        for ( unsigned int i = 0; i < NoStorageClass; i += 1 ) { // find duplicates
     478                                if ( storageClasses[i] && src->storageClasses[i] ) {
     479                                        appendError( error, string( "duplicate " ) + storageClassNames[i] );
     480                                } // if
     481                        } // for
     482                        // src is the new item being added and has a single bit
     483                } else if ( ! src->storageClasses[ Threadlocal ] ) { // conflict ?
     484                        appendError( error, string( "conflicting " ) + storageClassNames[ffs( storageClasses.to_ulong() ) - 1] +
     485                                                 " & " + storageClassNames[ffs( src->storageClasses.to_ulong() ) - 1] );
     486                        src->storageClasses.reset();                            // FIX to preserve invariant of one basic storage specifier
     487                } // if
     488        } // if
     489
     490        appendError( error, src->error );
     491} // DeclarationNode::checkSpecifiers
     492
     493DeclarationNode * DeclarationNode::copySpecifiers( DeclarationNode * q ) {
     494        funcSpecs = funcSpecs | q->funcSpecs;
     495        storageClasses = storageClasses | q->storageClasses;
    461496
    462497        for ( Attribute *attr: reverseIterate( q->attributes ) ) {
     
    464499        } // for
    465500        return this;
    466 } // DeclarationNode::copyStorageClasses
     501} // DeclarationNode::copySpecifiers
    467502
    468503static void addQualifiersToType( TypeData *&src, TypeData * dst ) {
     
    481516                src = nullptr;
    482517        } else {
    483                 dst->qualifiers |= src->qualifiers;
     518                dst->typeQualifiers |= src->typeQualifiers;
    484519        } // if
    485520} // addQualifiersToType
     
    488523        if ( ! q ) { delete q; return this; }
    489524
    490         checkStorageClasses( q );
    491         copyStorageClasses( q );
     525        checkSpecifiers( q );
     526        copySpecifiers( q );
    492527
    493528        if ( ! q->type ) {
     
    518553        } // if
    519554
    520         checkQualifiers( q->type, type );
     555        checkQualifiers( type, q->type );
    521556        addQualifiersToType( q->type, type );
    522557
     
    539574                switch ( dst->kind ) {
    540575                  case TypeData::Unknown:
    541                         src->qualifiers |= dst->qualifiers;
     576                        src->typeQualifiers |= dst->typeQualifiers;
    542577                        dst = src;
    543578                        src = nullptr;
    544579                        break;
    545580                  case TypeData::Basic:
    546                         dst->qualifiers |= src->qualifiers;
     581                        dst->typeQualifiers |= src->typeQualifiers;
    547582                        if ( src->kind != TypeData::Unknown ) {
    548583                                assert( src->kind == TypeData::Basic );
     
    551586                                        dst->basictype = src->basictype;
    552587                                } else if ( src->basictype != DeclarationNode::NoBasicType )
    553                                         throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::basicTypeName[ src->basictype ] + " in type: ", src );
     588                                        throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::basicTypeNames[ src->basictype ] + " in type: ", src );
    554589
    555590                                if ( dst->complextype == DeclarationNode::NoComplexType ) {
    556591                                        dst->complextype = src->complextype;
    557592                                } else if ( src->complextype != DeclarationNode::NoComplexType )
    558                                         throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::complexTypeName[ src->complextype ] + " in type: ", src );
     593                                        throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::complexTypeNames[ src->complextype ] + " in type: ", src );
    559594
    560595                                if ( dst->signedness == DeclarationNode::NoSignedness ) {
    561596                                        dst->signedness = src->signedness;
    562597                                } else if ( src->signedness != DeclarationNode::NoSignedness )
    563                                         throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::signednessName[ src->signedness ] + " in type: ", src );
     598                                        throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::signednessNames[ src->signedness ] + " in type: ", src );
    564599
    565600                                if ( dst->length == DeclarationNode::NoLength ) {
     
    568603                                        dst->length = DeclarationNode::LongLong;
    569604                                } else if ( src->length != DeclarationNode::NoLength )
    570                                         throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::lengthName[ src->length ] + " in type: ", src );
     605                                        throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::lengthNames[ src->length ] + " in type: ", src );
    571606                        } // if
    572607                        break;
     
    580615                                        dst->base->aggInst.params = maybeClone( src->aggregate.actuals );
    581616                                } // if
    582                                 dst->base->qualifiers |= src->qualifiers;
     617                                dst->base->typeQualifiers |= src->typeQualifiers;
    583618                                src = nullptr;
    584619                                break;
     
    599634DeclarationNode * DeclarationNode::addType( DeclarationNode * o ) {
    600635        if ( o ) {
    601                 checkStorageClasses( o );
    602                 copyStorageClasses( o );
     636                checkSpecifiers( o );
     637                copySpecifiers( o );
    603638                if ( o->type ) {
    604639                        if ( ! type ) {
     
    612647                                                type->aggInst.hoistType = o->type->enumeration.body;
    613648                                        } // if
    614                                         type->qualifiers |= o->type->qualifiers;
     649                                        type->typeQualifiers |= o->type->typeQualifiers;
    615650                                } else {
    616651                                        type = o->type;
     
    768803                                        p->type->base->aggInst.params = maybeClone( type->aggregate.actuals );
    769804                                } // if
    770                                 p->type->base->qualifiers |= type->qualifiers;
     805                                p->type->base->typeQualifiers |= type->typeQualifiers;
    771806                                break;
    772807
     
    805840                                        lastArray->base->aggInst.params = maybeClone( type->aggregate.actuals );
    806841                                } // if
    807                                 lastArray->base->qualifiers |= type->qualifiers;
     842                                lastArray->base->typeQualifiers |= type->typeQualifiers;
    808843                                break;
    809844                          default:
     
    854889        DeclarationNode * newnode = new DeclarationNode;
    855890        newnode->type = maybeClone( type );
    856         assert( storageClass == NoStorageClass );
    857         newnode->copyStorageClasses( this );
     891        newnode->copySpecifiers( this );
    858892        assert( newName );
    859893        newnode->name = newName;
     
    864898        if ( ! o ) return nullptr;
    865899
    866         o->copyStorageClasses( this );
     900        o->copySpecifiers( this );
    867901        if ( type ) {
    868902                TypeData * srcType = type;
     
    956990                                } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) {
    957991                                        StructInstType * inst = new StructInstType( Type::Qualifiers(), agg->get_name() );
    958                                         auto obj = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, nullptr, inst, nullptr );
     992                                        auto obj = new ObjectDecl( "", DeclarationNode::StorageClasses(), linkage, nullptr, inst, nullptr );
    959993                                        obj->location = cur->location;
    960994                                        * out++ = obj;
     
    962996                                } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) {
    963997                                        UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->get_name() );
    964                                         auto obj = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, nullptr, inst, nullptr );
     998                                        auto obj = new ObjectDecl( "", DeclarationNode::StorageClasses(), linkage, nullptr, inst, nullptr );
    965999                                        obj->location = cur->location;
    9661000                                        * out++ = obj;
     
    10051039        } // if
    10061040
    1007 //      if ( variable.name ) {
    10081041        if ( variable.tyClass != NoTypeClass ) {
    10091042                static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Dtype, TypeDecl::Ftype, TypeDecl::Ttype };
    10101043                assertf( sizeof(kindMap)/sizeof(kindMap[0] == NoTypeClass-1), "DeclarationNode::build: kindMap is out of sync." );
    10111044                assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." );
    1012 //              TypeDecl * ret = new TypeDecl( *variable.name, DeclarationNode::NoStorageClass, nullptr, kindMap[ variable.tyClass ] );
    1013                 TypeDecl * ret = new TypeDecl( *name, DeclarationNode::NoStorageClass, nullptr, kindMap[ variable.tyClass ] );
     1045                TypeDecl * ret = new TypeDecl( *name, DeclarationNode::StorageClasses(), nullptr, kindMap[ variable.tyClass ] );
    10141046                buildList( variable.assertions, ret->get_assertions() );
    10151047                return ret;
     
    10171049
    10181050        if ( type ) {
    1019                 return buildDecl( type, name ? *name : string( "" ), storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, asmName, maybeBuild< Initializer >(initializer), attributes )->set_extension( extension );
    1020         } // if
    1021 
    1022         if ( ! isInline && ! isNoreturn ) {
    1023                 assertf( name, "ObjectDecl are assumed to have names\n" );
    1024                 return (new ObjectDecl( *name, storageClass, linkage, maybeBuild< Expression >( bitfieldWidth ), nullptr, maybeBuild< Initializer >( initializer ) ))->set_asmName( asmName )->set_extension( extension );
    1025         } // if
    1026 
    1027         throw SemanticError( "invalid function specifier ", this );
     1051                // Function specifiers can only appear on a function definition/declaration.
     1052                //
     1053                //    inline _Noreturn int f();                 // allowed
     1054                //    inline _Noreturn int g( int i );  // allowed
     1055                //    inline _Noreturn int i;                   // disallowed
     1056                if ( type->kind != TypeData::Function && funcSpecs.any() ) {
     1057                        throw SemanticError( "invalid function specifier for ", this );
     1058                } // if
     1059                return buildDecl( type, name ? *name : string( "" ), storageClasses, maybeBuild< Expression >( bitfieldWidth ), funcSpecs, linkage, asmName, maybeBuild< Initializer >(initializer), attributes )->set_extension( extension );
     1060        } // if
     1061
     1062        // SUE's cannot have function specifiers, either
     1063        //
     1064        //    inlne _Noreturn struct S { ... };         // disallowed
     1065        //    inlne _Noreturn enum   E { ... };         // disallowed
     1066        if ( funcSpecs.any() ) {
     1067                throw SemanticError( "invalid function specifier for ", this );
     1068        } // if
     1069        assertf( name, "ObjectDecl must a have name\n" );
     1070        return (new ObjectDecl( *name, storageClasses, linkage, maybeBuild< Expression >( bitfieldWidth ), nullptr, maybeBuild< Initializer >( initializer ) ))->set_asmName( asmName )->set_extension( extension );
    10281071}
    10291072
     
    10321075
    10331076        if ( attr.expr ) {
    1034 //              return new AttrType( buildQualifiers( type ), *attr.name, attr.expr->build() );
    10351077                return new AttrType( buildQualifiers( type ), *name, attr.expr->build(), attributes );
    10361078        } else if ( attr.type ) {
    1037 //              return new AttrType( buildQualifiers( type ), *attr.name, attr.type->buildType() );
    10381079                return new AttrType( buildQualifiers( type ), *name, attr.type->buildType(), attributes );
    10391080        } // if
  • src/Parser/ExpressionNode.cc

    r87c3bef rbe8bd88  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Sep 16 16:27:44 2016
    13 // Update Count     : 508
     12// Last Modified On : Sat Mar  4 06:58:47 2017
     13// Update Count     : 509
    1414//
    1515
     
    173173
    174174Expression *build_constantZeroOne( const std::string & str ) {
    175         Expression * ret = new ConstantExpr( Constant( str == "0" ? (Type*)new ZeroType( emptyQualifiers ) : (Type*)new OneType( emptyQualifiers ), str ) );
     175        Expression * ret = new ConstantExpr( Constant( str == "0" ? (Type *)new ZeroType( emptyQualifiers ) : (Type*)new OneType( emptyQualifiers ), str ) );
    176176        delete &str;                                                                            // created by lex
    177177        return ret;
     
    275275}
    276276Expression *build_offsetOf( DeclarationNode *decl_node, NameExpr *member ) {
    277         Expression* ret = new UntypedOffsetofExpr( maybeMoveBuildType( decl_node ), member->get_name() );
     277        Expression * ret = new UntypedOffsetofExpr( maybeMoveBuildType( decl_node ), member->get_name() );
    278278        delete member;
    279279        return ret;
  • src/Parser/ParseNode.h

    r87c3bef rbe8bd88  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Feb 23 15:22:10 2017
    13 // Update Count     : 662
     12// Last Modified On : Tue Mar  7 08:10:53 2017
     13// Update Count     : 726
    1414//
    1515
     
    1919#include <string>
    2020#include <list>
     21#include <bitset>
    2122#include <iterator>
    2223#include <memory>
     
    3940//##############################################################################
    4041
    41 extern char* yyfilename;
     42extern char * yyfilename;
    4243extern int yylineno;
    4344
     
    122123        }
    123124
    124         Expression * build() const { return const_cast<ExpressionNode*>(this)->expr.release(); }
     125        Expression * build() const { return const_cast<ExpressionNode *>(this)->expr.release(); }
    125126  private:
    126127        bool extension = false;
     
    203204        // These must remain in the same order as the corresponding DeclarationNode names.
    204205
    205         // enum StorageClass { Extern, Static, Auto, Register, NoStorageClass };
    206         // enum FunctionSpec { Inline, Fortran, Noreturn, NoFunctionSpec };
    207         // enum Qualifier { Const, Restrict, Volatile, Lvalue, Atomic, Threadlocal, Mutex, NoQualifier };
    208 
    209         enum StorageClass { Extern, Static, Auto, Register, Inline, Fortran, Noreturn, Threadlocal, NoStorageClass, };
    210         enum Qualifier { Const, Restrict, Volatile, Lvalue, Atomic, NoQualifier };
     206        enum StorageClass { Extern, Static, Auto, Register, Threadlocal, NoStorageClass,
     207                                                ExternClass = 1 << Extern, StaticClass = 1 << Static, AutoClass = 1 << Auto, RegisterClass = 1 << Register, ThreadlocalClass = 1 << Threadlocal };
     208        enum FuncSpecifier { Inline, Noreturn, Fortran, NoFuncSpecifier,
     209                                                 InlineSpec = 1 << Inline, NoreturnSpec = 1 << Noreturn, FortranSpec = 1 << Fortran };
     210        enum TypeQualifier { Const, Restrict, Volatile, Lvalue, Mutex, Atomic, NoTypeQualifier };
    211211        enum BasicType { Void, Bool, Char, Int, Float, Double, LongDouble, NoBasicType };
    212212        enum ComplexType { Complex, Imaginary, NoComplexType };
     
    217217        enum BuiltinType { Valist, Zero, One, NoBuiltinType };
    218218
    219         static const char * storageName[];
    220         static const char * qualifierName[];
    221         static const char * basicTypeName[];
    222         static const char * complexTypeName[];
    223         static const char * signednessName[];
    224         static const char * lengthName[];
    225         static const char * aggregateName[];
    226         static const char * typeClassName[];
    227         static const char * builtinTypeName[];
    228 
    229         static DeclarationNode * newFunction( std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body, bool newStyle = false );
    230         static DeclarationNode * newQualifier( Qualifier );
    231         static DeclarationNode * newForall( DeclarationNode * );
     219        static const char * storageClassNames[];
     220        static const char * funcSpecifierNames[];
     221        static const char * typeQualifierNames[];
     222        static const char * basicTypeNames[];
     223        static const char * complexTypeNames[];
     224        static const char * signednessNames[];
     225        static const char * lengthNames[];
     226        static const char * aggregateNames[];
     227        static const char * typeClassNames[];
     228        static const char * builtinTypeNames[];
     229
    232230        static DeclarationNode * newStorageClass( StorageClass );
     231        static DeclarationNode * newFuncSpecifier( FuncSpecifier );
     232        static DeclarationNode * newTypeQualifier( TypeQualifier );
    233233        static DeclarationNode * newBasicType( BasicType );
    234234        static DeclarationNode * newComplexType( ComplexType );
    235         static DeclarationNode * newSignedNess( Signedness sn );
    236         static DeclarationNode * newLength( Length lnth );
     235        static DeclarationNode * newSignedNess( Signedness );
     236        static DeclarationNode * newLength( Length );
    237237        static DeclarationNode * newBuiltinType( BuiltinType );
     238        static DeclarationNode * newForall( DeclarationNode * );
    238239        static DeclarationNode * newFromTypedef( std::string * );
     240        static DeclarationNode * newFunction( std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body, bool newStyle = false );
    239241        static DeclarationNode * newAggregate( Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body );
    240242        static DeclarationNode * newEnum( std::string * name, DeclarationNode * constants, bool body );
     
    263265        DeclarationNode * addQualifiers( DeclarationNode * );
    264266        void checkQualifiers( const TypeData *, const TypeData * );
    265         void checkStorageClasses( DeclarationNode * );
    266         DeclarationNode * copyStorageClasses( DeclarationNode * );
     267        void checkSpecifiers( DeclarationNode * );
     268        DeclarationNode * copySpecifiers( DeclarationNode * );
    267269        DeclarationNode * addType( DeclarationNode * );
    268270        DeclarationNode * addTypedef();
     
    295297
    296298        Declaration * build() const;
    297         ::Type * buildType() const;
     299        Type * buildType() const;
    298300
    299301        bool get_hasEllipsis() const;
     
    301303        DeclarationNode * extractAggregate() const;
    302304        bool has_enumeratorValue() const { return (bool)enumeratorValue; }
    303         ExpressionNode * consume_enumeratorValue() const { return const_cast<DeclarationNode*>(this)->enumeratorValue.release(); }
     305        ExpressionNode * consume_enumeratorValue() const { return const_cast<DeclarationNode *>(this)->enumeratorValue.release(); }
    304306
    305307        bool get_extension() const { return extension; }
     
    323325
    324326        TypeData * type;
    325         StorageClass storageClass;
     327
     328        typedef std::bitset< DeclarationNode::NoStorageClass > StorageClasses;
     329        StorageClasses storageClasses;
     330        static void print_StorageClass( std::ostream & output, StorageClasses storageClasses );
     331
     332        typedef std::bitset< DeclarationNode::NoFuncSpecifier > FuncSpecifiers;
     333        FuncSpecifiers funcSpecs;
     334        static void print_FuncSpec( std::ostream & output, FuncSpecifiers funcSpecs );
     335
    326336        ExpressionNode * bitfieldWidth;
    327         bool isInline, isNoreturn;
    328337        std::unique_ptr<ExpressionNode> enumeratorValue;
    329338        bool hasEllipsis;
     
    342351
    343352static inline Type * maybeMoveBuildType( const DeclarationNode * orig ) {
    344         Type* ret = orig ? orig->buildType() : nullptr;
     353        Type * ret = orig ? orig->buildType() : nullptr;
    345354        delete orig;
    346355        return ret;
     
    357366
    358367        virtual StatementNode * clone() const final { assert( false ); return nullptr; }
    359         Statement * build() const { return const_cast<StatementNode*>(this)->stmt.release(); }
     368        Statement * build() const { return const_cast<StatementNode *>(this)->stmt.release(); }
    360369
    361370        virtual StatementNode * add_label( const std::string * name, DeclarationNode * attr = nullptr ) {
  • src/Parser/TypeData.cc

    r87c3bef rbe8bd88  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Feb 23 21:48:55 2017
    13 // Update Count     : 485
     12// Last Modified On : Tue Mar  7 08:08:21 2017
     13// Update Count     : 538
    1414//
    1515
     
    157157TypeData * TypeData::clone() const {
    158158        TypeData * newtype = new TypeData( kind );
    159         newtype->qualifiers = qualifiers;
     159        newtype->typeQualifiers = typeQualifiers;
    160160        newtype->base = maybeClone( base );
    161161        newtype->forall = maybeClone( forall );
     
    226226
    227227void TypeData::print( ostream &os, int indent ) const {
    228         for ( int i = 0; i < DeclarationNode::NoQualifier; i += 1 ) {
    229                 if ( qualifiers[i] ) os << DeclarationNode::qualifierName[ i ] << ' ';
     228        for ( int i = 0; i < DeclarationNode::NoTypeQualifier; i += 1 ) {
     229                if ( typeQualifiers[i] ) os << DeclarationNode::typeQualifierNames[ i ] << ' ';
    230230        } // for
    231231
     
    250250                break;
    251251          case Basic:
    252                 if ( signedness != DeclarationNode::NoSignedness ) os << DeclarationNode::signednessName[ signedness ] << " ";
    253                 if ( length != DeclarationNode::NoLength ) os << DeclarationNode::lengthName[ length ] << " ";
     252                if ( signedness != DeclarationNode::NoSignedness ) os << DeclarationNode::signednessNames[ signedness ] << " ";
     253                if ( length != DeclarationNode::NoLength ) os << DeclarationNode::lengthNames[ length ] << " ";
    254254                assert( basictype != DeclarationNode::NoBasicType );
    255                 os << DeclarationNode::basicTypeName[ basictype ] << " ";
    256                 if ( complextype != DeclarationNode::NoComplexType ) os << DeclarationNode::complexTypeName[ complextype ] << " ";
     255                os << DeclarationNode::basicTypeNames[ basictype ] << " ";
     256                if ( complextype != DeclarationNode::NoComplexType ) os << DeclarationNode::complexTypeNames[ complextype ] << " ";
    257257                break;
    258258          case Array:
     
    301301                break;
    302302          case Aggregate:
    303                 os << DeclarationNode::aggregateName[ aggregate.kind ] << ' ' << *aggregate.name << endl;
     303                os << DeclarationNode::aggregateNames[ aggregate.kind ] << ' ' << *aggregate.name << endl;
    304304                if ( aggregate.params ) {
    305305                        os << string( indent + 2, ' ' ) << "with type parameters " << endl;
     
    393393        buildList( firstNode, outputList );
    394394        for ( typename ForallList::iterator i = outputList.begin(); i != outputList.end(); ++i ) {
    395                 TypeDecl * td = static_cast<TypeDecl*>(*i);
     395                TypeDecl * td = static_cast<TypeDecl *>(*i);
    396396                if ( td->get_kind() == TypeDecl::Any ) {
    397397                        // add assertion parameters to `type' tyvars in reverse order
    398398                        // add dtor:  void ^?{}(T *)
    399399                        FunctionType * dtorType = new FunctionType( Type::Qualifiers(), false );
    400                         dtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );
    401                         td->get_assertions().push_front( new FunctionDecl( "^?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, dtorType, nullptr, false, false ) );
     400                        dtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );
     401                        td->get_assertions().push_front( new FunctionDecl( "^?{}", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, dtorType, nullptr ) );
    402402
    403403                        // add copy ctor:  void ?{}(T *, T)
    404404                        FunctionType * copyCtorType = new FunctionType( Type::Qualifiers(), false );
    405                         copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );
    406                         copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) );
    407                         td->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, copyCtorType, nullptr, false, false ) );
     405                        copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );
     406                        copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) );
     407                        td->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, copyCtorType, nullptr ) );
    408408
    409409                        // add default ctor:  void ?{}(T *)
    410410                        FunctionType * ctorType = new FunctionType( Type::Qualifiers(), false );
    411                         ctorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );
    412                         td->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, ctorType, nullptr, false, false ) );
     411                        ctorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );
     412                        td->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, ctorType, nullptr ) );
    413413
    414414                        // add assignment operator:  T * ?=?(T *, T)
    415415                        FunctionType * assignType = new FunctionType( Type::Qualifiers(), false );
    416                         assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );
    417                         assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) );
    418                         assignType->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) );
    419                         td->get_assertions().push_front( new FunctionDecl( "?=?", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, assignType, nullptr, false, false ) );
     416                        assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );
     417                        assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) );
     418                        assignType->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) );
     419                        td->get_assertions().push_front( new FunctionDecl( "?=?", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, assignType, nullptr ) );
    420420                } // if
    421421        } // for
     
    494494Type::Qualifiers buildQualifiers( const TypeData * td ) {
    495495        Type::Qualifiers q;
    496         q.isConst = td->qualifiers[ DeclarationNode::Const ];
    497         q.isVolatile = td->qualifiers[ DeclarationNode::Volatile ];
    498         q.isRestrict = td->qualifiers[ DeclarationNode::Restrict ];
    499         q.isLvalue = td->qualifiers[ DeclarationNode::Lvalue ];
    500         q.isAtomic = td->qualifiers[ DeclarationNode::Atomic ];;
     496        q.isConst = td->typeQualifiers[ DeclarationNode::Const ];
     497        q.isVolatile = td->typeQualifiers[ DeclarationNode::Volatile ];
     498        q.isRestrict = td->typeQualifiers[ DeclarationNode::Restrict ];
     499        q.isLvalue = td->typeQualifiers[ DeclarationNode::Lvalue ];
     500        q.isAtomic = td->typeQualifiers[ DeclarationNode::Atomic ];;
    501501        return q;
    502502} // buildQualifiers
     
    516516          case DeclarationNode::Bool:
    517517                if ( td->signedness != DeclarationNode::NoSignedness ) {
    518                         throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::signednessName[ td->signedness ] + " in type: ", td );
     518                        throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::signednessNames[ td->signedness ] + " in type: ", td );
    519519                } // if
    520520                if ( td->length != DeclarationNode::NoLength ) {
    521                         throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td );
     521                        throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::lengthNames[ td->length ] + " in type: ", td );
    522522                } // if
    523523
     
    532532
    533533                if ( td->length != DeclarationNode::NoLength ) {
    534                         throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td );
     534                        throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::lengthNames[ td->length ] + " in type: ", td );
    535535                } // if
    536536
     
    562562          FloatingPoint: ;
    563563                if ( td->signedness != DeclarationNode::NoSignedness ) {
    564                         throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::signednessName[ td->signedness ] + " in type: ", td );
     564                        throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::signednessNames[ td->signedness ] + " in type: ", td );
    565565                } // if
    566566                if ( td->length == DeclarationNode::Short || td->length == DeclarationNode::LongLong ) {
    567                         throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td );
     567                        throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::lengthNames[ td->length ] + " in type: ", td );
    568568                } // if
    569569                if ( td->basictype == DeclarationNode::Float && td->length == DeclarationNode::Long ) {
     
    732732} // buildAggInst
    733733
    734 NamedTypeDecl * buildSymbolic( const TypeData * td, const string & name, DeclarationNode::StorageClass sc ) {
     734NamedTypeDecl * buildSymbolic( const TypeData * td, const string & name, DeclarationNode::StorageClasses scs ) {
    735735        assert( td->kind == TypeData::Symbolic );
    736736        NamedTypeDecl * ret;
    737737        assert( td->base );
    738738        if ( td->symbolic.isTypedef ) {
    739                 ret = new TypedefDecl( name, sc, typebuild( td->base ) );
     739                ret = new TypedefDecl( name, scs, typebuild( td->base ) );
    740740        } else {
    741                 ret = new TypeDecl( name, sc, typebuild( td->base ), TypeDecl::Any );
     741                ret = new TypeDecl( name, scs, typebuild( td->base ), TypeDecl::Any );
    742742        } // if
    743743        buildList( td->symbolic.params, ret->get_parameters() );
     
    784784} // buildTypeof
    785785
    786 Declaration * buildDecl( const TypeData * td, const string &name, DeclarationNode::StorageClass sc, Expression * bitfieldWidth, bool isInline, bool isNoreturn, LinkageSpec::Spec linkage, ConstantExpr *asmName, Initializer * init, std::list< Attribute * > attributes ) {
     786Declaration * buildDecl( const TypeData * td, const string &name, DeclarationNode::StorageClasses scs, Expression * bitfieldWidth, DeclarationNode::FuncSpecifiers funcSpec, LinkageSpec::Spec linkage, ConstantExpr *asmName, Initializer * init, std::list< Attribute * > attributes ) {
    787787        if ( td->kind == TypeData::Function ) {
    788788                if ( td->function.idList ) {                                    // KR function ?
     
    792792                FunctionDecl * decl;
    793793                Statement * stmt = maybeBuild<Statement>( td->function.body );
    794                 CompoundStmt * body = dynamic_cast< CompoundStmt* >( stmt );
    795                 decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), body, isInline, isNoreturn, attributes );
     794                CompoundStmt * body = dynamic_cast< CompoundStmt * >( stmt );
     795                decl = new FunctionDecl( name, scs, linkage, buildFunction( td ), body, attributes, funcSpec );
    796796                return decl->set_asmName( asmName );
    797797        } else if ( td->kind == TypeData::Aggregate ) {
     
    800800                return buildEnum( td, attributes );
    801801        } else if ( td->kind == TypeData::Symbolic ) {
    802                 return buildSymbolic( td, name, sc );
     802                return buildSymbolic( td, name, scs );
    803803        } else {
    804                 return (new ObjectDecl( name, sc, linkage, bitfieldWidth, typebuild( td ), init, attributes, isInline, isNoreturn ))->set_asmName( asmName );
     804                return (new ObjectDecl( name, scs, linkage, bitfieldWidth, typebuild( td ), init, attributes ))->set_asmName( asmName );
    805805        } // if
    806806        return nullptr;
     
    820820                        break;
    821821                  default:
    822                         ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType* >( buildDecl( td->base,  "", DeclarationNode::NoStorageClass, nullptr, false, false, LinkageSpec::Cforall, nullptr ) ) );
     822                        ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType * >( buildDecl( td->base, "", DeclarationNode::StorageClasses(), nullptr, DeclarationNode::FuncSpecifiers(), LinkageSpec::Cforall, nullptr ) ) );
    823823                } // switch
    824824        } else {
    825                 ft->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) );
     825                ft->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) );
    826826        } // if
    827827        return ft;
     
    846846        for ( DeclarationNode * decl = function.oldDeclList; decl != nullptr; decl = dynamic_cast< DeclarationNode * >( decl->get_next() ) ) {
    847847                // scan ALL parameter names for each declaration name to check for duplicates
    848                 for ( DeclarationNode * param = function.idList; param != nullptr; param = dynamic_cast< DeclarationNode* >( param->get_next() ) ) {
     848                for ( DeclarationNode * param = function.idList; param != nullptr; param = dynamic_cast< DeclarationNode * >( param->get_next() ) ) {
    849849                        if ( *decl->name == *param->name ) {
    850850                                // type set => parameter name already transformed by a declaration names so there is a duplicate
     
    867867        //    rtb( a, b, c ) const char * b; {} => int rtn( int a, const char * b, int c ) {}
    868868
    869         for ( DeclarationNode * param = function.idList; param != nullptr; param = dynamic_cast< DeclarationNode* >( param->get_next() ) ) {
     869        for ( DeclarationNode * param = function.idList; param != nullptr; param = dynamic_cast< DeclarationNode * >( param->get_next() ) ) {
    870870                if ( ! param->type ) {                                                  // generate type int for empty parameter type
    871871                        param->type = new TypeData( TypeData::Basic );
  • src/Parser/TypeData.h

    r87c3bef rbe8bd88  
    1010// Created On       : Sat May 16 15:18:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Feb 23 17:14:46 2017
    13 // Update Count     : 158
     12// Last Modified On : Tue Mar  7 08:03:53 2017
     13// Update Count     : 173
    1414//
    1515
     
    7676        DeclarationNode::Length length = DeclarationNode::NoLength;
    7777        DeclarationNode::BuiltinType builtintype = DeclarationNode::NoBuiltinType;
    78         typedef std::bitset< DeclarationNode::NoQualifier > Qualifiers;
    79         Qualifiers qualifiers;
     78        typedef std::bitset< DeclarationNode::NoTypeQualifier > TypeQualifiers;
     79        TypeQualifiers typeQualifiers;
    8080        DeclarationNode * forall;
    8181
     
    107107ReferenceToType * buildComAggInst( const TypeData *, std::list< Attribute * > attributes );
    108108ReferenceToType * buildAggInst( const TypeData * );
    109 NamedTypeDecl * buildSymbolic( const TypeData *, const std::string &name, DeclarationNode::StorageClass sc );
    110109TypeDecl * buildVariable( const TypeData * );
    111110EnumDecl * buildEnum( const TypeData *, std::list< Attribute * > );
     
    113112TupleType * buildTuple( const TypeData * );
    114113TypeofType * buildTypeof( const TypeData * );
    115 Declaration * buildDecl( const TypeData *, const std::string &, DeclarationNode::StorageClass, Expression *, bool isInline, bool isNoreturn, LinkageSpec::Spec, ConstantExpr *asmName, Initializer * init = nullptr, std::list< class Attribute * > attributes = std::list< class Attribute * >() );
     114Declaration * buildDecl( const TypeData *, const std::string &, DeclarationNode::StorageClasses, Expression *, DeclarationNode::FuncSpecifiers funcSpec, LinkageSpec::Spec, ConstantExpr *asmName, Initializer * init = nullptr, std::list< class Attribute * > attributes = std::list< class Attribute * >() );
    116115FunctionType * buildFunction( const TypeData * );
    117116void buildKRFunction( const TypeData::Function_t & function );
  • src/Parser/lex.ll

    r87c3bef rbe8bd88  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Tue Nov 29 11:32:00 2016
    13  * Update Count     : 501
     12 * Last Modified On : Fri Mar  3 22:18:00 2017
     13 * Update Count     : 502
    1414 */
    1515
     
    235235long                    { KEYWORD_RETURN(LONG); }
    236236lvalue                  { KEYWORD_RETURN(LVALUE); }                             // CFA
     237mutex                   { KEYWORD_RETURN(MUTEX); }                              // CFA
    237238_Noreturn               { KEYWORD_RETURN(NORETURN); }                   // C11
    238239__builtin_offsetof { KEYWORD_RETURN(OFFSETOF); }                // GCC
  • src/Parser/parser.yy

    r87c3bef rbe8bd88  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb 28 09:58:10 2017
    13 // Update Count     : 2208
     12// Last Modified On : Sun Mar  5 15:48:24 2017
     13// Update Count     : 2227
    1414//
    1515
     
    9191// keywords
    9292%token TYPEDEF
    93 %token AUTO EXTERN REGISTER STATIC
    94 %token INLINE                                                                                   // C99
    95 %token FORTRAN                                                                                  // C99, extension ISO/IEC 9899:1999 Section J.5.9(1)
     93%token EXTERN STATIC AUTO REGISTER
     94%token THREADLOCAL                                                                              // C11
     95%token INLINE FORTRAN                                                                   // C99, extension ISO/IEC 9899:1999 Section J.5.9(1)
     96%token NORETURN                                                                                 // C11
    9697%token CONST VOLATILE
    9798%token RESTRICT                                                                                 // C99
    98 %token FORALL LVALUE                                                                    // CFA
     99%token ATOMIC                                                                                   // C11
     100%token FORALL LVALUE MUTEX                                                              // CFA
    99101%token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED ZERO_T ONE_T
    100102%token VALIST                                                                                   // GCC
     
    102104%token TYPEOF LABEL                                                                             // GCC
    103105%token ENUM STRUCT UNION
    104 %token OTYPE FTYPE DTYPE TTYPE TRAIT                                                    // CFA
     106%token OTYPE FTYPE DTYPE TTYPE TRAIT                                    // CFA
    105107%token SIZEOF OFFSETOF
    106108%token ATTRIBUTE EXTENSION                                                              // GCC
     
    108110%token CHOOSE DISABLE ENABLE FALLTHRU TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT        // CFA
    109111%token ASM                                                                                              // C99, extension ISO/IEC 9899:1999 Section J.5.10(1)
    110 %token ALIGNAS ALIGNOF ATOMIC GENERIC NORETURN STATICASSERT THREADLOCAL // C11
     112%token ALIGNAS ALIGNOF GENERIC STATICASSERT                             // C11
    111113
    112114// names and constants: lexer differentiates between identifier and typedef names
     
    14001402type_qualifier_name:
    14011403        CONST
    1402                 { $$ = DeclarationNode::newQualifier( DeclarationNode::Const ); }
     1404                { $$ = DeclarationNode::newTypeQualifier( DeclarationNode::Const ); }
    14031405        | RESTRICT
    1404                 { $$ = DeclarationNode::newQualifier( DeclarationNode::Restrict ); }
     1406                { $$ = DeclarationNode::newTypeQualifier( DeclarationNode::Restrict ); }
    14051407        | VOLATILE
    1406                 { $$ = DeclarationNode::newQualifier( DeclarationNode::Volatile ); }
     1408                { $$ = DeclarationNode::newTypeQualifier( DeclarationNode::Volatile ); }
    14071409        | LVALUE                                                                                        // CFA
    1408                 { $$ = DeclarationNode::newQualifier( DeclarationNode::Lvalue ); }
     1410                { $$ = DeclarationNode::newTypeQualifier( DeclarationNode::Lvalue ); }
     1411        | MUTEX
     1412                { $$ = DeclarationNode::newTypeQualifier( DeclarationNode::Mutex ); }
    14091413        | ATOMIC
    1410                 { $$ = DeclarationNode::newQualifier( DeclarationNode::Atomic ); }
     1414                { $$ = DeclarationNode::newTypeQualifier( DeclarationNode::Atomic ); }
    14111415        | FORALL '('
    14121416                {
     
    14481452        | REGISTER
    14491453                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Register ); }
    1450         | INLINE                                                                                        // C99
    1451                 //{ $$ = DeclarationNode::newStorageClass( DeclarationNode::Inline ); }
    1452                 { $$ = new DeclarationNode; $$->isInline = true; }
    1453         | FORTRAN                                                                                       // C99
    1454                 { $$ = DeclarationNode::newStorageClass( DeclarationNode::Fortran ); }
    1455         | NORETURN                                                                                      // C11
    1456                 //{ $$ = DeclarationNode::newStorageClass( DeclarationNode::Noreturn ); }
    1457                 { $$ = new DeclarationNode; $$->isNoreturn = true; }
    14581454        | THREADLOCAL                                                                           // C11
    14591455                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Threadlocal ); }
     1456                // Put function specifiers here to simplify parsing rules, but separate them semantically.
     1457        | INLINE                                                                                        // C99
     1458                { $$ = DeclarationNode::newFuncSpecifier( DeclarationNode::Inline ); }
     1459        | FORTRAN                                                                                       // C99
     1460                { $$ = DeclarationNode::newFuncSpecifier( DeclarationNode::Fortran ); }
     1461        | NORETURN                                                                                      // C11
     1462                { $$ = DeclarationNode::newFuncSpecifier( DeclarationNode::Noreturn ); }
    14601463        ;
    14611464
     
    20332036                { $$ = $3->addQualifiers( $1 ); }
    20342037        | type_declaring_list ',' type_declarator
    2035                 { $$ = $1->appendList( $3->copyStorageClasses( $1 ) ); }
     2038                { $$ = $1->appendList( $3->copySpecifiers( $1 ) ); }
    20362039        ;
    20372040
Note: See TracChangeset for help on using the changeset viewer.