| [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 |
|
|---|
| [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
|
|---|
| [51b73452] | 24 |
|
|---|
| 25 | namespace 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 );
|
|---|
| [51b73452] | 35 |
|
|---|
| [a32b204] | 36 | OpenVarSet &openVars, &closedVars;
|
|---|
| 37 | AssertionSet &needAssertions, &haveAssertions;
|
|---|
| 38 | bool nextIsOpen;
|
|---|
| 39 | };
|
|---|
| [51b73452] | 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 | }
|
|---|
| [51b73452] | 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 | }
|
|---|
| [51b73452] | 49 |
|
|---|
| [a32b204] | 50 | void FindOpenVars::common_action( Type *type ) {
|
|---|
| 51 | if ( nextIsOpen ) {
|
|---|
| [2f42718] | 52 | for ( const auto i : type->get_forall() ) {
|
|---|
| 53 | openVars[ i->get_name() ] = TypeDecl::Data{ i };
|
|---|
| 54 | for ( const auto assert : i->assertions ) {
|
|---|
| 55 | needAssertions[ assert ].isUsed = false;
|
|---|
| [a32b204] | 56 | }
|
|---|
| 57 | }
|
|---|
| 58 | } else {
|
|---|
| [2f42718] | 59 | for ( const auto i : type->get_forall() ) {
|
|---|
| 60 | closedVars[ i->get_name() ] = TypeDecl::Data{ i };
|
|---|
| 61 | for ( const auto assert : i->assertions ) {
|
|---|
| 62 | haveAssertions[ assert ].isUsed = false;
|
|---|
| [a32b204] | 63 | }
|
|---|
| 64 | } // for
|
|---|
| 65 | } // if
|
|---|
| 66 | }
|
|---|
| [51b73452] | 67 |
|
|---|
| [ce7ed2c] | 68 | void FindOpenVars::previsit(PointerType *pointerType) {
|
|---|
| [a32b204] | 69 | common_action( pointerType );
|
|---|
| 70 | }
|
|---|
| [51b73452] | 71 |
|
|---|
| [ce7ed2c] | 72 | void FindOpenVars::previsit(ArrayType *arrayType) {
|
|---|
| [a32b204] | 73 | common_action( arrayType );
|
|---|
| 74 | }
|
|---|
| [51b73452] | 75 |
|
|---|
| [ce7ed2c] | 76 | void FindOpenVars::previsit(FunctionType *functionType) {
|
|---|
| [a32b204] | 77 | common_action( functionType );
|
|---|
| 78 | nextIsOpen = ! nextIsOpen;
|
|---|
| [ce7ed2c] | 79 | GuardAction( [this](){ nextIsOpen = ! nextIsOpen; } );
|
|---|
| [a32b204] | 80 | }
|
|---|
| [51b73452] | 81 |
|
|---|
| [ce7ed2c] | 82 | void FindOpenVars::previsit(TupleType *tupleType) {
|
|---|
| [a32b204] | 83 | common_action( tupleType );
|
|---|
| 84 | }
|
|---|
| [51b73452] | 85 | } // namespace ResolvExpr
|
|---|
| [a32b204] | 86 |
|
|---|
| 87 | // Local Variables: //
|
|---|
| 88 | // tab-width: 4 //
|
|---|
| 89 | // mode: c++ //
|
|---|
| 90 | // compile-command: "make install" //
|
|---|
| 91 | // End: //
|
|---|