source: src/ResolvExpr/Occurs.cc @ 84b4ed72

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumwith_gc
Last change on this file since 84b4ed72 was 103b264, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Convert Occurs to PassVisitor?

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[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//
[103b264]7// Occurs.cc --
[a32b204]8//
9// Author           : Richard C. Bilson
10// Created On       : Sun May 17 09:47:41 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Sun May 17 09:49:26 2015
13// Update Count     : 2
14//
[51b7345]15
[ea6332d]16#include <set>                // for set, _Rb_tree_const_iterator
17#include <string>             // for string
18
[103b264]19#include "Common/PassVisitor.h"
[ea6332d]20#include "SynTree/Type.h"     // for TypeInstType, Type
21#include "TypeEnvironment.h"  // for EqvClass, TypeEnvironment
[51b7345]22
23namespace ResolvExpr {
[103b264]24        struct Occurs : public WithVisitorRef<Occurs> {
[a32b204]25                Occurs( std::string varName, const TypeEnvironment &env );
[103b264]26                void previsit( TypeInstType * typeInst );
27
[a32b204]28                bool result;
29                std::set< std::string > eqvVars;
[103b264]30                const TypeEnvironment &tenv;
[a32b204]31        };
[51b7345]32
[a32b204]33        bool occurs( Type *type, std::string varName, const TypeEnvironment &env ) {
[103b264]34                PassVisitor<Occurs> occur( varName, env );
[a32b204]35                type->accept( occur );
[103b264]36                return occur.pass.result;
[a32b204]37        }
[51b7345]38
[103b264]39        Occurs::Occurs( std::string varName, const TypeEnvironment & env ) : result( false ), tenv( env ) {
[a32b204]40                EqvClass eqvClass;
[103b264]41                if ( tenv.lookup( varName, eqvClass ) ) {
[a32b204]42                        eqvVars = eqvClass.vars;
43                } else {
44                        eqvVars.insert( varName );
45                } // if
46        }
[51b7345]47
[103b264]48        void Occurs::previsit( TypeInstType * typeInst ) {
[a32b204]49                EqvClass eqvClass;
[103b264]50///   std::cerr << "searching for vars: ";
51///   std::copy( eqvVars.begin(), eqvVars.end(), std::ostream_iterator< std::string >( std::cerr, " " ) );
52///   std::cerr << std::endl;
[a32b204]53                if ( eqvVars.find( typeInst->get_name() ) != eqvVars.end() ) {
54                        result = true;
[103b264]55                } else if ( tenv.lookup( typeInst->get_name(), eqvClass ) ) {
[a32b204]56                        if ( eqvClass.type ) {
[103b264]57///       std::cerr << typeInst->get_name() << " is bound to";
58///       eqvClass.type->print( std::cerr );
59///       std::cerr << std::endl;
60                                eqvClass.type->accept( *visitor );
[a32b204]61                        } // if
62                } // if
63        }
[51b7345]64} // namespace ResolvExpr
[a32b204]65
66// Local Variables: //
67// tab-width: 4 //
68// mode: c++ //
69// compile-command: "make install" //
70// End: //
Note: See TracBrowser for help on using the repository browser.