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 | EqvClass eqvClass;
|
---|
42 | if ( tenv.lookup( typeInst->name, eqvClass ) ) {
|
---|
43 | if ( eqvClass.type ) {
|
---|
44 | if ( TypeInstType * otherTypeInst = dynamic_cast< TypeInstType* >( eqvClass.type ) ) {
|
---|
45 | if ( indexer.lookupType( otherTypeInst->name ) ) {
|
---|
46 | // bound to opaque type
|
---|
47 | result += 1;
|
---|
48 | } // if
|
---|
49 | } else {
|
---|
50 | // bound to concrete type
|
---|
51 | result += 1;
|
---|
52 | } // if
|
---|
53 | } // if
|
---|
54 | } // if
|
---|
55 | }
|
---|
56 |
|
---|
57 | } // namespace ResolvExpr
|
---|
58 |
|
---|
59 | // Local Variables: //
|
---|
60 | // tab-width: 4 //
|
---|
61 | // mode: c++ //
|
---|
62 | // compile-command: "make install" //
|
---|
63 | // End: //
|
---|