Index: src/ControlStruct/ExceptTranslate.cc
===================================================================
--- src/ControlStruct/ExceptTranslate.cc	(revision ba9127067dc626fc81dbe378f35ac7259432e40d)
+++ src/ControlStruct/ExceptTranslate.cc	(revision fe5c01dc12bdff1880c53a48f4b74eb6262c2008)
@@ -10,10 +10,15 @@
 // Created On       : Wed Jun 14 16:49:00 2017
 // Last Modified By : Andrew Beach
-// Last Modified On : Thr Jun 22 15:57:00 2017
-// Update Count     : 0
+// Last Modified On : Thr Jun 29 15:18:00 2017
+// Update Count     : 1
 //
 
 #include "ExceptTranslate.h"
 #include "Common/PassVisitor.h"
+#include "SynTree/Statement.h"
+#include "SynTree/Declaration.h"
+#include "SynTree/Expression.h"
+#include "SynTree/Type.h"
+#include "SynTree/Attribute.h"
 
 namespace ControlFlow {
@@ -34,10 +39,10 @@
 
 	static void init_func_types() {
-		static init_complete = false;
+		static bool init_complete = false;
 		if (init_complete) {
 			return;
 		}
 		ObjectDecl index_obj(
-			"index_t",
+			"__handler_index",
 			Type::StorageClasses(),
 			LinkageSpec::Cforall,
@@ -47,5 +52,5 @@
 		);
 		ObjectDecl exception_obj(
-			"exception_t",
+			"__exception_inst",
 			Type::StorageClasses(),
 			LinkageSpec::Cforall,
@@ -55,5 +60,5 @@
 		);
 		ObjectDecl bool_obj(
-			"bool_t",
+			"__ret_bool",
 			Type::StorageClasses(),
 			LinkageSpec::Cforall,
@@ -80,7 +85,7 @@
 	            CatchList& resHandlers ) {
 		while ( !allHandlers.empty() ) {
-			Statement * stmt = allHandlers.front();
+			CatchStmt * stmt = allHandlers.front();
 			allHandlers.pop_front();
-			if (CaseStmt::Terminate == stmt->get_kind()) {
+			if (CatchStmt::Terminate == stmt->get_kind()) {
 				terHandlers.push_back(stmt);
 			} else {
@@ -92,5 +97,5 @@
 	template<typename T>
 	void free_all( std::list<T *> &list ) {
-		std::list<T *>::iterator it;
+		typename std::list<T *>::iterator it;
 		for ( it = list.begin() ; it != list.end() ; ++it ) {
 			delete *it;
@@ -100,9 +105,9 @@
 
 	void appendDeclStmt( CompoundStmt * block, Declaration * item ) {
-		block->push_back(new DeclStmt(no_labels, item));
-	}
-
-	Expression * nameOf( FunctionDecl * function ) {
-		return new VariableExpr( function );
+		block->push_back(new DeclStmt(noLabels, item));
+	}
+
+	Expression * nameOf( DeclarationWithType * decl ) {
+		return new VariableExpr( decl );
 	}
 
@@ -111,6 +116,7 @@
 	Statement * create_terminate_throw( ThrowStmt *throwStmt ) {
 		// __throw_terminate( EXPR );
-		ApplicationExpr * call = new ApplicationExpr( /* ... */ );
-		call->get_args.push_back( throwStmt->get_expr() );
+		UntypedExpr * call = new UntypedExpr( new NameExpr(
+			"__cfaehm__throw_termination" ) );
+		call->get_args().push_back( throwStmt->get_expr() );
 		Statement * result = new ExprStmt( throwStmt->get_labels(), call );
 		throwStmt->set_expr( nullptr );
@@ -120,7 +126,8 @@
 	Statement * create_terminate_rethrow( ThrowStmt *throwStmt ) {
 		// __rethrow_terminate();
+		assert( nullptr == throwStmt->get_expr() );
 		Statement * result = new ExprStmt(
 			throwStmt->get_labels(),
-			new ApplicationExpr( /* ... */ );
+			new UntypedExpr( new NameExpr( "__cfaehm__rethrow_termination" ) )
 			);
 		delete throwStmt;
@@ -129,6 +136,7 @@
 	Statement * create_resume_throw( ThrowStmt *throwStmt ) {
 		// __throw_resume( EXPR );
-		ApplicationExpr * call = new ApplicationExpr( /* ... */ );
-		call->get_args.push_back( throwStmt->get_expr() );
+		UntypedExpr * call = new UntypedExpr( new NameExpr(
+			"__cfaehm__throw_resumption" ) );
+		call->get_args().push_back( throwStmt->get_expr() );
 		Statement * result = new ExprStmt( throwStmt->get_labels(), call );
 		throwStmt->set_expr( nullptr );
@@ -140,12 +148,5 @@
 		Statement * result = new ReturnStmt(
 			throwStmt->get_labels(),
-			new ConstantExpr(
-				Constant(
-					new BasicType(
-						Type::Qualifiers(),
-						BasicType::Bool
-						),
-					"0")
-				)
+			new ConstantExpr( Constant::from_bool( false ) )
 			);
 		delete throwStmt;
@@ -160,14 +161,16 @@
 		return block;
 	}
-	FunctionDecl * create_try_wrapper( TryStmt *tryStmt ) {
-		CompoundStmt * body = base_try->get_block();
-		base_try->set_block(nullptr);
-
-		return new FunctionDecl("try", Type::StorageClasses(),
-			LinkageSpec::Cforall, void_func_t, body);
+	FunctionDecl * create_try_wrapper( CompoundStmt *body ) {
+
+		return new FunctionDecl( "try", Type::StorageClasses(),
+			LinkageSpec::Cforall, void_func_t.clone(), body );
 	}
 
 	FunctionDecl * create_terminate_catch( CatchList &handlers ) {
 		std::list<CaseStmt *> handler_wrappers;
+
+		FunctionType *func_type = catch_func_t.clone();
+		DeclarationWithType * index_obj = func_type->get_parameters().front();
+	//	DeclarationWithType * except_obj = func_type->get_parameters().back();
 
 		// Index 1..{number of handlers}
@@ -178,26 +181,33 @@
 			CatchStmt * handler = *it;
 
-			std::list<Statement *> core;
-			if ( /*the exception is named*/ ) {
-				ObjectDecl * local_except = /* Dynamic case, same */;
-				core->push_back( new DeclStmt( noLabel, local_except ) );
-			}
-			// Append the provided statement to the handler.
-			core->push_back( cur_handler->get_body() );
-			// Append return onto the inner block? case stmt list?
-			CaseStmt * wrapper = new CaseStmt(
+			// INTEGERconstant Version
+			// case `index`:
+			// {
+			//     `handler.body`
+			// }
+			// return;
+			std::list<Statement *> caseBody;
+			caseBody.push_back( handler->get_body() );
+			handler->set_body( nullptr );
+			caseBody.push_back( new ReturnStmt( noLabels, nullptr ) );
+
+			handler_wrappers.push_back( new CaseStmt(
 				noLabels,
 				new ConstantExpr( Constant::from_int( index ) ),
-				core
-				);
-			handler_wrappers.push_back(wrapper);
+				caseBody
+				) );
 		}
 		// TODO: Some sort of meaningful error on default perhaps?
+
+		std::list<Statement*> stmt_handlers;
+		while ( !handler_wrappers.empty() ) {
+			stmt_handlers.push_back( handler_wrappers.front() );
+			handler_wrappers.pop_front();
+		}
 
 		SwitchStmt * handler_lookup = new SwitchStmt(
 			noLabels,
-			/*parameter 0: index*/,
-			handler_wrappers,
-			false
+			nameOf( index_obj ),
+			stmt_handlers
 			);
 		CompoundStmt * body = new CompoundStmt( noLabels );
@@ -205,21 +215,33 @@
 
 		return new FunctionDecl("catch", Type::StorageClasses(),
-			LinkageSpec::Cforall, catch_func_t, body);
+			LinkageSpec::Cforall, func_type, body);
 	}
 
 	// Create a single check from a moddified handler.
-	CompoundStmt *create_single_matcher( CatchStmt * modded_handler ) {
-		CompoundStmt * block = new CompoundStmt( noLables );
-
-		appendDeclStmt( block, modded_handler->get_decl() );
-
-		// TODO: This is not the actual check.
-		LogicalExpr * cond = new ConstantExpr( Constant::from_bool( false ) );
+	// except_obj is referenced, modded_handler will be freed.
+	CompoundStmt *create_single_matcher(
+			DeclarationWithType * except_obj, CatchStmt * modded_handler ) {
+		CompoundStmt * block = new CompoundStmt( noLabels );
+
+		// INTEGERconstant Version
+		assert( nullptr == modded_handler->get_decl() );
+		ConstantExpr * number =
+			dynamic_cast<ConstantExpr*>( modded_handler->get_cond() );
+		assert( number );
+		modded_handler->set_cond( nullptr );
+
+		Expression * cond;
+		{
+			std::list<Expression *> args;
+			args.push_back( number );
+			args.push_back( nameOf( except_obj ) );
+			cond = new UntypedExpr( new NameExpr( "?==?" /*???*/), args );
+		}
 
 		if ( modded_handler->get_cond() ) {
-			cond = new LogicalExpr( cond, modded_handler->get_cond() )q
+			cond = new LogicalExpr( cond, modded_handler->get_cond() );
 		}
 		block->push_back( new IfStmt( noLabels,
-			cond, modded_handler->get_body() );
+			cond, modded_handler->get_body(), nullptr ) );
 
 		modded_handler->set_decl( nullptr );
@@ -232,4 +254,7 @@
 	FunctionDecl * create_terminate_match( CatchList &handlers ) {
 		CompoundStmt * body = new CompoundStmt( noLabels );
+
+		FunctionType * func_type = match_func_t.clone();
+		DeclarationWithType * except_obj = func_type->get_parameters().back();
 
 		// Index 1..{number of handlers}
@@ -240,32 +265,42 @@
 			CatchStmt * handler = *it;
 
-			// body should have been taken by create_terminate_catch.
-			// assert( nullptr == handler->get_body() );
+			// Body should have been taken by create_terminate_catch.
+			assert( nullptr == handler->get_body() );
+
+			// Create new body.
 			handler->set_body( new ReturnStmt( noLabels,
 				new ConstantExpr( Constant::from_int( index ) ) ) );
 
-			body->push_back( create_single_matcher( handler ) );
+			// Create the handler.
+			body->push_back( create_single_matcher( except_obj, handler ) );
+			*it = nullptr;
 		}
 
 		return new FunctionDecl("match", Type::StorageClasses(),
-			LinkageSpec::Cforall, match_func_t, body);
-	}
-
-	Statement * create_terminate_caller(
+			LinkageSpec::Cforall, func_type, body);
+	}
+
+	CompoundStmt * create_terminate_caller(
 			FunctionDecl * try_wrapper,
 			FunctionDecl * terminate_catch,
 			FunctionDecl * terminate_match) {
 
-		ApplicationExpr * caller = new ApplicationExpr( /* ... */ );
-		std::list<Expression *>& args = caller.get_args();
+		UntypedExpr * caller = new UntypedExpr( new NameExpr(
+			"__cfaehm__try_terminate" ) );
+		std::list<Expression *>& args = caller->get_args();
 		args.push_back( nameOf( try_wrapper ) );
 		args.push_back( nameOf( terminate_catch ) );
 		args.push_back( nameOf( terminate_match ) );
 
-		return new ExprStmt( noLabels, caller );
+		CompoundStmt * callStmt = new CompoundStmt( noLabels );
+		callStmt->push_back( new ExprStmt( noLabels, caller ) );
+		return callStmt;
 	}
 
 	FunctionDecl * create_resume_handler( CatchList &handlers ) {
-		CompoundStmt * body = new CompountStmt( noLabels );
+		CompoundStmt * body = new CompoundStmt( noLabels );
+
+		FunctionType * func_type = match_func_t.clone();
+		DeclarationWithType * except_obj = func_type->get_parameters().back();
 
 		CatchList::iterator it;
@@ -280,52 +315,58 @@
 				handling_code->push_back( handler->get_body() );
 			}
-			handling_code->push_back( new ReturnStmt( noLabel,
+			handling_code->push_back( new ReturnStmt( noLabels,
 				new ConstantExpr( Constant::from_bool( false ) ) ) );
 			handler->set_body( handling_code );
 
 			// Create the handler.
-			body->push_back( create_single_matcher( handler ) );
+			body->push_back( create_single_matcher( except_obj, handler ) );
+			*it = nullptr;
 		}
 
 		return new FunctionDecl("handle", Type::StorageClasses(),
-			LinkageSpec::Cforall, handle_func_t, body);
-	}
-
-	Statement * create_resume_wrapper(
+			LinkageSpec::Cforall, func_type, body);
+	}
+
+	CompoundStmt * create_resume_wrapper(
+			StructDecl * node_decl,
 			Statement * wraps,
 			FunctionDecl * resume_handler ) {
 		CompoundStmt * body = new CompoundStmt( noLabels );
 
-		// struct node = {current top resume handler, call to resume_handler};
-		// __attribute__((cleanup( ... )));
-		// set top resume handler to node.
-		// The wrapped statement.
-
-		ListInit * node_init;
-		{
-			std::list<Initializer*> field_inits;
-			field_inits.push_back( new SingleInit( /* ... */ ) );
-			field_inits.push_back( new SingleInit( nameOf( resume_handler ) ) );
-			node_init = new ListInit( field_inits );
-		}
+		// struct __try_resume_node __resume_node
+		//  	__attribute__((cleanup( __cfaehm__try_resume_cleanup )));
+		// ** unwinding of the stack here could cause problems **
+		// ** however I don't think that can happen currently **
+		// __cfaehm__try_resume_setup( &__resume_node, resume_handler );
 
 		std::list< Attribute * > attributes;
 		{
 			std::list< Expression * > attr_params;
-			attr_params.push_back( nameOf( /* ... deconstructor ... */ ) );
-			attrributes.push_back( new Attribute( "cleanup", attr_params ) );
-		}
-
-		appendDeclStmt( body,
-		/**/ ObjectDecl(
-			"resume_node",
+			attr_params.push_back( new NameExpr(
+				"__cfaehm__try_resume_cleanup" ) );
+			attributes.push_back( new Attribute( "cleanup", attr_params ) );
+		}
+
+		ObjectDecl * obj = new ObjectDecl(
+			"__resume_node",
 			Type::StorageClasses(),
 			LinkageSpec::Cforall,
 			nullptr,
-			/* Type* = resume_node */,
-			node_init,
+			new StructInstType(
+				Type::Qualifiers(),
+				node_decl
+				),
+			nullptr,
 			attributes
-			)
-		);
+			);
+		appendDeclStmt( body, obj );
+
+		UntypedExpr *setup = new UntypedExpr( new NameExpr(
+			"__cfaehm__try_resume_setup" ) );
+		setup->get_args().push_back( nameOf( obj ) );
+		setup->get_args().push_back( nameOf( resume_handler ) );
+
+		body->push_back( new ExprStmt( noLabels, setup ) );
+
 		body->push_back( wraps );
 		return body;
@@ -333,13 +374,18 @@
 
 	FunctionDecl * create_finally_wrapper( TryStmt * tryStmt ) {
-		CompoundStmt * body = tryStmt->get_finally();
+		FinallyStmt * finally = tryStmt->get_finally();
+		CompoundStmt * body = finally->get_block();
+		finally->set_block( nullptr );
+		delete finally;
 		tryStmt->set_finally( nullptr );
 
 		return new FunctionDecl("finally", Type::StorageClasses(),
-			LinkageSpec::Cforall, void_func_t, body);
-	}
-
-	ObjectDecl * create_finally_hook( FunctionDecl * finally_wrapper ) {
-		// struct _cleanup_hook NAME __attribute__((cleanup( ... )));
+			LinkageSpec::Cforall, void_func_t.clone(), body);
+	}
+
+	ObjectDecl * create_finally_hook(
+			StructDecl * hook_decl, FunctionDecl * finally_wrapper ) {
+		// struct __cfaehm__cleanup_hook __finally_hook
+		//   	__attribute__((cleanup( finally_wrapper )));
 
 		// Make Cleanup Attribute.
@@ -348,13 +394,16 @@
 			std::list< Expression * > attr_params;
 			attr_params.push_back( nameOf( finally_wrapper ) );
-			attrributes.push_back( new Attribute( "cleanup", attr_params ) );
-		}
-
-		return ObjectDecl( /* ... */
-			const std::string &name "finally_hook",
+			attributes.push_back( new Attribute( "cleanup", attr_params ) );
+		}
+
+		return new ObjectDecl(
+			"__finally_hook",
 			Type::StorageClasses(),
 			LinkageSpec::Cforall,
 			nullptr,
-			/* ... Type * ... */,
+			new StructInstType(
+				emptyQualifiers,
+				hook_decl
+				),
 			nullptr,
 			attributes
@@ -363,5 +412,5 @@
 
 
-	class ExceptionMutatorCore : public WithScoping {
+	class ExceptionMutatorCore : public WithScopes {
 		enum Context { NoHandler, TerHandler, ResHandler };
 
@@ -370,5 +419,5 @@
 		// loop, switch or the goto stays within the function.
 
-		Context curContext;
+		Context cur_context;
 
 		// We might not need this, but a unique base for each try block's
@@ -377,11 +426,15 @@
 		//unsigned int try_count = 0;
 
+		StructDecl *node_decl;
+		StructDecl *hook_decl;
 
 	public:
 		ExceptionMutatorCore() :
-			curContext(NoHandler)
+			cur_context(NoHandler),
+			node_decl(nullptr), hook_decl(nullptr)
 		{}
 
-		void premutate( CatchStmt *tryStmt );
+		void premutate( CatchStmt *catchStmt );
+		void premutate( StructDecl *structDecl );
 		Statement * postmutate( ThrowStmt *throwStmt );
 		Statement * postmutate( TryStmt *tryStmt );
@@ -393,9 +446,9 @@
 			if ( throwStmt->get_expr() ) {
 				return create_terminate_throw( throwStmt );
-			} else if ( TerHandler == curContext ) {
+			} else if ( TerHandler == cur_context ) {
 				return create_terminate_rethrow( throwStmt );
 			} else {
 				assertf(false, "Invalid throw in %s at %i\n",
-					throwStmt->location.filename,
+					throwStmt->location.filename.c_str(),
 					throwStmt->location.linenumber);
 				return nullptr;
@@ -404,9 +457,9 @@
 			if ( throwStmt->get_expr() ) {
 				return create_resume_throw( throwStmt );
-			} else if ( ResHandler == curContext ) {
+			} else if ( ResHandler == cur_context ) {
 				return create_resume_rethrow( throwStmt );
 			} else {
 				assertf(false, "Invalid throwResume in %s at %i\n",
-					throwStmt->location.filename,
+					throwStmt->location.filename.c_str(),
 					throwStmt->location.linenumber);
 				return nullptr;
@@ -416,8 +469,11 @@
 
 	Statement * ExceptionMutatorCore::postmutate( TryStmt *tryStmt ) {
+		assert( node_decl );
+		assert( hook_decl );
+
 		// Generate a prefix for the function names?
 
-		CompoundStmt * block = new CompoundStmt();
-		Statement * inner = take_try_block( tryStmt );
+		CompoundStmt * block = new CompoundStmt( noLabels );
+		CompoundStmt * inner = take_try_block( tryStmt );
 
 		if ( tryStmt->get_finally() ) {
@@ -427,13 +483,14 @@
 			appendDeclStmt( block, finally_block );
 			// Create and add the finally cleanup hook.
-			appendDeclStmt( block, create_finally_hook( finally_block ) );
-		}
-
-		StatementList termination_handlers;
-		StatementList resumption_handlers;
-		split( tryStmt->get_handlers(),
+			appendDeclStmt( block,
+				create_finally_hook( hook_decl, finally_block ) );
+		}
+
+		CatchList termination_handlers;
+		CatchList resumption_handlers;
+		split( tryStmt->get_catchers(),
 		       termination_handlers, resumption_handlers );
 
-		if ( resumeption_handlers.size() ) {
+		if ( resumption_handlers.size() ) {
 			// Define the helper function.
 			FunctionDecl * resume_handler =
@@ -441,5 +498,5 @@
 			appendDeclStmt( block, resume_handler );
 			// Prepare hooks
-			inner = create_resume_wrapper( inner, resume_handler );
+			inner = create_resume_wrapper( node_decl, inner, resume_handler );
 		}
 
@@ -462,6 +519,6 @@
 		block->push_back( inner );
 
-		free_all( termination_handlers );
-		free_all( resumption_handlers );
+		//free_all( termination_handlers );
+		//free_all( resumption_handlers );
 
 		return block;
@@ -469,16 +526,32 @@
 
 	void ExceptionMutatorCore::premutate( CatchStmt *catchStmt ) {
-		GuardValue( curContext );
-		if ( CatchStmt::Termination == catchStmt->get_kind() ) {
-			curContext = TerHandler;
+		GuardValue( cur_context );
+		if ( CatchStmt::Terminate == catchStmt->get_kind() ) {
+			cur_context = TerHandler;
 		} else {
-			curContext = ResHandler;
-		}
+			cur_context = ResHandler;
+		}
+	}
+
+	void ExceptionMutatorCore::premutate( StructDecl *structDecl ) {
+		if ( !structDecl->has_body() ) {
+			// Skip children?
+			return;
+		} else if ( structDecl->get_name() == "__cfaehm__try_resume_node" ) {
+			assert( nullptr == node_decl );
+			node_decl = structDecl;
+		} else if ( structDecl->get_name() == "__cfaehm__cleanup_hook" ) {
+			assert( nullptr == hook_decl );
+			hook_decl = structDecl;
+		}
+		// Later we might get the exception type as well.
 	}
 
     void translateEHM( std::list< Declaration *> & translationUnit ) {
+		init_func_types();
+
 		PassVisitor<ExceptionMutatorCore> translator;
 		for ( Declaration * decl : translationUnit ) {
-			decl->mutate( translator );
+			decl->acceptMutator( translator );
 		}
 	}
Index: src/ControlStruct/ExceptTranslate.h
===================================================================
--- src/ControlStruct/ExceptTranslate.h	(revision ba9127067dc626fc81dbe378f35ac7259432e40d)
+++ src/ControlStruct/ExceptTranslate.h	(revision fe5c01dc12bdff1880c53a48f4b74eb6262c2008)
@@ -10,10 +10,13 @@
 // Created On       : Tus Jun 06 10:13:00 2017
 // Last Modified By : Andrew Beach
-// Last Modified On : Thr Jun 22 15:57:00 2017
-// Update Count     : 0
+// Last Modified On : Thr Jun 29 15:18:00 2017
+// Update Count     : 1
 //
 
 #ifndef EXCEPT_TRANSLATE_H
 #define EXCEPT_TRANSLATE_H
+
+#include <list>
+#include "SynTree/SynTree.h"
 
 namespace ControlFlow {
Index: src/ControlStruct/module.mk
===================================================================
--- src/ControlStruct/module.mk	(revision ba9127067dc626fc81dbe378f35ac7259432e40d)
+++ src/ControlStruct/module.mk	(revision fe5c01dc12bdff1880c53a48f4b74eb6262c2008)
@@ -10,13 +10,13 @@
 ## Author           : Richard C. Bilson
 ## Created On       : Mon Jun  1 17:49:17 2015
-## Last Modified By : Peter A. Buhr
-## Last Modified On : Thu Aug  4 11:38:06 2016
-## Update Count     : 3
+## Last Modified By : Andrew Beach
+## Last Modified On : Wed Jun 28 16:15:00 2017
+## Update Count     : 4
 ###############################################################################
 
 SRC +=  ControlStruct/LabelGenerator.cc \
 	ControlStruct/LabelFixer.cc \
-        ControlStruct/MLEMutator.cc \
+	ControlStruct/MLEMutator.cc \
 	ControlStruct/Mutate.cc \
-	ControlStruct/ForExprMutator.cc
-
+	ControlStruct/ForExprMutator.cc \
+	ControlStruct/ExceptTranslate.cc
