Changeset 59cde21 for src


Ignore:
Timestamp:
Oct 7, 2015, 12:23:53 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
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:
b0be06ac, f28a53a
Parents:
4aa0858
Message:

rearrange IdTable? checks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/IdTable.cc

    r4aa0858 r59cde21  
    1010// Created On       : Sun May 17 17:04:02 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Aug 19 15:47:58 2015
    13 // Update Count     : 38
     12// Last Modified On : Wed Oct 07 12:21:13 2015
     13// Update Count     : 73
    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?
    3940                                if ( ! entry.empty() && entry.top().second == scopeLevel ) {
    4041                                        entry.pop();
     
    6566
    6667                if ( it == declTable.end() ) {
     68                        // first time this name mangling has been defined
    6769                        declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) );
    6870                } else {
    6971                        std::stack< DeclEntry >& entry = it->second;
    7072                        if ( ! entry.empty() && entry.top().second == scopeLevel ) {
    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?
     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 ) ) );
    7378
    74                                 if ( decl->get_linkage() != LinkageSpec::C || ResolvExpr::typesCompatible( decl->get_type(), entry.top().first->get_type(), Indexer() ) ) {
     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?
    7585                                        FunctionDecl *newentry = dynamic_cast< FunctionDecl* >( decl );
    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 );
     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
    8291                                        } else {
    8392                                                // two objects with the same mangled name defined in the same scope.
    84                                                 // both objects must be marked extern for this to be okay
     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?
    8596                                                ObjectDecl *newobj = dynamic_cast< ObjectDecl* >( 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 );
     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 );
    89100                                                } // if
    90101                                        } // if
    91102                                } else {
    92                                         // C definitions with the same name but incompatible types
    93                                         throw SemanticError( "duplicate definition for 2 ", decl );
     103                                        throw SemanticError( "duplicate definition for ", decl );
    94104                                } // if
    95105                        } else {
     106                                // new scope level - shadow existing definition
    96107                                declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) );
    97108                        } // if
    98109                } // if
    99                 // ensure the set of routines with C linkage cannot be overloaded
    100110                // this ensures that no two declarations with the same unmangled name both have C linkage
    101111                for ( InnerTableType::iterator i = declTable.begin(); i != declTable.end(); ++i ) {
Note: See TracChangeset for help on using the changeset viewer.