Index: src/ControlStruct/MultiLevelExit.cpp
===================================================================
--- src/ControlStruct/MultiLevelExit.cpp	(revision dd3263c12bfb027e62dfafee97f41063e987396a)
+++ src/ControlStruct/MultiLevelExit.cpp	(revision 66daee4974e1e75ffed3982f0d1d4a29e4eb5941)
@@ -9,7 +9,7 @@
 // Author           : Andrew Beach
 // Created On       : Mon Nov  1 13:48:00 2021
-// Last Modified By : Andrew Beach
-// Last Modified On : Mon Nov  8 10:56:00 2021
-// Update Count     : 2
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Mon Jan 31 22:35:08 2022
+// Update Count     : 28
 //
 
@@ -18,21 +18,20 @@
 #include "AST/Pass.hpp"
 #include "AST/Stmt.hpp"
-#include "ControlStruct/LabelGenerator.h"
+#include "LabelGeneratorNew.hpp"
 
 #include <set>
+using namespace std;
+using namespace ast;
 
 namespace ControlStruct {
-
-namespace {
-
 class Entry {
-public:
-	const ast::Stmt * stmt;
-private:
+  public:
+	const Stmt * stmt;
+  private:
 	// Organized like a manual ADT. Avoids creating a bunch of dead data.
 	struct Target {
-		ast::Label label;
+		Label label;
 		bool used = false;
-		Target( const ast::Label & label ) : label( label ) {}
+		Target( const Label & label ) : label( label ) {}
 		Target() : label( CodeLocation() ) {}
 	};
@@ -41,49 +40,49 @@
 
 	enum Kind {
-		ForStmt, WhileStmt, CompoundStmt, IfStmt, CaseStmt, SwitchStmt, TryStmt
+		ForStmtK, WhileStmtK, CompoundStmtK, IfStmtK, CaseStmtK, SwitchStmtK, TryStmtK
 	} kind;
 
 	bool fallDefaultValid = true;
 
-	static ast::Label & useTarget( Target & target ) {
+	static Label & useTarget( Target & target ) {
 		target.used = true;
 		return target.label;
 	}
 
-public:
-	Entry( const ast::ForStmt * stmt, ast::Label breakExit, ast::Label contExit ) :
-		stmt( stmt ), firstTarget( breakExit ), secondTarget( contExit ), kind( ForStmt ) {}
-	Entry( const ast::WhileStmt * stmt, ast::Label breakExit, ast::Label contExit ) :
-		stmt( stmt ), firstTarget( breakExit ), secondTarget( contExit ), kind( WhileStmt ) {}
-	Entry( const ast::CompoundStmt *stmt, ast::Label breakExit ) :
-		stmt( stmt ), firstTarget( breakExit ), secondTarget(), kind( CompoundStmt ) {}
-	Entry( const ast::IfStmt *stmt, ast::Label breakExit ) :
-		stmt( stmt ), firstTarget( breakExit ), secondTarget(), kind( IfStmt ) {}
-	Entry( const ast::CaseStmt *stmt, ast::Label fallExit ) :
-		stmt( stmt ), firstTarget( fallExit ), secondTarget(), kind( CaseStmt ) {}
-	Entry( const ast::SwitchStmt *stmt, ast::Label breakExit, ast::Label fallDefaultExit ) :
-		stmt( stmt ), firstTarget( breakExit ), secondTarget( fallDefaultExit ), kind( SwitchStmt ) {}
-	Entry( const ast::TryStmt *stmt, ast::Label breakExit ) :
-		stmt( stmt ), firstTarget( breakExit ), secondTarget(), kind( TryStmt ) {}
-
-	bool isContTarget() const { return kind <= WhileStmt; }
-	bool isBreakTarget() const { return CaseStmt != kind; }
-	bool isFallTarget() const { return CaseStmt == kind; }
-	bool isFallDefaultTarget() const { return SwitchStmt == kind; }
-
-	ast::Label useContExit() { assert( kind <= WhileStmt ); return useTarget(secondTarget); }
-	ast::Label useBreakExit() { assert( CaseStmt != kind ); return useTarget(firstTarget); }
-	ast::Label useFallExit() { assert( CaseStmt == kind );  return useTarget(firstTarget); }
-	ast::Label useFallDefaultExit() { assert( SwitchStmt == kind ); return useTarget(secondTarget); }
-
-	bool isContUsed() const { assert( kind <= WhileStmt ); return secondTarget.used; }
-	bool isBreakUsed() const { assert( CaseStmt != kind ); return firstTarget.used; }
-	bool isFallUsed() const { assert( CaseStmt == kind ); return firstTarget.used; }
-	bool isFallDefaultUsed() const { assert( SwitchStmt == kind ); return secondTarget.used; }
+  public:
+	Entry( const ForStmt * stmt, Label breakExit, Label contExit ) :
+		stmt( stmt ), firstTarget( breakExit ), secondTarget( contExit ), kind( ForStmtK ) {}
+	Entry( const WhileStmt * stmt, Label breakExit, Label contExit ) :
+		stmt( stmt ), firstTarget( breakExit ), secondTarget( contExit ), kind( WhileStmtK ) {}
+	Entry( const CompoundStmt *stmt, Label breakExit ) :
+		stmt( stmt ), firstTarget( breakExit ), secondTarget(), kind( CompoundStmtK ) {}
+	Entry( const IfStmt *stmt, Label breakExit ) :
+		stmt( stmt ), firstTarget( breakExit ), secondTarget(), kind( IfStmtK ) {}
+	Entry( const CaseStmt *stmt, Label fallExit ) :
+		stmt( stmt ), firstTarget( fallExit ), secondTarget(), kind( CaseStmtK ) {}
+	Entry( const SwitchStmt *stmt, Label breakExit, Label fallDefaultExit ) :
+		stmt( stmt ), firstTarget( breakExit ), secondTarget( fallDefaultExit ), kind( SwitchStmtK ) {}
+	Entry( const TryStmt *stmt, Label breakExit ) :
+		stmt( stmt ), firstTarget( breakExit ), secondTarget(), kind( TryStmtK ) {}
+
+	bool isContTarget() const { return kind <= WhileStmtK; }
+	bool isBreakTarget() const { return kind != CaseStmtK; }
+	bool isFallTarget() const { return kind == CaseStmtK; }
+	bool isFallDefaultTarget() const { return kind == SwitchStmtK; }
+
+	Label useContExit() { assert( kind <= WhileStmtK ); return useTarget(secondTarget); }
+	Label useBreakExit() { assert( kind != CaseStmtK ); return useTarget(firstTarget); }
+	Label useFallExit() { assert( kind == CaseStmtK );  return useTarget(firstTarget); }
+	Label useFallDefaultExit() { assert( kind == SwitchStmtK ); return useTarget(secondTarget); }
+
+	bool isContUsed() const { assert( kind <= WhileStmtK ); return secondTarget.used; }
+	bool isBreakUsed() const { assert( kind != CaseStmtK ); return firstTarget.used; }
+	bool isFallUsed() const { assert( kind == CaseStmtK ); return firstTarget.used; }
+	bool isFallDefaultUsed() const { assert( kind == SwitchStmtK ); return secondTarget.used; }
 	void seenDefault() { fallDefaultValid = false; }
 	bool isFallDefaultValid() const { return fallDefaultValid; }
 };
 
-// Helper predicates used in std::find_if calls (it doesn't take methods):
+// Helper predicates used in find_if calls (it doesn't take methods):
 bool isBreakTarget( const Entry & entry ) {
 	return entry.isBreakTarget();
@@ -103,32 +102,32 @@
 
 struct MultiLevelExitCore final :
-		public ast::WithVisitorRef<MultiLevelExitCore>,
-		public ast::WithShortCircuiting, public ast::WithGuards {
+	public WithVisitorRef<MultiLevelExitCore>,
+	public WithShortCircuiting, public WithGuards {
 	MultiLevelExitCore( const LabelToStmt & lt );
 
-	void previsit( const ast::FunctionDecl * );
-
-	const ast::CompoundStmt * previsit( const ast::CompoundStmt * );
-	const ast::BranchStmt * postvisit( const ast::BranchStmt * );
-	void previsit( const ast::WhileStmt * );
-	const ast::WhileStmt * postvisit( const ast::WhileStmt * );
-	void previsit( const ast::ForStmt * );
-	const ast::ForStmt * postvisit( const ast::ForStmt * );
-	const ast::CaseStmt * previsit( const ast::CaseStmt * );
-	void previsit( const ast::IfStmt * );
-	const ast::IfStmt * postvisit( const ast::IfStmt * );
-	void previsit( const ast::SwitchStmt * );
-	const ast::SwitchStmt * postvisit( const ast::SwitchStmt * );
-	void previsit( const ast::ReturnStmt * );
-	void previsit( const ast::TryStmt * );
-	void postvisit( const ast::TryStmt * );
-	void previsit( const ast::FinallyStmt * );
-
-	const ast::Stmt * mutateLoop( const ast::Stmt * body, Entry& );
+	void previsit( const FunctionDecl * );
+
+	const CompoundStmt * previsit( const CompoundStmt * );
+	const BranchStmt * postvisit( const BranchStmt * );
+	void previsit( const WhileStmt * );
+	const WhileStmt * postvisit( const WhileStmt * );
+	void previsit( const ForStmt * );
+	const ForStmt * postvisit( const ForStmt * );
+	const CaseStmt * previsit( const CaseStmt * );
+	void previsit( const IfStmt * );
+	const IfStmt * postvisit( const IfStmt * );
+	void previsit( const SwitchStmt * );
+	const SwitchStmt * postvisit( const SwitchStmt * );
+	void previsit( const ReturnStmt * );
+	void previsit( const TryStmt * );
+	void postvisit( const TryStmt * );
+	void previsit( const FinallyStmt * );
+
+	const Stmt * mutateLoop( const Stmt * body, Entry& );
 
 	const LabelToStmt & target_table;
-	std::set<ast::Label> fallthrough_labels;
-	std::vector<Entry> enclosing_control_structures;
-	ast::Label break_label;
+	set<Label> fallthrough_labels;
+	vector<Entry> enclosing_control_structures;
+	Label break_label;
 	bool inFinally;
 
@@ -138,17 +137,17 @@
 	const LoopNode * posthandleLoopStmt( const LoopNode * loopStmt );
 
-	std::list<ast::ptr<ast::Stmt>> fixBlock(
-		const std::list<ast::ptr<ast::Stmt>> & kids, bool caseClause );
+	list<ptr<Stmt>> fixBlock(
+		const list<ptr<Stmt>> & kids, bool caseClause );
 
 	template<typename UnaryPredicate>
 	auto findEnclosingControlStructure( UnaryPredicate pred ) {
-		return std::find_if( enclosing_control_structures.rbegin(),
-			enclosing_control_structures.rend(), pred );
+		return find_if( enclosing_control_structures.rbegin(),
+						enclosing_control_structures.rend(), pred );
 	}
 };
 
-ast::NullStmt * labelledNullStmt(
-		const CodeLocation & cl, const ast::Label & label ) {
-	return new ast::NullStmt( cl, std::vector<ast::Label>{ label } );
+NullStmt * labelledNullStmt(
+	const CodeLocation & cl, const Label & label ) {
+	return new NullStmt( cl, vector<Label>{ label } );
 }
 
@@ -158,21 +157,21 @@
 {}
 
-void MultiLevelExitCore::previsit( const ast::FunctionDecl * ) {
+void MultiLevelExitCore::previsit( const FunctionDecl * ) {
 	visit_children = false;
 }
 
-const ast::CompoundStmt * MultiLevelExitCore::previsit(
-		const ast::CompoundStmt * stmt ) {
+const CompoundStmt * MultiLevelExitCore::previsit(
+	const CompoundStmt * stmt ) {
 	visit_children = false;
 	bool isLabeled = !stmt->labels.empty();
 	if ( isLabeled ) {
-		ast::Label breakLabel = LabelGenerator::newLabel( "blockBreak", stmt );
+		Label breakLabel = newLabel( "blockBreak", stmt );
 		enclosing_control_structures.emplace_back( stmt, breakLabel );
 		GuardAction( [this]() { enclosing_control_structures.pop_back(); } );
 	}
 
-	auto mutStmt = ast::mutate( stmt );
+	auto mutStmt = mutate( stmt );
 	// A child statement may set the break label.
-	mutStmt->kids = std::move( fixBlock( stmt->kids, false ) );
+	mutStmt->kids = move( fixBlock( stmt->kids, false ) );
 
 	if ( isLabeled ) {
@@ -187,15 +186,15 @@
 
 size_t getUnusedIndex(
-		const ast::Stmt * stmt, const ast::Label & originalTarget ) {
+	const Stmt * stmt, const Label & originalTarget ) {
 	const size_t size = stmt->labels.size();
 
-	// If the label is empty, we can skip adding the unused attribute:
-	if ( originalTarget.empty() ) return size;
+	// If the label is empty, do not add unused attribute.
+  if ( originalTarget.empty() ) return size;
 
 	// Search for a label that matches the originalTarget.
 	for ( size_t i = 0 ; i < size ; ++i ) {
-		const ast::Label & label = stmt->labels[i];
+		const Label & label = stmt->labels[i];
 		if ( label == originalTarget ) {
-			for ( const ast::Attribute * attr : label.attributes ) {
+			for ( const Attribute * attr : label.attributes ) {
 				if ( attr->name == "unused" ) return size;
 			}
@@ -204,127 +203,124 @@
 	}
 	assertf( false, "Could not find label '%s' on statement %s",
-		originalTarget.name.c_str(), toString( stmt ).c_str() );
-}
-
-const ast::Stmt * addUnused(
-		const ast::Stmt * stmt, const ast::Label & originalTarget ) {
+			 originalTarget.name.c_str(), toString( stmt ).c_str() );
+}
+
+const Stmt * addUnused(
+	const Stmt * stmt, const Label & originalTarget ) {
 	size_t i = getUnusedIndex( stmt, originalTarget );
 	if ( i == stmt->labels.size() ) {
 		return stmt;
 	}
-	ast::Stmt * mutStmt = ast::mutate( stmt );
-	mutStmt->labels[i].attributes.push_back( new ast::Attribute( "unused" ) );
+	Stmt * mutStmt = mutate( stmt );
+	mutStmt->labels[i].attributes.push_back( new Attribute( "unused" ) );
 	return mutStmt;
 }
 
-const ast::BranchStmt * MultiLevelExitCore::postvisit( const ast::BranchStmt * stmt ) {
-	std::vector<Entry>::reverse_iterator targetEntry =
+const BranchStmt * MultiLevelExitCore::postvisit( const BranchStmt * stmt ) {
+	vector<Entry>::reverse_iterator targetEntry =
 		enclosing_control_structures.rend();
 	switch ( stmt->kind ) {
-	case ast::BranchStmt::Goto:
+	  case BranchStmt::Goto:
 		return stmt;
-	case ast::BranchStmt::Continue:
-	case ast::BranchStmt::Break: {
-		bool isContinue = stmt->kind == ast::BranchStmt::Continue;
-		// Handle unlabeled break and continue.
-		if ( stmt->target.empty() ) {
-			if ( isContinue ) {
-				targetEntry = findEnclosingControlStructure( isContinueTarget );
-			} else {
-				if ( enclosing_control_structures.empty() ) {
-					SemanticError( stmt->location,
-						"'break' outside a loop, 'switch', or labelled block" );
-				}
-				targetEntry = findEnclosingControlStructure( isBreakTarget );
-			}
-		// Handle labeled break and continue.
-		} else {
-			// Lookup label in table to find attached control structure.
-			targetEntry = findEnclosingControlStructure(
-				[ targetStmt = target_table.at(stmt->target) ](auto entry){
-					return entry.stmt == targetStmt;
-				} );
-		}
-		// Ensure that selected target is valid.
-		if ( targetEntry == enclosing_control_structures.rend() || ( isContinue && !isContinueTarget( *targetEntry ) ) ) {
-			SemanticError(
-				stmt->location,
-				toString( (isContinue ? "'continue'" : "'break'"),
-					" target must be an enclosing ",
-					(isContinue ? "loop: " : "control structure: "),
-					stmt->originalTarget ) );
-		}
-		break;
-	}
-	case ast::BranchStmt::FallThrough: {
-		targetEntry = findEnclosingControlStructure( isFallthroughTarget );
-		// Check that target is valid.
-		if ( targetEntry == enclosing_control_structures.rend() ) {
-			SemanticError( stmt->location, "'fallthrough' must be enclosed in a 'switch' or 'choose'" );
-		}
-		if ( !stmt->target.empty() ) {
-			// Labelled fallthrough: target must be a valid fallthough label.
-			if ( !fallthrough_labels.count( stmt->target ) ) {
-				SemanticError( stmt->location, toString( "'fallthrough' target must be a later case statement: ", stmt->originalTarget ) );
-			}
-			return new ast::BranchStmt(
-				stmt->location, ast::BranchStmt::Goto, stmt->originalTarget );
-		}
-		break;
-	}
-	case ast::BranchStmt::FallThroughDefault: {
-		targetEntry = findEnclosingControlStructure( isFallthroughDefaultTarget );
-
-		// Check that this is in a switch or choose statement.
-		if ( targetEntry == enclosing_control_structures.rend() ) {
-			SemanticError( stmt->location, "'fallthrough' must be enclosed in a 'switch' or 'choose'" );
-		}
-
-		// Check that the switch or choose has a default clause.
-		auto switchStmt = strict_dynamic_cast< const ast::SwitchStmt * >(
-			targetEntry->stmt );
-		bool foundDefault = false;
-		for ( auto subStmt : switchStmt->stmts ) {
-			const ast::CaseStmt * caseStmt = subStmt.strict_as<ast::CaseStmt>();
-			if ( caseStmt->isDefault() ) {
-				foundDefault = true;
-				break;
-			}
-		}
-		if ( !foundDefault ) {
-			SemanticError( stmt->location, "'fallthrough default' must be enclosed in a 'switch' or 'choose' control structure with a 'default' clause" );
-		}
-		break;
-	}
-	default:
+	  case BranchStmt::Continue:
+	  case BranchStmt::Break: {
+		  bool isContinue = stmt->kind == BranchStmt::Continue;
+		  // Handle unlabeled break and continue.
+		  if ( stmt->target.empty() ) {
+			  if ( isContinue ) {
+				  targetEntry = findEnclosingControlStructure( isContinueTarget );
+			  } else {
+				  if ( enclosing_control_structures.empty() ) {
+					  SemanticError( stmt->location,
+									 "'break' outside a loop, 'switch', or labelled block" );
+				  }
+				  targetEntry = findEnclosingControlStructure( isBreakTarget );
+			  }
+			  // Handle labeled break and continue.
+		  } else {
+			  // Lookup label in table to find attached control structure.
+			  targetEntry = findEnclosingControlStructure(
+				  [ targetStmt = target_table.at(stmt->target) ](auto entry){
+					  return entry.stmt == targetStmt;
+				  } );
+		  }
+		  // Ensure that selected target is valid.
+		  if ( targetEntry == enclosing_control_structures.rend() || ( isContinue && !isContinueTarget( *targetEntry ) ) ) {
+			  SemanticError( stmt->location, toString( (isContinue ? "'continue'" : "'break'"),
+							" target must be an enclosing ", (isContinue ? "loop: " : "control structure: "),
+							stmt->originalTarget ) );
+		  }
+		  break;
+	  }
+	  case BranchStmt::FallThrough: {
+		  targetEntry = findEnclosingControlStructure( isFallthroughTarget );
+		  // Check that target is valid.
+		  if ( targetEntry == enclosing_control_structures.rend() ) {
+			  SemanticError( stmt->location, "'fallthrough' must be enclosed in a 'switch' or 'choose'" );
+		  }
+		  if ( !stmt->target.empty() ) {
+			  // Labelled fallthrough: target must be a valid fallthough label.
+			  if ( !fallthrough_labels.count( stmt->target ) ) {
+				  SemanticError( stmt->location, toString( "'fallthrough' target must be a later case statement: ",
+														   stmt->originalTarget ) );
+			  }
+			  return new BranchStmt(
+				  stmt->location, BranchStmt::Goto, stmt->originalTarget );
+		  }
+		  break;
+	  }
+	  case BranchStmt::FallThroughDefault: {
+		  targetEntry = findEnclosingControlStructure( isFallthroughDefaultTarget );
+
+		  // Check if in switch or choose statement.
+		  if ( targetEntry == enclosing_control_structures.rend() ) {
+			  SemanticError( stmt->location, "'fallthrough' must be enclosed in a 'switch' or 'choose'" );
+		  }
+
+		  // Check if switch or choose has default clause.
+		  auto switchStmt = strict_dynamic_cast< const SwitchStmt * >( targetEntry->stmt );
+		  bool foundDefault = false;
+		  for ( auto subStmt : switchStmt->stmts ) {
+			  const CaseStmt * caseStmt = subStmt.strict_as<CaseStmt>();
+			  if ( caseStmt->isDefault() ) {
+				  foundDefault = true;
+				  break;
+			  }
+		  }
+		  if ( ! foundDefault ) {
+			  SemanticError( stmt->location, "'fallthrough default' must be enclosed in a 'switch' or 'choose'"
+							 "control structure with a 'default' clause" );
+		  }
+		  break;
+	  }
+	  default:
 		assert( false );
 	}
 
 	// Branch error checks: get the appropriate label name:
-	// (This label will always be replaced.)
-	ast::Label exitLabel( CodeLocation(), "" );
+	// (This label is always replaced.)
+	Label exitLabel( CodeLocation(), "" );
 	switch ( stmt->kind ) {
-	case ast::BranchStmt::Break:
+	  case BranchStmt::Break:
 		assert( !targetEntry->useBreakExit().empty() );
 		exitLabel = targetEntry->useBreakExit();
 		break;
-	case ast::BranchStmt::Continue:
+	  case BranchStmt::Continue:
 		assert( !targetEntry->useContExit().empty() );
 		exitLabel = targetEntry->useContExit();
 		break;
-	case ast::BranchStmt::FallThrough:
+	  case BranchStmt::FallThrough:
 		assert( !targetEntry->useFallExit().empty() );
 		exitLabel = targetEntry->useFallExit();
 		break;
-	case ast::BranchStmt::FallThroughDefault:
+	  case BranchStmt::FallThroughDefault:
 		assert( !targetEntry->useFallDefaultExit().empty() );
 		exitLabel = targetEntry->useFallDefaultExit();
 		// Check that fallthrough default comes before the default clause.
 		if ( !targetEntry->isFallDefaultValid() ) {
-			SemanticError( stmt->location,
-				"'fallthrough default' must precede the 'default' clause" );
+			SemanticError( stmt->location, "'fallthrough default' must precede the 'default' clause" );
 		}
 		break;
-	default:
+	  default:
 		assert(0);
 	}
@@ -333,21 +329,21 @@
 	targetEntry->stmt = addUnused( targetEntry->stmt, stmt->originalTarget );
 
-	// Replace this with a goto to make later passes more uniform.
-	return new ast::BranchStmt( stmt->location, ast::BranchStmt::Goto, exitLabel );
-}
-
-void MultiLevelExitCore::previsit( const ast::WhileStmt * stmt ) {
+	// Replace with goto to make later passes more uniform.
+	return new BranchStmt( stmt->location, BranchStmt::Goto, exitLabel );
+}
+
+void MultiLevelExitCore::previsit( const WhileStmt * stmt ) {
 	return prehandleLoopStmt( stmt );
 }
 
-const ast::WhileStmt * MultiLevelExitCore::postvisit( const ast::WhileStmt * stmt ) {
+const WhileStmt * MultiLevelExitCore::postvisit( const WhileStmt * stmt ) {
 	return posthandleLoopStmt( stmt );
 }
 
-void MultiLevelExitCore::previsit( const ast::ForStmt * stmt ) {
+void MultiLevelExitCore::previsit( const ForStmt * stmt ) {
 	return prehandleLoopStmt( stmt );
 }
 
-const ast::ForStmt * MultiLevelExitCore::postvisit( const ast::ForStmt * stmt ) {
+const ForStmt * MultiLevelExitCore::postvisit( const ForStmt * stmt ) {
 	return posthandleLoopStmt( stmt );
 }
@@ -355,16 +351,16 @@
 // Mimic what the built-in push_front would do anyways. It is O(n).
 void push_front(
-		std::vector<ast::ptr<ast::Stmt>> & vec, const ast::Stmt * element ) {
+	vector<ptr<Stmt>> & vec, const Stmt * element ) {
 	vec.emplace_back( nullptr );
 	for ( size_t i = vec.size() - 1 ; 0 < i ; --i ) {
-		vec[ i ] = std::move( vec[ i - 1 ] );
+		vec[ i ] = move( vec[ i - 1 ] );
 	}
 	vec[ 0 ] = element;
 }
 
-const ast::CaseStmt * MultiLevelExitCore::previsit( const ast::CaseStmt * stmt ) {
+const CaseStmt * MultiLevelExitCore::previsit( const CaseStmt * stmt ) {
 	visit_children = false;
 
-	// If it is the default, mark the default as seen.
+	// If default, mark seen.
 	if ( stmt->isDefault() ) {
 		assert( !enclosing_control_structures.empty() );
@@ -373,23 +369,23 @@
 
 	// The cond may not exist, but if it does update it now.
-	visitor->maybe_accept( stmt, &ast::CaseStmt::cond );
+	visitor->maybe_accept( stmt, &CaseStmt::cond );
 
 	// Just save the mutated node for simplicity.
-	ast::CaseStmt * mutStmt = ast::mutate( stmt );
-
-	ast::Label fallLabel = LabelGenerator::newLabel( "fallThrough", stmt );
-	if ( !mutStmt->stmts.empty() ) {
+	CaseStmt * mutStmt = mutate( stmt );
+
+	Label fallLabel = newLabel( "fallThrough", stmt );
+	if ( ! mutStmt->stmts.empty() ) {
 		// Ensure that the stack isn't corrupted by exceptions in fixBlock.
 		auto guard = makeFuncGuard(
 			[&](){ enclosing_control_structures.emplace_back( mutStmt, fallLabel ); },
 			[this](){ enclosing_control_structures.pop_back(); }
-		);
+			);
 
 		// These should already be in a block.
-		auto block = ast::mutate( mutStmt->stmts.front().strict_as<ast::CompoundStmt>() );
+		auto block = mutate( mutStmt->stmts.front().strict_as<CompoundStmt>() );
 		block->kids = fixBlock( block->kids, true );
 
 		// Add fallthrough label if necessary.
-		assert( !enclosing_control_structures.empty() );
+		assert( ! enclosing_control_structures.empty() );
 		Entry & entry = enclosing_control_structures.back();
 		if ( entry.isFallUsed() ) {
@@ -398,15 +394,15 @@
 		}
 	}
-	assert( !enclosing_control_structures.empty() );
+	assert( ! enclosing_control_structures.empty() );
 	Entry & entry = enclosing_control_structures.back();
-	assertf( dynamic_cast< const ast::SwitchStmt * >( entry.stmt ),
-		"Control structure enclosing a case clause must be a switch, but is: %s",
-		toString( entry.stmt ).c_str() );
+	assertf( dynamic_cast< const SwitchStmt * >( entry.stmt ),
+			 "Control structure enclosing a case clause must be a switch, but is: %s",
+			 toString( entry.stmt ).c_str() );
 	if ( mutStmt->isDefault() ) {
 		if ( entry.isFallDefaultUsed() ) {
 			// Add fallthrough default label if necessary.
 			push_front( mutStmt->stmts, labelledNullStmt(
-				stmt->location, entry.useFallDefaultExit()
-			) );
+							stmt->location, entry.useFallDefaultExit()
+							) );
 		}
 	}
@@ -414,8 +410,8 @@
 }
 
-void MultiLevelExitCore::previsit( const ast::IfStmt * stmt ) {
+void MultiLevelExitCore::previsit( const IfStmt * stmt ) {
 	bool labeledBlock = !stmt->labels.empty();
 	if ( labeledBlock ) {
-		ast::Label breakLabel = LabelGenerator::newLabel( "blockBreak", stmt );
+		Label breakLabel = newLabel( "blockBreak", stmt );
 		enclosing_control_structures.emplace_back( stmt, breakLabel );
 		GuardAction( [this](){ enclosing_control_structures.pop_back(); } );
@@ -423,5 +419,5 @@
 }
 
-const ast::IfStmt * MultiLevelExitCore::postvisit( const ast::IfStmt * stmt ) {
+const IfStmt * MultiLevelExitCore::postvisit( const IfStmt * stmt ) {
 	bool labeledBlock = !stmt->labels.empty();
 	if ( labeledBlock ) {
@@ -434,29 +430,29 @@
 }
 
-bool isDefaultCase( const ast::ptr<ast::Stmt> & stmt ) {
-	const ast::CaseStmt * caseStmt = stmt.strict_as<ast::CaseStmt>();
+bool isDefaultCase( const ptr<Stmt> & stmt ) {
+	const CaseStmt * caseStmt = stmt.strict_as<CaseStmt>();
 	return caseStmt->isDefault();
 }
 
-void MultiLevelExitCore::previsit( const ast::SwitchStmt * stmt ) {
-	ast::Label label = LabelGenerator::newLabel( "switchBreak", stmt );
-	auto it = std::find_if( stmt->stmts.rbegin(), stmt->stmts.rend(), isDefaultCase );
-
-	const ast::CaseStmt * defaultCase = it != stmt->stmts.rend()
-		? (it)->strict_as<ast::CaseStmt>() : nullptr;
-	ast::Label defaultLabel = defaultCase
-		? LabelGenerator::newLabel( "fallThroughDefault", defaultCase )
-		: ast::Label( stmt->location, "" );
+void MultiLevelExitCore::previsit( const SwitchStmt * stmt ) {
+	Label label = newLabel( "switchBreak", stmt );
+	auto it = find_if( stmt->stmts.rbegin(), stmt->stmts.rend(), isDefaultCase );
+
+	const CaseStmt * defaultCase = it != stmt->stmts.rend()
+		? (it)->strict_as<CaseStmt>() : nullptr;
+	Label defaultLabel = defaultCase
+		? newLabel( "fallThroughDefault", defaultCase )
+		: Label( stmt->location, "" );
 	enclosing_control_structures.emplace_back( stmt, label, defaultLabel );
 	GuardAction( [this]() { enclosing_control_structures.pop_back(); } );
 
 	// Collect valid labels for fallthrough. It starts with all labels at
-	// this level, then removed as we see them in traversal.
-	for ( const ast::Stmt * stmt : stmt->stmts ) {
-		auto * caseStmt = strict_dynamic_cast< const ast::CaseStmt * >( stmt );
+	// this level, then remove as each is seen during traversal.
+	for ( const Stmt * stmt : stmt->stmts ) {
+		auto * caseStmt = strict_dynamic_cast< const CaseStmt * >( stmt );
 		if ( caseStmt->stmts.empty() ) continue;
-		auto block = caseStmt->stmts.front().strict_as<ast::CompoundStmt>();
-		for ( const ast::Stmt * stmt : block->kids ) {
-			for ( const ast::Label & l : stmt->labels ) {
+		auto block = caseStmt->stmts.front().strict_as<CompoundStmt>();
+		for ( const Stmt * stmt : block->kids ) {
+			for ( const Label & l : stmt->labels ) {
 				fallthrough_labels.insert( l );
 			}
@@ -465,26 +461,26 @@
 }
 
-const ast::SwitchStmt * MultiLevelExitCore::postvisit( const ast::SwitchStmt * stmt ) {
+const SwitchStmt * MultiLevelExitCore::postvisit( const SwitchStmt * stmt ) {
 	assert( !enclosing_control_structures.empty() );
 	Entry & entry = enclosing_control_structures.back();
 	assert( entry.stmt == stmt );
 
-	// Only run if we need to generate the break label.
+	// Only run to generate the break label.
 	if ( entry.isBreakUsed() ) {
 		// To keep the switch statements uniform (all direct children of a
 		// SwitchStmt should be CastStmts), append the exit label and break
 		// to the last case, create a default case is there are no cases.
-		ast::SwitchStmt * mutStmt = ast::mutate( stmt );
+		SwitchStmt * mutStmt = mutate( stmt );
 		if ( mutStmt->stmts.empty() ) {
-			mutStmt->stmts.push_back( new ast::CaseStmt(
-				mutStmt->location, nullptr, {} ));
-		}
-
-		auto caseStmt = mutStmt->stmts.back().strict_as<ast::CaseStmt>();
-		auto mutCase = ast::mutate( caseStmt );
+			mutStmt->stmts.push_back( new CaseStmt(
+										  mutStmt->location, nullptr, {} ));
+		}
+
+		auto caseStmt = mutStmt->stmts.back().strict_as<CaseStmt>();
+		auto mutCase = mutate( caseStmt );
 		mutStmt->stmts.back() = mutCase;
 
-		ast::Label label( mutCase->location, "breakLabel" );
-		auto branch = new ast::BranchStmt( mutCase->location, ast::BranchStmt::Break, label );
+		Label label( mutCase->location, "breakLabel" );
+		auto branch = new BranchStmt( mutCase->location, BranchStmt::Break, label );
 		branch->labels.push_back( entry.useBreakExit() );
 		mutCase->stmts.push_back( branch );
@@ -495,5 +491,5 @@
 }
 
-void MultiLevelExitCore::previsit( const ast::ReturnStmt * stmt ) {
+void MultiLevelExitCore::previsit( const ReturnStmt * stmt ) {
 	if ( inFinally ) {
 		SemanticError( stmt->location, "'return' may not appear in a finally clause" );
@@ -501,8 +497,8 @@
 }
 
-void MultiLevelExitCore::previsit( const ast::TryStmt * stmt ) {
+void MultiLevelExitCore::previsit( const TryStmt * stmt ) {
 	bool isLabeled = !stmt->labels.empty();
 	if ( isLabeled ) {
-		ast::Label breakLabel = LabelGenerator::newLabel( "blockBreak", stmt );
+		Label breakLabel = newLabel( "blockBreak", stmt );
 		enclosing_control_structures.emplace_back( stmt, breakLabel );
 		GuardAction([this](){ enclosing_control_structures.pop_back(); } );
@@ -510,5 +506,5 @@
 }
 
-void MultiLevelExitCore::postvisit( const ast::TryStmt * stmt ) {
+void MultiLevelExitCore::postvisit( const TryStmt * stmt ) {
 	bool isLabeled = !stmt->labels.empty();
 	if ( isLabeled ) {
@@ -520,14 +516,14 @@
 }
 
-void MultiLevelExitCore::previsit( const ast::FinallyStmt * ) {
-	GuardAction([this, old = std::move(enclosing_control_structures)](){
-		enclosing_control_structures = std::move(old);
-	});
-	enclosing_control_structures = std::vector<Entry>();
+void MultiLevelExitCore::previsit( const FinallyStmt * ) {
+	GuardAction([this, old = move(enclosing_control_structures)](){
+					enclosing_control_structures = move(old);
+				});
+	enclosing_control_structures = vector<Entry>();
 	GuardValue( inFinally ) = true;
 }
 
-const ast::Stmt * MultiLevelExitCore::mutateLoop(
-		const ast::Stmt * body, Entry & entry ) {
+const Stmt * MultiLevelExitCore::mutateLoop(
+	const Stmt * body, Entry & entry ) {
 	if ( entry.isBreakUsed() ) {
 		break_label = entry.useBreakExit();
@@ -535,5 +531,5 @@
 
 	if ( entry.isContUsed() ) {
-		ast::CompoundStmt * new_body = new ast::CompoundStmt( body->location );
+		CompoundStmt * new_body = new CompoundStmt( body->location );
 		new_body->kids.push_back( body );
 		new_body->kids.push_back(
@@ -549,6 +545,6 @@
 	// Remember is loop before going onto mutate the body.
 	// The labels will be folded in if they are used.
-	ast::Label breakLabel = LabelGenerator::newLabel( "loopBreak", loopStmt );
-	ast::Label contLabel = LabelGenerator::newLabel( "loopContinue", loopStmt );
+	Label breakLabel = newLabel( "loopBreak", loopStmt );
+	Label contLabel = newLabel( "loopContinue", loopStmt );
 	enclosing_control_structures.emplace_back( loopStmt, breakLabel, contLabel );
 	GuardAction( [this](){ enclosing_control_structures.pop_back(); } );
@@ -561,21 +557,21 @@
 	assert( entry.stmt == loopStmt );
 
-	// Now we check if the labels are used and add them if so.
-	return ast::mutate_field(
+	// Now check if the labels are used and add them if so.
+	return mutate_field(
 		loopStmt, &LoopNode::body, mutateLoop( loopStmt->body, entry ) );
 }
 
-std::list<ast::ptr<ast::Stmt>> MultiLevelExitCore::fixBlock(
-		const std::list<ast::ptr<ast::Stmt>> & kids, bool is_case_clause ) {
-	// Unfortunately we can't use the automatic error collection.
+list<ptr<Stmt>> MultiLevelExitCore::fixBlock(
+	const list<ptr<Stmt>> & kids, bool is_case_clause ) {
+	// Unfortunately cannot use automatic error collection.
 	SemanticErrorException errors;
 
-	std::list<ast::ptr<ast::Stmt>> ret;
+	list<ptr<Stmt>> ret;
 
 	// Manually visit each child.
-	for ( const ast::ptr<ast::Stmt> & kid : kids ) {
+	for ( const ptr<Stmt> & kid : kids ) {
 		if ( is_case_clause ) {
 			// Once a label is seen, it's no longer a valid for fallthrough.
-			for ( const ast::Label & l : kid->labels ) {
+			for ( const Label & l : kid->labels ) {
 				fallthrough_labels.erase( l );
 			}
@@ -591,5 +587,5 @@
 			ret.push_back(
 				labelledNullStmt( ret.back()->location, break_label ) );
-			break_label = ast::Label( CodeLocation(), "" );
+			break_label = Label( CodeLocation(), "" );
 		}
 	}
@@ -601,15 +597,12 @@
 }
 
-} // namespace
-
-const ast::CompoundStmt * multiLevelExitUpdate(
-    	const ast::CompoundStmt * stmt,
-		const LabelToStmt & labelTable ) {
+const CompoundStmt * multiLevelExitUpdate(
+	const CompoundStmt * stmt,
+	const LabelToStmt & labelTable ) {
 	// Must start in the body, so FunctionDecls can be a stopping point.
-	ast::Pass<MultiLevelExitCore> visitor( labelTable );
-	const ast::CompoundStmt * ret = stmt->accept( visitor );
+	Pass<MultiLevelExitCore> visitor( labelTable );
+	const CompoundStmt * ret = stmt->accept( visitor );
 	return ret;
 }
-
 } // namespace ControlStruct
 
Index: src/ControlStruct/MultiLevelExit.hpp
===================================================================
--- src/ControlStruct/MultiLevelExit.hpp	(revision dd3263c12bfb027e62dfafee97f41063e987396a)
+++ src/ControlStruct/MultiLevelExit.hpp	(revision 66daee4974e1e75ffed3982f0d1d4a29e4eb5941)
@@ -9,7 +9,7 @@
 // Author           : Andrew Beach
 // Created On       : Mon Nov  1 13:49:00 2021
-// Last Modified By : Andrew Beach
-// Last Modified On : Mon Nov  8 10:53:00 2021
-// Update Count     : 3
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Mon Jan 31 22:34:06 2022
+// Update Count     : 6
 //
 
@@ -19,17 +19,14 @@
 
 namespace ast {
-	class CompoundStmt;
-	class Label;
-	class Stmt;
+class CompoundStmt;
+class Label;
+class Stmt;
 }
 
 namespace ControlStruct {
-
 using LabelToStmt = std::map<ast::Label, const ast::Stmt *>;
 
-/// Mutate a function body to handle multi-level exits.
-const ast::CompoundStmt * multiLevelExitUpdate(
-	const ast::CompoundStmt *, const LabelToStmt & );
-
+// Mutate a function body to handle multi-level exits.
+const ast::CompoundStmt * multiLevelExitUpdate(	const ast::CompoundStmt *, const LabelToStmt & );
 }
 
