Index: src/CodeGen/CodeGenerator.cc
===================================================================
--- src/CodeGen/CodeGenerator.cc	(revision 274ce8c98a0dc1608308c1bd35c41bcd52a1c812)
+++ src/CodeGen/CodeGenerator.cc	(revision 8bafacc74962838e850f1305c85abbf4ed4f878b)
@@ -10,6 +10,6 @@
 // Created On       : Mon May 18 07:44:20 2015
 // Last Modified By : Andrew Beach
-// Last Modified On : Tus Jul 25 15:29:00 2017
-// Update Count     : 486
+// Last Modified On : Fri Aug 18 14:20:00 2017
+// Update Count     : 487
 //
 #include "CodeGenerator.h"
@@ -101,4 +101,36 @@
 	}
 
+	/* Using updateLocation at the beginning of a node and nextLine
+	 * within a node should become the method of formating.
+	 */
+	void CodeGenerator::updateLocation( CodeLocation const & to ) {
+		if ( !lineMarks ) {
+			return;
+		} else if ( currentLocation.followedBy( to, 0 ) ) {
+			return;
+		} else if ( currentLocation.followedBy( to, 1 ) ) {
+			output << "\n" << indent;
+			currentLocation.linenumber += 1;
+		} else if ( currentLocation.followedBy( to, 2 ) ) {
+			output << "\n\n" << indent;
+			currentLocation.linenumber += 2;
+		} else {
+			output << "\n# " << to.linenumber << " \"" << to.filename
+			       << "\"\n" << indent;
+			currentLocation = to;
+		}
+		output << std::flush;
+	}
+
+	void CodeGenerator::updateLocation( BaseSyntaxNode const * to ) {
+		updateLocation( to->location );
+	}
+
+	void CodeGenerator::nextLine() {
+		if ( !lineMarks ) {
+			output << "\n" << indent << std::flush;
+		}
+	}
+
 	CodeGenerator::CodeGenerator( std::ostream & os, bool pretty, bool genC, bool lineMarks ) : indent( CodeGenerator::tabsize ), insideFunction( false ), output( os ), printLabels( *this ), pretty( pretty ), genC( genC ), lineMarks( lineMarks ) {}
 
