Ignore:
Timestamp:
Jun 12, 2023, 6:06:26 PM (13 months ago)
Author:
caparsons <caparson@…>
Branches:
ast-experimental, master
Children:
e172f42
Parents:
24d6572 (diff), 38e266c (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 ast-experimental

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/SymbolTable.cpp

    r24d6572 r62d62db  
    9191}
    9292
    93 SymbolTable::SymbolTable()
     93SymbolTable::SymbolTable( ErrorDetection errorMode )
    9494: idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(),
    95   prevScope(), scope( 0 ), repScope( 0 ) { ++*stats().count; }
     95  prevScope(), scope( 0 ), repScope( 0 ), errorMode(errorMode) { ++*stats().count; }
    9696
    9797SymbolTable::~SymbolTable() { stats().size->push( idTable ? idTable->size() : 0 ); }
     98
     99void SymbolTable::OnFindError( CodeLocation location, std::string error ) const {
     100        assertf( errorMode != AssertClean, "Name collision/redefinition, found during a compilation phase where none should be possible.  Detail: %s", error.c_str() );
     101        if (errorMode == ValidateOnAdd) {
     102                SemanticError(location, error);
     103        }
     104        assertf( errorMode == IgnoreErrors, "Unrecognized symbol-table error mode %d", errorMode );
     105}
    98106
    99107void SymbolTable::enterScope() {
     
    274282}
    275283
    276 namespace {
    277         /// true if redeclaration conflict between two types
    278         bool addedTypeConflicts( const NamedTypeDecl * existing, const NamedTypeDecl * added ) {
    279                 if ( existing->base == nullptr ) {
    280                         return false;
    281                 } else if ( added->base == nullptr ) {
    282                         return true;
    283                 } else {
    284                         // typedef redeclarations are errors only if types are different
    285                         if ( ! ResolvExpr::typesCompatible( existing->base, added->base ) ) {
    286                                 SemanticError( added->location, "redeclaration of " + added->name );
    287                         }
    288                 }
    289                 // does not need to be added to the table if both existing and added have a base that are
    290                 // the same
     284bool SymbolTable::addedTypeConflicts(
     285                const NamedTypeDecl * existing, const NamedTypeDecl * added ) const {
     286        if ( existing->base == nullptr ) {
     287                return false;
     288        } else if ( added->base == nullptr ) {
    291289                return true;
    292         }
    293 
    294         /// true if redeclaration conflict between two aggregate declarations
    295         bool addedDeclConflicts( const AggregateDecl * existing, const AggregateDecl * added ) {
    296                 if ( ! existing->body ) {
    297                         return false;
    298                 } else if ( added->body ) {
    299                         SemanticError( added, "redeclaration of " );
    300                 }
    301                 return true;
    302         }
     290        } else {
     291                // typedef redeclarations are errors only if types are different
     292                if ( ! ResolvExpr::typesCompatible( existing->base, added->base ) ) {
     293                        OnFindError( added->location, "redeclaration of " + added->name );
     294                }
     295        }
     296        // does not need to be added to the table if both existing and added have a base that are
     297        // the same
     298        return true;
     299}
     300
     301bool SymbolTable::addedDeclConflicts(
     302                const AggregateDecl * existing, const AggregateDecl * added ) const {
     303        if ( ! existing->body ) {
     304                return false;
     305        } else if ( added->body ) {
     306                OnFindError( added, "redeclaration of " );
     307        }
     308        return true;
    303309}
    304310
     
    653659                if ( deleter && ! existing.deleter ) {
    654660                        if ( handleConflicts.mode == OnConflict::Error ) {
    655                                 SemanticError( added, "deletion of defined identifier " );
     661                                OnFindError( added, "deletion of defined identifier " );
    656662                        }
    657663                        return true;
    658664                } else if ( ! deleter && existing.deleter ) {
    659665                        if ( handleConflicts.mode == OnConflict::Error ) {
    660                                 SemanticError( added, "definition of deleted identifier " );
     666                                OnFindError( added, "definition of deleted identifier " );
    661667                        }
    662668                        return true;
     
    666672                if ( isDefinition( added ) && isDefinition( existing.id ) ) {
    667673                        if ( handleConflicts.mode == OnConflict::Error ) {
    668                                 SemanticError( added,
     674                                OnFindError( added,
    669675                                        isFunction( added ) ?
    670676                                                "duplicate function definition for " :
     
    675681        } else {
    676682                if ( handleConflicts.mode == OnConflict::Error ) {
    677                         SemanticError( added, "duplicate definition for " );
     683                        OnFindError( added, "duplicate definition for " );
    678684                }
    679685                return true;
     
    727733                // Check that a Cforall declaration doesn't override any C declaration
    728734                if ( hasCompatibleCDecl( name, mangleName ) ) {
    729                         SemanticError( decl, "Cforall declaration hides C function " );
     735                        OnFindError( decl, "Cforall declaration hides C function " );
    730736                }
    731737        } else {
     
    733739                // type-compatibility, which it may not be.
    734740                if ( hasIncompatibleCDecl( name, mangleName ) ) {
    735                         SemanticError( decl, "conflicting overload of C function " );
     741                        OnFindError( decl, "conflicting overload of C function " );
    736742                }
    737743        }
Note: See TracChangeset for help on using the changeset viewer.