Ignore:
Timestamp:
Apr 4, 2016, 1:18:17 PM (10 years ago)
Author:
Aaron Moss <a3moss@…>
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, string, with_gc
Children:
afc1045
Parents:
89173242 (diff), 3cfe27f (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' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Indexer.cc

    r89173242 rb3f9a0cb  
    1919#include <typeinfo>
    2020#include <unordered_map>
     21#include <unordered_set>
    2122#include <utility>
    2223
     
    435436
    436437        void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &out ) const {
    437                 if ( ! tables ) return;
    438 
    439                 IdTable::const_iterator decls = tables->idTable.find( id );
    440                 if ( decls != tables->idTable.end() ) {
    441                         const MangleTable &mangleTable = decls->second;
    442                         for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) {
    443                                 out.push_back( decl->second );
    444                         }
    445                 }
     438                std::unordered_set< std::string > foundMangleNames;
    446439               
    447                 // get declarations from base indexers
    448                 tables->base.lookupId( id, out );
     440                Indexer::Impl *searchTables = tables;
     441                while ( searchTables ) {
     442
     443                        IdTable::const_iterator decls = searchTables->idTable.find( id );
     444                        if ( decls != searchTables->idTable.end() ) {
     445                                const MangleTable &mangleTable = decls->second;
     446                                for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) {
     447                                        // mark the mangled name as found, skipping this insertion if a declaration for that name has already been found
     448                                        if ( foundMangleNames.insert( decl->first ).second == false ) continue;
     449                                       
     450                                        out.push_back( decl->second );
     451                                }
     452                        }
     453                       
     454                        // get declarations from base indexers
     455                        searchTables = searchTables->base.tables;
     456                }
    449457        }
    450458
     
    498506        }
    499507
    500         bool Indexer::hasCDeclWithName( const std::string &id ) const {
     508        bool Indexer::hasIncompatibleCDecl( const std::string &id, const std::string &mangleName ) const {
    501509                if ( ! tables ) return false;
    502510
     
    505513                        const MangleTable &mangleTable = decls->second;
    506514                        for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) {
    507                                 if ( decl->second->get_linkage() == LinkageSpec::C ) return true;
    508                         }
    509                 }
    510 
    511                 return tables->base.hasCDeclWithName( id );
     515                                // check for C decls with the same name, skipping
     516                                // those with a compatible type (by mangleName)
     517                                if ( decl->second->get_linkage() == LinkageSpec::C && decl->first != mangleName ) return true;
     518                        }
     519                }
     520
     521                return tables->base.hasIncompatibleCDecl( id, mangleName );
    512522        }
    513523       
     
    592602                const std::string &name = decl->get_name();
    593603                std::string mangleName;
    594                 if ( decl->get_linkage() == LinkageSpec::C ) {
    595                         mangleName = name;
    596                 } else if ( LinkageSpec::isOverridable( decl->get_linkage() ) ) {
     604                if ( LinkageSpec::isOverridable( decl->get_linkage() ) ) {
    597605                        // mangle the name without including the appropriate suffix, so overridable routines are placed into the
    598606                        // same "bucket" as their user defined versions.
     
    605613                if ( ! existing || ! addedIdConflicts( existing, decl ) ) {
    606614                        // this ensures that no two declarations with the same unmangled name both have C linkage
    607                         if ( decl->get_linkage() == LinkageSpec::C && hasCDeclWithName( name ) ) {
     615                        if ( decl->get_linkage() == LinkageSpec::C && hasIncompatibleCDecl( name, mangleName ) ) {
    608616                                throw SemanticError( "invalid overload of C function ", decl );
    609                         }
     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
     619                          // 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
     621                          // isomorphic to C type-compatibility, which it may not be.
    610622                       
    611623                        tables->idTable[ name ][ mangleName ] = decl;
Note: See TracChangeset for help on using the changeset viewer.