Index: src/InitTweak/FixInit.cc
===================================================================
--- src/InitTweak/FixInit.cc	(revision d32c4e295f91b7b5d9ffc75dd2c9e23529a5c41d)
+++ src/InitTweak/FixInit.cc	(revision 3f869f0ffd7b467d53412bd6d1ddf2097487e768)
@@ -9,7 +9,7 @@
 // Author           : Rob Schluntz
 // Created On       : Wed Jan 13 16:29:30 2016
-// Last Modified By : Rob Schluntz
-// Last Modified On : Fri May 13 11:44:26 2016
-// Update Count     : 30
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Wed Jul  6 17:34:46 2016
+// Update Count     : 33
 //
 
@@ -47,7 +47,6 @@
 		class InsertImplicitCalls : public GenPoly::PolyMutator {
 		public:
-			/// wrap function application expressions as ImplicitCopyCtorExpr nodes
-			/// so that it is easy to identify which function calls need their parameters
-			/// to be copy constructed
+			/// wrap function application expressions as ImplicitCopyCtorExpr nodes so that it is easy to identify which
+			/// function calls need their parameters to be copy constructed
 			static void insert( std::list< Declaration * > & translationUnit );
 
@@ -57,7 +56,7 @@
 		class ResolveCopyCtors : public SymTab::Indexer {
 		public:
-			/// generate temporary ObjectDecls for each argument and return value of each
-			/// ImplicitCopyCtorExpr, generate/resolve copy construction expressions for each,
-			/// and generate/resolve destructors for both arguments and return value temporaries
+			/// generate temporary ObjectDecls for each argument and return value of each ImplicitCopyCtorExpr,
+			/// generate/resolve copy construction expressions for each, and generate/resolve destructors for both
+			/// arguments and return value temporaries
 			static void resolveImplicitCalls( std::list< Declaration * > & translationUnit );
 
@@ -93,5 +92,5 @@
 			for ( ObjectDecl * obj : set.objs ) {
 				out << obj->get_name() << ", " ;
-			}
+			} // for
 			out << " }";
 			return out;
@@ -108,10 +107,8 @@
 
 			// xxx - This needs to be done better.
-			// allow some generalization among different kinds of nodes with
-			// with similar parentage (e.g. all expressions, all statements, etc.)
-			// important to have this to provide a single entry point so that as
-			// new subclasses are added, there is only one place that the code has
-			// to be updated, rather than ensure that every specialized class knows
-			// about every new kind of statement that might be added.
+			// allow some generalization among different kinds of nodes with with similar parentage (e.g. all
+			// expressions, all statements, etc.)  important to have this to provide a single entry point so that as new
+			// subclasses are added, there is only one place that the code has to be updated, rather than ensure that
+			// every specialized class knows about every new kind of statement that might be added.
 			virtual void visit( CompoundStmt *stmt ) { handleStmt( stmt ); return Parent::visit( stmt ); }
 			virtual void visit( ExprStmt *stmt ) { handleStmt( stmt ); return Parent::visit( stmt ); }
@@ -136,6 +133,6 @@
 		class InsertDtors : public ObjDeclCollector {
 		public:
-			/// insert destructor calls at the appropriate places.
-			/// must happen before CtorInit nodes are removed (currently by FixInit)
+			/// insert destructor calls at the appropriate places.  must happen before CtorInit nodes are removed
+			/// (currently by FixInit)
 			static void insert( std::list< Declaration * > & translationUnit );
 
@@ -168,6 +165,6 @@
 		class FixCopyCtors : public GenPoly::PolyMutator {
 		  public:
-			/// expand ImplicitCopyCtorExpr nodes into the temporary declarations, copy constructors,
-			/// call expression, and destructors
+			/// expand ImplicitCopyCtorExpr nodes into the temporary declarations, copy constructors, call expression,
+			/// and destructors
 			static void fixCopyCtors( std::list< Declaration * > &translationUnit );
 
@@ -235,11 +232,11 @@
 							// assignment operator
 							return appExpr;
-						}
+						} // if
 					} else if ( funcDecl->get_name() == "^?{}" ) {
 						// correctness: never copy construct arguments to a destructor
 						return appExpr;
-					}
-				}
-			}
+					} // if
+				} // if
+			} // if
 			CP_CTOR_PRINT( std::cerr << "InsertImplicitCalls: adding a wrapper " << appExpr << std::endl; )
 
@@ -270,11 +267,11 @@
 
 			// resolve copy constructor
-			// should only be one alternative for copy ctor and dtor expressions, since
-			// all arguments are fixed (VariableExpr and already resolved expression)
+			// should only be one alternative for copy ctor and dtor expressions, since all arguments are fixed
+			// (VariableExpr and already resolved expression)
 			CP_CTOR_PRINT( std::cerr << "ResolvingCtorDtor " << untyped << std::endl; )
 			ApplicationExpr * resolved = dynamic_cast< ApplicationExpr * >( ResolvExpr::findVoidExpression( untyped, *this ) );
 			if ( resolved->get_env() ) {
 				env->add( *resolved->get_env() );
-			}
+			} // if
 
 			assert( resolved );
