- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/InstantiateGeneric.cc
rb95fe40 r760ba67 27 27 #include "Common/utility.h" // for deleteAll, cloneAll 28 28 #include "GenPoly.h" // for isPolyType, typesPolyCompatible 29 #include "ResolvExpr/typeops.h"30 29 #include "ScopedSet.h" // for ScopedSet, ScopedSet<>::iterator 31 30 #include "ScrubTyVars.h" // for ScrubTyVars … … 152 151 return gt; 153 152 } 154 155 /// Add cast to dtype-static member expressions so that type information is not lost in GenericInstantiator156 struct FixDtypeStatic final {157 Expression * postmutate( MemberExpr * memberExpr );158 159 template<typename AggrInst>160 Expression * fixMemberExpr( AggrInst * inst, MemberExpr * memberExpr );161 };162 153 163 154 /// Mutator pass that replaces concrete instantiations of generic types with actual struct declarations, scoped appropriately … … 207 198 208 199 void instantiateGeneric( std::list< Declaration* > &translationUnit ) { 209 PassVisitor<FixDtypeStatic> fixer;210 200 PassVisitor<GenericInstantiator> instantiator; 211 212 mutateAll( translationUnit, fixer );213 201 mutateAll( translationUnit, instantiator ); 214 }215 216 bool isDtypeStatic( const std::list< TypeDecl* >& baseParams ) {217 return std::all_of( baseParams.begin(), baseParams.end(), []( TypeDecl * td ) { return ! td->isComplete(); } );218 202 } 219 203 … … 495 479 } 496 480 497 template< typename AggrInst >498 Expression * FixDtypeStatic::fixMemberExpr( AggrInst * inst, MemberExpr * memberExpr ) {499 // need to cast dtype-static member expressions to their actual type before that type is erased.500 auto & baseParams = *inst->get_baseParameters();501 if ( isDtypeStatic( baseParams ) ) {502 if ( ! ResolvExpr::typesCompatible( memberExpr->result, memberExpr->member->get_type(), SymTab::Indexer() ) ) {503 // type of member and type of expression differ, so add cast to actual type504 return new CastExpr( memberExpr, memberExpr->result->clone() );505 }506 }507 return memberExpr;508 }509 510 Expression * FixDtypeStatic::postmutate( MemberExpr * memberExpr ) {511 Type * aggrType = memberExpr->aggregate->result;512 if ( isGenericType( aggrType ) ) {513 if ( StructInstType * inst = dynamic_cast< StructInstType * >( aggrType ) ) {514 return fixMemberExpr( inst, memberExpr );515 } else if ( UnionInstType * inst = dynamic_cast< UnionInstType * >( aggrType ) ) {516 return fixMemberExpr( inst, memberExpr );517 }518 }519 return memberExpr;520 }521 522 481 } // namespace GenPoly 523 482
Note: See TracChangeset
for help on using the changeset viewer.