- Timestamp:
- Dec 16, 2015, 4:59:58 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 69911c11
- Parents:
- 0f889a77
- Location:
- src/GenPoly
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
r0f889a77 r7754cde 306 306 307 307 void Pass1::passTypeVars( ApplicationExpr *appExpr, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) { 308 // pass size/align for type variables 308 309 for ( TyVarMap::const_iterator tyParm = exprTyVars.begin(); tyParm != exprTyVars.end(); ++tyParm ) { 309 310 ResolvExpr::EqvClass eqvClass; … … 321 322 } // if 322 323 } // for 324 325 // add size/align for generic types to parameter list 326 //assert( ! appExpr->get_function()->get_results().empty() ); 327 if ( appExpr->get_function()->get_results().empty() ) return; 328 FunctionType *funcType = getFunctionType( appExpr->get_function()->get_results().front() ); 329 assert( funcType ); 330 331 std::list< DeclarationWithType* >::const_iterator fnParm = funcType->get_parameters().begin(); 332 std::list< Expression* >::const_iterator fnArg = arg; 333 std::set< std::string > seenTypes; //< sizeofName for generic types we've seen 334 for ( ; fnParm != funcType->get_parameters().end() && fnArg != appExpr->get_args().end(); ++fnParm, ++fnArg ) { 335 Type *parmType = (*fnParm)->get_type(); 336 if ( ! dynamic_cast< TypeInstType* >( parmType ) && isPolyType( parmType, exprTyVars ) ) { 337 std::string sizeName = sizeofName( parmType ); 338 if ( seenTypes.count( sizeName ) ) continue; 339 340 assert( ! (*fnArg)->get_results().empty() ); 341 Type *argType = (*fnArg)->get_results().front(); 342 arg = appExpr->get_args().insert( arg, new SizeofExpr( argType->clone() ) ); 343 arg++; 344 arg = appExpr->get_args().insert( arg, new AlignofExpr( argType->clone() ) ); 345 arg++; 346 347 seenTypes.insert( sizeName ); 348 } 349 } 323 350 } 324 351 … … 971 998 TyVarMap oldtyVars = scopeTyVars; 972 999 makeTyVarMap( funcType, scopeTyVars ); 973 1000 1001 // move polymorphic return type to parameter list 974 1002 std::string typeName; 975 1003 if ( isPolyRet( funcType, typeName ) ) { … … 979 1007 funcType->get_returnVals().pop_front(); 980 1008 } 981 1009 1010 // add size/align and assertions for type parameters to parameter list 982 1011 std::list< DeclarationWithType *>::iterator last = funcType->get_parameters().begin(); 983 1012 std::list< DeclarationWithType *> inferredParams; … … 1007 1036 (*tyParm)->get_assertions().clear(); 1008 1037 } 1038 1039 // add size/align for generic types to parameter list 1040 std::set< std::string > seenTypes; //< sizeofName for generic types we've seen 1041 for ( std::list< DeclarationWithType* >::const_iterator fnParm = last; fnParm != funcType->get_parameters().end(); ++fnParm ) { 1042 Type *parmType = (*fnParm)->get_type(); 1043 if ( ! dynamic_cast< TypeInstType* >( parmType ) && isPolyType( parmType, scopeTyVars ) ) { 1044 std::string sizeName = sizeofName( parmType ); 1045 if ( seenTypes.count( sizeName ) ) continue; 1046 1047 ObjectDecl *sizeParm, *alignParm; 1048 sizeParm = newObj.clone(); 1049 sizeParm->set_name( sizeName ); 1050 last = funcType->get_parameters().insert( last, sizeParm ); 1051 ++last; 1052 1053 alignParm = newObj.clone(); 1054 alignParm->set_name( alignofName( parmType ) ); 1055 last = funcType->get_parameters().insert( last, alignParm ); 1056 ++last; 1057 1058 seenTypes.insert( sizeName ); 1059 } 1060 } 1061 1062 // splice assertion parameters into parameter list 1009 1063 funcType->get_parameters().splice( last, inferredParams ); 1010 1064 addAdapters( funcType ); -
src/GenPoly/GenPoly.cc
r0f889a77 r7754cde 149 149 } 150 150 151 FunctionType * getFunctionType( Type *ty ) { 152 PointerType *ptrType; 153 if ( ( ptrType = dynamic_cast< PointerType* >( ty ) ) ) { 154 return dynamic_cast< FunctionType* >( ptrType->get_base() ); // pointer if FunctionType, NULL otherwise 155 } else { 156 return dynamic_cast< FunctionType* >( ty ); // pointer if FunctionType, NULL otherwise 157 } 158 } 159 151 160 void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ) { 152 161 for ( TyVarMap::const_iterator i = tyVarMap.begin(); i != tyVarMap.end(); ++i ) { -
src/GenPoly/GenPoly.h
r0f889a77 r7754cde 48 48 Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 ); 49 49 50 /// Returns a pointer to the base FunctionType if ty is the type of a function (or pointer to one), NULL otherwise 51 FunctionType * getFunctionType( Type *ty ); 52 50 53 /// Prints type variable map 51 54 void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ); -
src/GenPoly/ScrubTyVars.cc
r0f889a77 r7754cde 46 46 Expression * ScrubTyVars::mutate( SizeofExpr *szeof ) { 47 47 // sizeof( T ) => _sizeof_T parameter, which is the size of T 48 if ( Type InstType *typeInst = dynamic_cast< TypeInstType * >( szeof->get_type() ) ) {49 Expression *expr = new NameExpr( sizeofName( typeInst) );48 if ( Type *polyType = isPolyType( szeof->get_type() ) ) { 49 Expression *expr = new NameExpr( sizeofName( polyType ) ); 50 50 return expr; 51 51 } else { … … 56 56 Expression * ScrubTyVars::mutate( AlignofExpr *algnof ) { 57 57 // alignof( T ) => _alignof_T parameter, which is the alignment of T 58 if ( Type InstType *typeInst = dynamic_cast< TypeInstType * >( algnof->get_type() ) ) {59 Expression *expr = new NameExpr( alignofName( typeInst) );58 if ( Type *polyType = isPolyType( algnof->get_type() ) ) { 59 Expression *expr = new NameExpr( alignofName( polyType ) ); 60 60 return expr; 61 61 } else { -
src/GenPoly/Specialize.cc
r0f889a77 r7754cde 17 17 18 18 #include "Specialize.h" 19 #include "GenPoly.h" 19 20 #include "PolyMutator.h" 20 21 … … 87 88 } 88 89 89 /// Returns a pointer to the base FunctionType if ty is the type of a function (or pointer to one), NULL otherwise90 FunctionType * getFunctionType( Type *ty ) {91 PointerType *ptrType;92 if ( ( ptrType = dynamic_cast< PointerType* >( ty ) ) ) {93 return dynamic_cast< FunctionType* >( ptrType->get_base() ); // pointer if FunctionType, NULL otherwise94 } else {95 return dynamic_cast< FunctionType* >( ty ); // pointer if FunctionType, NULL otherwise96 }97 }98 99 90 /// Generates a thunk that calls `actual` with type `funType` and returns its address 100 91 Expression * Specialize::createThunkFunction( FunctionType *funType, Expression *actual, InferredParams *inferParams ) {
Note: See TracChangeset
for help on using the changeset viewer.