source: src/ResolvExpr/FindOpenVars.cc @ 8b001bd

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 8b001bd was ce7ed2c, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Convert FindOpenVars? to PassVisitor?

  • Property mode set to 100644
File size: 3.9 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
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Sun May 17 09:45:25 2015
13// Update Count     : 3
14//
[51b7345]15
16#include "FindOpenVars.h"
[ea6332d]17
18#include <list>                   // for _List_const_iterator, list<>::const...
19#include <map>                    // for map<>::mapped_type
20
[ce7ed2c]21#include "Common/PassVisitor.h"
[ea6332d]22#include "SynTree/Declaration.h"  // for TypeDecl, DeclarationWithType (ptr ...
23#include "SynTree/Type.h"         // for Type, Type::ForallList, ArrayType
[51b7345]24
25namespace ResolvExpr {
[ce7ed2c]26        struct FindOpenVars : public WithGuards {
[a32b204]27                FindOpenVars( OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen );
28
[ce7ed2c]29                void previsit( PointerType * pointerType );
30                void previsit( ArrayType * arrayType );
31                void previsit( FunctionType * functionType );
32                void previsit( TupleType * tupleType );
[a32b204]33
34                void common_action( Type *type );
[51b7345]35
[a32b204]36                OpenVarSet &openVars, &closedVars;
37                AssertionSet &needAssertions, &haveAssertions;
38                bool nextIsOpen;
39        };
[51b7345]40
[a32b204]41        void findOpenVars( Type *type, OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen ) {
[ce7ed2c]42                PassVisitor<FindOpenVars> finder( openVars, closedVars, needAssertions, haveAssertions, firstIsOpen );
[a32b204]43                type->accept( finder );
44        }
[51b7345]45
[a32b204]46        FindOpenVars::FindOpenVars( OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen )
47                : openVars( openVars ), closedVars( closedVars ), needAssertions( needAssertions ), haveAssertions( haveAssertions ), nextIsOpen( firstIsOpen ) {
48        }
[51b7345]49
[a32b204]50        void FindOpenVars::common_action( Type *type ) {
51                if ( nextIsOpen ) {
[8c49c0e]52                        for ( Type::ForallList::const_iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) {
[2c57025]53                                openVars[ (*i)->get_name() ] = TypeDecl::Data{ (*i) };
[a32b204]54                                for ( std::list< DeclarationWithType* >::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) {
[6c3a988f]55                                        needAssertions[ *assert ].isUsed = false;
[a32b204]56                                }
[51b7345]57///       cloneAll( (*i)->get_assertions(), needAssertions );
58///       needAssertions.insert( needAssertions.end(), (*i)->get_assertions().begin(), (*i)->get_assertions().end() );
[a32b204]59                        }
60                } else {
[8c49c0e]61                        for ( Type::ForallList::const_iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) {
[2c57025]62                                closedVars[ (*i)->get_name() ] = TypeDecl::Data{ (*i) };
[a32b204]63                                for ( std::list< DeclarationWithType* >::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) {
[6c3a988f]64                                        haveAssertions[ *assert ].isUsed = false;
[a32b204]65                                }
[51b7345]66///       cloneAll( (*i)->get_assertions(), haveAssertions );
67///       haveAssertions.insert( haveAssertions.end(), (*i)->get_assertions().begin(), (*i)->get_assertions().end() );
[a32b204]68                        } // for
69                } // if
[ce7ed2c]70///   std::cerr << "type is ";
71///   type->print( std::cerr );
72///   std::cerr << std::endl << "need is" << std::endl;
73///   printAssertionSet( needAssertions, std::cerr );
74///   std::cerr << std::endl << "have is" << std::endl;
75///   printAssertionSet( haveAssertions, std::cerr );
[a32b204]76        }
[51b7345]77
[ce7ed2c]78        void FindOpenVars::previsit(PointerType *pointerType) {
[a32b204]79                common_action( pointerType );
80        }
[51b7345]81
[ce7ed2c]82        void FindOpenVars::previsit(ArrayType *arrayType) {
[a32b204]83                common_action( arrayType );
84        }
[51b7345]85
[ce7ed2c]86        void FindOpenVars::previsit(FunctionType *functionType) {
[a32b204]87                common_action( functionType );
88                nextIsOpen = ! nextIsOpen;
[ce7ed2c]89                GuardAction( [this](){ nextIsOpen = ! nextIsOpen; } );
[a32b204]90        }
[51b7345]91
[ce7ed2c]92        void FindOpenVars::previsit(TupleType *tupleType) {
[a32b204]93                common_action( tupleType );
94        }
[51b7345]95} // namespace ResolvExpr
[a32b204]96
97// Local Variables: //
98// tab-width: 4 //
99// mode: c++ //
100// compile-command: "make install" //
101// End: //
Note: See TracBrowser for help on using the repository browser.