Changeset 8a930c03 for src/AST/SymbolTable.cpp
- Timestamp:
- Jun 12, 2023, 12:05:58 PM (2 years ago)
- Branches:
- master
- Children:
- fec8bd1
- Parents:
- 2b78949 (diff), 38e266ca (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
r2b78949 r8a930c03 18 18 #include <cassert> 19 19 20 #include "Copy.hpp" 20 21 #include "Decl.hpp" 21 22 #include "Expr.hpp" … … 87 88 } 88 89 89 SymbolTable::SymbolTable( )90 SymbolTable::SymbolTable( ErrorDetection errorMode ) 90 91 : idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(), 91 prevScope(), scope( 0 ), repScope( 0 ) { ++*stats().count; }92 prevScope(), scope( 0 ), repScope( 0 ), errorMode(errorMode) { ++*stats().count; } 92 93 93 94 SymbolTable::~SymbolTable() { stats().size->push( idTable ? idTable->size() : 0 ); } 95 96 void SymbolTable::OnFindError( CodeLocation location, std::string error ) const { 97 assertf( errorMode != AssertClean, "Name collision/redefinition, found during a compilation phase where none should be possible. Detail: %s", error.c_str() ); 98 if (errorMode == ValidateOnAdd) { 99 SemanticError(location, error); 100 } 101 assertf( errorMode == IgnoreErrors, "Unrecognized symbol-table error mode %d", errorMode ); 102 } 94 103 95 104 void SymbolTable::enterScope() { … … 268 277 } 269 278 270 namespace { 271 /// true if redeclaration conflict between two types 272 bool addedTypeConflicts( const NamedTypeDecl * existing, const NamedTypeDecl * added ) { 273 if ( existing->base == nullptr ) { 274 return false; 275 } else if ( added->base == nullptr ) { 276 return true; 277 } else { 278 // typedef redeclarations are errors only if types are different 279 if ( ! ResolvExpr::typesCompatible( existing->base, added->base, SymbolTable{} ) ) { 280 SemanticError( added->location, "redeclaration of " + added->name ); 281 } 282 } 283 // does not need to be added to the table if both existing and added have a base that are 284 // the same 279 bool SymbolTable::addedTypeConflicts( 280 const NamedTypeDecl * existing, const NamedTypeDecl * added ) const { 281 if ( existing->base == nullptr ) { 282 return false; 283 } else if ( added->base == nullptr ) { 285 284 return true; 286 } 287 288 /// true if redeclaration conflict between two aggregate declarations 289 bool addedDeclConflicts( const AggregateDecl * existing, const AggregateDecl * added ) { 290 if ( ! existing->body ) { 291 return false; 292 } else if ( added->body ) { 293 SemanticError( added, "redeclaration of " ); 294 } 295 return true; 296 } 285 } else { 286 // typedef redeclarations are errors only if types are different 287 if ( ! ResolvExpr::typesCompatible( existing->base, added->base ) ) { 288 OnFindError( added->location, "redeclaration of " + added->name ); 289 } 290 } 291 // does not need to be added to the table if both existing and added have a base that are 292 // the same 293 return true; 294 } 295 296 bool SymbolTable::addedDeclConflicts( 297 const AggregateDecl * existing, const AggregateDecl * added ) const { 298 if ( ! existing->body ) { 299 return false; 300 } else if ( added->body ) { 301 OnFindError( added, "redeclaration of " ); 302 } 303 return true; 297 304 } 298 305 … … 642 649 } else if ( existing.id->linkage.is_mangled 643 650 || ResolvExpr::typesCompatible( 644 added->get_type(), existing.id->get_type() , SymbolTable{}) ) {651 added->get_type(), existing.id->get_type() ) ) { 645 652 646 653 // it is a conflict if one declaration is deleted and the other is not 647 654 if ( deleter && ! existing.deleter ) { 648 655 if ( handleConflicts.mode == OnConflict::Error ) { 649 SemanticError( added, "deletion of defined identifier " );656 OnFindError( added, "deletion of defined identifier " ); 650 657 } 651 658 return true; 652 659 } else if ( ! deleter && existing.deleter ) { 653 660 if ( handleConflicts.mode == OnConflict::Error ) { 654 SemanticError( added, "definition of deleted identifier " );661 OnFindError( added, "definition of deleted identifier " ); 655 662 } 656 663 return true; … … 660 667 if ( isDefinition( added ) && isDefinition( existing.id ) ) { 661 668 if ( handleConflicts.mode == OnConflict::Error ) { 662 SemanticError( added,669 OnFindError( added, 663 670 isFunction( added ) ? 664 671 "duplicate function definition for " : … … 669 676 } else { 670 677 if ( handleConflicts.mode == OnConflict::Error ) { 671 SemanticError( added, "duplicate definition for " );678 OnFindError( added, "duplicate definition for " ); 672 679 } 673 680 return true; … … 721 728 // Check that a Cforall declaration doesn't override any C declaration 722 729 if ( hasCompatibleCDecl( name, mangleName ) ) { 723 SemanticError( decl, "Cforall declaration hides C function " );730 OnFindError( decl, "Cforall declaration hides C function " ); 724 731 } 725 732 } else { … … 727 734 // type-compatibility, which it may not be. 728 735 if ( hasIncompatibleCDecl( name, mangleName ) ) { 729 SemanticError( decl, "conflicting overload of C function " );736 OnFindError( decl, "conflicting overload of C function " ); 730 737 } 731 738 }
Note:
See TracChangeset
for help on using the changeset viewer.