source: src/ResolvExpr/FindOpenVars.cc@ 2f42718

no_list
Last change on this file since 2f42718 was 2f42718, checked in by tdelisle <tdelisle@…>, 7 years ago

Parameters and return value of functions are now vectors (and some related clean-up)

  • Property mode set to 100644
File size: 2.9 KB
Line 
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
18#include <list> // for _List_const_iterator, list<>::const...
19#include <map> // for map<>::mapped_type
20
21#include "Common/PassVisitor.h"
22#include "SynTree/Declaration.h" // for TypeDecl, DeclarationWithType (ptr ...
23#include "SynTree/Type.h" // for Type, Type::ForallList, ArrayType
24
25namespace ResolvExpr {
26 struct FindOpenVars : public WithGuards {
27 FindOpenVars( OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen );
28
29 void previsit( PointerType * pointerType );
30 void previsit( ArrayType * arrayType );
31 void previsit( FunctionType * functionType );
32 void previsit( TupleType * tupleType );
33
34 void common_action( Type *type );
35
36 OpenVarSet &openVars, &closedVars;
37 AssertionSet &needAssertions, &haveAssertions;
38 bool nextIsOpen;
39 };
40
41 void findOpenVars( Type *type, OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen ) {
42 PassVisitor<FindOpenVars> finder( openVars, closedVars, needAssertions, haveAssertions, firstIsOpen );
43 type->accept( finder );
44 }
45
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 }
49
50 void FindOpenVars::common_action( Type *type ) {
51 if ( nextIsOpen ) {
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;
56 }
57 }
58 } else {
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;
63 }
64 } // for
65 } // if
66 }
67
68 void FindOpenVars::previsit(PointerType *pointerType) {
69 common_action( pointerType );
70 }
71
72 void FindOpenVars::previsit(ArrayType *arrayType) {
73 common_action( arrayType );
74 }
75
76 void FindOpenVars::previsit(FunctionType *functionType) {
77 common_action( functionType );
78 nextIsOpen = ! nextIsOpen;
79 GuardAction( [this](){ nextIsOpen = ! nextIsOpen; } );
80 }
81
82 void FindOpenVars::previsit(TupleType *tupleType) {
83 common_action( tupleType );
84 }
85} // namespace ResolvExpr
86
87// Local Variables: //
88// tab-width: 4 //
89// mode: c++ //
90// compile-command: "make install" //
91// End: //
Note: See TracBrowser for help on using the repository browser.