source: src/ResolvExpr/PolyCost.cc @ 0873d22e

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumwith_gc
Last change on this file since 0873d22e was a180ded, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

Convert PolyCost? to PassVisitor?

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