| [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 |
|
|---|
| [9d5089e] | 16 | #include "AST/SymbolTable.hpp"
|
|---|
| 17 | #include "AST/Type.hpp"
|
|---|
| 18 | #include "AST/TypeEnvironment.hpp"
|
|---|
| [a180ded] | 19 | #include "Common/PassVisitor.h"
|
|---|
| [ea6332d] | 20 | #include "SymTab/Indexer.h" // for Indexer
|
|---|
| 21 | #include "SynTree/Type.h" // for TypeInstType, Type
|
|---|
| 22 | #include "TypeEnvironment.h" // for EqvClass, TypeEnvironment
|
|---|
| [51b73452] | 23 |
|
|---|
| 24 | namespace ResolvExpr {
|
|---|
| [a180ded] | 25 | struct PolyCost {
|
|---|
| [a32b204] | 26 | PolyCost( const TypeEnvironment &env, const SymTab::Indexer &indexer );
|
|---|
| [a180ded] | 27 |
|
|---|
| 28 | void previsit( TypeInstType * aggregateUseType );
|
|---|
| [a32b204] | 29 | int result;
|
|---|
| [a180ded] | 30 | const TypeEnvironment &tenv;
|
|---|
| [a32b204] | 31 | const SymTab::Indexer &indexer;
|
|---|
| 32 | };
|
|---|
| [51b73452] | 33 |
|
|---|
| [b0837e4] | 34 | int polyCost( Type *type, const TypeEnvironment & env, const SymTab::Indexer &indexer ) {
|
|---|
| [a180ded] | 35 | PassVisitor<PolyCost> coster( env, indexer );
|
|---|
| [a32b204] | 36 | type->accept( coster );
|
|---|
| [a180ded] | 37 | return coster.pass.result;
|
|---|
| [a32b204] | 38 | }
|
|---|
| [51b73452] | 39 |
|
|---|
| [a180ded] | 40 | PolyCost::PolyCost( const TypeEnvironment & env, const SymTab::Indexer & indexer ) : result( 0 ), tenv( env ), indexer( indexer ) {
|
|---|
| [a32b204] | 41 | }
|
|---|
| [51b73452] | 42 |
|
|---|
| [a180ded] | 43 | void PolyCost::previsit(TypeInstType * typeInst) {
|
|---|
| [00ac42e] | 44 | if ( const EqvClass *eqvClass = tenv.lookup( typeInst->name ) ) {
|
|---|
| 45 | if ( eqvClass->type ) {
|
|---|
| 46 | if ( TypeInstType * otherTypeInst = dynamic_cast< TypeInstType* >( eqvClass->type ) ) {
|
|---|
| [b0837e4] | 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 |
|
|---|
| [9d5089e] | 59 | int polyCost(
|
|---|
| 60 | const ast::Type * type, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env
|
|---|
| 61 | ) {
|
|---|
| 62 | #warning unimplemented
|
|---|
| 63 | (void)type; (void)symtab; (void)env;
|
|---|
| 64 | assert(false);
|
|---|
| 65 | return 0;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| [51b73452] | 68 | } // namespace ResolvExpr
|
|---|
| [a32b204] | 69 |
|
|---|
| 70 | // Local Variables: //
|
|---|
| 71 | // tab-width: 4 //
|
|---|
| 72 | // mode: c++ //
|
|---|
| 73 | // compile-command: "make install" //
|
|---|
| 74 | // End: //
|
|---|