Changes in src/AST/SymbolTable.cpp [251ce80:4b8b2a4]
- File:
-
- 1 edited
-
src/AST/SymbolTable.cpp (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/SymbolTable.cpp
r251ce80 r4b8b2a4 18 18 #include <cassert> 19 19 20 #include "Copy.hpp"21 20 #include "Decl.hpp" 22 21 #include "Expr.hpp" 23 22 #include "Inspect.hpp" 24 23 #include "Type.hpp" 25 #include "CodeGen/OperatorTable.h" // for isCtorDtorAssign24 #include "CodeGen/OperatorTable.h" // for isCtorDtorAssign 26 25 #include "Common/SemanticError.h" 27 26 #include "Common/Stats/Counter.h" … … 29 28 #include "InitTweak/InitTweak.h" 30 29 #include "ResolvExpr/Cost.h" 31 #include "ResolvExpr/CandidateFinder.hpp" // for referenceToRvalueConversion 32 #include "ResolvExpr/Unify.h" 30 #include "ResolvExpr/typeops.h" 33 31 #include "SymTab/Mangler.h" 34 32 … … 71 69 if ( baseExpr ) { 72 70 if (baseExpr->env) { 73 Expr * base = deepCopy(baseExpr);71 Expr * base = shallowCopy(baseExpr); 74 72 const TypeSubstitution * subs = baseExpr->env; 75 73 base->env = nullptr; … … 261 259 void SymbolTable::addId( const DeclWithType * decl, const Expr * baseExpr ) { 262 260 // default handling of conflicts is to raise an error 263 addId Common( decl, OnConflict::error(), baseExpr, decl->isDeleted ? decl : nullptr );261 addId( decl, OnConflict::error(), baseExpr, decl->isDeleted ? decl : nullptr ); 264 262 } 265 263 266 264 void SymbolTable::addDeletedId( const DeclWithType * decl, const Decl * deleter ) { 267 265 // default handling of conflicts is to raise an error 268 addId Common( decl, OnConflict::error(), nullptr, deleter );266 addId( decl, OnConflict::error(), nullptr, deleter ); 269 267 } 270 268 … … 278 276 } else { 279 277 // 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{} ) ) { 281 279 SemanticError( added->location, "redeclaration of " + added->name ); 282 280 } … … 643 641 } else if ( existing.id->linkage.is_mangled 644 642 || ResolvExpr::typesCompatible( 645 added->get_type(), existing.id->get_type() ) ) {643 added->get_type(), existing.id->get_type(), SymbolTable{} ) ) { 646 644 647 645 // it is a conflict if one declaration is deleted and the other is not … … 678 676 } 679 677 680 void SymbolTable::addId Common(681 const DeclWithType * decl, SymbolTable::OnConflict handleConflicts, 682 const Expr * baseExpr, constDecl * deleter ) {678 void SymbolTable::addId( 679 const DeclWithType * decl, SymbolTable::OnConflict handleConflicts, const Expr * baseExpr, 680 const Decl * deleter ) { 683 681 SpecialFunctionKind kind = getSpecialFunctionKind(decl->name); 684 682 if (kind == NUMBER_OF_KINDS) { // not a special decl 685 addId ToTable(decl, decl->name, idTable, handleConflicts, baseExpr, deleter);683 addId(decl, decl->name, idTable, handleConflicts, baseExpr, deleter); 686 684 } 687 685 else { … … 696 694 assertf(false, "special decl with non-function type"); 697 695 } 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 700 void SymbolTable::addId( 701 const DeclWithType * decl, const std::string & lookupKey, IdTable::Ptr & table, SymbolTable::OnConflict handleConflicts, const Expr * baseExpr, 702 const Decl * deleter ) { 706 703 ++*stats().add_calls; 707 704 const std::string &name = decl->name; … … 780 777 void SymbolTable::addMembers( 781 778 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 } 800 797 } 801 798 }
Note:
See TracChangeset
for help on using the changeset viewer.