Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Indexer.cc

    r4e06c1e r8884112  
    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 : Tue Jul 12 17:47:47 2016
    13 // Update Count     : 12
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Fri Apr 22 15:25:43 2016
     13// Update Count     : 11
    1414//
    1515
     
    520520                        const MangleTable &mangleTable = decls->second;
    521521                        for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) {
    522                                 // check for C decls with the same name, skipping those with a compatible type (by mangleName)
     522                                // check for C decls with the same name, skipping
     523                                // those with a compatible type (by mangleName)
    523524                                if ( decl->second->get_linkage() == LinkageSpec::C && decl->first != mangleName ) return true;
    524525                        }
     
    526527
    527528                return tables->base.hasIncompatibleCDecl( id, mangleName, scope );
     529        }
     530
     531        bool Indexer::hasCompatibleCDecl( const std::string &id, const std::string &mangleName, unsigned long scope ) const {
     532                if ( ! tables ) return false;
     533                if ( tables->scope < scope ) return false;
     534
     535                IdTable::const_iterator decls = tables->idTable.find( id );
     536                if ( decls != tables->idTable.end() ) {
     537                        const MangleTable &mangleTable = decls->second;
     538                        for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) {
     539                                // check for C decls with the same name, skipping
     540                                // those with an incompatible type (by mangleName)
     541                                if ( decl->second->get_linkage() == LinkageSpec::C && decl->first == mangleName ) return true;
     542                        }
     543                }
     544
     545                return tables->base.hasCompatibleCDecl( id, mangleName, scope );
    528546        }
    529547
     
    616634                } // if
    617635
     636                // this ensures that no two declarations with the same unmangled name at the same scope both have C linkage
     637                if ( decl->get_linkage() == LinkageSpec::C ) {
     638                        // NOTE this is broken in Richard's original code in such a way that it never triggers (it
     639                        // doesn't check decls that have the same manglename, and all C-linkage decls are defined to
     640                        // have their name as their manglename, hence the error can never trigger).
     641                        // The code here is closer to correct, but name mangling would have to be completely
     642                        // isomorphic to C type-compatibility, which it may not be.
     643                        if ( hasIncompatibleCDecl( name, mangleName, scope ) ) {
     644                                throw SemanticError( "conflicting overload of C function ", decl );
     645                        }
     646                } else {
     647                        // Check that a Cforall declaration doesn't overload any C declaration
     648                        if ( hasCompatibleCDecl( name, mangleName, scope ) ) {
     649                                throw SemanticError( "Cforall declaration hides C function ", decl );
     650                        }
     651                }
     652
     653                // Skip repeat declarations of the same identifier
    618654                DeclarationWithType *existing = lookupIdAtScope( name, mangleName, scope );
    619                 if ( ! existing || ! addedIdConflicts( existing, decl ) ) {
    620                         // this ensures that no two declarations with the same unmangled name at the same scope both have C linkage
    621                         if ( decl->get_linkage() == LinkageSpec::C && hasIncompatibleCDecl( name, mangleName, scope ) ) {
    622                                 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
    625                           // 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                           // isomorphic to C type-compatibility, which it may not be.
    628 
    629                         tables->idTable[ name ][ mangleName ] = decl;
    630                         ++tables->size;
    631                 }
     655                if ( existing && addedIdConflicts( existing, decl ) ) return;
     656
     657                // add to indexer
     658                tables->idTable[ name ][ mangleName ] = decl;
     659                ++tables->size;
    632660        }
    633661
Note: See TracChangeset for help on using the changeset viewer.