source: src/ResolvExpr/FindOpenVars.cpp@ 718601e

Last change on this file since 718601e was c92bdcc, checked in by Andrew Beach <ajbeach@…>, 17 months ago

Updated the rest of the names in src/ (except for the generated files).

  • Property mode set to 100644
File size: 2.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// FindOpenVars.cpp --
8//
9// Author : Richard C. Bilson
10// Created On : Sun May 17 09:42:48 2015
11// Last Modified By : Andrew
12// Last Modified On : Fri Jul 12 14:18:00 2019
13// Update Count : 4
14//
15
16#include "FindOpenVars.hpp"
17
18#include "AST/Pass.hpp"
19#include "AST/Type.hpp"
20#include "AST/TypeEnvironment.hpp"
21
22#include <iostream>
23
24namespace ResolvExpr {
25
26namespace {
27
28struct 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;
55 }
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 }
64
65 // flip open variables for contained function types
66 // nextIsOpen = ! nextIsOpen;
67 // GuardAction( [this](){ nextIsOpen = ! nextIsOpen; } );
68 GuardValue( nextIsOpen ) = !nextIsOpen;
69 }
70};
71
72} // namespace
73
74void 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 << ' ';
84 }
85 std::cerr << std::endl;
86 }
87}
88
89} // namespace ResolvExpr
90
91// Local Variables: //
92// tab-width: 4 //
93// mode: c++ //
94// compile-command: "make install" //
95// End: //
Note: See TracBrowser for help on using the repository browser.