Changeset 12bc63a


Ignore:
Timestamp:
Sep 15, 2016, 3:49:22 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
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:
3c13c03
Parents:
4ab9536 (diff), fc4a0fa (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' into tuples

Conflicts:

src/Parser/parser.cc

Location:
src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r4ab9536 r12bc63a  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Sep 11 09:24:11 2016
    13 // Update Count     : 438
     12// Last Modified On : Wed Sep 14 23:13:28 2016
     13// Update Count     : 502
    1414//
    1515
     
    3232// These must remain in the same order as the corresponding DeclarationNode enumerations.
    3333const char *DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", "NoStorageClass" };
    34 const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic" };
    35 const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary",  };
    36 const char *DeclarationNode::modifierName[]  = { "signed", "unsigned", "short", "long" };
     34const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic", "NoQualifier" };
     35const char *DeclarationNode::basicTypeName[] = { "void", "_Bool", "char", "int", "float", "double", "long double", "NoBasicType" };
     36const char *DeclarationNode::complexTypeName[] = { "_Complex", "_Imaginary", "NoComplexType" };
     37const char *DeclarationNode::signednessName[] = { "signed", "unsigned", "NoSignedness" };
     38const char *DeclarationNode::lengthName[] = { "short", "long", "long long", "NoLength" };
    3739const char *DeclarationNode::aggregateName[] = { "struct", "union", "context" };
    38 const char *DeclarationNode::typeClassName[] = { "type", "dtype", "ftype" };
     40const char *DeclarationNode::typeClassName[] = { "otype", "dtype", "ftype" };
    3941const char *DeclarationNode::builtinTypeName[] = { "__builtin_va_list" };
    4042
     
    5355                linkage( ::linkage ),
    5456                extension( false ) {
    55         variable.tyClass = DeclarationNode::Type;
     57        variable.tyClass = DeclarationNode::Otype;
    5658        variable.assertions = nullptr;
    5759
     
    188190        DeclarationNode *newnode = new DeclarationNode;
    189191        newnode->type = new TypeData( TypeData::Basic );
    190         newnode->type->basic.typeSpec.push_back( bt );
     192        newnode->type->basictype = bt;
    191193        return newnode;
    192194} // DeclarationNode::newBasicType
    193195
    194 DeclarationNode * DeclarationNode::newModifier( Modifier mod ) {
     196DeclarationNode * DeclarationNode::newComplexType( ComplexType ct ) {
    195197        DeclarationNode *newnode = new DeclarationNode;
    196198        newnode->type = new TypeData( TypeData::Basic );
    197         newnode->type->basic.modifiers.push_back( mod );
    198         return newnode;
    199 } // DeclarationNode::newModifier
     199        newnode->type->complextype = ct;
     200        return newnode;
     201} // DeclarationNode::newComplexType
     202
     203DeclarationNode * DeclarationNode::newSignedNess( Signedness sn ) {
     204        DeclarationNode *newnode = new DeclarationNode;
     205        newnode->type = new TypeData( TypeData::Basic );
     206        newnode->type->signedness = sn;
     207        return newnode;
     208} // DeclarationNode::newSignedNess
     209
     210DeclarationNode * DeclarationNode::newLength( Length lnth ) {
     211        DeclarationNode *newnode = new DeclarationNode;
     212        newnode->type = new TypeData( TypeData::Basic );
     213        newnode->type->length = lnth;
     214        return newnode;
     215} // DeclarationNode::newLength
    200216
    201217DeclarationNode * DeclarationNode::newFromTypedef( std::string *name ) {
     
    367383}
    368384
    369 static void addQualifiersToType( TypeData *&src, TypeData *dst ) {
    370         if ( src && dst ) {
    371                 if ( src->forall && dst->kind == TypeData::Function ) {
    372                         if ( dst->forall ) {
    373                                 dst->forall->appendList( src->forall );
    374                         } else {
    375                                 dst->forall = src->forall;
    376                         } // if
    377                         src->forall = 0;
    378                 } // if
    379                 if ( dst->base ) {
    380                         addQualifiersToType( src, dst->base );
    381                 } else if ( dst->kind == TypeData::Function ) {
    382                         dst->base = src;
    383                         src = 0;
    384                 } else {
    385                         dst->qualifiers |= src->qualifiers;
    386                 } // if
    387         } // if
    388 }
     385void appendError( string & dst, const string & src ) {
     386        if ( src.empty() ) return;
     387        if ( dst.empty() ) { dst = src; return; }
     388        dst += ", " + src;
     389} // appendError
    389390
    390391void DeclarationNode::checkQualifiers( const TypeData *src, const TypeData *dst ) {
     
    392393
    393394        if ( (qsrc & qdst).any() ) {                                            // common qualifier ?
    394                 for ( int i = 0; i < NoOfQualifier; i += 1 ) {  // find common qualifiers
    395                         if ( qsrc[i] & qdst[i] ) {
    396                                 if ( ! error.empty() ) error += ", ";   // separator
    397                                 error += string( "duplicate " ) + DeclarationNode::qualifierName[i];
     395                for ( int i = 0; i < NoQualifier; i += 1 ) {    // find common qualifiers
     396                        if ( qsrc[i] && qdst[i] ) {
     397                                appendError( error, string( "duplicate " ) + DeclarationNode::qualifierName[i] );
    398398                        } // if
    399399                } // for
     
    403403void DeclarationNode::checkStorageClasses( DeclarationNode *q ) {
    404404        if ( storageClass != NoStorageClass && q->storageClass != NoStorageClass ) {
    405                 if ( ! error.empty() ) error += ", ";                   // separator
    406405                if ( storageClass == q->storageClass ) {                // duplicate qualifier
    407                         error += string( "duplicate " ) + storageName[ storageClass ];
     406                        appendError( error, string( "duplicate " ) + storageName[ storageClass ] );
    408407                } else {                                                                                // only one storage class
    409                         error += string( "conflicting " ) + storageName[ storageClass ] + " & " + storageName[ q->storageClass ];
    410                         q->storageClass = storageClass;                         // FIX ERROR
    411                 } // if
    412                 if ( ! q->error.empty() ) error += ", " + q->error;     // separator
    413         } else {
    414                 if ( ! error.empty() ) {
    415                         if ( ! q->error.empty() ) error += ", " + q->error; // separator
    416                 } else if ( ! q->error.empty() ) error += q->error;
    417         } // if
     408                        appendError( error, string( "conflicting " ) + storageName[ storageClass ] + " & " + storageName[ q->storageClass ] );
     409                        q->storageClass = storageClass;                         // FIX ERROR, prevent assertions from triggering
     410                } // if
     411        } // if
     412        appendError( error, q->error );
    418413} // DeclarationNode::copyStorageClasses
    419414
    420415DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) {
    421         isInline = isInline | q->isInline;
    422         isNoreturn = isNoreturn | q->isNoreturn;
     416        isInline = isInline || q->isInline;
     417        isNoreturn = isNoreturn || q->isNoreturn;
    423418        // do not overwrite an existing value with NoStorageClass
    424419        if ( q->storageClass != NoStorageClass ) {
     
    429424} // DeclarationNode::copyStorageClasses
    430425
     426static void addQualifiersToType( TypeData *&src, TypeData *dst ) {
     427        if ( src->forall && dst->kind == TypeData::Function ) {
     428                if ( dst->forall ) {
     429                        dst->forall->appendList( src->forall );
     430                } else {
     431                        dst->forall = src->forall;
     432                } // if
     433                src->forall = 0;
     434        } // if
     435        if ( dst->base ) {
     436                addQualifiersToType( src, dst->base );
     437        } else if ( dst->kind == TypeData::Function ) {
     438                dst->base = src;
     439                src = 0;
     440        } else {
     441                dst->qualifiers |= src->qualifiers;
     442        } // if
     443} // addQualifiersToType
     444
    431445DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) {
    432         if ( q ) {
    433                 checkStorageClasses( q );
    434                 copyStorageClasses( q );
    435                 if ( q->type ) {
    436                         if ( ! type ) {
    437                                 type = new TypeData;
     446        if ( ! q ) return this;
     447
     448        checkStorageClasses( q );
     449        copyStorageClasses( q );
     450
     451        if ( ! q->type ) { delete q; return this; }
     452
     453        if ( ! type ) {
     454//              type = new TypeData;
     455                type = q->type;
     456                return this;
     457        } // if
     458
     459        checkQualifiers( q->type, type );
     460        addQualifiersToType( q->type, type );
     461
     462        if ( q->type->forall ) {
     463                if ( type->forall ) {
     464                        type->forall->appendList( q->type->forall );
     465                } else {
     466                        if ( type->kind == TypeData::Aggregate ) {
     467                                type->aggregate.params = q->type->forall;
     468                                // change implicit typedef from TYPEDEFname to TYPEGENname
     469                                typedefTable.changeKind( type->aggregate.name, TypedefTable::TG );
    438470                        } else {
    439                                 checkQualifiers( q->type, type );
     471                                type->forall = q->type->forall;
    440472                        } // if
    441                         addQualifiersToType( q->type, type );
    442                         if ( q->type && q->type->forall ) {
    443                                 if ( type->forall ) {
    444                                         type->forall->appendList( q->type->forall );
    445                                 } else {
    446                                         if ( type->kind == TypeData::Aggregate ) {
    447                                                 type->aggregate.params = q->type->forall;
    448                                                 // change implicit typedef from TYPEDEFname to TYPEGENname
    449                                                 typedefTable.changeKind( type->aggregate.name, TypedefTable::TG );
    450                                         } else {
    451                                                 type->forall = q->type->forall;
    452                                         } // if
     473                } // if
     474                q->type->forall = 0;
     475        } // if
     476        delete q;
     477        return this;
     478} // addQualifiers
     479
     480static void addTypeToType( TypeData *&src, TypeData *&dst ) {
     481        if ( src->forall && dst->kind == TypeData::Function ) {
     482                if ( dst->forall ) {
     483                        dst->forall->appendList( src->forall );
     484                } else {
     485                        dst->forall = src->forall;
     486                } // if
     487                src->forall = 0;
     488        } // if
     489        if ( dst->base ) {
     490                addTypeToType( src, dst->base );
     491        } else {
     492                switch ( dst->kind ) {
     493                  case TypeData::Unknown:
     494                        src->qualifiers |= dst->qualifiers;
     495                        dst = src;
     496                        src = 0;
     497                        break;
     498                  case TypeData::Basic:
     499                        dst->qualifiers |= src->qualifiers;
     500                        if ( src->kind != TypeData::Unknown ) {
     501                                assert( src->kind == TypeData::Basic );
     502
     503                                if ( dst->basictype == DeclarationNode::NoBasicType ) {
     504                                        dst->basictype = src->basictype;
     505                                } else if ( src->basictype != DeclarationNode::NoBasicType )
     506                                        throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::basicTypeName[ src->basictype ] + " in type: ", src );
     507
     508                                if ( dst->complextype == DeclarationNode::NoComplexType ) {
     509                                        dst->complextype = src->complextype;
     510                                } else if ( src->complextype != DeclarationNode::NoComplexType )
     511                                        throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::complexTypeName[ src->complextype ] + " in type: ", src );
     512
     513                                if ( dst->signedness == DeclarationNode::NoSignedness ) {
     514                                        dst->signedness = src->signedness;
     515                                } else if ( src->signedness != DeclarationNode::NoSignedness )
     516                                        throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::signednessName[ src->signedness ] + " in type: ", src );
     517
     518                                if ( dst->length == DeclarationNode::NoLength ) {
     519                                        dst->length = src->length;
     520                                } else if ( dst->length == DeclarationNode::Long && src->length == DeclarationNode::Long ) {
     521                                        dst->length = DeclarationNode::LongLong;
     522                                } else if ( src->length != DeclarationNode::NoLength )
     523                                        throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::lengthName[ src->length ] + " in type: ", src );
     524                        } // if
     525                        break;
     526                  default:
     527                        switch ( src->kind ) {
     528                          case TypeData::Aggregate:
     529                          case TypeData::Enum:
     530                                dst->base = new TypeData( TypeData::AggregateInst );
     531                                dst->base->aggInst.aggregate = src;
     532                                if ( src->kind == TypeData::Aggregate ) {
     533                                        dst->base->aggInst.params = maybeClone( src->aggregate.actuals );
    453534                                } // if
    454                                 q->type->forall = 0;
    455                         } // if
    456                 } // if
    457         } // if
    458         delete q;
    459         return this;
    460 }
    461 
    462 static void addTypeToType( TypeData *&src, TypeData *&dst ) {
    463         if ( src && dst ) {
    464                 if ( src->forall && dst->kind == TypeData::Function ) {
    465                         if ( dst->forall ) {
    466                                 dst->forall->appendList( src->forall );
    467                         } else {
    468                                 dst->forall = src->forall;
    469                         } // if
    470                         src->forall = 0;
    471                 } // if
    472                 if ( dst->base ) {
    473                         addTypeToType( src, dst->base );
    474                 } else {
    475                         switch ( dst->kind ) {
    476                           case TypeData::Unknown:
    477                                 src->qualifiers |= dst->qualifiers;
    478                                 dst = src;
     535                                dst->base->qualifiers |= src->qualifiers;
    479536                                src = 0;
    480537                                break;
    481                           case TypeData::Basic:
    482                                 dst->qualifiers |= src->qualifiers;
    483                                 if ( src->kind != TypeData::Unknown ) {
    484                                         assert( src->kind == TypeData::Basic );
    485                                         dst->basic.modifiers.splice( dst->basic.modifiers.end(), src->basic.modifiers );
    486                                         dst->basic.typeSpec.splice( dst->basic.typeSpec.end(), src->basic.typeSpec );
     538                          default:
     539                                if ( dst->forall ) {
     540                                        dst->forall->appendList( src->forall );
     541                                } else {
     542                                        dst->forall = src->forall;
    487543                                } // if
    488                                 break;
    489                           default:
    490                                 switch ( src->kind ) {
    491                                   case TypeData::Aggregate:
    492                                   case TypeData::Enum:
    493                                         dst->base = new TypeData( TypeData::AggregateInst );
    494                                         dst->base->aggInst.aggregate = src;
    495                                         if ( src->kind == TypeData::Aggregate ) {
    496                                                 dst->base->aggInst.params = maybeClone( src->aggregate.actuals );
    497                                         } // if
    498                                         dst->base->qualifiers |= src->qualifiers;
    499                                         src = 0;
    500                                         break;
    501                                   default:
    502                                         if ( dst->forall ) {
    503                                                 dst->forall->appendList( src->forall );
    504                                         } else {
    505                                                 dst->forall = src->forall;
    506                                         } // if
    507                                         src->forall = 0;
    508                                         dst->base = src;
    509                                         src = 0;
    510                                 } // switch
     544                                src->forall = 0;
     545                                dst->base = src;
     546                                src = 0;
    511547                        } // switch
    512                 } // if
     548                } // switch
    513549        } // if
    514550}
     
    875911        while ( cur ) {
    876912                try {
    877 ///       if ( DeclarationNode *extr = cur->extractAggregate() ) {
    878 ///     // handle the case where a structure declaration is contained within an object or type
    879 ///     // declaration
    880 ///     Declaration *decl = extr->build();
    881 ///     if ( decl ) {
    882 ///          *out++ = decl;
    883 ///     }
    884 ///       }
    885913                        Declaration *decl = cur->build();
    886914                        if ( decl ) {
  • src/Parser/ParseNode.h

    r4ab9536 r12bc63a  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Sep 10 17:14:37 2016
    13 // Update Count     : 589
     12// Last Modified On : Mon Sep 12 08:00:05 2016
     13// Update Count     : 603
    1414//
    1515
     
    196196class DeclarationNode : public ParseNode {
    197197  public:
    198         enum Qualifier { Const, Restrict, Volatile, Lvalue, Atomic, NoOfQualifier };
     198        // These must remain in the same order as the corresponding DeclarationNode names.
    199199        enum StorageClass { Extern, Static, Auto, Register, Inline, Fortran, Noreturn, Threadlocal, NoStorageClass, };
    200         enum BasicType { Char, Int, Float, Double, Void, Bool, Complex, Imaginary };
    201         enum Modifier  { Signed, Unsigned, Short, Long };
     200        enum Qualifier { Const, Restrict, Volatile, Lvalue, Atomic, NoQualifier };
     201        enum BasicType { Void, Bool, Char, Int, Float, Double, LongDouble, NoBasicType };
     202        enum ComplexType { Complex, Imaginary, NoComplexType };
     203        enum Signedness { Signed, Unsigned, NoSignedness };
     204        enum Length { Short, Long, LongLong, NoLength };
    202205        enum Aggregate { Struct, Union, Trait };
    203         enum TypeClass { Type, Dtype, Ftype };
     206        enum TypeClass { Otype, Dtype, Ftype };
    204207        enum BuiltinType { Valist };
    205208
     209        static const char * storageName[];
    206210        static const char * qualifierName[];
    207         static const char * storageName[];
    208211        static const char * basicTypeName[];
    209         static const char * modifierName[];
     212        static const char * complexTypeName[];
     213        static const char * signednessName[];
     214        static const char * lengthName[];
    210215        static const char * aggregateName[];
    211216        static const char * typeClassName[];
     
    217222        static DeclarationNode * newStorageClass( StorageClass );
    218223        static DeclarationNode * newBasicType( BasicType );
    219         static DeclarationNode * newModifier( Modifier );
     224        static DeclarationNode * newComplexType( ComplexType );
     225        static DeclarationNode * newSignedNess( Signedness sn );
     226        static DeclarationNode * newLength( Length lnth );
    220227        static DeclarationNode * newBuiltinType( BuiltinType );
    221228        static DeclarationNode * newFromTypedef( std::string *);
     
    309316        TypeData * type;
    310317        std::string name;
    311         // std::list< StorageClass > storageClasses;
    312318        StorageClass storageClass;
    313319        bool isInline, isNoreturn;
  • src/Parser/TypeData.cc

    r4ab9536 r12bc63a  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 29 22:31:53 2016
    13 // Update Count     : 277
     12// Last Modified On : Mon Sep 12 21:11:22 2016
     13// Update Count     : 377
    1414//
    1515
     
    178178                break;
    179179          case Basic:
    180                 newtype->basic.typeSpec = basic.typeSpec;
    181                 newtype->basic.modifiers = basic.modifiers;
     180                newtype->basictype = basictype;
     181                newtype->complextype = complextype;
     182                newtype->signedness = signedness;
     183                newtype->length = length;
    182184                break;
    183185          case Array:
     
    247249        using std::string;
    248250
    249         for ( int i = 0; i < DeclarationNode::NoOfQualifier; i += 1 ) {
     251        for ( int i = 0; i < DeclarationNode::NoQualifier; i += 1 ) {
    250252                if ( qualifiers[i] ) os << DeclarationNode::qualifierName[ i ] << ' ';
    251253        } // for
     
    271273                break;
    272274          case Basic:
    273                 printEnums( basic.modifiers.begin(), basic.modifiers.end(), DeclarationNode::modifierName, os );
    274                 printEnums( basic.typeSpec.begin(), basic.typeSpec.end(), DeclarationNode::basicTypeName, os );
     275                if ( signedness != DeclarationNode::NoSignedness ) os << DeclarationNode::signednessName[ signedness ] << " ";
     276                if ( length != DeclarationNode::NoLength ) os << DeclarationNode::lengthName[ length ] << " ";
     277                assert( basictype != DeclarationNode::NoBasicType );
     278                os << DeclarationNode::basicTypeName[ basictype ] << " ";
     279                if ( complextype != DeclarationNode::NoComplexType ) os << DeclarationNode::complexTypeName[ complextype ] << " ";
    275280                break;
    276281          case Array:
     
    418423                break;
    419424          default:
    420                 os << "internal error: TypeData::print " << kind  << endl;
     425                os << "internal error: TypeData::print " << kind << endl;
    421426                assert( false );
    422427        } // switch
     
    531536
    532537Type * buildBasicType( const TypeData * td ) {
    533         static const BasicType::Kind kindMap[] = { BasicType::Char, BasicType::SignedInt, BasicType::Float, BasicType::Double,
    534                                                                                            BasicType::Char /* void */, BasicType::Bool, BasicType::DoubleComplex,
    535                                                                                            BasicType::DoubleImaginary };
    536         bool init = false;
    537         bool sawDouble = false;
    538         bool sawSigned = false;
    539538        BasicType::Kind ret;
    540539
    541         for ( std::list< DeclarationNode::BasicType >::const_iterator i = td->basic.typeSpec.begin(); i != td->basic.typeSpec.end(); ++i ) {
    542                 if ( ! init ) {
    543                         init = true;
    544                         if ( *i == DeclarationNode::Void ) {
    545                                 if ( td->basic.typeSpec.size() != 1 || ! td->basic.modifiers.empty() ) {
    546                                         throw SemanticError( "invalid type specifier \"void\" in type: ", td );
    547                                 } else {
    548                                         return new VoidType( buildQualifiers( td ) );
    549                                 } // if
    550                         } else {
    551                                 ret = kindMap[ *i ];
    552                         } // if
    553                 } else {
    554                         switch ( *i ) {
    555                           case DeclarationNode::Float:
    556                                 if ( sawDouble ) {
    557                                         throw SemanticError( "invalid type specifier \"float\" in type: ", td );
    558                                 } else {
    559                                         switch ( ret ) {
    560                                           case BasicType::DoubleComplex:
    561                                                 ret = BasicType::FloatComplex;
    562                                                 break;
    563                                           case BasicType::DoubleImaginary:
    564                                                 ret = BasicType::FloatImaginary;
    565                                                 break;
    566                                           default:
    567                                                 throw SemanticError( "invalid type specifier \"float\" in type: ", td );
    568                                         } // switch
    569                                 } // if
    570                                 break;
    571                           case DeclarationNode::Double:
    572                                 if ( sawDouble ) {
    573                                         throw SemanticError( "duplicate type specifier \"double\" in type: ", td );
    574                                 } else {
    575                                         switch ( ret ) {
    576                                           case BasicType::DoubleComplex:
    577                                           case BasicType::DoubleImaginary:
    578                                                 break;
    579                                           default:
    580                                                 throw SemanticError( "invalid type specifier \"double\" in type: ", td );
    581                                         } // switch
    582                                 } // if
    583                                 break;
    584                           case DeclarationNode::Complex:
    585                                 switch ( ret ) {
    586                                   case BasicType::Float:
    587                                         ret = BasicType::FloatComplex;
    588                                         break;
    589                                   case BasicType::Double:
    590                                         ret = BasicType::DoubleComplex;
    591                                         break;
    592                                   default:
    593                                         throw SemanticError( "invalid type specifier \"_Complex\" in type: ", td );
    594                                 } // switch
    595                                 break;
    596                           case DeclarationNode::Imaginary:
    597                                 switch ( ret ) {
    598                                   case BasicType::Float:
    599                                         ret = BasicType::FloatImaginary;
    600                                         break;
    601                                   case BasicType::Double:
    602                                         ret = BasicType::DoubleImaginary;
    603                                         break;
    604                                   default:
    605                                         throw SemanticError( "invalid type specifier \"_Imaginary\" in type: ", td );
    606                                 } // switch
    607                                 break;
    608                           default:
    609                                 throw SemanticError( std::string( "invalid type specifier \"" ) + DeclarationNode::basicTypeName[ *i ] + "\" in type: ", td );
    610                         } // switch
    611                 } // if
    612                 if ( *i == DeclarationNode::Double ) {
    613                         sawDouble = true;
    614                 } // if
    615         } // for
    616 
    617         for ( std::list< DeclarationNode::Modifier >::const_iterator i = td->basic.modifiers.begin(); i != td->basic.modifiers.end(); ++i ) {
    618                 switch ( *i ) {
    619                   case DeclarationNode::Long:
    620                         if ( ! init ) {
    621                                 init = true;
    622                                 ret = BasicType::LongSignedInt;
    623                         } else {
    624                                 switch ( ret ) {
    625                                   case BasicType::SignedInt:
    626                                         ret = BasicType::LongSignedInt;
    627                                         break;
    628                                   case BasicType::UnsignedInt:
    629                                         ret = BasicType::LongUnsignedInt;
    630                                         break;
    631                                   case BasicType::LongSignedInt:
    632                                         ret = BasicType::LongLongSignedInt;
    633                                         break;
    634                                   case BasicType::LongUnsignedInt:
    635                                         ret = BasicType::LongLongUnsignedInt;
    636                                         break;
    637                                   case BasicType::Double:
    638                                         ret = BasicType::LongDouble;
    639                                         break;
    640                                   case BasicType::DoubleComplex:
    641                                         ret = BasicType::LongDoubleComplex;
    642                                         break;
    643                                   case BasicType::DoubleImaginary:
    644                                         ret = BasicType::LongDoubleImaginary;
    645                                         break;
    646                                   default:
    647                                         throw SemanticError( "invalid type modifier \"long\" in type: ", td );
    648                                 } // switch
    649                         } // if
    650                         break;
    651                   case DeclarationNode::Short:
    652                         if ( ! init ) {
    653                                 init = true;
    654                                 ret = BasicType::ShortSignedInt;
    655                         } else {
    656                                 switch ( ret ) {
    657                                   case BasicType::SignedInt:
    658                                         ret = BasicType::ShortSignedInt;
    659                                         break;
    660                                   case BasicType::UnsignedInt:
    661                                         ret = BasicType::ShortUnsignedInt;
    662                                         break;
    663                                   default:
    664                                         throw SemanticError( "invalid type modifier \"short\" in type: ", td );
    665                                 } // switch
    666                         } // if
    667                         break;
    668                   case DeclarationNode::Signed:
    669                         if ( ! init ) {
    670                                 init = true;
    671                                 ret = BasicType::SignedInt;
    672                         } else if ( sawSigned ) {
    673                                 throw SemanticError( "duplicate type modifer \"signed\" in type: ", td );
    674                         } else {
    675                                 switch ( ret ) {
    676                                   case BasicType::LongLongSignedInt:
    677                                         ret = BasicType::LongLongUnsignedInt;
    678                                         break;
    679                                   case BasicType::LongSignedInt:
    680                                         ret = BasicType::LongUnsignedInt;
    681                                         break;
    682                                   case BasicType::SignedInt:
    683                                   case BasicType::ShortSignedInt:
    684                                         break;
    685                                   case BasicType::Char:
    686                                         ret = BasicType::SignedChar;
    687                                         break;
    688                                   default:
    689                                         throw SemanticError( "invalid type modifer \"signed\" in type: ", td );
    690                                 } // switch
    691                         } // if
    692                         break;
    693                   case DeclarationNode::Unsigned:
    694                         if ( ! init ) {
    695                                 init = true;
    696                                 ret = BasicType::UnsignedInt;
    697                         } else if ( sawSigned ) {
    698                                 throw SemanticError( "invalid type modifer \"unsigned\" in type: ", td );
    699                         } else {
    700                                 switch ( ret ) {
    701                                   case BasicType::LongLongSignedInt:
    702                                         ret = BasicType::LongLongUnsignedInt;
    703                                         break;
    704                                   case BasicType::LongSignedInt:
    705                                         ret = BasicType::LongUnsignedInt;
    706                                         break;
    707                                   case BasicType::SignedInt:
    708                                         ret = BasicType::UnsignedInt;
    709                                         break;
    710                                   case BasicType::ShortSignedInt:
    711                                         ret = BasicType::ShortUnsignedInt;
    712                                         break;
    713                                   case BasicType::Char:
    714                                         ret = BasicType::UnsignedChar;
    715                                         break;
    716                                   default:
    717                                         throw SemanticError( "invalid type modifer \"unsigned\" in type: ", td );
    718                                 } // switch
    719                         } // if
    720                         break;
    721                 } // switch
    722 
    723                 if ( *i == DeclarationNode::Signed ) {
    724                         sawSigned = true;
    725                 } // if
    726         } // for
    727 
    728         BasicType * bt;
    729         if ( ! init ) {
    730                 bt = new BasicType( buildQualifiers( td ), BasicType::SignedInt );
    731         } else {
    732                 bt = new BasicType( buildQualifiers( td ), ret );
    733         } // if
     540        switch ( td->basictype ) {
     541          case DeclarationNode::Void:
     542                if ( td->signedness != DeclarationNode::NoSignedness && td->length != DeclarationNode::NoLength ) {
     543                        throw SemanticError( "invalid type specifier \"void\" in type: ", td );
     544                } // if
     545
     546                return new VoidType( buildQualifiers( td ) );
     547                break;
     548
     549          case DeclarationNode::Bool:
     550                if ( td->signedness != DeclarationNode::NoSignedness ) {
     551                        throw SemanticError( std::string( "invalid type specifier " ) + DeclarationNode::signednessName[ td->signedness ] + " in type: ", td );
     552                } // if
     553                if ( td->length != DeclarationNode::NoLength ) {
     554                        throw SemanticError( std::string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td );
     555                } // if
     556
     557                ret = BasicType::Bool;
     558                break;
     559
     560          case DeclarationNode::Char:
     561                // C11 Standard 6.2.5.15: The three types char, signed char, and unsigned char are collectively called the
     562                // character types. The implementation shall define char to have the same range, representation, and behavior as
     563                // either signed char or unsigned char.
     564                static BasicType::Kind chartype[] = { BasicType::SignedChar, BasicType::UnsignedChar, BasicType::Char };
     565
     566                if ( td->length != DeclarationNode::NoLength ) {
     567                        throw SemanticError( std::string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td );
     568                } // if
     569
     570                ret = chartype[ td->signedness ];
     571                break;
     572
     573          case DeclarationNode::Int:
     574                static BasicType::Kind inttype[2][4] = {
     575                        { BasicType::ShortSignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt, BasicType::SignedInt },
     576                        { BasicType::ShortUnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::UnsignedInt },
     577                };
     578
     579          Integral: ;
     580                if ( td->signedness == DeclarationNode::NoSignedness ) {
     581                        const_cast<TypeData *>(td)->signedness = DeclarationNode::Signed;
     582                } // if
     583                ret = inttype[ td->signedness ][ td->length ];
     584                break;
     585
     586          case DeclarationNode::Float:
     587          case DeclarationNode::Double:
     588          case DeclarationNode::LongDouble:                                     // not set until below
     589                static BasicType::Kind floattype[3][3] = {
     590                        { BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex },
     591                        { BasicType::FloatImaginary, BasicType::DoubleImaginary, BasicType::LongDoubleImaginary },
     592                        { BasicType::Float, BasicType::Double, BasicType::LongDouble },
     593                };
     594
     595          FloatingPoint: ;
     596                if ( td->signedness != DeclarationNode::NoSignedness ) {
     597                        throw SemanticError( std::string( "invalid type specifier " ) + DeclarationNode::signednessName[ td->signedness ] + " in type: ", td );
     598                } // if
     599                if ( td->length == DeclarationNode::Short || td->length == DeclarationNode::LongLong ) {
     600                        throw SemanticError( std::string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td );
     601                } // if
     602                if ( td->basictype == DeclarationNode::Float && td->length == DeclarationNode::Long ) {
     603                        throw SemanticError( "invalid type specifier \"long\" in type: ", td );
     604                } // if
     605                if ( td->length == DeclarationNode::Long ) {
     606                        const_cast<TypeData *>(td)->basictype = DeclarationNode::LongDouble;
     607                } // if
     608
     609                ret = floattype[ td->complextype ][ td->basictype - DeclarationNode::Float ];
     610                break;
     611
     612          case DeclarationNode::NoBasicType:
     613                // No basic type in declaration => default double for Complex/Imaginary and int type for integral types
     614                if ( td->complextype == DeclarationNode::Complex || td->complextype == DeclarationNode::Imaginary ) {
     615                        const_cast<TypeData *>(td)->basictype = DeclarationNode::Double;
     616                        goto FloatingPoint;
     617                } // if
     618
     619                const_cast<TypeData *>(td)->basictype = DeclarationNode::Int;
     620                goto Integral;
     621        } // switch
     622
     623        BasicType * bt = new BasicType( buildQualifiers( td ), ret );
    734624        buildForall( td->forall, bt->get_forall() );
    735625        return bt;
  • src/Parser/TypeData.h

    r4ab9536 r12bc63a  
    1010// Created On       : Sat May 16 15:18:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Sep 10 09:42:54 2016
    13 // Update Count     : 118
     12// Last Modified On : Mon Sep 12 17:15:49 2016
     13// Update Count     : 129
    1414//
    1515
     
    2525        enum Kind { Unknown, Basic, Pointer, Array, Function, Aggregate, AggregateInst,
    2626                                Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Builtin, Attr };
    27 
    28         struct Basic_t {
    29                 std::list< DeclarationNode::BasicType > typeSpec;
    30                 std::list< DeclarationNode::Modifier > modifiers;
    31         };
    3227
    3328        struct Aggregate_t {
     
    7368        };
    7469
    75         // struct Tuple_t {
    76         //      DeclarationNode * members;
    77         // };
    78  
    79         // struct Typeof_t {
    80         //      ExpressionNode * expr;
    81         // };
    82 
    83         // struct Builtin_t {
    84         //      DeclarationNode::BuiltinType type;
    85         // };
    86 
    8770        Kind kind;
    8871        TypeData * base;
    89         typedef std::bitset< DeclarationNode::NoOfQualifier > Qualifiers;
     72        DeclarationNode::BasicType basictype = DeclarationNode::NoBasicType;
     73        DeclarationNode::ComplexType complextype = DeclarationNode::NoComplexType;
     74        DeclarationNode::Signedness signedness = DeclarationNode::NoSignedness;
     75        DeclarationNode::Length length = DeclarationNode::NoLength;
     76        typedef std::bitset< DeclarationNode::NoQualifier > Qualifiers;
    9077        Qualifiers qualifiers;
    91         typedef std::bitset< DeclarationNode::NoStorageClass > StorageClasses;
    92         StorageClasses storageclasses;
    9378        DeclarationNode * forall;
    9479
    95                 Basic_t basic;
     80                // Basic_t basic;
    9681                Aggregate_t aggregate;
    9782                AggInst_t aggInst;
  • src/Parser/parser.cc

    r4ab9536 r12bc63a  
    67586758/* Line 1806 of yacc.c  */
    67596759#line 1367 "parser.yy"
    6760     { (yyval.decl) = DeclarationNode::newModifier( DeclarationNode::Long ); }
     6760    { (yyval.decl) = DeclarationNode::newLength( DeclarationNode::Long ); }
    67616761    break;
    67626762
     
    67656765/* Line 1806 of yacc.c  */
    67666766#line 1369 "parser.yy"
    6767     { (yyval.decl) = DeclarationNode::newModifier( DeclarationNode::Short ); }
     6767    { (yyval.decl) = DeclarationNode::newLength( DeclarationNode::Short ); }
    67686768    break;
    67696769
     
    67726772/* Line 1806 of yacc.c  */
    67736773#line 1371 "parser.yy"
    6774     { (yyval.decl) = DeclarationNode::newModifier( DeclarationNode::Signed ); }
     6774    { (yyval.decl) = DeclarationNode::newSignedNess( DeclarationNode::Signed ); }
    67756775    break;
    67766776
     
    67796779/* Line 1806 of yacc.c  */
    67806780#line 1373 "parser.yy"
    6781     { (yyval.decl) = DeclarationNode::newModifier( DeclarationNode::Unsigned ); }
     6781    { (yyval.decl) = DeclarationNode::newSignedNess( DeclarationNode::Unsigned ); }
    67826782    break;
    67836783
     
    68006800/* Line 1806 of yacc.c  */
    68016801#line 1379 "parser.yy"
    6802     { (yyval.decl) = DeclarationNode::newBasicType( DeclarationNode::Complex ); }
     6802    { (yyval.decl) = DeclarationNode::newComplexType( DeclarationNode::Complex ); }
    68036803    break;
    68046804
     
    68076807/* Line 1806 of yacc.c  */
    68086808#line 1381 "parser.yy"
    6809     { (yyval.decl) = DeclarationNode::newBasicType( DeclarationNode::Imaginary ); }
     6809    { (yyval.decl) = DeclarationNode::newComplexType( DeclarationNode::Imaginary ); }
    68106810    break;
    68116811
     
    75587558/* Line 1806 of yacc.c  */
    75597559#line 1853 "parser.yy"
    7560     { (yyval.tclass) = DeclarationNode::Type; }
     7560    { (yyval.tclass) = DeclarationNode::Otype; }
    75617561    break;
    75627562
  • src/Parser/parser.yy

    r4ab9536 r12bc63a  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Aug 26 16:45:44 2016
    13 // Update Count     : 1964
     12// Last Modified On : Mon Sep 12 17:29:45 2016
     13// Update Count     : 1969
    1414//
    1515
     
    13651365                { $$ = DeclarationNode::newBasicType( DeclarationNode::Int ); }
    13661366        | LONG
    1367                 { $$ = DeclarationNode::newModifier( DeclarationNode::Long ); }
     1367                { $$ = DeclarationNode::newLength( DeclarationNode::Long ); }
    13681368        | SHORT
    1369                 { $$ = DeclarationNode::newModifier( DeclarationNode::Short ); }
     1369                { $$ = DeclarationNode::newLength( DeclarationNode::Short ); }
    13701370        | SIGNED
    1371                 { $$ = DeclarationNode::newModifier( DeclarationNode::Signed ); }
     1371                { $$ = DeclarationNode::newSignedNess( DeclarationNode::Signed ); }
    13721372        | UNSIGNED
    1373                 { $$ = DeclarationNode::newModifier( DeclarationNode::Unsigned ); }
     1373                { $$ = DeclarationNode::newSignedNess( DeclarationNode::Unsigned ); }
    13741374        | VOID
    13751375                { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); }
     
    13771377                { $$ = DeclarationNode::newBasicType( DeclarationNode::Bool ); }
    13781378        | COMPLEX                                                                                       // C99
    1379                 { $$ = DeclarationNode::newBasicType( DeclarationNode::Complex ); }
     1379                { $$ = DeclarationNode::newComplexType( DeclarationNode::Complex ); }
    13801380        | IMAGINARY                                                                                     // C99
    1381                 { $$ = DeclarationNode::newBasicType( DeclarationNode::Imaginary ); }
     1381                { $$ = DeclarationNode::newComplexType( DeclarationNode::Imaginary ); }
    13821382        | VALIST                                                                                        // GCC, __builtin_va_list
    13831383                { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Valist ); }
     
    18511851type_class:                                                                                             // CFA
    18521852        OTYPE
    1853                 { $$ = DeclarationNode::Type; }
     1853                { $$ = DeclarationNode::Otype; }
    18541854        | DTYPE
    18551855                { $$ = DeclarationNode::Ftype; }
  • src/libcfa/limits.c

    r4ab9536 r12bc63a  
    1010// Created On       : Wed Apr  6 18:06:52 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul  8 13:23:33 2016
    13 // Update Count     : 14
     12// Last Modified On : Mon Sep 12 10:34:48 2016
     13// Update Count     : 17
    1414//
    1515
     
    6363const long double _2_SQRT_PI = 1.1283791670955125738961589031215452_DL; // 2 / sqrt(pi)
    6464
    65 const _Complex PI = 3.14159265358979323846_D+0.0_iD;    // pi
    66 const _Complex PI_2 = 1.57079632679489661923_D+0.0_iD;  // pi / 2
    67 const _Complex PI_4 = 0.78539816339744830962_D+0.0_iD;  // pi / 4
    68 const _Complex _1_PI = 0.31830988618379067154_D+0.0_iD; // 1 / pi
    69 const _Complex _2_PI = 0.63661977236758134308_D+0.0_iD; // 2 / pi
    70 const _Complex _2_SQRT_PI = 1.12837916709551257390_D+0.0_iD; // 2 / sqrt(pi)
     65const double _Complex PI = 3.14159265358979323846_D+0.0_iD;     // pi
     66const double _Complex PI_2 = 1.57079632679489661923_D+0.0_iD; // pi / 2
     67const double _Complex PI_4 = 0.78539816339744830962_D+0.0_iD; // pi / 4
     68const double _Complex _1_PI = 0.31830988618379067154_D+0.0_iD; // 1 / pi
     69const double _Complex _2_PI = 0.63661977236758134308_D+0.0_iD; // 2 / pi
     70const double _Complex _2_SQRT_PI = 1.12837916709551257390_D+0.0_iD; // 2 / sqrt(pi)
    7171
    72 const long _Complex PI = 3.1415926535897932384626433832795029_L+0.0iL; // pi
    73 const long _Complex PI_2 = 1.5707963267948966192313216916397514_L+0.0iL; // pi / 2
    74 const long _Complex PI_4 = 0.7853981633974483096156608458198757_L+0.0iL; // pi / 4
    75 const long _Complex _1_PI = 0.3183098861837906715377675267450287_L+0.0iL; // 1 / pi
    76 const long _Complex _2_PI = 0.6366197723675813430755350534900574_L+0.0iL; // 2 / pi
    77 const long _Complex _2_SQRT_PI = 1.1283791670955125738961589031215452_L+0.0iL; // 2 / sqrt(pi)
     72const long double _Complex PI = 3.1415926535897932384626433832795029_L+0.0iL; // pi
     73const long double _Complex PI_2 = 1.5707963267948966192313216916397514_L+0.0iL; // pi / 2
     74const long double _Complex PI_4 = 0.7853981633974483096156608458198757_L+0.0iL; // pi / 4
     75const long double _Complex _1_PI = 0.3183098861837906715377675267450287_L+0.0iL; // 1 / pi
     76const long double _Complex _2_PI = 0.6366197723675813430755350534900574_L+0.0iL; // 2 / pi
     77const long double _Complex _2_SQRT_PI = 1.1283791670955125738961589031215452_L+0.0iL; // 2 / sqrt(pi)
    7878
    7979const float E = 2.718281;                                                               // e
     
    101101const long double _1_SQRT_2 = 0.7071067811865475244008443621048490_DL; // 1/sqrt(2)
    102102
    103 const _Complex E = 2.7182818284590452354_D+0.0_iD;              // e
    104 const _Complex LOG2_E = 1.4426950408889634074_D+0.0_iD; // log_2(e)
    105 const _Complex LOG10_E = 0.43429448190325182765_D+0.0_iD; // log_10(e)
    106 const _Complex LN_2 = 0.69314718055994530942_D+0.0_iD;  // log_e(2)
    107 const _Complex LN_10 = 2.30258509299404568402_D+0.0_iD; // log_e(10)
    108 const _Complex SQRT_2 = 1.41421356237309504880_D+0.0_iD; // sqrt(2)
    109 const _Complex _1_SQRT_2 = 0.70710678118654752440_D+0.0_iD; // 1 / sqrt(2)
     103const double _Complex E = 2.7182818284590452354_D+0.0_iD; // e
     104const double _Complex LOG2_E = 1.4426950408889634074_D+0.0_iD; // log_2(e)
     105const double _Complex LOG10_E = 0.43429448190325182765_D+0.0_iD; // log_10(e)
     106const double _Complex LN_2 = 0.69314718055994530942_D+0.0_iD; // log_e(2)
     107const double _Complex LN_10 = 2.30258509299404568402_D+0.0_iD; // log_e(10)
     108const double _Complex SQRT_2 = 1.41421356237309504880_D+0.0_iD; // sqrt(2)
     109const double _Complex _1_SQRT_2 = 0.70710678118654752440_D+0.0_iD; // 1 / sqrt(2)
    110110
    111 const long _Complex E = 2.7182818284590452353602874713526625_L+0.0_iL; // e
    112 const long _Complex LOG2_E = 1.4426950408889634073599246810018921_L+0.0_iL; // log_2(e)
    113 const long _Complex LOG10_E = 0.4342944819032518276511289189166051_L+0.0_iL; // log_10(e)
    114 const long _Complex LN_2 = 0.6931471805599453094172321214581766_L+0.0_iL; // log_e(2)
    115 const long _Complex LN_10 = 2.3025850929940456840179914546843642_L+0.0_iL; // log_e(10)
    116 const long _Complex SQRT_2 = 1.4142135623730950488016887242096981_L+0.0_iL; // sqrt(2)
    117 const long _Complex _1_SQRT_2 = 0.7071067811865475244008443621048490_L+0.0_iL; // 1 / sqrt(2)
     111const long double _Complex E = 2.7182818284590452353602874713526625_L+0.0_iL; // e
     112const long double _Complex LOG2_E = 1.4426950408889634073599246810018921_L+0.0_iL; // log_2(e)
     113const long double _Complex LOG10_E = 0.4342944819032518276511289189166051_L+0.0_iL; // log_10(e)
     114const long double _Complex LN_2 = 0.6931471805599453094172321214581766_L+0.0_iL; // log_e(2)
     115const long double _Complex LN_10 = 2.3025850929940456840179914546843642_L+0.0_iL; // log_e(10)
     116const long double _Complex SQRT_2 = 1.4142135623730950488016887242096981_L+0.0_iL; // sqrt(2)
     117const long double _Complex _1_SQRT_2 = 0.7071067811865475244008443621048490_L+0.0_iL; // 1 / sqrt(2)
    118118
    119119// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.