Index: src/GenPoly/Box.cc
===================================================================
--- src/GenPoly/Box.cc	(revision eada3cfc526a731d1ac85003f73c04f68d7ae037)
+++ src/GenPoly/Box.cc	(revision 92b3de18e700712b3d68077d08943feb95d6e9e4)
@@ -32,5 +32,4 @@
 #include "Common/UniqueName.h"           // for UniqueName
 #include "Common/utility.h"              // for toString
-#include "DeclMutator.h"                 // for DeclMutator
 #include "FindFunction.h"                // for findFunction, findAndReplace...
 #include "GenPoly/ErasableScopedMap.h"   // for ErasableScopedMap<>::const_i...
@@ -63,13 +62,10 @@
 
 		/// Adds layout-generation functions to polymorphic types
-		class LayoutFunctionBuilder final : public DeclMutator {
-			unsigned int functionNesting;  // current level of nested functions
+		class LayoutFunctionBuilder final : public WithDeclsToAdd, public WithVisitorRef<LayoutFunctionBuilder>, public WithShortCircuiting {
+			unsigned int functionNesting = 0;  // current level of nested functions
 		public:
-			LayoutFunctionBuilder() : functionNesting( 0 ) {}
-
-			using DeclMutator::mutate;
-			virtual DeclarationWithType *mutate( FunctionDecl *functionDecl ) override;
-			virtual Declaration *mutate( StructDecl *structDecl ) override;
-			virtual Declaration *mutate( UnionDecl *unionDecl ) override;
+			void previsit( FunctionDecl *functionDecl );
+			void previsit( StructDecl *structDecl );
+			void previsit( UnionDecl *unionDecl );
 		};
 
@@ -247,5 +243,5 @@
 
 	void box( std::list< Declaration *>& translationUnit ) {
-		LayoutFunctionBuilder layoutBuilder;
+		PassVisitor<LayoutFunctionBuilder> layoutBuilder;
 		Pass1 pass1;
 		Pass2 pass2;
@@ -253,5 +249,5 @@
 		Pass3 pass3;
 
-		layoutBuilder.mutateDeclarationList( translationUnit );
+		acceptAll( translationUnit, layoutBuilder );
 		mutateTranslationUnit/*All*/( translationUnit, pass1 );
 		mutateTranslationUnit/*All*/( translationUnit, pass2 );
@@ -262,10 +258,10 @@
 	////////////////////////////////// LayoutFunctionBuilder ////////////////////////////////////////////
 
-	DeclarationWithType *LayoutFunctionBuilder::mutate( FunctionDecl *functionDecl ) {
-		functionDecl->set_functionType( maybeMutate( functionDecl->get_functionType(), *this ) );
+	void LayoutFunctionBuilder::previsit( FunctionDecl *functionDecl ) {
+		visit_children = false;
+		maybeAccept( functionDecl->get_functionType(), *visitor );
 		++functionNesting;
-		functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) );
+		maybeAccept( functionDecl->get_statements(), *visitor );
 		--functionNesting;
-		return functionDecl;
 	}
 
@@ -356,11 +352,12 @@
 	}
 
-	Declaration *LayoutFunctionBuilder::mutate( StructDecl *structDecl ) {
+	void LayoutFunctionBuilder::previsit( StructDecl *structDecl ) {
 		// do not generate layout function for "empty" tag structs
-		if ( structDecl->get_members().empty() ) return structDecl;
+		visit_children = false;
+		if ( structDecl->get_members().empty() ) return;
 
 		// get parameters that can change layout, exiting early if none
 		std::list< TypeDecl* > otypeParams = takeOtypeOnly( structDecl->get_parameters() );
-		if ( otypeParams.empty() ) return structDecl;
+		if ( otypeParams.empty() ) return;
 
 		// build layout function signature
@@ -413,15 +410,15 @@
 		addStmt( layoutDecl->get_statements(), makeAlignTo( derefVar( sizeParam ), derefVar( alignParam ) ) );
 
-		addDeclarationAfter( layoutDecl );
-		return structDecl;
+		declsToAddAfter.push_back( layoutDecl );
 	}
 
-	Declaration *LayoutFunctionBuilder::mutate( UnionDecl *unionDecl ) {
+	void LayoutFunctionBuilder::previsit( UnionDecl *unionDecl ) {
 		// do not generate layout function for "empty" tag unions
-		if ( unionDecl->get_members().empty() ) return unionDecl;
+		visit_children = false;
+		if ( unionDecl->get_members().empty() ) return;
 
 		// get parameters that can change layout, exiting early if none
 		std::list< TypeDecl* > otypeParams = takeOtypeOnly( unionDecl->get_parameters() );
-		if ( otypeParams.empty() ) return unionDecl;
+		if ( otypeParams.empty() ) return;
 
 		// build layout function signature
@@ -456,6 +453,5 @@
 		addStmt( layoutDecl->get_statements(), makeAlignTo( derefVar( sizeParam ), derefVar( alignParam ) ) );
 
-		addDeclarationAfter( layoutDecl );
-		return unionDecl;
+		declsToAddAfter.push_back( layoutDecl );
 	}
 
