source: src/ResolvExpr/PolyCost.cc@ 7faab5e

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 new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 7faab5e was b0837e4, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

Minor cleanup in conversion code

  • Property mode set to 100644
File size: 1.8 KB
Line 
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//
15
16#include "SymTab/Indexer.h" // for Indexer
17#include "SynTree/Type.h" // for TypeInstType, Type
18#include "SynTree/Visitor.h" // for Visitor
19#include "TypeEnvironment.h" // for EqvClass, TypeEnvironment
20
21namespace ResolvExpr {
22 class PolyCost : public Visitor {
23 public:
24 PolyCost( const TypeEnvironment &env, const SymTab::Indexer &indexer );
25 int get_result() const { return result; }
26 private:
27 virtual void visit(TypeInstType *aggregateUseType);
28 int result;
29 const TypeEnvironment &env;
30 const SymTab::Indexer &indexer;
31 };
32
33 int polyCost( Type *type, const TypeEnvironment & env, const SymTab::Indexer &indexer ) {
34 PolyCost coster( env, indexer );
35 type->accept( coster );
36 return coster.get_result();
37 }
38
39 PolyCost::PolyCost( const TypeEnvironment & env, const SymTab::Indexer & indexer ) : result( 0 ), env( env ), indexer( indexer ) {
40 }
41
42 void PolyCost::visit(TypeInstType * typeInst) {
43 EqvClass eqvClass;
44 if ( env.lookup( typeInst->name, eqvClass ) ) {
45 if ( eqvClass.type ) {
46 if ( TypeInstType * otherTypeInst = dynamic_cast< TypeInstType* >( eqvClass.type ) ) {
47 if ( indexer.lookupType( otherTypeInst->name ) ) {
48 // bound to opaque type
49 result += 1;
50 } // if
51 } else {
52 // bound to concrete type
53 result += 1;
54 } // if
55 } // if
56 } // if
57 }
58
59} // namespace ResolvExpr
60
61// Local Variables: //
62// tab-width: 4 //
63// mode: c++ //
64// compile-command: "make install" //
65// End: //
Note: See TracBrowser for help on using the repository browser.