ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change
on this file since 02e9ae2 was
51b7345,
checked in by Peter A. Buhr <pabuhr@…>, 10 years ago
|
initial commit
|
-
Property mode set to
100644
|
File size:
1.3 KB
|
Line | |
---|
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 | |
---|
11 | |
---|
12 | namespace GenPoly { |
---|
13 | |
---|
14 | bool |
---|
15 | isPolyVal( Type *type, const TyVarMap &tyVars ) |
---|
16 | { |
---|
17 | if( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( type ) ) { |
---|
18 | if( tyVars.find( typeInst->get_name() ) != tyVars.end() ) { |
---|
19 | return true; |
---|
20 | } |
---|
21 | } |
---|
22 | return false; |
---|
23 | } |
---|
24 | |
---|
25 | // A function needs an adapter if it returns a polymorphic value or if any of its |
---|
26 | // parameters have polymorphic type |
---|
27 | bool |
---|
28 | needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) |
---|
29 | { |
---|
30 | bool needsAdapter = false; |
---|
31 | if( !adaptee->get_returnVals().empty() && isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars ) ) { |
---|
32 | needsAdapter = true; |
---|
33 | } |
---|
34 | for( std::list< DeclarationWithType* >::const_iterator innerArg = adaptee->get_parameters().begin(); !needsAdapter && innerArg != adaptee->get_parameters().end(); ++innerArg ) { |
---|
35 | if( isPolyVal( (*innerArg)->get_type(), tyVars ) ) { |
---|
36 | needsAdapter = true; |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | return needsAdapter; |
---|
41 | } |
---|
42 | |
---|
43 | void |
---|
44 | printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ) |
---|
45 | { |
---|
46 | for( TyVarMap::const_iterator i = tyVarMap.begin(); i != tyVarMap.end(); ++i ) { |
---|
47 | os << i->first << " (" << i->second << ") "; |
---|
48 | } |
---|
49 | os << std::endl; |
---|
50 | } |
---|
51 | |
---|
52 | } // namespace GenPoly |
---|
Note: See
TracBrowser
for help on using the repository browser.