[51b7345] | 1 | /* |
---|
| 2 | * This file is part of the Cforall project |
---|
| 3 | * |
---|
| 4 | * $Id: FindOpenVars.cc,v 1.4 2005/08/29 20:14:16 rcbilson Exp $ |
---|
| 5 | * |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #include "FindOpenVars.h" |
---|
| 9 | #include "SynTree/Type.h" |
---|
| 10 | #include "SynTree/Visitor.h" |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | namespace ResolvExpr { |
---|
| 14 | |
---|
| 15 | class FindOpenVars : public Visitor |
---|
| 16 | { |
---|
| 17 | public: |
---|
| 18 | FindOpenVars( OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen ); |
---|
| 19 | |
---|
| 20 | private: |
---|
| 21 | virtual void visit(PointerType *pointerType); |
---|
| 22 | virtual void visit(ArrayType *arrayType); |
---|
| 23 | virtual void visit(FunctionType *functionType); |
---|
| 24 | virtual void visit(TupleType *tupleType); |
---|
| 25 | |
---|
| 26 | void common_action( Type *type ); |
---|
| 27 | |
---|
| 28 | OpenVarSet &openVars, &closedVars; |
---|
| 29 | AssertionSet &needAssertions, &haveAssertions; |
---|
| 30 | bool nextIsOpen; |
---|
| 31 | }; |
---|
| 32 | |
---|
| 33 | void |
---|
| 34 | findOpenVars( Type *type, OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen ) |
---|
| 35 | { |
---|
| 36 | FindOpenVars finder( openVars, closedVars, needAssertions, haveAssertions, firstIsOpen ); |
---|
| 37 | type->accept( finder ); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | FindOpenVars::FindOpenVars( OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen ) |
---|
| 41 | : openVars( openVars ), closedVars( closedVars ), needAssertions( needAssertions ), haveAssertions( haveAssertions ), nextIsOpen( firstIsOpen ) |
---|
| 42 | { |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | void |
---|
| 46 | FindOpenVars::common_action( Type *type ) |
---|
| 47 | { |
---|
| 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 | } |
---|
| 54 | /// cloneAll( (*i)->get_assertions(), needAssertions ); |
---|
| 55 | /// needAssertions.insert( needAssertions.end(), (*i)->get_assertions().begin(), (*i)->get_assertions().end() ); |
---|
| 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 | } |
---|
| 63 | /// cloneAll( (*i)->get_assertions(), haveAssertions ); |
---|
| 64 | /// haveAssertions.insert( haveAssertions.end(), (*i)->get_assertions().begin(), (*i)->get_assertions().end() ); |
---|
| 65 | } |
---|
| 66 | } |
---|
| 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 ); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | void |
---|
| 76 | FindOpenVars::visit(PointerType *pointerType) |
---|
| 77 | { |
---|
| 78 | common_action( pointerType ); |
---|
| 79 | Visitor::visit( pointerType ); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | void |
---|
| 83 | FindOpenVars::visit(ArrayType *arrayType) |
---|
| 84 | { |
---|
| 85 | common_action( arrayType ); |
---|
| 86 | Visitor::visit( arrayType ); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | void |
---|
| 90 | FindOpenVars::visit(FunctionType *functionType) |
---|
| 91 | { |
---|
| 92 | common_action( functionType ); |
---|
| 93 | nextIsOpen = !nextIsOpen; |
---|
| 94 | Visitor::visit( functionType ); |
---|
| 95 | nextIsOpen = !nextIsOpen; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | void |
---|
| 99 | FindOpenVars::visit(TupleType *tupleType) |
---|
| 100 | { |
---|
| 101 | common_action( tupleType ); |
---|
| 102 | Visitor::visit( tupleType ); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | } // namespace ResolvExpr |
---|