source: src/ResolvExpr/Occurs.cc @ da48183

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resnenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexerpthread-emulationqualifiedEnum
Last change on this file since da48183 was 00ac42e, checked in by Aaron Moss <a3moss@…>, 6 years ago

stop eagerly copying EqvClass? on lookup

  • 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 ) {
[00ac42e]40                if ( const EqvClass *eqvClass = tenv.lookup( varName ) ) {
41                        eqvVars = eqvClass->vars;
[a32b204]42                } else {
43                        eqvVars.insert( varName );
44                } // if
45        }
[51b7345]46
[103b264]47        void Occurs::previsit( TypeInstType * typeInst ) {
[00ac42e]48                ///   std::cerr << "searching for vars: ";
[103b264]49///   std::copy( eqvVars.begin(), eqvVars.end(), std::ostream_iterator< std::string >( std::cerr, " " ) );
50///   std::cerr << std::endl;
[a32b204]51                if ( eqvVars.find( typeInst->get_name() ) != eqvVars.end() ) {
52                        result = true;
[00ac42e]53                } else if ( const EqvClass *eqvClass = tenv.lookup( typeInst->get_name() ) ) {
54                        if ( eqvClass->type ) {
[103b264]55///       std::cerr << typeInst->get_name() << " is bound to";
56///       eqvClass.type->print( std::cerr );
57///       std::cerr << std::endl;
[00ac42e]58                                eqvClass->type->accept( *visitor );
[a32b204]59                        } // if
60                } // if
61        }
[51b7345]62} // namespace ResolvExpr
[a32b204]63
64// Local Variables: //
65// tab-width: 4 //
66// mode: c++ //
67// compile-command: "make install" //
68// End: //
Note: See TracBrowser for help on using the repository browser.