Changeset 5447e09
- Timestamp:
- Mar 22, 2016, 12:48:17 PM (9 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:
- 6c91065
- Parents:
- ae357ec
- Location:
- src/SymTab
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Indexer.cc
rae357ec r5447e09 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; 604 // TODO the first branch of this if is a bug-for-bug replication of Richard's code; 605 // it can allow C decls to hide CFA decls when they shouldn't, but the current prelude 606 // depends on this bug to build ... <stdlib>'s random() should be fixed to *not* hide 607 // <stdlib.h>'s random() before this first branch is taken out again 594 608 if ( decl->get_linkage() == LinkageSpec::C ) { 595 609 mangleName = name; … … 605 619 if ( ! existing || ! addedIdConflicts( existing, decl ) ) { 606 620 // 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 ) ) {621 if ( decl->get_linkage() == LinkageSpec::C && hasIncompatibleCDecl( name, mangleName ) ) { 608 622 throw SemanticError( "invalid overload of C function ", decl ); 609 } 623 } // NOTE this is broken in Richard's original code in such a way that it never triggers (it 624 // doesn't check decls that have the same manglename, and all C-linkage decls are defined to 625 // have their name as their manglename, hence the error can never trigger). 626 // The elided code here is closer to correct, but name mangling would have to be completely 627 // isomorphic to C type-compatibility, which it may not be. 610 628 611 629 tables->idTable[ name ][ mangleName ] = decl; -
src/SymTab/Indexer.h
rae357ec r5447e09 97 97 /// looks up a specific mangled ID at the given scope 98 98 DeclarationWithType *lookupIdAtScope( const std::string &id, const std::string &mangleName, unsigned long scope ) const; 99 /// returns true if there exists a declaration with C linkage and the given name 100 bool has CDeclWithName( const std::string &id) const;99 /// returns true if there exists a declaration with C linkage and the given name with a different mangled name 100 bool hasIncompatibleCDecl( const std::string &id, const std::string &mangleName ) const; 101 101 // equivalents to lookup functions that only look at tables at scope `scope` (which should be >= tables->scope) 102 102 NamedTypeDecl *lookupTypeAtScope( const std::string &id, unsigned long scope ) const;
Note: See TracChangeset
for help on using the changeset viewer.