Changeset a32b204 for translator/ResolvExpr/PolyCost.cc
- Timestamp:
- May 17, 2015, 1:19:35 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 0dd3a2f
- Parents:
- b87a5ed
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/ResolvExpr/PolyCost.cc
rb87a5ed ra32b204 1 /* 2 * This file is part of the Cforall project 3 * 4 * $Id: PolyCost.cc,v 1.2 2005/08/29 20:14:16 rcbilson Exp $ 5 * 6 */ 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 // 7 15 8 16 #include "typeops.h" … … 12 20 #include "TypeEnvironment.h" 13 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 }; 14 33 15 namespace ResolvExpr { 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 } 16 39 17 class PolyCost : public Visitor 18 { 19 public: 20 PolyCost( const TypeEnvironment &env, const SymTab::Indexer &indexer ); 40 PolyCost::PolyCost( const TypeEnvironment &env, const SymTab::Indexer &indexer ) : result( 0 ), env( env ), indexer( indexer ) { 41 } 21 42 22 int get_result() const { return result; } 23 24 private: 25 virtual void visit(TypeInstType *aggregateUseType); 26 27 int result; 28 const TypeEnvironment &env; 29 const SymTab::Indexer &indexer; 30 }; 31 32 int 33 polyCost( Type *type, const TypeEnvironment &env, const SymTab::Indexer &indexer ) 34 { 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 ) 41 : result( 0 ), env( env ), indexer( indexer ) 42 { 43 } 44 45 void 46 PolyCost::visit(TypeInstType *typeInst) 47 { 48 EqvClass eqvClass; 49 if( env.lookup( typeInst->get_name(), eqvClass ) ) { 50 if( eqvClass.type ) { 51 if( TypeInstType *otherTypeInst = dynamic_cast< TypeInstType* >( eqvClass.type ) ) { 52 if( indexer.lookupType( otherTypeInst->get_name() ) ) { 53 result += 1; 54 } 55 } else { 56 result += 1; 57 } 58 } 59 } 60 } 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 } 61 57 62 58 } // namespace ResolvExpr 59 60 // Local Variables: // 61 // tab-width: 4 // 62 // mode: c++ // 63 // compile-command: "make install" // 64 // End: //
Note: See TracChangeset
for help on using the changeset viewer.