Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/SymbolTable.cpp

    r251ce80 r4b8b2a4  
    1818#include <cassert>
    1919
    20 #include "Copy.hpp"
    2120#include "Decl.hpp"
    2221#include "Expr.hpp"
    2322#include "Inspect.hpp"
    2423#include "Type.hpp"
    25 #include "CodeGen/OperatorTable.h"         // for isCtorDtorAssign
     24#include "CodeGen/OperatorTable.h"  // for isCtorDtorAssign
    2625#include "Common/SemanticError.h"
    2726#include "Common/Stats/Counter.h"
     
    2928#include "InitTweak/InitTweak.h"
    3029#include "ResolvExpr/Cost.h"
    31 #include "ResolvExpr/CandidateFinder.hpp"  // for referenceToRvalueConversion
    32 #include "ResolvExpr/Unify.h"
     30#include "ResolvExpr/typeops.h"
    3331#include "SymTab/Mangler.h"
    3432
     
    7169        if ( baseExpr ) {
    7270                if (baseExpr->env) {
    73                         Expr * base = deepCopy(baseExpr);
     71                        Expr * base = shallowCopy(baseExpr);
    7472                        const TypeSubstitution * subs = baseExpr->env;
    7573                        base->env = nullptr;
     
    261259void SymbolTable::addId( const DeclWithType * decl, const Expr * baseExpr ) {
    262260        // default handling of conflicts is to raise an error
    263         addIdCommon( decl, OnConflict::error(), baseExpr, decl->isDeleted ? decl : nullptr );
     261        addId( decl, OnConflict::error(), baseExpr, decl->isDeleted ? decl : nullptr );
    264262}
    265263
    266264void SymbolTable::addDeletedId( const DeclWithType * decl, const Decl * deleter ) {
    267265        // default handling of conflicts is to raise an error
    268         addIdCommon( decl, OnConflict::error(), nullptr, deleter );
     266        addId( decl, OnConflict::error(), nullptr, deleter );
    269267}
    270268
     
    278276                } else {
    279277                        // typedef redeclarations are errors only if types are different
    280                         if ( ! ResolvExpr::typesCompatible( existing->base, added->base ) ) {
     278                        if ( ! ResolvExpr::typesCompatible( existing->base, added->base, SymbolTable{} ) ) {
    281279                                SemanticError( added->location, "redeclaration of " + added->name );
    282280                        }
     
    643641        } else if ( existing.id->linkage.is_mangled
    644642                        || ResolvExpr::typesCompatible(
    645                                 added->get_type(), existing.id->get_type() ) ) {
     643                                added->get_type(), existing.id->get_type(), SymbolTable{} ) ) {
    646644
    647645                // it is a conflict if one declaration is deleted and the other is not
     
    678676}
    679677
    680 void SymbolTable::addIdCommon(
    681                 const DeclWithType * decl, SymbolTable::OnConflict handleConflicts,
    682                 const Expr * baseExpr, const Decl * deleter ) {
     678void SymbolTable::addId(
     679                const DeclWithType * decl, SymbolTable::OnConflict handleConflicts, const Expr * baseExpr,
     680                const Decl * deleter ) {
    683681        SpecialFunctionKind kind = getSpecialFunctionKind(decl->name);
    684682        if (kind == NUMBER_OF_KINDS) { // not a special decl
    685                 addIdToTable(decl, decl->name, idTable, handleConflicts, baseExpr, deleter);
     683                addId(decl, decl->name, idTable, handleConflicts, baseExpr, deleter);
    686684        }
    687685        else {
     
    696694                        assertf(false, "special decl with non-function type");
    697695                }
    698                 addIdToTable(decl, key, specialFunctionTable[kind], handleConflicts, baseExpr, deleter);
    699         }
    700 }
    701 
    702 void SymbolTable::addIdToTable(
    703                 const DeclWithType * decl, const std::string & lookupKey,
    704                 IdTable::Ptr & table, SymbolTable::OnConflict handleConflicts,
    705                 const Expr * baseExpr, const Decl * deleter ) {
     696                addId(decl, key, specialFunctionTable[kind], handleConflicts, baseExpr, deleter);
     697        }
     698}
     699
     700void SymbolTable::addId(
     701                const DeclWithType * decl, const std::string & lookupKey, IdTable::Ptr & table, SymbolTable::OnConflict handleConflicts, const Expr * baseExpr,
     702                const Decl * deleter ) {
    706703        ++*stats().add_calls;
    707704        const std::string &name = decl->name;
     
    780777void SymbolTable::addMembers(
    781778                const AggregateDecl * aggr, const Expr * expr, SymbolTable::OnConflict handleConflicts ) {
    782         for ( const ptr<Decl> & decl : aggr->members ) {
    783                 auto dwt = decl.as<DeclWithType>();
    784                 if ( nullptr == dwt ) continue;
    785                 addIdCommon( dwt, handleConflicts, expr );
    786                 // Inline through unnamed struct/union members.
    787                 if ( "" != dwt->name ) continue;
    788                 const Type * t = dwt->get_type()->stripReferences();
    789                 if ( auto rty = dynamic_cast<const BaseInstType *>( t ) ) {
    790                         if ( ! dynamic_cast<const StructInstType *>(rty)
    791                                 && ! dynamic_cast<const UnionInstType *>(rty) ) continue;
    792                         ResolvExpr::Cost cost = ResolvExpr::Cost::zero;
    793                         ast::ptr<ast::TypeSubstitution> tmp = expr->env;
    794                         expr = mutate_field(expr, &Expr::env, nullptr);
    795                         const Expr * base = ResolvExpr::referenceToRvalueConversion( expr, cost );
    796                         base = mutate_field(base, &Expr::env, tmp);
    797 
    798                         addMembers(
    799                                 rty->aggr(), new MemberExpr{ base->location, dwt, base }, handleConflicts );
     779        for ( const Decl * decl : aggr->members ) {
     780                if ( auto dwt = dynamic_cast< const DeclWithType * >( decl ) ) {
     781                        addId( dwt, handleConflicts, expr );
     782                        if ( dwt->name == "" ) {
     783                                const Type * t = dwt->get_type()->stripReferences();
     784                                if ( auto rty = dynamic_cast<const BaseInstType *>( t ) ) {
     785                                        if ( ! dynamic_cast<const StructInstType *>(rty)
     786                                                && ! dynamic_cast<const UnionInstType *>(rty) ) continue;
     787                                        ResolvExpr::Cost cost = ResolvExpr::Cost::zero;
     788                                        ast::ptr<ast::TypeSubstitution> tmp = expr->env;
     789                                        expr = mutate_field(expr, &Expr::env, nullptr);
     790                                        const Expr * base = ResolvExpr::referenceToRvalueConversion( expr, cost );
     791                                        base = mutate_field(base, &Expr::env, tmp);
     792
     793                                        addMembers(
     794                                                rty->aggr(), new MemberExpr{ base->location, dwt, base }, handleConflicts );
     795                                }
     796                        }
    800797                }
    801798        }
Note: See TracChangeset for help on using the changeset viewer.