ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change
on this file since 02e9ae2 was
51b7345,
checked in by Peter A. Buhr <pabuhr@…>, 10 years ago
|
initial commit
|
-
Property mode set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | /* |
---|
2 | * This file is part of the Cforall project |
---|
3 | * |
---|
4 | * $Id: PolyCost.cc,v 1.2 2005/08/29 20:14:16 rcbilson Exp $ |
---|
5 | * |
---|
6 | */ |
---|
7 | |
---|
8 | #include "typeops.h" |
---|
9 | #include "SynTree/Type.h" |
---|
10 | #include "SynTree/Visitor.h" |
---|
11 | #include "SymTab/Indexer.h" |
---|
12 | #include "TypeEnvironment.h" |
---|
13 | |
---|
14 | |
---|
15 | namespace ResolvExpr { |
---|
16 | |
---|
17 | class PolyCost : public Visitor |
---|
18 | { |
---|
19 | public: |
---|
20 | PolyCost( const TypeEnvironment &env, const SymTab::Indexer &indexer ); |
---|
21 | |
---|
22 | int get_result() const { return result; } |
---|
23 | |
---|
24 | private: |
---|
25 | virtual void visit(TypeInstType *aggregateUseType); |
---|
26 | |
---|
27 | int result; |
---|
28 | const TypeEnvironment &env; |
---|
29 | const SymTab::Indexer &indexer; |
---|
30 | }; |
---|
31 | |
---|
32 | int |
---|
33 | polyCost( Type *type, const TypeEnvironment &env, const SymTab::Indexer &indexer ) |
---|
34 | { |
---|
35 | PolyCost coster( env, indexer ); |
---|
36 | type->accept( coster ); |
---|
37 | return coster.get_result(); |
---|
38 | } |
---|
39 | |
---|
40 | PolyCost::PolyCost( const TypeEnvironment &env, const SymTab::Indexer &indexer ) |
---|
41 | : result( 0 ), env( env ), indexer( indexer ) |
---|
42 | { |
---|
43 | } |
---|
44 | |
---|
45 | void |
---|
46 | PolyCost::visit(TypeInstType *typeInst) |
---|
47 | { |
---|
48 | EqvClass eqvClass; |
---|
49 | if( env.lookup( typeInst->get_name(), eqvClass ) ) { |
---|
50 | if( eqvClass.type ) { |
---|
51 | if( TypeInstType *otherTypeInst = dynamic_cast< TypeInstType* >( eqvClass.type ) ) { |
---|
52 | if( indexer.lookupType( otherTypeInst->get_name() ) ) { |
---|
53 | result += 1; |
---|
54 | } |
---|
55 | } else { |
---|
56 | result += 1; |
---|
57 | } |
---|
58 | } |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | } // namespace ResolvExpr |
---|
Note: See
TracBrowser
for help on using the repository browser.