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 | // PolyCost.cc -- |
---|
8 | // |
---|
9 | // Author : Richard C. Bilson |
---|
10 | // Created On : Sun May 17 09:50:12 2015 |
---|
11 | // Last Modified By : Peter A. Buhr |
---|
12 | // Last Modified On : Sun May 17 09:52:02 2015 |
---|
13 | // Update Count : 3 |
---|
14 | // |
---|
15 | |
---|
16 | #include "Common/PassVisitor.h" |
---|
17 | #include "SymTab/Indexer.h" // for Indexer |
---|
18 | #include "SynTree/Type.h" // for TypeInstType, Type |
---|
19 | #include "TypeEnvironment.h" // for EqvClass, TypeEnvironment |
---|
20 | |
---|
21 | namespace ResolvExpr { |
---|
22 | struct PolyCost { |
---|
23 | PolyCost( const TypeEnvironment &env, const SymTab::Indexer &indexer ); |
---|
24 | |
---|
25 | void previsit( TypeInstType * aggregateUseType ); |
---|
26 | int result; |
---|
27 | const TypeEnvironment &tenv; |
---|
28 | const SymTab::Indexer &indexer; |
---|
29 | }; |
---|
30 | |
---|
31 | int polyCost( Type *type, const TypeEnvironment & env, const SymTab::Indexer &indexer ) { |
---|
32 | PassVisitor<PolyCost> coster( env, indexer ); |
---|
33 | type->accept( coster ); |
---|
34 | return coster.pass.result; |
---|
35 | } |
---|
36 | |
---|
37 | PolyCost::PolyCost( const TypeEnvironment & env, const SymTab::Indexer & indexer ) : result( 0 ), tenv( env ), indexer( indexer ) { |
---|
38 | } |
---|
39 | |
---|
40 | void PolyCost::previsit(TypeInstType * typeInst) { |
---|
41 | if ( const EqvClass *eqvClass = tenv.lookup( typeInst->name ) ) { |
---|
42 | if ( eqvClass->type ) { |
---|
43 | if ( TypeInstType * otherTypeInst = dynamic_cast< TypeInstType* >( eqvClass->type ) ) { |
---|
44 | if ( indexer.lookupType( otherTypeInst->name ) ) { |
---|
45 | // bound to opaque type |
---|
46 | result += 1; |
---|
47 | } // if |
---|
48 | } else { |
---|
49 | // bound to concrete type |
---|
50 | result += 1; |
---|
51 | } // if |
---|
52 | } // if |
---|
53 | } // if |
---|
54 | } |
---|
55 | |
---|
56 | } // namespace ResolvExpr |
---|
57 | |
---|
58 | // Local Variables: // |
---|
59 | // tab-width: 4 // |
---|
60 | // mode: c++ // |
---|
61 | // compile-command: "make install" // |
---|
62 | // End: // |
---|