Changes in src/SymTab/Indexer.cc [743fbda:afc1045]
- File:
-
- 1 edited
-
src/SymTab/Indexer.cc (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Indexer.cc
r743fbda rafc1045 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 : Rob Schluntz12 // Last Modified On : Fri Apr 22 15:25:43201611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 2 17:31:29 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 // needs to be on the heap because addStruct saves the pointer 216 StructDecl &fwdDecl = *new StructDecl( aggregateDecl->get_name() ); 215 StructDecl fwdDecl( aggregateDecl->get_name() ); 217 216 cloneAll( aggregateDecl->get_parameters(), fwdDecl.get_parameters() ); 218 217 debugPrint( "Adding fwd decl for struct " << fwdDecl.get_name() << std::endl ); 219 218 addStruct( &fwdDecl ); 220 219 221 220 enterScope(); 222 221 acceptAll( aggregateDecl->get_parameters(), *this ); 223 222 acceptAll( aggregateDecl->get_members(), *this ); 224 223 leaveScope(); 225 224 226 225 debugPrint( "Adding struct " << aggregateDecl->get_name() << std::endl ); 227 226 // this addition replaces the forward declaration … … 235 234 debugPrint( "Adding fwd decl for union " << fwdDecl.get_name() << std::endl ); 236 235 addUnion( &fwdDecl ); 237 236 238 237 enterScope(); 239 238 acceptAll( aggregateDecl->get_parameters(), *this ); 240 239 acceptAll( aggregateDecl->get_members(), *this ); 241 240 leaveScope(); 242 241 243 242 debugPrint( "Adding union " << aggregateDecl->get_name() << std::endl ); 244 243 addUnion( aggregateDecl ); … … 257 256 acceptAll( aggregateDecl->get_members(), *this ); 258 257 leaveScope(); 259 258 260 259 debugPrint( "Adding context " << aggregateDecl->get_name() << std::endl ); 261 260 addTrait( aggregateDecl ); … … 439 438 } 440 439 441 440 442 441 443 442 void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &out ) const { 444 443 std::unordered_set< std::string > foundMangleNames; 445 444 446 445 Indexer::Impl *searchTables = tables; 447 446 while ( searchTables ) { … … 453 452 // mark the mangled name as found, skipping this insertion if a declaration for that name has already been found 454 453 if ( foundMangleNames.insert( decl->first ).second == false ) continue; 455 454 456 455 out.push_back( decl->second ); 457 456 } 458 457 } 459 458 460 459 // get declarations from base indexers 461 460 searchTables = searchTables->base.tables; … … 512 511 } 513 512 514 bool Indexer::hasIncompatibleCDecl( const std::string &id, const std::string &mangleName , unsigned long scope) const {513 bool Indexer::hasIncompatibleCDecl( const std::string &id, const std::string &mangleName ) const { 515 514 if ( ! tables ) return false; 516 if ( tables->scope < scope ) return false;517 515 518 516 IdTable::const_iterator decls = tables->idTable.find( id ); … … 520 518 const MangleTable &mangleTable = decls->second; 521 519 for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) { 522 // check for C decls with the same name, skipping 520 // check for C decls with the same name, skipping 523 521 // those with a compatible type (by mangleName) 524 522 if ( decl->second->get_linkage() == LinkageSpec::C && decl->first != mangleName ) return true; … … 526 524 } 527 525 528 return tables->base.hasIncompatibleCDecl( id, mangleName , scope);529 } 530 526 return tables->base.hasIncompatibleCDecl( id, mangleName ); 527 } 528 531 529 NamedTypeDecl *Indexer::lookupTypeAtScope( const std::string &id, unsigned long scope ) const { 532 530 if ( ! tables ) return 0; … … 536 534 return ret != tables->typeTable.end() ? ret->second : tables->base.lookupTypeAtScope( id, scope ); 537 535 } 538 536 539 537 StructDecl *Indexer::lookupStructAtScope( const std::string &id, unsigned long scope ) const { 540 538 if ( ! tables ) return 0; … … 544 542 return ret != tables->structTable.end() ? ret->second : tables->base.lookupStructAtScope( id, scope ); 545 543 } 546 544 547 545 EnumDecl *Indexer::lookupEnumAtScope( const std::string &id, unsigned long scope ) const { 548 546 if ( ! tables ) return 0; … … 552 550 return ret != tables->enumTable.end() ? ret->second : tables->base.lookupEnumAtScope( id, scope ); 553 551 } 554 552 555 553 UnionDecl *Indexer::lookupUnionAtScope( const std::string &id, unsigned long scope ) const { 556 554 if ( ! tables ) return 0; … … 560 558 return ret != tables->unionTable.end() ? ret->second : tables->base.lookupUnionAtScope( id, scope ); 561 559 } 562 560 563 561 TraitDecl *Indexer::lookupTraitAtScope( const std::string &id, unsigned long scope ) const { 564 562 if ( ! tables ) return 0; … … 603 601 return true; 604 602 } 605 603 606 604 void Indexer::addId( DeclarationWithType *decl ) { 607 605 makeWritable(); … … 619 617 DeclarationWithType *existing = lookupIdAtScope( name, mangleName, scope ); 620 618 if ( ! existing || ! addedIdConflicts( existing, decl ) ) { 621 // this ensures that no two declarations with the same unmangled name at the same scopeboth have C linkage622 if ( decl->get_linkage() == LinkageSpec::C && hasIncompatibleCDecl( name, mangleName , scope) ) {619 // this ensures that no two declarations with the same unmangled name both have C linkage 620 if ( decl->get_linkage() == LinkageSpec::C && hasIncompatibleCDecl( name, mangleName ) ) { 623 621 throw SemanticError( "invalid overload of C function ", decl ); 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 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 626 624 // have their name as their manglename, hence the error can never trigger). 627 // The code here is closer to correct, but name mangling would have to be completely 625 // The code here is closer to correct, but name mangling would have to be completely 628 626 // isomorphic to C type-compatibility, which it may not be. 629 627 630 628 tables->idTable[ name ][ mangleName ] = decl; 631 629 ++tables->size; … … 642 640 } 643 641 } 644 642 645 643 void Indexer::addType( NamedTypeDecl *decl ) { 646 644 makeWritable(); … … 673 671 addStruct( new StructDecl( id ) ); 674 672 } 675 673 676 674 void Indexer::addStruct( StructDecl *decl ) { 677 675 makeWritable(); … … 691 689 } 692 690 } 693 691 694 692 void Indexer::addEnum( EnumDecl *decl ) { 695 693 makeWritable(); … … 713 711 addUnion( new UnionDecl( id ) ); 714 712 } 715 713 716 714 void Indexer::addUnion( UnionDecl *decl ) { 717 715 makeWritable(); … … 731 729 } 732 730 } 733 731 734 732 void Indexer::addTrait( TraitDecl *decl ) { 735 733 makeWritable(); … … 752 750 void Indexer::enterScope() { 753 751 ++scope; 754 752 755 753 if ( doDebug ) { 756 754 std::cout << "--- Entering scope " << scope << std::endl; … … 785 783 using std::cerr; 786 784 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 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 ); 808 797 } 809 798 } // namespace SymTab
Note:
See TracChangeset
for help on using the changeset viewer.