Changes in src/AST/SymbolTable.cpp [b9fe89b:d859a30]
- File:
-
- 1 edited
-
src/AST/SymbolTable.cpp (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/SymbolTable.cpp
rb9fe89b rd859a30 18 18 #include <cassert> 19 19 20 #include "Copy.hpp"21 20 #include "Decl.hpp" 22 21 #include "Expr.hpp" … … 88 87 } 89 88 90 SymbolTable::SymbolTable( ErrorDetection errorMode)89 SymbolTable::SymbolTable() 91 90 : idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(), 92 prevScope(), scope( 0 ), repScope( 0 ) , errorMode(errorMode){ ++*stats().count; }91 prevScope(), scope( 0 ), repScope( 0 ) { ++*stats().count; } 93 92 94 93 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 }103 94 104 95 void SymbolTable::enterScope() { … … 277 268 } 278 269 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 ) { 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 284 285 return true; 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; 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 } 304 297 } 305 298 … … 649 642 } else if ( existing.id->linkage.is_mangled 650 643 || ResolvExpr::typesCompatible( 651 added->get_type(), existing.id->get_type() ) ) {644 added->get_type(), existing.id->get_type(), SymbolTable{} ) ) { 652 645 653 646 // it is a conflict if one declaration is deleted and the other is not 654 647 if ( deleter && ! existing.deleter ) { 655 648 if ( handleConflicts.mode == OnConflict::Error ) { 656 OnFindError( added, "deletion of defined identifier " );649 SemanticError( added, "deletion of defined identifier " ); 657 650 } 658 651 return true; 659 652 } else if ( ! deleter && existing.deleter ) { 660 653 if ( handleConflicts.mode == OnConflict::Error ) { 661 OnFindError( added, "definition of deleted identifier " );654 SemanticError( added, "definition of deleted identifier " ); 662 655 } 663 656 return true; … … 667 660 if ( isDefinition( added ) && isDefinition( existing.id ) ) { 668 661 if ( handleConflicts.mode == OnConflict::Error ) { 669 OnFindError( added,662 SemanticError( added, 670 663 isFunction( added ) ? 671 664 "duplicate function definition for " : … … 676 669 } else { 677 670 if ( handleConflicts.mode == OnConflict::Error ) { 678 OnFindError( added, "duplicate definition for " );671 SemanticError( added, "duplicate definition for " ); 679 672 } 680 673 return true; … … 728 721 // Check that a Cforall declaration doesn't override any C declaration 729 722 if ( hasCompatibleCDecl( name, mangleName ) ) { 730 OnFindError( decl, "Cforall declaration hides C function " );723 SemanticError( decl, "Cforall declaration hides C function " ); 731 724 } 732 725 } else { … … 734 727 // type-compatibility, which it may not be. 735 728 if ( hasIncompatibleCDecl( name, mangleName ) ) { 736 OnFindError( decl, "conflicting overload of C function " );729 SemanticError( decl, "conflicting overload of C function " ); 737 730 } 738 731 }
Note:
See TracChangeset
for help on using the changeset viewer.