[51587aa] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
| 7 | // XXX.cc -- |
---|
| 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Mon May 18 07:44:20 2015 |
---|
| 11 | // Last Modified By : |
---|
| 12 | // Last Modified On : |
---|
| 13 | // Update Count : 0 |
---|
| 14 | // |
---|
[51b7345] | 15 | /* |
---|
| 16 | * This file is part of the Cforall project |
---|
| 17 | * |
---|
| 18 | * $Id: GenPoly.cc,v 1.4 2005/08/29 20:14:13 rcbilson Exp $ |
---|
| 19 | * |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | #include "GenPoly.h" |
---|
| 23 | #include "SynTree/Type.h" |
---|
| 24 | |
---|
[b1a6d6b] | 25 | #include <iostream> |
---|
| 26 | using namespace std; |
---|
[51b7345] | 27 | |
---|
| 28 | namespace GenPoly { |
---|
| 29 | |
---|
[b1a6d6b] | 30 | // interface functions |
---|
| 31 | bool isPolyVal( Type *type, const TyVarMap &tyVars ) { |
---|
| 32 | return isPolyVal( type, tyVars, false ); |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) { |
---|
| 36 | return needsAdapter( adaptee, tyVars, false ); |
---|
| 37 | } |
---|
| 38 | |
---|
[51b7345] | 39 | bool |
---|
[b1a6d6b] | 40 | isPolyVal( Type *type, const TyVarMap &tyVars, bool considerAllTyVars ) |
---|
[51b7345] | 41 | { |
---|
[a32b204] | 42 | if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( type ) ) { |
---|
| 43 | if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) { |
---|
[51b7345] | 44 | return true; |
---|
| 45 | } |
---|
[b1a6d6b] | 46 | return considerAllTyVars; |
---|
[51b7345] | 47 | } |
---|
| 48 | return false; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | // A function needs an adapter if it returns a polymorphic value or if any of its |
---|
| 52 | // parameters have polymorphic type |
---|
| 53 | bool |
---|
[b1a6d6b] | 54 | needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars, bool considerAllTyVars ) |
---|
[51b7345] | 55 | { |
---|
| 56 | bool needsAdapter = false; |
---|
[a32b204] | 57 | if ( ! adaptee->get_returnVals().empty() && isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars, considerAllTyVars ) ) { |
---|
[51b7345] | 58 | needsAdapter = true; |
---|
| 59 | } |
---|
[a32b204] | 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 ) ) { |
---|
[51b7345] | 62 | needsAdapter = true; |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | return needsAdapter; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | void |
---|
| 70 | printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ) |
---|
| 71 | { |
---|
[a32b204] | 72 | for ( TyVarMap::const_iterator i = tyVarMap.begin(); i != tyVarMap.end(); ++i ) { |
---|
[51b7345] | 73 | os << i->first << " (" << i->second << ") "; |
---|
| 74 | } |
---|
| 75 | os << std::endl; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | } // namespace GenPoly |
---|
[51587aa] | 79 | // Local Variables: // |
---|
| 80 | // tab-width: 4 // |
---|
| 81 | // mode: c++ // |
---|
| 82 | // compile-command: "make install" // |
---|
| 83 | // End: // |
---|