source: src/ResolvExpr/Occurs.cc @ f739788

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since f739788 was ea6332d, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Big header cleaning pass - commit 3

  • Property mode set to 100644
File size: 2.1 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// Occurs.cc --
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//
15
16#include <set>                // for set, _Rb_tree_const_iterator
17#include <string>             // for string
18
19#include "SynTree/Type.h"     // for TypeInstType, Type
20#include "SynTree/Visitor.h"  // for Visitor
21#include "TypeEnvironment.h"  // for EqvClass, TypeEnvironment
22
23namespace ResolvExpr {
24        class Occurs : public Visitor {
25          public:
26                Occurs( std::string varName, const TypeEnvironment &env );
27                bool get_result() const { return result; }
28                virtual void visit( TypeInstType *typeInst );
29          private:
30                bool result;
31                std::set< std::string > eqvVars;
32                const TypeEnvironment &env;
33        };
34
35        bool occurs( Type *type, std::string varName, const TypeEnvironment &env ) {
36                Occurs occur( varName, env );
37                type->accept( occur );
38                return occur.get_result();
39        }
40
41        Occurs::Occurs( std::string varName, const TypeEnvironment &env ) : result( false ), env( env ) {
42                EqvClass eqvClass;
43                if ( env.lookup( varName, eqvClass ) ) {
44                        eqvVars = eqvClass.vars;
45                } else {
46                        eqvVars.insert( varName );
47                } // if
48        }
49
50        void Occurs::visit( TypeInstType *typeInst ) {
51                EqvClass eqvClass;
52///   std::cout << "searching for vars: ";
53///   std::copy( eqvVars.begin(), eqvVars.end(), std::ostream_iterator< std::string >( std::cout, " " ) );
54///   std::cout << std::endl;
55                if ( eqvVars.find( typeInst->get_name() ) != eqvVars.end() ) {
56                        result = true;
57                } else if ( env.lookup( typeInst->get_name(), eqvClass ) ) {
58                        if ( eqvClass.type ) {
59///       std::cout << typeInst->get_name() << " is bound to";
60///       eqvClass.type->print( std::cout );
61///       std::cout << std::endl;
62                                eqvClass.type->accept( *this );
63                        } // if
64                } // if
65        }
66} // namespace ResolvExpr
67
68// Local Variables: //
69// tab-width: 4 //
70// mode: c++ //
71// compile-command: "make install" //
72// End: //
Note: See TracBrowser for help on using the repository browser.