Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Indexer.cc

    rac57659 r5fe35d6  
    4040
    4141namespace SymTab {
    42         std::ostream & operator<<( std::ostream & out, const Indexer::IdData & data ) {
    43                 return out << "(" << data.id << "," << data.baseExpr << ")";
    44         }
    45 
    46         typedef std::unordered_map< std::string, Indexer::IdData > MangleTable;
     42        typedef std::unordered_map< std::string, DeclarationWithType* > MangleTable;
    4743        typedef std::unordered_map< std::string, MangleTable > IdTable;
    4844        typedef std::unordered_map< std::string, NamedTypeDecl* > TypeTable;
     
    10197        }
    10298
    103         void Indexer::removeSpecialOverrides( const std::string &id, std::list< IdData > & out ) const {
     99        void Indexer::removeSpecialOverrides( const std::string &id, std::list< DeclarationWithType * > & out ) const {
    104100                // only need to perform this step for constructors, destructors, and assignment functions
    105101                if ( ! CodeGen::isCtorDtorAssign( id ) ) return;
     
    108104                struct ValueType {
    109105                        struct DeclBall {
    110                                 IdData decl;
     106                                FunctionDecl * decl;
    111107                                bool isUserDefinedFunc; // properties for this particular decl
    112108                                bool isDefaultCtor;
     
    124120                        // another FunctionDecl for the current type was found - determine
    125121                        // if it has special properties and update data structure accordingly
    126                         ValueType & operator+=( IdData data ) {
    127                                 DeclarationWithType * function = data.id;
     122                        ValueType & operator+=( FunctionDecl * function ) {
    128123                                bool isUserDefinedFunc = ! LinkageSpec::isOverridable( function->get_linkage() );
    129124                                bool isDefaultCtor = InitTweak::isDefaultConstructor( function );
    130125                                bool isDtor = InitTweak::isDestructor( function );
    131126                                bool isCopyFunc = InitTweak::isCopyFunction( function, function->get_name() );
    132                                 decls.push_back( DeclBall{ data, isUserDefinedFunc, isDefaultCtor, isDtor, isCopyFunc } );
     127                                decls.push_back( DeclBall{ function, isUserDefinedFunc, isDefaultCtor, isDtor, isCopyFunc } );
    133128                                existsUserDefinedFunc = existsUserDefinedFunc || isUserDefinedFunc;
    134129                                existsUserDefinedCtor = existsUserDefinedCtor || (isUserDefinedFunc && CodeGen::isConstructor( function->get_name() ) );
     
    140135                }; // ValueType
    141136
    142                 std::list< IdData > copy;
     137                std::list< DeclarationWithType * > copy;
    143138                copy.splice( copy.end(), out );
    144139
    145140                // organize discovered declarations by type
    146141                std::unordered_map< std::string, ValueType > funcMap;
    147                 for ( auto decl : copy ) {
    148                         if ( FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl.id ) ) {
     142                for ( DeclarationWithType * decl : copy ) {
     143                        if ( FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl ) ) {
    149144                                std::list< DeclarationWithType * > & params = function->get_functionType()->get_parameters();
    150145                                assert( ! params.empty() );
     
    152147                                Type * base = InitTweak::getPointerBase( params.front()->get_type() );
    153148                                assert( base );
    154                                 funcMap[ Mangler::mangle( base ) ] += decl;
     149                                funcMap[ Mangler::mangle( base ) ] += function;
    155150                        } else {
    156151                                out.push_back( decl );
     
    169164                                bool noUserDefinedFunc = ! val.existsUserDefinedFunc;
    170165                                bool isUserDefinedFunc = ball.isUserDefinedFunc;
    171                                 bool isAcceptableDefaultCtor = (! val.existsUserDefinedCtor || (! val.existsUserDefinedDefaultCtor && ball.decl.id->get_linkage() == LinkageSpec::Intrinsic)) && ball.isDefaultCtor; // allow default constructors only when no user-defined constructors exist, except in the case of intrinsics, which require exact overrides
     166                                bool isAcceptableDefaultCtor = (! val.existsUserDefinedCtor || (! val.existsUserDefinedDefaultCtor && ball.decl->get_linkage() == LinkageSpec::Intrinsic)) && ball.isDefaultCtor; // allow default constructors only when no user-defined constructors exist, except in the case of intrinsics, which require exact overrides
    172167                                bool isAcceptableCopyFunc = ! val.existsUserDefinedCopyFunc && ball.isCopyFunc; // handles copy ctor and assignment operator
    173168                                bool isAcceptableDtor = ! val.existsUserDefinedDtor && ball.isDtor;
     
    224219        }
    225220
    226         void Indexer::lookupId( const std::string &id, std::list< IdData > &out ) const {
     221        void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &out ) const {
    227222                std::unordered_set< std::string > foundMangleNames;
    228223
     
    294289                        const MangleTable &mangleTable = decls->second;
    295290                        MangleTable::const_iterator decl = mangleTable.find( mangleName );
    296                         if ( decl != mangleTable.end() ) return decl->second.id;
     291                        if ( decl != mangleTable.end() ) return decl->second;
    297292                }
    298293
     
    309304                        for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) {
    310305                                // check for C decls with the same name, skipping those with a compatible type (by mangleName)
    311                                 if ( ! LinkageSpec::isMangled( decl->second.id->get_linkage() ) && decl->first != mangleName ) return true;
     306                                if ( ! LinkageSpec::isMangled( decl->second->get_linkage() ) && decl->first != mangleName ) return true;
    312307                        }
    313308                }
     
    326321                                // check for C decls with the same name, skipping
    327322                                // those with an incompatible type (by mangleName)
    328                                 if ( ! LinkageSpec::isMangled( decl->second.id->get_linkage() ) && decl->first == mangleName ) return true;
     323                                if ( ! LinkageSpec::isMangled( decl->second->get_linkage() ) && decl->first == mangleName ) return true;
    329324                        }
    330325                }
     
    408403        }
    409404
    410         void Indexer::addId( DeclarationWithType *decl, Expression * baseExpr ) {
     405        void Indexer::addId( DeclarationWithType *decl ) {
    411406                debugPrint( "Adding Id " << decl->name << std::endl );
    412407                makeWritable();
     
    444439
    445440                // add to indexer
    446                 tables->idTable[ name ][ mangleName ] = { decl, baseExpr };
     441                tables->idTable[ name ][ mangleName ] = decl;
    447442                ++tables->size;
    448443        }
     
    568563                        if ( ! addedDeclConflicts( existing->second, decl ) ) {
    569564                                existing->second = decl;
    570                         }
    571                 }
    572         }
    573 
    574         void Indexer::addWith( WithStmt * stmt ) {
    575                 for ( Expression * expr : stmt->exprs ) {
    576                         if ( expr->result ) {
    577                                 AggregateDecl * aggr = expr->result->stripReferences()->getAggr();
    578                                 assertf( aggr, "WithStmt expr has non-aggregate type: %s", toString( expr->result ).c_str() );
    579 
    580                                 for ( Declaration * decl : aggr->members ) {
    581                                         if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
    582                                                 addId( dwt, expr );
    583                                         }
    584                                 }
    585565                        }
    586566                }
     
    665645
    666646        }
    667 
    668         Expression * Indexer::IdData::combine() const {
    669                 if ( baseExpr ) {
    670                         Expression * base = baseExpr->clone();
    671                         ResolvExpr::referenceToRvalueConversion( base );
    672                         Expression * ret = new MemberExpr( id, base );
    673                         // xxx - this introduces hidden environments, for now remove them.
    674                         // std::swap( base->env, ret->env );
    675                         delete base->env;
    676                         base->env = nullptr;
    677                         return ret;
    678                 } else {
    679                         return new VariableExpr( id );
    680                 }
    681         }
    682647} // namespace SymTab
    683648
Note: See TracChangeset for help on using the changeset viewer.