source: src/ResolvExpr/FindOpenVars.cc @ c6b4432

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

Remove BaseSyntaxNode? and clean-up.

  • Property mode set to 100644
File size: 2.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//
[8c49c0e]7// FindOpenVars.cc --
[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//
[51b7345]15
16#include "FindOpenVars.h"
[ea6332d]17
[9519aba]18#include "AST/Pass.hpp"
19#include "AST/Type.hpp"
[46da46b]20#include "AST/TypeEnvironment.hpp"
[51b7345]21
[46da46b]22#include <iostream>
23
[51b7345]24namespace ResolvExpr {
[f474e91]25
[9519aba]26        namespace {
27                struct FindOpenVars_new final : public ast::WithGuards {
28                        ast::OpenVarSet & open;
29                        ast::OpenVarSet & closed;
30                        ast::AssertionSet & need;
31                        ast::AssertionSet & have;
[46da46b]32                        ast::TypeEnvironment & env;
[9519aba]33                        bool nextIsOpen;
34
[85dac33]35                        FindOpenVars_new(
36                                ast::OpenVarSet & o, ast::OpenVarSet & c, ast::AssertionSet & n,
[46da46b]37                                ast::AssertionSet & h, ast::TypeEnvironment & env, FirstMode firstIsOpen )
38                        : open( o ), closed( c ), need( n ), have( h ), env (env), nextIsOpen( firstIsOpen ) {}
[9519aba]39
40                        void previsit( const ast::FunctionType * type ) {
41                                // mark open/closed variables
42                                if ( nextIsOpen ) {
[46da46b]43                                        // trying to remove this from resolver.
44                                        // occasionally used in other parts so not deleting right now.
45
46                                        // insert open variables unbound to environment.
47                                        env.add(type->forall);
48
[3e5dd913]49                                        for ( auto & decl : type->forall ) {
[93c10de]50                                                open[ *decl ] = ast::TypeData{ decl->base };
[3e5dd913]51                                        }
52                                        for ( auto & assert : type->assertions ) {
53                                                need[ assert ].isUsed = false;
[9519aba]54                                        }
55                                } else {
[3e5dd913]56                                        for ( auto & decl : type->forall ) {
[93c10de]57                                                closed[ *decl ] = ast::TypeData{ decl->base };
[3e5dd913]58                                        }
59                                        for ( auto & assert : type->assertions ) {
60                                                have[ assert ].isUsed = false;
[9519aba]61                                        }
62                                }
63
64                                // flip open variables for contained function types
65                                nextIsOpen = ! nextIsOpen;
66                                GuardAction( [this](){ nextIsOpen = ! nextIsOpen; } );
67                        }
68
69                };
70        }
71
[85dac33]72        void findOpenVars(
73                        const ast::Type * type, ast::OpenVarSet & open, ast::OpenVarSet & closed,
[46da46b]74                        ast::AssertionSet & need, ast::AssertionSet & have, ast::TypeEnvironment & env, FirstMode firstIsOpen ) {
75                ast::Pass< FindOpenVars_new > finder{ open, closed, need, have, env, firstIsOpen };
[9519aba]76                type->accept( finder );
[46da46b]77
78                if (!closed.empty()) {
79                        std::cerr << "closed: ";
80                        for (auto& i : closed) {
81                                std::cerr << i.first.base->location << ":" << i.first.base->name << ' ';
82                        }
83                        std::cerr << std::endl;
84                }
[f474e91]85        }
[51b7345]86} // namespace ResolvExpr
[a32b204]87
88// Local Variables: //
89// tab-width: 4 //
90// mode: c++ //
91// compile-command: "make install" //
92// End: //
Note: See TracBrowser for help on using the repository browser.