Index: src/SynTree/AddStmtVisitor.cc
===================================================================
--- src/SynTree/AddStmtVisitor.cc	(revision 4d3ca1d868f76bdc3c138e232ca019fd019466eb)
+++ src/SynTree/AddStmtVisitor.cc	(revision 4d3ca1d868f76bdc3c138e232ca019fd019466eb)
@@ -0,0 +1,96 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// AddStmtVisitor.cc --
+//
+// Author           : Rob Schluntz
+// Created On       : Wed Jun 22 12:11:17 2016
+// Last Modified By : Rob Schluntz
+// Last Modified On : Wed Jun 22 12:16:29 2016
+// Update Count     : 11
+//
+
+#include "AddStmtVisitor.h"
+#include "Statement.h"
+#include "Declaration.h"
+#include "Expression.h"
+#include "Common/utility.h"
+
+void AddStmtVisitor::visitStatementList( std::list< Statement* > &statements ) {
+	for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
+		if ( ! stmtsToAddAfter.empty() ) {
+			statements.splice( i, stmtsToAddAfter );
+		} // if
+		(*i)->accept( *this );
+		if ( ! stmtsToAdd.empty() ) {
+			statements.splice( i, stmtsToAdd );
+		} // if
+	} // for
+	if ( ! stmtsToAddAfter.empty() ) {
+		statements.splice( statements.end(), stmtsToAddAfter );
+	} // if
+}
+
+Statement * AddStmtVisitor::visitStatement( Statement *stmt ) {
+	maybeAccept( stmt, *this );
+	if ( ! stmtsToAdd.empty() || ! stmtsToAddAfter.empty() ) {
+		CompoundStmt *compound = new CompoundStmt( noLabels );
+		compound->get_kids().splice( compound->get_kids().end(), stmtsToAdd );
+		compound->get_kids().push_back( stmt );
+		compound->get_kids().splice( compound->get_kids().end(), stmtsToAddAfter );
+		return compound;
+	} else {
+		return stmt;
+	}
+}
+
+void AddStmtVisitor::visit(CompoundStmt *compoundStmt) {
+	visitStatementList( compoundStmt->get_kids() );
+}
+
+void AddStmtVisitor::visit(IfStmt *ifStmt) {
+	ifStmt->set_thenPart( visitStatement( ifStmt->get_thenPart() ) );
+	ifStmt->set_elsePart( visitStatement( ifStmt->get_elsePart() ) );
+	maybeAccept( ifStmt->get_condition(), *this );
+}
+
+void AddStmtVisitor::visit(WhileStmt *whileStmt) {
+	whileStmt->set_body( visitStatement( whileStmt->get_body() ) );
+	maybeAccept( whileStmt->get_condition(), *this );
+}
+
+void AddStmtVisitor::visit(ForStmt *forStmt) {
+	forStmt->set_body( visitStatement( forStmt->get_body() ) );
+	acceptAll( forStmt->get_initialization(), *this );
+	maybeAccept( forStmt->get_condition(), *this );
+	maybeAccept( forStmt->get_increment(), *this );
+}
+
+void AddStmtVisitor::visit(SwitchStmt *switchStmt) {
+	visitStatementList( switchStmt->get_branches() );
+	maybeAccept( switchStmt->get_condition(), *this );
+}
+
+void AddStmtVisitor::visit(ChooseStmt *switchStmt) {
+	visitStatementList( switchStmt->get_branches() );
+	maybeAccept( switchStmt->get_condition(), *this );
+}
+
+void AddStmtVisitor::visit(CaseStmt *caseStmt) {
+	visitStatementList( caseStmt->get_statements() );
+	maybeAccept( caseStmt->get_condition(), *this );
+}
+
+void AddStmtVisitor::visit(CatchStmt *catchStmt) {
+	catchStmt->set_body( visitStatement( catchStmt->get_body() ) );
+	maybeAccept( catchStmt->get_decl(), *this );
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/SynTree/AddStmtVisitor.h
===================================================================
--- src/SynTree/AddStmtVisitor.h	(revision 4d3ca1d868f76bdc3c138e232ca019fd019466eb)
+++ src/SynTree/AddStmtVisitor.h	(revision 4d3ca1d868f76bdc3c138e232ca019fd019466eb)
@@ -0,0 +1,45 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// AddStmtVisitor.h --
+//
+// Author           : Rob Schluntz
+// Created On       : Wed Jun 22 12:05:48 2016
+// Last Modified By : Rob Schluntz
+// Last Modified On : Wed Jun 22 12:12:05 2016
+// Update Count     : 7
+//
+
+#ifndef ADD_STATEMENT_VISITOR_H
+#define ADD_STATEMENT_VISITOR_H
+
+#include <list>
+
+#include "SynTree/SynTree.h"
+#include "SynTree/Visitor.h"
+
+class AddStmtVisitor : public Visitor {
+  public:
+	typedef Visitor Parent;
+
+	using Parent::visit;
+	virtual void visit(CompoundStmt *compoundStmt);
+	virtual void visit(IfStmt *ifStmt);
+	virtual void visit(WhileStmt *whileStmt);
+	virtual void visit(ForStmt *forStmt);
+	virtual void visit(SwitchStmt *switchStmt);
+	virtual void visit(ChooseStmt *chooseStmt);
+	virtual void visit(CaseStmt *caseStmt);
+	virtual void visit(CatchStmt *catchStmt);
+
+  protected:
+	void visitStatementList( std::list< Statement * > & );
+	Statement * visitStatement( Statement * );
+	std::list< Statement* > stmtsToAdd;
+	std::list< Statement* > stmtsToAddAfter;
+};
+
+#endif // ADD_STATEMENT_VISITOR_H
Index: src/SynTree/Label.h
===================================================================
--- src/SynTree/Label.h	(revision 4d3ca1d868f76bdc3c138e232ca019fd019466eb)
+++ src/SynTree/Label.h	(revision 4d3ca1d868f76bdc3c138e232ca019fd019466eb)
@@ -0,0 +1,64 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// Label.h --
+//
+// Author           : Rob Schluntz
+// Created On       : Wed Jun 8 12:53:12 2016
+// Last Modified By : Rob Schluntz
+// Last Modified On : Wed Jun 8 12:53:28 2016
+// Update Count     : 1
+//
+
+#ifndef LABEL_H
+#define LABEL_H
+
+#include <string>
+#include <list>
+#include <iostream>
+#include "SynTree.h"
+
+// Label needs to know
+// * how deeply nested it is (scopeLevel)
+// * relative position in a scope compared with other labels (index?)
+// * either the original label it was generated from or the labels it generates (for labelled break/continue)
+
+class Label {
+  public:
+	Label( const std::string & name = "", Statement * labelled = 0 ) : name( name ), labelled( labelled ) {}
+	Label( const char * name, Statement * labelled = 0 ) : name( name ), labelled( labelled ) {}
+
+	const std::string & get_name() const { return name; }
+	void set_name( const std::string & newValue ) { name = newValue; }
+
+	Statement * get_statement() const { return labelled; }
+	void set_statement( Statement * newValue ) { labelled = newValue; }
+	std::list< Attribute * >& get_attributes() { return attributes; }
+
+	operator std::string() { return name; }
+	bool empty() { return name.empty(); }
+  private:
+	std::string name;
+	Statement * labelled;
+	std::list< Attribute * > attributes;
+};
+
+inline bool operator==( Label l1, Label l2 ) { return l1.get_name() == l2.get_name(); }
+inline bool operator!=( Label l1, Label l2 ) { return ! (l1 == l2); }
+inline bool operator<( Label l1, Label l2 ) { return l1.get_name() < l2.get_name(); }
+// inline Label operator+( Label l1, Label l2 ) { return l1.get_name() + l2.get_name(); }
+// inline Label operator+( Label l1, const char * str ) { return l1.get_name() + Label( str ); }
+inline std::ostream & operator<<( std::ostream & out, const Label & l ) { return out << l.get_name(); }
+
+static const std::list< Label > noLabels;
+
+#endif // LABEL_H
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/SynTree/Statement.cc
===================================================================
--- src/SynTree/Statement.cc	(revision 74d1804d72905cf06786275cfde2ae94369611fb)
+++ src/SynTree/Statement.cc	(revision 4d3ca1d868f76bdc3c138e232ca019fd019466eb)
@@ -87,5 +87,5 @@
 	Statement( labels ), originalTarget( _target ), target( _target ), computedTarget( NULL ), type( _type ) {
 	//actually this is a syntactic error signaled by the parser
-	if ( type == BranchStmt::Goto && target.size() == 0 )
+	if ( type == BranchStmt::Goto && target.empty() )
 		throw SemanticError("goto without target");
 }
Index: src/SynTree/Statement.h
===================================================================
--- src/SynTree/Statement.h	(revision 74d1804d72905cf06786275cfde2ae94369611fb)
+++ src/SynTree/Statement.h	(revision 4d3ca1d868f76bdc3c138e232ca019fd019466eb)
@@ -22,4 +22,5 @@
 #include "Common/SemanticError.h"
 #include "Type.h"
+#include "Label.h"
 
 class Statement {
Index: src/SynTree/SynTree.h
===================================================================
--- src/SynTree/SynTree.h	(revision 74d1804d72905cf06786275cfde2ae94369611fb)
+++ src/SynTree/SynTree.h	(revision 4d3ca1d868f76bdc3c138e232ca019fd019466eb)
@@ -113,5 +113,6 @@
 class Constant;
 
-typedef std::string Label;
+// typedef std::string Label;
+class Label;
 typedef unsigned int UniqueId;
 
Index: src/SynTree/Visitor.cc
===================================================================
--- src/SynTree/Visitor.cc	(revision 74d1804d72905cf06786275cfde2ae94369611fb)
+++ src/SynTree/Visitor.cc	(revision 4d3ca1d868f76bdc3c138e232ca019fd019466eb)
@@ -39,5 +39,5 @@
 }
 
-void Visitor::visit( AggregateDecl *aggregateDecl ) {
+void Visitor::handleAggregateDecl( AggregateDecl *aggregateDecl ) {
 	acceptAll( aggregateDecl->get_parameters(), *this );
 	acceptAll( aggregateDecl->get_members(), *this );
@@ -45,20 +45,20 @@
 
 void Visitor::visit( StructDecl *aggregateDecl ) {
-	visit( static_cast< AggregateDecl* >( aggregateDecl ) );
+	handleAggregateDecl( static_cast< AggregateDecl* >( aggregateDecl ) );
 }
 
 void Visitor::visit( UnionDecl *aggregateDecl ) {
-	visit( static_cast< AggregateDecl* >( aggregateDecl ) );
+	handleAggregateDecl( static_cast< AggregateDecl* >( aggregateDecl ) );
 }
 
 void Visitor::visit( EnumDecl *aggregateDecl ) {
-	visit( static_cast< AggregateDecl* >( aggregateDecl ) );
+	handleAggregateDecl( static_cast< AggregateDecl* >( aggregateDecl ) );
 }
 
 void Visitor::visit( TraitDecl *aggregateDecl ) {
-	visit( static_cast< AggregateDecl* >( aggregateDecl ) );
-}
-
-void Visitor::visit( NamedTypeDecl *typeDecl ) {
+	handleAggregateDecl( static_cast< AggregateDecl* >( aggregateDecl ) );
+}
+
+void Visitor::handleNamedTypeDecl( NamedTypeDecl *typeDecl ) {
 	acceptAll( typeDecl->get_parameters(), *this );
 	acceptAll( typeDecl->get_assertions(), *this );
@@ -67,9 +67,9 @@
 
 void Visitor::visit( TypeDecl *typeDecl ) {
-	visit( static_cast< NamedTypeDecl* >( typeDecl ) );
+	handleNamedTypeDecl( static_cast< NamedTypeDecl* >( typeDecl ) );
 }
 
 void Visitor::visit( TypedefDecl *typeDecl ) {
-	visit( static_cast< NamedTypeDecl* >( typeDecl ) );
+	handleNamedTypeDecl( static_cast< NamedTypeDecl* >( typeDecl ) );
 }
 
@@ -330,5 +330,5 @@
 }
 
-void Visitor::visit( ReferenceToType *aggregateUseType ) {
+void Visitor::handleReferenceToType( ReferenceToType *aggregateUseType ) {
 	acceptAll( aggregateUseType->get_forall(), *this );
 	acceptAll( aggregateUseType->get_parameters(), *this );
@@ -336,22 +336,22 @@
 
 void Visitor::visit( StructInstType *aggregateUseType ) {
-	visit( static_cast< ReferenceToType * >( aggregateUseType ) );
+	handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) );
 }
 
 void Visitor::visit( UnionInstType *aggregateUseType ) {
-	visit( static_cast< ReferenceToType * >( aggregateUseType ) );
+	handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) );
 }
 
 void Visitor::visit( EnumInstType *aggregateUseType ) {
-	visit( static_cast< ReferenceToType * >( aggregateUseType ) );
+	handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) );
 }
 
 void Visitor::visit( TraitInstType *aggregateUseType ) {
-	visit( static_cast< ReferenceToType * >( aggregateUseType ) );
+	handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) );
 	acceptAll( aggregateUseType->get_members(), *this );
 }
 
 void Visitor::visit( TypeInstType *aggregateUseType ) {
-	visit( static_cast< ReferenceToType * >( aggregateUseType ) );
+	handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) );
 }
 
