Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/SymbolTable.cpp

    rb9fe89b rd859a30  
    1818#include <cassert>
    1919
    20 #include "Copy.hpp"
    2120#include "Decl.hpp"
    2221#include "Expr.hpp"
     
    8887}
    8988
    90 SymbolTable::SymbolTable( ErrorDetection errorMode )
     89SymbolTable::SymbolTable()
    9190: idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(),
    92   prevScope(), scope( 0 ), repScope( 0 ), errorMode(errorMode) { ++*stats().count; }
     91  prevScope(), scope( 0 ), repScope( 0 ) { ++*stats().count; }
    9392
    9493SymbolTable::~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 }
    10394
    10495void SymbolTable::enterScope() {
     
    277268}
    278269
    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 ) {
     270namespace {
     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
    284285                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        }
    304297}
    305298
     
    649642        } else if ( existing.id->linkage.is_mangled
    650643                        || ResolvExpr::typesCompatible(
    651                                 added->get_type(), existing.id->get_type() ) ) {
     644                                added->get_type(), existing.id->get_type(), SymbolTable{} ) ) {
    652645
    653646                // it is a conflict if one declaration is deleted and the other is not
    654647                if ( deleter && ! existing.deleter ) {
    655648                        if ( handleConflicts.mode == OnConflict::Error ) {
    656                                 OnFindError( added, "deletion of defined identifier " );
     649                                SemanticError( added, "deletion of defined identifier " );
    657650                        }
    658651                        return true;
    659652                } else if ( ! deleter && existing.deleter ) {
    660653                        if ( handleConflicts.mode == OnConflict::Error ) {
    661                                 OnFindError( added, "definition of deleted identifier " );
     654                                SemanticError( added, "definition of deleted identifier " );
    662655                        }
    663656                        return true;
     
    667660                if ( isDefinition( added ) && isDefinition( existing.id ) ) {
    668661                        if ( handleConflicts.mode == OnConflict::Error ) {
    669                                 OnFindError( added,
     662                                SemanticError( added,
    670663                                        isFunction( added ) ?
    671664                                                "duplicate function definition for " :
     
    676669        } else {
    677670                if ( handleConflicts.mode == OnConflict::Error ) {
    678                         OnFindError( added, "duplicate definition for " );
     671                        SemanticError( added, "duplicate definition for " );
    679672                }
    680673                return true;
     
    728721                // Check that a Cforall declaration doesn't override any C declaration
    729722                if ( hasCompatibleCDecl( name, mangleName ) ) {
    730                         OnFindError( decl, "Cforall declaration hides C function " );
     723                        SemanticError( decl, "Cforall declaration hides C function " );
    731724                }
    732725        } else {
     
    734727                // type-compatibility, which it may not be.
    735728                if ( hasIncompatibleCDecl( name, mangleName ) ) {
    736                         OnFindError( decl, "conflicting overload of C function " );
     729                        SemanticError( decl, "conflicting overload of C function " );
    737730                }
    738731        }
Note: See TracChangeset for help on using the changeset viewer.