Ignore:
Timestamp:
Jul 16, 2019, 10:38:32 AM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
6f15121
Parents:
7dc2e57b
Message:

WithStmt? is now a Declaration

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/SymbolTable.cpp

    r7dc2e57b re67991f  
    7373
    7474SymbolTable::SymbolTable()
    75 : idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(), 
     75: idTable(), typeTable(), structTable(), enumTable(), unionTable(), traitTable(),
    7676  prevScope(), scope( 0 ), repScope( 0 ) { ++*stats().count; }
    7777
     
    171171}
    172172
    173 void SymbolTable::addDeletedId( const DeclWithType * decl, const Node * deleter ) {
     173void SymbolTable::addDeletedId( const DeclWithType * decl, const Decl * deleter ) {
    174174        // default handling of conflicts is to raise an error
    175175        addId( decl, OnConflict::error(), nullptr, deleter );
     
    189189                        }
    190190                }
    191                 // does not need to be added to the table if both existing and added have a base that are 
     191                // does not need to be added to the table if both existing and added have a base that are
    192192                // the same
    193193                return true;
     
    209209        const std::string &id = decl->name;
    210210
    211         if ( ! typeTable ) { 
     211        if ( ! typeTable ) {
    212212                typeTable = TypeTable::new_ptr();
    213213        } else {
    214214                ++*stats().map_lookups;
    215215                auto existing = typeTable->find( id );
    216                 if ( existing != typeTable->end() 
    217                         && existing->second.scope == scope 
     216                if ( existing != typeTable->end()
     217                        && existing->second.scope == scope
    218218                        && addedTypeConflicts( existing->second.decl, decl ) ) return;
    219219        }
    220        
     220
    221221        lazyInitScope();
    222222        ++*stats().map_mutations;
     
    237237                ++*stats().map_lookups;
    238238                auto existing = structTable->find( id );
    239                 if ( existing != structTable->end() 
    240                         && existing->second.scope == scope 
     239                if ( existing != structTable->end()
     240                        && existing->second.scope == scope
    241241                        && addedDeclConflicts( existing->second.decl, decl ) ) return;
    242242        }
     
    256256                ++*stats().map_lookups;
    257257                auto existing = enumTable->find( id );
    258                 if ( existing != enumTable->end() 
    259                         && existing->second.scope == scope 
     258                if ( existing != enumTable->end()
     259                        && existing->second.scope == scope
    260260                        && addedDeclConflicts( existing->second.decl, decl ) ) return;
    261261        }
    262        
     262
    263263        lazyInitScope();
    264264        ++*stats().map_mutations;
     
    279279                ++*stats().map_lookups;
    280280                auto existing = unionTable->find( id );
    281                 if ( existing != unionTable->end() 
    282                         && existing->second.scope == scope 
     281                if ( existing != unionTable->end()
     282                        && existing->second.scope == scope
    283283                        && addedDeclConflicts( existing->second.decl, decl ) ) return;
    284284        }
     
    298298                ++*stats().map_lookups;
    299299                auto existing = traitTable->find( id );
    300                 if ( existing != traitTable->end() 
    301                         && existing->second.scope == scope 
     300                if ( existing != traitTable->end()
     301                        && existing->second.scope == scope
    302302                        && addedDeclConflicts( existing->second.decl, decl ) ) return;
    303303        }
     
    309309
    310310
    311 void SymbolTable::addWith( const std::vector< ptr<Expr> > & withExprs, const Node * withStmt ) {
     311void SymbolTable::addWith( const std::vector< ptr<Expr> > & withExprs, const Decl * withStmt ) {
    312312        for ( const Expr * expr : withExprs ) {
    313313                if ( ! expr->result ) continue;
    314314                const Type * resTy = expr->result->stripReferences();
    315315                auto aggrType = dynamic_cast< const ReferenceToType * >( resTy );
    316                 assertf( aggrType, "WithStmt expr has non-aggregate type: %s", 
     316                assertf( aggrType, "WithStmt expr has non-aggregate type: %s",
    317317                        toString( expr->result ).c_str() );
    318318                const AggregateDecl * aggr = aggrType->aggr();
    319                 assertf( aggr, "WithStmt has null aggregate from type: %s", 
     319                assertf( aggr, "WithStmt has null aggregate from type: %s",
    320320                        toString( expr->result ).c_str() );
    321                
     321
    322322                addMembers( aggr, expr, OnConflict::deleteWith( withStmt ) );
    323323        }
     
    373373        }
    374374
    375         /// gets the declaration for the function acting on a type specified by otype key, 
     375        /// gets the declaration for the function acting on a type specified by otype key,
    376376        /// nullptr if none such
    377         const FunctionDecl * getFunctionForOtype( 
     377        const FunctionDecl * getFunctionForOtype(
    378378                        const DeclWithType * decl, const std::string & otypeKey ) {
    379379                auto func = dynamic_cast< const FunctionDecl * >( decl );
     
    383383}
    384384
    385 bool SymbolTable::removeSpecialOverrides( 
     385bool SymbolTable::removeSpecialOverrides(
    386386                SymbolTable::IdData & data, SymbolTable::MangleTable::Ptr & mangleTable ) {
    387         // if a type contains user defined ctor/dtor/assign, then special rules trigger, which 
    388         // determine the set of ctor/dtor/assign that can be used  by the requester. In particular, 
    389         // if the user defines a default ctor, then the generated default ctor is unavailable, 
    390         // likewise for copy ctor and dtor. If the user defines any ctor/dtor, then no generated 
    391         // field ctors are available. If the user defines any ctor then the generated default ctor 
    392         // is unavailable (intrinsic default ctor must be overridden exactly). If the user defines 
    393         // anything that looks like a copy constructor, then the generated copy constructor is 
     387        // if a type contains user defined ctor/dtor/assign, then special rules trigger, which
     388        // determine the set of ctor/dtor/assign that can be used  by the requester. In particular,
     389        // if the user defines a default ctor, then the generated default ctor is unavailable,
     390        // likewise for copy ctor and dtor. If the user defines any ctor/dtor, then no generated
     391        // field ctors are available. If the user defines any ctor then the generated default ctor
     392        // is unavailable (intrinsic default ctor must be overridden exactly). If the user defines
     393        // anything that looks like a copy constructor, then the generated copy constructor is
    394394        // unavailable, and likewise for the assignment operator.
    395395
     
    450450                // if this is the first user-defined function, delete non-user-defined overloads
    451451                std::vector< MangleTable::value_type > deleted;
    452                
     452
    453453                for ( const auto& entry : *mangleTable ) {
    454454                        // skip decls that aren't functions or are for the wrong type
     
    489489                        if ( dataIsCopyFunc ) {
    490490                                // remove current function if exists a user-defined copy function
    491                                 // since the signatures for copy functions don't need to match exactly, using 
     491                                // since the signatures for copy functions don't need to match exactly, using
    492492                                // a delete statement is the wrong approach
    493493                                if ( InitTweak::isCopyFunction( decl ) ) return false;
     
    499499                }
    500500        }
    501        
     501
    502502        // nothing (more) to fix, return true
    503503        return true;
     
    525525
    526526bool SymbolTable::addedIdConflicts(
    527                 const SymbolTable::IdData & existing, const DeclWithType * added, 
    528                 SymbolTable::OnConflict handleConflicts, const Node * deleter ) {
    529         // if we're giving the same name mangling to things of different types then there is something 
     527                const SymbolTable::IdData & existing, const DeclWithType * added,
     528                SymbolTable::OnConflict handleConflicts, const Decl * deleter ) {
     529        // if we're giving the same name mangling to things of different types then there is something
    530530        // wrong
    531531        assert( (isObject( added ) && isObject( existing.id ) )
    532532                || ( isFunction( added ) && isFunction( existing.id ) ) );
    533        
     533
    534534        if ( existing.id->linkage.is_overrideable ) {
    535535                // new definition shadows the autogenerated one, even at the same scope
    536536                return false;
    537         } else if ( existing.id->linkage.is_mangled 
    538                         || ResolvExpr::typesCompatible( 
     537        } else if ( existing.id->linkage.is_mangled
     538                        || ResolvExpr::typesCompatible(
    539539                                added->get_type(), existing.id->get_type(), SymbolTable{} ) ) {
    540                
     540
    541541                // it is a conflict if one declaration is deleted and the other is not
    542542                if ( deleter && ! existing.deleter ) {
     
    555555                if ( isDefinition( added ) && isDefinition( existing.id ) ) {
    556556                        if ( handleConflicts.mode == OnConflict::Error ) {
    557                                 SemanticError( added, 
    558                                         isFunction( added ) ? 
    559                                                 "duplicate function definition for " : 
     557                                SemanticError( added,
     558                                        isFunction( added ) ?
     559                                                "duplicate function definition for " :
    560560                                                "duplicate object definition for " );
    561561                        }
     
    572572}
    573573
    574 void SymbolTable::addId( 
    575                 const DeclWithType * decl, SymbolTable::OnConflict handleConflicts, const Expr * baseExpr, 
    576                 const Node * deleter ) {
     574void SymbolTable::addId(
     575                const DeclWithType * decl, SymbolTable::OnConflict handleConflicts, const Expr * baseExpr,
     576                const Decl * deleter ) {
    577577        ++*stats().add_calls;
    578578        const std::string &name = decl->name;
     
    581581        std::string mangleName;
    582582        if ( decl->linkage.is_overrideable ) {
    583                 // mangle the name without including the appropriate suffix, so overridable routines 
     583                // mangle the name without including the appropriate suffix, so overridable routines
    584584                // are placed into the same "bucket" as their user defined versions.
    585585                mangleName = Mangle::mangle( decl, Mangle::Mode{ Mangle::NoOverrideable } );
     
    588588        }
    589589
    590         // this ensures that no two declarations with the same unmangled name at the same scope 
     590        // this ensures that no two declarations with the same unmangled name at the same scope
    591591        // both have C linkage
    592592        if ( decl->linkage.is_mangled ) {
     
    596596                }
    597597        } else {
    598                 // NOTE: only correct if name mangling is completely isomorphic to C 
     598                // NOTE: only correct if name mangling is completely isomorphic to C
    599599                // type-compatibility, which it may not be.
    600600                if ( hasIncompatibleCDecl( name, mangleName ) ) {
     
    628628                                                idTable = idTable->set(
    629629                                                        name,
    630                                                         mangleTable->set( 
    631                                                                 mangleName, 
     630                                                        mangleTable->set(
     631                                                                mangleName,
    632632                                                                IdData{ existing->second, handleConflicts.deleter } ) );
    633633                                        }
     
    647647}
    648648
    649 void SymbolTable::addMembers( 
     649void SymbolTable::addMembers(
    650650                const AggregateDecl * aggr, const Expr * expr, SymbolTable::OnConflict handleConflicts ) {
    651651        for ( const Decl * decl : aggr->members ) {
     
    655655                                const Type * t = dwt->get_type()->stripReferences();
    656656                                if ( auto rty = dynamic_cast<const ReferenceToType *>( t ) ) {
    657                                         if ( ! dynamic_cast<const StructInstType *>(rty) 
     657                                        if ( ! dynamic_cast<const StructInstType *>(rty)
    658658                                                && ! dynamic_cast<const UnionInstType *>(rty) ) continue;
    659659                                        ResolvExpr::Cost cost = ResolvExpr::Cost::zero;
    660660                                        const Expr * base = ResolvExpr::referenceToRvalueConversion( expr, cost );
    661                                         addMembers( 
     661                                        addMembers(
    662662                                                rty->aggr(), new MemberExpr{ base->location, dwt, base }, handleConflicts );
    663663                                }
     
    680680                if ( ! decl.second.id->linkage.is_mangled && decl.first == mangleName ) return true;
    681681        }
    682        
     682
    683683        return false;
    684684}
Note: See TracChangeset for help on using the changeset viewer.