aaron-thesisarm-ehcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change
on this file since b1a6d6b was
b1a6d6b,
checked in by Rob Schluntz <rschlunt@…>, 8 years ago
|
removed duplicate adapters, switch to c99 for initializer declarations
|
-
Property mode set to
100644
|
File size:
1.7 KB
|
Rev | Line | |
---|
[51b7345] | 1 | /* |
---|
| 2 | * This file is part of the Cforall project |
---|
| 3 | * |
---|
| 4 | * $Id: GenPoly.cc,v 1.4 2005/08/29 20:14:13 rcbilson Exp $ |
---|
| 5 | * |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #include "GenPoly.h" |
---|
| 9 | #include "SynTree/Type.h" |
---|
| 10 | |
---|
[b1a6d6b] | 11 | #include <iostream> |
---|
| 12 | using namespace std; |
---|
[51b7345] | 13 | |
---|
| 14 | namespace GenPoly { |
---|
| 15 | |
---|
[b1a6d6b] | 16 | // interface functions |
---|
| 17 | bool isPolyVal( Type *type, const TyVarMap &tyVars ) { |
---|
| 18 | return isPolyVal( type, tyVars, false ); |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) { |
---|
| 22 | return needsAdapter( adaptee, tyVars, false ); |
---|
| 23 | } |
---|
| 24 | |
---|
[51b7345] | 25 | bool |
---|
[b1a6d6b] | 26 | isPolyVal( Type *type, const TyVarMap &tyVars, bool considerAllTyVars ) |
---|
[51b7345] | 27 | { |
---|
| 28 | if( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( type ) ) { |
---|
| 29 | if( tyVars.find( typeInst->get_name() ) != tyVars.end() ) { |
---|
| 30 | return true; |
---|
| 31 | } |
---|
[b1a6d6b] | 32 | return considerAllTyVars; |
---|
[51b7345] | 33 | } |
---|
| 34 | return false; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | // A function needs an adapter if it returns a polymorphic value or if any of its |
---|
| 38 | // parameters have polymorphic type |
---|
| 39 | bool |
---|
[b1a6d6b] | 40 | needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars, bool considerAllTyVars ) |
---|
[51b7345] | 41 | { |
---|
| 42 | bool needsAdapter = false; |
---|
[b1a6d6b] | 43 | if( !adaptee->get_returnVals().empty() && isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars, considerAllTyVars ) ) { |
---|
[51b7345] | 44 | needsAdapter = true; |
---|
| 45 | } |
---|
| 46 | for( std::list< DeclarationWithType* >::const_iterator innerArg = adaptee->get_parameters().begin(); !needsAdapter && innerArg != adaptee->get_parameters().end(); ++innerArg ) { |
---|
[b1a6d6b] | 47 | if( isPolyVal( (*innerArg)->get_type(), tyVars, considerAllTyVars ) ) { |
---|
[51b7345] | 48 | needsAdapter = true; |
---|
| 49 | } |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | return needsAdapter; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | void |
---|
| 56 | printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ) |
---|
| 57 | { |
---|
| 58 | for( TyVarMap::const_iterator i = tyVarMap.begin(); i != tyVarMap.end(); ++i ) { |
---|
| 59 | os << i->first << " (" << i->second << ") "; |
---|
| 60 | } |
---|
| 61 | os << std::endl; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | } // namespace GenPoly |
---|
Note: See
TracBrowser
for help on using the repository browser.