| 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 : Andrew Beach
 | 
|---|
| 12 | // Last Modified On : Wed Jun 19 10:45:00 2019
 | 
|---|
| 13 | // Update Count     : 4
 | 
|---|
| 14 | //
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #include "AST/SymbolTable.hpp"
 | 
|---|
| 17 | #include "AST/Pass.hpp"
 | 
|---|
| 18 | #include "AST/Type.hpp"
 | 
|---|
| 19 | #include "AST/TypeEnvironment.hpp"
 | 
|---|
| 20 | 
 | 
|---|
| 21 | namespace ResolvExpr {
 | 
|---|
| 22 | 
 | 
|---|
| 23 | namespace {
 | 
|---|
| 24 | 
 | 
|---|
| 25 | class PolyCost {
 | 
|---|
| 26 |         const ast::SymbolTable &symtab;
 | 
|---|
| 27 | public:
 | 
|---|
| 28 |         int result;
 | 
|---|
| 29 |         const ast::TypeEnvironment &env_;
 | 
|---|
| 30 | 
 | 
|---|
| 31 |         PolyCost( const ast::SymbolTable & symtab, const ast::TypeEnvironment & env ) 
 | 
|---|
| 32 |         : symtab( symtab ), result( 0 ), env_( env ) {}
 | 
|---|
| 33 | 
 | 
|---|
| 34 |         void previsit( const ast::TypeInstType * type ) {
 | 
|---|
| 35 |                 if ( const ast::EqvClass * eqv = env_.lookup( *type ) ) /* && */ if ( eqv->bound ) {
 | 
|---|
| 36 |                         if ( const ast::TypeInstType * otherType = eqv->bound.as< ast::TypeInstType >() ) {
 | 
|---|
| 37 |                                 if ( symtab.lookupType( otherType->name ) ) {
 | 
|---|
| 38 |                                         // Bound to opaque type.
 | 
|---|
| 39 |                                         result += 1;
 | 
|---|
| 40 |                                 }
 | 
|---|
| 41 |                         } else {
 | 
|---|
| 42 |                                 // Bound to concrete type.
 | 
|---|
| 43 |                                 result += 1;
 | 
|---|
| 44 |                         }
 | 
|---|
| 45 |                 }
 | 
|---|
| 46 |         }
 | 
|---|
| 47 | };
 | 
|---|
| 48 | 
 | 
|---|
| 49 | } // namespace
 | 
|---|
| 50 | 
 | 
|---|
| 51 | int polyCost(
 | 
|---|
| 52 |         const ast::Type * type, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env
 | 
|---|
| 53 | ) {
 | 
|---|
| 54 |         ast::Pass<PolyCost> costing( symtab, env );
 | 
|---|
| 55 |         type->accept( costing );
 | 
|---|
| 56 |         return (costing.core.result > 0) ? 1 : 0;
 | 
|---|
| 57 | }
 | 
|---|
| 58 | 
 | 
|---|
| 59 | } // namespace ResolvExpr
 | 
|---|
| 60 | 
 | 
|---|
| 61 | // Local Variables: //
 | 
|---|
| 62 | // tab-width: 4 //
 | 
|---|
| 63 | // mode: c++ //
 | 
|---|
| 64 | // compile-command: "make install" //
 | 
|---|
| 65 | // End: //
 | 
|---|