Changeset 01aeade for translator/GenPoly/GenPoly.cc
- Timestamp:
- May 19, 2015, 7:57:09 AM (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:
- a08ba92
- Parents:
- 51587aa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/GenPoly/GenPoly.cc
r51587aa r01aeade 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // GenPoly.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 07:37:46 2015 13 // Update Count : 1 14 14 // 15 /*16 * This file is part of the Cforall project17 *18 * $Id: GenPoly.cc,v 1.4 2005/08/29 20:14:13 rcbilson Exp $19 *20 */21 15 22 16 #include "GenPoly.h" … … 27 21 28 22 namespace GenPoly { 23 // interface functions 24 bool isPolyVal( Type *type, const TyVarMap &tyVars ) { 25 return isPolyVal( type, tyVars, false ); 26 } 29 27 30 // interface functions 31 bool isPolyVal( Type *type, const TyVarMap &tyVars ) { 32 return isPolyVal( type, tyVars, false ); 33 } 28 bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) { 29 return needsAdapter( adaptee, tyVars, false ); 30 } 34 31 35 bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) { 36 return needsAdapter( adaptee, tyVars, false ); 37 } 32 bool isPolyVal( Type *type, const TyVarMap &tyVars, bool considerAllTyVars ) { 33 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( type ) ) { 34 if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) { 35 return true; 36 } // if 37 return considerAllTyVars; 38 } // if 39 return false; 40 } 38 41 39 bool 40 isPolyVal( Type *type, const TyVarMap &tyVars, bool considerAllTyVars ) 41 { 42 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( type ) ) { 43 if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) { 44 return true; 45 } 46 return considerAllTyVars; 47 } 48 return false; 49 } 42 // A function needs an adapter if it returns a polymorphic value or if any of its 43 // parameters have polymorphic type 44 bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars, bool considerAllTyVars ) { 45 bool needsAdapter = false; 46 if ( ! adaptee->get_returnVals().empty() && isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars, considerAllTyVars ) ) { 47 needsAdapter = true; 48 } // if 49 for ( std::list< DeclarationWithType* >::const_iterator innerArg = adaptee->get_parameters().begin(); ! needsAdapter && innerArg != adaptee->get_parameters().end(); ++innerArg ) { 50 if ( isPolyVal( (*innerArg)->get_type(), tyVars, considerAllTyVars ) ) { 51 needsAdapter = true; 52 } // if 53 } // for 54 return needsAdapter; 55 } 50 56 51 // A function needs an adapter if it returns a polymorphic value or if any of its 52 // parameters have polymorphic type 53 bool 54 needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars, bool considerAllTyVars ) 55 { 56 bool needsAdapter = false; 57 if ( ! adaptee->get_returnVals().empty() && isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars, considerAllTyVars ) ) { 58 needsAdapter = true; 59 } 60 for ( std::list< DeclarationWithType* >::const_iterator innerArg = adaptee->get_parameters().begin(); ! needsAdapter && innerArg != adaptee->get_parameters().end(); ++innerArg ) { 61 if ( isPolyVal( (*innerArg)->get_type(), tyVars, considerAllTyVars ) ) { 62 needsAdapter = true; 63 } 64 } 65 66 return needsAdapter; 67 } 57 void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ) { 58 for ( TyVarMap::const_iterator i = tyVarMap.begin(); i != tyVarMap.end(); ++i ) { 59 os << i->first << " (" << i->second << ") "; 60 } // for 61 os << std::endl; 62 } 63 } // namespace GenPoly 68 64 69 void70 printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap )71 {72 for ( TyVarMap::const_iterator i = tyVarMap.begin(); i != tyVarMap.end(); ++i ) {73 os << i->first << " (" << i->second << ") ";74 }75 os << std::endl;76 }77 78 } // namespace GenPoly79 65 // Local Variables: // 80 66 // tab-width: 4 //
Note: See TracChangeset
for help on using the changeset viewer.