source: translator/ResolvExpr/Occurs.cc @ 51b7345

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 51b7345 was 51b7345, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

initial commit

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/*
2 * This file is part of the Cforall project
3 *
4 * $Id: Occurs.cc,v 1.2 2005/08/29 20:14:16 rcbilson Exp $
5 *
6 */
7
8#include <set>
9#include <algorithm>
10#include <iterator>
11#include "SynTree/Type.h"
12#include "SynTree/Visitor.h"
13#include "TypeEnvironment.h"
14
15
16namespace ResolvExpr {
17
18class Occurs : public Visitor
19{
20public:
21  Occurs( std::string varName, const TypeEnvironment &env );
22 
23  bool get_result() const { return result; }
24
25  virtual void visit( TypeInstType *typeInst );
26
27private:
28  bool result;
29  std::set< std::string > eqvVars;
30  const TypeEnvironment &env;
31};
32
33bool
34occurs( Type *type, std::string varName, const TypeEnvironment &env )
35{
36  Occurs occur( varName, env );
37  type->accept( occur );
38  return occur.get_result();
39}
40
41Occurs::Occurs( std::string varName, const TypeEnvironment &env )
42  : result( false ), env( env )
43{
44  EqvClass eqvClass;
45  if( env.lookup( varName, eqvClass ) ) {
46    eqvVars = eqvClass.vars;
47  } else {
48    eqvVars.insert( varName );
49  }
50}
51
52void 
53Occurs::visit( TypeInstType *typeInst )
54{
55  EqvClass eqvClass;
56///   std::cout << "searching for vars: ";
57///   std::copy( eqvVars.begin(), eqvVars.end(), std::ostream_iterator< std::string >( std::cout, " " ) );
58///   std::cout << std::endl;
59  if( eqvVars.find( typeInst->get_name() ) != eqvVars.end() ) {
60    result = true;
61  } else if( env.lookup( typeInst->get_name(), eqvClass ) ) {
62    if( eqvClass.type ) {
63///       std::cout << typeInst->get_name() << " is bound to";
64///       eqvClass.type->print( std::cout );
65///       std::cout << std::endl;
66      eqvClass.type->accept( *this );
67    }
68  }
69}
70
71} // namespace ResolvExpr
Note: See TracBrowser for help on using the repository browser.