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