Changeset 62d62db for src/AST/SymbolTable.cpp
- Timestamp:
- Jun 12, 2023, 6:06:26 PM (13 months ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/SymbolTable.cpp
r24d6572 r62d62db 91 91 } 92 92 93 SymbolTable::SymbolTable( )93 SymbolTable::SymbolTable( ErrorDetection errorMode ) 94 94 : idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(), 95 prevScope(), scope( 0 ), repScope( 0 ) { ++*stats().count; }95 prevScope(), scope( 0 ), repScope( 0 ), errorMode(errorMode) { ++*stats().count; } 96 96 97 97 SymbolTable::~SymbolTable() { stats().size->push( idTable ? idTable->size() : 0 ); } 98 99 void 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 } 98 106 99 107 void SymbolTable::enterScope() { … … 274 282 } 275 283 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 284 bool SymbolTable::addedTypeConflicts( 285 const NamedTypeDecl * existing, const NamedTypeDecl * added ) const { 286 if ( existing->base == nullptr ) { 287 return false; 288 } else if ( added->base == nullptr ) { 291 289 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 301 bool 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; 303 309 } 304 310 … … 653 659 if ( deleter && ! existing.deleter ) { 654 660 if ( handleConflicts.mode == OnConflict::Error ) { 655 SemanticError( added, "deletion of defined identifier " );661 OnFindError( added, "deletion of defined identifier " ); 656 662 } 657 663 return true; 658 664 } else if ( ! deleter && existing.deleter ) { 659 665 if ( handleConflicts.mode == OnConflict::Error ) { 660 SemanticError( added, "definition of deleted identifier " );666 OnFindError( added, "definition of deleted identifier " ); 661 667 } 662 668 return true; … … 666 672 if ( isDefinition( added ) && isDefinition( existing.id ) ) { 667 673 if ( handleConflicts.mode == OnConflict::Error ) { 668 SemanticError( added,674 OnFindError( added, 669 675 isFunction( added ) ? 670 676 "duplicate function definition for " : … … 675 681 } else { 676 682 if ( handleConflicts.mode == OnConflict::Error ) { 677 SemanticError( added, "duplicate definition for " );683 OnFindError( added, "duplicate definition for " ); 678 684 } 679 685 return true; … … 727 733 // Check that a Cforall declaration doesn't override any C declaration 728 734 if ( hasCompatibleCDecl( name, mangleName ) ) { 729 SemanticError( decl, "Cforall declaration hides C function " );735 OnFindError( decl, "Cforall declaration hides C function " ); 730 736 } 731 737 } else { … … 733 739 // type-compatibility, which it may not be. 734 740 if ( hasIncompatibleCDecl( name, mangleName ) ) { 735 SemanticError( decl, "conflicting overload of C function " );741 OnFindError( decl, "conflicting overload of C function " ); 736 742 } 737 743 }
Note: See TracChangeset
for help on using the changeset viewer.