Ignore:
Timestamp:
Jun 30, 2016, 4:32:56 PM (10 years ago)
Author:
Thierry Delisle <tdelisle@…>
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.
Message:

Merge branch 'master' into gc_noraii

Conflicts:

Jenkinsfile
src/SymTab/Validate.cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Indexer.cc

    r1b5c81ed rf80e0218  
    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 );
     
    438439        }
    439440
    440        
     441
    441442
    442443        void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &out ) const {
    443444                std::unordered_set< std::string > foundMangleNames;
    444                
     445
    445446                Indexer::Impl *searchTables = tables;
    446447                while ( searchTables ) {
     
    452453                                        // mark the mangled name as found, skipping this insertion if a declaration for that name has already been found
    453454                                        if ( foundMangleNames.insert( decl->first ).second == false ) continue;
    454                                        
     455
    455456                                        out.push_back( decl->second );
    456457                                }
    457458                        }
    458                        
     459
    459460                        // get declarations from base indexers
    460461                        searchTables = searchTables->base.tables;
     
    511512        }
    512513
    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 {
    514515                if ( ! tables ) return false;
     516                if ( tables->scope < scope ) return false;
    515517
    516518                IdTable::const_iterator decls = tables->idTable.find( id );
     
    518520                        const MangleTable &mangleTable = decls->second;
    519521                        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
    521523                                // those with a compatible type (by mangleName)
    522524                                if ( decl->second->get_linkage() == LinkageSpec::C && decl->first != mangleName ) return true;
     
    524526                }
    525527
    526                 return tables->base.hasIncompatibleCDecl( id, mangleName );
    527         }
    528        
     528                return tables->base.hasIncompatibleCDecl( id, mangleName, scope );
     529        }
     530
    529531        NamedTypeDecl *Indexer::lookupTypeAtScope( const std::string &id, unsigned long scope ) const {
    530532                if ( ! tables ) return 0;
     
    534536                return ret != tables->typeTable.end() ? ret->second : tables->base.lookupTypeAtScope( id, scope );
    535537        }
    536        
     538
    537539        StructDecl *Indexer::lookupStructAtScope( const std::string &id, unsigned long scope ) const {
    538540                if ( ! tables ) return 0;
     
    542544                return ret != tables->structTable.end() ? ret->second : tables->base.lookupStructAtScope( id, scope );
    543545        }
    544        
     546
    545547        EnumDecl *Indexer::lookupEnumAtScope( const std::string &id, unsigned long scope ) const {
    546548                if ( ! tables ) return 0;
     
    550552                return ret != tables->enumTable.end() ? ret->second : tables->base.lookupEnumAtScope( id, scope );
    551553        }
    552        
     554
    553555        UnionDecl *Indexer::lookupUnionAtScope( const std::string &id, unsigned long scope ) const {
    554556                if ( ! tables ) return 0;
     
    558560                return ret != tables->unionTable.end() ? ret->second : tables->base.lookupUnionAtScope( id, scope );
    559561        }
    560        
     562
    561563        TraitDecl *Indexer::lookupTraitAtScope( const std::string &id, unsigned long scope ) const {
    562564                if ( ! tables ) return 0;
     
    601603                return true;
    602604        }
    603        
     605
    604606        void Indexer::addId( DeclarationWithType *decl ) {
    605607                makeWritable();
     
    617619                DeclarationWithType *existing = lookupIdAtScope( name, mangleName, scope );
    618620                if ( ! existing || ! addedIdConflicts( existing, decl ) ) {
    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 ) ) {
     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 ) ) {
    621623                                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
    624626                          // 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
    626628                          // isomorphic to C type-compatibility, which it may not be.
    627                        
     629
    628630                        tables->idTable[ name ][ mangleName ] = decl;
    629631                        ++tables->size;
     
    640642                }
    641643        }
    642        
     644
    643645        void Indexer::addType( NamedTypeDecl *decl ) {
    644646                makeWritable();
     
    671673                addStruct( new StructDecl( id ) );
    672674        }
    673        
     675
    674676        void Indexer::addStruct( StructDecl *decl ) {
    675677                makeWritable();
     
    689691                }
    690692        }
    691        
     693
    692694        void Indexer::addEnum( EnumDecl *decl ) {
    693695                makeWritable();
     
    711713                addUnion( new UnionDecl( id ) );
    712714        }
    713        
     715
    714716        void Indexer::addUnion( UnionDecl *decl ) {
    715717                makeWritable();
     
    729731                }
    730732        }
    731        
     733
    732734        void Indexer::addTrait( TraitDecl *decl ) {
    733735                makeWritable();
     
    750752        void Indexer::enterScope() {
    751753                ++scope;
    752                
     754
    753755                if ( doDebug ) {
    754756                        std::cout << "--- Entering scope " << scope << std::endl;
     
    783785            using std::cerr;
    784786
    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
    797808        }
    798809} // namespace SymTab
Note: See TracChangeset for help on using the changeset viewer.