Changeset 30b65d8
- Timestamp:
- Nov 10, 2016, 4:16:32 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 8f9cc50
- Parents:
- b726084
- Location:
- src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/GenInit.cc
rb726084 r30b65d8 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
rb726084 r30b65d8 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 … … 397 397 } 398 398 399 void Resolver::resolveSingleAggrInit( Declaration * dcl, InitIterator & init, InitIterator & initEnd ) { 399 template< typename AggrInst > 400 TypeSubstitution makeGenericSubstitutuion( AggrInst * inst ) { 401 std::list< TypeDecl * > baseParams = *inst->get_baseParameters(); 402 std::list< Expression * > typeSubs = inst->get_parameters(); 403 TypeSubstitution subs( baseParams.begin(), baseParams.end(), typeSubs.begin() ); 404 return subs; 405 } 406 407 ReferenceToType * isStructOrUnion( Type * type ) { 408 if ( StructInstType * sit = dynamic_cast< StructInstType * >( type ) ) { 409 return sit; 410 } else if ( UnionInstType * uit = dynamic_cast< UnionInstType * >( type ) ) { 411 return uit; 412 } 413 return nullptr; 414 } 415 416 void Resolver::resolveSingleAggrInit( Declaration * dcl, InitIterator & init, InitIterator & initEnd, TypeSubstitution sub ) { 400 417 DeclarationWithType * dt = dynamic_cast< DeclarationWithType * >( dcl ); 401 418 assert( dt ); 402 initContext = dt->get_type(); 419 // need to substitute for generic types, so that casts are to concrete types 420 initContext = dt->get_type()->clone(); 421 sub.apply( initContext ); 422 403 423 try { 404 424 if ( init == initEnd ) return; // stop when there are no more initializers … … 407 427 } catch( SemanticError & ) { 408 428 // need to delve deeper, if you can 409 if ( StructInstType * sit = dynamic_cast< StructInstType * >( dt->get_type() ) ) { 410 resolveAggrInit( sit->get_baseStruct(), init, initEnd ); 411 } else if ( UnionInstType * uit = dynamic_cast< UnionInstType * >( dt->get_type() ) ) { 412 resolveAggrInit( uit->get_baseUnion(), init, initEnd ); 429 if ( ReferenceToType * type = isStructOrUnion( initContext ) ) { 430 resolveAggrInit( type, init, initEnd ); 413 431 } else { 414 432 // member is not an aggregate type, so can't go any deeper … … 420 438 } 421 439 422 void Resolver::resolveAggrInit( AggregateDecl * aggr, InitIterator & init, InitIterator & initEnd ) { 423 if ( StructDecl * st = dynamic_cast< StructDecl * >( aggr ) ) { 440 void Resolver::resolveAggrInit( ReferenceToType * inst, InitIterator & init, InitIterator & initEnd ) { 441 442 if ( StructInstType * sit = dynamic_cast< StructInstType * >( inst ) ) { 443 TypeSubstitution sub = makeGenericSubstitutuion( sit ); 444 StructDecl * st = sit->get_baseStruct(); 424 445 // want to resolve each initializer to the members of the struct, 425 446 // but if there are more initializers than members we should stop 426 447 list< Declaration * >::iterator it = st->get_members().begin(); 427 448 for ( ; it != st->get_members().end(); ++it) { 428 resolveSingleAggrInit( *it, init, initEnd );449 resolveSingleAggrInit( *it, init, initEnd, sub ); 429 450 } 430 } else if ( UnionDecl * un = dynamic_cast< UnionDecl * >( aggr ) ) { 451 } else if ( UnionInstType * uit = dynamic_cast< UnionInstType * >( inst ) ) { 452 TypeSubstitution sub = makeGenericSubstitutuion( sit ); 453 UnionDecl * un = uit->get_baseUnion(); 431 454 // only resolve to the first member of a union 432 resolveSingleAggrInit( *un->get_members().begin(), init, initEnd );455 resolveSingleAggrInit( *un->get_members().begin(), init, initEnd, sub ); 433 456 } // if 434 457 } … … 450 473 (*iter++)->accept( *this ); 451 474 } 452 } else if ( StructInstType * st = dynamic_cast< StructInstType * >( initContext ) ) { 453 resolveAggrInit( st->get_baseStruct(), iter, end ); 454 } else if ( UnionInstType * st = dynamic_cast< UnionInstType * >( initContext ) ) { 455 resolveAggrInit( st->get_baseUnion(), iter, end ); 475 } else if ( ReferenceToType * type = isStructOrUnion( initContext ) ) { 476 resolveAggrInit( type, iter, end ); 456 477 } else if ( TypeInstType * tt = dynamic_cast< TypeInstType * >( initContext ) ) { 457 478 Type * base = tt->get_baseType()->get_base();
Note: See TracChangeset
for help on using the changeset viewer.