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