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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.