Changes in / [8f9cc50:668e971a]


Ignore:
Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/GenInit.cc

    r8f9cc50 r668e971a  
    246246                        }
    247247                }
    248                 // a type is managed if it appears in the map of known managed types, or if it contains any polymorphism (is a type variable or generic type containing a type variable)
    249                 return managedTypes.find( SymTab::Mangler::mangle( type ) ) != managedTypes.end() || GenPoly::isPolyType( type );
     248                return managedTypes.find( SymTab::Mangler::mangle( type ) ) != managedTypes.end();
    250249        }
    251250
  • src/ResolvExpr/Resolver.cc

    r8f9cc50 r668e971a  
    6666                void handlePtrType( PtrType * type );
    6767
    68           void resolveAggrInit( ReferenceToType *, InitIterator &, InitIterator & );
    69           void resolveSingleAggrInit( Declaration *, InitIterator &, InitIterator &, TypeSubstitution sub );
     68          void resolveAggrInit( AggregateDecl *, InitIterator &, InitIterator & );
     69          void resolveSingleAggrInit( Declaration *, InitIterator &, InitIterator & );
    7070          void fallbackInit( ConstructorInit * ctorInit );
    7171
     
    396396        }
    397397
    398         template< typename AggrInst >
    399         TypeSubstitution makeGenericSubstitutuion( AggrInst * inst ) {
    400                 std::list< TypeDecl * > baseParams = *inst->get_baseParameters();
    401                 std::list< Expression * > typeSubs = inst->get_parameters();
    402                 TypeSubstitution subs( baseParams.begin(), baseParams.end(), typeSubs.begin() );
    403                 return subs;
    404         }
    405 
    406         ReferenceToType * isStructOrUnion( Type * type ) {
    407                 if ( StructInstType * sit = dynamic_cast< StructInstType * >( type ) ) {
    408                         return sit;
    409                 } else if ( UnionInstType * uit = dynamic_cast< UnionInstType * >( type ) ) {
    410                         return uit;
    411                 }
    412                 return nullptr;
    413         }
    414 
    415         void Resolver::resolveSingleAggrInit( Declaration * dcl, InitIterator & init, InitIterator & initEnd, TypeSubstitution sub ) {
     398        void Resolver::resolveSingleAggrInit( Declaration * dcl, InitIterator & init, InitIterator & initEnd ) {
    416399                DeclarationWithType * dt = dynamic_cast< DeclarationWithType * >( dcl );
    417400                assert( dt );
    418                 // need to substitute for generic types, so that casts are to concrete types
    419                 initContext = dt->get_type()->clone();
    420                 sub.apply( initContext );
    421 
     401                initContext = dt->get_type();
    422402                try {
    423403                        if ( init == initEnd ) return; // stop when there are no more initializers
     
    426406                } catch( SemanticError & ) {
    427407                        // need to delve deeper, if you can
    428                         if ( ReferenceToType * type = isStructOrUnion( initContext ) ) {
    429                                 resolveAggrInit( type, init, initEnd );
     408                        if ( StructInstType * sit = dynamic_cast< StructInstType * >( dt->get_type() ) ) {
     409                                resolveAggrInit( sit->get_baseStruct(), init, initEnd );
     410                        } else if ( UnionInstType * uit = dynamic_cast< UnionInstType * >( dt->get_type() ) ) {
     411                                resolveAggrInit( uit->get_baseUnion(), init, initEnd );
    430412                        } else {
    431413                                // member is not an aggregate type, so can't go any deeper
     
    437419        }
    438420
    439         void Resolver::resolveAggrInit( ReferenceToType * inst, InitIterator & init, InitIterator & initEnd ) {
    440 
    441                 if ( StructInstType * sit = dynamic_cast< StructInstType * >( inst ) ) {
    442                         TypeSubstitution sub = makeGenericSubstitutuion( sit );
    443                         StructDecl * st = sit->get_baseStruct();
     421        void Resolver::resolveAggrInit( AggregateDecl * aggr, InitIterator & init, InitIterator & initEnd ) {
     422                if ( StructDecl * st = dynamic_cast< StructDecl * >( aggr ) ) {
    444423                        // want to resolve each initializer to the members of the struct,
    445424                        // but if there are more initializers than members we should stop
    446425                        list< Declaration * >::iterator it = st->get_members().begin();
    447426                        for ( ; it != st->get_members().end(); ++it) {
    448                                 resolveSingleAggrInit( *it, init, initEnd, sub );
     427                                resolveSingleAggrInit( *it, init, initEnd );
    449428                        }
    450                 } else if ( UnionInstType * uit = dynamic_cast< UnionInstType * >( inst ) ) {
    451                         TypeSubstitution sub = makeGenericSubstitutuion( sit );
    452                         UnionDecl * un = uit->get_baseUnion();
     429                } else if ( UnionDecl * un = dynamic_cast< UnionDecl * >( aggr ) ) {
    453430                        // only resolve to the first member of a union
    454                         resolveSingleAggrInit( *un->get_members().begin(), init, initEnd, sub );
     431                        resolveSingleAggrInit( *un->get_members().begin(), init, initEnd );
    455432                } // if
    456433        }
     
    472449                                (*iter++)->accept( *this );
    473450                        }
    474                 } else if ( ReferenceToType * type = isStructOrUnion( initContext ) ) {
    475                         resolveAggrInit( type, iter, end );
     451                } else if ( StructInstType * st = dynamic_cast< StructInstType * >( initContext ) ) {
     452                        resolveAggrInit( st->get_baseStruct(), iter, end );
     453                } else if ( UnionInstType * st = dynamic_cast< UnionInstType * >( initContext ) ) {
     454                        resolveAggrInit( st->get_baseUnion(), iter, end );
    476455                } else if ( TypeInstType * tt = dynamic_cast< TypeInstType * >( initContext ) ) {
    477456                        Type * base = tt->get_baseType()->get_base();
Note: See TracChangeset for help on using the changeset viewer.