Changes in src/SymTab/Indexer.cc [ac57659:5fe35d6]
- File:
-
- 1 edited
-
src/SymTab/Indexer.cc (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Indexer.cc
rac57659 r5fe35d6 40 40 41 41 namespace 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; 47 43 typedef std::unordered_map< std::string, MangleTable > IdTable; 48 44 typedef std::unordered_map< std::string, NamedTypeDecl* > TypeTable; … … 101 97 } 102 98 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 { 104 100 // only need to perform this step for constructors, destructors, and assignment functions 105 101 if ( ! CodeGen::isCtorDtorAssign( id ) ) return; … … 108 104 struct ValueType { 109 105 struct DeclBall { 110 IdDatadecl;106 FunctionDecl * decl; 111 107 bool isUserDefinedFunc; // properties for this particular decl 112 108 bool isDefaultCtor; … … 124 120 // another FunctionDecl for the current type was found - determine 125 121 // 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 ) { 128 123 bool isUserDefinedFunc = ! LinkageSpec::isOverridable( function->get_linkage() ); 129 124 bool isDefaultCtor = InitTweak::isDefaultConstructor( function ); 130 125 bool isDtor = InitTweak::isDestructor( function ); 131 126 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 } ); 133 128 existsUserDefinedFunc = existsUserDefinedFunc || isUserDefinedFunc; 134 129 existsUserDefinedCtor = existsUserDefinedCtor || (isUserDefinedFunc && CodeGen::isConstructor( function->get_name() ) ); … … 140 135 }; // ValueType 141 136 142 std::list< IdData> copy;137 std::list< DeclarationWithType * > copy; 143 138 copy.splice( copy.end(), out ); 144 139 145 140 // organize discovered declarations by type 146 141 std::unordered_map< std::string, ValueType > funcMap; 147 for ( autodecl : copy ) {148 if ( FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl .id) ) {142 for ( DeclarationWithType * decl : copy ) { 143 if ( FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl ) ) { 149 144 std::list< DeclarationWithType * > & params = function->get_functionType()->get_parameters(); 150 145 assert( ! params.empty() ); … … 152 147 Type * base = InitTweak::getPointerBase( params.front()->get_type() ); 153 148 assert( base ); 154 funcMap[ Mangler::mangle( base ) ] += decl;149 funcMap[ Mangler::mangle( base ) ] += function; 155 150 } else { 156 151 out.push_back( decl ); … … 169 164 bool noUserDefinedFunc = ! val.existsUserDefinedFunc; 170 165 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 overrides166 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 172 167 bool isAcceptableCopyFunc = ! val.existsUserDefinedCopyFunc && ball.isCopyFunc; // handles copy ctor and assignment operator 173 168 bool isAcceptableDtor = ! val.existsUserDefinedDtor && ball.isDtor; … … 224 219 } 225 220 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 { 227 222 std::unordered_set< std::string > foundMangleNames; 228 223 … … 294 289 const MangleTable &mangleTable = decls->second; 295 290 MangleTable::const_iterator decl = mangleTable.find( mangleName ); 296 if ( decl != mangleTable.end() ) return decl->second .id;291 if ( decl != mangleTable.end() ) return decl->second; 297 292 } 298 293 … … 309 304 for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) { 310 305 // 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; 312 307 } 313 308 } … … 326 321 // check for C decls with the same name, skipping 327 322 // 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; 329 324 } 330 325 } … … 408 403 } 409 404 410 void Indexer::addId( DeclarationWithType *decl , Expression * baseExpr) {405 void Indexer::addId( DeclarationWithType *decl ) { 411 406 debugPrint( "Adding Id " << decl->name << std::endl ); 412 407 makeWritable(); … … 444 439 445 440 // add to indexer 446 tables->idTable[ name ][ mangleName ] = { decl, baseExpr };441 tables->idTable[ name ][ mangleName ] = decl; 447 442 ++tables->size; 448 443 } … … 568 563 if ( ! addedDeclConflicts( existing->second, decl ) ) { 569 564 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 }585 565 } 586 566 } … … 665 645 666 646 } 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 }682 647 } // namespace SymTab 683 648
Note:
See TracChangeset
for help on using the changeset viewer.