@@ -194,5 +226,5 @@
 			++indent;
 			for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) {
-				output << lineDirective( *i ) << indent;
+				updateLocation( *i );
 				(*i)->accept( *this );
 				output << ";" << endl;
@@ -217,5 +249,5 @@
 	void CodeGenerator::visit( EnumDecl * enumDecl ) {
 		extension( enumDecl );
-		output << lineDirective ( enumDecl );
+		updateLocation( enumDecl );
 		output << "enum ";
 		genAttributes( enumDecl->get_attributes() );
@@ -233,5 +265,6 @@
 				ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i );
 				assert( obj );
-				output << lineDirective( obj ) << indent << mangleName( obj );
+				updateLocation( obj );
+				output << mangleName( obj );
 				if ( obj->get_init() ) {
 					output << " = ";
@@ -251,5 +284,5 @@
 	void CodeGenerator::visit( TypedefDecl * typeDecl ) {
 		assertf( ! genC, "Typedefs are removed and substituted in earlier passes." );
-		output << lineDirective( typeDecl );
+		updateLocation( typeDecl );
 		output << "typedef ";
 		output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty, genC ) << endl;
@@ -752,10 +785,11 @@
 	void CodeGenerator::visit( StmtExpr * stmtExpr ) {
 		std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids();
-		output << lineDirective( stmtExpr) << "({" << std::endl;
+		updateLocation( stmtExpr );
+		output << "({" << std::endl;
 		++indent;
 		unsigned int numStmts = stmts.size();
 		unsigned int i = 0;
 		for ( Statement * stmt : stmts ) {
-			output << lineDirective( stmt ) << indent;
+			updateLocation( stmt );
             output << printLabels( stmt->get_labels() );
 			if ( i+1 == numStmts ) {
@@ -844,5 +878,5 @@
 
 	void CodeGenerator::visit( IfStmt * ifStmt ) {
-		output << lineDirective( ifStmt );
+		updateLocation( ifStmt );
 		output << "if ( ";
 		ifStmt->get_condition()->accept( *this );
@@ -858,5 +892,5 @@
 
 	void CodeGenerator::visit( SwitchStmt * switchStmt ) {
-		output << lineDirective( switchStmt );
+		updateLocation( switchStmt );
 		output << "switch ( " ;
 		switchStmt->get_condition()->accept( *this );
@@ -871,6 +905,5 @@
 
 	void CodeGenerator::visit( CaseStmt * caseStmt ) {
-		output << lineDirective( caseStmt );
-		output << indent;
+		updateLocation( caseStmt );
 		if ( caseStmt->isDefault()) {
 			output << "default";
Index: src/CodeGen/CodeGenerator.h
===================================================================
--- src/CodeGen/CodeGenerator.h	(revision 274ce8c98a0dc1608308c1bd35c41bcd52a1c812)
+++ src/CodeGen/CodeGenerator.h	(revision 8bafacc74962838e850f1305c85abbf4ed4f878b)
@@ -10,6 +10,6 @@
 // Created On       : Mon May 18 07:44:20 2015
 // Last Modified By : Andrew Beach
-// Last Modified On : Tus Jul 25 25:30:00 2017
-// Update Count     : 54
+// Last Modified On : Fri Aug 18 13:52:00 2017
+// Update Count     : 55
 //
 
@@ -130,4 +130,9 @@
 		bool lineMarks = false;
 
+		CodeLocation currentLocation;
+		void updateLocation( CodeLocation const & to );
+		void updateLocation( BaseSyntaxNode const * to );
+		void nextLine();
+
 		void handleStorageClass( DeclarationWithType *decl );
 		void handleAggregate( AggregateDecl *aggDecl, const std::string & kind );
Index: src/ControlStruct/ForExprMutator.cc
===================================================================
--- src/ControlStruct/ForExprMutator.cc	(revision 274ce8c98a0dc1608308c1bd35c41bcd52a1c812)
+++ src/ControlStruct/ForExprMutator.cc	(revision 8bafacc74962838e850f1305c85abbf4ed4f878b)
@@ -9,7 +9,7 @@
 // Author           : Rodolfo G. Esteves
 // Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Thu Aug 17 15:32:46 2017
-// Update Count     : 11
+// Last Modified By : Andrew Beach
+// Last Modified On : Fri Aug 18 10:22:00 2017
+// Update Count     : 12
 //
 
@@ -21,35 +21,27 @@
 
 namespace ControlStruct {
-	Statement *ForExprMutator::postmutate( IfStmt *ifStmt ) {
-		std::list<Statement *> &init = ifStmt->get_initialization();
-		if ( init.size() == 0 ) {
-			return ifStmt;
-		} // if
+	Statement *hoist( Statement *originalStmt, std::list<Statement *> &init ) {
+		// If no hoisting is needed, skip:
+		if ( 0 == init.size() ) {
+			return originalStmt;
+		}
 
-		// create compound statement, move initializers outside, leave _for_ as-is
+		// Create compound statement, move initializers outside,
+		// the resut of the original stays as is.
 		CompoundStmt *block = new CompoundStmt( std::list< Label >() );
 		std::list<Statement *> &stmts = block->get_kids();
 		stmts.splice( stmts.end(), init );
 
-		// add for to the new block
-		stmts.push_back( ifStmt );
+		// Add for to the new block.
+		stmts.push_back( originalStmt );
 		return block;
 	}
 
+	Statement *ForExprMutator::postmutate( IfStmt *ifStmt ) {
+		return hoist( ifStmt, ifStmt->initialization );
+	}
 	Statement *ForExprMutator::postmutate( ForStmt *forStmt ) {
 		// hoist any initializer declarations to make them C89 (rather than C99)
-		std::list<Statement *> &init = forStmt->get_initialization();
-		if ( init.size() == 0 ) {
-			return forStmt;
-		} // if
-
-		// create compound statement, move initializers outside, leave _for_ as-is
-		CompoundStmt *block = new CompoundStmt( std::list< Label >() );
-		std::list<Statement *> &stmts = block->get_kids();
-		stmts.splice( stmts.end(), init );
-
-		// add for to the new block
-		stmts.push_back( forStmt );
-		return block;
+		return hoist( forStmt, forStmt->initialization );
 	}
 } // namespace ControlStruct
