Ignore:
Timestamp:
May 2, 2016, 3:28:16 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
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:
1b7ea43
Parents:
1f6e009 (diff), e945826 (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.
Message:

Merge branch 'master' into global-init

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Indexer.cc

    r1f6e009 r1048b31  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Indexer.cc -- 
     7// Indexer.cc --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:37:33 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 17:31:29 2016
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Fri Apr 22 15:25:43 2016
    1313// Update Count     : 11
    1414//
     
    5959                }
    6060        }
    61        
     61
    6262        template< typename Decl >
    6363        void dump( const std::unordered_map< std::string, Decl* > &table, std::ostream &os ) {
     
    6666                } // for
    6767        }
    68        
     68
    6969        struct Indexer::Impl {
    7070                Impl( unsigned long _scope ) : refCount(1), scope( _scope ), size( 0 ), base(),
     
    7676                unsigned long size;       ///< Number of elements stored in this table
    7777                const Indexer base;       ///< Base indexer this extends
    78                
     78
    7979                IdTable idTable;          ///< Identifier namespace
    8080                TypeTable typeTable;      ///< Type namespace
     
    213213        void Indexer::visit( StructDecl *aggregateDecl ) {
    214214                // 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() );
    216217                cloneAll( aggregateDecl->get_parameters(), fwdDecl.get_parameters() );
    217218                debugPrint( "Adding fwd decl for struct " << fwdDecl.get_name() << std::endl );
    218219                addStruct( &fwdDecl );
    219  
     220
    220221                enterScope();
    221222                acceptAll( aggregateDecl->get_parameters(), *this );
    222223                acceptAll( aggregateDecl->get_members(), *this );
    223224                leaveScope();
    224  
     225
    225226                debugPrint( "Adding struct " << aggregateDecl->get_name() << std::endl );
    226227                // this addition replaces the forward declaration
     
    234235                debugPrint( "Adding fwd decl for union " << fwdDecl.get_name() << std::endl );
    235236                addUnion( &fwdDecl );
    236  
     237
    237238                enterScope();
    238239                acceptAll( aggregateDecl->get_parameters(), *this );
    239240                acceptAll( aggregateDecl->get_members(), *this );
    240241                leaveScope();
    241  
     242
    242243                debugPrint( "Adding union " << aggregateDecl->get_name() << std::endl );
    243244                addUnion( aggregateDecl );
     
    256257                acceptAll( aggregateDecl->get_members(), *this );
    257258                leaveScope();
    258  
     259
    259260                debugPrint( "Adding context " << aggregateDecl->get_name() << std::endl );
    260261                addTrait( aggregateDecl );
     
    344345                maybeAccept( offsetofExpr->get_type(), *this );
    345346                maybeAccept( offsetofExpr->get_member(), *this );
     347        }
     348
     349        void Indexer::visit( OffsetPackExpr *offsetPackExpr ) {
     350                acceptAllNewScope( offsetPackExpr->get_results(), *this );
     351                maybeAccept( offsetPackExpr->get_type(), *this );
    346352        }
    347353
     
    433439        }
    434440
    435        
     441
    436442
    437443        void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &out ) const {
    438444                std::unordered_set< std::string > foundMangleNames;
    439                
     445
    440446                Indexer::Impl *searchTables = tables;
    441447                while ( searchTables ) {
     
    447453                                        // mark the mangled name as found, skipping this insertion if a declaration for that name has already been found
    448454                                        if ( foundMangleNames.insert( decl->first ).second == false ) continue;
    449                                        
     455
    450456                                        out.push_back( decl->second );
    451457                                }
    452458                        }
    453                        
     459
    454460                        // get declarations from base indexers
    455461                        searchTables = searchTables->base.tables;
     
    506512        }
    507513
    508         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 {
    509515                if ( ! tables ) return false;
     516                if ( tables->scope < scope ) return false;
    510517
    511518                IdTable::const_iterator decls = tables->idTable.find( id );
     
    513520                        const MangleTable &mangleTable = decls->second;
    514521                        for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) {
    515                                 // check for C decls with the same name, skipping 
     522                                // check for C decls with the same name, skipping
    516523                                // those with a compatible type (by mangleName)
    517524                                if ( decl->second->get_linkage() == LinkageSpec::C && decl->first != mangleName ) return true;
     
    519526                }
    520527
    521                 return tables->base.hasIncompatibleCDecl( id, mangleName );
    522         }
    523        
     528                return tables->base.hasIncompatibleCDecl( id, mangleName, scope );
     529        }
     530
    524531        NamedTypeDecl *Indexer::lookupTypeAtScope( const std::string &id, unsigned long scope ) const {
    525532                if ( ! tables ) return 0;
     
    529536                return ret != tables->typeTable.end() ? ret->second : tables->base.lookupTypeAtScope( id, scope );
    530537        }
    531        
     538
    532539        StructDecl *Indexer::lookupStructAtScope( const std::string &id, unsigned long scope ) const {
    533540                if ( ! tables ) return 0;
     
    537544                return ret != tables->structTable.end() ? ret->second : tables->base.lookupStructAtScope( id, scope );
    538545        }
    539        
     546
    540547        EnumDecl *Indexer::lookupEnumAtScope( const std::string &id, unsigned long scope ) const {
    541548                if ( ! tables ) return 0;
     
    545552                return ret != tables->enumTable.end() ? ret->second : tables->base.lookupEnumAtScope( id, scope );
    546553        }
    547        
     554
    548555        UnionDecl *Indexer::lookupUnionAtScope( const std::string &id, unsigned long scope ) const {
    549556                if ( ! tables ) return 0;
     
    553560                return ret != tables->unionTable.end() ? ret->second : tables->base.lookupUnionAtScope( id, scope );
    554561        }
    555        
     562
    556563        TraitDecl *Indexer::lookupTraitAtScope( const std::string &id, unsigned long scope ) const {
    557564                if ( ! tables ) return 0;
     
    596603                return true;
    597604        }
    598        
     605
    599606        void Indexer::addId( DeclarationWithType *decl ) {
    600607                makeWritable();
     
    612619                DeclarationWithType *existing = lookupIdAtScope( name, mangleName, scope );
    613620                if ( ! existing || ! addedIdConflicts( existing, decl ) ) {
    614                         // this ensures that no two declarations with the same unmangled name both have C linkage
    615                         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 ) ) {
    616623                                throw SemanticError( "invalid overload of C function ", decl );
    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 
     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
    619626                          // 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 
     627                          // The code here is closer to correct, but name mangling would have to be completely
    621628                          // isomorphic to C type-compatibility, which it may not be.
    622                        
     629
    623630                        tables->idTable[ name ][ mangleName ] = decl;
    624631                        ++tables->size;
     
    635642                }
    636643        }
    637        
     644
    638645        void Indexer::addType( NamedTypeDecl *decl ) {
    639646                makeWritable();
     
    666673                addStruct( new StructDecl( id ) );
    667674        }
    668        
     675
    669676        void Indexer::addStruct( StructDecl *decl ) {
    670677                makeWritable();
     
    684691                }
    685692        }
    686        
     693
    687694        void Indexer::addEnum( EnumDecl *decl ) {
    688695                makeWritable();
     
    706713                addUnion( new UnionDecl( id ) );
    707714        }
    708        
     715
    709716        void Indexer::addUnion( UnionDecl *decl ) {
    710717                makeWritable();
     
    724731                }
    725732        }
    726        
     733
    727734        void Indexer::addTrait( TraitDecl *decl ) {
    728735                makeWritable();
     
    745752        void Indexer::enterScope() {
    746753                ++scope;
    747                
     754
    748755                if ( doDebug ) {
    749756                        std::cout << "--- Entering scope " << scope << std::endl;
     
    778785            using std::cerr;
    779786
    780             cerr << "===idTable===" << std::endl;
    781             if ( tables ) dump( tables->idTable, os );
    782             cerr << "===typeTable===" << std::endl;
    783             if ( tables ) dump( tables->typeTable, os );
    784             cerr << "===structTable===" << std::endl;
    785             if ( tables ) dump( tables->structTable, os );
    786             cerr << "===enumTable===" << std::endl;
    787             if ( tables ) dump( tables->enumTable, os );
    788             cerr << "===unionTable===" << std::endl;
    789             if ( tables ) dump( tables->unionTable, os );
    790             cerr << "===contextTable===" << std::endl;
    791             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
    792808        }
    793809} // namespace SymTab
Note: See TracChangeset for help on using the changeset viewer.