Changes in / [668e971a:8f9cc50]
- Location:
- src
- Files:
-
- 2 edited
-
InitTweak/GenInit.cc (modified) (1 diff)
-
ResolvExpr/Resolver.cc (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/GenInit.cc
r668e971a r8f9cc50 246 246 } 247 247 } 248 return managedTypes.find( SymTab::Mangler::mangle( type ) ) != managedTypes.end(); 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 ); 249 250 } 250 251 -
src/ResolvExpr/Resolver.cc
r668e971a r8f9cc50 66 66 void handlePtrType( PtrType * type ); 67 67 68 void resolveAggrInit( AggregateDecl*, InitIterator &, InitIterator & );69 void resolveSingleAggrInit( Declaration *, InitIterator &, InitIterator & );68 void resolveAggrInit( ReferenceToType *, InitIterator &, InitIterator & ); 69 void resolveSingleAggrInit( Declaration *, InitIterator &, InitIterator &, TypeSubstitution sub ); 70 70 void fallbackInit( ConstructorInit * ctorInit ); 71 71 … … 396 396 } 397 397 398 void Resolver::resolveSingleAggrInit( Declaration * dcl, InitIterator & init, InitIterator & initEnd ) { 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 ) { 399 416 DeclarationWithType * dt = dynamic_cast< DeclarationWithType * >( dcl ); 400 417 assert( dt ); 401 initContext = dt->get_type(); 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 402 422 try { 403 423 if ( init == initEnd ) return; // stop when there are no more initializers … … 406 426 } catch( SemanticError & ) { 407 427 // need to delve deeper, if you can 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 ); 428 if ( ReferenceToType * type = isStructOrUnion( initContext ) ) { 429 resolveAggrInit( type, init, initEnd ); 412 430 } else { 413 431 // member is not an aggregate type, so can't go any deeper … … 419 437 } 420 438 421 void Resolver::resolveAggrInit( AggregateDecl * aggr, InitIterator & init, InitIterator & initEnd ) { 422 if ( StructDecl * st = dynamic_cast< StructDecl * >( aggr ) ) { 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(); 423 444 // want to resolve each initializer to the members of the struct, 424 445 // but if there are more initializers than members we should stop 425 446 list< Declaration * >::iterator it = st->get_members().begin(); 426 447 for ( ; it != st->get_members().end(); ++it) { 427 resolveSingleAggrInit( *it, init, initEnd );448 resolveSingleAggrInit( *it, init, initEnd, sub ); 428 449 } 429 } else if ( UnionDecl * un = dynamic_cast< UnionDecl * >( aggr ) ) { 450 } else if ( UnionInstType * uit = dynamic_cast< UnionInstType * >( inst ) ) { 451 TypeSubstitution sub = makeGenericSubstitutuion( sit ); 452 UnionDecl * un = uit->get_baseUnion(); 430 453 // only resolve to the first member of a union 431 resolveSingleAggrInit( *un->get_members().begin(), init, initEnd );454 resolveSingleAggrInit( *un->get_members().begin(), init, initEnd, sub ); 432 455 } // if 433 456 } … … 449 472 (*iter++)->accept( *this ); 450 473 } 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 ); 474 } else if ( ReferenceToType * type = isStructOrUnion( initContext ) ) { 475 resolveAggrInit( type, iter, end ); 455 476 } else if ( TypeInstType * tt = dynamic_cast< TypeInstType * >( initContext ) ) { 456 477 Type * base = tt->get_baseType()->get_base();
Note:
See TracChangeset
for help on using the changeset viewer.