Changeset f80e0218 for src/SymTab/Indexer.cc
- Timestamp:
- Jun 30, 2016, 4:32:56 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, with_gc
- Children:
- ea29e73
- Parents:
- 1b5c81ed (diff), 84d4d6f (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) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Indexer.cc
r1b5c81ed rf80e0218 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Indexer.cc -- 7 // Indexer.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 21:37:33 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Wed Mar 2 17:31:29201611 // Last Modified By : Rob Schluntz 12 // Last Modified On : Fri Apr 22 15:25:43 2016 13 13 // Update Count : 11 14 14 // … … 59 59 } 60 60 } 61 61 62 62 template< typename Decl > 63 63 void dump( const std::unordered_map< std::string, Decl* > &table, std::ostream &os ) { … … 66 66 } // for 67 67 } 68 68 69 69 struct Indexer::Impl { 70 70 Impl( unsigned long _scope ) : refCount(1), scope( _scope ), size( 0 ), base(), … … 76 76 unsigned long size; ///< Number of elements stored in this table 77 77 const Indexer base; ///< Base indexer this extends 78 78 79 79 IdTable idTable; ///< Identifier namespace 80 80 TypeTable typeTable; ///< Type namespace … … 213 213 void Indexer::visit( StructDecl *aggregateDecl ) { 214 214 // make up a forward declaration and add it before processing the members 215 StructDecl fwdDecl( aggregateDecl->get_name() ); 215 // needs to be on the heap because addStruct saves the pointer 216 StructDecl &fwdDecl = *new StructDecl( aggregateDecl->get_name() ); 216 217 cloneAll( aggregateDecl->get_parameters(), fwdDecl.get_parameters() ); 217 218 debugPrint( "Adding fwd decl for struct " << fwdDecl.get_name() << std::endl ); 218 219 addStruct( &fwdDecl ); 219 220 220 221 enterScope(); 221 222 acceptAll( aggregateDecl->get_parameters(), *this ); 222 223 acceptAll( aggregateDecl->get_members(), *this ); 223 224 leaveScope(); 224 225 225 226 debugPrint( "Adding struct " << aggregateDecl->get_name() << std::endl ); 226 227 // this addition replaces the forward declaration … … 234 235 debugPrint( "Adding fwd decl for union " << fwdDecl.get_name() << std::endl ); 235 236 addUnion( &fwdDecl ); 236 237 237 238 enterScope(); 238 239 acceptAll( aggregateDecl->get_parameters(), *this ); 239 240 acceptAll( aggregateDecl->get_members(), *this ); 240 241 leaveScope(); 241 242 242 243 debugPrint( "Adding union " << aggregateDecl->get_name() << std::endl ); 243 244 addUnion( aggregateDecl ); … … 256 257 acceptAll( aggregateDecl->get_members(), *this ); 257 258 leaveScope(); 258 259 259 260 debugPrint( "Adding context " << aggregateDecl->get_name() << std::endl ); 260 261 addTrait( aggregateDecl ); … … 438 439 } 439 440 440 441 441 442 442 443 void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &out ) const { 443 444 std::unordered_set< std::string > foundMangleNames; 444 445 445 446 Indexer::Impl *searchTables = tables; 446 447 while ( searchTables ) { … … 452 453 // mark the mangled name as found, skipping this insertion if a declaration for that name has already been found 453 454 if ( foundMangleNames.insert( decl->first ).second == false ) continue; 454 455 455 456 out.push_back( decl->second ); 456 457 } 457 458 } 458 459 459 460 // get declarations from base indexers 460 461 searchTables = searchTables->base.tables; … … 511 512 } 512 513 513 bool Indexer::hasIncompatibleCDecl( const std::string &id, const std::string &mangleName ) const {514 bool Indexer::hasIncompatibleCDecl( const std::string &id, const std::string &mangleName, unsigned long scope ) const { 514 515 if ( ! tables ) return false; 516 if ( tables->scope < scope ) return false; 515 517 516 518 IdTable::const_iterator decls = tables->idTable.find( id ); … … 518 520 const MangleTable &mangleTable = decls->second; 519 521 for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) { 520 // check for C decls with the same name, skipping 522 // check for C decls with the same name, skipping 521 523 // those with a compatible type (by mangleName) 522 524 if ( decl->second->get_linkage() == LinkageSpec::C && decl->first != mangleName ) return true; … … 524 526 } 525 527 526 return tables->base.hasIncompatibleCDecl( id, mangleName );527 } 528 528 return tables->base.hasIncompatibleCDecl( id, mangleName, scope ); 529 } 530 529 531 NamedTypeDecl *Indexer::lookupTypeAtScope( const std::string &id, unsigned long scope ) const { 530 532 if ( ! tables ) return 0; … … 534 536 return ret != tables->typeTable.end() ? ret->second : tables->base.lookupTypeAtScope( id, scope ); 535 537 } 536 538 537 539 StructDecl *Indexer::lookupStructAtScope( const std::string &id, unsigned long scope ) const { 538 540 if ( ! tables ) return 0; … … 542 544 return ret != tables->structTable.end() ? ret->second : tables->base.lookupStructAtScope( id, scope ); 543 545 } 544 546 545 547 EnumDecl *Indexer::lookupEnumAtScope( const std::string &id, unsigned long scope ) const { 546 548 if ( ! tables ) return 0; … … 550 552 return ret != tables->enumTable.end() ? ret->second : tables->base.lookupEnumAtScope( id, scope ); 551 553 } 552 554 553 555 UnionDecl *Indexer::lookupUnionAtScope( const std::string &id, unsigned long scope ) const { 554 556 if ( ! tables ) return 0; … … 558 560 return ret != tables->unionTable.end() ? ret->second : tables->base.lookupUnionAtScope( id, scope ); 559 561 } 560 562 561 563 TraitDecl *Indexer::lookupTraitAtScope( const std::string &id, unsigned long scope ) const { 562 564 if ( ! tables ) return 0; … … 601 603 return true; 602 604 } 603 605 604 606 void Indexer::addId( DeclarationWithType *decl ) { 605 607 makeWritable(); … … 617 619 DeclarationWithType *existing = lookupIdAtScope( name, mangleName, scope ); 618 620 if ( ! existing || ! addedIdConflicts( existing, decl ) ) { 619 // this ensures that no two declarations with the same unmangled name both have C linkage620 if ( decl->get_linkage() == LinkageSpec::C && hasIncompatibleCDecl( name, mangleName ) ) {621 // this ensures that no two declarations with the same unmangled name at the same scope both have C linkage 622 if ( decl->get_linkage() == LinkageSpec::C && hasIncompatibleCDecl( name, mangleName, scope ) ) { 621 623 throw SemanticError( "invalid overload of C function ", decl ); 622 } // NOTE this is broken in Richard's original code in such a way that it never triggers (it 623 // doesn't check decls that have the same manglename, and all C-linkage decls are defined to 624 } // NOTE this is broken in Richard's original code in such a way that it never triggers (it 625 // doesn't check decls that have the same manglename, and all C-linkage decls are defined to 624 626 // have their name as their manglename, hence the error can never trigger). 625 // The code here is closer to correct, but name mangling would have to be completely 627 // The code here is closer to correct, but name mangling would have to be completely 626 628 // isomorphic to C type-compatibility, which it may not be. 627 629 628 630 tables->idTable[ name ][ mangleName ] = decl; 629 631 ++tables->size; … … 640 642 } 641 643 } 642 644 643 645 void Indexer::addType( NamedTypeDecl *decl ) { 644 646 makeWritable(); … … 671 673 addStruct( new StructDecl( id ) ); 672 674 } 673 675 674 676 void Indexer::addStruct( StructDecl *decl ) { 675 677 makeWritable(); … … 689 691 } 690 692 } 691 693 692 694 void Indexer::addEnum( EnumDecl *decl ) { 693 695 makeWritable(); … … 711 713 addUnion( new UnionDecl( id ) ); 712 714 } 713 715 714 716 void Indexer::addUnion( UnionDecl *decl ) { 715 717 makeWritable(); … … 729 731 } 730 732 } 731 733 732 734 void Indexer::addTrait( TraitDecl *decl ) { 733 735 makeWritable(); … … 750 752 void Indexer::enterScope() { 751 753 ++scope; 752 754 753 755 if ( doDebug ) { 754 756 std::cout << "--- Entering scope " << scope << std::endl; … … 783 785 using std::cerr; 784 786 785 cerr << "===idTable===" << std::endl; 786 if ( tables ) dump( tables->idTable, os ); 787 cerr << "===typeTable===" << std::endl; 788 if ( tables ) dump( tables->typeTable, os ); 789 cerr << "===structTable===" << std::endl; 790 if ( tables ) dump( tables->structTable, os ); 791 cerr << "===enumTable===" << std::endl; 792 if ( tables ) dump( tables->enumTable, os ); 793 cerr << "===unionTable===" << std::endl; 794 if ( tables ) dump( tables->unionTable, os ); 795 cerr << "===contextTable===" << std::endl; 796 if ( tables ) dump( tables->traitTable, os ); 787 if ( tables ) { 788 os << "--- scope " << tables->scope << " ---" << std::endl; 789 790 os << "===idTable===" << std::endl; 791 dump( tables->idTable, os ); 792 os << "===typeTable===" << std::endl; 793 dump( tables->typeTable, os ); 794 os << "===structTable===" << std::endl; 795 dump( tables->structTable, os ); 796 os << "===enumTable===" << std::endl; 797 dump( tables->enumTable, os ); 798 os << "===unionTable===" << std::endl; 799 dump( tables->unionTable, os ); 800 os << "===contextTable===" << std::endl; 801 dump( tables->traitTable, os ); 802 803 tables->base.print( os, indent ); 804 } else { 805 os << "--- end ---" << std::endl; 806 } 807 797 808 } 798 809 } // namespace SymTab
Note:
See TracChangeset
for help on using the changeset viewer.