source: src/ResolvExpr/PolyCost.cc @ be9288a

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since be9288a was ea6332d, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Big header cleaning pass - commit 3

  • 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->get_name(), eqvClass ) ) {
45                        if ( eqvClass.type ) {
46                                if ( TypeInstType *otherTypeInst = dynamic_cast< TypeInstType* >( eqvClass.type ) ) {
47                                        if ( indexer.lookupType( otherTypeInst->get_name() ) ) {
48                                                result += 1;
49                                        } // if
50                                } else {
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.