[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 | //
|
---|
| 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 | //
|
---|
[51b73452] | 15 |
|
---|
| 16 | #include "FindOpenVars.h"
|
---|
| 17 | #include "SynTree/Type.h"
|
---|
| 18 | #include "SynTree/Visitor.h"
|
---|
| 19 |
|
---|
| 20 | namespace ResolvExpr {
|
---|
[a32b204] | 21 | class FindOpenVars : public Visitor {
|
---|
| 22 | public:
|
---|
| 23 | FindOpenVars( OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen );
|
---|
| 24 |
|
---|
| 25 | private:
|
---|
| 26 | virtual void visit(PointerType *pointerType);
|
---|
| 27 | virtual void visit(ArrayType *arrayType);
|
---|
| 28 | virtual void visit(FunctionType *functionType);
|
---|
| 29 | virtual void visit(TupleType *tupleType);
|
---|
| 30 |
|
---|
| 31 | void common_action( Type *type );
|
---|
[51b73452] | 32 |
|
---|
[a32b204] | 33 | OpenVarSet &openVars, &closedVars;
|
---|
| 34 | AssertionSet &needAssertions, &haveAssertions;
|
---|
| 35 | bool nextIsOpen;
|
---|
| 36 | };
|
---|
[51b73452] | 37 |
|
---|
[a32b204] | 38 | void findOpenVars( Type *type, OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen ) {
|
---|
| 39 | FindOpenVars finder( openVars, closedVars, needAssertions, haveAssertions, firstIsOpen );
|
---|
| 40 | type->accept( finder );
|
---|
| 41 | }
|
---|
[51b73452] | 42 |
|
---|
[a32b204] | 43 | FindOpenVars::FindOpenVars( OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen )
|
---|
| 44 | : openVars( openVars ), closedVars( closedVars ), needAssertions( needAssertions ), haveAssertions( haveAssertions ), nextIsOpen( firstIsOpen ) {
|
---|
| 45 | }
|
---|
[51b73452] | 46 |
|
---|
[a32b204] | 47 | void FindOpenVars::common_action( Type *type ) {
|
---|
| 48 | if ( nextIsOpen ) {
|
---|
| 49 | for ( std::list< TypeDecl* >::const_iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) {
|
---|
| 50 | openVars[ (*i)->get_name() ] = (*i)->get_kind();
|
---|
| 51 | for ( std::list< DeclarationWithType* >::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) {
|
---|
| 52 | needAssertions[ *assert ] = false;
|
---|
| 53 | }
|
---|
[51b73452] | 54 | /// cloneAll( (*i)->get_assertions(), needAssertions );
|
---|
| 55 | /// needAssertions.insert( needAssertions.end(), (*i)->get_assertions().begin(), (*i)->get_assertions().end() );
|
---|
[a32b204] | 56 | }
|
---|
| 57 | } else {
|
---|
| 58 | for ( std::list< TypeDecl* >::const_iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) {
|
---|
| 59 | closedVars[ (*i)->get_name() ] = (*i)->get_kind();
|
---|
| 60 | for ( std::list< DeclarationWithType* >::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) {
|
---|
| 61 | haveAssertions[ *assert ] = false;
|
---|
| 62 | }
|
---|
[51b73452] | 63 | /// cloneAll( (*i)->get_assertions(), haveAssertions );
|
---|
| 64 | /// haveAssertions.insert( haveAssertions.end(), (*i)->get_assertions().begin(), (*i)->get_assertions().end() );
|
---|
[a32b204] | 65 | } // for
|
---|
| 66 | } // if
|
---|
[51b73452] | 67 | /// std::cout << "type is ";
|
---|
| 68 | /// type->print( std::cout );
|
---|
| 69 | /// std::cout << std::endl << "need is" << std::endl;
|
---|
| 70 | /// printAssertionSet( needAssertions, std::cout );
|
---|
| 71 | /// std::cout << std::endl << "have is" << std::endl;
|
---|
| 72 | /// printAssertionSet( haveAssertions, std::cout );
|
---|
[a32b204] | 73 | }
|
---|
[51b73452] | 74 |
|
---|
[a32b204] | 75 | void FindOpenVars::visit(PointerType *pointerType) {
|
---|
| 76 | common_action( pointerType );
|
---|
| 77 | Visitor::visit( pointerType );
|
---|
| 78 | }
|
---|
[51b73452] | 79 |
|
---|
[a32b204] | 80 | void FindOpenVars::visit(ArrayType *arrayType) {
|
---|
| 81 | common_action( arrayType );
|
---|
| 82 | Visitor::visit( arrayType );
|
---|
| 83 | }
|
---|
[51b73452] | 84 |
|
---|
[a32b204] | 85 | void FindOpenVars::visit(FunctionType *functionType) {
|
---|
| 86 | common_action( functionType );
|
---|
| 87 | nextIsOpen = ! nextIsOpen;
|
---|
| 88 | Visitor::visit( functionType );
|
---|
| 89 | nextIsOpen = ! nextIsOpen;
|
---|
| 90 | }
|
---|
[51b73452] | 91 |
|
---|
[a32b204] | 92 | void FindOpenVars::visit(TupleType *tupleType) {
|
---|
| 93 | common_action( tupleType );
|
---|
| 94 | Visitor::visit( tupleType );
|
---|
| 95 | }
|
---|
[51b73452] | 96 | } // namespace ResolvExpr
|
---|
[a32b204] | 97 |
|
---|
| 98 | // Local Variables: //
|
---|
| 99 | // tab-width: 4 //
|
---|
| 100 | // mode: c++ //
|
---|
| 101 | // compile-command: "make install" //
|
---|
| 102 | // End: //
|
---|