source: src/ResolvExpr/PolyCost.cc @ 0bd3faf

Last change on this file since 0bd3faf was 0bd3faf, checked in by Andrew Beach <ajbeach@…>, 8 months ago

Removed forward declarations missed in the BaseSyntaxNode? removal. Removed code and modified names to support two versions of the ast.

  • Property mode set to 100644
File size: 1.5 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//
[51b7345]15
[9d5089e]16#include "AST/SymbolTable.hpp"
[bccd70a]17#include "AST/Pass.hpp"
[9d5089e]18#include "AST/Type.hpp"
19#include "AST/TypeEnvironment.hpp"
[51b7345]20
21namespace ResolvExpr {
22
[0bd3faf]23class PolyCost {
[5aa4656]24        const ast::SymbolTable &symtab;
[9ea38de]25public:
26        int result;
[5aa4656]27        const ast::TypeEnvironment &env_;
28
[0bd3faf]29        PolyCost( const ast::SymbolTable & symtab, const ast::TypeEnvironment & env ) 
[9ea38de]30        : symtab( symtab ), result( 0 ), env_( env ) {}
[5aa4656]31
32        void previsit( const ast::TypeInstType * type ) {
[3e5dd913]33                if ( const ast::EqvClass * eqv = env_.lookup( *type ) ) /* && */ if ( eqv->bound ) {
[5aa4656]34                        if ( const ast::TypeInstType * otherType = eqv->bound.as< ast::TypeInstType >() ) {
35                                if ( symtab.lookupType( otherType->name ) ) {
36                                        // Bound to opaque type.
37                                        result += 1;
38                                }
39                        } else {
40                                // Bound to concrete type.
41                                result += 1;
42                        }
43                }
[9d5089e]44        }
[5aa4656]45};
46
47int polyCost(
48        const ast::Type * type, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env
49) {
[0bd3faf]50        ast::Pass<PolyCost> costing( symtab, env );
[5aa4656]51        type->accept( costing );
[fcd0b9d7]52        return (costing.core.result > 0) ? 1 : 0;
[5aa4656]53}
[9d5089e]54
[51b7345]55} // namespace ResolvExpr
[a32b204]56
57// Local Variables: //
58// tab-width: 4 //
59// mode: c++ //
60// compile-command: "make install" //
61// End: //
Note: See TracBrowser for help on using the repository browser.