source: src/ResolvExpr/Occurs.cc @ d318a18

new-env
Last change on this file since d318a18 was 982f95d, checked in by Aaron Moss <a3moss@…>, 6 years ago

Start of new environment implementation; terribly broken

  • 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 <string>             // for string
[982f95d]17#include <unordered_set>      // for unordered_set
[ea6332d]18
[103b264]19#include "Common/PassVisitor.h"
[ea6332d]20#include "SynTree/Type.h"     // for TypeInstType, Type
[982f95d]21#include "TypeEnvironment.h"  // for ClassRef, 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;
[982f95d]29                using VarSet = std::unordered_set< std::string >;
30                VarSet eqvVars;
[103b264]31                const TypeEnvironment &tenv;
[a32b204]32        };
[51b7345]33
[a32b204]34        bool occurs( Type *type, std::string varName, const TypeEnvironment &env ) {
[103b264]35                PassVisitor<Occurs> occur( varName, env );
[a32b204]36                type->accept( occur );
[103b264]37                return occur.pass.result;
[a32b204]38        }
[51b7345]39
[103b264]40        Occurs::Occurs( std::string varName, const TypeEnvironment & env ) : result( false ), tenv( env ) {
[982f95d]41                if ( ClassRef eqvClass = tenv.lookup( varName ) ) {
42                        eqvVars = eqvClass.get_vars<VarSet>();
[a32b204]43                } else {
44                        eqvVars.insert( varName );
45                } // if
46        }
[51b7345]47
[103b264]48        void Occurs::previsit( TypeInstType * typeInst ) {
[8e18b8e]49                ///   std::cerr << "searching for vars: ";
[103b264]50///   std::copy( eqvVars.begin(), eqvVars.end(), std::ostream_iterator< std::string >( std::cerr, " " ) );
51///   std::cerr << std::endl;
[a32b204]52                if ( eqvVars.find( typeInst->get_name() ) != eqvVars.end() ) {
53                        result = true;
[982f95d]54                } else if ( ClassRef eqvClass = tenv.lookup( typeInst->get_name() ) ) {
55                        if ( Type* boundTy = eqvClass.get_bound().type ) {
[103b264]56///       std::cerr << typeInst->get_name() << " is bound to";
[982f95d]57///       boundTy->print( std::cerr );
[103b264]58///       std::cerr << std::endl;
[982f95d]59                                boundTy->accept( *visitor );
[a32b204]60                        } // if
61                } // if
62        }
[51b7345]63} // namespace ResolvExpr
[a32b204]64
65// Local Variables: //
66// tab-width: 4 //
67// mode: c++ //
68// compile-command: "make install" //
69// End: //
Note: See TracBrowser for help on using the repository browser.