Index: src/SynTree/Visitor.h
===================================================================
--- src/SynTree/Visitor.h	(revision 74d1804d72905cf06786275cfde2ae94369611fb)
+++ src/SynTree/Visitor.h	(revision 4d3ca1d868f76bdc3c138e232ca019fd019466eb)
@@ -104,7 +104,7 @@
 	virtual void visit( Constant *constant );
   private:
-	virtual void visit( AggregateDecl *aggregateDecl );
-	virtual void visit( NamedTypeDecl *typeDecl );
-	virtual void visit( ReferenceToType *aggregateUseType );
+	virtual void handleAggregateDecl( AggregateDecl *aggregateDecl );
+	virtual void handleNamedTypeDecl( NamedTypeDecl *typeDecl );
+	virtual void handleReferenceToType( ReferenceToType *aggregateUseType );
 };
 
Index: src/SynTree/module.mk
===================================================================
--- src/SynTree/module.mk	(revision 74d1804d72905cf06786275cfde2ae94369611fb)
+++ src/SynTree/module.mk	(revision 4d3ca1d868f76bdc3c138e232ca019fd019466eb)
@@ -46,4 +46,5 @@
        SynTree/Visitor.cc \
        SynTree/Mutator.cc \
+       SynTree/AddStmtVisitor.cc \
        SynTree/TypeSubstitution.cc \
        SynTree/Attribute.cc
