Changeset a40d503 for src/SymTab/Indexer.cc
- Timestamp:
- Dec 1, 2017, 5:12:03 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- e4bc986
- Parents:
- 3ca540f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Indexer.cc
r3ca540f ra40d503 40 40 41 41 namespace SymTab { 42 typedef std::unordered_map< std::string, DeclarationWithType* > MangleTable; 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; 43 47 typedef std::unordered_map< std::string, MangleTable > IdTable; 44 48 typedef std::unordered_map< std::string, NamedTypeDecl* > TypeTable; … … 97 101 } 98 102 99 void Indexer::removeSpecialOverrides( const std::string &id, std::list< DeclarationWithType *> & out ) const {103 void Indexer::removeSpecialOverrides( const std::string &id, std::list< IdData > & out ) const { 100 104 // only need to perform this step for constructors, destructors, and assignment functions 101 105 if ( ! CodeGen::isCtorDtorAssign( id ) ) return; … … 104 108 struct ValueType { 105 109 struct DeclBall { 106 FunctionDecl *decl;110 IdData decl; 107 111 bool isUserDefinedFunc; // properties for this particular decl 108 112 bool isDefaultCtor; … … 120 124 // another FunctionDecl for the current type was found - determine 121 125 // if it has special properties and update data structure accordingly 122 ValueType & operator+=( FunctionDecl * function ) { 126 ValueType & operator+=( IdData data ) { 127 DeclarationWithType * function = data.id; 123 128 bool isUserDefinedFunc = ! LinkageSpec::isOverridable( function->get_linkage() ); 124 129 bool isDefaultCtor = InitTweak::isDefaultConstructor( function ); 125 130 bool isDtor = InitTweak::isDestructor( function ); 126 131 bool isCopyFunc = InitTweak::isCopyFunction( function, function->get_name() ); 127 decls.push_back( DeclBall{ function, isUserDefinedFunc, isDefaultCtor, isDtor, isCopyFunc } );132 decls.push_back( DeclBall{ data, isUserDefinedFunc, isDefaultCtor, isDtor, isCopyFunc } ); 128 133 existsUserDefinedFunc = existsUserDefinedFunc || isUserDefinedFunc; 129 134 existsUserDefinedCtor = existsUserDefinedCtor || (isUserDefinedFunc && CodeGen::isConstructor( function->get_name() ) ); … … 135 140 }; // ValueType 136 141 137 std::list< DeclarationWithType *> copy;142 std::list< IdData > copy; 138 143 copy.splice( copy.end(), out ); 139 144 140 145 // organize discovered declarations by type 141 146 std::unordered_map< std::string, ValueType > funcMap; 142 for ( DeclarationWithType *decl : copy ) {143 if ( FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl ) ) {147 for ( auto decl : copy ) { 148 if ( FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl.id ) ) { 144 149 std::list< DeclarationWithType * > & params = function->get_functionType()->get_parameters(); 145 150 assert( ! params.empty() ); … … 147 152 Type * base = InitTweak::getPointerBase( params.front()->get_type() ); 148 153 assert( base ); 149 funcMap[ Mangler::mangle( base ) ] += function;154 funcMap[ Mangler::mangle( base ) ] += decl; 150 155 } else { 151 156 out.push_back( decl ); … … 164 169 bool noUserDefinedFunc = ! val.existsUserDefinedFunc; 165 170 bool isUserDefinedFunc = ball.isUserDefinedFunc; 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 overrides171 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 167 172 bool isAcceptableCopyFunc = ! val.existsUserDefinedCopyFunc && ball.isCopyFunc; // handles copy ctor and assignment operator 168 173 bool isAcceptableDtor = ! val.existsUserDefinedDtor && ball.isDtor; … … 219 224 } 220 225 221 void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType*> &out ) const {226 void Indexer::lookupId( const std::string &id, std::list< IdData > &out ) const { 222 227 std::unordered_set< std::string > foundMangleNames; 223 228 … … 289 294 const MangleTable &mangleTable = decls->second; 290 295 MangleTable::const_iterator decl = mangleTable.find( mangleName ); 291 if ( decl != mangleTable.end() ) return decl->second ;296 if ( decl != mangleTable.end() ) return decl->second.id; 292 297 } 293 298 … … 304 309 for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) { 305 310 // check for C decls with the same name, skipping those with a compatible type (by mangleName) 306 if ( ! LinkageSpec::isMangled( decl->second ->get_linkage() ) && decl->first != mangleName ) return true;311 if ( ! LinkageSpec::isMangled( decl->second.id->get_linkage() ) && decl->first != mangleName ) return true; 307 312 } 308 313 } … … 321 326 // check for C decls with the same name, skipping 322 327 // those with an incompatible type (by mangleName) 323 if ( ! LinkageSpec::isMangled( decl->second ->get_linkage() ) && decl->first == mangleName ) return true;328 if ( ! LinkageSpec::isMangled( decl->second.id->get_linkage() ) && decl->first == mangleName ) return true; 324 329 } 325 330 } … … 403 408 } 404 409 405 void Indexer::addId( DeclarationWithType *decl ) {410 void Indexer::addId( DeclarationWithType *decl, Expression * baseExpr ) { 406 411 debugPrint( "Adding Id " << decl->name << std::endl ); 407 412 makeWritable(); … … 439 444 440 445 // add to indexer 441 tables->idTable[ name ][ mangleName ] = decl;446 tables->idTable[ name ][ mangleName ] = { decl, baseExpr }; 442 447 ++tables->size; 443 448 } … … 573 578 assertf( aggr, "WithStmt expr has non-aggregate type: %s", toString( expr->result ).c_str() ); 574 579 575 // xxx - this is wrong, needs to somehow hook up chain of objects576 580 for ( Declaration * decl : aggr->members ) { 577 581 if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) { 578 addId( dwt );582 addId( dwt, expr ); 579 583 } 580 584 } … … 661 665 662 666 } 667 668 Expression * Indexer::IdData::combine() const { 669 if ( baseExpr ) { 670 Expression * base = baseExpr->clone(); 671 Expression * ret = new MemberExpr( id, base ); 672 // xxx - this introduces hidden environments, for now remove them. 673 // std::swap( base->env, ret->env ); 674 delete base->env; 675 base->env = nullptr; 676 return ret; 677 } else { 678 return new VariableExpr( id ); 679 } 680 } 663 681 } // namespace SymTab 664 682
Note: See TracChangeset
for help on using the changeset viewer.