Index: src/ResolvExpr/RenameVars.cc
===================================================================
--- src/ResolvExpr/RenameVars.cc	(revision c95b11526c10568ee3415f3873af592f6779ea99)
+++ src/ResolvExpr/RenameVars.cc	(revision 7416d46ae4c80902ec659807c72c4b3d78cdba5c)
@@ -19,4 +19,5 @@
 #include <utility>                 // for pair
 
+#include "Common/PassVisitor.h"
 #include "Common/SemanticError.h"  // for SemanticError
 #include "RenameVars.h"
@@ -27,126 +28,72 @@
 
 namespace ResolvExpr {
-	RenameVars global_renamer;
+	namespace {
+		struct RenameVars {
+			RenameVars();
+			void reset();
 
-	RenameVars::RenameVars() : level( 0 ), resetCount( 0 ) {
-		mapStack.push_front( std::map< std::string, std::string >() );
+			void previsit( TypeInstType * instType );
+			void previsit( Type * );
+			void postvisit( Type * );
+
+		  private:
+			int level, resetCount;
+			std::list< std::map< std::string, std::string > > mapStack;
+		};
+
+		PassVisitor<RenameVars> global_renamer;
+	} // namespace
+
+	void renameTyVars( Type * t ) {
+		t->accept( global_renamer );
 	}
 
-	void RenameVars::reset() {
-		level = 0;
-		resetCount++;
+	void resetTyVarRenaming() {
+		global_renamer.pass.reset();
 	}
 
-	void RenameVars::visit( VoidType *voidType ) {
-		typeBefore( voidType );
-		typeAfter( voidType );
-	}
+	namespace {
+		RenameVars::RenameVars() : level( 0 ), resetCount( 0 ) {
+			mapStack.push_front( std::map< std::string, std::string >() );
+		}
 
-	void RenameVars::visit( BasicType *basicType ) {
-		typeBefore( basicType );
-		typeAfter( basicType );
-	}
+		void RenameVars::reset() {
+			level = 0;
+			resetCount++;
+		}
 
-	void RenameVars::visit( PointerType *pointerType ) {
-		typeBefore( pointerType );
-		maybeAccept( pointerType->get_base(), *this );
-		typeAfter( pointerType );
-	}
+		void RenameVars::previsit( TypeInstType * instType ) {
+			previsit( (Type *)instType );
+			std::map< std::string, std::string >::const_iterator i = mapStack.front().find( instType->name );
+			if ( i != mapStack.front().end() ) {
+				instType->name = i->second;
+			} // if
+		}
 
-	void RenameVars::visit( ArrayType *arrayType ) {
-		typeBefore( arrayType );
-		maybeAccept( arrayType->get_dimension(), *this );
-		maybeAccept( arrayType->get_base(), *this );
-		typeAfter( arrayType );
-	}
+		void RenameVars::previsit( Type * type ) {
+			if ( ! type->forall.empty() ) {
+				// copies current name mapping into new mapping
+				mapStack.push_front( mapStack.front() );
+				// renames all "forall" type names to `_${level}_${name}'
+				for ( auto td : type->forall ) {
+					std::ostringstream output;
+					output << "_" << resetCount << "_" << level << "_" << td->name;
+					std::string newname( output.str() );
+					mapStack.front()[ td->get_name() ] = newname;
+					td->name = newname;
+					// ditto for assertion names, the next level in
+					level++;
+					// acceptAll( td->assertions, *this );
+				} // for
+			} // if
+		}
 
-	void RenameVars::visit( FunctionType *functionType ) {
-		typeBefore( functionType );
-		acceptAll( functionType->get_returnVals(), *this );
-		acceptAll( functionType->get_parameters(), *this );
-		typeAfter( functionType );
-	}
-
-	void RenameVars::visit( StructInstType *aggregateUseType ) {
-		typeBefore( aggregateUseType );
-		acceptAll( aggregateUseType->get_parameters(), *this );
-		typeAfter( aggregateUseType );
-	}
-
-	void RenameVars::visit( UnionInstType *aggregateUseType ) {
-		typeBefore( aggregateUseType );
-		acceptAll( aggregateUseType->get_parameters(), *this );
-		typeAfter( aggregateUseType );
-	}
-
-	void RenameVars::visit( EnumInstType *aggregateUseType ) {
-		typeBefore( aggregateUseType );
-		acceptAll( aggregateUseType->get_parameters(), *this );
-		typeAfter( aggregateUseType );
-	}
-
-	void RenameVars::visit( TraitInstType *aggregateUseType ) {
-		typeBefore( aggregateUseType );
-		acceptAll( aggregateUseType->get_parameters(), *this );
-		typeAfter( aggregateUseType );
-	}
-
-	void RenameVars::visit( TypeInstType *instType ) {
-		typeBefore( instType );
-		std::map< std::string, std::string >::const_iterator i = mapStack.front().find( instType->get_name() );
-		if ( i != mapStack.front().end() ) {
-			instType->set_name( i->second );
-		} else {
-		} // if
-		acceptAll( instType->get_parameters(), *this );
-		typeAfter( instType );
-	}
-
-	void RenameVars::visit( TupleType *tupleType ) {
-		typeBefore( tupleType );
-		acceptAll( tupleType->get_types(), *this );
-		typeAfter( tupleType );
-	}
-
-	void RenameVars::visit( VarArgsType *varArgsType ) {
-		typeBefore( varArgsType );
-		typeAfter( varArgsType );
-	}
-
-	void RenameVars::visit( ZeroType *zeroType ) {
-		typeBefore( zeroType );
-		typeAfter( zeroType );
-	}
-
-	void RenameVars::visit( OneType *oneType ) {
-		typeBefore( oneType );
-		typeAfter( oneType );
-	}
-
-	void RenameVars::typeBefore( Type *type ) {
-		if ( ! type->get_forall().empty() ) {
-			// copies current name mapping into new mapping
-			mapStack.push_front( mapStack.front() );
-			// renames all "forall" type names to `_${level}_${name}'
-			for ( Type::ForallList::iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) {
-				std::ostringstream output;
-				output << "_" << resetCount << "_" << level << "_" << (*i)->get_name();
-				std::string newname( output.str() );
-				mapStack.front()[ (*i)->get_name() ] = newname;
-				(*i)->set_name( newname );
-				// ditto for assertion names, the next level in
-				level++;
-				acceptAll( (*i)->get_assertions(), *this );
-			} // for
-		} // if
-	}
-
-	void RenameVars::typeAfter( Type *type ) {
-		// clears name mapping added by typeBefore()
-		if ( ! type->get_forall().empty() ) {
-			mapStack.pop_front();
-		} // if
-	}
-
+		void RenameVars::postvisit( Type * type ) {
+			// clears name mapping added by typeBefore()
+			if ( ! type->forall.empty() ) {
+				mapStack.pop_front();
+			} // if
+		}
+	} // namespace
 } // namespace ResolvExpr
 
