source: translator/GenPoly/GenPoly.cc @ 5c7fb6c

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 5c7fb6c was b1a6d6b, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

removed duplicate adapters, switch to c99 for initializer declarations

  • Property mode set to 100644
File size: 1.7 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#include <iostream>
12using namespace std;
13
14namespace GenPoly {
15
16// interface functions
17bool isPolyVal( Type *type, const TyVarMap &tyVars ) {
18  return isPolyVal( type, tyVars, false );
19}
20
21bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) { 
22  return needsAdapter( adaptee, tyVars, false );
23}
24
25bool
26isPolyVal( Type *type, const TyVarMap &tyVars, bool considerAllTyVars )
27{
28  if( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( type ) ) {
29    if( tyVars.find( typeInst->get_name() ) != tyVars.end() ) {
30      return true;
31    }
32    return considerAllTyVars;
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
39bool
40needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars, bool considerAllTyVars )
41{
42  bool needsAdapter = false;
43  if( !adaptee->get_returnVals().empty() && isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars, considerAllTyVars ) ) {
44    needsAdapter = true;
45  }
46  for( std::list< DeclarationWithType* >::const_iterator innerArg = adaptee->get_parameters().begin(); !needsAdapter && innerArg != adaptee->get_parameters().end(); ++innerArg ) {
47    if( isPolyVal( (*innerArg)->get_type(), tyVars, considerAllTyVars ) ) {
48      needsAdapter = true;
49    }
50  }
51 
52  return needsAdapter;
53}
54
55void 
56printTyVarMap( 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.