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
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.cc --
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.h"
17
18#include "AST/Pass.hpp"
19#include "AST/Type.hpp"
20#include "AST/TypeEnvironment.hpp"
21
22#include <iostream>
23
24namespace ResolvExpr {
25
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;
32                        ast::TypeEnvironment & env;
33                        bool nextIsOpen;
34
35                        FindOpenVars_new(
36                                ast::OpenVarSet & o, ast::OpenVarSet & c, ast::AssertionSet & n,
37                                ast::AssertionSet & h, ast::TypeEnvironment & env, FirstMode firstIsOpen )
38                        : open( o ), closed( c ), need( n ), have( h ), env (env), nextIsOpen( firstIsOpen ) {}
39
40                        void previsit( const ast::FunctionType * type ) {
41                                // mark open/closed variables
42                                if ( nextIsOpen ) {
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
49                                        for ( auto & decl : type->forall ) {
50                                                open[ *decl ] = ast::TypeData{ decl->base };
51                                        }
52                                        for ( auto & assert : type->assertions ) {
53                                                need[ assert ].isUsed = false;
54                                        }
55                                } else {
56                                        for ( auto & decl : type->forall ) {
57                                                closed[ *decl ] = ast::TypeData{ decl->base };
58                                        }
59                                        for ( auto & assert : type->assertions ) {
60                                                have[ assert ].isUsed = false;
61                                        }
62                                }
63
64                                // flip open variables for contained function types
65                                nextIsOpen = ! nextIsOpen;
66                                GuardAction( [this](){ nextIsOpen = ! nextIsOpen; } );
67                        }
68
69                };
70        }
71
72        void findOpenVars(
73                        const ast::Type * type, ast::OpenVarSet & open, ast::OpenVarSet & closed,
74                        ast::AssertionSet & need, ast::AssertionSet & have, ast::TypeEnvironment & env, FirstMode firstIsOpen ) {
75                ast::Pass< FindOpenVars_new > finder{ open, closed, need, have, env, firstIsOpen };
76                type->accept( finder );
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                }
85        }
86} // namespace ResolvExpr
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.