| [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 | //
|
|---|
| [c92bdcc] | 7 | // FindOpenVars.cpp --
|
|---|
| [a32b204] | 8 | //
|
|---|
| 9 | // Author : Richard C. Bilson
|
|---|
| 10 | // Created On : Sun May 17 09:42:48 2015
|
|---|
| [85dac33] | 11 | // Last Modified By : Andrew
|
|---|
| 12 | // Last Modified On : Fri Jul 12 14:18:00 2019
|
|---|
| 13 | // Update Count : 4
|
|---|
| [a32b204] | 14 | //
|
|---|
| [51b73452] | 15 |
|
|---|
| [c92bdcc] | 16 | #include "FindOpenVars.hpp"
|
|---|
| [ea6332d] | 17 |
|
|---|
| [9519aba] | 18 | #include "AST/Pass.hpp"
|
|---|
| 19 | #include "AST/Type.hpp"
|
|---|
| [46da46b] | 20 | #include "AST/TypeEnvironment.hpp"
|
|---|
| [51b73452] | 21 |
|
|---|
| [46da46b] | 22 | #include <iostream>
|
|---|
| 23 |
|
|---|
| [51b73452] | 24 | namespace ResolvExpr {
|
|---|
| [f474e91] | 25 |
|
|---|
| [2908f08] | 26 | namespace {
|
|---|
| 27 |
|
|---|
| 28 | struct FindOpenVars final : public ast::WithGuards {
|
|---|
| 29 | ast::OpenVarSet & open;
|
|---|
| 30 | ast::OpenVarSet & closed;
|
|---|
| 31 | ast::AssertionSet & need;
|
|---|
| 32 | ast::AssertionSet & have;
|
|---|
| 33 | ast::TypeEnvironment & env;
|
|---|
| 34 | bool nextIsOpen;
|
|---|
| 35 |
|
|---|
| 36 | FindOpenVars(
|
|---|
| 37 | ast::OpenVarSet & o, ast::OpenVarSet & c, ast::AssertionSet & n,
|
|---|
| 38 | ast::AssertionSet & h, ast::TypeEnvironment & env, FirstMode firstIsOpen )
|
|---|
| 39 | : open( o ), closed( c ), need( n ), have( h ), env (env), nextIsOpen( firstIsOpen ) {}
|
|---|
| 40 |
|
|---|
| 41 | void previsit( const ast::FunctionType * type ) {
|
|---|
| 42 | // mark open/closed variables
|
|---|
| 43 | if ( nextIsOpen ) {
|
|---|
| 44 | // trying to remove this from resolver.
|
|---|
| 45 | // occasionally used in other parts so not deleting right now.
|
|---|
| 46 |
|
|---|
| 47 | // insert open variables unbound to environment.
|
|---|
| 48 | env.add(type->forall);
|
|---|
| 49 |
|
|---|
| 50 | for ( auto & decl : type->forall ) {
|
|---|
| 51 | open[ *decl ] = ast::TypeData{ decl->base };
|
|---|
| 52 | }
|
|---|
| 53 | for ( auto & assert : type->assertions ) {
|
|---|
| 54 | need[ assert ].isUsed = false;
|
|---|
| [9519aba] | 55 | }
|
|---|
| [2908f08] | 56 | } else {
|
|---|
| 57 | for ( auto & decl : type->forall ) {
|
|---|
| 58 | closed[ *decl ] = ast::TypeData{ decl->base };
|
|---|
| 59 | }
|
|---|
| 60 | for ( auto & assert : type->assertions ) {
|
|---|
| 61 | have[ assert ].isUsed = false;
|
|---|
| 62 | }
|
|---|
| 63 | }
|
|---|
| [9519aba] | 64 |
|
|---|
| [2908f08] | 65 | // flip open variables for contained function types
|
|---|
| 66 | // nextIsOpen = ! nextIsOpen;
|
|---|
| 67 | // GuardAction( [this](){ nextIsOpen = ! nextIsOpen; } );
|
|---|
| 68 | GuardValue( nextIsOpen ) = !nextIsOpen;
|
|---|
| [9519aba] | 69 | }
|
|---|
| [2908f08] | 70 | };
|
|---|
| [9519aba] | 71 |
|
|---|
| [2908f08] | 72 | } // namespace
|
|---|
| [46da46b] | 73 |
|
|---|
| [2908f08] | 74 | void findOpenVars(
|
|---|
| 75 | const ast::Type * type, ast::OpenVarSet & open, ast::OpenVarSet & closed,
|
|---|
| 76 | ast::AssertionSet & need, ast::AssertionSet & have, ast::TypeEnvironment & env, FirstMode firstIsOpen ) {
|
|---|
| 77 | ast::Pass< FindOpenVars > finder{ open, closed, need, have, env, firstIsOpen };
|
|---|
| 78 | type->accept( finder );
|
|---|
| 79 |
|
|---|
| 80 | if (!closed.empty()) {
|
|---|
| 81 | std::cerr << "closed: ";
|
|---|
| 82 | for (auto& i : closed) {
|
|---|
| 83 | std::cerr << i.first.base->location << ":" << i.first.base->name << ' ';
|
|---|
| [46da46b] | 84 | }
|
|---|
| [2908f08] | 85 | std::cerr << std::endl;
|
|---|
| [f474e91] | 86 | }
|
|---|
| [2908f08] | 87 | }
|
|---|
| 88 |
|
|---|
| [51b73452] | 89 | } // namespace ResolvExpr
|
|---|
| [a32b204] | 90 |
|
|---|
| 91 | // Local Variables: //
|
|---|
| 92 | // tab-width: 4 //
|
|---|
| 93 | // mode: c++ //
|
|---|
| 94 | // compile-command: "make install" //
|
|---|
| 95 | // End: //
|
|---|