Changeset b3f9a0cb for src/SymTab/Indexer.cc
- Timestamp:
- Apr 4, 2016, 1:18:17 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- afc1045
- Parents:
- 89173242 (diff), 3cfe27f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
src/SymTab/Indexer.cc (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Indexer.cc
r89173242 rb3f9a0cb 19 19 #include <typeinfo> 20 20 #include <unordered_map> 21 #include <unordered_set> 21 22 #include <utility> 22 23 … … 435 436 436 437 void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &out ) const { 437 if ( ! tables ) return; 438 439 IdTable::const_iterator decls = tables->idTable.find( id ); 440 if ( decls != tables->idTable.end() ) { 441 const MangleTable &mangleTable = decls->second; 442 for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) { 443 out.push_back( decl->second ); 444 } 445 } 438 std::unordered_set< std::string > foundMangleNames; 446 439 447 // get declarations from base indexers 448 tables->base.lookupId( id, out ); 440 Indexer::Impl *searchTables = tables; 441 while ( searchTables ) { 442 443 IdTable::const_iterator decls = searchTables->idTable.find( id ); 444 if ( decls != searchTables->idTable.end() ) { 445 const MangleTable &mangleTable = decls->second; 446 for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) { 447 // mark the mangled name as found, skipping this insertion if a declaration for that name has already been found 448 if ( foundMangleNames.insert( decl->first ).second == false ) continue; 449 450 out.push_back( decl->second ); 451 } 452 } 453 454 // get declarations from base indexers 455 searchTables = searchTables->base.tables; 456 } 449 457 } 450 458 … … 498 506 } 499 507 500 bool Indexer::has CDeclWithName( const std::string &id) const {508 bool Indexer::hasIncompatibleCDecl( const std::string &id, const std::string &mangleName ) const { 501 509 if ( ! tables ) return false; 502 510 … … 505 513 const MangleTable &mangleTable = decls->second; 506 514 for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) { 507 if ( decl->second->get_linkage() == LinkageSpec::C ) return true; 508 } 509 } 510 511 return tables->base.hasCDeclWithName( id ); 515 // check for C decls with the same name, skipping 516 // those with a compatible type (by mangleName) 517 if ( decl->second->get_linkage() == LinkageSpec::C && decl->first != mangleName ) return true; 518 } 519 } 520 521 return tables->base.hasIncompatibleCDecl( id, mangleName ); 512 522 } 513 523 … … 592 602 const std::string &name = decl->get_name(); 593 603 std::string mangleName; 594 if ( decl->get_linkage() == LinkageSpec::C ) { 595 mangleName = name; 596 } else if ( LinkageSpec::isOverridable( decl->get_linkage() ) ) { 604 if ( LinkageSpec::isOverridable( decl->get_linkage() ) ) { 597 605 // mangle the name without including the appropriate suffix, so overridable routines are placed into the 598 606 // same "bucket" as their user defined versions. … … 605 613 if ( ! existing || ! addedIdConflicts( existing, decl ) ) { 606 614 // this ensures that no two declarations with the same unmangled name both have C linkage 607 if ( decl->get_linkage() == LinkageSpec::C && has CDeclWithName( name ) ) {615 if ( decl->get_linkage() == LinkageSpec::C && hasIncompatibleCDecl( name, mangleName ) ) { 608 616 throw SemanticError( "invalid overload of C function ", decl ); 609 } 617 } // NOTE this is broken in Richard's original code in such a way that it never triggers (it 618 // doesn't check decls that have the same manglename, and all C-linkage decls are defined to 619 // have their name as their manglename, hence the error can never trigger). 620 // The code here is closer to correct, but name mangling would have to be completely 621 // isomorphic to C type-compatibility, which it may not be. 610 622 611 623 tables->idTable[ name ][ mangleName ] = decl;
Note:
See TracChangeset
for help on using the changeset viewer.