Changeset aadc9a4 for src/GenPoly
- Timestamp:
- Jan 12, 2016, 6:12:10 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:
- 4d7e8f5
- Parents:
- ebe9b3a
- Location:
- src/GenPoly
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
rebe9b3a raadc9a4 231 231 // process polymorphic return value 232 232 retval = 0; 233 std::string typeName; 234 if ( isPolyRet( functionDecl->get_functionType(), typeName ) && functionDecl->get_linkage() == LinkageSpec::Cforall ) { 233 if ( isPolyRet( functionDecl->get_functionType() ) && functionDecl->get_linkage() == LinkageSpec::Cforall ) { 235 234 retval = functionDecl->get_functionType()->get_returnVals().front(); 236 235 … … 787 786 std::list< Expression *>::iterator paramBegin = appExpr->get_args().begin(); 788 787 789 std::string typeName; 790 if ( isPolyRet( function, typeName ) ) { 791 ret = addPolyRetParam( appExpr, function, typeName, arg ); 788 if ( ReferenceToType *polyType = isPolyRet( function ) ) { 789 ret = addPolyRetParam( appExpr, function, polyType->get_name(), arg ); 792 790 } else if ( needsAdapter( function, scopeTyVars ) ) { 793 791 // std::cerr << "needs adapter: "; … … 994 992 995 993 // move polymorphic return type to parameter list 996 std::string typeName; 997 if ( isPolyRet( funcType, typeName ) ) { 994 if ( isPolyRet( funcType ) ) { 998 995 DeclarationWithType *ret = funcType->get_returnVals().front(); 999 996 ret->set_type( new PointerType( Type::Qualifiers(), ret->get_type() ) ); -
src/GenPoly/GenPoly.cc
rebe9b3a raadc9a4 36 36 } 37 37 38 bool isPolyRet( FunctionType *function, std::string &name, const TyVarMap &otherTyVars ) { 39 bool doTransform = false; 38 ReferenceToType *isPolyRet( FunctionType *function ) { 40 39 if ( ! function->get_returnVals().empty() ) { 41 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( function->get_returnVals().front()->get_type() ) ) { 42 43 // figure out if the return type is specified by a type parameter 44 for ( std::list< TypeDecl *>::const_iterator tyVar = function->get_forall().begin(); tyVar != function->get_forall().end(); ++tyVar ) { 45 if ( (*tyVar)->get_name() == typeInst->get_name() ) { 46 doTransform = true; 47 name = typeInst->get_name(); 48 break; 49 } // if 50 } // for 51 if ( ! doTransform && otherTyVars.find( typeInst->get_name() ) != otherTyVars.end() ) { 52 doTransform = true; 53 } // if 54 } // if 40 TyVarMap forallTypes; 41 makeTyVarMap( function, forallTypes ); 42 return (ReferenceToType*)isPolyType( function->get_returnVals().front()->get_type(), forallTypes ); 55 43 } // if 56 return doTransform; 57 } 58 59 bool isPolyRet( FunctionType *function, std::string &name ) { 60 TyVarMap dummyTyVars; 61 return isPolyRet( function, name, dummyTyVars ); 62 } 63 64 bool isPolyRet( FunctionType *function, const TyVarMap &otherTyVars ) { 65 std::string dummyString; 66 return isPolyRet( function, dummyString, otherTyVars ); 44 return 0; 67 45 } 68 46 … … 158 136 } 159 137 138 void makeTyVarMap( Type *type, TyVarMap &tyVarMap ) { 139 for ( std::list< TypeDecl* >::const_iterator tyVar = type->get_forall().begin(); tyVar != type->get_forall().end(); ++tyVar ) { 140 assert( *tyVar ); 141 tyVarMap[ (*tyVar)->get_name() ] = (*tyVar)->get_kind(); 142 } 143 if ( PointerType *pointer = dynamic_cast< PointerType* >( type ) ) { 144 makeTyVarMap( pointer->get_base(), tyVarMap ); 145 } 146 } 147 160 148 void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ) { 161 149 for ( TyVarMap::const_iterator i = tyVarMap.begin(); i != tyVarMap.end(); ++i ) { -
src/GenPoly/GenPoly.h
rebe9b3a raadc9a4 22 22 23 23 #include "SynTree/Declaration.h" 24 #include "SynTree/Type.h" 24 25 #include "SynTree/TypeSubstitution.h" 25 26 … … 32 33 33 34 /// true iff function has polymorphic return type 34 bool isPolyRet( FunctionType *function, std::string &name, const TyVarMap &otherTyVars ); 35 bool isPolyRet( FunctionType *function, std::string &name ); 36 bool isPolyRet( FunctionType *function, const TyVarMap &otherTyVars ); 35 ReferenceToType *isPolyRet( FunctionType *function ); 37 36 38 37 /// returns polymorphic type if is polymorphic type, NULL otherwise; will look up substitution in env if provided … … 51 50 FunctionType * getFunctionType( Type *ty ); 52 51 52 /// Adds the declarations in the forall list of type (and its pointed-to type if it's a pointer type) to `tyVarMap` 53 void makeTyVarMap( Type *type, TyVarMap &tyVarMap ); 54 53 55 /// Prints type variable map 54 56 void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ); -
src/GenPoly/PolyMutator.cc
rebe9b3a raadc9a4 152 152 } 153 153 154 155 /* static class method */156 void PolyMutator::makeTyVarMap( Type *type, TyVarMap &tyVarMap ) {157 for ( std::list< TypeDecl* >::const_iterator tyVar = type->get_forall().begin(); tyVar != type->get_forall().end(); ++tyVar ) {158 assert( *tyVar );159 tyVarMap[ (*tyVar)->get_name() ] = (*tyVar)->get_kind();160 }161 if ( PointerType *pointer = dynamic_cast< PointerType* >( type ) ) {162 makeTyVarMap( pointer->get_base(), tyVarMap );163 }164 }165 154 } // namespace GenPoly 166 155 -
src/GenPoly/PolyMutator.h
rebe9b3a raadc9a4 51 51 virtual void doBeginScope() {} 52 52 virtual void doEndScope() {} 53 54 static void makeTyVarMap( Type *type, TyVarMap &tyVarMap );55 53 protected: 56 54 void mutateStatementList( std::list< Statement* > &statements );
Note: See TracChangeset
for help on using the changeset viewer.