Ignore:
Timestamp:
Aug 27, 2018, 4:40:34 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
b7c89aa
Parents:
f9feab8 (diff), 305581d (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 cleanup-dtors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/TypeData.cc

    rf9feab8 r90152a4  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Sep 25 18:33:41 2017
    13 // Update Count     : 587
     12// Last Modified On : Fri Jul 20 14:39:31 2018
     13// Update Count     : 622
    1414//
    1515
     
    3131using namespace std;
    3232
    33 TypeData::TypeData( Kind k ) : kind( k ), base( nullptr ), forall( nullptr ) /*, PTR1( (void*)(0xdeadbeefdeadbeef)), PTR2( (void*)(0xdeadbeefdeadbeef) ) */ {
     33TypeData::TypeData( Kind k ) : location( yylloc ), kind( k ), base( nullptr ), forall( nullptr ) /*, PTR1( (void*)(0xdeadbeefdeadbeef)), PTR2( (void*)(0xdeadbeefdeadbeef) ) */ {
    3434        switch ( kind ) {
    3535          case Unknown:
     
    3737          case Reference:
    3838          case EnumConstant:
     39          case GlobalScope:
    3940                // nothing else to initialize
    4041                break;
     
    5455                function.oldDeclList = nullptr;
    5556                function.body = nullptr;
    56                 function.newStyle = false;
     57                function.withExprs = nullptr;
    5758                break;
    5859                // Enum is an Aggregate, so both structures are initialized together.
     
    6263                enumeration.constants = nullptr;
    6364                enumeration.body = false;
     65                enumeration.anon = false;
     66                break;
    6467          case Aggregate:
    6568                // aggregate = new Aggregate_t;
     69                aggregate.kind = DeclarationNode::NoAggregate;
    6670                aggregate.name = nullptr;
    6771                aggregate.params = nullptr;
     
    6973                aggregate.fields = nullptr;
    7074                aggregate.body = false;
     75                aggregate.tagged = false;
     76                aggregate.parent = nullptr;
     77                aggregate.anon = false;
    7178                break;
    7279          case AggregateInst:
     
    7481                aggInst.aggregate = nullptr;
    7582                aggInst.params = nullptr;
    76                 aggInst.hoistType = false;;
     83                aggInst.hoistType = false;
    7784                break;
    7885          case Symbolic:
     
    94101          case Builtin:
    95102                // builtin = new Builtin_t;
     103                case Qualified:
     104                qualified.parent = nullptr;
     105                qualified.child = nullptr;
    96106                break;
    97107        } // switch
     
    108118          case Reference:
    109119          case EnumConstant:
     120          case GlobalScope:
    110121                // nothing to destroy
    111122                break;
     
    122133                delete function.oldDeclList;
    123134                delete function.body;
     135                delete function.withExprs;
    124136                // delete function;
    125137                break;
     
    160172                // delete builtin;
    161173                break;
     174          case Qualified:
     175                delete qualified.parent;
     176                delete qualified.child;
    162177        } // switch
    163178} // TypeData::~TypeData
     
    175190          case Pointer:
    176191          case Reference:
     192          case GlobalScope:
    177193                // nothing else to copy
    178194                break;
     
    193209                newtype->function.oldDeclList = maybeClone( function.oldDeclList );
    194210                newtype->function.body = maybeClone( function.body );
    195                 newtype->function.newStyle = function.newStyle;
     211                newtype->function.withExprs = maybeClone( function.withExprs );
    196212                break;
    197213          case Aggregate:
     214                newtype->aggregate.kind = aggregate.kind;
    198215                newtype->aggregate.name = aggregate.name ? new string( *aggregate.name ) : nullptr;
    199216                newtype->aggregate.params = maybeClone( aggregate.params );
    200217                newtype->aggregate.actuals = maybeClone( aggregate.actuals );
    201218                newtype->aggregate.fields = maybeClone( aggregate.fields );
    202                 newtype->aggregate.kind = aggregate.kind;
    203219                newtype->aggregate.body = aggregate.body;
     220                newtype->aggregate.anon = aggregate.anon;
    204221                newtype->aggregate.tagged = aggregate.tagged;
    205222                newtype->aggregate.parent = aggregate.parent ? new string( *aggregate.parent ) : nullptr;
     
    214231                newtype->enumeration.constants = maybeClone( enumeration.constants );
    215232                newtype->enumeration.body = enumeration.body;
     233                newtype->enumeration.anon = enumeration.anon;
    216234                break;
    217235          case Symbolic:
     
    233251                newtype->builtintype = builtintype;
    234252                break;
     253                case Qualified:
     254                newtype->qualified.parent = maybeClone( qualified.parent );
     255                newtype->qualified.child = maybeClone( qualified.child );
     256                break;
    235257        } // switch
    236258        return newtype;
     
    249271
    250272        switch ( kind ) {
    251           case Unknown:
    252                 os << "entity of unknown type ";
     273          case Basic:
     274                if ( signedness != DeclarationNode::NoSignedness ) os << DeclarationNode::signednessNames[ signedness ] << " ";
     275                if ( length != DeclarationNode::NoLength ) os << DeclarationNode::lengthNames[ length ] << " ";
     276                if ( complextype == DeclarationNode::NoComplexType ) { // basic type
     277                        assert( basictype != DeclarationNode::NoBasicType );
     278                        os << DeclarationNode::basicTypeNames[ basictype ] << " ";
     279                } else {                                                                                // complex type
     280                        // handle double _Complex
     281                        if ( basictype != DeclarationNode::NoBasicType ) os << DeclarationNode::basicTypeNames[ basictype ] << " ";
     282                        os << DeclarationNode::complexTypeNames[ complextype ] << " ";
     283                } // if
    253284                break;
    254285          case Pointer:
     
    259290                } // if
    260291                break;
    261           case EnumConstant:
    262                 os << "enumeration constant ";
    263                 break;
    264           case Basic:
    265                 if ( signedness != DeclarationNode::NoSignedness ) os << DeclarationNode::signednessNames[ signedness ] << " ";
    266                 if ( length != DeclarationNode::NoLength ) os << DeclarationNode::lengthNames[ length ] << " ";
    267                 assert( basictype != DeclarationNode::NoBasicType );
    268                 os << DeclarationNode::basicTypeNames[ basictype ] << " ";
    269                 if ( complextype != DeclarationNode::NoComplexType ) os << DeclarationNode::complexTypeNames[ complextype ] << " ";
     292          case Reference:
     293                os << "reference ";
     294                if ( base ) {
     295                        os << "to ";
     296                        base->print( os, indent );
     297                } // if
    270298                break;
    271299          case Array:
     
    353381                } // if
    354382                break;
    355           case SymbolicInst:
    356                 os << "instance of type " << *symbolic.name;
    357                 if ( symbolic.actuals ) {
    358                         os << " with parameters" << endl;
    359                         symbolic.actuals->printList( os, indent + 2 );
    360                 } // if
     383          case EnumConstant:
     384                os << "enumeration constant ";
    361385                break;
    362386          case Symbolic:
     
    380404                } // if
    381405                break;
     406          case SymbolicInst:
     407                os << *symbolic.name;
     408                if ( symbolic.actuals ) {
     409                        os << "(";
     410                        symbolic.actuals->printList( os, indent + 2 );
     411                        os << ")";
     412                } // if
     413                break;
    382414          case Tuple:
    383415                os << "tuple ";
     
    394426                break;
    395427          case Builtin:
    396                 os << "gcc builtin type";
     428                os << DeclarationNode::builtinTypeNames[builtintype];
     429                break;
     430          case GlobalScope:
     431                break;
     432          case Qualified:
     433                qualified.parent->print( os );
     434                os << ".";
     435                qualified.child->print( os );
     436                break;
     437          case Unknown:
     438                os << "entity of unknown type ";
    397439                break;
    398440          default:
     
    401443        } // switch
    402444} // TypeData::print
     445
     446const std::string * TypeData::leafName() const {
     447        switch ( kind ) {
     448          case Unknown:
     449          case Pointer:
     450          case Reference:
     451          case EnumConstant:
     452          case GlobalScope:
     453          case Array:
     454          case Basic:
     455          case Function:
     456          case AggregateInst:
     457          case Tuple:
     458          case Typeof:
     459          case Builtin:
     460                assertf(false, "Tried to get leaf name from kind without a name: %d", kind);
     461                break;
     462          case Aggregate:
     463                return aggregate.name;
     464          case Enum:
     465                return enumeration.name;
     466          case Symbolic:
     467          case SymbolicInst:
     468                return symbolic.name;
     469          case Qualified:
     470                return qualified.child->leafName();
     471        } // switch
     472        assert(false);
     473}
    403474
    404475
     
    460531                return new EnumInstType( buildQualifiers( td ), "" );
    461532          case TypeData::SymbolicInst:
    462                 return buildSymbolicInst( td );;
     533                return buildSymbolicInst( td );
    463534          case TypeData::Tuple:
    464535                return buildTuple( td );
     
    475546                        return new VarArgsType( buildQualifiers( td ) );
    476547                }
     548          case TypeData::GlobalScope:
     549                return new GlobalScopeType();
     550                case TypeData::Qualified:
     551                return new QualifiedType( buildQualifiers( td ), typebuild( td->qualified.parent ), typebuild( td->qualified.child ) );
    477552          case TypeData::Symbolic:
    478553          case TypeData::Enum:
     
    480555                assert( false );
    481556        } // switch
     557
    482558        return nullptr;
    483559} // typebuild
     
    489565        switch ( td->kind ) {
    490566          case TypeData::Aggregate:
    491                 if ( ! toplevel && td->aggregate.fields ) {
     567                if ( ! toplevel && td->aggregate.body ) {
    492568                        ret = td->clone();
    493569                } // if
    494570                break;
    495571          case TypeData::Enum:
    496                 if ( ! toplevel && td->enumeration.constants ) {
     572                if ( ! toplevel && td->enumeration.body ) {
    497573                        ret = td->clone();
    498574                } // if
     
    518594
    519595static string genTSError( string msg, DeclarationNode::BasicType basictype ) {
    520         throw SemanticError( string( "invalid type specifier \"" ) + msg + "\" for type \"" + DeclarationNode::basicTypeNames[basictype] + "\"." );
     596        SemanticError( yylloc, string( "invalid type specifier \"" ) + msg + "\" for type \"" + DeclarationNode::basicTypeNames[basictype] + "\"." );
    521597} // genTSError
    522598
     
    573649
    574650          case DeclarationNode::Int128:
    575                 ret = td->signedness == 1 ? BasicType::UnsignedInt128 : BasicType::SignedInt128;
     651                ret = td->signedness == DeclarationNode::Unsigned ? BasicType::UnsignedInt128 : BasicType::SignedInt128;
    576652                if ( td->length != DeclarationNode::NoLength ) {
    577653                        genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );
     
    597673                        genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );
    598674                } // if
    599                 if ( td->basictype == DeclarationNode::Float && td->length == DeclarationNode::Long ) {
     675                if ( td->basictype != DeclarationNode::Double && td->length == DeclarationNode::Long ) {
    600676                        genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );
    601677                } // if
     
    603679                        const_cast<TypeData *>(td)->basictype = DeclarationNode::LongDouble;
    604680                } // if
     681
     682                if ( td->basictype == DeclarationNode::Float80 || td->basictype == DeclarationNode::Float128 ) {
     683                        // if ( td->complextype != DeclarationNode::NoComplexType ) {
     684                        //      genTSError( DeclarationNode::complexTypeNames[ td->complextype ], td->basictype );
     685                        // }
     686                        if ( td->basictype == DeclarationNode::Float80 ) ret = BasicType::Float80;
     687                        else ret = BasicType::Float128;
     688                        break;
     689                }
    605690
    606691                ret = floattype[ td->complextype ][ td->basictype - DeclarationNode::Float ];
     
    797882        assert( td->base );
    798883        if ( td->symbolic.isTypedef ) {
    799                 ret = new TypedefDecl( name, scs, typebuild( td->base ), linkage );
     884                ret = new TypedefDecl( name, td->location, scs, typebuild( td->base ), linkage );
    800885        } else {
    801886                ret = new TypeDecl( name, scs, typebuild( td->base ), TypeDecl::Dtype, true );
     
    861946                CompoundStmt * body = dynamic_cast< CompoundStmt * >( stmt );
    862947                decl = new FunctionDecl( name, scs, linkage, buildFunction( td ), body, attributes, funcSpec );
     948                buildList( td->function.withExprs, decl->withExprs );
    863949                return decl->set_asmName( asmName );
    864950        } else if ( td->kind == TypeData::Aggregate ) {
     
    877963FunctionType * buildFunction( const TypeData * td ) {
    878964        assert( td->kind == TypeData::Function );
    879         bool hasEllipsis = td->function.params ? td->function.params->get_hasEllipsis() : true;
    880         if ( ! td->function.params ) hasEllipsis = ! td->function.newStyle;
    881         FunctionType * ft = new FunctionType( buildQualifiers( td ), hasEllipsis );
    882         buildList( td->function.params, ft->get_parameters() );
    883         buildForall( td->forall, ft->get_forall() );
     965        FunctionType * ft = new FunctionType( buildQualifiers( td ), ! td->function.params || td->function.params->hasEllipsis );
     966        buildList( td->function.params, ft->parameters );
     967        buildForall( td->forall, ft->forall );
    884968        if ( td->base ) {
    885969                switch ( td->base->kind ) {
    886970                  case TypeData::Tuple:
    887                         buildList( td->base->tuple, ft->get_returnVals() );
     971                        buildList( td->base->tuple, ft->returnVals );
    888972                        break;
    889973                  default:
     
    9191003                                // type set => parameter name already transformed by a declaration names so there is a duplicate
    9201004                                // declaration name attempting a second transformation
    921                                 if ( param->type ) throw SemanticError( string( "duplicate declaration name " ) + *param->name );
     1005                                if ( param->type ) SemanticError( param->location, string( "duplicate declaration name " ) + *param->name );
    9221006                                // declaration type reset => declaration already transformed by a parameter name so there is a duplicate
    9231007                                // parameter name attempting a second transformation
    924                                 if ( ! decl->type ) throw SemanticError( string( "duplicate parameter name " ) + *param->name );
     1008                                if ( ! decl->type ) SemanticError( param->location, string( "duplicate parameter name " ) + *param->name );
    9251009                                param->type = decl->type;                               // set copy declaration type to parameter type
    9261010                                decl->type = nullptr;                                   // reset declaration type
     
    9291013                } // for
    9301014                // declaration type still set => type not moved to a matching parameter so there is a missing parameter name
    931                 if ( decl->type ) throw SemanticError( string( "missing name in parameter list " ) + *decl->name );
     1015                if ( decl->type ) SemanticError( decl->location, string( "missing name in parameter list " ) + *decl->name );
    9321016        } // for
    9331017
Note: See TracChangeset for help on using the changeset viewer.