source: translator/ResolvExpr/PolyCost.cc @ a0d9f94

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 a0d9f94 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: PolyCost.cc,v 1.2 2005/08/29 20:14:16 rcbilson Exp $
5 *
6 */
7
8#include "typeops.h"
9#include "SynTree/Type.h"
10#include "SynTree/Visitor.h"
11#include "SymTab/Indexer.h"
12#include "TypeEnvironment.h"
13
14
15namespace ResolvExpr {
16
17class PolyCost : public Visitor
18{
19public:
20  PolyCost( const TypeEnvironment &env, const SymTab::Indexer &indexer );
21
22  int get_result() const { return result; }
23
24private:
25  virtual void visit(TypeInstType *aggregateUseType);
26 
27  int result;
28  const TypeEnvironment &env;
29  const SymTab::Indexer &indexer;
30};
31
32int
33polyCost( Type *type, const TypeEnvironment &env, const SymTab::Indexer &indexer )
34{
35  PolyCost coster( env, indexer );
36  type->accept( coster );
37  return coster.get_result();
38}
39
40PolyCost::PolyCost( const TypeEnvironment &env, const SymTab::Indexer &indexer )
41  : result( 0 ), env( env ), indexer( indexer )
42{
43}
44
45void 
46PolyCost::visit(TypeInstType *typeInst)
47{
48  EqvClass eqvClass;
49  if( env.lookup( typeInst->get_name(), eqvClass ) ) {
50    if( eqvClass.type ) {
51      if( TypeInstType *otherTypeInst = dynamic_cast< TypeInstType* >( eqvClass.type ) ) {
52        if( indexer.lookupType( otherTypeInst->get_name() ) ) {
53          result += 1;
54        }
55      } else {
56        result += 1;
57      }
58    }
59  }
60}
61
62} // namespace ResolvExpr
Note: See TracBrowser for help on using the repository browser.