Changeset 103b264
- Timestamp:
- Dec 18, 2017, 3:18:41 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- a180ded
- Parents:
- ecd4923
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Occurs.cc
recd4923 r103b264 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Occurs.cc -- 7 // Occurs.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 17 17 #include <string> // for string 18 18 19 #include "Common/PassVisitor.h" 19 20 #include "SynTree/Type.h" // for TypeInstType, Type 20 #include "SynTree/Visitor.h" // for Visitor21 21 #include "TypeEnvironment.h" // for EqvClass, TypeEnvironment 22 22 23 23 namespace ResolvExpr { 24 class Occurs : public Visitor { 25 public: 24 struct Occurs : public WithVisitorRef<Occurs> { 26 25 Occurs( std::string varName, const TypeEnvironment &env ); 27 bool get_result() const { return result; } 28 virtual void visit( TypeInstType *typeInst ); 29 private: 26 void previsit( TypeInstType * typeInst ); 27 30 28 bool result; 31 29 std::set< std::string > eqvVars; 32 const TypeEnvironment & env;30 const TypeEnvironment &tenv; 33 31 }; 34 32 35 33 bool occurs( Type *type, std::string varName, const TypeEnvironment &env ) { 36 Occursoccur( varName, env );34 PassVisitor<Occurs> occur( varName, env ); 37 35 type->accept( occur ); 38 return occur. get_result();36 return occur.pass.result; 39 37 } 40 38 41 Occurs::Occurs( std::string varName, const TypeEnvironment & env ) : result( false ),env( env ) {39 Occurs::Occurs( std::string varName, const TypeEnvironment & env ) : result( false ), tenv( env ) { 42 40 EqvClass eqvClass; 43 if ( env.lookup( varName, eqvClass ) ) {41 if ( tenv.lookup( varName, eqvClass ) ) { 44 42 eqvVars = eqvClass.vars; 45 43 } else { … … 48 46 } 49 47 50 void Occurs:: visit( TypeInstType *typeInst ) {48 void Occurs::previsit( TypeInstType * typeInst ) { 51 49 EqvClass eqvClass; 52 /// std::c out<< "searching for vars: ";53 /// std::copy( eqvVars.begin(), eqvVars.end(), std::ostream_iterator< std::string >( std::c out, " " ) );54 /// std::c out<< std::endl;50 /// std::cerr << "searching for vars: "; 51 /// std::copy( eqvVars.begin(), eqvVars.end(), std::ostream_iterator< std::string >( std::cerr, " " ) ); 52 /// std::cerr << std::endl; 55 53 if ( eqvVars.find( typeInst->get_name() ) != eqvVars.end() ) { 56 54 result = true; 57 } else if ( env.lookup( typeInst->get_name(), eqvClass ) ) {55 } else if ( tenv.lookup( typeInst->get_name(), eqvClass ) ) { 58 56 if ( eqvClass.type ) { 59 /// std::c out<< typeInst->get_name() << " is bound to";60 /// eqvClass.type->print( std::c out);61 /// std::c out<< std::endl;62 eqvClass.type->accept( * this);57 /// std::cerr << typeInst->get_name() << " is bound to"; 58 /// eqvClass.type->print( std::cerr ); 59 /// std::cerr << std::endl; 60 eqvClass.type->accept( *visitor ); 63 61 } // if 64 62 } // if
Note: See TracChangeset
for help on using the changeset viewer.