Ignore:
Timestamp:
Jun 19, 2023, 1:57:11 PM (2 years ago)
Author:
caparson <caparson@…>
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.
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/SymbolTable.cpp

    rfa5e1aa5 rb7b3e41  
    1919
    2020#include "Copy.hpp"
     21#include <iostream>
     22#include <algorithm>
     23
    2124#include "Decl.hpp"
    2225#include "Expr.hpp"
     
    8891}
    8992
    90 SymbolTable::SymbolTable()
     93SymbolTable::SymbolTable( ErrorDetection errorMode )
    9194: idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(),
    92   prevScope(), scope( 0 ), repScope( 0 ) { ++*stats().count; }
     95  prevScope(), scope( 0 ), repScope( 0 ), errorMode(errorMode) { ++*stats().count; }
    9396
    9497SymbolTable::~SymbolTable() { stats().size->push( idTable ? idTable->size() : 0 ); }
     98
     99void 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}
    95106
    96107void SymbolTable::enterScope() {
     
    195206                        out.push_back(decl.second);
    196207                }
     208
     209                // std::cerr << otypeKey << ' ' << out.size() << std::endl;
    197210        }
    198211
     
    269282}
    270283
    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
     284bool SymbolTable::addedTypeConflicts(
     285                const NamedTypeDecl * existing, const NamedTypeDecl * added ) const {
     286        if ( existing->base == nullptr ) {
     287                return false;
     288        } else if ( added->base == nullptr ) {
    286289                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
     301bool 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;
    298309}
    299310
     
    648659                if ( deleter && ! existing.deleter ) {
    649660                        if ( handleConflicts.mode == OnConflict::Error ) {
    650                                 SemanticError( added, "deletion of defined identifier " );
     661                                OnFindError( added, "deletion of defined identifier " );
    651662                        }
    652663                        return true;
    653664                } else if ( ! deleter && existing.deleter ) {
    654665                        if ( handleConflicts.mode == OnConflict::Error ) {
    655                                 SemanticError( added, "definition of deleted identifier " );
     666                                OnFindError( added, "definition of deleted identifier " );
    656667                        }
    657668                        return true;
     
    661672                if ( isDefinition( added ) && isDefinition( existing.id ) ) {
    662673                        if ( handleConflicts.mode == OnConflict::Error ) {
    663                                 SemanticError( added,
     674                                OnFindError( added,
    664675                                        isFunction( added ) ?
    665676                                                "duplicate function definition for " :
     
    670681        } else {
    671682                if ( handleConflicts.mode == OnConflict::Error ) {
    672                         SemanticError( added, "duplicate definition for " );
     683                        OnFindError( added, "duplicate definition for " );
    673684                }
    674685                return true;
     
    722733                // Check that a Cforall declaration doesn't override any C declaration
    723734                if ( hasCompatibleCDecl( name, mangleName ) ) {
    724                         SemanticError( decl, "Cforall declaration hides C function " );
     735                        OnFindError( decl, "Cforall declaration hides C function " );
    725736                }
    726737        } else {
     
    728739                // type-compatibility, which it may not be.
    729740                if ( hasIncompatibleCDecl( name, mangleName ) ) {
    730                         SemanticError( decl, "conflicting overload of C function " );
     741                        OnFindError( decl, "conflicting overload of C function " );
    731742                }
    732743        }
Note: See TracChangeset for help on using the changeset viewer.