/* * This file is part of the Cforall project * * $Id: PolyCost.cc,v 1.2 2005/08/29 20:14:16 rcbilson Exp $ * */ #include "typeops.h" #include "SynTree/Type.h" #include "SynTree/Visitor.h" #include "SymTab/Indexer.h" #include "TypeEnvironment.h" namespace ResolvExpr { class PolyCost : public Visitor { public: PolyCost( const TypeEnvironment &env, const SymTab::Indexer &indexer ); int get_result() const { return result; } private: virtual void visit(TypeInstType *aggregateUseType); int result; const TypeEnvironment &env; const SymTab::Indexer &indexer; }; int polyCost( Type *type, const TypeEnvironment &env, const SymTab::Indexer &indexer ) { PolyCost coster( env, indexer ); type->accept( coster ); return coster.get_result(); } PolyCost::PolyCost( const TypeEnvironment &env, const SymTab::Indexer &indexer ) : result( 0 ), env( env ), indexer( indexer ) { } void PolyCost::visit(TypeInstType *typeInst) { EqvClass eqvClass; if( env.lookup( typeInst->get_name(), eqvClass ) ) { if( eqvClass.type ) { if( TypeInstType *otherTypeInst = dynamic_cast< TypeInstType* >( eqvClass.type ) ) { if( indexer.lookupType( otherTypeInst->get_name() ) ) { result += 1; } } else { result += 1; } } } } } // namespace ResolvExpr