source: translator/GenPoly/GenPoly.cc @ 51587aa

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 51587aa was 51587aa, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

licencing: fourth groups of files

  • Property mode set to 100644
File size: 2.2 KB
Line 
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//
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
25#include <iostream>
26using namespace std;
27
28namespace GenPoly {
29
30// interface functions
31bool isPolyVal( Type *type, const TyVarMap &tyVars ) {
32  return isPolyVal( type, tyVars, false );
33}
34
35bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) { 
36  return needsAdapter( adaptee, tyVars, false );
37}
38
39bool
40isPolyVal( 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}
50
51// A function needs an adapter if it returns a polymorphic value or if any of its
52// parameters have polymorphic type
53bool
54needsAdapter( 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}
68
69void 
70printTyVarMap( 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 GenPoly
79// Local Variables: //
80// tab-width: 4 //
81// mode: c++ //
82// compile-command: "make install" //
83// End: //
Note: See TracBrowser for help on using the repository browser.