source: src/ResolvExpr/FindOpenVars.cc @ 0982a05

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resnenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexerpthread-emulationqualifiedEnum
Last change on this file since 0982a05 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
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 : Peter A. Buhr
12// Last Modified On : Sun May 17 09:45:25 2015
13// Update Count     : 3
14//
15
16#include "FindOpenVars.h"
17
18#include <list>                   // for _List_const_iterator, list<>::const...
19#include <map>                    // for map<>::mapped_type
20
21#include "Common/PassVisitor.h"
22#include "SynTree/Declaration.h"  // for TypeDecl, DeclarationWithType (ptr ...
23#include "SynTree/Type.h"         // for Type, Type::ForallList, ArrayType
24
25namespace ResolvExpr {
26        struct FindOpenVars : public WithGuards {
27                FindOpenVars( OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen );
28
29                void previsit( PointerType * pointerType );
30                void previsit( ArrayType * arrayType );
31                void previsit( FunctionType * functionType );
32                void previsit( TupleType * tupleType );
33
34                void common_action( Type *type );
35
36                OpenVarSet &openVars, &closedVars;
37                AssertionSet &needAssertions, &haveAssertions;
38                bool nextIsOpen;
39        };
40
41        void findOpenVars( Type *type, OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen ) {
42                PassVisitor<FindOpenVars> finder( openVars, closedVars, needAssertions, haveAssertions, firstIsOpen );
43                type->accept( finder );
44        }
45
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        }
49
50        void FindOpenVars::common_action( Type *type ) {
51                if ( nextIsOpen ) {
52                        for ( Type::ForallList::const_iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) {
53                                openVars[ (*i)->get_name() ] = TypeDecl::Data{ (*i) };
54                                for ( std::list< DeclarationWithType* >::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) {
55                                        needAssertions[ *assert ].isUsed = false;
56                                }
57///       cloneAll( (*i)->get_assertions(), needAssertions );
58///       needAssertions.insert( needAssertions.end(), (*i)->get_assertions().begin(), (*i)->get_assertions().end() );
59                        }
60                } else {
61                        for ( Type::ForallList::const_iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) {
62                                closedVars[ (*i)->get_name() ] = TypeDecl::Data{ (*i) };
63                                for ( std::list< DeclarationWithType* >::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) {
64                                        haveAssertions[ *assert ].isUsed = false;
65                                }
66///       cloneAll( (*i)->get_assertions(), haveAssertions );
67///       haveAssertions.insert( haveAssertions.end(), (*i)->get_assertions().begin(), (*i)->get_assertions().end() );
68                        } // for
69                } // if
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 );
76        }
77
78        void FindOpenVars::previsit(PointerType *pointerType) {
79                common_action( pointerType );
80        }
81
82        void FindOpenVars::previsit(ArrayType *arrayType) {
83                common_action( arrayType );
84        }
85
86        void FindOpenVars::previsit(FunctionType *functionType) {
87                common_action( functionType );
88                nextIsOpen = ! nextIsOpen;
89                GuardAction( [this](){ nextIsOpen = ! nextIsOpen; } );
90        }
91
92        void FindOpenVars::previsit(TupleType *tupleType) {
93                common_action( tupleType );
94        }
95} // namespace ResolvExpr
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.