Index: src/CodeGen/CodeGenerator.cc
===================================================================
--- src/CodeGen/CodeGenerator.cc	(revision 4cc585bb6e75a6cc6a7522c493ccc0e85d5d1641)
+++ src/CodeGen/CodeGenerator.cc	(revision 59162729114763bb6807d7c311d21ccaa3f889fd)
@@ -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 15:34:00 2017
+// Update Count     : 488
 //
 #include "CodeGenerator.h"
@@ -79,23 +79,33 @@
 	}
 
-	CodeGenerator::LineMarker::LineMarker(
-			CodeLocation const & loc, bool toPrint) :
-		loc(loc), toPrint(toPrint)
-	{}
-
-	CodeGenerator::LineMarker CodeGenerator::lineDirective(
-			BaseSyntaxNode const * node) {
-		return LineMarker(node->location, lineMarks);
-	}
-
-	std::ostream & operator<<(std::ostream & out,
-			CodeGenerator::LineMarker const & marker) {
-		if (marker.toPrint && marker.loc.isSet()) {
-			return out << "\n# " << marker.loc.linenumber << " \""
-				<< marker.loc.filename << "\"\n";
-		} else if (marker.toPrint) {
-			return out << "\n/* Missing CodeLocation */\n";
-		} else {
-        	return out;
+	/* 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;
 		}
 	}
@@ -194,5 +204,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 +227,5 @@
 	void CodeGenerator::visit( EnumDecl * enumDecl ) {
 		extension( enumDecl );
-		output << lineDirective ( enumDecl );
+		updateLocation( enumDecl );
 		output << "enum ";
 		genAttributes( enumDecl->get_attributes() );
@@ -233,5 +243,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 +262,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 +763,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 +856,5 @@
 
 	void CodeGenerator::visit( IfStmt * ifStmt ) {
-		output << lineDirective( ifStmt );
+		updateLocation( ifStmt );
 		output << "if ( ";
 		ifStmt->get_condition()->accept( *this );
@@ -858,5 +870,5 @@
 
 	void CodeGenerator::visit( SwitchStmt * switchStmt ) {
-		output << lineDirective( switchStmt );
+		updateLocation( switchStmt );
 		output << "switch ( " ;
 		switchStmt->get_condition()->accept( *this );
@@ -871,6 +883,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 4cc585bb6e75a6cc6a7522c493ccc0e85d5d1641)
+++ src/CodeGen/CodeGenerator.h	(revision 59162729114763bb6807d7c311d21ccaa3f889fd)
@@ -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 15:40:00 2017
+// Update Count     : 56
 //
 
@@ -108,17 +108,10 @@
 		};
 
-		struct LineMarker {
-			CodeLocation const & loc;
-			bool toPrint;
-
-			LineMarker(CodeLocation const & loc, bool toPrint);
-		};
-
-		LineMarker lineDirective(BaseSyntaxNode const * node);
-
 		void asmName( DeclarationWithType *decl );
 
 		void extension( Expression *expr );
 		void extension( Declaration *decl );
+
+		void updateLocation( BaseSyntaxNode const * to );
 	  private:
 		Indenter indent;
@@ -129,4 +122,8 @@
 		bool genC = false;    // true if output has to be C code
 		bool lineMarks = false;
+
+		CodeLocation currentLocation;
+		void updateLocation( CodeLocation const & to );
+		void nextLine();
 
 		void handleStorageClass( DeclarationWithType *decl );
@@ -155,7 +152,4 @@
 	/// returns C-compatible name of declaration
 	std::string genName( DeclarationWithType * decl );
-
-	std::ostream & operator<<(std::ostream &,
-		CodeGenerator::LineMarker const &);
 } // namespace CodeGen
 
Index: src/CodeGen/Generate.cc
===================================================================
--- src/CodeGen/Generate.cc	(revision 4cc585bb6e75a6cc6a7522c493ccc0e85d5d1641)
+++ src/CodeGen/Generate.cc	(revision 59162729114763bb6807d7c311d21ccaa3f889fd)
@@ -10,6 +10,6 @@
 // Created On       : Mon May 18 07:44:20 2015
 // Last Modified By : Andrew Beach
-// Last Modified On : Wed May 19 13:05:00 2017
-// Update Count     : 6
+// Last Modified On : Fri Aug 18 15:39:00 2017
+// Update Count     : 7
 //
 #include "Generate.h"
@@ -33,5 +33,5 @@
 		for ( auto & dcl : translationUnit ) {
 			if ( LinkageSpec::isGeneratable( dcl->get_linkage() ) && (doIntrinsics || ! LinkageSpec::isBuiltin( dcl->get_linkage() ) ) ) {
-				os << cgv.lineDirective(dcl);
+				cgv.updateLocation( dcl );
 				dcl->accept(cgv);
 				if ( doSemicolon( dcl ) ) {
Index: src/ControlStruct/ForExprMutator.cc
===================================================================
--- src/ControlStruct/ForExprMutator.cc	(revision 4cc585bb6e75a6cc6a7522c493ccc0e85d5d1641)
+++ src/ControlStruct/ForExprMutator.cc	(revision 59162729114763bb6807d7c311d21ccaa3f889fd)
@@ -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
