Changes in src/ResolvExpr/Resolver.cc [30b65d8:5f5083e]
- File:
-
- 1 edited
-
src/ResolvExpr/Resolver.cc (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Resolver.cc
r30b65d8 r5f5083e 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 72 72 Type * functionReturn = nullptr; 73 73 Type *initContext = nullptr; 74 Type *switchType = nullptr;75 74 bool inEnumDecl = false; 76 75 }; … … 397 396 } 398 397 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 ) { 398 void Resolver::resolveSingleAggrInit( Declaration * dcl, InitIterator & init, InitIterator & initEnd ) { 417 399 DeclarationWithType * dt = dynamic_cast< DeclarationWithType * >( dcl ); 418 400 assert( dt ); 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 401 initContext = dt->get_type(); 423 402 try { 424 403 if ( init == initEnd ) return; // stop when there are no more initializers … … 427 406 } catch( SemanticError & ) { 428 407 // need to delve deeper, if you can 429 if ( ReferenceToType * type = isStructOrUnion( initContext ) ) { 430 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 ); 431 412 } else { 432 413 // member is not an aggregate type, so can't go any deeper … … 438 419 } 439 420 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(); 421 void Resolver::resolveAggrInit( AggregateDecl * aggr, InitIterator & init, InitIterator & initEnd ) { 422 if ( StructDecl * st = dynamic_cast< StructDecl * >( aggr ) ) { 445 423 // want to resolve each initializer to the members of the struct, 446 424 // but if there are more initializers than members we should stop 447 425 list< Declaration * >::iterator it = st->get_members().begin(); 448 426 for ( ; it != st->get_members().end(); ++it) { 449 resolveSingleAggrInit( *it, init, initEnd , sub);427 resolveSingleAggrInit( *it, init, initEnd ); 450 428 } 451 } else if ( UnionInstType * uit = dynamic_cast< UnionInstType * >( inst ) ) { 452 TypeSubstitution sub = makeGenericSubstitutuion( sit ); 453 UnionDecl * un = uit->get_baseUnion(); 429 } else if ( UnionDecl * un = dynamic_cast< UnionDecl * >( aggr ) ) { 454 430 // only resolve to the first member of a union 455 resolveSingleAggrInit( *un->get_members().begin(), init, initEnd , sub);431 resolveSingleAggrInit( *un->get_members().begin(), init, initEnd ); 456 432 } // if 457 433 } … … 473 449 (*iter++)->accept( *this ); 474 450 } 475 } else if ( ReferenceToType * type = isStructOrUnion( initContext ) ) { 476 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 ); 477 455 } else if ( TypeInstType * tt = dynamic_cast< TypeInstType * >( initContext ) ) { 478 456 Type * base = tt->get_baseType()->get_base();
Note:
See TracChangeset
for help on using the changeset viewer.