source: src/ResolvExpr/Occurs.cc@ eff03a94

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

Start of new environment implementation; terribly broken

  • 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 <string> // for string
17#include <unordered_set> // for unordered_set
18
19#include "Common/PassVisitor.h"
20#include "SynTree/Type.h" // for TypeInstType, Type
21#include "TypeEnvironment.h" // for ClassRef, TypeEnvironment
22
23namespace ResolvExpr {
24 struct Occurs : public WithVisitorRef<Occurs> {
25 Occurs( std::string varName, const TypeEnvironment &env );
26 void previsit( TypeInstType * typeInst );
27
28 bool result;
29 using VarSet = std::unordered_set< std::string >;
30 VarSet eqvVars;
31 const TypeEnvironment &tenv;
32 };
33
34 bool occurs( Type *type, std::string varName, const TypeEnvironment &env ) {
35 PassVisitor<Occurs> occur( varName, env );
36 type->accept( occur );
37 return occur.pass.result;
38 }
39
40 Occurs::Occurs( std::string varName, const TypeEnvironment & env ) : result( false ), tenv( env ) {
41 if ( ClassRef eqvClass = tenv.lookup( varName ) ) {
42 eqvVars = eqvClass.get_vars<VarSet>();
43 } else {
44 eqvVars.insert( varName );
45 } // if
46 }
47
48 void Occurs::previsit( TypeInstType * typeInst ) {
49 /// std::cerr << "searching for vars: ";
50/// std::copy( eqvVars.begin(), eqvVars.end(), std::ostream_iterator< std::string >( std::cerr, " " ) );
51/// std::cerr << std::endl;
52 if ( eqvVars.find( typeInst->get_name() ) != eqvVars.end() ) {
53 result = true;
54 } else if ( ClassRef eqvClass = tenv.lookup( typeInst->get_name() ) ) {
55 if ( Type* boundTy = eqvClass.get_bound().type ) {
56/// std::cerr << typeInst->get_name() << " is bound to";
57/// boundTy->print( std::cerr );
58/// std::cerr << std::endl;
59 boundTy->accept( *visitor );
60 } // if
61 } // if
62 }
63} // namespace ResolvExpr
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.