Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/FindOpenVars.cc

    r85dac33 rce7ed2c  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 09:42:48 2015
    11 // Last Modified By : Andrew
    12 // Last Modified On : Fri Jul 12 14:18:00 2019
    13 // Update Count     : 4
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun May 17 09:45:25 2015
     13// Update Count     : 3
    1414//
    1515
     
    1919#include <map>                    // for map<>::mapped_type
    2020
    21 #include "AST/Pass.hpp"
    22 #include "AST/Type.hpp"
    2321#include "Common/PassVisitor.h"
    2422#include "SynTree/Declaration.h"  // for TypeDecl, DeclarationWithType (ptr ...
     
    2624
    2725namespace ResolvExpr {
    28         struct FindOpenVars_old : public WithGuards {
    29                 FindOpenVars_old( OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen );
     26        struct FindOpenVars : public WithGuards {
     27                FindOpenVars( OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen );
    3028
    31                 void previsit( const PointerType * pointerType );
    32                 void previsit( const ArrayType * arrayType );
    33                 void previsit( const FunctionType * functionType );
    34                 void previsit( const TupleType * tupleType );
     29                void previsit( PointerType * pointerType );
     30                void previsit( ArrayType * arrayType );
     31                void previsit( FunctionType * functionType );
     32                void previsit( TupleType * tupleType );
    3533
    36                 void common_action( const Type *type );
     34                void common_action( Type *type );
    3735
    3836                OpenVarSet &openVars, &closedVars;
     
    4139        };
    4240
    43         void findOpenVars( const Type *type, OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen ) {
    44                 PassVisitor<FindOpenVars_old> finder( openVars, closedVars, needAssertions, haveAssertions, firstIsOpen );
     41        void findOpenVars( Type *type, OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen ) {
     42                PassVisitor<FindOpenVars> finder( openVars, closedVars, needAssertions, haveAssertions, firstIsOpen );
    4543                type->accept( finder );
    4644        }
    4745
    48         FindOpenVars_old::FindOpenVars_old( OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen )
     46        FindOpenVars::FindOpenVars( OpenVarSet &openVars, OpenVarSet &closedVars, AssertionSet &needAssertions, AssertionSet &haveAssertions, bool firstIsOpen )
    4947                : openVars( openVars ), closedVars( closedVars ), needAssertions( needAssertions ), haveAssertions( haveAssertions ), nextIsOpen( firstIsOpen ) {
    5048        }
    5149
    52         void FindOpenVars_old::common_action( const Type * type ) {
     50        void FindOpenVars::common_action( Type *type ) {
    5351                if ( nextIsOpen ) {
    54                         for ( Type::ForallList::const_iterator i = type->forall.begin(); i != type->forall.end(); ++i ) {
     52                        for ( Type::ForallList::const_iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) {
    5553                                openVars[ (*i)->get_name() ] = TypeDecl::Data{ (*i) };
    5654                                for ( std::list< DeclarationWithType* >::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) {
     
    6159                        }
    6260                } else {
    63                         for ( Type::ForallList::const_iterator i = type->forall.begin(); i != type->forall.end(); ++i ) {
     61                        for ( Type::ForallList::const_iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) {
    6462                                closedVars[ (*i)->get_name() ] = TypeDecl::Data{ (*i) };
    6563                                for ( std::list< DeclarationWithType* >::const_iterator assert = (*i)->get_assertions().begin(); assert != (*i)->get_assertions().end(); ++assert ) {
     
    7876        }
    7977
    80         void FindOpenVars_old::previsit(const PointerType * pointerType) {
     78        void FindOpenVars::previsit(PointerType *pointerType) {
    8179                common_action( pointerType );
    8280        }
    8381
    84         void FindOpenVars_old::previsit(const ArrayType * arrayType) {
     82        void FindOpenVars::previsit(ArrayType *arrayType) {
    8583                common_action( arrayType );
    8684        }
    8785
    88         void FindOpenVars_old::previsit(const FunctionType * functionType) {
     86        void FindOpenVars::previsit(FunctionType *functionType) {
    8987                common_action( functionType );
    9088                nextIsOpen = ! nextIsOpen;
     
    9290        }
    9391
    94         void FindOpenVars_old::previsit(const TupleType * tupleType) {
     92        void FindOpenVars::previsit(TupleType *tupleType) {
    9593                common_action( tupleType );
    96         }
    97 
    98         namespace {
    99                 struct FindOpenVars_new final : public ast::WithGuards {
    100                         ast::OpenVarSet & open;
    101                         ast::OpenVarSet & closed;
    102                         ast::AssertionSet & need;
    103                         ast::AssertionSet & have;
    104                         bool nextIsOpen;
    105 
    106                         FindOpenVars_new(
    107                                 ast::OpenVarSet & o, ast::OpenVarSet & c, ast::AssertionSet & n,
    108                                 ast::AssertionSet & h, FirstMode firstIsOpen )
    109                         : open( o ), closed( c ), need( n ), have( h ), nextIsOpen( firstIsOpen ) {}
    110 
    111                         void previsit( const ast::FunctionType * type ) {
    112                                 // mark open/closed variables
    113                                 if ( nextIsOpen ) {
    114                                         for ( const ast::TypeDecl * decl : type->forall ) {
    115                                                 open[ decl->name ] = ast::TypeDecl::Data{ decl };
    116                                                 for ( const ast::DeclWithType * assert : decl->assertions ) {
    117                                                         need[ assert ].isUsed = false;
    118                                                 }
    119                                         }
    120                                 } else {
    121                                         for ( const ast::TypeDecl * decl : type->forall ) {
    122                                                 closed[ decl->name ] = ast::TypeDecl::Data{ decl };
    123                                                 for ( const ast::DeclWithType * assert : decl->assertions ) {
    124                                                         have[ assert ].isUsed = false;
    125                                                 }
    126                                         }
    127                                 }
    128 
    129                                 // flip open variables for contained function types
    130                                 nextIsOpen = ! nextIsOpen;
    131                                 GuardAction( [this](){ nextIsOpen = ! nextIsOpen; } );
    132                         }
    133 
    134                 };
    135         }
    136 
    137         void findOpenVars(
    138                         const ast::Type * type, ast::OpenVarSet & open, ast::OpenVarSet & closed,
    139                         ast::AssertionSet & need, ast::AssertionSet & have, FirstMode firstIsOpen ) {
    140                 ast::Pass< FindOpenVars_new > finder{ open, closed, need, have, firstIsOpen };
    141                 type->accept( finder );
    14294        }
    14395} // namespace ResolvExpr
Note: See TracChangeset for help on using the changeset viewer.