source: src/ResolvExpr/PolyCost.cc @ 41606df1

Last change on this file since 41606df1 was 0bd3faf, checked in by Andrew Beach <ajbeach@…>, 6 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
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 : Andrew Beach
12// Last Modified On : Wed Jun 19 10:45:00 2019
13// Update Count     : 4
14//
15
16#include "AST/SymbolTable.hpp"
17#include "AST/Pass.hpp"
18#include "AST/Type.hpp"
19#include "AST/TypeEnvironment.hpp"
20
21namespace ResolvExpr {
22
23class PolyCost {
24        const ast::SymbolTable &symtab;
25public:
26        int result;
27        const ast::TypeEnvironment &env_;
28
29        PolyCost( const ast::SymbolTable & symtab, const ast::TypeEnvironment & env ) 
30        : symtab( symtab ), result( 0 ), env_( env ) {}
31
32        void previsit( const ast::TypeInstType * type ) {
33                if ( const ast::EqvClass * eqv = env_.lookup( *type ) ) /* && */ if ( eqv->bound ) {
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                }
44        }
45};
46
47int polyCost(
48        const ast::Type * type, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env
49) {
50        ast::Pass<PolyCost> costing( symtab, env );
51        type->accept( costing );
52        return (costing.core.result > 0) ? 1 : 0;
53}
54
55} // namespace ResolvExpr
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.