[a32b204] | 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 | //
|
---|
[b0837e4] | 7 | // PolyCost.cc --
|
---|
[a32b204] | 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 | //
|
---|
[51b73452] | 15 |
|
---|
[ea6332d] | 16 | #include "SymTab/Indexer.h" // for Indexer
|
---|
| 17 | #include "SynTree/Type.h" // for TypeInstType, Type
|
---|
| 18 | #include "SynTree/Visitor.h" // for Visitor
|
---|
| 19 | #include "TypeEnvironment.h" // for EqvClass, TypeEnvironment
|
---|
[51b73452] | 20 |
|
---|
| 21 | namespace ResolvExpr {
|
---|
[a32b204] | 22 | class PolyCost : public Visitor {
|
---|
| 23 | public:
|
---|
| 24 | PolyCost( const TypeEnvironment &env, const SymTab::Indexer &indexer );
|
---|
| 25 | int get_result() const { return result; }
|
---|
| 26 | private:
|
---|
| 27 | virtual void visit(TypeInstType *aggregateUseType);
|
---|
| 28 | int result;
|
---|
| 29 | const TypeEnvironment &env;
|
---|
| 30 | const SymTab::Indexer &indexer;
|
---|
| 31 | };
|
---|
[51b73452] | 32 |
|
---|
[b0837e4] | 33 | int polyCost( Type *type, const TypeEnvironment & env, const SymTab::Indexer &indexer ) {
|
---|
[a32b204] | 34 | PolyCost coster( env, indexer );
|
---|
| 35 | type->accept( coster );
|
---|
| 36 | return coster.get_result();
|
---|
| 37 | }
|
---|
[51b73452] | 38 |
|
---|
[b0837e4] | 39 | PolyCost::PolyCost( const TypeEnvironment & env, const SymTab::Indexer & indexer ) : result( 0 ), env( env ), indexer( indexer ) {
|
---|
[a32b204] | 40 | }
|
---|
[51b73452] | 41 |
|
---|
[b0837e4] | 42 | void PolyCost::visit(TypeInstType * typeInst) {
|
---|
[a32b204] | 43 | EqvClass eqvClass;
|
---|
[b0837e4] | 44 | if ( env.lookup( typeInst->name, eqvClass ) ) {
|
---|
[a32b204] | 45 | if ( eqvClass.type ) {
|
---|
[b0837e4] | 46 | if ( TypeInstType * otherTypeInst = dynamic_cast< TypeInstType* >( eqvClass.type ) ) {
|
---|
| 47 | if ( indexer.lookupType( otherTypeInst->name ) ) {
|
---|
| 48 | // bound to opaque type
|
---|
[a32b204] | 49 | result += 1;
|
---|
| 50 | } // if
|
---|
| 51 | } else {
|
---|
[b0837e4] | 52 | // bound to concrete type
|
---|
[a32b204] | 53 | result += 1;
|
---|
| 54 | } // if
|
---|
| 55 | } // if
|
---|
| 56 | } // if
|
---|
| 57 | }
|
---|
[51b73452] | 58 |
|
---|
| 59 | } // namespace ResolvExpr
|
---|
[a32b204] | 60 |
|
---|
| 61 | // Local Variables: //
|
---|
| 62 | // tab-width: 4 //
|
---|
| 63 | // mode: c++ //
|
---|
| 64 | // compile-command: "make install" //
|
---|
| 65 | // End: //
|
---|