source: translator/ResolvExpr/FindOpenVars.cc @ d9a0e76

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since d9a0e76 was 51b7345, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

initial commit

  • Property mode set to 100644
File size: 3.3 KB
RevLine 
[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
13namespace ResolvExpr {
14
15class FindOpenVars : public Visitor
16{
17public:
18  FindOpenVars( OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen );
19 
20private:
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
33void
34findOpenVars( 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
40FindOpenVars::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
45void
46FindOpenVars::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
75void 
76FindOpenVars::visit(PointerType *pointerType)
77{
78  common_action( pointerType );
79  Visitor::visit( pointerType );
80}
81
82void 
83FindOpenVars::visit(ArrayType *arrayType)
84{
85  common_action( arrayType );
86  Visitor::visit( arrayType );
87}
88
89void 
90FindOpenVars::visit(FunctionType *functionType)
91{
92  common_action( functionType );
93  nextIsOpen = !nextIsOpen;
94  Visitor::visit( functionType );
95  nextIsOpen = !nextIsOpen;
96}
97
98void 
99FindOpenVars::visit(TupleType *tupleType)
100{
101  common_action( tupleType );
102  Visitor::visit( tupleType );
103}
104
105} // namespace ResolvExpr
Note: See TracBrowser for help on using the repository browser.