@@ -319,14 +316,13 @@
 					impCpCtorExpr->get_tempDecls().push_back( tmp );
 					impCpCtorExpr->get_dtors().push_front( makeCtorDtor( "^?{}", tmp ) );
-				}
-			}
-
-			// each return value from the call needs to be connected with an ObjectDecl
-			// at the call site, which is initialized with the return value and is destructed
-			// later
+				} // if
+			} // for
+
+			// each return value from the call needs to be connected with an ObjectDecl at the call site, which is
+			// initialized with the return value and is destructed later
 			// xxx - handle multiple return values
 			ApplicationExpr * callExpr = impCpCtorExpr->get_callExpr();
-			// xxx - is this right? callExpr may not have the right environment, because it was attached
-			// at a higher level. Trying to pass that environment along.
+			// xxx - is this right? callExpr may not have the right environment, because it was attached at a higher
+			// level. Trying to pass that environment along.
 			callExpr->set_env( impCpCtorExpr->get_env()->clone() );
 			for ( Type * result : appExpr->get_results() ) {
@@ -338,5 +334,5 @@
 				CP_CTOR_PRINT( std::cerr << "makeCtorDtor for a return" << std::endl; )
 				impCpCtorExpr->get_dtors().push_front( makeCtorDtor( "^?{}", ret ) );
-			}
+			} // for
 			CP_CTOR_PRINT( std::cerr << "after Resolving: " << impCpCtorExpr << std::endl; )
 		}
@@ -356,13 +352,13 @@
 			for ( ObjectDecl * obj : tempDecls ) {
 				stmtsToAdd.push_back( new DeclStmt( noLabels, obj ) );
-			}
+			} // for
 			for ( ObjectDecl * obj : returnDecls ) {
 				stmtsToAdd.push_back( new DeclStmt( noLabels, obj ) );
-			}
+			} // for
 
 			// add destructors after current statement
 			for ( Expression * dtor : dtors ) {
 				stmtsToAddAfter.push_back( new ExprStmt( noLabels, dtor ) );
-			}
+			} // for
 
 			// xxx - update to work with multiple return values
@@ -390,10 +386,9 @@
 				Expression * retExpr = new CommaExpr( assign, new VariableExpr( returnDecl ) );
 				if ( callExpr->get_results().front()->get_isLvalue() ) {
-					// lvalue returning functions are funny. Lvalue.cc inserts a *? in front of any
-					// lvalue returning non-intrinsic function. Add an AddressExpr to the call to negate
-					// the derefence and change the type of the return temporary from T to T* to properly
-					// capture the return value. Then dereference the result of the comma expression, since
-					// the lvalue returning call was originally wrapped with an AddressExpr.
-					// Effectively, this turns
+					// lvalue returning functions are funny. Lvalue.cc inserts a *? in front of any lvalue returning
+					// non-intrinsic function. Add an AddressExpr to the call to negate the derefence and change the
+					// type of the return temporary from T to T* to properly capture the return value. Then dereference
+					// the result of the comma expression, since the lvalue returning call was originally wrapped with
+					// an AddressExpr.  Effectively, this turns
 					//   lvalue T f();
 					//   &*f()
@@ -410,5 +405,5 @@
 					deref->add_result( resultType );
 					retExpr = deref;
-				}
+				} // if
 				// xxx - might need to set env on retExpr...
 				// retExpr->set_env( env->clone() );
@@ -416,10 +411,10 @@
 			} else {
 				return callExpr;
-			}
+			} // if
 		}
 
 		DeclarationWithType *FixInit::mutate( ObjectDecl *objDecl ) {
-			// first recursively handle pieces of ObjectDecl so that they aren't missed by other visitors
-			// when the init is removed from the ObjectDecl
+			// first recursively handle pieces of ObjectDecl so that they aren't missed by other visitors when the init
+			// is removed from the ObjectDecl
 			objDecl = dynamic_cast< ObjectDecl * >( Mutator::mutate( objDecl ) );
 
@@ -474,5 +469,5 @@
 					} else {
 						stmtsToAddAfter.push_back( ctor );
-					}
+					} // if
 					objDecl->set_init( NULL );
 					ctorInit->set_ctor( NULL );
@@ -483,7 +478,7 @@
 					// no constructor and no initializer, which is okay
 					objDecl->set_init( NULL );
-				}
+				} // if
 				delete ctorInit;
-			}
+			} // if
 			return objDecl;
 		}
@@ -499,5 +494,5 @@
 			if ( ObjectDecl * objDecl = dynamic_cast< ObjectDecl * > ( stmt->get_decl() ) ) {
 				curVars.insert( objDecl );
-			}
+			} // if
 			Parent::visit( stmt );
 		}
