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 | #include "SynTree/Type.h" |
---|
18 | #include "SynTree/Visitor.h" |
---|
19 | |
---|
20 | namespace ResolvExpr { |
---|
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 ); |
---|
32 | |
---|
33 | OpenVarSet &openVars, &closedVars; |
---|
34 | AssertionSet &needAssertions, &haveAssertions; |
---|
35 | bool nextIsOpen; |
---|
36 | }; |
---|
37 | |
---|
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 | } |
---|
42 | |
---|
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 | } |
---|
46 | |
---|
47 | void FindOpenVars::common_action( Type *type ) { |
---|
48 | if ( nextIsOpen ) { |
---|
49 | for ( Type::ForallList::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 ( Type::ForallList::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 | } // for |
---|
66 | } // if |
---|
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 FindOpenVars::visit(PointerType *pointerType) { |
---|
76 | common_action( pointerType ); |
---|
77 | Visitor::visit( pointerType ); |
---|
78 | } |
---|
79 | |
---|
80 | void FindOpenVars::visit(ArrayType *arrayType) { |
---|
81 | common_action( arrayType ); |
---|
82 | Visitor::visit( arrayType ); |
---|
83 | } |
---|
84 | |
---|
85 | void FindOpenVars::visit(FunctionType *functionType) { |
---|
86 | common_action( functionType ); |
---|
87 | nextIsOpen = ! nextIsOpen; |
---|
88 | Visitor::visit( functionType ); |
---|
89 | nextIsOpen = ! nextIsOpen; |
---|
90 | } |
---|
91 | |
---|
92 | void FindOpenVars::visit(TupleType *tupleType) { |
---|
93 | common_action( tupleType ); |
---|
94 | Visitor::visit( tupleType ); |
---|
95 | } |
---|
96 | } // namespace ResolvExpr |
---|
97 | |
---|
98 | // Local Variables: // |
---|
99 | // tab-width: 4 // |
---|
100 | // mode: c++ // |
---|
101 | // compile-command: "make install" // |
---|
102 | // End: // |
---|