Changeset b7b3e41 for src/AST/SymbolTable.cpp
- Timestamp:
- Jun 19, 2023, 1:57:11 PM (2 years ago)
- Branches:
- master
- Children:
- adc73a5
- Parents:
- fa5e1aa5 (diff), 33d4bc8 (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
rfa5e1aa5 rb7b3e41 19 19 20 20 #include "Copy.hpp" 21 #include <iostream> 22 #include <algorithm> 23 21 24 #include "Decl.hpp" 22 25 #include "Expr.hpp" … … 88 91 } 89 92 90 SymbolTable::SymbolTable( )93 SymbolTable::SymbolTable( ErrorDetection errorMode ) 91 94 : idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(), 92 prevScope(), scope( 0 ), repScope( 0 ) { ++*stats().count; }95 prevScope(), scope( 0 ), repScope( 0 ), errorMode(errorMode) { ++*stats().count; } 93 96 94 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 } 95 106 96 107 void SymbolTable::enterScope() { … … 195 206 out.push_back(decl.second); 196 207 } 208 209 // std::cerr << otypeKey << ' ' << out.size() << std::endl; 197 210 } 198 211 … … 269 282 } 270 283 271 namespace { 272 /// true if redeclaration conflict between two types 273 bool addedTypeConflicts( const NamedTypeDecl * existing, const NamedTypeDecl * added ) { 274 if ( existing->base == nullptr ) { 275 return false; 276 } else if ( added->base == nullptr ) { 277 return true; 278 } else { 279 // typedef redeclarations are errors only if types are different 280 if ( ! ResolvExpr::typesCompatible( existing->base, added->base ) ) { 281 SemanticError( added->location, "redeclaration of " + added->name ); 282 } 283 } 284 // does not need to be added to the table if both existing and added have a base that are 285 // 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 ) { 286 289 return true; 287 } 288 289 /// true if redeclaration conflict between two aggregate declarations 290 bool addedDeclConflicts( const AggregateDecl * existing, const AggregateDecl * added ) { 291 if ( ! existing->body ) { 292 return false; 293 } else if ( added->body ) { 294 SemanticError( added, "redeclaration of " ); 295 } 296 return true; 297 } 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; 298 309 } 299 310 … … 648 659 if ( deleter && ! existing.deleter ) { 649 660 if ( handleConflicts.mode == OnConflict::Error ) { 650 SemanticError( added, "deletion of defined identifier " );661 OnFindError( added, "deletion of defined identifier " ); 651 662 } 652 663 return true; 653 664 } else if ( ! deleter && existing.deleter ) { 654 665 if ( handleConflicts.mode == OnConflict::Error ) { 655 SemanticError( added, "definition of deleted identifier " );666 OnFindError( added, "definition of deleted identifier " ); 656 667 } 657 668 return true; … … 661 672 if ( isDefinition( added ) && isDefinition( existing.id ) ) { 662 673 if ( handleConflicts.mode == OnConflict::Error ) { 663 SemanticError( added,674 OnFindError( added, 664 675 isFunction( added ) ? 665 676 "duplicate function definition for " : … … 670 681 } else { 671 682 if ( handleConflicts.mode == OnConflict::Error ) { 672 SemanticError( added, "duplicate definition for " );683 OnFindError( added, "duplicate definition for " ); 673 684 } 674 685 return true; … … 722 733 // Check that a Cforall declaration doesn't override any C declaration 723 734 if ( hasCompatibleCDecl( name, mangleName ) ) { 724 SemanticError( decl, "Cforall declaration hides C function " );735 OnFindError( decl, "Cforall declaration hides C function " ); 725 736 } 726 737 } else { … … 728 739 // type-compatibility, which it may not be. 729 740 if ( hasIncompatibleCDecl( name, mangleName ) ) { 730 SemanticError( decl, "conflicting overload of C function " );741 OnFindError( decl, "conflicting overload of C function " ); 731 742 } 732 743 }
Note:
See TracChangeset
for help on using the changeset viewer.