@@ -507,5 +502,5 @@
 			for ( Label l : stmt->get_labels() ) {
 				vars[l] = curVars;
-			}
+			} // for
 		}
 
@@ -513,15 +508,13 @@
 		void insertDtors( Iterator begin, Iterator end, OutputIterator out ) {
 			for ( Iterator it = begin ; it != end ; ++it ) {
-				// extract destructor statement from the object decl and
-				// insert it into the output. Note that this is only called
-				// on lists of non-static objects with implicit non-intrinsic
-				// dtors, so if the user manually calls an intrinsic dtor
-				// then the call must (and will) still be generated since
-				// the argument may contain side effects.
+				// extract destructor statement from the object decl and insert it into the output. Note that this is
+				// only called on lists of non-static objects with implicit non-intrinsic dtors, so if the user manually
+				// calls an intrinsic dtor then the call must (and will) still be generated since the argument may
+				// contain side effects.
 				ObjectDecl * objDecl = *it;
 				ConstructorInit * ctorInit = dynamic_cast< ConstructorInit * >( objDecl->get_init() );
 				assert( ctorInit && ctorInit->get_dtor() );
 				*out++ = ctorInit->get_dtor()->clone();
-			}
+			} // for
 		}
 
@@ -537,15 +530,14 @@
 						// non-intrinsic dtors must be called
 						reverseDeclOrder.front().push_front( objDecl );
-					}
-				}
-			}
+					} // if
+				} // if
+			} // if
 			Parent::visit( objDecl );
 		}
 
 		void InsertDtors::visit( CompoundStmt * compoundStmt ) {
-			// visit statements - this will also populate reverseDeclOrder list.
-			// don't want to dump all destructors when block is left,
-			// just the destructors associated with variables defined in this block,
-			// so push a new list to the top of the stack so that we can differentiate scopes
+			// visit statements - this will also populate reverseDeclOrder list.  don't want to dump all destructors
+			// when block is left, just the destructors associated with variables defined in this block, so push a new
+			// list to the top of the stack so that we can differentiate scopes
 			reverseDeclOrder.push_front( OrderedDecls() );
 			Parent::visit( compoundStmt );
@@ -561,14 +553,11 @@
 			for ( OrderedDecls & od : reverseDeclOrder ) {
 				insertDtors( od.begin(), od.end(), back_inserter( stmtsToAdd ) );
-			}
-		}
-
-		// Handle break/continue/goto in the same manner as C++.
-		// Basic idea: any objects that are in scope at the BranchStmt
-		// but not at the labelled (target) statement must be destructed.
-		// If there are any objects in scope at the target location but
-		// not at the BranchStmt then those objects would be uninitialized
-		// so notify the user of the error.
-		// See C++ Reference 6.6 Jump Statements for details.
+			} // for
+		}
+
+		// Handle break/continue/goto in the same manner as C++.  Basic idea: any objects that are in scope at the
+		// BranchStmt but not at the labelled (target) statement must be destructed.  If there are any objects in scope
+		// at the target location but not at the BranchStmt then those objects would be uninitialized so notify the user
+		// of the error.  See C++ Reference 6.6 Jump Statements for details.
 		void InsertDtors::handleGoto( BranchStmt * stmt ) {
 			assert( stmt->get_target() != "" && "BranchStmt missing a label" );
@@ -591,5 +580,5 @@
 			if ( ! diff.empty() ) {
 				throw SemanticError( std::string("jump to label '") + stmt->get_target().get_name() + "' crosses initialization of " + (*diff.begin())->get_name() + " ", stmt );
-			}
+			} // if
 			// S_G-S_L results in set of objects that must be destructed
 			diff.clear();
@@ -604,22 +593,21 @@
 					// add elements from reverseDeclOrder into ordered if they occur in diff - it is key that this happens in reverse declaration order.
 					copy_if( rdo.begin(), rdo.end(), back_inserter( ordered ), [&]( ObjectDecl * objDecl ) { return diff.count( objDecl ); } );
-				}
+				} // for
 				insertDtors( ordered.begin(), ordered.end(), back_inserter( stmtsToAdd ) );
-			}
+			} // if
 		}
 
 		void InsertDtors::visit( BranchStmt * stmt ) {
 			switch( stmt->get_type() ) {
-				case BranchStmt::Continue:
-				case BranchStmt::Break:
-				// could optimize the break/continue case, because the S_L-S_G check
-				// is unnecessary (this set should always be empty), but it serves
-				// as a small sanity check.
-				case BranchStmt::Goto:
-					handleGoto( stmt );
-					break;
-				default:
-					assert( false );
-			}
+			  case BranchStmt::Continue:
+			  case BranchStmt::Break:
+				// could optimize the break/continue case, because the S_L-S_G check is unnecessary (this set should
+				// always be empty), but it serves as a small sanity check.
+			  case BranchStmt::Goto:
+				handleGoto( stmt );
+				break;
+			  default:
+				assert( false );
+			} // switch
 		}
 	} // namespace
