Ignore:
Timestamp:
Jun 12, 2023, 12:05:58 PM (2 years ago)
Author:
JiadaL <j82liang@…>
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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/SymbolTable.cpp

    r2b78949 r8a930c03  
    1818#include <cassert>
    1919
     20#include "Copy.hpp"
    2021#include "Decl.hpp"
    2122#include "Expr.hpp"
     
    8788}
    8889
    89 SymbolTable::SymbolTable()
     90SymbolTable::SymbolTable( ErrorDetection errorMode )
    9091: idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(),
    91   prevScope(), scope( 0 ), repScope( 0 ) { ++*stats().count; }
     92  prevScope(), scope( 0 ), repScope( 0 ), errorMode(errorMode) { ++*stats().count; }
    9293
    9394SymbolTable::~SymbolTable() { stats().size->push( idTable ? idTable->size() : 0 ); }
     95
     96void 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}
    94103
    95104void SymbolTable::enterScope() {
     
    268277}
    269278
    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
     279bool SymbolTable::addedTypeConflicts(
     280                const NamedTypeDecl * existing, const NamedTypeDecl * added ) const {
     281        if ( existing->base == nullptr ) {
     282                return false;
     283        } else if ( added->base == nullptr ) {
    285284                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
     296bool 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;
    297304}
    298305
     
    642649        } else if ( existing.id->linkage.is_mangled
    643650                        || ResolvExpr::typesCompatible(
    644                                 added->get_type(), existing.id->get_type(), SymbolTable{} ) ) {
     651                                added->get_type(), existing.id->get_type() ) ) {
    645652
    646653                // it is a conflict if one declaration is deleted and the other is not
    647654                if ( deleter && ! existing.deleter ) {
    648655                        if ( handleConflicts.mode == OnConflict::Error ) {
    649                                 SemanticError( added, "deletion of defined identifier " );
     656                                OnFindError( added, "deletion of defined identifier " );
    650657                        }
    651658                        return true;
    652659                } else if ( ! deleter && existing.deleter ) {
    653660                        if ( handleConflicts.mode == OnConflict::Error ) {
    654                                 SemanticError( added, "definition of deleted identifier " );
     661                                OnFindError( added, "definition of deleted identifier " );
    655662                        }
    656663                        return true;
     
    660667                if ( isDefinition( added ) && isDefinition( existing.id ) ) {
    661668                        if ( handleConflicts.mode == OnConflict::Error ) {
    662                                 SemanticError( added,
     669                                OnFindError( added,
    663670                                        isFunction( added ) ?
    664671                                                "duplicate function definition for " :
     
    669676        } else {
    670677                if ( handleConflicts.mode == OnConflict::Error ) {
    671                         SemanticError( added, "duplicate definition for " );
     678                        OnFindError( added, "duplicate definition for " );
    672679                }
    673680                return true;
     
    721728                // Check that a Cforall declaration doesn't override any C declaration
    722729                if ( hasCompatibleCDecl( name, mangleName ) ) {
    723                         SemanticError( decl, "Cforall declaration hides C function " );
     730                        OnFindError( decl, "Cforall declaration hides C function " );
    724731                }
    725732        } else {
     
    727734                // type-compatibility, which it may not be.
    728735                if ( hasIncompatibleCDecl( name, mangleName ) ) {
    729                         SemanticError( decl, "conflicting overload of C function " );
     736                        OnFindError( decl, "conflicting overload of C function " );
    730737                }
    731738        }
Note: See TracChangeset for help on using the changeset viewer.