Changeset ef5b828 for src/SymTab


Ignore:
Timestamp:
Jul 12, 2019, 1:35:58 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
fce4e31
Parents:
7870799
Message:

Indexer now has const lookup by default

Location:
src/SymTab
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Indexer.cc

    r7870799 ref5b828  
    7474        }
    7575
    76         Indexer::Indexer() 
    77         : idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(), 
    78           prevScope(), scope( 0 ), repScope( 0 ) { ++*stats().count; }
     76        Indexer::Indexer()
     77        : idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(),
     78          prevScope(), scope( 0 ), repScope( 0 ) { ++* stats().count; }
    7979
    8080        Indexer::~Indexer() {
     
    8484        void Indexer::lazyInitScope() {
    8585                if ( repScope < scope ) {
    86                         ++*stats().lazy_scopes;
     86                        ++* stats().lazy_scopes;
    8787                        // create rollback
    88                         prevScope = std::make_shared<Indexer>( *this );
     88                        prevScope = std::make_shared<Indexer>( * this );
    8989                        // update repScope
    9090                        repScope = scope;
     
    9595                ++scope;
    9696
    97                 ++*stats().new_scopes;
     97                ++* stats().new_scopes;
    9898                stats().avg_scope_depth->push( scope );
    9999                stats().max_scope_depth->push( scope );
     
    103103                if ( repScope == scope ) {
    104104                        Ptr prev = prevScope;           // make sure prevScope stays live
    105                         *this = std::move(*prevScope);  // replace with previous scope
     105                        * this = std::move(* prevScope);  // replace with previous scope
    106106                }
    107107
     
    109109        }
    110110
    111         void Indexer::lookupId( const std::string &id, std::list< IdData > &out ) const {
    112                 ++*stats().lookup_calls;
     111        void Indexer::lookupId( const std::string & id, std::list< IdData > &out ) const {
     112                ++* stats().lookup_calls;
    113113                if ( ! idTable ) return;
    114114
    115                 ++*stats().map_lookups;
     115                ++* stats().map_lookups;
    116116                auto decls = idTable->find( id );
    117117                if ( decls == idTable->end() ) return;
     
    122122        }
    123123
    124         NamedTypeDecl *Indexer::lookupType( const std::string &id ) const {
    125                 ++*stats().lookup_calls;
     124        const NamedTypeDecl * Indexer::lookupType( const std::string & id ) const { return lookupMutableType(id); }
     125        NamedTypeDecl * Indexer::lookupMutableType( const std::string & id ) const {
     126                ++* stats().lookup_calls;
    126127                if ( ! typeTable ) return nullptr;
    127                 ++*stats().map_lookups;
     128                ++* stats().map_lookups;
    128129                auto it = typeTable->find( id );
    129130                return it == typeTable->end() ? nullptr : it->second.decl;
    130131        }
    131132
    132         StructDecl *Indexer::lookupStruct( const std::string &id ) const {
    133                 ++*stats().lookup_calls;
     133        const StructDecl * Indexer::lookupStruct( const std::string & id ) const { return lookupMutableStruct(id); }
     134        StructDecl * Indexer::lookupMutableStruct( const std::string & id ) const {
     135                ++* stats().lookup_calls;
    134136                if ( ! structTable ) return nullptr;
    135                 ++*stats().map_lookups;
     137                ++* stats().map_lookups;
    136138                auto it = structTable->find( id );
    137139                return it == structTable->end() ? nullptr : it->second.decl;
    138140        }
    139141
    140         EnumDecl *Indexer::lookupEnum( const std::string &id ) const {
    141                 ++*stats().lookup_calls;
     142        const EnumDecl * Indexer::lookupEnum( const std::string & id ) const { return lookupMutableEnum(id); }
     143        EnumDecl * Indexer::lookupMutableEnum( const std::string & id ) const {
     144                ++* stats().lookup_calls;
    142145                if ( ! enumTable ) return nullptr;
    143                 ++*stats().map_lookups;
     146                ++* stats().map_lookups;
    144147                auto it = enumTable->find( id );
    145148                return it == enumTable->end() ? nullptr : it->second.decl;
    146149        }
    147150
    148         UnionDecl *Indexer::lookupUnion( const std::string &id ) const {
    149                 ++*stats().lookup_calls;
     151        const UnionDecl * Indexer::lookupUnion( const std::string & id ) const { return lookupMutableUnion(id); }
     152        UnionDecl * Indexer::lookupMutableUnion( const std::string & id ) const {
     153                ++* stats().lookup_calls;
    150154                if ( ! unionTable ) return nullptr;
    151                 ++*stats().map_lookups;
     155                ++* stats().map_lookups;
    152156                auto it = unionTable->find( id );
    153157                return it == unionTable->end() ? nullptr : it->second.decl;
    154158        }
    155159
    156         TraitDecl *Indexer::lookupTrait( const std::string &id ) const {
    157                 ++*stats().lookup_calls;
     160        const TraitDecl * Indexer::lookupTrait( const std::string & id ) const { return lookupMutableTrait(id); }
     161        TraitDecl * Indexer::lookupMutableTrait( const std::string & id ) const {
     162                ++* stats().lookup_calls;
    158163                if ( ! traitTable ) return nullptr;
    159                 ++*stats().map_lookups;
     164                ++* stats().map_lookups;
    160165                auto it = traitTable->find( id );
    161166                return it == traitTable->end() ? nullptr : it->second.decl;
    162167        }
    163168
    164         const Indexer* Indexer::atScope( unsigned long target ) const {
     169        const Indexer * Indexer::atScope( unsigned long target ) const {
    165170                // by lazy construction, final indexer in list has repScope 0, cannot be > target
    166171                // otherwise, will find first scope representing the target
    167                 const Indexer* indexer = this;
     172                const Indexer * indexer = this;
    168173                while ( indexer->repScope > target ) {
    169174                        indexer = indexer->prevScope.get();
     
    172177        }
    173178
    174         NamedTypeDecl *Indexer::globalLookupType( const std::string &id ) const {
     179        const NamedTypeDecl * Indexer::globalLookupType( const std::string & id ) const {
    175180                return atScope( 0 )->lookupType( id );
    176181        }
    177182
    178         StructDecl *Indexer::globalLookupStruct( const std::string &id ) const {
     183        const StructDecl * Indexer::globalLookupStruct( const std::string & id ) const {
    179184                return atScope( 0 )->lookupStruct( id );
    180185        }
    181186
    182         UnionDecl *Indexer::globalLookupUnion( const std::string &id ) const {
     187        const UnionDecl * Indexer::globalLookupUnion( const std::string & id ) const {
    183188                return atScope( 0 )->lookupUnion( id );
    184189        }
    185190
    186         EnumDecl *Indexer::globalLookupEnum( const std::string &id ) const {
     191        const EnumDecl * Indexer::globalLookupEnum( const std::string & id ) const {
    187192                return atScope( 0 )->lookupEnum( id );
    188193        }
     
    207212        }
    208213
    209        
    210         bool Indexer::addedIdConflicts( 
    211                         const Indexer::IdData & existing, DeclarationWithType *added,
     214
     215        bool Indexer::addedIdConflicts(
     216                        const Indexer::IdData & existing, DeclarationWithType * added,
    212217                        Indexer::OnConflict handleConflicts, BaseSyntaxNode * deleteStmt ) {
    213                 // if we're giving the same name mangling to things of different types then there is 
     218                // if we're giving the same name mangling to things of different types then there is
    214219                // something wrong
    215220                assert( (isObject( added ) && isObject( existing.id ) )
     
    219224                        // new definition shadows the autogenerated one, even at the same scope
    220225                        return false;
    221                 } else if ( LinkageSpec::isMangled( added->linkage ) 
    222                                 || ResolvExpr::typesCompatible( 
     226                } else if ( LinkageSpec::isMangled( added->linkage )
     227                                || ResolvExpr::typesCompatible(
    223228                                        added->get_type(), existing.id->get_type(), Indexer() ) ) {
    224229
     
    238243                        if ( isDefinition( added ) && isDefinition( existing.id ) ) {
    239244                                if ( handleConflicts.mode == OnConflict::Error ) {
    240                                         SemanticError( added, 
    241                                                 isFunction( added ) ? 
    242                                                         "duplicate function definition for " : 
     245                                        SemanticError( added,
     246                                                isFunction( added ) ?
     247                                                        "duplicate function definition for " :
    243248                                                        "duplicate object definition for " );
    244249                                }
     
    255260        }
    256261
    257         bool Indexer::hasCompatibleCDecl( const std::string &id, const std::string &mangleName ) const {
     262        bool Indexer::hasCompatibleCDecl( const std::string & id, const std::string &mangleName ) const {
    258263                if ( ! idTable ) return false;
    259264
    260                 ++*stats().map_lookups;
     265                ++* stats().map_lookups;
    261266                auto decls = idTable->find( id );
    262267                if ( decls == idTable->end() ) return false;
     
    270275                        }
    271276                }
    272                
     277
    273278                return false;
    274279        }
    275280
    276         bool Indexer::hasIncompatibleCDecl( 
    277                         const std::string &id, const std::string &mangleName ) const {
     281        bool Indexer::hasIncompatibleCDecl(
     282                        const std::string & id, const std::string &mangleName ) const {
    278283                if ( ! idTable ) return false;
    279284
    280                 ++*stats().map_lookups;
     285                ++* stats().map_lookups;
    281286                auto decls = idTable->find( id );
    282287                if ( decls == idTable->end() ) return false;
     
    295300
    296301        /// gets the base type of the first parameter; decl must be a ctor/dtor/assignment function
    297         std::string getOtypeKey( FunctionDecl* function ) {
     302        std::string getOtypeKey( FunctionDecl * function ) {
    298303                auto& params = function->type->parameters;
    299304                assert( ! params.empty() );
    300305                // use base type of pointer, so that qualifiers on the pointer type aren't considered.
    301                 Type* base = InitTweak::getPointerBase( params.front()->get_type() );
     306                Type * base = InitTweak::getPointerBase( params.front()->get_type() );
    302307                assert( base );
    303308                return Mangler::mangle( base );
    304309        }
    305310
    306         /// gets the declaration for the function acting on a type specified by otype key, 
     311        /// gets the declaration for the function acting on a type specified by otype key,
    307312        /// nullptr if none such
    308313        FunctionDecl * getFunctionForOtype( DeclarationWithType * decl, const std::string& otypeKey ) {
     
    312317        }
    313318
    314         bool Indexer::removeSpecialOverrides( 
     319        bool Indexer::removeSpecialOverrides(
    315320                        Indexer::IdData& data, Indexer::MangleTable::Ptr& mangleTable ) {
    316                 // if a type contains user defined ctor/dtor/assign, then special rules trigger, which 
    317                 // determinethe set of ctor/dtor/assign that can be used  by the requester. In particular, 
    318                 // if the user defines a default ctor, then the generated default ctor is unavailable, 
    319                 // likewise for copy ctor and dtor. If the user defines any ctor/dtor, then no generated 
    320                 // field ctors are available. If the user defines any ctor then the generated default ctor 
    321                 // is unavailable (intrinsic default ctor must be overridden exactly). If the user defines 
    322                 // anything that looks like a copy constructor, then the generated copy constructor is 
     321                // if a type contains user defined ctor/dtor/assign, then special rules trigger, which
     322                // determinethe set of ctor/dtor/assign that can be used  by the requester. In particular,
     323                // if the user defines a default ctor, then the generated default ctor is unavailable,
     324                // likewise for copy ctor and dtor. If the user defines any ctor/dtor, then no generated
     325                // field ctors are available. If the user defines any ctor then the generated default ctor
     326                // is unavailable (intrinsic default ctor must be overridden exactly). If the user defines
     327                // anything that looks like a copy constructor, then the generated copy constructor is
    323328                // unavailable, and likewise for the assignment operator.
    324329
     
    340345                        std::vector< MangleTable::value_type > deleted;
    341346                        bool alreadyUserDefinedFunc = false;
    342                        
    343                         for ( const auto& entry : *mangleTable ) {
     347
     348                        for ( const auto& entry : * mangleTable ) {
    344349                                // skip decls that aren't functions or are for the wrong type
    345350                                FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
     
    368373                        // perform removals from mangle table, and deletions if necessary
    369374                        for ( const auto& key : removed ) {
    370                                 ++*stats().map_mutations;
     375                                ++* stats().map_mutations;
    371376                                mangleTable = mangleTable->erase( key );
    372377                        }
    373378                        if ( ! alreadyUserDefinedFunc ) for ( const auto& entry : deleted ) {
    374                                 ++*stats().map_mutations;
     379                                ++* stats().map_mutations;
    375380                                mangleTable = mangleTable->set( entry.first, IdData{ entry.second, function } );
    376381                        }
     
    379384                        // if this is the first user-defined function, delete non-user-defined overloads
    380385                        std::vector< MangleTable::value_type > deleted;
    381                        
    382                         for ( const auto& entry : *mangleTable ) {
     386
     387                        for ( const auto& entry : * mangleTable ) {
    383388                                // skip decls that aren't functions or are for the wrong type
    384389                                FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
     
    402407                        // this needs to be a separate loop because of iterator invalidation
    403408                        for ( const auto& entry : deleted ) {
    404                                 ++*stats().map_mutations;
     409                                ++* stats().map_mutations;
    405410                                mangleTable = mangleTable->set( entry.first, IdData{ entry.second, function } );
    406411                        }
     
    408413                        // this is an overridable generated function
    409414                        // if there already exists a matching user-defined function, delete this appropriately
    410                         for ( const auto& entry : *mangleTable ) {
     415                        for ( const auto& entry : * mangleTable ) {
    411416                                // skip decls that aren't functions or are for the wrong type
    412417                                FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
     
    418423                                if ( dataIsCopyFunc ) {
    419424                                        // remove current function if exists a user-defined copy function
    420                                         // since the signatures for copy functions don't need to match exactly, using 
     425                                        // since the signatures for copy functions don't need to match exactly, using
    421426                                        // a delete statement is the wrong approach
    422427                                        if ( InitTweak::isCopyFunction( decl, decl->name ) ) return false;
     
    428433                        }
    429434                }
    430                
     435
    431436                // nothing (more) to fix, return true
    432437                return true;
    433438        }
    434439
    435         void Indexer::addId( 
    436                         DeclarationWithType *decl, OnConflict handleConflicts, Expression * baseExpr,
     440        void Indexer::addId(
     441                        DeclarationWithType * decl, OnConflict handleConflicts, Expression * baseExpr,
    437442                        BaseSyntaxNode * deleteStmt ) {
    438                 ++*stats().add_calls;
     443                ++* stats().add_calls;
    439444                const std::string &name = decl->name;
    440445                if ( name == "" ) return;
    441                
     446
    442447                std::string mangleName;
    443448                if ( LinkageSpec::isOverridable( decl->linkage ) ) {
    444                         // mangle the name without including the appropriate suffix, so overridable routines 
     449                        // mangle the name without including the appropriate suffix, so overridable routines
    445450                        // are placed into the same "bucket" as their user defined versions.
    446451                        mangleName = Mangler::mangle( decl, false );
     
    449454                } // if
    450455
    451                 // this ensures that no two declarations with the same unmangled name at the same scope 
     456                // this ensures that no two declarations with the same unmangled name at the same scope
    452457                // both have C linkage
    453458                if ( LinkageSpec::isMangled( decl->linkage ) ) {
     
    457462                        }
    458463                } else {
    459                         // NOTE: only correct if name mangling is completely isomorphic to C 
     464                        // NOTE: only correct if name mangling is completely isomorphic to C
    460465                        // type-compatibility, which it may not be.
    461466                        if ( hasIncompatibleCDecl( name, mangleName ) ) {
     
    470475                        mangleTable = MangleTable::new_ptr();
    471476                } else {
    472                         ++*stats().map_lookups;
     477                        ++* stats().map_lookups;
    473478                        auto decls = idTable->find( name );
    474479                        if ( decls == idTable->end() ) {
     
    477482                                mangleTable = decls->second;
    478483                                // skip in-scope repeat declarations of same identifier
    479                                 ++*stats().map_lookups;
     484                                ++* stats().map_lookups;
    480485                                auto existing = mangleTable->find( mangleName );
    481486                                if ( existing != mangleTable->end()
     
    486491                                                        // set delete expression for conflicting identifier
    487492                                                        lazyInitScope();
    488                                                         *stats().map_mutations += 2;
     493                                                        * stats().map_mutations += 2;
    489494                                                        idTable = idTable->set(
    490495                                                                name,
    491                                                                 mangleTable->set( 
    492                                                                         mangleName, 
     496                                                                mangleTable->set(
     497                                                                        mangleName,
    493498                                                                        IdData{ existing->second, handleConflicts.deleteStmt } ) );
    494499                                                }
     
    504509                // Ensure that auto-generated ctor/dtor/assignment are deleted if necessary
    505510                if ( ! removeSpecialOverrides( data, mangleTable ) ) return;
    506                 *stats().map_mutations += 2;
     511                * stats().map_mutations += 2;
    507512                idTable = idTable->set( name, mangleTable->set( mangleName, std::move(data) ) );
    508513        }
     
    518523        }
    519524
    520         bool addedTypeConflicts( NamedTypeDecl *existing, NamedTypeDecl *added ) {
     525        bool addedTypeConflicts( NamedTypeDecl * existing, NamedTypeDecl * added ) {
    521526                if ( existing->base == nullptr ) {
    522527                        return false;
     
    530535                        }
    531536                }
    532                 // does not need to be added to the table if both existing and added have a base that are 
     537                // does not need to be added to the table if both existing and added have a base that are
    533538                // the same
    534539                return true;
    535540        }
    536541
    537         void Indexer::addType( NamedTypeDecl *decl ) {
    538                 ++*stats().add_calls;
    539                 const std::string &id = decl->name;
    540 
    541                 if ( ! typeTable ) { 
     542        void Indexer::addType( NamedTypeDecl * decl ) {
     543                ++* stats().add_calls;
     544                const std::string & id = decl->name;
     545
     546                if ( ! typeTable ) {
    542547                        typeTable = TypeTable::new_ptr();
    543548                } else {
    544                         ++*stats().map_lookups;
     549                        ++* stats().map_lookups;
    545550                        auto existing = typeTable->find( id );
    546                         if ( existing != typeTable->end() 
    547                                 && existing->second.scope == scope 
     551                        if ( existing != typeTable->end()
     552                                && existing->second.scope == scope
    548553                                && addedTypeConflicts( existing->second.decl, decl ) ) return;
    549554                }
    550                
     555
    551556                lazyInitScope();
    552                 ++*stats().map_mutations;
     557                ++* stats().map_mutations;
    553558                typeTable = typeTable->set( id, Scoped<NamedTypeDecl>{ decl, scope } );
    554559        }
    555560
    556         bool addedDeclConflicts( AggregateDecl *existing, AggregateDecl *added ) {
     561        bool addedDeclConflicts( AggregateDecl * existing, AggregateDecl * added ) {
    557562                if ( ! existing->body ) {
    558563                        return false;
     
    563568        }
    564569
    565         void Indexer::addStruct( const std::string &id ) {
     570        void Indexer::addStruct( const std::string & id ) {
    566571                addStruct( new StructDecl( id ) );
    567572        }
    568573
    569         void Indexer::addStruct( StructDecl *decl ) {
    570                 ++*stats().add_calls;
    571                 const std::string &id = decl->name;
     574        void Indexer::addStruct( StructDecl * decl ) {
     575                ++* stats().add_calls;
     576                const std::string & id = decl->name;
    572577
    573578                if ( ! structTable ) {
    574579                        structTable = StructTable::new_ptr();
    575580                } else {
    576                         ++*stats().map_lookups;
     581                        ++* stats().map_lookups;
    577582                        auto existing = structTable->find( id );
    578                         if ( existing != structTable->end() 
    579                                 && existing->second.scope == scope 
     583                        if ( existing != structTable->end()
     584                                && existing->second.scope == scope
    580585                                && addedDeclConflicts( existing->second.decl, decl ) ) return;
    581586                }
    582587
    583588                lazyInitScope();
    584                 ++*stats().map_mutations;
     589                ++* stats().map_mutations;
    585590                structTable = structTable->set( id, Scoped<StructDecl>{ decl, scope } );
    586591        }
    587592
    588         void Indexer::addEnum( EnumDecl *decl ) {
    589                 ++*stats().add_calls;
    590                 const std::string &id = decl->name;
     593        void Indexer::addEnum( EnumDecl * decl ) {
     594                ++* stats().add_calls;
     595                const std::string & id = decl->name;
    591596
    592597                if ( ! enumTable ) {
    593598                        enumTable = EnumTable::new_ptr();
    594599                } else {
    595                         ++*stats().map_lookups;
     600                        ++* stats().map_lookups;
    596601                        auto existing = enumTable->find( id );
    597                         if ( existing != enumTable->end() 
    598                                 && existing->second.scope == scope 
     602                        if ( existing != enumTable->end()
     603                                && existing->second.scope == scope
    599604                                && addedDeclConflicts( existing->second.decl, decl ) ) return;
    600605                }
    601                
     606
    602607                lazyInitScope();
    603                 ++*stats().map_mutations;
     608                ++* stats().map_mutations;
    604609                enumTable = enumTable->set( id, Scoped<EnumDecl>{ decl, scope } );
    605610        }
    606611
    607         void Indexer::addUnion( const std::string &id ) {
     612        void Indexer::addUnion( const std::string & id ) {
    608613                addUnion( new UnionDecl( id ) );
    609614        }
    610615
    611         void Indexer::addUnion( UnionDecl *decl ) {
    612                 ++*stats().add_calls;
    613                 const std::string &id = decl->name;
     616        void Indexer::addUnion( UnionDecl * decl ) {
     617                ++* stats().add_calls;
     618                const std::string & id = decl->name;
    614619
    615620                if ( ! unionTable ) {
    616621                        unionTable = UnionTable::new_ptr();
    617622                } else {
    618                         ++*stats().map_lookups;
     623                        ++* stats().map_lookups;
    619624                        auto existing = unionTable->find( id );
    620                         if ( existing != unionTable->end() 
    621                                 && existing->second.scope == scope 
     625                        if ( existing != unionTable->end()
     626                                && existing->second.scope == scope
    622627                                && addedDeclConflicts( existing->second.decl, decl ) ) return;
    623628                }
    624629
    625630                lazyInitScope();
    626                 ++*stats().map_mutations;
     631                ++* stats().map_mutations;
    627632                unionTable = unionTable->set( id, Scoped<UnionDecl>{ decl, scope } );
    628633        }
    629634
    630         void Indexer::addTrait( TraitDecl *decl ) {
    631                 ++*stats().add_calls;
    632                 const std::string &id = decl->name;
     635        void Indexer::addTrait( TraitDecl * decl ) {
     636                ++* stats().add_calls;
     637                const std::string & id = decl->name;
    633638
    634639                if ( ! traitTable ) {
    635640                        traitTable = TraitTable::new_ptr();
    636641                } else {
    637                         ++*stats().map_lookups;
     642                        ++* stats().map_lookups;
    638643                        auto existing = traitTable->find( id );
    639                         if ( existing != traitTable->end() 
    640                                 && existing->second.scope == scope 
     644                        if ( existing != traitTable->end()
     645                                && existing->second.scope == scope
    641646                                && addedDeclConflicts( existing->second.decl, decl ) ) return;
    642647                }
    643648
    644649                lazyInitScope();
    645                 ++*stats().map_mutations;
     650                ++* stats().map_mutations;
    646651                traitTable = traitTable->set( id, Scoped<TraitDecl>{ decl, scope } );
    647652        }
    648653
    649         void Indexer::addMembers( AggregateDecl * aggr, Expression * expr, 
     654        void Indexer::addMembers( AggregateDecl * aggr, Expression * expr,
    650655                        OnConflict handleConflicts ) {
    651656                for ( Declaration * decl : aggr->members ) {
     
    654659                                if ( dwt->name == "" ) {
    655660                                        Type * t = dwt->get_type()->stripReferences();
    656                                         if ( dynamic_cast<StructInstType*>( t ) || dynamic_cast<UnionInstType*>( t ) ) {
     661                                        if ( dynamic_cast<StructInstType *>( t ) || dynamic_cast<UnionInstType *>( t ) ) {
    657662                                                Expression * base = expr->clone();
    658663                                                ResolvExpr::Cost cost = ResolvExpr::Cost::zero; // xxx - carry this cost into the indexer as a base cost?
  • src/SymTab/Indexer.h

    r7870799 ref5b828  
    3434                virtual ~Indexer();
    3535
    36                 // when using an indexer manually (e.g., within a mutator traversal), it is necessary to 
     36                // when using an indexer manually (e.g., within a mutator traversal), it is necessary to
    3737                // tell the indexer explicitly when scopes begin and end
    3838                void enterScope();
     
    5050                        // NOTE: shouldn't need either of these constructors, but gcc-4 does not properly support initializer lists with default members.
    5151                        IdData() = default;
    52                         IdData( 
     52                        IdData(
    5353                                DeclarationWithType * id, Expression * baseExpr, BaseSyntaxNode * deleteStmt,
    54                                 unsigned long scope ) 
     54                                unsigned long scope )
    5555                                : id( id ), baseExpr( baseExpr ), deleteStmt( deleteStmt ), scope( scope ) {}
    5656                        IdData( const IdData& o, BaseSyntaxNode * deleteStmt )
     
    6161
    6262                /// Gets all declarations with the given ID
    63                 void lookupId( const std::string &id, std::list< IdData > &out ) const;
     63                void lookupId( const std::string & id, std::list< IdData > &out ) const;
    6464                /// Gets the top-most type declaration with the given ID
    65                 NamedTypeDecl *lookupType( const std::string &id ) const;
     65                const NamedTypeDecl * lookupType( const std::string & id ) const;
     66                NamedTypeDecl * lookupMutableType( const std::string & id ) const;
    6667                /// Gets the top-most struct declaration with the given ID
    67                 StructDecl *lookupStruct( const std::string &id ) const;
     68                const StructDecl * lookupStruct( const std::string & id ) const;
     69                StructDecl * lookupMutableStruct( const std::string & id ) const;
    6870                /// Gets the top-most enum declaration with the given ID
    69                 EnumDecl *lookupEnum( const std::string &id ) const;
     71                const EnumDecl * lookupEnum( const std::string & id ) const;
     72                EnumDecl * lookupMutableEnum( const std::string & id ) const;
    7073                /// Gets the top-most union declaration with the given ID
    71                 UnionDecl *lookupUnion( const std::string &id ) const;
     74                const UnionDecl * lookupUnion( const std::string & id ) const;
     75                UnionDecl * lookupMutableUnion( const std::string & id ) const;
    7276                /// Gets the top-most trait declaration with the given ID
    73                 TraitDecl *lookupTrait( const std::string &id ) const;
     77                const TraitDecl * lookupTrait( const std::string & id ) const;
     78                TraitDecl * lookupMutableTrait( const std::string & id ) const;
    7479
    7580                /// Gets the type declaration with the given ID at global scope
    76                 NamedTypeDecl *globalLookupType( const std::string &id ) const;
     81                const NamedTypeDecl * globalLookupType( const std::string & id ) const;
    7782                /// Gets the struct declaration with the given ID at global scope
    78                 StructDecl *globalLookupStruct( const std::string &id ) const;
     83                const StructDecl * globalLookupStruct( const std::string & id ) const;
    7984                /// Gets the union declaration with the given ID at global scope
    80                 UnionDecl *globalLookupUnion( const std::string &id ) const;
     85                const UnionDecl * globalLookupUnion( const std::string & id ) const;
    8186                /// Gets the enum declaration with the given ID at global scope
    82                 EnumDecl *globalLookupEnum( const std::string &id ) const;
     87                const EnumDecl * globalLookupEnum( const std::string & id ) const;
    8388
    8489                void addId( DeclarationWithType * decl, Expression * baseExpr = nullptr );
    8590                void addDeletedId( DeclarationWithType * decl, BaseSyntaxNode * deleteStmt );
    8691
    87                 void addType( NamedTypeDecl *decl );
    88                 void addStruct( const std::string &id );
    89                 void addStruct( StructDecl *decl );
    90                 void addEnum( EnumDecl *decl );
    91                 void addUnion( const std::string &id );
    92                 void addUnion( UnionDecl *decl );
    93                 void addTrait( TraitDecl *decl );
     92                void addType( NamedTypeDecl * decl );
     93                void addStruct( const std::string & id );
     94                void addStruct( StructDecl * decl );
     95                void addEnum( EnumDecl * decl );
     96                void addUnion( const std::string & id );
     97                void addUnion( UnionDecl * decl );
     98                void addTrait( TraitDecl * decl );
    9499
    95100                /// adds all of the IDs from WithStmt exprs
     
    106111
    107112          private:
    108                 /// Wraps a Decl* with a scope
     113                /// Wraps a Decl * with a scope
    109114                template<typename Decl>
    110115                struct Scoped {
    111                         Decl* decl;           ///< declaration
     116                        Decl * decl;           ///< declaration
    112117                        unsigned long scope;  ///< scope of this declaration
    113118
    114                         Scoped(Decl* d, unsigned long s) : decl(d), scope(s) {}
     119                        Scoped(Decl * d, unsigned long s) : decl(d), scope(s) {}
    115120                };
    116121
     
    140145
    141146                /// Gets the indexer at the given scope
    142                 const Indexer* atScope( unsigned long scope ) const;
     147                const Indexer * atScope( unsigned long scope ) const;
    143148
    144                 /// Removes matching autogenerated constructors and destructors so that they will not be 
     149                /// Removes matching autogenerated constructors and destructors so that they will not be
    145150                /// selected. If returns false, passed decl should not be added.
    146151                bool removeSpecialOverrides( IdData& decl, MangleTable::Ptr& mangleTable );
     
    166171                /// true if the existing identifier conflicts with the added identifier
    167172                bool addedIdConflicts(
    168                         const IdData& existing, DeclarationWithType * added, OnConflict handleConflicts, 
     173                        const IdData& existing, DeclarationWithType * added, OnConflict handleConflicts,
    169174                        BaseSyntaxNode * deleteStmt );
    170175
    171176                /// common code for addId, addDeletedId, etc.
    172                 void addId( 
    173                         DeclarationWithType * decl, OnConflict handleConflicts, 
     177                void addId(
     178                        DeclarationWithType * decl, OnConflict handleConflicts,
    174179                        Expression * baseExpr = nullptr, BaseSyntaxNode * deleteStmt = nullptr );
    175180
     
    178183
    179184                /// returns true if there exists a declaration with C linkage and the given name with the same mangled name
    180                 bool hasCompatibleCDecl( const std::string &id, const std::string &mangleName ) const;
     185                bool hasCompatibleCDecl( const std::string & id, const std::string &mangleName ) const;
    181186                /// returns true if there exists a declaration with C linkage and the given name with a different mangled name
    182                 bool hasIncompatibleCDecl( const std::string &id, const std::string &mangleName ) const;
     187                bool hasIncompatibleCDecl( const std::string & id, const std::string &mangleName ) const;
    183188        };
    184189} // namespace SymTab
  • src/SymTab/Validate.cc

    r7870799 ref5b828  
    119119
    120120          private:
    121                 template< typename AggDecl > void handleAggregate( AggDecl *aggregateDecl );
     121                template< typename AggDecl > void handleAggregate( AggDecl * aggregateDecl );
    122122
    123123                AggregateDecl * parentAggr = nullptr;
     
    134134        /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers.
    135135        struct EnumAndPointerDecay_old {
    136                 void previsit( EnumDecl *aggregateDecl );
    137                 void previsit( FunctionType *func );
     136                void previsit( EnumDecl * aggregateDecl );
     137                void previsit( FunctionType * func );
    138138        };
    139139
    140140        /// Associates forward declarations of aggregates with their definitions
    141141        struct LinkReferenceToTypes_old final : public WithIndexer, public WithGuards, public WithVisitorRef<LinkReferenceToTypes_old>, public WithShortCircuiting {
    142                 LinkReferenceToTypes_old( const Indexer *indexer );
    143                 void postvisit( TypeInstType *typeInst );
    144 
    145                 void postvisit( EnumInstType *enumInst );
    146                 void postvisit( StructInstType *structInst );
    147                 void postvisit( UnionInstType *unionInst );
    148                 void postvisit( TraitInstType *traitInst );
     142                LinkReferenceToTypes_old( const Indexer * indexer );
     143                void postvisit( TypeInstType * typeInst );
     144
     145                void postvisit( EnumInstType * enumInst );
     146                void postvisit( StructInstType * structInst );
     147                void postvisit( UnionInstType * unionInst );
     148                void postvisit( TraitInstType * traitInst );
    149149                void previsit( QualifiedType * qualType );
    150150                void postvisit( QualifiedType * qualType );
    151151
    152                 void postvisit( EnumDecl *enumDecl );
    153                 void postvisit( StructDecl *structDecl );
    154                 void postvisit( UnionDecl *unionDecl );
     152                void postvisit( EnumDecl * enumDecl );
     153                void postvisit( StructDecl * structDecl );
     154                void postvisit( UnionDecl * unionDecl );
    155155                void postvisit( TraitDecl * traitDecl );
    156156
    157                 void previsit( StructDecl *structDecl );
    158                 void previsit( UnionDecl *unionDecl );
     157                void previsit( StructDecl * structDecl );
     158                void previsit( UnionDecl * unionDecl );
    159159
    160160                void renameGenericParams( std::list< TypeDecl * > & params );
    161161
    162162          private:
    163                 const Indexer *local_indexer;
     163                const Indexer * local_indexer;
    164164
    165165                typedef std::map< std::string, std::list< EnumInstType * > > ForwardEnumsType;
     
    239239
    240240                template<typename AggDecl>
    241                 void handleAggregate( AggDecl *aggregateDecl );
     241                void handleAggregate( AggDecl * aggregateDecl );
    242242
    243243                void previsit( StructDecl * aggregateDecl );
     
    252252                static void verify( std::list< Declaration * > &translationUnit );
    253253
    254                 void previsit( FunctionDecl *funcDecl );
     254                void previsit( FunctionDecl * funcDecl );
    255255        };
    256256
     
    287287                Type::StorageClasses storageClasses;
    288288
    289                 void premutate( ObjectDecl *objectDecl );
    290                 Expression * postmutate( CompoundLiteralExpr *compLitExpr );
     289                void premutate( ObjectDecl * objectDecl );
     290                Expression * postmutate( CompoundLiteralExpr * compLitExpr );
    291291        };
    292292
     
    393393        }
    394394
    395         void validateType( Type *type, const Indexer *indexer ) {
     395        void validateType( Type * type, const Indexer * indexer ) {
    396396                PassVisitor<EnumAndPointerDecay_old> epc;
    397397                PassVisitor<LinkReferenceToTypes_old> lrt( indexer );
     
    496496        }
    497497
    498         bool shouldHoist( Declaration *decl ) {
     498        bool shouldHoist( Declaration * decl ) {
    499499                return dynamic_cast< StructDecl * >( decl ) || dynamic_cast< UnionDecl * >( decl ) || dynamic_cast< StaticAssertDecl * >( decl );
    500500        }
     
    515515
    516516        template< typename AggDecl >
    517         void HoistStruct::handleAggregate( AggDecl *aggregateDecl ) {
     517        void HoistStruct::handleAggregate( AggDecl * aggregateDecl ) {
    518518                if ( parentAggr ) {
    519519                        aggregateDecl->parent = parentAggr;
     
    560560
    561561
    562         bool isTypedef( Declaration *decl ) {
     562        bool isTypedef( Declaration * decl ) {
    563563                return dynamic_cast< TypedefDecl * >( decl );
    564564        }
     
    571571
    572572        template< typename AggDecl >
    573         void EliminateTypedef::handleAggregate( AggDecl *aggregateDecl ) {
     573        void EliminateTypedef::handleAggregate( AggDecl * aggregateDecl ) {
    574574                filter( aggregateDecl->members, isTypedef, true );
    575575        }
     
    586586                // remove and delete decl stmts
    587587                filter( compoundStmt->kids, [](Statement * stmt) {
    588                         if ( DeclStmt *declStmt = dynamic_cast< DeclStmt * >( stmt ) ) {
     588                        if ( DeclStmt * declStmt = dynamic_cast< DeclStmt * >( stmt ) ) {
    589589                                if ( dynamic_cast< TypedefDecl * >( declStmt->decl ) ) {
    590590                                        return true;
     
    595595        }
    596596
    597         void EnumAndPointerDecay_old::previsit( EnumDecl *enumDecl ) {
     597        void EnumAndPointerDecay_old::previsit( EnumDecl * enumDecl ) {
    598598                // Set the type of each member of the enumeration to be EnumConstant
    599599                for ( std::list< Declaration * >::iterator i = enumDecl->members.begin(); i != enumDecl->members.end(); ++i ) {
    600                         ObjectDecl * obj = dynamic_cast< ObjectDecl * >( *i );
     600                        ObjectDecl * obj = dynamic_cast< ObjectDecl * >( * i );
    601601                        assert( obj );
    602602                        obj->set_type( new EnumInstType( Type::Qualifiers( Type::Const ), enumDecl->name ) );
     
    627627        }
    628628
    629         void EnumAndPointerDecay_old::previsit( FunctionType *func ) {
     629        void EnumAndPointerDecay_old::previsit( FunctionType * func ) {
    630630                // Fix up parameters and return types
    631631                fixFunctionList( func->parameters, func->isVarArgs, func );
     
    633633        }
    634634
    635         LinkReferenceToTypes_old::LinkReferenceToTypes_old( const Indexer *other_indexer ) {
     635        LinkReferenceToTypes_old::LinkReferenceToTypes_old( const Indexer * other_indexer ) {
    636636                if ( other_indexer ) {
    637637                        local_indexer = other_indexer;
     
    641641        }
    642642
    643         void LinkReferenceToTypes_old::postvisit( EnumInstType *enumInst ) {
    644                 EnumDecl *st = local_indexer->lookupEnum( enumInst->name );
     643        void LinkReferenceToTypes_old::postvisit( EnumInstType * enumInst ) {
     644                EnumDecl * st = local_indexer->lookupMutableEnum( enumInst->name );
    645645                // it's not a semantic error if the enum is not found, just an implicit forward declaration
    646646                if ( st ) {
     
    661661        }
    662662
    663         void LinkReferenceToTypes_old::postvisit( StructInstType *structInst ) {
    664                 StructDecl *st = local_indexer->lookupStruct( structInst->name );
     663        void LinkReferenceToTypes_old::postvisit( StructInstType * structInst ) {
     664                StructDecl * st = local_indexer->lookupMutableStruct( structInst->name );
    665665                // it's not a semantic error if the struct is not found, just an implicit forward declaration
    666666                if ( st ) {
     
    674674        }
    675675
    676         void LinkReferenceToTypes_old::postvisit( UnionInstType *unionInst ) {
    677                 UnionDecl *un = local_indexer->lookupUnion( unionInst->name );
     676        void LinkReferenceToTypes_old::postvisit( UnionInstType * unionInst ) {
     677                UnionDecl * un = local_indexer->lookupMutableUnion( unionInst->name );
    678678                // it's not a semantic error if the union is not found, just an implicit forward declaration
    679679                if ( un ) {
     
    693693        void LinkReferenceToTypes_old::postvisit( QualifiedType * qualType ) {
    694694                // linking only makes sense for the 'oldest ancestor' of the qualified type
    695                 qualType->parent->accept( *visitor );
     695                qualType->parent->accept( * visitor );
    696696        }
    697697
     
    762762        void LinkReferenceToTypes_old::postvisit( TraitInstType * traitInst ) {
    763763                // handle other traits
    764                 TraitDecl *traitDecl = local_indexer->lookupTrait( traitInst->name );
     764                TraitDecl * traitDecl = local_indexer->lookupMutableTrait( traitInst->name );
    765765                if ( ! traitDecl ) {
    766766                        SemanticError( traitInst->location, "use of undeclared trait " + traitInst->name );
     
    786786        }
    787787
    788         void LinkReferenceToTypes_old::postvisit( EnumDecl *enumDecl ) {
     788        void LinkReferenceToTypes_old::postvisit( EnumDecl * enumDecl ) {
    789789                // visit enum members first so that the types of self-referencing members are updated properly
    790790                if ( enumDecl->body ) {
     
    792792                        if ( fwds != forwardEnums.end() ) {
    793793                                for ( std::list< EnumInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
    794                                         (*inst)->baseEnum = enumDecl;
     794                                        (* inst)->baseEnum = enumDecl;
    795795                                } // for
    796796                                forwardEnums.erase( fwds );
     
    834834        }
    835835
    836         void LinkReferenceToTypes_old::postvisit( StructDecl *structDecl ) {
     836        void LinkReferenceToTypes_old::postvisit( StructDecl * structDecl ) {
    837837                // visit struct members first so that the types of self-referencing members are updated properly
    838838                // xxx - need to ensure that type parameters match up between forward declarations and definition (most importantly, number of type parameters and their defaults)
     
    841841                        if ( fwds != forwardStructs.end() ) {
    842842                                for ( std::list< StructInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
    843                                         (*inst)->baseStruct = structDecl;
     843                                        (* inst)->baseStruct = structDecl;
    844844                                } // for
    845845                                forwardStructs.erase( fwds );
     
    848848        }
    849849
    850         void LinkReferenceToTypes_old::postvisit( UnionDecl *unionDecl ) {
     850        void LinkReferenceToTypes_old::postvisit( UnionDecl * unionDecl ) {
    851851                if ( unionDecl->body ) {
    852852                        ForwardUnionsType::iterator fwds = forwardUnions.find( unionDecl->name );
    853853                        if ( fwds != forwardUnions.end() ) {
    854854                                for ( std::list< UnionInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
    855                                         (*inst)->baseUnion = unionDecl;
     855                                        (* inst)->baseUnion = unionDecl;
    856856                                } // for
    857857                                forwardUnions.erase( fwds );
     
    860860        }
    861861
    862         void LinkReferenceToTypes_old::postvisit( TypeInstType *typeInst ) {
     862        void LinkReferenceToTypes_old::postvisit( TypeInstType * typeInst ) {
    863863                // ensure generic parameter instances are renamed like the base type
    864864                if ( inGeneric && typeInst->baseType ) typeInst->name = typeInst->baseType->name;
    865                 if ( NamedTypeDecl *namedTypeDecl = local_indexer->lookupType( typeInst->name ) ) {
    866                         if ( TypeDecl *typeDecl = dynamic_cast< TypeDecl * >( namedTypeDecl ) ) {
    867                                 typeInst->set_isFtype( typeDecl->get_kind() == TypeDecl::Ftype );
     865                if ( const NamedTypeDecl * namedTypeDecl = local_indexer->lookupType( typeInst->name ) ) {
     866                        if ( const TypeDecl * typeDecl = dynamic_cast< const TypeDecl * >( namedTypeDecl ) ) {
     867                                typeInst->set_isFtype( typeDecl->kind == TypeDecl::Ftype );
    868868                        } // if
    869869                } // if
     
    877877                        // expand trait instances into their members
    878878                        for ( DeclarationWithType * assertion : asserts ) {
    879                                 if ( TraitInstType *traitInst = dynamic_cast< TraitInstType * >( assertion->get_type() ) ) {
     879                                if ( TraitInstType * traitInst = dynamic_cast< TraitInstType * >( assertion->get_type() ) ) {
    880880                                        // expand trait instance into all of its members
    881881                                        expandAssertions( traitInst, back_inserter( type->assertions ) );
     
    897897        }
    898898
    899         void ForallPointerDecay_old::previsit( ObjectDecl *object ) {
     899        void ForallPointerDecay_old::previsit( ObjectDecl * object ) {
    900900                // ensure that operator names only apply to functions or function pointers
    901901                if ( CodeGen::isOperator( object->name ) && ! dynamic_cast< FunctionType * >( object->type->stripDeclarator() ) ) {
     
    905905        }
    906906
    907         void ForallPointerDecay_old::previsit( FunctionDecl *func ) {
     907        void ForallPointerDecay_old::previsit( FunctionDecl * func ) {
    908908                func->fixUniqueId();
    909909        }
     
    961961        Type * ReplaceTypedef::postmutate( QualifiedType * qualType ) {
    962962                // replacing typedefs only makes sense for the 'oldest ancestor' of the qualified type
    963                 qualType->parent = qualType->parent->acceptMutator( *visitor );
     963                qualType->parent = qualType->parent->acceptMutator( * visitor );
    964964                return qualType;
    965965        }
     
    970970                TypedefMap::const_iterator def = typedefNames.find( typeInst->name );
    971971                if ( def != typedefNames.end() ) {
    972                         Type *ret = def->second.first->base->clone();
     972                        Type * ret = def->second.first->base->clone();
    973973                        ret->location = typeInst->location;
    974974                        ret->get_qualifiers() |= typeInst->get_qualifiers();
     
    982982                        // place instance parameters on the typedef'd type
    983983                        if ( ! typeInst->parameters.empty() ) {
    984                                 ReferenceToType *rtt = dynamic_cast<ReferenceToType*>(ret);
     984                                ReferenceToType * rtt = dynamic_cast<ReferenceToType *>(ret);
    985985                                if ( ! rtt ) {
    986986                                        SemanticError( typeInst->location, "Cannot apply type parameters to base type of " + typeInst->name );
     
    988988                                rtt->parameters.clear();
    989989                                cloneAll( typeInst->parameters, rtt->parameters );
    990                                 mutateAll( rtt->parameters, *visitor );  // recursively fix typedefs on parameters
     990                                mutateAll( rtt->parameters, * visitor );  // recursively fix typedefs on parameters
    991991                        } // if
    992992                        delete typeInst;
     
    10431043                //    struct screen;
    10441044                // because the expansion of the typedef is:
    1045                 //    void rtn( SCREEN *p ) => void rtn( struct screen *p )
     1045                //    void rtn( SCREEN * p ) => void rtn( struct screen * p )
    10461046                // hence the type-name "screen" must be defined.
    10471047                // Note, qualifiers on the typedef are superfluous for the forward declaration.
    10481048
    1049                 Type *designatorType = tyDecl->base->stripDeclarator();
    1050                 if ( StructInstType *aggDecl = dynamic_cast< StructInstType * >( designatorType ) ) {
     1049                Type * designatorType = tyDecl->base->stripDeclarator();
     1050                if ( StructInstType * aggDecl = dynamic_cast< StructInstType * >( designatorType ) ) {
    10511051                        declsToAddBefore.push_back( new StructDecl( aggDecl->name, DeclarationNode::Struct, noAttributes, tyDecl->linkage ) );
    1052                 } else if ( UnionInstType *aggDecl = dynamic_cast< UnionInstType * >( designatorType ) ) {
     1052                } else if ( UnionInstType * aggDecl = dynamic_cast< UnionInstType * >( designatorType ) ) {
    10531053                        declsToAddBefore.push_back( new UnionDecl( aggDecl->name, noAttributes, tyDecl->linkage ) );
    1054                 } else if ( EnumInstType *enumDecl = dynamic_cast< EnumInstType * >( designatorType ) ) {
     1054                } else if ( EnumInstType * enumDecl = dynamic_cast< EnumInstType * >( designatorType ) ) {
    10551055                        declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage ) );
    10561056                } // if
     
    10781078
    10791079        DeclarationWithType * ReplaceTypedef::postmutate( ObjectDecl * objDecl ) {
    1080                 if ( FunctionType *funtype = dynamic_cast<FunctionType *>( objDecl->type ) ) { // function type?
     1080                if ( FunctionType * funtype = dynamic_cast<FunctionType *>( objDecl->type ) ) { // function type?
    10811081                        // replace the current object declaration with a function declaration
    10821082                        FunctionDecl * newDecl = new FunctionDecl( objDecl->name, objDecl->get_storageClasses(), objDecl->linkage, funtype, 0, objDecl->attributes, objDecl->get_funcSpec() );
     
    11041104        void ReplaceTypedef::addImplicitTypedef( AggDecl * aggDecl ) {
    11051105                if ( typedefNames.count( aggDecl->get_name() ) == 0 ) {
    1106                         Type *type = nullptr;
     1106                        Type * type = nullptr;
    11071107                        if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( aggDecl ) ) {
    11081108                                type = new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() );
     
    11301130                GuardScope( typedefNames );
    11311131                GuardScope( typedeclNames );
    1132                 mutateAll( aggr->parameters, *visitor );
     1132                mutateAll( aggr->parameters, * visitor );
    11331133
    11341134                // unroll mutateAll for aggr->members so that implicit typedefs for nested types are added to the aggregate body.
     
    11371137
    11381138                        try {
    1139                                 *i = maybeMutate( *i, *visitor );
     1139                                * i = maybeMutate( * i, * visitor );
    11401140                        } catch ( SemanticErrorException &e ) {
    11411141                                errors.append( e );
     
    12171217                        for ( size_t i = 0; paramIter != params->end(); ++paramIter, ++i ) {
    12181218                                if ( i < args.size() ) {
    1219                                         TypeExpr * expr = strict_dynamic_cast< TypeExpr * >( *std::next( args.begin(), i ) );
    1220                                         sub.add( (*paramIter)->get_name(), expr->get_type()->clone() );
     1219                                        TypeExpr * expr = strict_dynamic_cast< TypeExpr * >( * std::next( args.begin(), i ) );
     1220                                        sub.add( (* paramIter)->get_name(), expr->get_type()->clone() );
    12211221                                } else if ( i == args.size() ) {
    1222                                         Type * defaultType = (*paramIter)->get_init();
     1222                                        Type * defaultType = (* paramIter)->get_init();
    12231223                                        if ( defaultType ) {
    12241224                                                args.push_back( new TypeExpr( defaultType->clone() ) );
    1225                                                 sub.add( (*paramIter)->get_name(), defaultType->clone() );
     1225                                                sub.add( (* paramIter)->get_name(), defaultType->clone() );
    12261226                                        }
    12271227                                }
     
    12421242        }
    12431243
    1244         void CompoundLiteral::premutate( ObjectDecl *objectDecl ) {
     1244        void CompoundLiteral::premutate( ObjectDecl * objectDecl ) {
    12451245                storageClasses = objectDecl->get_storageClasses();
    12461246        }
    12471247
    1248         Expression *CompoundLiteral::postmutate( CompoundLiteralExpr *compLitExpr ) {
     1248        Expression * CompoundLiteral::postmutate( CompoundLiteralExpr * compLitExpr ) {
    12491249                // transform [storage_class] ... (struct S){ 3, ... };
    12501250                // into [storage_class] struct S temp =  { 3, ... };
    12511251                static UniqueName indexName( "_compLit" );
    12521252
    1253                 ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageClasses, LinkageSpec::C, nullptr, compLitExpr->get_result(), compLitExpr->get_initializer() );
     1253                ObjectDecl * tempvar = new ObjectDecl( indexName.newName(), storageClasses, LinkageSpec::C, nullptr, compLitExpr->get_result(), compLitExpr->get_initializer() );
    12541254                compLitExpr->set_result( nullptr );
    12551255                compLitExpr->set_initializer( nullptr );
     
    12891289                        TupleType * tupleType = strict_dynamic_cast< TupleType * >( ResolvExpr::extractResultType( ftype ) );
    12901290                        // ensure return value is not destructed by explicitly creating an empty ListInit node wherein maybeConstruct is false.
    1291                         ObjectDecl * newRet = new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, 0, tupleType, new ListInit( std::list<Initializer*>(), noDesignators, false ) );
     1291                        ObjectDecl * newRet = new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, 0, tupleType, new ListInit( std::list<Initializer *>(), noDesignators, false ) );
    12921292                        deleteAll( retVals );
    12931293                        retVals.clear();
     
    13021302
    13031303        void FixObjectType::previsit( ObjectDecl * objDecl ) {
    1304                 Type *new_type = ResolvExpr::resolveTypeof( objDecl->get_type(), indexer );
     1304                Type * new_type = ResolvExpr::resolveTypeof( objDecl->get_type(), indexer );
    13051305                new_type->get_qualifiers() -= Type::Lvalue; // even if typeof is lvalue, variable can never have lvalue-qualified type
    13061306                objDecl->set_type( new_type );
     
    13081308
    13091309        void FixObjectType::previsit( FunctionDecl * funcDecl ) {
    1310                 Type *new_type = ResolvExpr::resolveTypeof( funcDecl->type, indexer );
     1310                Type * new_type = ResolvExpr::resolveTypeof( funcDecl->type, indexer );
    13111311                new_type->get_qualifiers() -= Type::Lvalue; // even if typeof is lvalue, variable can never have lvalue-qualified type
    13121312                funcDecl->set_type( new_type );
    13131313        }
    13141314
    1315         void FixObjectType::previsit( TypeDecl *typeDecl ) {
     1315        void FixObjectType::previsit( TypeDecl * typeDecl ) {
    13161316                if ( typeDecl->get_base() ) {
    1317                         Type *new_type = ResolvExpr::resolveTypeof( typeDecl->get_base(), indexer );
     1317                        Type * new_type = ResolvExpr::resolveTypeof( typeDecl->get_base(), indexer );
    13181318                        new_type->get_qualifiers() -= Type::Lvalue; // even if typeof is lvalue, variable can never have lvalue-qualified type
    13191319                        typeDecl->set_base( new_type );
     
    13781378
    13791379namespace {
    1380         /// Replaces enum types by int, and function/array types in function parameter and return 
     1380        /// Replaces enum types by int, and function/array types in function parameter and return
    13811381        /// lists by appropriate pointers
    13821382        struct EnumAndPointerDecay_new {
     
    13851385                        for ( unsigned i = 0; i < enumDecl->members.size(); ++i ) {
    13861386                                // build new version of object with EnumConstant
    1387                                 ast::ptr< ast::ObjectDecl > obj = 
     1387                                ast::ptr< ast::ObjectDecl > obj =
    13881388                                        enumDecl->members[i].strict_as< ast::ObjectDecl >();
    1389                                 obj.get_and_mutate()->type = 
     1389                                obj.get_and_mutate()->type =
    13901390                                        new ast::EnumInstType{ enumDecl->name, ast::CV::Const };
    1391                                
     1391
    13921392                                // set into decl
    13931393                                ast::EnumDecl * mut = mutate( enumDecl );
     
    13991399
    14001400                static const ast::FunctionType * fixFunctionList(
    1401                         const ast::FunctionType * func, 
     1401                        const ast::FunctionType * func,
    14021402                        std::vector< ast::ptr< ast::DeclWithType > > ast::FunctionType::* field,
    14031403                        ast::ArgumentFlag isVarArgs = ast::FixedArgs
    14041404                ) {
    1405                         const auto & dwts = func->*field;
     1405                        const auto & dwts = func->* field;
    14061406                        unsigned nvals = dwts.size();
    14071407                        bool hasVoid = false;
     
    14091409                                func = ast::mutate_field_index( func, field, i, fixFunction( dwts[i], hasVoid ) );
    14101410                        }
    1411                        
     1411
    14121412                        // the only case in which "void" is valid is where it is the only one in the list
    14131413                        if ( hasVoid && ( nvals > 1 || isVarArgs ) ) {
    1414                                 SemanticError( 
     1414                                SemanticError(
    14151415                                        dwts.front()->location, func, "invalid type void in function type" );
    14161416                        }
     
    14181418                        // one void is the only thing in the list, remove it
    14191419                        if ( hasVoid ) {
    1420                                 func = ast::mutate_field( 
     1420                                func = ast::mutate_field(
    14211421                                        func, field, std::vector< ast::ptr< ast::DeclWithType > >{} );
    14221422                        }
     
    14321432
    14331433        /// expand assertions from a trait instance, performing appropriate type variable substitutions
    1434         void expandAssertions( 
    1435                 const ast::TraitInstType * inst, std::vector< ast::ptr< ast::DeclWithType > > & out 
     1434        void expandAssertions(
     1435                const ast::TraitInstType * inst, std::vector< ast::ptr< ast::DeclWithType > > & out
    14361436        ) {
    14371437                assertf( inst->base, "Trait instance not linked to base trait: %s", toCString( inst ) );
    14381438
    14391439                // build list of trait members, substituting trait decl parameters for instance parameters
    1440                 ast::TypeSubstitution sub{ 
     1440                ast::TypeSubstitution sub{
    14411441                        inst->base->params.begin(), inst->base->params.end(), inst->params.begin() };
    14421442                // deliberately take ast::ptr by-value to ensure this does not mutate inst->base
     
    14491449
    14501450        /// Associates forward declarations of aggregates with their definitions
    1451         class LinkReferenceToTypes_new final 
    1452         : public ast::WithSymbolTable, public ast::WithGuards, public 
     1451        class LinkReferenceToTypes_new final
     1452        : public ast::WithSymbolTable, public ast::WithGuards, public
    14531453          ast::WithVisitorRef<LinkReferenceToTypes_new>, public ast::WithShortCircuiting {
    1454                
    1455                 // these maps of uses of forward declarations of types need to have the actual type 
    1456                 // declaration switched in *after* they have been traversed. To enable this in the
    1457                 // ast::Pass framework, any node that needs to be so mutated has mutate() called on it 
    1458                 // before it is placed in the map, properly updating its parents in the usual traversal, 
     1454
     1455                // these maps of uses of forward declarations of types need to have the actual type
     1456                // declaration switched in * after * they have been traversed. To enable this in the
     1457                // ast::Pass framework, any node that needs to be so mutated has mutate() called on it
     1458                // before it is placed in the map, properly updating its parents in the usual traversal,
    14591459                // then can have the actual mutation applied later
    14601460                using ForwardEnumsType = std::unordered_multimap< std::string, ast::EnumInstType * >;
    14611461                using ForwardStructsType = std::unordered_multimap< std::string, ast::StructInstType * >;
    14621462                using ForwardUnionsType = std::unordered_multimap< std::string, ast::UnionInstType * >;
    1463                
     1463
    14641464                const CodeLocation & location;
    14651465                const ast::SymbolTable * localSymtab;
    1466                
     1466
    14671467                ForwardEnumsType forwardEnums;
    14681468                ForwardStructsType forwardStructs;
    14691469                ForwardUnionsType forwardUnions;
    14701470
    1471                 /// true if currently in a generic type body, so that type parameter instances can be 
     1471                /// true if currently in a generic type body, so that type parameter instances can be
    14721472                /// renamed appropriately
    14731473                bool inGeneric = false;
     
    14751475        public:
    14761476                /// contstruct using running symbol table
    1477                 LinkReferenceToTypes_new( const CodeLocation & loc ) 
     1477                LinkReferenceToTypes_new( const CodeLocation & loc )
    14781478                : location( loc ), localSymtab( &symtab ) {}
    1479                
     1479
    14801480                /// construct using provided symbol table
    1481                 LinkReferenceToTypes_new( const CodeLocation & loc, const ast::SymbolTable & syms ) 
     1481                LinkReferenceToTypes_new( const CodeLocation & loc, const ast::SymbolTable & syms )
    14821482                : location( loc ), localSymtab( &syms ) {}
    14831483
     
    14851485                        // ensure generic parameter instances are renamed like the base type
    14861486                        if ( inGeneric && typeInst->base ) {
    1487                                 typeInst = ast::mutate_field( 
     1487                                typeInst = ast::mutate_field(
    14881488                                        typeInst, &ast::TypeInstType::name, typeInst->base->name );
    14891489                        }
    14901490
    1491                         if ( 
    1492                                 auto typeDecl = dynamic_cast< const ast::TypeDecl * >( 
    1493                                         localSymtab->lookupType( typeInst->name ) ) 
     1491                        if (
     1492                                auto typeDecl = dynamic_cast< const ast::TypeDecl * >(
     1493                                        localSymtab->lookupType( typeInst->name ) )
    14941494                        ) {
    14951495                                typeInst = ast::mutate_field( typeInst, &ast::TypeInstType::kind, typeDecl->kind );
     
    15171517                        for ( const ast::Expr * param : inst->params ) {
    15181518                                if ( ! dynamic_cast< const ast::TypeExpr * >( param ) ) {
    1519                                         SemanticError( 
     1519                                        SemanticError(
    15201520                                                location, inst, "Expression parameters for generic types are currently "
    15211521                                                "unsupported: " );
     
    15711571                                auto expr = traitInst->params[i].as< ast::TypeExpr >();
    15721572                                if ( ! expr ) {
    1573                                         SemanticError( 
     1573                                        SemanticError(
    15741574                                                traitInst->params[i].get(), "Expression parameters for trait instances "
    15751575                                                "are currently unsupported: " );
     
    15931593                        return traitInst;
    15941594                }
    1595                
     1595
    15961596                void previsit( const ast::QualifiedType * ) { visit_children = false; }
    1597                
     1597
    15981598                const ast::Type * postvisit( const ast::QualifiedType * qualType ) {
    15991599                        // linking only makes sense for the "oldest ancestor" of the qualified type
    1600                         return ast::mutate_field( 
    1601                                 qualType, &ast::QualifiedType::parent, qualType->parent->accept( *visitor ) );
     1600                        return ast::mutate_field(
     1601                                qualType, &ast::QualifiedType::parent, qualType->parent->accept( * visitor ) );
    16021602                }
    16031603
    16041604                const ast::Decl * postvisit( const ast::EnumDecl * enumDecl ) {
    1605                         // visit enum members first so that the types of self-referencing members are updated 
     1605                        // visit enum members first so that the types of self-referencing members are updated
    16061606                        // properly
    16071607                        if ( ! enumDecl->body ) return enumDecl;
     
    16121612                                auto inst = fwds.first;
    16131613                                do {
    1614                                         // forward decl is stored *mutably* in map, can thus be updated
     1614                                        // forward decl is stored * mutably * in map, can thus be updated
    16151615                                        inst->second->base = enumDecl;
    16161616                                } while ( ++inst != fwds.second );
    16171617                                forwardEnums.erase( fwds.first, fwds.second );
    16181618                        }
    1619                        
     1619
    16201620                        // ensure that enumerator initializers are properly set
    16211621                        for ( unsigned i = 0; i < enumDecl->members.size(); ++i ) {
    16221622                                auto field = enumDecl->members[i].strict_as< ast::ObjectDecl >();
    16231623                                if ( field->init ) {
    1624                                         // need to resolve enumerator initializers early so that other passes that 
     1624                                        // need to resolve enumerator initializers early so that other passes that
    16251625                                        // determine if an expression is constexpr have appropriate information
    16261626                                        auto init = field->init.strict_as< ast::SingleInit >();
    1627                                        
    1628                                         enumDecl = ast::mutate_field_index( 
    1629                                                 enumDecl, &ast::EnumDecl::members, i, 
    1630                                                 ast::mutate_field( field, &ast::ObjectDecl::init, 
     1627
     1628                                        enumDecl = ast::mutate_field_index(
     1629                                                enumDecl, &ast::EnumDecl::members, i,
     1630                                                ast::mutate_field( field, &ast::ObjectDecl::init,
    16311631                                                        ast::mutate_field( init, &ast::SingleInit::value,
    1632                                                                 ResolvExpr::findSingleExpression( 
     1632                                                                ResolvExpr::findSingleExpression(
    16331633                                                                        init->value, new ast::BasicType{ ast::BasicType::SignedInt },
    16341634                                                                        symtab ) ) ) );
     
    16391639                }
    16401640
    1641                 /// rename generic type parameters uniquely so that they do not conflict with user defined 
     1641                /// rename generic type parameters uniquely so that they do not conflict with user defined
    16421642                /// function forall parameters, e.g. the T in Box and the T in f, below
    16431643                ///   forall(otype T)
     
    16571657                                const ast::TypeDecl * td = aggr->params[i];
    16581658
    1659                                 aggr = ast::mutate_field_index( 
    1660                                         aggr, &AggrDecl::params, i, 
     1659                                aggr = ast::mutate_field_index(
     1660                                        aggr, &AggrDecl::params, i,
    16611661                                        ast::mutate_field( td, &ast::TypeDecl::name, "__" + td->name + "_generic_" ) );
    16621662                        }
     
    16691669
    16701670                void postvisit( const ast::StructDecl * structDecl ) {
    1671                         // visit struct members first so that the types of self-referencing members are 
     1671                        // visit struct members first so that the types of self-referencing members are
    16721672                        // updated properly
    16731673                        if ( ! structDecl->body ) return;
     
    16781678                                auto inst = fwds.first;
    16791679                                do {
    1680                                         // forward decl is stored *mutably* in map, can thus be updated
     1680                                        // forward decl is stored * mutably * in map, can thus be updated
    16811681                                        inst->second->base = structDecl;
    16821682                                } while ( ++inst != fwds.second );
     
    16901690
    16911691                void postvisit( const ast::UnionDecl * unionDecl ) {
    1692                         // visit union members first so that the types of self-referencing members are updated 
     1692                        // visit union members first so that the types of self-referencing members are updated
    16931693                        // properly
    16941694                        if ( ! unionDecl->body ) return;
     
    16991699                                auto inst = fwds.first;
    17001700                                do {
    1701                                         // forward decl is stored *mutably* in map, can thus be updated
     1701                                        // forward decl is stored * mutably * in map, can thus be updated
    17021702                                        inst->second->base = unionDecl;
    17031703                                } while ( ++inst != fwds.second );
     
    17121712                                        "number of parameters: %zd", traitDecl->params.size() );
    17131713
    1714                                 traitDecl = ast::mutate_field_index( 
    1715                                         traitDecl, &ast::TraitDecl::params, 0, 
    1716                                         ast::mutate_field( 
     1714                                traitDecl = ast::mutate_field_index(
     1715                                        traitDecl, &ast::TraitDecl::params, 0,
     1716                                        ast::mutate_field(
    17171717                                                traitDecl->params.front().get(), &ast::TypeDecl::sized, true ) );
    17181718                        }
     
    17371737                                traitDecl = mut;
    17381738                        }
    1739                        
     1739
    17401740                        return traitDecl;
    17411741                }
    17421742        };
    17431743
    1744         /// Replaces array and function types in forall lists by appropriate pointer type and assigns 
     1744        /// Replaces array and function types in forall lists by appropriate pointer type and assigns
    17451745        /// each object and function declaration a unique ID
    17461746        class ForallPointerDecay_new {
     
    17511751                const ast::ObjectDecl * previsit( const ast::ObjectDecl * obj ) {
    17521752                        // ensure that operator names only apply to functions or function pointers
    1753                         if ( 
    1754                                 CodeGen::isOperator( obj->name ) 
     1753                        if (
     1754                                CodeGen::isOperator( obj->name )
    17551755                                && ! dynamic_cast< const ast::FunctionType * >( obj->type->stripDeclarator() )
    17561756                        ) {
     
    17761776                /// Fix up assertions -- flattens assertion lists, removing all trait instances
    17771777                template< typename node_t, typename parent_t >
    1778                 static const node_t * forallFixer( 
    1779                         const CodeLocation & loc, const node_t * node, 
     1778                static const node_t * forallFixer(
     1779                        const CodeLocation & loc, const node_t * node,
    17801780                        ast::ParameterizedType::ForallList parent_t::* forallField
    17811781                ) {
    1782                         for ( unsigned i = 0; i < (node->*forallField).size(); ++i ) {
    1783                                 const ast::TypeDecl * type = (node->*forallField)[i];
     1782                        for ( unsigned i = 0; i < (node->* forallField).size(); ++i ) {
     1783                                const ast::TypeDecl * type = (node->* forallField)[i];
    17841784                                if ( type->assertions.empty() ) continue;
    17851785
     
    17891789                                // expand trait instances into their members
    17901790                                for ( const ast::DeclWithType * assn : type->assertions ) {
    1791                                         auto traitInst = 
    1792                                                 dynamic_cast< const ast::TraitInstType * >( assn->get_type() ); 
     1791                                        auto traitInst =
     1792                                                dynamic_cast< const ast::TraitInstType * >( assn->get_type() );
    17931793                                        if ( traitInst ) {
    17941794                                                // expand trait instance to all its members
     
    18311831} // anonymous namespace
    18321832
    1833 const ast::Type * validateType( 
     1833const ast::Type * validateType(
    18341834                const CodeLocation & loc, const ast::Type * type, const ast::SymbolTable & symtab ) {
    18351835        ast::Pass< EnumAndPointerDecay_new > epc;
Note: See TracChangeset for help on using the changeset viewer.