Changes in / [8f9cc50:668e971a]
- 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
r8f9cc50 r668e971a 246 246 } 247 247 } 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(); 250 249 } 251 250 -
src/ResolvExpr/Resolver.cc
r8f9cc50 r668e971a 66 66 void handlePtrType( PtrType * type ); 67 67 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 & ); 70 70 void fallbackInit( ConstructorInit * ctorInit ); 71 71 … … 396 396 } 397 397 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 ) { 416 399 DeclarationWithType * dt = dynamic_cast< DeclarationWithType * >( dcl ); 417 400 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(); 422 402 try { 423 403 if ( init == initEnd ) return; // stop when there are no more initializers … … 426 406 } catch( SemanticError & ) { 427 407 // 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 ); 430 412 } else { 431 413 // member is not an aggregate type, so can't go any deeper … … 437 419 } 438 420 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 ) ) { 444 423 // want to resolve each initializer to the members of the struct, 445 424 // but if there are more initializers than members we should stop 446 425 list< Declaration * >::iterator it = st->get_members().begin(); 447 426 for ( ; it != st->get_members().end(); ++it) { 448 resolveSingleAggrInit( *it, init, initEnd , sub);427 resolveSingleAggrInit( *it, init, initEnd ); 449 428 } 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 ) ) { 453 430 // 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 ); 455 432 } // if 456 433 } … … 472 449 (*iter++)->accept( *this ); 473 450 } 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 ); 476 455 } else if ( TypeInstType * tt = dynamic_cast< TypeInstType * >( initContext ) ) { 477 456 Type * base = tt->get_baseType()->get_base();
Note:
See TracChangeset
for help on using the changeset viewer.