Changes in / [b0be06ac:24e7b47]


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/IdTable.cc

    rb0be06ac r24e7b47  
    1010// Created On       : Sun May 17 17:04:02 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Oct 07 12:21:13 2015
    13 // Update Count     : 73
     12// Last Modified On : Wed Aug 19 15:47:58 2015
     13// Update Count     : 38
    1414//
    1515
     
    3737                        for ( InnerTableType::iterator inner = outer->second.begin(); inner != outer->second.end(); ++inner ) {
    3838                                std::stack< DeclEntry >& entry = inner->second;
    39                                 // xxx - should be while?
    4039                                if ( ! entry.empty() && entry.top().second == scopeLevel ) {
    4140                                        entry.pop();
     
    6665
    6766                if ( it == declTable.end() ) {
    68                         // first time this name mangling has been defined
    6967                        declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) );
    7068                } else {
    7169                        std::stack< DeclEntry >& entry = it->second;
    7270                        if ( ! entry.empty() && entry.top().second == scopeLevel ) {
    73                                 // if we're giving the same name mangling to things of
    74                                 //  different types then there is something wrong
    75                                 Declaration *old = entry.top().first;
    76                                 assert( (dynamic_cast<ObjectDecl*>( decl ) && dynamic_cast<ObjectDecl*>( old ) )
    77                                   || (dynamic_cast<FunctionDecl*>( decl ) && dynamic_cast<FunctionDecl*>( old ) ) );
     71                                // typesCompatible doesn't really do the right thing here. When checking compatibility of function types,
     72                                // we should ignore outermost pointer qualifiers, except _Atomic?
    7873
    79                                 if ( LinkageSpec::isOverridable( old->get_linkage() ) ) {
    80                                         // new definition shadows the autogenerated one, even at the same scope
    81                                         declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) );
    82                                 } else if ( decl->get_linkage() != LinkageSpec::C || ResolvExpr::typesCompatible( decl->get_type(), entry.top().first->get_type(), Indexer() ) ) {
    83                                         // typesCompatible doesn't really do the right thing here. When checking compatibility of function types,
    84                                         // we should ignore outermost pointer qualifiers, except _Atomic?
     74                                if ( decl->get_linkage() != LinkageSpec::C || ResolvExpr::typesCompatible( decl->get_type(), entry.top().first->get_type(), Indexer() ) ) {
    8575                                        FunctionDecl *newentry = dynamic_cast< FunctionDecl* >( decl );
    86                                         FunctionDecl *oldentry = dynamic_cast< FunctionDecl* >( old );
    87                                         if ( newentry && oldentry ) {
    88                                                 if ( newentry->get_statements() && oldentry->get_statements() ) {
    89                                                         throw SemanticError( "duplicate function definition for 1 ", decl );
    90                                                 } // if
     76                                        FunctionDecl *old = dynamic_cast< FunctionDecl* >( entry.top().first );
     77                                        if ( LinkageSpec::isOverridable( old->get_linkage() ) ) {
     78                                                // new definition shadows the autogenerated one, even at the same scope
     79                                                declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) );
     80                                        } else if ( newentry && old && newentry->get_statements() && old->get_statements() ) {
     81                                                throw SemanticError( "duplicate function definition for 1 ", decl );
    9182                                        } else {
    9283                                                // two objects with the same mangled name defined in the same scope.
    93                                                 // both objects must be marked extern or both must be intrinsic for this to be okay
    94                                                 // xxx - perhaps it's actually if either is intrinsic then this is okay?
    95                                                 //       might also need to be same storage class?
     84                                                // both objects must be marked extern for this to be okay
    9685                                                ObjectDecl *newobj = dynamic_cast< ObjectDecl* >( decl );
    97                                                 ObjectDecl *oldobj = dynamic_cast< ObjectDecl* >( old );
    98                                                 if (newobj->get_storageClass() != DeclarationNode::Extern && oldobj->get_storageClass() != DeclarationNode::Extern ) {
    99                                                         throw SemanticError( "duplicate definition for 3 ", decl );
     86                                                ObjectDecl *oldobj = dynamic_cast< ObjectDecl* >( entry.top().first );
     87                                                if ( newobj && oldobj && newobj->get_storageClass() != DeclarationNode::Extern && oldobj->get_storageClass() != DeclarationNode::Extern ) {
     88                                                        throw SemanticError( "duplicate definition for ", decl );
    10089                                                } // if
    10190                                        } // if
    10291                                } else {
    103                                         throw SemanticError( "duplicate definition for ", decl );
     92                                        // C definitions with the same name but incompatible types
     93                                        throw SemanticError( "duplicate definition for 2 ", decl );
    10494                                } // if
    10595                        } else {
    106                                 // new scope level - shadow existing definition
    10796                                declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) );
    10897                        } // if
    10998                } // if
     99                // ensure the set of routines with C linkage cannot be overloaded
    110100                // this ensures that no two declarations with the same unmangled name both have C linkage
    111101                for ( InnerTableType::iterator i = declTable.begin(); i != declTable.end(); ++i ) {
Note: See TracChangeset for help on using the changeset viewer.