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