Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Indexer.cc

    r114bde6 re67991f  
    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 {
     125                ++* stats().lookup_calls;
    126126                if ( ! typeTable ) return nullptr;
    127                 ++*stats().map_lookups;
     127                ++* stats().map_lookups;
    128128                auto it = typeTable->find( id );
    129129                return it == typeTable->end() ? nullptr : it->second.decl;
    130130        }
    131131
    132         StructDecl *Indexer::lookupStruct( const std::string &id ) const {
    133                 ++*stats().lookup_calls;
     132        const StructDecl * Indexer::lookupStruct( const std::string & id ) const {
     133                ++* stats().lookup_calls;
    134134                if ( ! structTable ) return nullptr;
    135                 ++*stats().map_lookups;
     135                ++* stats().map_lookups;
    136136                auto it = structTable->find( id );
    137137                return it == structTable->end() ? nullptr : it->second.decl;
    138138        }
    139139
    140         EnumDecl *Indexer::lookupEnum( const std::string &id ) const {
    141                 ++*stats().lookup_calls;
     140        const EnumDecl * Indexer::lookupEnum( const std::string & id ) const {
     141                ++* stats().lookup_calls;
    142142                if ( ! enumTable ) return nullptr;
    143                 ++*stats().map_lookups;
     143                ++* stats().map_lookups;
    144144                auto it = enumTable->find( id );
    145145                return it == enumTable->end() ? nullptr : it->second.decl;
    146146        }
    147147
    148         UnionDecl *Indexer::lookupUnion( const std::string &id ) const {
    149                 ++*stats().lookup_calls;
     148        const UnionDecl * Indexer::lookupUnion( const std::string & id ) const {
     149                ++* stats().lookup_calls;
    150150                if ( ! unionTable ) return nullptr;
    151                 ++*stats().map_lookups;
     151                ++* stats().map_lookups;
    152152                auto it = unionTable->find( id );
    153153                return it == unionTable->end() ? nullptr : it->second.decl;
    154154        }
    155155
    156         TraitDecl *Indexer::lookupTrait( const std::string &id ) const {
    157                 ++*stats().lookup_calls;
     156        const TraitDecl * Indexer::lookupTrait( const std::string & id ) const {
     157                ++* stats().lookup_calls;
    158158                if ( ! traitTable ) return nullptr;
    159                 ++*stats().map_lookups;
     159                ++* stats().map_lookups;
    160160                auto it = traitTable->find( id );
    161161                return it == traitTable->end() ? nullptr : it->second.decl;
    162162        }
    163163
    164         const Indexer* Indexer::atScope( unsigned long target ) const {
     164        const Indexer * Indexer::atScope( unsigned long target ) const {
    165165                // by lazy construction, final indexer in list has repScope 0, cannot be > target
    166166                // otherwise, will find first scope representing the target
    167                 const Indexer* indexer = this;
     167                const Indexer * indexer = this;
    168168                while ( indexer->repScope > target ) {
    169169                        indexer = indexer->prevScope.get();
     
    172172        }
    173173
    174         NamedTypeDecl *Indexer::globalLookupType( const std::string &id ) const {
     174        const NamedTypeDecl * Indexer::globalLookupType( const std::string & id ) const {
    175175                return atScope( 0 )->lookupType( id );
    176176        }
    177177
    178         StructDecl *Indexer::globalLookupStruct( const std::string &id ) const {
     178        const StructDecl * Indexer::globalLookupStruct( const std::string & id ) const {
    179179                return atScope( 0 )->lookupStruct( id );
    180180        }
    181181
    182         UnionDecl *Indexer::globalLookupUnion( const std::string &id ) const {
     182        const UnionDecl * Indexer::globalLookupUnion( const std::string & id ) const {
    183183                return atScope( 0 )->lookupUnion( id );
    184184        }
    185185
    186         EnumDecl *Indexer::globalLookupEnum( const std::string &id ) const {
     186        const EnumDecl * Indexer::globalLookupEnum( const std::string & id ) const {
    187187                return atScope( 0 )->lookupEnum( id );
    188188        }
    189189
    190         bool isFunction( DeclarationWithType * decl ) {
     190        bool isFunction( const DeclarationWithType * decl ) {
    191191                return GenPoly::getFunctionType( decl->get_type() );
    192192        }
    193193
    194         bool isObject( DeclarationWithType * decl ) {
     194        bool isObject( const DeclarationWithType * decl ) {
    195195                return ! isFunction( decl );
    196196        }
    197197
    198         bool isDefinition( DeclarationWithType * decl ) {
    199                 if ( FunctionDecl * func = dynamic_cast< FunctionDecl * >( decl ) ) {
     198        bool isDefinition( const DeclarationWithType * decl ) {
     199                if ( const FunctionDecl * func = dynamic_cast< const FunctionDecl * >( decl ) ) {
    200200                        // a function is a definition if it has a body
    201201                        return func->statements;
     
    207207        }
    208208
    209        
    210         bool Indexer::addedIdConflicts( 
    211                         const Indexer::IdData & existing, DeclarationWithType *added,
    212                         Indexer::OnConflict handleConflicts, BaseSyntaxNode * deleteStmt ) {
    213                 // if we're giving the same name mangling to things of different types then there is 
     209
     210        bool Indexer::addedIdConflicts(
     211                        const Indexer::IdData & existing, const DeclarationWithType * added,
     212                        Indexer::OnConflict handleConflicts, const Declaration * deleteStmt ) {
     213                // if we're giving the same name mangling to things of different types then there is
    214214                // something wrong
    215215                assert( (isObject( added ) && isObject( existing.id ) )
     
    219219                        // new definition shadows the autogenerated one, even at the same scope
    220220                        return false;
    221                 } else if ( LinkageSpec::isMangled( added->linkage ) 
    222                                 || ResolvExpr::typesCompatible( 
     221                } else if ( LinkageSpec::isMangled( added->linkage )
     222                                || ResolvExpr::typesCompatible(
    223223                                        added->get_type(), existing.id->get_type(), Indexer() ) ) {
    224224
     
    238238                        if ( isDefinition( added ) && isDefinition( existing.id ) ) {
    239239                                if ( handleConflicts.mode == OnConflict::Error ) {
    240                                         SemanticError( added, 
    241                                                 isFunction( added ) ? 
    242                                                         "duplicate function definition for " : 
     240                                        SemanticError( added,
     241                                                isFunction( added ) ?
     242                                                        "duplicate function definition for " :
    243243                                                        "duplicate object definition for " );
    244244                                }
     
    255255        }
    256256
    257         bool Indexer::hasCompatibleCDecl( const std::string &id, const std::string &mangleName ) const {
     257        bool Indexer::hasCompatibleCDecl( const std::string & id, const std::string &mangleName ) const {
    258258                if ( ! idTable ) return false;
    259259
    260                 ++*stats().map_lookups;
     260                ++* stats().map_lookups;
    261261                auto decls = idTable->find( id );
    262262                if ( decls == idTable->end() ) return false;
     
    270270                        }
    271271                }
    272                
     272
    273273                return false;
    274274        }
    275275
    276         bool Indexer::hasIncompatibleCDecl(
    277                         const std::string &id, const std::string &mangleName ) const {
     276        bool Indexer::hasIncompatibleCDecl(const std::string & id, const std::string &mangleName ) const {
    278277                if ( ! idTable ) return false;
    279278
    280                 ++*stats().map_lookups;
     279                ++* stats().map_lookups;
    281280                auto decls = idTable->find( id );
    282281                if ( decls == idTable->end() ) return false;
     
    295294
    296295        /// gets the base type of the first parameter; decl must be a ctor/dtor/assignment function
    297         std::string getOtypeKey( FunctionDecl* function ) {
     296        std::string getOtypeKey( const FunctionDecl * function ) {
    298297                auto& params = function->type->parameters;
    299298                assert( ! params.empty() );
    300299                // use base type of pointer, so that qualifiers on the pointer type aren't considered.
    301                 Type* base = InitTweak::getPointerBase( params.front()->get_type() );
     300                Type * base = InitTweak::getPointerBase( params.front()->get_type() );
    302301                assert( base );
    303302                return Mangler::mangle( base );
    304303        }
    305304
    306         /// gets the declaration for the function acting on a type specified by otype key, 
     305        /// gets the declaration for the function acting on a type specified by otype key,
    307306        /// nullptr if none such
    308         FunctionDecl * getFunctionForOtype( DeclarationWithType * decl, const std::string& otypeKey ) {
    309                 FunctionDecl * func = dynamic_cast< FunctionDecl * >( decl );
     307        const FunctionDecl * getFunctionForOtype( const DeclarationWithType * decl, const std::string& otypeKey ) {
     308                const FunctionDecl * func = dynamic_cast< const FunctionDecl * >( decl );
    310309                if ( ! func || otypeKey != getOtypeKey( func ) ) return nullptr;
    311310                return func;
    312311        }
    313312
    314         bool Indexer::removeSpecialOverrides(
    315                         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
     313        bool Indexer::removeSpecialOverrides(Indexer::IdData& data, Indexer::MangleTable::Ptr& mangleTable ) {
     314                // if a type contains user defined ctor/dtor/assign, then special rules trigger, which
     315                // determinethe set of ctor/dtor/assign that can be used  by the requester. In particular,
     316                // if the user defines a default ctor, then the generated default ctor is unavailable,
     317                // likewise for copy ctor and dtor. If the user defines any ctor/dtor, then no generated
     318                // field ctors are available. If the user defines any ctor then the generated default ctor
     319                // is unavailable (intrinsic default ctor must be overridden exactly). If the user defines
     320                // anything that looks like a copy constructor, then the generated copy constructor is
    323321                // unavailable, and likewise for the assignment operator.
    324322
    325323                // only relevant on function declarations
    326                 FunctionDecl * function = dynamic_cast< FunctionDecl * >( data.id );
     324                const FunctionDecl * function = dynamic_cast< const FunctionDecl * >( data.id );
    327325                if ( ! function ) return true;
    328326                // only need to perform this check for constructors, destructors, and assignment functions
     
    340338                        std::vector< MangleTable::value_type > deleted;
    341339                        bool alreadyUserDefinedFunc = false;
    342                        
    343                         for ( const auto& entry : *mangleTable ) {
     340
     341                        for ( const auto& entry : * mangleTable ) {
    344342                                // skip decls that aren't functions or are for the wrong type
    345                                 FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
     343                                const FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
    346344                                if ( ! decl ) continue;
    347345
     
    368366                        // perform removals from mangle table, and deletions if necessary
    369367                        for ( const auto& key : removed ) {
    370                                 ++*stats().map_mutations;
     368                                ++* stats().map_mutations;
    371369                                mangleTable = mangleTable->erase( key );
    372370                        }
    373371                        if ( ! alreadyUserDefinedFunc ) for ( const auto& entry : deleted ) {
    374                                 ++*stats().map_mutations;
     372                                ++* stats().map_mutations;
    375373                                mangleTable = mangleTable->set( entry.first, IdData{ entry.second, function } );
    376374                        }
     
    379377                        // if this is the first user-defined function, delete non-user-defined overloads
    380378                        std::vector< MangleTable::value_type > deleted;
    381                        
    382                         for ( const auto& entry : *mangleTable ) {
     379
     380                        for ( const auto& entry : * mangleTable ) {
    383381                                // skip decls that aren't functions or are for the wrong type
    384                                 FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
     382                                const FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
    385383                                if ( ! decl ) continue;
    386384
     
    402400                        // this needs to be a separate loop because of iterator invalidation
    403401                        for ( const auto& entry : deleted ) {
    404                                 ++*stats().map_mutations;
     402                                ++* stats().map_mutations;
    405403                                mangleTable = mangleTable->set( entry.first, IdData{ entry.second, function } );
    406404                        }
     
    408406                        // this is an overridable generated function
    409407                        // if there already exists a matching user-defined function, delete this appropriately
    410                         for ( const auto& entry : *mangleTable ) {
     408                        for ( const auto& entry : * mangleTable ) {
    411409                                // skip decls that aren't functions or are for the wrong type
    412                                 FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
     410                                const FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
    413411                                if ( ! decl ) continue;
    414412
     
    418416                                if ( dataIsCopyFunc ) {
    419417                                        // remove current function if exists a user-defined copy function
    420                                         // since the signatures for copy functions don't need to match exactly, using 
     418                                        // since the signatures for copy functions don't need to match exactly, using
    421419                                        // a delete statement is the wrong approach
    422420                                        if ( InitTweak::isCopyFunction( decl, decl->name ) ) return false;
     
    428426                        }
    429427                }
    430                
     428
    431429                // nothing (more) to fix, return true
    432430                return true;
    433431        }
    434432
    435         void Indexer::addId(
    436                         DeclarationWithType *decl, OnConflict handleConflicts, Expression * baseExpr,
    437                         BaseSyntaxNode * deleteStmt ) {
    438                 ++*stats().add_calls;
     433        void Indexer::addId(const DeclarationWithType * decl, OnConflict handleConflicts, const Expression * baseExpr,
     434                        const Declaration * deleteStmt ) {
     435                ++* stats().add_calls;
    439436                const std::string &name = decl->name;
    440437                if ( name == "" ) return;
    441                
     438
    442439                std::string mangleName;
    443440                if ( LinkageSpec::isOverridable( decl->linkage ) ) {
    444                         // mangle the name without including the appropriate suffix, so overridable routines 
     441                        // mangle the name without including the appropriate suffix, so overridable routines
    445442                        // are placed into the same "bucket" as their user defined versions.
    446443                        mangleName = Mangler::mangle( decl, false );
     
    449446                } // if
    450447
    451                 // this ensures that no two declarations with the same unmangled name at the same scope 
     448                // this ensures that no two declarations with the same unmangled name at the same scope
    452449                // both have C linkage
    453450                if ( LinkageSpec::isMangled( decl->linkage ) ) {
     
    457454                        }
    458455                } else {
    459                         // NOTE: only correct if name mangling is completely isomorphic to C 
     456                        // NOTE: only correct if name mangling is completely isomorphic to C
    460457                        // type-compatibility, which it may not be.
    461458                        if ( hasIncompatibleCDecl( name, mangleName ) ) {
     
    470467                        mangleTable = MangleTable::new_ptr();
    471468                } else {
    472                         ++*stats().map_lookups;
     469                        ++* stats().map_lookups;
    473470                        auto decls = idTable->find( name );
    474471                        if ( decls == idTable->end() ) {
     
    477474                                mangleTable = decls->second;
    478475                                // skip in-scope repeat declarations of same identifier
    479                                 ++*stats().map_lookups;
     476                                ++* stats().map_lookups;
    480477                                auto existing = mangleTable->find( mangleName );
    481478                                if ( existing != mangleTable->end()
     
    486483                                                        // set delete expression for conflicting identifier
    487484                                                        lazyInitScope();
    488                                                         *stats().map_mutations += 2;
     485                                                        * stats().map_mutations += 2;
    489486                                                        idTable = idTable->set(
    490487                                                                name,
    491                                                                 mangleTable->set( 
    492                                                                         mangleName, 
     488                                                                mangleTable->set(
     489                                                                        mangleName,
    493490                                                                        IdData{ existing->second, handleConflicts.deleteStmt } ) );
    494491                                                }
     
    504501                // Ensure that auto-generated ctor/dtor/assignment are deleted if necessary
    505502                if ( ! removeSpecialOverrides( data, mangleTable ) ) return;
    506                 *stats().map_mutations += 2;
     503                * stats().map_mutations += 2;
    507504                idTable = idTable->set( name, mangleTable->set( mangleName, std::move(data) ) );
    508505        }
    509506
    510         void Indexer::addId( DeclarationWithType * decl, Expression * baseExpr ) {
     507        void Indexer::addId( const DeclarationWithType * decl, const Expression * baseExpr ) {
    511508                // default handling of conflicts is to raise an error
    512509                addId( decl, OnConflict::error(), baseExpr, decl->isDeleted ? decl : nullptr );
    513510        }
    514511
    515         void Indexer::addDeletedId( DeclarationWithType * decl, BaseSyntaxNode * deleteStmt ) {
     512        void Indexer::addDeletedId( const DeclarationWithType * decl, const Declaration * deleteStmt ) {
    516513                // default handling of conflicts is to raise an error
    517514                addId( decl, OnConflict::error(), nullptr, deleteStmt );
    518515        }
    519516
    520         bool addedTypeConflicts( NamedTypeDecl *existing, NamedTypeDecl *added ) {
     517        bool addedTypeConflicts( const NamedTypeDecl * existing, const NamedTypeDecl * added ) {
    521518                if ( existing->base == nullptr ) {
    522519                        return false;
     
    530527                        }
    531528                }
    532                 // does not need to be added to the table if both existing and added have a base that are 
     529                // does not need to be added to the table if both existing and added have a base that are
    533530                // the same
    534531                return true;
    535532        }
    536533
    537         void Indexer::addType( NamedTypeDecl *decl ) {
    538                 ++*stats().add_calls;
    539                 const std::string &id = decl->name;
    540 
    541                 if ( ! typeTable ) { 
     534        void Indexer::addType( const NamedTypeDecl * decl ) {
     535                ++* stats().add_calls;
     536                const std::string & id = decl->name;
     537
     538                if ( ! typeTable ) {
    542539                        typeTable = TypeTable::new_ptr();
    543540                } else {
    544                         ++*stats().map_lookups;
     541                        ++* stats().map_lookups;
    545542                        auto existing = typeTable->find( id );
    546                         if ( existing != typeTable->end() 
    547                                 && existing->second.scope == scope 
     543                        if ( existing != typeTable->end()
     544                                && existing->second.scope == scope
    548545                                && addedTypeConflicts( existing->second.decl, decl ) ) return;
    549546                }
    550                
     547
    551548                lazyInitScope();
    552                 ++*stats().map_mutations;
     549                ++* stats().map_mutations;
    553550                typeTable = typeTable->set( id, Scoped<NamedTypeDecl>{ decl, scope } );
    554551        }
    555552
    556         bool addedDeclConflicts( AggregateDecl *existing, AggregateDecl *added ) {
     553        bool addedDeclConflicts( const AggregateDecl * existing, const AggregateDecl * added ) {
    557554                if ( ! existing->body ) {
    558555                        return false;
     
    563560        }
    564561
    565         void Indexer::addStruct( const std::string &id ) {
     562        void Indexer::addStruct( const std::string & id ) {
    566563                addStruct( new StructDecl( id ) );
    567564        }
    568565
    569         void Indexer::addStruct( StructDecl *decl ) {
    570                 ++*stats().add_calls;
    571                 const std::string &id = decl->name;
     566        void Indexer::addStruct( const StructDecl * decl ) {
     567                ++* stats().add_calls;
     568                const std::string & id = decl->name;
    572569
    573570                if ( ! structTable ) {
    574571                        structTable = StructTable::new_ptr();
    575572                } else {
    576                         ++*stats().map_lookups;
     573                        ++* stats().map_lookups;
    577574                        auto existing = structTable->find( id );
    578                         if ( existing != structTable->end() 
    579                                 && existing->second.scope == scope 
     575                        if ( existing != structTable->end()
     576                                && existing->second.scope == scope
    580577                                && addedDeclConflicts( existing->second.decl, decl ) ) return;
    581578                }
    582579
    583580                lazyInitScope();
    584                 ++*stats().map_mutations;
     581                ++* stats().map_mutations;
    585582                structTable = structTable->set( id, Scoped<StructDecl>{ decl, scope } );
    586583        }
    587584
    588         void Indexer::addEnum( EnumDecl *decl ) {
    589                 ++*stats().add_calls;
    590                 const std::string &id = decl->name;
     585        void Indexer::addEnum( const EnumDecl * decl ) {
     586                ++* stats().add_calls;
     587                const std::string & id = decl->name;
    591588
    592589                if ( ! enumTable ) {
    593590                        enumTable = EnumTable::new_ptr();
    594591                } else {
    595                         ++*stats().map_lookups;
     592                        ++* stats().map_lookups;
    596593                        auto existing = enumTable->find( id );
    597                         if ( existing != enumTable->end() 
    598                                 && existing->second.scope == scope 
     594                        if ( existing != enumTable->end()
     595                                && existing->second.scope == scope
    599596                                && addedDeclConflicts( existing->second.decl, decl ) ) return;
    600597                }
    601                
     598
    602599                lazyInitScope();
    603                 ++*stats().map_mutations;
     600                ++* stats().map_mutations;
    604601                enumTable = enumTable->set( id, Scoped<EnumDecl>{ decl, scope } );
    605602        }
    606603
    607         void Indexer::addUnion( const std::string &id ) {
     604        void Indexer::addUnion( const std::string & id ) {
    608605                addUnion( new UnionDecl( id ) );
    609606        }
    610607
    611         void Indexer::addUnion( UnionDecl *decl ) {
    612                 ++*stats().add_calls;
    613                 const std::string &id = decl->name;
     608        void Indexer::addUnion( const UnionDecl * decl ) {
     609                ++* stats().add_calls;
     610                const std::string & id = decl->name;
    614611
    615612                if ( ! unionTable ) {
    616613                        unionTable = UnionTable::new_ptr();
    617614                } else {
    618                         ++*stats().map_lookups;
     615                        ++* stats().map_lookups;
    619616                        auto existing = unionTable->find( id );
    620                         if ( existing != unionTable->end() 
    621                                 && existing->second.scope == scope 
     617                        if ( existing != unionTable->end()
     618                                && existing->second.scope == scope
    622619                                && addedDeclConflicts( existing->second.decl, decl ) ) return;
    623620                }
    624621
    625622                lazyInitScope();
    626                 ++*stats().map_mutations;
     623                ++* stats().map_mutations;
    627624                unionTable = unionTable->set( id, Scoped<UnionDecl>{ decl, scope } );
    628625        }
    629626
    630         void Indexer::addTrait( TraitDecl *decl ) {
    631                 ++*stats().add_calls;
    632                 const std::string &id = decl->name;
     627        void Indexer::addTrait( const TraitDecl * decl ) {
     628                ++* stats().add_calls;
     629                const std::string & id = decl->name;
    633630
    634631                if ( ! traitTable ) {
    635632                        traitTable = TraitTable::new_ptr();
    636633                } else {
    637                         ++*stats().map_lookups;
     634                        ++* stats().map_lookups;
    638635                        auto existing = traitTable->find( id );
    639                         if ( existing != traitTable->end() 
    640                                 && existing->second.scope == scope 
     636                        if ( existing != traitTable->end()
     637                                && existing->second.scope == scope
    641638                                && addedDeclConflicts( existing->second.decl, decl ) ) return;
    642639                }
    643640
    644641                lazyInitScope();
    645                 ++*stats().map_mutations;
     642                ++* stats().map_mutations;
    646643                traitTable = traitTable->set( id, Scoped<TraitDecl>{ decl, scope } );
    647644        }
    648645
    649         void Indexer::addMembers( AggregateDecl * aggr, Expression * expr,
    650                         OnConflict handleConflicts ) {
     646        void Indexer::addMembers( const AggregateDecl * aggr, const Expression * expr, OnConflict handleConflicts ) {
    651647                for ( Declaration * decl : aggr->members ) {
    652648                        if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
    653649                                addId( dwt, handleConflicts, expr );
    654650                                if ( dwt->name == "" ) {
    655                                         Type * t = dwt->get_type()->stripReferences();
    656                                         if ( dynamic_cast<StructInstType*>( t ) || dynamic_cast<UnionInstType*>( t ) ) {
     651                                        const Type * t = dwt->get_type()->stripReferences();
     652                                        if ( dynamic_cast<const StructInstType *>( t ) || dynamic_cast<const UnionInstType *>( t ) ) {
    657653                                                Expression * base = expr->clone();
    658654                                                ResolvExpr::Cost cost = ResolvExpr::Cost::zero; // xxx - carry this cost into the indexer as a base cost?
     
    665661        }
    666662
    667         void Indexer::addWith( std::list< Expression * > & withExprs, BaseSyntaxNode * withStmt ) {
    668                 for ( Expression * expr : withExprs ) {
     663        void Indexer::addWith( const std::list< Expression * > & withExprs, const Declaration * withStmt ) {
     664                for ( const Expression * expr : withExprs ) {
    669665                        if ( expr->result ) {
    670666                                AggregateDecl * aggr = expr->result->stripReferences()->getAggr();
     
    689685        }
    690686
    691         void Indexer::addFunctionType( FunctionType * ftype ) {
     687        void Indexer::addFunctionType( const FunctionType * ftype ) {
    692688                addTypes( ftype->forall );
    693689                addIds( ftype->returnVals );
     
    700696                        Expression * base = baseExpr->clone();
    701697                        ResolvExpr::referenceToRvalueConversion( base, cost );
    702                         ret = new MemberExpr( id, base );
     698                        ret = new MemberExpr( const_cast<DeclarationWithType *>(id), base );
    703699                        // xxx - this introduces hidden environments, for now remove them.
    704700                        // std::swap( base->env, ret->env );
     
    706702                        base->env = nullptr;
    707703                } else {
    708                         ret = new VariableExpr( id );
    709                 }
    710                 if ( deleteStmt ) ret = new DeletedExpr( ret, deleteStmt );
     704                        ret = new VariableExpr( const_cast<DeclarationWithType *>(id) );
     705                }
     706                if ( deleteStmt ) ret = new DeletedExpr( ret, const_cast<Declaration *>(deleteStmt) );
    711707                return ret;
    712708        }
Note: See TracChangeset for help on using the changeset viewer.