source: src/ResolvExpr/PolyCost.cc@ f5ec35a

Last change on this file since f5ec35a was c6b4432, checked in by Andrew Beach <ajbeach@…>, 2 years ago

Remove BaseSyntaxNode and clean-up.

  • Property mode set to 100644
File size: 1.6 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
[5aa4656]11// Last Modified By : Andrew Beach
12// Last Modified On : Wed Jun 19 10:45:00 2019
13// Update Count : 4
[a32b204]14//
[51b73452]15
[9d5089e]16#include "AST/SymbolTable.hpp"
[bccd70a]17#include "AST/Pass.hpp"
[9d5089e]18#include "AST/Type.hpp"
19#include "AST/TypeEnvironment.hpp"
[51b73452]20
21namespace ResolvExpr {
22
[5aa4656]23// TODO: When the old PolyCost is torn out get rid of the _new suffix.
[9ea38de]24class PolyCost_new {
[5aa4656]25 const ast::SymbolTable &symtab;
[9ea38de]26public:
27 int result;
[5aa4656]28 const ast::TypeEnvironment &env_;
29
[9ea38de]30 PolyCost_new( const ast::SymbolTable & symtab, const ast::TypeEnvironment & env )
31 : symtab( symtab ), result( 0 ), env_( env ) {}
[5aa4656]32
33 void previsit( const ast::TypeInstType * type ) {
[3e5dd913]34 if ( const ast::EqvClass * eqv = env_.lookup( *type ) ) /* && */ if ( eqv->bound ) {
[5aa4656]35 if ( const ast::TypeInstType * otherType = eqv->bound.as< ast::TypeInstType >() ) {
36 if ( symtab.lookupType( otherType->name ) ) {
37 // Bound to opaque type.
38 result += 1;
39 }
40 } else {
41 // Bound to concrete type.
42 result += 1;
43 }
44 }
[9d5089e]45 }
[5aa4656]46};
47
48int polyCost(
49 const ast::Type * type, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env
50) {
51 ast::Pass<PolyCost_new> costing( symtab, env );
52 type->accept( costing );
[fcd0b9d7]53 return (costing.core.result > 0) ? 1 : 0;
[5aa4656]54}
[9d5089e]55
[51b73452]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.