Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Indexer.cc

    re67991f r114bde6  
    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         const NamedTypeDecl * Indexer::lookupType( const std::string & id ) const {
    125                 ++* stats().lookup_calls;
     124        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         const StructDecl * Indexer::lookupStruct( const std::string & id ) const {
    133                 ++* stats().lookup_calls;
     132        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         const EnumDecl * Indexer::lookupEnum( const std::string & id ) const {
    141                 ++* stats().lookup_calls;
     140        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         const UnionDecl * Indexer::lookupUnion( const std::string & id ) const {
    149                 ++* stats().lookup_calls;
     148        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         const TraitDecl * Indexer::lookupTrait( const std::string & id ) const {
    157                 ++* stats().lookup_calls;
     156        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         const NamedTypeDecl * Indexer::globalLookupType( const std::string & id ) const {
     174        NamedTypeDecl *Indexer::globalLookupType( const std::string &id ) const {
    175175                return atScope( 0 )->lookupType( id );
    176176        }
    177177
    178         const StructDecl * Indexer::globalLookupStruct( const std::string & id ) const {
     178        StructDecl *Indexer::globalLookupStruct( const std::string &id ) const {
    179179                return atScope( 0 )->lookupStruct( id );
    180180        }
    181181
    182         const UnionDecl * Indexer::globalLookupUnion( const std::string & id ) const {
     182        UnionDecl *Indexer::globalLookupUnion( const std::string &id ) const {
    183183                return atScope( 0 )->lookupUnion( id );
    184184        }
    185185
    186         const EnumDecl * Indexer::globalLookupEnum( const std::string & id ) const {
     186        EnumDecl *Indexer::globalLookupEnum( const std::string &id ) const {
    187187                return atScope( 0 )->lookupEnum( id );
    188188        }
    189189
    190         bool isFunction( const DeclarationWithType * decl ) {
     190        bool isFunction( DeclarationWithType * decl ) {
    191191                return GenPoly::getFunctionType( decl->get_type() );
    192192        }
    193193
    194         bool isObject( const DeclarationWithType * decl ) {
     194        bool isObject( DeclarationWithType * decl ) {
    195195                return ! isFunction( decl );
    196196        }
    197197
    198         bool isDefinition( const DeclarationWithType * decl ) {
    199                 if ( const FunctionDecl * func = dynamic_cast< const FunctionDecl * >( decl ) ) {
     198        bool isDefinition( DeclarationWithType * decl ) {
     199                if ( FunctionDecl * func = dynamic_cast< 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, 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
     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 
    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(const std::string & id, const std::string &mangleName ) const {
     276        bool Indexer::hasIncompatibleCDecl(
     277                        const std::string &id, const std::string &mangleName ) const {
    277278                if ( ! idTable ) return false;
    278279
    279                 ++* stats().map_lookups;
     280                ++*stats().map_lookups;
    280281                auto decls = idTable->find( id );
    281282                if ( decls == idTable->end() ) return false;
     
    294295
    295296        /// gets the base type of the first parameter; decl must be a ctor/dtor/assignment function
    296         std::string getOtypeKey( const FunctionDecl * function ) {
     297        std::string getOtypeKey( FunctionDecl* function ) {
    297298                auto& params = function->type->parameters;
    298299                assert( ! params.empty() );
    299300                // use base type of pointer, so that qualifiers on the pointer type aren't considered.
    300                 Type * base = InitTweak::getPointerBase( params.front()->get_type() );
     301                Type* base = InitTweak::getPointerBase( params.front()->get_type() );
    301302                assert( base );
    302303                return Mangler::mangle( base );
    303304        }
    304305
    305         /// gets the declaration for the function acting on a type specified by otype key,
     306        /// gets the declaration for the function acting on a type specified by otype key, 
    306307        /// nullptr if none such
    307         const FunctionDecl * getFunctionForOtype( const DeclarationWithType * decl, const std::string& otypeKey ) {
    308                 const FunctionDecl * func = dynamic_cast< const FunctionDecl * >( decl );
     308        FunctionDecl * getFunctionForOtype( DeclarationWithType * decl, const std::string& otypeKey ) {
     309                FunctionDecl * func = dynamic_cast< FunctionDecl * >( decl );
    309310                if ( ! func || otypeKey != getOtypeKey( func ) ) return nullptr;
    310311                return func;
    311312        }
    312313
    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
     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
    321323                // unavailable, and likewise for the assignment operator.
    322324
    323325                // only relevant on function declarations
    324                 const FunctionDecl * function = dynamic_cast< const FunctionDecl * >( data.id );
     326                FunctionDecl * function = dynamic_cast< FunctionDecl * >( data.id );
    325327                if ( ! function ) return true;
    326328                // only need to perform this check for constructors, destructors, and assignment functions
     
    338340                        std::vector< MangleTable::value_type > deleted;
    339341                        bool alreadyUserDefinedFunc = false;
    340 
    341                         for ( const auto& entry : * mangleTable ) {
     342                       
     343                        for ( const auto& entry : *mangleTable ) {
    342344                                // skip decls that aren't functions or are for the wrong type
    343                                 const FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
     345                                FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
    344346                                if ( ! decl ) continue;
    345347
     
    366368                        // perform removals from mangle table, and deletions if necessary
    367369                        for ( const auto& key : removed ) {
    368                                 ++* stats().map_mutations;
     370                                ++*stats().map_mutations;
    369371                                mangleTable = mangleTable->erase( key );
    370372                        }
    371373                        if ( ! alreadyUserDefinedFunc ) for ( const auto& entry : deleted ) {
    372                                 ++* stats().map_mutations;
     374                                ++*stats().map_mutations;
    373375                                mangleTable = mangleTable->set( entry.first, IdData{ entry.second, function } );
    374376                        }
     
    377379                        // if this is the first user-defined function, delete non-user-defined overloads
    378380                        std::vector< MangleTable::value_type > deleted;
    379 
    380                         for ( const auto& entry : * mangleTable ) {
     381                       
     382                        for ( const auto& entry : *mangleTable ) {
    381383                                // skip decls that aren't functions or are for the wrong type
    382                                 const FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
     384                                FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
    383385                                if ( ! decl ) continue;
    384386
     
    400402                        // this needs to be a separate loop because of iterator invalidation
    401403                        for ( const auto& entry : deleted ) {
    402                                 ++* stats().map_mutations;
     404                                ++*stats().map_mutations;
    403405                                mangleTable = mangleTable->set( entry.first, IdData{ entry.second, function } );
    404406                        }
     
    406408                        // this is an overridable generated function
    407409                        // if there already exists a matching user-defined function, delete this appropriately
    408                         for ( const auto& entry : * mangleTable ) {
     410                        for ( const auto& entry : *mangleTable ) {
    409411                                // skip decls that aren't functions or are for the wrong type
    410                                 const FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
     412                                FunctionDecl * decl = getFunctionForOtype( entry.second.id, dataOtypeKey );
    411413                                if ( ! decl ) continue;
    412414
     
    416418                                if ( dataIsCopyFunc ) {
    417419                                        // remove current function if exists a user-defined copy function
    418                                         // since the signatures for copy functions don't need to match exactly, using
     420                                        // since the signatures for copy functions don't need to match exactly, using 
    419421                                        // a delete statement is the wrong approach
    420422                                        if ( InitTweak::isCopyFunction( decl, decl->name ) ) return false;
     
    426428                        }
    427429                }
    428 
     430               
    429431                // nothing (more) to fix, return true
    430432                return true;
    431433        }
    432434
    433         void Indexer::addId(const DeclarationWithType * decl, OnConflict handleConflicts, const Expression * baseExpr,
    434                         const Declaration * deleteStmt ) {
    435                 ++* stats().add_calls;
     435        void Indexer::addId(
     436                        DeclarationWithType *decl, OnConflict handleConflicts, Expression * baseExpr,
     437                        BaseSyntaxNode * deleteStmt ) {
     438                ++*stats().add_calls;
    436439                const std::string &name = decl->name;
    437440                if ( name == "" ) return;
    438 
     441               
    439442                std::string mangleName;
    440443                if ( LinkageSpec::isOverridable( decl->linkage ) ) {
    441                         // mangle the name without including the appropriate suffix, so overridable routines
     444                        // mangle the name without including the appropriate suffix, so overridable routines 
    442445                        // are placed into the same "bucket" as their user defined versions.
    443446                        mangleName = Mangler::mangle( decl, false );
     
    446449                } // if
    447450
    448                 // this ensures that no two declarations with the same unmangled name at the same scope
     451                // this ensures that no two declarations with the same unmangled name at the same scope 
    449452                // both have C linkage
    450453                if ( LinkageSpec::isMangled( decl->linkage ) ) {
     
    454457                        }
    455458                } else {
    456                         // NOTE: only correct if name mangling is completely isomorphic to C
     459                        // NOTE: only correct if name mangling is completely isomorphic to C 
    457460                        // type-compatibility, which it may not be.
    458461                        if ( hasIncompatibleCDecl( name, mangleName ) ) {
     
    467470                        mangleTable = MangleTable::new_ptr();
    468471                } else {
    469                         ++* stats().map_lookups;
     472                        ++*stats().map_lookups;
    470473                        auto decls = idTable->find( name );
    471474                        if ( decls == idTable->end() ) {
     
    474477                                mangleTable = decls->second;
    475478                                // skip in-scope repeat declarations of same identifier
    476                                 ++* stats().map_lookups;
     479                                ++*stats().map_lookups;
    477480                                auto existing = mangleTable->find( mangleName );
    478481                                if ( existing != mangleTable->end()
     
    483486                                                        // set delete expression for conflicting identifier
    484487                                                        lazyInitScope();
    485                                                         * stats().map_mutations += 2;
     488                                                        *stats().map_mutations += 2;
    486489                                                        idTable = idTable->set(
    487490                                                                name,
    488                                                                 mangleTable->set(
    489                                                                         mangleName,
     491                                                                mangleTable->set( 
     492                                                                        mangleName, 
    490493                                                                        IdData{ existing->second, handleConflicts.deleteStmt } ) );
    491494                                                }
     
    501504                // Ensure that auto-generated ctor/dtor/assignment are deleted if necessary
    502505                if ( ! removeSpecialOverrides( data, mangleTable ) ) return;
    503                 * stats().map_mutations += 2;
     506                *stats().map_mutations += 2;
    504507                idTable = idTable->set( name, mangleTable->set( mangleName, std::move(data) ) );
    505508        }
    506509
    507         void Indexer::addId( const DeclarationWithType * decl, const Expression * baseExpr ) {
     510        void Indexer::addId( DeclarationWithType * decl, Expression * baseExpr ) {
    508511                // default handling of conflicts is to raise an error
    509512                addId( decl, OnConflict::error(), baseExpr, decl->isDeleted ? decl : nullptr );
    510513        }
    511514
    512         void Indexer::addDeletedId( const DeclarationWithType * decl, const Declaration * deleteStmt ) {
     515        void Indexer::addDeletedId( DeclarationWithType * decl, BaseSyntaxNode * deleteStmt ) {
    513516                // default handling of conflicts is to raise an error
    514517                addId( decl, OnConflict::error(), nullptr, deleteStmt );
    515518        }
    516519
    517         bool addedTypeConflicts( const NamedTypeDecl * existing, const NamedTypeDecl * added ) {
     520        bool addedTypeConflicts( NamedTypeDecl *existing, NamedTypeDecl *added ) {
    518521                if ( existing->base == nullptr ) {
    519522                        return false;
     
    527530                        }
    528531                }
    529                 // does not need to be added to the table if both existing and added have a base that are
     532                // does not need to be added to the table if both existing and added have a base that are 
    530533                // the same
    531534                return true;
    532535        }
    533536
    534         void Indexer::addType( const NamedTypeDecl * decl ) {
    535                 ++* stats().add_calls;
    536                 const std::string & id = decl->name;
    537 
    538                 if ( ! typeTable ) {
     537        void Indexer::addType( NamedTypeDecl *decl ) {
     538                ++*stats().add_calls;
     539                const std::string &id = decl->name;
     540
     541                if ( ! typeTable ) { 
    539542                        typeTable = TypeTable::new_ptr();
    540543                } else {
    541                         ++* stats().map_lookups;
     544                        ++*stats().map_lookups;
    542545                        auto existing = typeTable->find( id );
    543                         if ( existing != typeTable->end()
    544                                 && existing->second.scope == scope
     546                        if ( existing != typeTable->end() 
     547                                && existing->second.scope == scope 
    545548                                && addedTypeConflicts( existing->second.decl, decl ) ) return;
    546549                }
    547 
     550               
    548551                lazyInitScope();
    549                 ++* stats().map_mutations;
     552                ++*stats().map_mutations;
    550553                typeTable = typeTable->set( id, Scoped<NamedTypeDecl>{ decl, scope } );
    551554        }
    552555
    553         bool addedDeclConflicts( const AggregateDecl * existing, const AggregateDecl * added ) {
     556        bool addedDeclConflicts( AggregateDecl *existing, AggregateDecl *added ) {
    554557                if ( ! existing->body ) {
    555558                        return false;
     
    560563        }
    561564
    562         void Indexer::addStruct( const std::string & id ) {
     565        void Indexer::addStruct( const std::string &id ) {
    563566                addStruct( new StructDecl( id ) );
    564567        }
    565568
    566         void Indexer::addStruct( const StructDecl * decl ) {
    567                 ++* stats().add_calls;
    568                 const std::string & id = decl->name;
     569        void Indexer::addStruct( StructDecl *decl ) {
     570                ++*stats().add_calls;
     571                const std::string &id = decl->name;
    569572
    570573                if ( ! structTable ) {
    571574                        structTable = StructTable::new_ptr();
    572575                } else {
    573                         ++* stats().map_lookups;
     576                        ++*stats().map_lookups;
    574577                        auto existing = structTable->find( id );
    575                         if ( existing != structTable->end()
    576                                 && existing->second.scope == scope
     578                        if ( existing != structTable->end() 
     579                                && existing->second.scope == scope 
    577580                                && addedDeclConflicts( existing->second.decl, decl ) ) return;
    578581                }
    579582
    580583                lazyInitScope();
    581                 ++* stats().map_mutations;
     584                ++*stats().map_mutations;
    582585                structTable = structTable->set( id, Scoped<StructDecl>{ decl, scope } );
    583586        }
    584587
    585         void Indexer::addEnum( const EnumDecl * decl ) {
    586                 ++* stats().add_calls;
    587                 const std::string & id = decl->name;
     588        void Indexer::addEnum( EnumDecl *decl ) {
     589                ++*stats().add_calls;
     590                const std::string &id = decl->name;
    588591
    589592                if ( ! enumTable ) {
    590593                        enumTable = EnumTable::new_ptr();
    591594                } else {
    592                         ++* stats().map_lookups;
     595                        ++*stats().map_lookups;
    593596                        auto existing = enumTable->find( id );
    594                         if ( existing != enumTable->end()
    595                                 && existing->second.scope == scope
     597                        if ( existing != enumTable->end() 
     598                                && existing->second.scope == scope 
    596599                                && addedDeclConflicts( existing->second.decl, decl ) ) return;
    597600                }
    598 
     601               
    599602                lazyInitScope();
    600                 ++* stats().map_mutations;
     603                ++*stats().map_mutations;
    601604                enumTable = enumTable->set( id, Scoped<EnumDecl>{ decl, scope } );
    602605        }
    603606
    604         void Indexer::addUnion( const std::string & id ) {
     607        void Indexer::addUnion( const std::string &id ) {
    605608                addUnion( new UnionDecl( id ) );
    606609        }
    607610
    608         void Indexer::addUnion( const UnionDecl * decl ) {
    609                 ++* stats().add_calls;
    610                 const std::string & id = decl->name;
     611        void Indexer::addUnion( UnionDecl *decl ) {
     612                ++*stats().add_calls;
     613                const std::string &id = decl->name;
    611614
    612615                if ( ! unionTable ) {
    613616                        unionTable = UnionTable::new_ptr();
    614617                } else {
    615                         ++* stats().map_lookups;
     618                        ++*stats().map_lookups;
    616619                        auto existing = unionTable->find( id );
    617                         if ( existing != unionTable->end()
    618                                 && existing->second.scope == scope
     620                        if ( existing != unionTable->end() 
     621                                && existing->second.scope == scope 
    619622                                && addedDeclConflicts( existing->second.decl, decl ) ) return;
    620623                }
    621624
    622625                lazyInitScope();
    623                 ++* stats().map_mutations;
     626                ++*stats().map_mutations;
    624627                unionTable = unionTable->set( id, Scoped<UnionDecl>{ decl, scope } );
    625628        }
    626629
    627         void Indexer::addTrait( const TraitDecl * decl ) {
    628                 ++* stats().add_calls;
    629                 const std::string & id = decl->name;
     630        void Indexer::addTrait( TraitDecl *decl ) {
     631                ++*stats().add_calls;
     632                const std::string &id = decl->name;
    630633
    631634                if ( ! traitTable ) {
    632635                        traitTable = TraitTable::new_ptr();
    633636                } else {
    634                         ++* stats().map_lookups;
     637                        ++*stats().map_lookups;
    635638                        auto existing = traitTable->find( id );
    636                         if ( existing != traitTable->end()
    637                                 && existing->second.scope == scope
     639                        if ( existing != traitTable->end() 
     640                                && existing->second.scope == scope 
    638641                                && addedDeclConflicts( existing->second.decl, decl ) ) return;
    639642                }
    640643
    641644                lazyInitScope();
    642                 ++* stats().map_mutations;
     645                ++*stats().map_mutations;
    643646                traitTable = traitTable->set( id, Scoped<TraitDecl>{ decl, scope } );
    644647        }
    645648
    646         void Indexer::addMembers( const AggregateDecl * aggr, const Expression * expr, OnConflict handleConflicts ) {
     649        void Indexer::addMembers( AggregateDecl * aggr, Expression * expr,
     650                        OnConflict handleConflicts ) {
    647651                for ( Declaration * decl : aggr->members ) {
    648652                        if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
    649653                                addId( dwt, handleConflicts, expr );
    650654                                if ( dwt->name == "" ) {
    651                                         const Type * t = dwt->get_type()->stripReferences();
    652                                         if ( dynamic_cast<const StructInstType *>( t ) || dynamic_cast<const UnionInstType *>( t ) ) {
     655                                        Type * t = dwt->get_type()->stripReferences();
     656                                        if ( dynamic_cast<StructInstType*>( t ) || dynamic_cast<UnionInstType*>( t ) ) {
    653657                                                Expression * base = expr->clone();
    654658                                                ResolvExpr::Cost cost = ResolvExpr::Cost::zero; // xxx - carry this cost into the indexer as a base cost?
     
    661665        }
    662666
    663         void Indexer::addWith( const std::list< Expression * > & withExprs, const Declaration * withStmt ) {
    664                 for ( const Expression * expr : withExprs ) {
     667        void Indexer::addWith( std::list< Expression * > & withExprs, BaseSyntaxNode * withStmt ) {
     668                for ( Expression * expr : withExprs ) {
    665669                        if ( expr->result ) {
    666670                                AggregateDecl * aggr = expr->result->stripReferences()->getAggr();
     
    685689        }
    686690
    687         void Indexer::addFunctionType( const FunctionType * ftype ) {
     691        void Indexer::addFunctionType( FunctionType * ftype ) {
    688692                addTypes( ftype->forall );
    689693                addIds( ftype->returnVals );
     
    696700                        Expression * base = baseExpr->clone();
    697701                        ResolvExpr::referenceToRvalueConversion( base, cost );
    698                         ret = new MemberExpr( const_cast<DeclarationWithType *>(id), base );
     702                        ret = new MemberExpr( id, base );
    699703                        // xxx - this introduces hidden environments, for now remove them.
    700704                        // std::swap( base->env, ret->env );
     
    702706                        base->env = nullptr;
    703707                } else {
    704                         ret = new VariableExpr( const_cast<DeclarationWithType *>(id) );
    705                 }
    706                 if ( deleteStmt ) ret = new DeletedExpr( ret, const_cast<Declaration *>(deleteStmt) );
     708                        ret = new VariableExpr( id );
     709                }
     710                if ( deleteStmt ) ret = new DeletedExpr( ret, deleteStmt );
    707711                return ret;
    708712        }
Note: See TracChangeset for help on using the changeset viewer.