source: src/ResolvExpr/PolyCost.cc@ c5283ba

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr no_list persistent-indexer pthread-emulation qualifiedEnum
Last change on this file since c5283ba was 00ac42e, checked in by Aaron Moss <a3moss@…>, 7 years ago

stop eagerly copying EqvClass on lookup

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[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
21namespace 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) {
[00ac42e]41 if ( const EqvClass *eqvClass = tenv.lookup( typeInst->name ) ) {
42 if ( eqvClass->type ) {
43 if ( TypeInstType * otherTypeInst = dynamic_cast< TypeInstType* >( eqvClass->type ) ) {
[b0837e4]44 if ( indexer.lookupType( otherTypeInst->name ) ) {
45 // bound to opaque type
[a32b204]46 result += 1;
47 } // if
48 } else {
[b0837e4]49 // bound to concrete type
[a32b204]50 result += 1;
51 } // if
52 } // if
53 } // if
54 }
[51b73452]55
56} // namespace ResolvExpr
[a32b204]57
58// Local Variables: //
59// tab-width: 4 //
60// mode: c++ //
61// compile-command: "make install" //
62// End: //
Note: See TracBrowser for help on using the repository browser.