[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 | // |
---|
| 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 | // |
---|
[51b7345] | 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 |
---|
[51b7345] | 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 | }; |
---|
[51b7345] | 32 | |
---|
[a32b204] | 33 | int polyCost( Type *type, const TypeEnvironment &env, const SymTab::Indexer &indexer ) { |
---|
| 34 | PolyCost coster( env, indexer ); |
---|
| 35 | type->accept( coster ); |
---|
| 36 | return coster.get_result(); |
---|
| 37 | } |
---|
[51b7345] | 38 | |
---|
[a32b204] | 39 | PolyCost::PolyCost( const TypeEnvironment &env, const SymTab::Indexer &indexer ) : result( 0 ), env( env ), indexer( indexer ) { |
---|
| 40 | } |
---|
[51b7345] | 41 | |
---|
[a32b204] | 42 | void PolyCost::visit(TypeInstType *typeInst) { |
---|
| 43 | EqvClass eqvClass; |
---|
| 44 | if ( env.lookup( typeInst->get_name(), eqvClass ) ) { |
---|
| 45 | if ( eqvClass.type ) { |
---|
| 46 | if ( TypeInstType *otherTypeInst = dynamic_cast< TypeInstType* >( eqvClass.type ) ) { |
---|
| 47 | if ( indexer.lookupType( otherTypeInst->get_name() ) ) { |
---|
| 48 | result += 1; |
---|
| 49 | } // if |
---|
| 50 | } else { |
---|
| 51 | result += 1; |
---|
| 52 | } // if |
---|
| 53 | } // if |
---|
| 54 | } // if |
---|
| 55 | } |
---|
[51b7345] | 56 | |
---|
| 57 | } // namespace ResolvExpr |
---|
[a32b204] | 58 | |
---|
| 59 | // Local Variables: // |
---|
| 60 | // tab-width: 4 // |
---|
| 61 | // mode: c++ // |
---|
| 62 | // compile-command: "make install" // |
---|
| 63 | // End: // |
---|