Changeset 67b1180


Ignore:
Timestamp:
Apr 22, 2016, 3:31:05 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, ctor, deferred_resn, demangler, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
845cedc
Parents:
fbfb38e (diff), 743fbda (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 ctor

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Indexer.cc

    rfbfb38e r67b1180  
    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;
     
    519520                        const MangleTable &mangleTable = decls->second;
    520521                        for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) {
    521                                 // check for C decls with the same name, skipping 
     522                                // check for C decls with the same name, skipping
    522523                                // those with a compatible type (by mangleName)
    523524                                if ( decl->second->get_linkage() == LinkageSpec::C && decl->first != mangleName ) return true;
     
    527528                return tables->base.hasIncompatibleCDecl( id, mangleName, scope );
    528529        }
    529        
     530
    530531        NamedTypeDecl *Indexer::lookupTypeAtScope( const std::string &id, unsigned long scope ) const {
    531532                if ( ! tables ) return 0;
     
    535536                return ret != tables->typeTable.end() ? ret->second : tables->base.lookupTypeAtScope( id, scope );
    536537        }
    537        
     538
    538539        StructDecl *Indexer::lookupStructAtScope( const std::string &id, unsigned long scope ) const {
    539540                if ( ! tables ) return 0;
     
    543544                return ret != tables->structTable.end() ? ret->second : tables->base.lookupStructAtScope( id, scope );
    544545        }
    545        
     546
    546547        EnumDecl *Indexer::lookupEnumAtScope( const std::string &id, unsigned long scope ) const {
    547548                if ( ! tables ) return 0;
     
    551552                return ret != tables->enumTable.end() ? ret->second : tables->base.lookupEnumAtScope( id, scope );
    552553        }
    553        
     554
    554555        UnionDecl *Indexer::lookupUnionAtScope( const std::string &id, unsigned long scope ) const {
    555556                if ( ! tables ) return 0;
     
    559560                return ret != tables->unionTable.end() ? ret->second : tables->base.lookupUnionAtScope( id, scope );
    560561        }
    561        
     562
    562563        TraitDecl *Indexer::lookupTraitAtScope( const std::string &id, unsigned long scope ) const {
    563564                if ( ! tables ) return 0;
     
    602603                return true;
    603604        }
    604        
     605
    605606        void Indexer::addId( DeclarationWithType *decl ) {
    606607                makeWritable();
     
    621622                        if ( decl->get_linkage() == LinkageSpec::C && hasIncompatibleCDecl( name, mangleName, scope ) ) {
    622623                                throw SemanticError( "invalid overload of C function ", decl );
    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 
     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
    625626                          // have their name as their manglename, hence the error can never trigger).
    626                           // 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
    627628                          // isomorphic to C type-compatibility, which it may not be.
    628                        
     629
    629630                        tables->idTable[ name ][ mangleName ] = decl;
    630631                        ++tables->size;
     
    641642                }
    642643        }
    643        
     644
    644645        void Indexer::addType( NamedTypeDecl *decl ) {
    645646                makeWritable();
     
    672673                addStruct( new StructDecl( id ) );
    673674        }
    674        
     675
    675676        void Indexer::addStruct( StructDecl *decl ) {
    676677                makeWritable();
     
    690691                }
    691692        }
    692        
     693
    693694        void Indexer::addEnum( EnumDecl *decl ) {
    694695                makeWritable();
     
    712713                addUnion( new UnionDecl( id ) );
    713714        }
    714        
     715
    715716        void Indexer::addUnion( UnionDecl *decl ) {
    716717                makeWritable();
     
    730731                }
    731732        }
    732        
     733
    733734        void Indexer::addTrait( TraitDecl *decl ) {
    734735                makeWritable();
     
    751752        void Indexer::enterScope() {
    752753                ++scope;
    753                
     754
    754755                if ( doDebug ) {
    755756                        std::cout << "--- Entering scope " << scope << std::endl;
     
    804805                        os << "--- end ---" << std::endl;
    805806                }
    806                
     807
    807808        }
    808809} // namespace SymTab
Note: See TracChangeset for help on using the changeset viewer.