Index: src/ControlStruct/LabelFixer.cc
===================================================================
--- src/ControlStruct/LabelFixer.cc	(revision de62360d1d2709386152807b3d18e159e241ab1f)
+++ src/ControlStruct/LabelFixer.cc	(revision 2871210d7be1910f7296a17164d525f66ef82648)
@@ -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 : Tue Jun 23 12:42:23 2015
-// Update Count     : 96
+// Last Modified By : Rob Schluntz
+// Last Modified On : Wed Jun 24 16:24:34 2015
+// Update Count     : 141
 //
 
@@ -19,4 +19,5 @@
 #include "LabelFixer.h"
 #include "MLEMutator.h"
+#include "SynTree/Expression.h"
 #include "SynTree/Statement.h"
 #include "SynTree/Declaration.h"
@@ -26,8 +27,18 @@
 
 namespace ControlStruct {
-	LabelFixer::Entry::Entry( Statement *to, BranchStmt *from ) : definition ( to ) {
-		if ( from != 0 )
-			usage.push_back( from );
-	}
+	LabelFixer::Entry::Entry( Statement *to, Statement *from ) : definition ( to ) {
+		if ( from != 0 ) {
+			UsageLoc loc; loc.stmt = from;
+			usage.push_back( loc );
+		}
+	}
+
+	LabelFixer::Entry::Entry( Statement *to, Expression *from ) : definition ( to ) {
+		if ( from != 0 ) {
+			UsageLoc loc; loc.expr = from;
+			usage.push_back( loc );
+		}
+	}
+
 
 	bool LabelFixer::Entry::insideLoop() {
@@ -36,4 +47,12 @@
 	}
 
+	void LabelFixer::Entry::UsageLoc::accept( Visitor & visitor ) {
+		if ( dynamic_cast< Statement * >( stmt ) ) {
+			stmt->accept( visitor );
+		} else {
+			expr->accept( visitor );
+		}
+	}
+
 	LabelFixer::LabelFixer( LabelGenerator *gen ) : generator ( gen ) {
 		if ( generator == 0 )
@@ -50,4 +69,5 @@
 	// prune to at most one label definition for each statement
 	void LabelFixer::visit( Statement *stmt ) {
+		currentStatement = stmt;
 		std::list< Label > &labels = stmt->get_labels();
 
@@ -69,4 +89,18 @@
 		}
 	}
+
+	void LabelFixer::visit( UntypedExpr *untyped ) {
+		if ( NameExpr * func = dynamic_cast< NameExpr * >( untyped->get_function() ) ) {
+			if ( func->get_name() == "&&" ) {
+				NameExpr * arg = dynamic_cast< NameExpr * >( untyped->get_args().front() );
+				Label target = arg->get_name();
+				assert( target != "" );
+				setLabelsUsg( target, untyped );
+			} else {
+				Visitor::visit( untyped );
+			}
+		}
+	}
+
 
 	// sets the definition of the labelTable entry to be the provided 
@@ -89,5 +123,5 @@
 				// used previously, but undefined until now -> link with this entry
 				Entry * oldEntry = labelTable[ *i ];
-				e->add_uses( oldEntry->get_uses() );
+				e->add_uses( *oldEntry );
 				labelTable[ *i ] = e;
 			} // if
@@ -100,5 +134,6 @@
 
 	// Remember all uses of a label.
-	void LabelFixer::setLabelsUsg( Label orgValue, BranchStmt *use ) {
+	template< typename UsageNode >
+	void LabelFixer::setLabelsUsg( Label orgValue, UsageNode *use ) {
 		assert( use != 0 );
 
@@ -111,4 +146,46 @@
 	}
 
+	class LabelGetter : public Visitor {
+		public:
+		LabelGetter( Label &label ) : label( label ) {}
+
+		virtual void visit( BranchStmt * branchStmt ) {
+			label = branchStmt->get_target();
+		}
+
+		virtual void visit( UntypedExpr * untyped ) {
+			NameExpr * name = dynamic_cast< NameExpr * >( untyped->get_function() );
+			assert( name );
+			assert( name->get_name() == "&&" );
+			NameExpr * arg = dynamic_cast< NameExpr * >( untyped->get_args().front() );
+			assert( arg );
+			label = arg->get_name();
+		}		
+
+		private:
+			Label &label;
+	};
+
+	class LabelSetter : public Visitor {
+		public:
+		LabelSetter( Label label ) : label( label ) {}
+
+		virtual void visit( BranchStmt * branchStmt ) {
+			branchStmt->set_target( label );
+		}
+
+		virtual void visit( UntypedExpr * untyped ) {
+			NameExpr * name = dynamic_cast< NameExpr * >( untyped->get_function() );
+			assert( name );
+			assert( name->get_name() == "&&" );
+			NameExpr * arg = dynamic_cast< NameExpr * >( untyped->get_args().front() );
+			assert( arg );
+			arg->set_name( label );
+		}
+
+	private:
+		Label label;
+	};
+
 	// Ultimately builds a table that maps a label to its defining statement.
 	// In the process, 
@@ -121,7 +198,7 @@
 
 			if ( def_us.find ( e->get_definition() ) == def_us.end() ) {
-				def_us[ e->get_definition() ] = e;				
+				def_us[ e->get_definition() ] = e;
 			} else if ( e->used() ) {
-				def_us[ e->get_definition() ]->add_uses( e->get_uses() );
+				def_us[ e->get_definition() ]->add_uses( *e );
 			}
 		}
@@ -131,9 +208,12 @@
 			Statement *to = (*i).first;
 			Entry * entry = (*i).second;
-			std::list< BranchStmt *> &from = entry->get_uses();
+			std::list< Entry::UsageLoc > &from = entry->get_uses();
 
 			// no label definition found
 			if ( to == 0 ) {
-				Label undef = from.back()->get_target();
+				Label undef;
+				LabelGetter getLabel( undef );
+				from.back().accept( getLabel );
+				// Label undef = getLabel( from.back()->get_target() );
 				throw SemanticError ( "'" + undef + "' label not defined");
 			} // if
@@ -147,8 +227,12 @@
 
 			// redirect each of the source branch statements to the new target label
-			for ( std::list< BranchStmt *>::iterator j = from.begin(); j != from.end(); ++j ) {
-				BranchStmt *jump = *j;
-				assert( jump != 0 );
-				jump->set_target( finalLabel );
+			for ( std::list< Entry::UsageLoc >::iterator j = from.begin(); j != from.end(); ++j ) {
+				LabelSetter setLabel( finalLabel );
+				(*j).accept( setLabel );
+				// setLabel( *j, finalLabel );
+
+				// BranchStmt *jump = *j;
+				// assert( jump != 0 );
+				// jump->set_target( finalLabel );
 			} // for
 		} // for
