Index: INSTALL
===================================================================
--- INSTALL	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ INSTALL	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -19,4 +19,7 @@
   cfa-cc components.  Some components will be installed in /some/directory/bin,
   others in /some/directory/lib.  If unspecified, this defaults to /usr/local.
+  If you wish to use (a subdirectory of) your home directory, ${HOME}/some/dir 
+  works, but it is important not to put quotes around the directory path; 
+  Cforall may appear to build, but the installed version may not work properly.
 
 --with-backend-compiler=PROGRAM specifies the installed path of gcc.  It
Index: configure
===================================================================
--- configure	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ configure	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -2999,5 +2999,5 @@
  	cfa_incdir="${cfa_prefix}/include"
 else
- 	cfa_incdir=${$includedir}
+ 	cfa_incdir=${includedir}
 fi
 
Index: configure.ac
===================================================================
--- configure.ac	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ configure.ac	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -41,5 +41,5 @@
  	cfa_incdir="${cfa_prefix}/include"
 else
- 	cfa_incdir=${$includedir}
+ 	cfa_incdir=${includedir}
 fi 
 AC_DEFINE_UNQUOTED(CFA_INCDIR, "${cfa_incdir}", [Location of include files.])
Index: doc/refrat/refrat.tex
===================================================================
--- doc/refrat/refrat.tex	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ doc/refrat/refrat.tex	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -112,14 +112,12 @@
 \lstset{
 language=CFA,
-columns=fullflexible,
+columns=flexible,
 basicstyle=\sf\small,
 tabsize=4,
 xleftmargin=\parindent,
 escapechar=@,
-%fancyvrb=true,
+keepspaces=true,
 %showtabs=true,
-keepspaces=true,
-showtabs=true,
-tab=,
+%tab=\rightarrowfill,
 }%
 
Index: src/CodeGen/CodeGenerator.cc
===================================================================
--- src/CodeGen/CodeGenerator.cc	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/CodeGen/CodeGenerator.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -446,4 +446,15 @@
 		output << ")";
 	}
+
+	void CodeGenerator::visit( AlignofExpr *sizeofExpr ) {
+		// use GCC extension to avoid bumping std to C11
+		output << "__alignof__(";
+		if ( sizeofExpr->get_isType() ) {
+			output << genType( sizeofExpr->get_type(), "" );
+		} else {
+			sizeofExpr->get_expr()->accept( *this );
+		} // if
+		output << ")";
+	}
   
 	void CodeGenerator::visit( LogicalExpr *logicalExpr ) {
Index: src/CodeGen/CodeGenerator.h
===================================================================
--- src/CodeGen/CodeGenerator.h	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/CodeGen/CodeGenerator.h	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -60,4 +60,5 @@
 		virtual void visit( ConstantExpr *constantExpr ); 
 		virtual void visit( SizeofExpr *sizeofExpr );
+		virtual void visit( AlignofExpr *alignofExpr );
 		virtual void visit( LogicalExpr *logicalExpr );
 		virtual void visit( ConditionalExpr *conditionalExpr );
Index: src/GenPoly/Box.cc
===================================================================
--- src/GenPoly/Box.cc	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/GenPoly/Box.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -5,11 +5,11 @@
 // file "LICENCE" distributed with Cforall.
 //
-// Box.cc -- 
+// Box.cc --
 //
 // Author           : Richard C. Bilson
 // Created On       : Mon May 18 07:44:20 2015
 // Last Modified By : Rob Schluntz
-// Last Modified On : Wed Dec 02 11:52:37 2015
-// Update Count     : 201
+// Last Modified On : Fri Dec 18 14:53:08 2015
+// Update Count     : 217
 //
 
@@ -28,4 +28,5 @@
 #include "Parser/ParseNode.h"
 
+#include "SynTree/Constant.h"
 #include "SynTree/Type.h"
 #include "SynTree/Expression.h"
@@ -50,4 +51,5 @@
 		FunctionType *makeAdapterType( FunctionType *adaptee, const TyVarMap &tyVars );
 
+		/// Replaces polymorphic return types with out-parameters, replaces calls to polymorphic functions with adapter calls as needed, and adds appropriate type variables to the function call
 		class Pass1 : public PolyMutator {
 		  public:
@@ -60,8 +62,8 @@
 			virtual Expression *mutate( CommaExpr *commaExpr );
 			virtual Expression *mutate( ConditionalExpr *condExpr );
-			virtual Statement *mutate(ReturnStmt *catchStmt);
+			virtual Statement * mutate( ReturnStmt *returnStmt );
 			virtual Type *mutate( PointerType *pointerType );
-			virtual Type *mutate( FunctionType *pointerType );
-  
+			virtual Type * mutate( FunctionType *functionType );
+
 			virtual void doBeginScope();
 			virtual void doEndScope();
@@ -88,7 +90,7 @@
 		};
 
+		/// Moves polymorphic returns in function types to pointer-type parameters, adds type size and assertion parameters to parameter lists as well
 		class Pass2 : public PolyMutator {
 		  public:
-			Pass2();
 			template< typename DeclClass >
 			DeclClass *handleDecl( DeclClass *decl, Type *type );
@@ -101,8 +103,9 @@
 		  private:
 			void addAdapters( FunctionType *functionType );
-  
+
 			std::map< UniqueId, std::string > adapterName;
 		};
 
+		/// Replaces initialization of polymorphic values with alloca, declaration of dtype/ftype with appropriate void expression, and sizeof expressions of polymorphic types with the proper variable
 		class Pass3 : public PolyMutator {
 		  public:
@@ -148,9 +151,9 @@
 			// the correct thing in some situations. It's not clear to me why this wasn't working.
 
-			// if the return type or a parameter type involved polymorphic types, then the adapter will need 
-			// to take those polymorphic types as pointers. Therefore, there can be two different functions 
+			// if the return type or a parameter type involved polymorphic types, then the adapter will need
+			// to take those polymorphic types as pointers. Therefore, there can be two different functions
 			// with the same mangled name, so we need to further mangle the names.
 			for ( std::list< DeclarationWithType *>::iterator retval = function->get_returnVals().begin(); retval != function->get_returnVals().end(); ++retval ) {
-				if ( isPolyVal( (*retval)->get_type(), tyVars ) ) {
+				if ( isPolyType( (*retval)->get_type(), tyVars ) ) {
 					name << "P";
 				} else {
@@ -161,8 +164,8 @@
 			std::list< DeclarationWithType *> &paramList = function->get_parameters();
 			for ( std::list< DeclarationWithType *>::iterator arg = paramList.begin(); arg != paramList.end(); ++arg ) {
-				if ( isPolyVal( (*arg)->get_type(), tyVars ) ) {
+				if ( isPolyType( (*arg)->get_type(), tyVars ) ) {
 					name << "P";
 				} else {
-					name << "M";				
+					name << "M";
 				}
 			} // for
@@ -178,6 +181,5 @@
 		}
 
-		Pass1::Pass1()
-			: useRetval( false ), tempNamer( "_temp" ) {
+		Pass1::Pass1() : useRetval( false ), tempNamer( "_temp" ) {
 			adapters.push(AdapterMap());
 		}
@@ -191,6 +193,10 @@
 							if ( PointerType *pointer = dynamic_cast< PointerType *>( funType->get_parameters().front()->get_type() ) ) {
 								if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( pointer->get_base() ) ) {
-									name = typeInst->get_name();
-									return true;
+									if ( TypeInstType *typeInst2 = dynamic_cast< TypeInstType *>( funType->get_parameters().back()->get_type() ) ) {
+										if ( typeInst->get_name() == typeInst2->get_name() ) {
+											name = typeInst->get_name();
+											return true;
+										} // if
+									} // if
 								} // if
 							} // if
@@ -228,5 +234,5 @@
 				if ( isPolyRet( functionDecl->get_functionType(), typeName ) && functionDecl->get_linkage() == LinkageSpec::Cforall ) {
 					retval = functionDecl->get_functionType()->get_returnVals().front();
-  
+
 					// give names to unnamed return values
 					if ( retval->get_name() == "" ) {
@@ -235,5 +241,5 @@
 					} // if
 				} // if
-	
+
 				FunctionType *functionType = functionDecl->get_functionType();
 				makeTyVarMap( functionDecl->get_functionType(), scopeTyVars );
@@ -260,5 +266,5 @@
 
 				functionDecl->set_statements( functionDecl->get_statements()->acceptMutator( *this ) );
-  
+
 				scopeTyVars = oldtyVars;
 				assignOps = oldassignOps;
@@ -276,5 +282,4 @@
 
 		TypeDecl *Pass1::mutate( TypeDecl *typeDecl ) {
-///     std::cerr << "add " << typeDecl->get_name() << "\n";
 			scopeTyVars[ typeDecl->get_name() ] = typeDecl->get_kind();
 			return Mutator::mutate( typeDecl );
@@ -302,4 +307,5 @@
 
 		void Pass1::passTypeVars( ApplicationExpr *appExpr, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) {
+			// pass size/align for type variables
 			for ( TyVarMap::const_iterator tyParm = exprTyVars.begin(); tyParm != exprTyVars.end(); ++tyParm ) {
 				ResolvExpr::EqvClass eqvClass;
@@ -310,4 +316,6 @@
 						arg = appExpr->get_args().insert( arg, new SizeofExpr( concrete->clone() ) );
 						arg++;
+						arg = appExpr->get_args().insert( arg, new AlignofExpr( concrete->clone() ) );
+						arg++;
 					} else {
 						throw SemanticError( "unbound type variable in application ", appExpr );
@@ -315,4 +323,30 @@
 				} // if
 			} // for
+
+			// add size/align for generic types to parameter list
+			//assert( ! appExpr->get_function()->get_results().empty() );
+			if ( appExpr->get_function()->get_results().empty() ) return;
+			FunctionType *funcType = getFunctionType( appExpr->get_function()->get_results().front() );
+			assert( funcType );
+
+			std::list< DeclarationWithType* >::const_iterator fnParm = funcType->get_parameters().begin();
+			std::list< Expression* >::const_iterator fnArg = arg;
+			std::set< std::string > seenTypes; //< names for generic types we've seen
+			for ( ; fnParm != funcType->get_parameters().end() && fnArg != appExpr->get_args().end(); ++fnParm, ++fnArg ) {
+				Type *parmType = (*fnParm)->get_type();
+				if ( ! dynamic_cast< TypeInstType* >( parmType ) && isPolyType( parmType, exprTyVars ) ) {
+					std::string sizeName = sizeofName( parmType );
+					if ( seenTypes.count( sizeName ) ) continue;
+
+					assert( ! (*fnArg)->get_results().empty() );
+					Type *argType = (*fnArg)->get_results().front();
+					arg = appExpr->get_args().insert( arg, new SizeofExpr( argType->clone() ) );
+					arg++;
+					arg = appExpr->get_args().insert( arg, new AlignofExpr( argType->clone() ) );
+					arg++;
+
+					seenTypes.insert( sizeName );
+				}
+			}
 		}
 
@@ -323,41 +357,31 @@
 		}
 
-		TypeInstType *isPolyType( Type *type, const TypeSubstitution *env, const TyVarMap &tyVars ) {
-			if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
-				if ( env ) {
-					if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
-						return isPolyType( newType, env, tyVars );
-					} // if
-				} // if
-				if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) {
-					return typeInst;
-				} else {
-					return 0;
-				} // if
-			} else {
-				return 0;
-			} // if
-		}
-
 		Expression *Pass1::addRetParam( ApplicationExpr *appExpr, FunctionType *function, Type *retType, std::list< Expression *>::iterator &arg ) {
-			if ( useRetval ) {
-				assert( retval );
-				arg = appExpr->get_args().insert( arg, new VariableExpr( retval ) );
-				arg++;
-			} else {
-				ObjectDecl *newObj = makeTemporary( retType->clone() );
-				Expression *paramExpr = new VariableExpr( newObj );
-				if ( ! isPolyType( newObj->get_type(), env, scopeTyVars ) ) {
-					paramExpr = new AddressExpr( paramExpr );
-				} // if
-				arg = appExpr->get_args().insert( arg, paramExpr );
-				arg++;
-///     stmtsToAdd.push_back( new ExprStmt( noLabels, appExpr ) );
-				CommaExpr *commaExpr = new CommaExpr( appExpr, new VariableExpr( newObj ) );
-				commaExpr->set_env( appExpr->get_env() );
-				appExpr->set_env( 0 );
-				return commaExpr;
-			} // if
-			return appExpr;
+			// ***** Code Removal ***** After introducing a temporary variable for all return expressions, the following code appears superfluous.
+			// if ( useRetval ) {
+			// 	assert( retval );
+			// 	arg = appExpr->get_args().insert( arg, new VariableExpr( retval ) );
+			// 	arg++;
+			// } else {
+
+			// Create temporary to hold return value of polymorphic function and produce that temporary as a result
+			// using a comma expression.  Possibly change comma expression into statement expression "{}" for multiple
+			// return values.
+			ObjectDecl *newObj = makeTemporary( retType->clone() );
+			Expression *paramExpr = new VariableExpr( newObj );
+			// If the type of the temporary is not polymorphic, box temporary by taking its address; otherwise the
+			// temporary is already boxed and can be used directly.
+			if ( ! isPolyType( newObj->get_type(), scopeTyVars, env ) ) {
+				paramExpr = new AddressExpr( paramExpr );
+			} // if
+			arg = appExpr->get_args().insert( arg, paramExpr ); // add argument to function call
+			arg++;
+			// Build a comma expression to call the function and emulate a normal return.
+			CommaExpr *commaExpr = new CommaExpr( appExpr, new VariableExpr( newObj ) );
+			commaExpr->set_env( appExpr->get_env() );
+			appExpr->set_env( 0 );
+			return commaExpr;
+			// } // if
+			// return appExpr;
 		}
 
@@ -374,5 +398,5 @@
 		Expression *Pass1::applyAdapter( ApplicationExpr *appExpr, FunctionType *function, std::list< Expression *>::iterator &arg, const TyVarMap &tyVars ) {
 			Expression *ret = appExpr;
-			if ( ! function->get_returnVals().empty() && isPolyVal( function->get_returnVals().front()->get_type(), tyVars ) ) {
+			if ( ! function->get_returnVals().empty() && isPolyType( function->get_returnVals().front()->get_type(), tyVars ) ) {
 				ret = addRetParam( appExpr, function, function->get_returnVals().front()->get_type(), arg );
 			} // if
@@ -382,5 +406,5 @@
 			appExpr->get_args().push_front( appExpr->get_function() );
 			appExpr->set_function( new NameExpr( adapterName ) );
-  
+
 			return ret;
 		}
@@ -388,5 +412,5 @@
 		void Pass1::boxParam( Type *param, Expression *&arg, const TyVarMap &exprTyVars ) {
 			assert( ! arg->get_results().empty() );
-///   if ( ! dynamic_cast< PointerType *>( arg->get_results().front() ) ) {
+//   if ( ! dynamic_cast< PointerType *>( arg->get_results().front() ) ) {
 			TypeInstType *typeInst = dynamic_cast< TypeInstType *>( param );
 			if ( typeInst && exprTyVars.find( typeInst->get_name() ) != exprTyVars.end() ) {
@@ -408,5 +432,5 @@
 				} // if
 			} // if
-///   }
+//   }
 		}
 
@@ -425,11 +449,5 @@
 
 		void Pass1::boxParams( ApplicationExpr *appExpr, FunctionType *function, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) {
-///   std::cout << "function is ";
-///   function->print( std::cout );
 			for ( std::list< DeclarationWithType *>::const_iterator param = function->get_parameters().begin(); param != function->get_parameters().end(); ++param, ++arg ) {
-///     std::cout << "parameter is ";
-///     (*param)->print( std::fcout );
-///     std::cout << std::endl << "argument is ";
-///     (*arg)->print( std::cout );
 				assert( arg != appExpr->get_args().end() );
 				addCast( *arg, (*param)->get_type(), exprTyVars );
@@ -466,5 +484,5 @@
 			// actually make the adapter type
 			FunctionType *adapter = adaptee->clone();
-			if ( ! adapter->get_returnVals().empty() && isPolyVal( adapter->get_returnVals().front()->get_type(), tyVars ) ) {
+			if ( ! adapter->get_returnVals().empty() && isPolyType( adapter->get_returnVals().front()->get_type(), tyVars ) ) {
 				makeRetParm( adapter );
 			} // if
@@ -476,14 +494,8 @@
 			assert( param );
 			assert( arg );
-///   std::cout << "arg type is ";
-///   arg->get_type()->print( std::cout );
-///   std::cout << "param type is ";
-///   param->get_type()->print( std::cout );
-///   std::cout << " tyVars are: ";
-///   printTyVarMap( std::cout, tyVars );
-			if ( isPolyVal( realParam->get_type(), tyVars ) ) {
-///     if ( dynamic_cast< PointerType *>( arg->get_type() ) ) {
-///       return new CastExpr( new VariableExpr( param ), arg->get_type()->clone() );
-///     } else {
+			if ( isPolyType( realParam->get_type(), tyVars ) ) {
+//     if ( dynamic_cast< PointerType *>( arg->get_type() ) ) {
+//       return new CastExpr( new VariableExpr( param ), arg->get_type()->clone() );
+//     } else {
 				if ( dynamic_cast<TypeInstType *>(arg->get_type()) == NULL ) {
 					UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
@@ -492,5 +504,5 @@
 					return deref;
 				} // if
-///     }
+//     }
 			} // if
 			return new VariableExpr( param );
@@ -517,5 +529,5 @@
 			ApplicationExpr *adapteeApp = new ApplicationExpr( new CastExpr( new VariableExpr( adapteeDecl ), new PointerType( Type::Qualifiers(), realType ) ) );
 			Statement *bodyStmt;
-  
+
 			std::list< TypeDecl *>::iterator tyArg = realType->get_forall().begin();
 			std::list< TypeDecl *>::iterator tyParam = adapterType->get_forall().begin();
@@ -531,5 +543,5 @@
 				} // for
 			} // for
-  
+
 			std::list< DeclarationWithType *>::iterator arg = realType->get_parameters().begin();
 			std::list< DeclarationWithType *>::iterator param = adapterType->get_parameters().begin();
@@ -539,5 +551,5 @@
 				addAdapterParams( adapteeApp, arg, param, adapterType->get_parameters().end(), realParam, tyVars );
 				bodyStmt = new ExprStmt( noLabels, adapteeApp );
-			} else if ( isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {
+			} else if ( isPolyType( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {
 				if ( (*param)->get_name() == "" ) {
 					(*param)->set_name( "_ret" );
@@ -588,9 +600,9 @@
 				if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) {
 					adaptersDone.insert( adaptersDone.begin(), mangleName );
-					
+
 					// apply substitution to type variables to figure out what the adapter's type should look like
 					assert( env );
 					env->apply( realFunction );
-					mangleName = SymTab::Mangler::mangle( realFunction ); 
+					mangleName = SymTab::Mangler::mangle( realFunction );
 					mangleName += makePolyMonoSuffix( originalFunction, exprTyVars );
 
@@ -611,31 +623,5 @@
 		} // passAdapters
 
-		TypeInstType *isPolyPtr( Type *type, const TypeSubstitution *env, const TyVarMap &tyVars ) {
-			if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
-				return isPolyType( ptr->get_base(), env, tyVars );
-			} else if ( env ) {
-				if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
-					if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
-						return isPolyPtr( newType, env, tyVars );
-					} // if
-				} // if
-			} // if
-			return 0;
-		}
-
-		TypeInstType *isPolyPtrPtr( Type *type, const TypeSubstitution *env, const TyVarMap &tyVars ) {
-			if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
-				return isPolyPtr( ptr->get_base(), env, tyVars );
-			} else if ( env ) {
-				if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
-					if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
-						return isPolyPtrPtr( newType, env, tyVars );
-					} // if
-				} // if
-			} // if
-			return 0;
-		}
-
-		Expression *makeIncrDecrExpr( ApplicationExpr *appExpr, std::string polyName, bool isIncr ) {
+		Expression *makeIncrDecrExpr( ApplicationExpr *appExpr, Type *polyType, bool isIncr ) {
 			NameExpr *opExpr;
 			if ( isIncr ) {
@@ -650,5 +636,5 @@
 				addAssign->get_args().push_back( appExpr->get_args().front() );
 			} // if
-			addAssign->get_args().push_back( new NameExpr( polyName ) );
+			addAssign->get_args().push_back( new NameExpr( sizeofName( polyType ) ) );
 			addAssign->get_results().front() = appExpr->get_results().front()->clone();
 			if ( appExpr->get_env() ) {
@@ -667,25 +653,25 @@
 						assert( ! appExpr->get_results().empty() );
 						assert( appExpr->get_args().size() == 2 );
-						TypeInstType *typeInst1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), env, scopeTyVars );
-						TypeInstType *typeInst2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), env, scopeTyVars );
-						assert( ! typeInst1 || ! typeInst2 );  // the arguments cannot both be polymorphic pointers
+						Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), scopeTyVars, env );
+						Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), scopeTyVars, env );
+						assert( ! baseType1 || ! baseType2 ); // the arguments cannot both be polymorphic pointers
 						UntypedExpr *ret = 0;
-						if ( typeInst1 || typeInst2 ) { // one of the arguments is a polymorphic pointer
+						if ( baseType1 || baseType2 ) { // one of the arguments is a polymorphic pointer
 							ret = new UntypedExpr( new NameExpr( "?+?" ) );
 						} // if
-						if ( typeInst1 ) {
+						if ( baseType1 ) {
 							UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
 							multiply->get_args().push_back( appExpr->get_args().back() );
-							multiply->get_args().push_back( new NameExpr( typeInst1->get_name() ) );
+							multiply->get_args().push_back( new NameExpr( sizeofName( baseType1 ) ) );
 							ret->get_args().push_back( appExpr->get_args().front() );
 							ret->get_args().push_back( multiply );
-						} else if ( typeInst2 ) {
+						} else if ( baseType2 ) {
 							UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
 							multiply->get_args().push_back( appExpr->get_args().front() );
-							multiply->get_args().push_back( new NameExpr( typeInst2->get_name() ) );
+							multiply->get_args().push_back( new NameExpr( sizeofName( baseType2 ) ) );
 							ret->get_args().push_back( multiply );
 							ret->get_args().push_back( appExpr->get_args().back() );
 						} // if
-						if ( typeInst1 || typeInst2 ) {
+						if ( baseType1 || baseType2 ) {
 							ret->get_results().push_front( appExpr->get_results().front()->clone() );
 							if ( appExpr->get_env() ) {
@@ -700,5 +686,5 @@
 						assert( ! appExpr->get_results().empty() );
 						assert( ! appExpr->get_args().empty() );
-						if ( isPolyType( appExpr->get_results().front(), env, scopeTyVars ) ) {
+						if ( isPolyType( appExpr->get_results().front(), scopeTyVars, env ) ) {
 							Expression *ret = appExpr->get_args().front();
 							delete ret->get_results().front();
@@ -715,5 +701,5 @@
 						assert( ! appExpr->get_results().empty() );
 						assert( appExpr->get_args().size() == 1 );
-						if ( TypeInstType *typeInst = isPolyPtr( appExpr->get_results().front(), env, scopeTyVars ) ) {
+						if ( Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env ) ) {
 							Type *tempType = appExpr->get_results().front()->clone();
 							if ( env ) {
@@ -729,5 +715,5 @@
 								assignExpr->get_args().push_back( appExpr->get_args().front()->clone() );
 							} // if
-							CommaExpr *firstComma = new CommaExpr( assignExpr, makeIncrDecrExpr( appExpr, typeInst->get_name(), varExpr->get_var()->get_name() == "?++" ) );
+							CommaExpr *firstComma = new CommaExpr( assignExpr, makeIncrDecrExpr( appExpr, baseType, varExpr->get_var()->get_name() == "?++" ) );
 							return new CommaExpr( firstComma, tempExpr );
 						} // if
@@ -735,16 +721,16 @@
 						assert( ! appExpr->get_results().empty() );
 						assert( appExpr->get_args().size() == 1 );
-						if ( TypeInstType *typeInst = isPolyPtr( appExpr->get_results().front(), env, scopeTyVars ) ) {
-							return makeIncrDecrExpr( appExpr, typeInst->get_name(), varExpr->get_var()->get_name() == "++?" );
+						if ( Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env ) ) {
+							return makeIncrDecrExpr( appExpr, baseType, varExpr->get_var()->get_name() == "++?" );
 						} // if
 					} else if ( varExpr->get_var()->get_name() == "?+?" || varExpr->get_var()->get_name() == "?-?" ) {
 						assert( ! appExpr->get_results().empty() );
 						assert( appExpr->get_args().size() == 2 );
-						TypeInstType *typeInst1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), env, scopeTyVars );
-						TypeInstType *typeInst2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), env, scopeTyVars );
-						if ( typeInst1 && typeInst2 ) {
+						Type *baseType1 = isPolyPtr( appExpr->get_args().front()->get_results().front(), scopeTyVars, env );
+						Type *baseType2 = isPolyPtr( appExpr->get_args().back()->get_results().front(), scopeTyVars, env );
+						if ( baseType1 && baseType2 ) {
 							UntypedExpr *divide = new UntypedExpr( new NameExpr( "?/?" ) );
 							divide->get_args().push_back( appExpr );
-							divide->get_args().push_back( new NameExpr( typeInst1->get_name() ) );
+							divide->get_args().push_back( new NameExpr( sizeofName( baseType1 ) ) );
 							divide->get_results().push_front( appExpr->get_results().front()->clone() );
 							if ( appExpr->get_env() ) {
@@ -753,13 +739,13 @@
 							} // if
 							return divide;
-						} else if ( typeInst1 ) {
+						} else if ( baseType1 ) {
 							UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
 							multiply->get_args().push_back( appExpr->get_args().back() );
-							multiply->get_args().push_back( new NameExpr( typeInst1->get_name() ) );
+							multiply->get_args().push_back( new NameExpr( sizeofName( baseType1 ) ) );
 							appExpr->get_args().back() = multiply;
-						} else if ( typeInst2 ) {
+						} else if ( baseType2 ) {
 							UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
 							multiply->get_args().push_back( appExpr->get_args().front() );
-							multiply->get_args().push_back( new NameExpr( typeInst2->get_name() ) );
+							multiply->get_args().push_back( new NameExpr( sizeofName( baseType2 ) ) );
 							appExpr->get_args().front() = multiply;
 						} // if
@@ -767,9 +753,9 @@
 						assert( ! appExpr->get_results().empty() );
 						assert( appExpr->get_args().size() == 2 );
-						TypeInstType *typeInst = isPolyPtr( appExpr->get_results().front(), env, scopeTyVars );
-						if ( typeInst ) {
+						Type *baseType = isPolyPtr( appExpr->get_results().front(), scopeTyVars, env );
+						if ( baseType ) {
 							UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) );
 							multiply->get_args().push_back( appExpr->get_args().back() );
-							multiply->get_args().push_back( new NameExpr( typeInst->get_name() ) );
+							multiply->get_args().push_back( new NameExpr( sizeofName( baseType ) ) );
 							appExpr->get_args().back() = multiply;
 						} // if
@@ -792,5 +778,5 @@
 			mutateAll( appExpr->get_args(), *this );
 			useRetval = oldUseRetval;
-  
+
 			assert( ! appExpr->get_function()->get_results().empty() );
 			PointerType *pointer = dynamic_cast< PointerType *>( appExpr->get_function()->get_results().front() );
@@ -798,14 +784,14 @@
 			FunctionType *function = dynamic_cast< FunctionType *>( pointer->get_base() );
 			assert( function );
-  
+
 			if ( Expression *newExpr = handleIntrinsics( appExpr ) ) {
 				return newExpr;
 			} // if
-  
+
 			Expression *ret = appExpr;
-  
+
 			std::list< Expression *>::iterator arg = appExpr->get_args().begin();
 			std::list< Expression *>::iterator paramBegin = appExpr->get_args().begin();
-  
+
 			std::string typeName;
 			if ( isPolyRet( function, typeName ) ) {
@@ -821,13 +807,13 @@
 			} // if
 			arg = appExpr->get_args().begin();
-  
+
 			TyVarMap exprTyVars;
 			makeTyVarMap( function, exprTyVars );
-  
+
 			passTypeVars( appExpr, arg, exprTyVars );
 			addInferredParams( appExpr, function, arg, exprTyVars );
 
 			arg = paramBegin;
-  
+
 			boxParams( appExpr, function, arg, exprTyVars );
 
@@ -838,5 +824,5 @@
 
 		Expression *Pass1::mutate( UntypedExpr *expr ) {
-			if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), env, scopeTyVars ) ) {
+			if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), scopeTyVars, env ) ) {
 				if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) {
 					if ( name->get_name() == "*?" ) {
@@ -853,6 +839,24 @@
 		Expression *Pass1::mutate( AddressExpr *addrExpr ) {
 			assert( ! addrExpr->get_arg()->get_results().empty() );
+
+			bool needs = false;
+			if ( UntypedExpr *expr = dynamic_cast< UntypedExpr *>( addrExpr->get_arg() ) ) {
+				if ( ! expr->get_results().empty() && isPolyType( expr->get_results().front(), scopeTyVars, env ) ) {
+					if ( NameExpr *name = dynamic_cast< NameExpr *>( expr->get_function() ) ) {
+						if ( name->get_name() == "*?" ) {
+							if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr->get_args().front() ) ) {
+								assert( ! appExpr->get_function()->get_results().empty() );
+								PointerType *pointer = dynamic_cast< PointerType *>( appExpr->get_function()->get_results().front() );
+								assert( pointer );
+								FunctionType *function = dynamic_cast< FunctionType *>( pointer->get_base() );
+								assert( function );
+								needs = needsAdapter( function, scopeTyVars );
+							} // if
+						} // if
+					} // if
+				} // if
+			} // if
 			addrExpr->set_arg( mutateExpression( addrExpr->get_arg() ) );
-			if ( isPolyType( addrExpr->get_arg()->get_results().front(), env, scopeTyVars ) ) {
+			if ( isPolyType( addrExpr->get_arg()->get_results().front(), scopeTyVars, env ) || needs ) {
 				Expression *ret = addrExpr->get_arg();
 				delete ret->get_results().front();
@@ -866,39 +870,39 @@
 		}
 
-		Statement * Pass1::mutate(ReturnStmt *retStmt) {
-			// by this point, a cast expr on a polymorphic return value is redundant
-			while ( CastExpr *castExpr = dynamic_cast< CastExpr *>( retStmt->get_expr() ) ) {
-				retStmt->set_expr( castExpr->get_arg() );
-				retStmt->get_expr()->set_env( castExpr->get_env() );
-				castExpr->set_env( 0 );
-				castExpr->set_arg( 0 );
-				delete castExpr;
-			}
-			if ( retval && retStmt->get_expr() ) {
-				assert( ! retStmt->get_expr()->get_results().empty() );
-				if ( retStmt->get_expr()->get_results().front()->get_isLvalue() ) {
-///       retStmt->set_expr( mutateExpression( retStmt->get_expr() ) );
-					TypeInstType *typeInst = dynamic_cast< TypeInstType *>( retval->get_type() );
-					assert( typeInst );
-					std::map< std::string, DeclarationWithType *>::const_iterator assignIter = assignOps.find( typeInst->get_name() );
-					if ( assignIter == assignOps.end() ) {
-						throw SemanticError( "Attempt to return dtype or ftype object in ", retStmt->get_expr() );
-					} // if
-					ApplicationExpr *assignExpr = new ApplicationExpr( new VariableExpr( assignIter->second ) );
-					Expression *retParm = new NameExpr( retval->get_name() );
-					retParm->get_results().push_back( new PointerType( Type::Qualifiers(), retval->get_type()->clone() ) );
-					assignExpr->get_args().push_back( retParm );
-					assignExpr->get_args().push_back( retStmt->get_expr() );
-					stmtsToAdd.push_back( new ExprStmt( noLabels, mutateExpression( assignExpr ) ) );
-				} else {
-					useRetval = true;
-					stmtsToAdd.push_back( new ExprStmt( noLabels, mutateExpression( retStmt->get_expr() ) ) );
-					useRetval = false;
+		Statement * Pass1::mutate( ReturnStmt *returnStmt ) {
+			if ( retval && returnStmt->get_expr() ) {
+				assert( ! returnStmt->get_expr()->get_results().empty() );
+				// ***** Code Removal ***** After introducing a temporary variable for all return expressions, the following code appears superfluous.
+				// if ( returnStmt->get_expr()->get_results().front()->get_isLvalue() ) {
+				// by this point, a cast expr on a polymorphic return value is redundant
+				while ( CastExpr *castExpr = dynamic_cast< CastExpr *>( returnStmt->get_expr() ) ) {
+					returnStmt->set_expr( castExpr->get_arg() );
+					returnStmt->get_expr()->set_env( castExpr->get_env() );
+					castExpr->set_env( 0 );
+					castExpr->set_arg( 0 );
+					delete castExpr;
+				} //while
+				TypeInstType *typeInst = dynamic_cast< TypeInstType *>( retval->get_type() );
+				assert( typeInst );
+				std::map< std::string, DeclarationWithType *>::const_iterator assignIter = assignOps.find( typeInst->get_name() );
+				if ( assignIter == assignOps.end() ) {
+					throw SemanticError( "Attempt to return dtype or ftype object in ", returnStmt->get_expr() );
 				} // if
-				retStmt->set_expr( 0 );
+				ApplicationExpr *assignExpr = new ApplicationExpr( new VariableExpr( assignIter->second ) );
+				Expression *retParm = new NameExpr( retval->get_name() );
+				retParm->get_results().push_back( new PointerType( Type::Qualifiers(), retval->get_type()->clone() ) );
+				assignExpr->get_args().push_back( retParm );
+				assignExpr->get_args().push_back( returnStmt->get_expr() );
+				stmtsToAdd.push_back( new ExprStmt( noLabels, mutateExpression( assignExpr ) ) );
+				// } else {
+				// 	useRetval = true;
+				// 	stmtsToAdd.push_back( new ExprStmt( noLabels, mutateExpression( returnStmt->get_expr() ) ) );
+				// 	useRetval = false;
+				// } // if
+				returnStmt->set_expr( 0 );
 			} else {
-				retStmt->set_expr( mutateExpression( retStmt->get_expr() ) );
-			} // if
-			return retStmt;
+				returnStmt->set_expr( mutateExpression( returnStmt->get_expr() ) );
+			} // if
+			return returnStmt;
 		}
 
@@ -906,7 +910,7 @@
 			TyVarMap oldtyVars = scopeTyVars;
 			makeTyVarMap( pointerType, scopeTyVars );
-  
+
 			Type *ret = Mutator::mutate( pointerType );
-  
+
 			scopeTyVars = oldtyVars;
 			return ret;
@@ -916,7 +920,7 @@
 			TyVarMap oldtyVars = scopeTyVars;
 			makeTyVarMap( functionType, scopeTyVars );
-  
+
 			Type *ret = Mutator::mutate( functionType );
-  
+
 			scopeTyVars = oldtyVars;
 			return ret;
@@ -933,6 +937,4 @@
 
 ////////////////////////////////////////// Pass2 ////////////////////////////////////////////////////
-
-		Pass2::Pass2() {}
 
 		void Pass2::addAdapters( FunctionType *functionType ) {
@@ -953,5 +955,5 @@
 				}
 			}
-///  deleteAll( functions );
+//  deleteAll( functions );
 		}
 
@@ -987,7 +989,7 @@
 			TyVarMap oldtyVars = scopeTyVars;
 			makeTyVarMap( pointerType, scopeTyVars );
-  
+
 			Type *ret = Mutator::mutate( pointerType );
-  
+
 			scopeTyVars = oldtyVars;
 			return ret;
@@ -997,5 +999,6 @@
 			TyVarMap oldtyVars = scopeTyVars;
 			makeTyVarMap( funcType, scopeTyVars );
-  
+
+			// move polymorphic return type to parameter list
 			std::string typeName;
 			if ( isPolyRet( funcType, typeName ) ) {
@@ -1005,31 +1008,63 @@
 				funcType->get_returnVals().pop_front();
 			}
-  
+
+			// add size/align and assertions for type parameters to parameter list
 			std::list< DeclarationWithType *>::iterator last = funcType->get_parameters().begin();
 			std::list< DeclarationWithType *> inferredParams;
-			ObjectDecl *newObj = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0 );
-///   ObjectDecl *newFunPtr = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ), 0 );
+			ObjectDecl newObj( "", DeclarationNode::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0 );
+//   ObjectDecl *newFunPtr = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ), 0 );
 			for ( std::list< TypeDecl *>::const_iterator tyParm = funcType->get_forall().begin(); tyParm != funcType->get_forall().end(); ++tyParm ) {
-				ObjectDecl *thisParm;
-				// add all size parameters to parameter list
+				ObjectDecl *sizeParm, *alignParm;
+				// add all size and alignment parameters to parameter list
 				if ( (*tyParm)->get_kind() == TypeDecl::Any ) {
-					thisParm = newObj->clone();
-					thisParm->set_name( (*tyParm)->get_name() );
-					last = funcType->get_parameters().insert( last, thisParm );
+					TypeInstType parmType( Type::Qualifiers(), (*tyParm)->get_name(), *tyParm );
+
+					sizeParm = newObj.clone();
+					sizeParm->set_name( sizeofName( &parmType ) );
+					last = funcType->get_parameters().insert( last, sizeParm );
+					++last;
+
+					alignParm = newObj.clone();
+					alignParm->set_name( alignofName( &parmType ) );
+					last = funcType->get_parameters().insert( last, alignParm );
 					++last;
 				}
 				// move all assertions into parameter list
 				for ( std::list< DeclarationWithType *>::iterator assert = (*tyParm)->get_assertions().begin(); assert != (*tyParm)->get_assertions().end(); ++assert ) {
-///      *assert = (*assert)->acceptMutator( *this );
+//      *assert = (*assert)->acceptMutator( *this );
 					inferredParams.push_back( *assert );
 				}
 				(*tyParm)->get_assertions().clear();
 			}
-			delete newObj;
+
+			// add size/align for generic types to parameter list
+			std::set< std::string > seenTypes; //< sizeofName for generic types we've seen
+			for ( std::list< DeclarationWithType* >::const_iterator fnParm = last; fnParm != funcType->get_parameters().end(); ++fnParm ) {
+				Type *parmType = (*fnParm)->get_type();
+				if ( ! dynamic_cast< TypeInstType* >( parmType ) && isPolyType( parmType, scopeTyVars ) ) {
+					std::string sizeName = sizeofName( parmType );
+					if ( seenTypes.count( sizeName ) ) continue;
+
+					ObjectDecl *sizeParm, *alignParm;
+					sizeParm = newObj.clone();
+					sizeParm->set_name( sizeName );
+					last = funcType->get_parameters().insert( last, sizeParm );
+					++last;
+
+					alignParm = newObj.clone();
+					alignParm->set_name( alignofName( parmType ) );
+					last = funcType->get_parameters().insert( last, alignParm );
+					++last;
+
+					seenTypes.insert( sizeName );
+				}
+			}
+
+			// splice assertion parameters into parameter list
 			funcType->get_parameters().splice( last, inferredParams );
 			addAdapters( funcType );
 			mutateAll( funcType->get_returnVals(), *this );
 			mutateAll( funcType->get_parameters(), *this );
-  
+
 			scopeTyVars = oldtyVars;
 			return funcType;
@@ -1042,5 +1077,5 @@
 			TyVarMap oldtyVars = scopeTyVars;
 			makeTyVarMap( type, scopeTyVars );
-  
+
 			DeclClass *ret = static_cast< DeclClass *>( Mutator::mutate( decl ) );
 			ScrubTyVars::scrub( decl, scopeTyVars );
@@ -1063,11 +1098,11 @@
 
 		TypeDecl * Pass3::mutate( TypeDecl *typeDecl ) {
-///   Initializer *init = 0;
-///   std::list< Expression *> designators;
-///   scopeTyVars[ typeDecl->get_name() ] = typeDecl->get_kind();
-///   if ( typeDecl->get_base() ) {
-///     init = new SimpleInit( new SizeofExpr( handleDecl( typeDecl, typeDecl->get_base() ) ), designators );
-///   }
-///   return new ObjectDecl( typeDecl->get_name(), Declaration::Extern, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ), init );
+//   Initializer *init = 0;
+//   std::list< Expression *> designators;
+//   scopeTyVars[ typeDecl->get_name() ] = typeDecl->get_kind();
+//   if ( typeDecl->get_base() ) {
+//     init = new SimpleInit( new SizeofExpr( handleDecl( typeDecl, typeDecl->get_base() ) ), designators );
+//   }
+//   return new ObjectDecl( typeDecl->get_name(), Declaration::Extern, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ), init );
 
 			scopeTyVars[ typeDecl->get_name() ] = typeDecl->get_kind();
@@ -1078,7 +1113,7 @@
 			TyVarMap oldtyVars = scopeTyVars;
 			makeTyVarMap( pointerType, scopeTyVars );
-  
+
 			Type *ret = Mutator::mutate( pointerType );
-  
+
 			scopeTyVars = oldtyVars;
 			return ret;
@@ -1088,7 +1123,7 @@
 			TyVarMap oldtyVars = scopeTyVars;
 			makeTyVarMap( functionType, scopeTyVars );
-  
+
 			Type *ret = Mutator::mutate( functionType );
-  
+
 			scopeTyVars = oldtyVars;
 			return ret;
@@ -1097,11 +1132,10 @@
 		Statement *Pass3::mutate( DeclStmt *declStmt ) {
 			if ( ObjectDecl *objectDecl = dynamic_cast< ObjectDecl *>( declStmt->get_decl() ) ) {
-				if ( isPolyVal( objectDecl->get_type(), scopeTyVars ) ) {
+				if ( isPolyType( objectDecl->get_type(), scopeTyVars ) ) {
 					// change initialization of a polymorphic value object
 					// to allocate storage with alloca
-					TypeInstType *typeInst = dynamic_cast< TypeInstType *>( objectDecl->get_type() );
-					assert( typeInst );
+					Type *declType = objectDecl->get_type();
 					UntypedExpr *alloc = new UntypedExpr( new NameExpr( "__builtin_alloca" ) );
-					alloc->get_args().push_back( new NameExpr( typeInst->get_name() ) );
+					alloc->get_args().push_back( new NameExpr( sizeofName( declType ) ) );
 
 					delete objectDecl->get_init();
Index: src/GenPoly/DeclMutator.cc
===================================================================
--- src/GenPoly/DeclMutator.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
+++ src/GenPoly/DeclMutator.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -0,0 +1,164 @@
+//
+// 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.
+//
+// DeclMutator.cc --
+//
+// Author           : Aaron B. Moss
+// Created On       : Fri Nov 27 14:44:00 2015
+// Last Modified By : Aaron B. Moss
+// Last Modified On : Fri Nov 27 14:44:00 2015
+// Update Count     : 1
+//
+
+#include "DeclMutator.h"
+
+#include "SynTree/Expression.h"
+#include "SynTree/Statement.h"
+
+namespace GenPoly {
+	namespace {
+		const std::list<Label> noLabels;
+	}
+
+	DeclMutator::DeclMutator() : Mutator(), declsToAdd(1) {}
+
+	DeclMutator::~DeclMutator() {}
+	
+	void DeclMutator::mutateDeclarationList( std::list< Declaration* > &decls ) {
+		for ( std::list< Declaration* >::iterator decl = decls.begin(); decl != decls.end(); ++decl ) {
+			// run mutator on declaration
+			*decl = maybeMutate( *decl, *this );
+
+			// splice in new declarations before current decl
+			decls.splice( decl, declsToAdd.back() );
+		}
+	}
+
+	void DeclMutator::doBeginScope() {
+		// add new decl list for inside of scope
+		declsToAdd.resize( declsToAdd.size()+1 );
+	}
+
+	void DeclMutator::doEndScope() {
+		// splice any leftover declarations from this scope onto the containing scope
+		std::vector< std::list< Declaration* > >::reverse_iterator back = declsToAdd.rbegin();
+		std::vector< std::list< Declaration* > >::reverse_iterator newBack = back + 1;
+		newBack->splice( newBack->end(), *back );
+		declsToAdd.pop_back();
+	}
+
+	Statement* DeclMutator::mutateStatement( Statement *stmt ) {
+		// shunt over to compound statement handling if applicable
+		CompoundStmt *compoundStmt = dynamic_cast< CompoundStmt* >(stmt);
+		if ( compoundStmt ) return mutate( compoundStmt );
+		
+		doBeginScope();
+		
+		// run mutator on statement
+		stmt = maybeMutate( stmt, *this );
+		// return if no declarations to add
+		if ( declsToAdd.back().empty() ) return stmt;
+
+		// otherwise add declarations to new compound statement
+		CompoundStmt *compound = new CompoundStmt( noLabels );
+		for ( std::list< Declaration* >::iterator decl = declsToAdd.back().begin(); decl != declsToAdd.back().end(); ++decl ) {
+			DeclStmt *declStmt = new DeclStmt( noLabels, *decl );
+			compound->get_kids().push_back( declStmt );
+		}
+		declsToAdd.back().clear();
+
+		doEndScope();
+
+		// add mutated statement and return
+		compound->get_kids().push_back( stmt );
+		return compound;
+	}
+
+	void DeclMutator::mutateStatementList( std::list< Statement* > &stmts ) {
+		doBeginScope();
+		
+		for ( std::list< Statement* >::iterator stmt = stmts.begin(); stmt != stmts.end(); ++stmt ) {
+			// run mutator on statement
+			*stmt = maybeMutate( *stmt, *this );
+
+			// add any new declarations before the statement
+			for ( std::list< Declaration* >::iterator decl = declsToAdd.back().begin(); decl != declsToAdd.back().end(); ++decl ) {
+				DeclStmt *declStmt = new DeclStmt( noLabels, *decl );
+				stmts.insert( stmt, declStmt );
+			}
+			declsToAdd.back().clear();
+		}
+
+		doEndScope();
+	}
+
+	void DeclMutator::addDeclaration( Declaration *decl ) {
+		declsToAdd.back().push_back( decl );
+	}
+
+	CompoundStmt* DeclMutator::mutate(CompoundStmt *compoundStmt) {
+		mutateStatementList( compoundStmt->get_kids() );
+		return compoundStmt;
+	}
+	
+	Statement* DeclMutator::mutate(IfStmt *ifStmt) {
+		ifStmt->set_condition( maybeMutate( ifStmt->get_condition(), *this ) );
+		ifStmt->set_thenPart( mutateStatement( ifStmt->get_thenPart() ) );
+		ifStmt->set_elsePart( mutateStatement( ifStmt->get_elsePart() ) );
+		return ifStmt;
+	}
+	
+	Statement* DeclMutator::mutate(WhileStmt *whileStmt) {
+		whileStmt->set_condition( maybeMutate( whileStmt->get_condition(), *this ) );
+		whileStmt->set_body(  mutateStatement( whileStmt->get_body() ) );
+		return whileStmt;
+	}
+	
+	Statement* DeclMutator::mutate(ForStmt *forStmt) {
+		mutateAll( forStmt->get_initialization(), *this );
+		forStmt->set_condition(  maybeMutate( forStmt->get_condition(), *this ) );
+		forStmt->set_increment(  maybeMutate( forStmt->get_increment(), *this ) );
+		forStmt->set_body(  mutateStatement( forStmt->get_body() ) );
+		return forStmt;
+	}
+	
+	Statement* DeclMutator::mutate(SwitchStmt *switchStmt) {
+		switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) );
+		mutateAll( switchStmt->get_branches(), *this );
+		return switchStmt;
+	}
+	
+	Statement* DeclMutator::mutate(ChooseStmt *chooseStmt) {
+		chooseStmt->set_condition( maybeMutate( chooseStmt->get_condition(), *this ) );
+		mutateAll( chooseStmt->get_branches(), *this );
+		return chooseStmt;
+	}
+	
+	Statement* DeclMutator::mutate(CaseStmt *caseStmt) {
+		caseStmt->set_condition( maybeMutate( caseStmt->get_condition(), *this ) );
+		mutateAll( caseStmt->get_statements(), *this );
+		return caseStmt;
+	}
+	
+	Statement* DeclMutator::mutate(TryStmt *tryStmt) {
+		tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) );
+		mutateAll( tryStmt->get_catchers(), *this );
+		tryStmt->set_finally( maybeMutate( tryStmt->get_finally(), *this ) );
+		return tryStmt;
+	}
+	
+	Statement* DeclMutator::mutate(CatchStmt *catchStmt) {
+		catchStmt->set_decl( maybeMutate( catchStmt->get_decl(), *this ) );
+		catchStmt->set_body( mutateStatement( catchStmt->get_body() ) );
+		return catchStmt;
+	}
+}  // namespace GenPoly
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/GenPoly/DeclMutator.h
===================================================================
--- src/GenPoly/DeclMutator.h	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
+++ src/GenPoly/DeclMutator.h	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -0,0 +1,69 @@
+//
+// 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.
+//
+// DeclMutator.h --
+//
+// Author           : Aaron B. Moss
+// Created On       : Fri Nov 27 14:44:00 2015
+// Last Modified By : Aaron B. Moss
+// Last Modified On : Fri Nov 27 14:44:00 2015
+// Update Count     : 1
+//
+
+#ifndef _DECLMUTATOR_H
+#define _DECLMUTATOR_H
+
+#include <list>
+#include <vector>
+
+#include "SynTree/SynTree.h"
+#include "SynTree/Declaration.h"
+#include "SynTree/Mutator.h"
+
+namespace GenPoly {
+	/// Mutates a list of declarations, providing a means of adding new declarations into the list
+	class DeclMutator : public Mutator {
+	public:
+		DeclMutator();
+		virtual ~DeclMutator();
+		
+		virtual CompoundStmt* mutate(CompoundStmt *compoundStmt);
+		virtual Statement* mutate(IfStmt *ifStmt);
+		virtual Statement* mutate(WhileStmt *whileStmt);
+		virtual Statement* mutate(ForStmt *forStmt);
+		virtual Statement* mutate(SwitchStmt *switchStmt);
+		virtual Statement* mutate(ChooseStmt *chooseStmt);
+		virtual Statement* mutate(CaseStmt *caseStmt);
+		virtual Statement* mutate(TryStmt *tryStmt);
+		virtual Statement* mutate(CatchStmt *catchStmt);
+
+		/// Mutates a list of declarations with this visitor
+		void mutateDeclarationList(std::list< Declaration* >& decls);
+		
+		/// Called on entry to a new scope; overriders should call this as a super-class call
+		virtual void doBeginScope();
+		/// Called on exit from a scope; overriders should call this as a super-class call
+		virtual void doEndScope();
+	protected:
+		/// Mutate a statement that forms its own scope
+		Statement* mutateStatement( Statement *stmt );
+		/// Mutate a list of statements that form a scope
+		void mutateStatementList( std::list< Statement* > &stmts );
+		/// Add a declaration to the list to be added before the current position
+		void addDeclaration( Declaration* decl );
+	private:
+		/// A stack of declarations to add before the current declaration or statement
+		std::vector< std::list< Declaration* > > declsToAdd;
+	};
+} // namespace
+
+#endif // _DECLMUTATOR_H
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/GenPoly/FindFunction.h
===================================================================
--- src/GenPoly/FindFunction.h	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/GenPoly/FindFunction.h	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -23,5 +23,7 @@
 	typedef bool (*FindFunctionPredicate)( FunctionType*, const TyVarMap& );
 
+	/// recursively walk `type`, placing all functions that match `predicate` under `tyVars` into `functions`
 	void findFunction( Type *type, std::list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate );
+	/// like `findFunction`, but also replaces the function type with void ()(void)
 	void findAndReplaceFunction( Type *&type, std::list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate );
 } // namespace GenPoly
Index: src/GenPoly/GenPoly.cc
===================================================================
--- src/GenPoly/GenPoly.cc	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/GenPoly/GenPoly.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -9,10 +9,13 @@
 // Author           : Richard C. Bilson
 // Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Rob Schluntz
-// Last Modified On : Tue Nov 24 15:23:08 2015
-// Update Count     : 11
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Tue Dec 15 16:11:18 2015
+// Update Count     : 13
 //
 
 #include "GenPoly.h"
+
+#include "SymTab/Mangler.h"
+#include "SynTree/Expression.h"
 #include "SynTree/Type.h"
 
@@ -21,12 +24,10 @@
 
 namespace GenPoly {
-	// A function needs an adapter if it returns a polymorphic value or if any of its
-	// parameters have polymorphic type
 	bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) {
-		if ( ! adaptee->get_returnVals().empty() && isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {
+		if ( ! adaptee->get_returnVals().empty() && isPolyType( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {
 			return true;
 		} // if
 		for ( std::list< DeclarationWithType* >::const_iterator innerArg = adaptee->get_parameters().begin(); innerArg != adaptee->get_parameters().end(); ++innerArg ) {
-			if ( isPolyVal( (*innerArg)->get_type(), tyVars ) ) {
+			if ( isPolyType( (*innerArg)->get_type(), tyVars ) ) {
 				return true;
 			} // if
@@ -66,20 +67,92 @@
 	}
 
-	bool isPolyVal( Type *type, const TyVarMap &tyVars ) {
+	namespace {
+		/// Checks a parameter list for polymorphic parameters; will substitute according to env if present
+		bool hasPolyParams( std::list< Expression* >& params, const TypeSubstitution *env ) {
+			for ( std::list< Expression* >::iterator param = params.begin(); param != params.end(); ++param ) {
+				TypeExpr *paramType = dynamic_cast< TypeExpr* >( *param );
+				assert(paramType && "Aggregate parameters should be type expressions");
+				if ( isPolyType( paramType->get_type(), env ) ) return true;
+			}
+			return false;
+		}
+
+		/// Checks a parameter list for polymorphic parameters from tyVars; will substitute according to env if present
+		bool hasPolyParams( std::list< Expression* >& params, const TyVarMap &tyVars, const TypeSubstitution *env ) {
+			for ( std::list< Expression* >::iterator param = params.begin(); param != params.end(); ++param ) {
+				TypeExpr *paramType = dynamic_cast< TypeExpr* >( *param );
+				assert(paramType && "Aggregate parameters should be type expressions");
+				if ( isPolyType( paramType->get_type(), tyVars, env ) ) return true;
+			}
+			return false;
+		}
+	}
+
+	Type *isPolyType( Type *type, const TypeSubstitution *env ) {
 		if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( type ) ) {
+			if ( env ) {
+				if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
+					return isPolyType( newType, env );
+				} // if
+			} // if
+			return type;
+		} else if ( StructInstType *structType = dynamic_cast< StructInstType* >( type ) ) {
+			if ( hasPolyParams( structType->get_parameters(), env ) ) return type;
+		} else if ( UnionInstType *unionType = dynamic_cast< UnionInstType* >( type ) ) {
+			if ( hasPolyParams( unionType->get_parameters(), env ) ) return type;
+		}
+		return 0;
+	}
+	
+	Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) {
+		if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( type ) ) {
+			if ( env ) {
+				if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
+					return isPolyType( newType, tyVars, env );
+				} // if
+			} // if
 			if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) {
-				return true;
+				return type;
+			}
+		} else if ( StructInstType *structType = dynamic_cast< StructInstType* >( type ) ) {
+			if ( hasPolyParams( structType->get_parameters(), tyVars, env ) ) return type;
+		} else if ( UnionInstType *unionType = dynamic_cast< UnionInstType* >( type ) ) {
+			if ( hasPolyParams( unionType->get_parameters(), tyVars, env ) ) return type;
+		}
+		return 0;
+	}
+
+	Type *isPolyPtr( Type *type, const TypeSubstitution *env ) {
+		if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
+			return isPolyType( ptr->get_base(), env );
+		} else if ( env ) {
+			if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
+				if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
+					return isPolyPtr( newType, env );
+				} // if
 			} // if
 		} // if
-		return false;
+		return 0;
+	}
+	
+	Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) {
+		if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
+			return isPolyType( ptr->get_base(), tyVars, env );
+		} else if ( env ) {
+			if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
+				if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
+					return isPolyPtr( newType, tyVars, env );
+				} // if
+			} // if
+		} // if
+		return 0;
 	}
 
-	bool isPolyObj( Type *type, const TyVarMap &tyVars ) {
-		if ( isPolyVal( type, tyVars ) ) {
-			return true;
-		} else if ( PointerType *pt = dynamic_cast<PointerType*>( type ) ) {
-			return isPolyObj( pt->get_base(), tyVars );
+	FunctionType * getFunctionType( Type *ty ) {
+		PointerType *ptrType;
+		if ( ( ptrType = dynamic_cast< PointerType* >( ty ) ) ) {
+			return dynamic_cast< FunctionType* >( ptrType->get_base() ); // pointer if FunctionType, NULL otherwise
 		} else {
-			return false;
+			return dynamic_cast< FunctionType* >( ty ); // pointer if FunctionType, NULL otherwise
 		}
 	}
@@ -91,4 +164,12 @@
 		os << std::endl;
 	}
+
+	std::string sizeofName( Type *ty ) {
+		return std::string( "_sizeof_" ) + SymTab::Mangler::mangleType( ty );
+	}
+
+	std::string alignofName( Type *ty ) {
+		return std::string( "_alignof_" ) + SymTab::Mangler::mangleType( ty );
+	}
 } // namespace GenPoly
 
Index: src/GenPoly/GenPoly.h
===================================================================
--- src/GenPoly/GenPoly.h	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/GenPoly/GenPoly.h	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -20,19 +20,43 @@
 #include <string>
 #include <iostream>
+
 #include "SynTree/Declaration.h"
+#include "SynTree/TypeSubstitution.h"
 
 namespace GenPoly {
 	typedef std::map< std::string, TypeDecl::Kind > TyVarMap;
 
+	/// A function needs an adapter if it returns a polymorphic value or if any of its
+	/// parameters have polymorphic type
 	bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVarr );
+
+	/// true iff function has polymorphic return type
 	bool isPolyRet( FunctionType *function, std::string &name, const TyVarMap &otherTyVars );
 	bool isPolyRet( FunctionType *function, std::string &name );
 	bool isPolyRet( FunctionType *function, const TyVarMap &otherTyVars );
-//	bool isPolyFun( FunctionType *fun, const TyVarMap &tyVars );
-	bool isPolyVal( Type *type, const TyVarMap &tyVars );
 
-  // true if type variable or any number of pointers to type variable 
-  bool isPolyObj( Type *type, const TyVarMap &tyVars );
+	/// returns polymorphic type if is polymorphic type, NULL otherwise; will look up substitution in env if provided
+	Type *isPolyType( Type *type, const TypeSubstitution *env = 0 );
+	
+	/// returns polymorphic type if is polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided
+	Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
+
+	/// returns polymorphic type if is pointer to polymorphic type, NULL otherwise; will look up substitution in env if provided
+	Type *isPolyPtr( Type *type, const TypeSubstitution *env = 0 );
+	
+	/// returns polymorphic type if is pointer to polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided
+	Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
+
+	/// Returns a pointer to the base FunctionType if ty is the type of a function (or pointer to one), NULL otherwise
+	FunctionType * getFunctionType( Type *ty );
+
+	/// Prints type variable map
 	void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap );
+
+	/// Gets the name of the sizeof parameter for the type
+	std::string sizeofName( Type *ty );
+
+	/// Gets the name of the alignof parameter for the type
+	std::string alignofName( Type *ty );
 } // namespace GenPoly
 
Index: src/GenPoly/InstantiateGeneric.cc
===================================================================
--- src/GenPoly/InstantiateGeneric.cc	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/GenPoly/InstantiateGeneric.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -5,5 +5,5 @@
 // file "LICENCE" distributed with Cforall.
 //
-// InstantiateGeneric.h --
+// InstantiateGeneric.cc --
 //
 // Author           : Aaron B. Moss
@@ -21,5 +21,5 @@
 
 #include "InstantiateGeneric.h"
-#include "PolyMutator.h"
+#include "DeclMutator.h"
 
 #include "ResolvExpr/typeops.h"
@@ -44,10 +44,8 @@
 		ConcreteType(const ConcreteType& that) : base(that.base), params() { cloneAll(that.params, params); }
 
-		/// Extracts types from a list of Expression* (which should be TypeExpr*)
-		ConcreteType(AggregateDecl *_base, const std::list< Expression* >& _params) : base(_base), params() {
-			for ( std::list< Expression* >::const_iterator it = _params.begin(); it != _params.end(); ++it ) {
-				TypeExpr *param = dynamic_cast< TypeExpr* >(*it);
-				assert(param && "Aggregate parameters should be type expressions");
-				params.push_back( param->get_type()->clone() );
+		/// Extracts types from a list of TypeExpr*
+		ConcreteType(AggregateDecl *_base, const std::list< TypeExpr* >& _params) : base(_base), params() {
+			for ( std::list< TypeExpr* >::const_iterator param = _params.begin(); param != _params.end(); ++param ) {
+				params.push_back( (*param)->get_type()->clone() );
 			}
 		}
@@ -66,7 +64,7 @@
 
 		bool operator== (const ConcreteType& that) const {
+			if ( base != that.base ) return false;
+
 			SymTab::Indexer dummy;
-
-			if ( base != that.base ) return false;
 			if ( params.size() != that.params.size() ) return false;
 			for ( std::list< Type* >::const_iterator it = params.begin(), jt = that.params.begin(); it != params.end(); ++it, ++jt ) {
@@ -79,9 +77,15 @@
 		std::list< Type* > params;  ///< Instantiation parameters
 	};
-
+	
 	/// Maps a concrete type to the instantiated struct type, accounting for scope
 	class InstantiationMap {
-		/// Pair of concrete type and declaration that instantiates it
-		typedef std::pair< ConcreteType, AggregateDecl* > Instantiation;
+		/// Instantiation of a generic type, with key information to find it
+		struct Instantiation {
+			ConcreteType key;     ///< Instantiation parameters for this type
+			AggregateDecl *decl;  ///< Declaration of the instantiated generic type
+
+			Instantiation() : key(), decl(0) {}
+			Instantiation(const ConcreteType &_key, AggregateDecl *_decl) : key(_key), decl(_decl) {}
+		};
 		/// Map of generic types to instantiations of them
 		typedef std::map< AggregateDecl*, std::vector< Instantiation > > Scope;
@@ -107,5 +111,5 @@
 		/// Gets the declaration for the concrete instantiation of this type, assuming it has already been instantiated in the current scope.
 		/// Returns NULL on none such.
-		AggregateDecl* lookup( AggregateDecl *generic, std::list< Expression* >& params ) {
+		AggregateDecl* lookup( AggregateDecl *generic, const std::list< TypeExpr* >& params ) {
 			ConcreteType key(generic, params);
 			// scan scopes from innermost out
@@ -116,5 +120,5 @@
 				// look through instantiations for matches to concrete type
 				for ( std::vector< Instantiation >::const_iterator inst = insts->second.begin(); inst != insts->second.end(); ++inst ) {
-					if ( inst->first == key ) return inst->second;
+					if ( inst->key == key ) return inst->decl;
 				}
 			}
@@ -123,81 +127,94 @@
 		}
 	public:
-		StructDecl* lookup( StructInstType *inst ) { return (StructDecl*)lookup( inst->get_baseStruct(), inst->get_parameters() ); }
-		UnionDecl* lookup( UnionInstType *inst ) { return (UnionDecl*)lookup( inst->get_baseUnion(), inst->get_parameters() ); }
+		StructDecl* lookup( StructInstType *inst, const std::list< TypeExpr* > &typeSubs ) { return (StructDecl*)lookup( inst->get_baseStruct(), typeSubs ); }
+		UnionDecl* lookup( UnionInstType *inst, const std::list< TypeExpr* > &typeSubs ) { return (UnionDecl*)lookup( inst->get_baseUnion(), typeSubs ); }
 
 	private:
 		/// Adds a declaration for a concrete type to the current scope
-		void insert( AggregateDecl *generic, std::list< Expression* >& params, AggregateDecl *decl ) {
+		void insert( AggregateDecl *generic, const std::list< TypeExpr* > &params, AggregateDecl *decl ) {
 			ConcreteType key(generic, params);
-			scopes.back()[generic].push_back( std::make_pair( key, decl ) );
+			scopes.back()[generic].push_back( Instantiation( key, decl ) );
 		}
 	public:
-		void insert( StructInstType *inst, StructDecl *decl ) { insert( inst->get_baseStruct(), inst->get_parameters(), decl ); }
-		void insert( UnionInstType *inst, UnionDecl *decl ) { insert( inst->get_baseUnion(), inst->get_parameters(), decl ); }
+		void insert( StructInstType *inst, const std::list< TypeExpr* > &typeSubs, StructDecl *decl ) { insert( inst->get_baseStruct(), typeSubs, decl ); }
+		void insert( UnionInstType *inst, const std::list< TypeExpr* > &typeSubs, UnionDecl *decl ) { insert( inst->get_baseUnion(), typeSubs, decl ); }
 	};
 
 	/// Mutator pass that replaces concrete instantiations of generic types with actual struct declarations, scoped appropriately
-	class Instantiate : public PolyMutator {
+	class Instantiate : public DeclMutator {
+		/// Map of (generic type, parameter list) pairs to concrete type instantiations
 		InstantiationMap instantiations;
+		/// Namer for concrete types
 		UniqueName typeNamer;
 
 	public:
-		Instantiate() : instantiations(), typeNamer("_conc_") {}
-
-		/// Mutates the whole translation unit, inserting new struct declarations as appropriate
-		void mutateAll( std::list< Declaration* >& translationUnit );
-		
+		Instantiate() : DeclMutator(), instantiations(), typeNamer("_conc_") {}
+
 		virtual Type* mutate( StructInstType *inst );
 		virtual Type* mutate( UnionInstType *inst );
+
+// 		virtual Expression* mutate( MemberExpr *memberExpr );
 		
 		virtual void doBeginScope();
 		virtual void doEndScope();
-
-	private:
-		/// Adds a declaration to the current environment and the statements to add
-		void addDeclaration( AggregateDecl *decl ) {
-			std::list< Label > nolabels;
-			DeclStmt *stmt = new DeclStmt( nolabels, decl );
-			PolyMutator::stmtsToAdd.push_back( stmt );
-		}
 	};
 	
 	void instantiateGeneric( std::list< Declaration* >& translationUnit ) {
 		Instantiate instantiator;
-//		mutateAll( translationUnit, instantiator );
-		instantiator.mutateAll( translationUnit );
-	}
-
-	void Instantiate::mutateAll( std::list< Declaration* >& translationUnit ) {
-		// below copied and modified from Mutator.h:mutateAll()
-		SemanticError errors;
-		for ( std::list< Declaration* >::iterator decl = translationUnit.begin(); decl != translationUnit.end(); ++decl ) {
-			try {
-				if ( *decl ) {
-					*decl = dynamic_cast< Declaration* >( (*decl)->acceptMutator( *this ) );
-					assert( *decl );
-					// account for missing top-level declarations
-					for ( std::list< Statement* >::const_iterator stmt = PolyMutator::stmtsToAdd.begin(); stmt != PolyMutator::stmtsToAdd.end(); ++stmt ) {
-						DeclStmt *declStmt = dynamic_cast< DeclStmt* >( *stmt );
-						assert( declStmt );
-						translationUnit.insert( decl, declStmt->get_decl() );
-					}
-					PolyMutator::stmtsToAdd.clear();
-				} // if
-			} catch( SemanticError &e ) {
-				errors.append( e );
-			} // try
-		} // for
-		if ( ! errors.isEmpty() ) {
-			throw errors;
-		} // if
-	}
-
-	/// Substitutes types of members of in according to baseParams => params, appending the result to out
-	void substituteMembers( const std::list< Declaration* >& in,
-							const std::list< TypeDecl * >& baseParams, const std::list< Expression* >& params,
+		instantiator.mutateDeclarationList( translationUnit );
+	}
+
+	/// Makes substitutions of params into baseParams; returns true if all parameters substituted for a concrete type
+	bool makeSubstitutions( const std::list< TypeDecl* >& baseParams, const std::list< Expression* >& params, std::list< TypeExpr* >& out ) {
+ 		bool allConcrete = true;  // will finish the substitution list even if they're not all concrete
+
+		// substitute concrete types for given parameters, and incomplete types for placeholders
+		std::list< TypeDecl* >::const_iterator baseParam = baseParams.begin();
+		std::list< Expression* >::const_iterator param = params.begin();
+		for ( ; baseParam != baseParams.end() && param != params.end(); ++baseParam, ++param ) {
+// 			switch ( (*baseParam)->get_kind() ) {
+// 			case TypeDecl::Any: {   // any type is a valid substitution here; complete types can be used to instantiate generics
+				TypeExpr *paramType = dynamic_cast< TypeExpr* >( *param );
+				assert(paramType && "Aggregate parameters should be type expressions");
+				out.push_back( paramType->clone() );
+				// check that the substituted type isn't a type variable itself
+				if ( dynamic_cast< TypeInstType* >( paramType->get_type() ) ) {
+ 					allConcrete = false;
+				}
+// 				break;
+// 			}
+// 			case TypeDecl::Dtype:  // dtype can be consistently replaced with void [only pointers, which become void*]
+// 				out.push_back( new TypeExpr( new VoidType( Type::Qualifiers() ) ) );
+// 				break;
+// 			case TypeDecl::Ftype:  // pointer-to-ftype can be consistently replaced with void (*)(void) [similar to dtype]
+// 				out.push_back( new TypeExpr( new FunctionType( Type::Qualifiers(), false ) ) );
+// 				break;
+// 			}
+		}
+
+		// if any parameters left over, not done
+		if ( baseParam != baseParams.end() ) return false;
+// 		// if not enough parameters given, substitute remaining incomplete types for placeholders
+// 		for ( ; baseParam != baseParams.end(); ++baseParam ) {
+// 			switch ( (*baseParam)->get_kind() ) {
+// 			case TypeDecl::Any:    // no more substitutions here, fail early
+// 				return false;
+// 			case TypeDecl::Dtype:  // dtype can be consistently replaced with void [only pointers, which become void*]
+// 				out.push_back( new TypeExpr( new VoidType( Type::Qualifiers() ) ) );
+// 				break;
+// 			case TypeDecl::Ftype:  // pointer-to-ftype can be consistently replaced with void (*)(void) [similar to dtype]
+// 				out.push_back( new TypeExpr( new FunctionType( Type::Qualifiers(), false ) ) );
+// 				break;
+// 			}
+// 		}
+
+ 		return allConcrete;
+	}
+
+	/// Substitutes types of members of in according to baseParams => typeSubs, appending the result to out
+	void substituteMembers( const std::list< Declaration* >& in, const std::list< TypeDecl* >& baseParams, const std::list< TypeExpr* >& typeSubs, 
 						    std::list< Declaration* >& out ) {
 		// substitute types into new members
-		TypeSubstitution subs( baseParams.begin(), baseParams.end(), params.begin() );
+		TypeSubstitution subs( baseParams.begin(), baseParams.end(), typeSubs.begin() );
 		for ( std::list< Declaration* >::const_iterator member = in.begin(); member != in.end(); ++member ) {
 			Declaration *newMember = (*member)->clone();
@@ -215,19 +232,26 @@
 		// exit early if no need for further mutation
 		if ( inst->get_parameters().empty() ) return inst;
+		assert( inst->get_baseParameters() && "Base struct has parameters" );
+
+		// check if type can be concretely instantiated; put substitutions into typeSubs
+		std::list< TypeExpr* > typeSubs;
+		if ( ! makeSubstitutions( *inst->get_baseParameters(), inst->get_parameters(), typeSubs ) ) {
+			deleteAll( typeSubs );
+			return inst;
+		}
 		
 		// make concrete instantiation of generic type
-		StructDecl *concDecl = instantiations.lookup( inst );
+		StructDecl *concDecl = instantiations.lookup( inst, typeSubs );
 		if ( ! concDecl ) {
-			assert( inst->get_baseParameters() && "Base struct has parameters" );
 			// set concDecl to new type, insert type declaration into statements to add
 			concDecl = new StructDecl( typeNamer.newName( inst->get_name() ) );
-			substituteMembers( inst->get_baseStruct()->get_members(),
-								*inst->get_baseParameters(), inst->get_parameters(),
-								concDecl->get_members() );
-			addDeclaration( concDecl );
-			instantiations.insert( inst, concDecl );
+			substituteMembers( inst->get_baseStruct()->get_members(), *inst->get_baseParameters(), typeSubs, 	concDecl->get_members() );
+			DeclMutator::addDeclaration( concDecl );
+			instantiations.insert( inst, typeSubs, concDecl );
 		}
 		StructInstType *newInst = new StructInstType( inst->get_qualifiers(), concDecl->get_name() );
 		newInst->set_baseStruct( concDecl );
+
+		deleteAll( typeSubs );
 		delete inst;
 		return newInst;
@@ -242,30 +266,87 @@
 		// exit early if no need for further mutation
 		if ( inst->get_parameters().empty() ) return inst;
-
+		assert( inst->get_baseParameters() && "Base union has parameters" );
+
+		// check if type can be concretely instantiated; put substitutions into typeSubs
+		std::list< TypeExpr* > typeSubs;
+		if ( ! makeSubstitutions( *inst->get_baseParameters(), inst->get_parameters(), typeSubs ) ) {
+			deleteAll( typeSubs );
+			return inst;
+		}
+		
 		// make concrete instantiation of generic type
-		UnionDecl *concDecl = instantiations.lookup( inst );
+		UnionDecl *concDecl = instantiations.lookup( inst, typeSubs );
 		if ( ! concDecl ) {
 			// set concDecl to new type, insert type declaration into statements to add
-			assert( inst->get_baseParameters() && "Base union has parameters" );
 			concDecl = new UnionDecl( typeNamer.newName( inst->get_name() ) );
-			substituteMembers( inst->get_baseUnion()->get_members(),
-								*inst->get_baseParameters(), inst->get_parameters(),
-								concDecl->get_members() );
-			addDeclaration( concDecl );
-			instantiations.insert( inst, concDecl );
+			substituteMembers( inst->get_baseUnion()->get_members(), *inst->get_baseParameters(), typeSubs, concDecl->get_members() );
+			DeclMutator::addDeclaration( concDecl );
+			instantiations.insert( inst, typeSubs, concDecl );
 		}
 		UnionInstType *newInst = new UnionInstType( inst->get_qualifiers(), concDecl->get_name() );
 		newInst->set_baseUnion( concDecl );
+
+		deleteAll( typeSubs );
 		delete inst;
 		return newInst;
 	}
+
+// 	/// Gets the base struct or union declaration for a member expression; NULL if not applicable
+// 	AggregateDecl* getMemberBaseDecl( MemberExpr *memberExpr ) {
+// 		// get variable for member aggregate
+// 		VariableExpr *varExpr = dynamic_cast< VariableExpr* >( memberExpr->get_aggregate() );
+// 		if ( ! varExpr ) return NULL;
+// 
+// 		// get object for variable
+// 		ObjectDecl *objectDecl = dynamic_cast< ObjectDecl* >( varExpr->get_var() );
+// 		if ( ! objectDecl ) return NULL;
+// 
+// 		// get base declaration from object type
+// 		Type *objectType = objectDecl->get_type();
+// 		StructInstType *structType = dynamic_cast< StructInstType* >( objectType );
+// 		if ( structType ) return structType->get_baseStruct();
+// 		UnionInstType *unionType = dynamic_cast< UnionInstType* >( objectType );
+// 		if ( unionType ) return unionType->get_baseUnion();
+// 
+// 		return NULL;
+// 	}
+// 
+// 	/// Finds the declaration with the given name, returning decls.end() if none such
+// 	std::list< Declaration* >::const_iterator findDeclNamed( const std::list< Declaration* > &decls, const std::string &name ) {
+// 		for( std::list< Declaration* >::const_iterator decl = decls.begin(); decl != decls.end(); ++decl ) {
+// 			if ( (*decl)->get_name() == name ) return decl;
+// 		}
+// 		return decls.end();
+// 	}
+// 	
+// 	Expression* Instantiate::mutate( MemberExpr *memberExpr ) {
+// 		// mutate, exiting early if no longer MemberExpr
+// 		Expression *expr = Mutator::mutate( memberExpr );
+// 		memberExpr = dynamic_cast< MemberExpr* >( expr );
+// 		if ( ! memberExpr ) return expr;
+// 
+// 		// get declaration of member and base declaration of member, exiting early if not found
+// 		AggregateDecl *memberBase = getMemberBaseDecl( memberExpr );
+// 		if ( ! memberBase ) return memberExpr;
+// 		DeclarationWithType *memberDecl = memberExpr->get_member();
+// 		std::list< Declaration* >::const_iterator baseIt = findDeclNamed( memberBase->get_members(), memberDecl->get_name() );
+// 		if ( baseIt == memberBase->get_members().end() ) return memberExpr;
+// 		DeclarationWithType *baseDecl = dynamic_cast< DeclarationWithType* >( *baseIt );
+// 		if ( ! baseDecl ) return memberExpr;
+// 
+// 		// check if stated type of the member is not the type of the member's declaration; if so, need a cast
+// 		// this *SHOULD* be safe, I don't think anything but the void-replacements I put in for dtypes would make it past the typechecker
+// 		SymTab::Indexer dummy;
+// 		if ( ResolvExpr::typesCompatible( memberDecl->get_type(), baseDecl->get_type(), dummy ) ) return memberExpr;
+// 		else return new CastExpr( memberExpr, memberDecl->get_type() );
+// 	}
 	
 	void Instantiate::doBeginScope() {
-		// push a new concrete type scope
+		DeclMutator::doBeginScope();
 		instantiations.beginScope();
 	}
 
 	void Instantiate::doEndScope() {
-		// pop the last concrete type scope
+		DeclMutator::doEndScope();
 		instantiations.endScope();
 	}
Index: src/GenPoly/Lvalue.cc
===================================================================
--- src/GenPoly/Lvalue.cc	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/GenPoly/Lvalue.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -10,6 +10,6 @@
 // Created On       : Mon May 18 07:44:20 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Tue May 19 07:41:33 2015
-// Update Count     : 1
+// Last Modified On : Tue Dec 15 15:33:13 2015
+// Update Count     : 3
 //
 
@@ -35,4 +35,5 @@
 		const std::list<Label> noLabels;
 
+		/// Replace uses of lvalue returns with appropriate pointers
 		class Pass1 : public Mutator {
 		  public:
@@ -46,4 +47,5 @@
 		};
 
+		/// Replace declarations of lvalue returns with appropriate pointers
 		class Pass2 : public Visitor {
 		  public:
@@ -120,12 +122,15 @@
 			if ( retval && retStmt->get_expr() ) {
 				assert( ! retStmt->get_expr()->get_results().empty() );
-				while ( CastExpr *castExpr = dynamic_cast< CastExpr* >( retStmt->get_expr() ) ) {
-					retStmt->set_expr( castExpr->get_arg() );
-					retStmt->get_expr()->set_env( castExpr->get_env() );
-					castExpr->set_env( 0 );
-					castExpr->set_arg( 0 );
-					delete castExpr;
-				} // while
 				if ( retStmt->get_expr()->get_results().front()->get_isLvalue() ) {
+					// ***** Code Removal ***** because casts may be stripped already
+
+					// strip casts because not allowed to take address of cast
+					// while ( CastExpr *castExpr = dynamic_cast< CastExpr* >( retStmt->get_expr() ) ) {
+					// 	retStmt->set_expr( castExpr->get_arg() );
+					// 	retStmt->get_expr()->set_env( castExpr->get_env() );
+					// 	castExpr->set_env( 0 );
+					// 	castExpr->set_arg( 0 );
+					// 	delete castExpr;
+					// } // while
 					retStmt->set_expr( new AddressExpr( retStmt->get_expr()->acceptMutator( *this ) ) );
 				} else {
Index: src/GenPoly/PolyMutator.h
===================================================================
--- src/GenPoly/PolyMutator.h	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/GenPoly/PolyMutator.h	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -10,6 +10,6 @@
 // Created On       : Mon May 18 07:44:20 2015
 // Last Modified By : Rob Schluntz
-// Last Modified On : Fri Aug 14 15:27:38 2015
-// Update Count     : 4
+// Last Modified On : Tue Dec 08 15:19:05 2015
+// Update Count     : 5
 //
 
@@ -51,9 +51,10 @@
 		virtual void doBeginScope() {}
 		virtual void doEndScope() {}
+		
+		static void makeTyVarMap( Type *type, TyVarMap &tyVarMap );
 	  protected:
 		void mutateStatementList( std::list< Statement* > &statements );
 		Statement* mutateStatement( Statement *stmt );
 		Expression* mutateExpression( Expression *expr );
-		static void makeTyVarMap( Type *type, TyVarMap &tyVarMap );
   
 		TyVarMap scopeTyVars;
Index: src/GenPoly/ScrubTyVars.cc
===================================================================
--- src/GenPoly/ScrubTyVars.cc	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/GenPoly/ScrubTyVars.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -13,4 +13,7 @@
 // Update Count     : 2
 //
+
+#include <sstream>
+#include <string>
 
 #include "GenPoly.h"
@@ -42,10 +45,20 @@
 
 	Expression * ScrubTyVars::mutate( SizeofExpr *szeof ) {
-		// sizeof( T ) => T parameter, which is the size of T
-		if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( szeof->get_type() ) ) {
-			Expression *expr = new NameExpr( typeInst->get_name() );
+		// sizeof( T ) => _sizeof_T parameter, which is the size of T
+		if ( Type *polyType = isPolyType( szeof->get_type() ) ) {
+			Expression *expr = new NameExpr( sizeofName( polyType ) );
 			return expr;
 		} else {
 			return Mutator::mutate( szeof );
+		} // if
+	}
+
+	Expression * ScrubTyVars::mutate( AlignofExpr *algnof ) {
+		// alignof( T ) => _alignof_T parameter, which is the alignment of T
+		if ( Type *polyType = isPolyType( algnof->get_type() ) ) {
+			Expression *expr = new NameExpr( alignofName( polyType ) );
+			return expr;
+		} else {
+			return Mutator::mutate( algnof );
 		} // if
 	}
Index: src/GenPoly/ScrubTyVars.h
===================================================================
--- src/GenPoly/ScrubTyVars.h	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/GenPoly/ScrubTyVars.h	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -17,4 +17,6 @@
 #define _SCRUBTYVARS_H
 
+#include <string>
+
 #include "GenPoly.h"
 
@@ -26,7 +28,9 @@
 	  public:
 		ScrubTyVars( bool doAll, const TyVarMap &tyVars ): doAll( doAll ), tyVars( tyVars ) {}
-  
+
+		/// Like scrub( SynTreeClass* ), but only applies to type variables in `tyVars`
 		template< typename SynTreeClass >
 		static SynTreeClass *scrub( SynTreeClass *target, const TyVarMap &tyVars );
+		/// Replaces dtypes and ftypes with the appropriate void type, and sizeof expressions of polymorphic types with the proper variable
 		template< typename SynTreeClass >
 		static SynTreeClass *scrub( SynTreeClass *target );
@@ -34,4 +38,5 @@
 		virtual Type* mutate( TypeInstType *typeInst );
 		Expression* mutate( SizeofExpr *szeof );
+		Expression* mutate( AlignofExpr *algnof );
 		virtual Type* mutate( PointerType *pointer );
 	  private:
Index: src/GenPoly/Specialize.cc
===================================================================
--- src/GenPoly/Specialize.cc	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/GenPoly/Specialize.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -17,4 +17,5 @@
 
 #include "Specialize.h"
+#include "GenPoly.h"
 #include "PolyMutator.h"
 
@@ -87,14 +88,4 @@
 	}
 
-	/// Returns a pointer to the base FunctionType if ty is the type of a function (or pointer to one), NULL otherwise
-	FunctionType * getFunctionType( Type *ty ) {
-		PointerType *ptrType;
-		if ( ( ptrType = dynamic_cast< PointerType* >( ty ) ) ) {
-			return dynamic_cast< FunctionType* >( ptrType->get_base() ); // pointer if FunctionType, NULL otherwise
-		} else {
-			return dynamic_cast< FunctionType* >( ty ); // pointer if FunctionType, NULL otherwise
-		}
-	}
-
 	/// Generates a thunk that calls `actual` with type `funType` and returns its address
 	Expression * Specialize::createThunkFunction( FunctionType *funType, Expression *actual, InferredParams *inferParams ) {
Index: src/GenPoly/module.mk
===================================================================
--- src/GenPoly/module.mk	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/GenPoly/module.mk	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -23,3 +23,4 @@
        GenPoly/CopyParams.cc \
        GenPoly/FindFunction.cc \
-       GenPoly/InstantiateGeneric.cc
+       GenPoly/InstantiateGeneric.cc \
+       GenPoly/DeclMutator.cc
Index: src/InitTweak/InitModel.h
===================================================================
--- src/InitTweak/InitModel.h	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/InitTweak/InitModel.h	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -72,4 +72,5 @@
 			void visit( ConstantExpr * );
 			void visit( SizeofExpr * ) { throw 0; }
+			void visit( AlignofExpr * ) { throw 0; }
 			void visit( AttrExpr * ) { throw 0; }
 			void visit( LogicalExpr * ) { throw 0; }
Index: src/InitTweak/RemoveInit.cc
===================================================================
--- src/InitTweak/RemoveInit.cc	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/InitTweak/RemoveInit.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -7,9 +7,9 @@
 // RemoveInit.cc -- 
 //
-// Author           : Rodolfo G. Esteves
+// Author           : Rob Schluntz
 // Created On       : Mon May 18 07:44:20 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Tue May 19 16:39:32 2015
-// Update Count     : 1
+// Last Modified On : Tue Dec 15 15:37:26 2015
+// Update Count     : 15
 //
 
@@ -26,4 +26,24 @@
 		const std::list<Label> noLabels;
 	}
+	
+	class RemoveInit : public Mutator {
+	  public:
+		RemoveInit();
+		virtual ObjectDecl * mutate(ObjectDecl *objDecl);
+		virtual DeclarationWithType * mutate( FunctionDecl *functionDecl );
+
+		virtual Statement * mutate( ReturnStmt * returnStmt );
+		
+		virtual CompoundStmt * mutate(CompoundStmt * compoundStmt);
+		
+	  protected:
+		std::list< Statement* > stmtsToAddBefore;
+		std::list< Statement* > stmtsToAddAfter;
+		void mutateStatementList( std::list< Statement* > &statements );
+
+		std::list<DeclarationWithType*> returnVals;
+		UniqueName tempNamer;
+		std::string funcName;
+	};
 
 	void tweak( std::list< Declaration * > translationUnit ) {
@@ -32,4 +52,6 @@
 	}
 
+	RemoveInit::RemoveInit() : tempNamer( "_retVal" ) {}
+	
 	void RemoveInit::mutateStatementList( std::list< Statement* > &statements ) {
 		for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
@@ -38,4 +60,7 @@
 			} // if
 			*i = (*i)->acceptMutator( *this );
+			if ( ! stmtsToAddBefore.empty() ) {
+				statements.splice( i, stmtsToAddBefore );
+			} // if
 		} // for
 		if ( ! stmtsToAddAfter.empty() ) {
@@ -49,7 +74,6 @@
 	}
 
-// in the case where an object has an initializer and a polymorphic type, insert an assignment
-// immediately after the declaration. This will (seemingly) cause the later phases to do the right
-// thing with the assignment
+	// in the case where an object has an initializer and a polymorphic type, insert an assignment immediately after the
+	// declaration. This will (seemingly) cause the later phases to do the right thing with the assignment
 	ObjectDecl *RemoveInit::mutate( ObjectDecl *objDecl ) {
 		if (objDecl->get_init() && dynamic_cast<TypeInstType*>(objDecl->get_type())) {
@@ -63,4 +87,36 @@
 		return objDecl;
 	}
+
+	Statement *RemoveInit::mutate( ReturnStmt *returnStmt ) {
+		// update for multiple return values
+		assert( returnVals.size() == 0 || returnVals.size() == 1 );
+		// hands off if the function returns an lvalue - we don't want to allocate a temporary if a variable's address
+		// is being returned
+		if ( returnStmt->get_expr() && returnVals.size() == 1 && funcName != "?=?" && ! returnVals.front()->get_type()->get_isLvalue()  ) {
+			ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, returnVals.front()->get_type()->clone(), 0 );
+			stmtsToAddBefore.push_back( new DeclStmt( noLabels, newObj ) );
+			
+			UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) );
+			assign->get_args().push_back( new AddressExpr (new NameExpr( newObj->get_name() ) ) );
+			assign->get_args().push_back( returnStmt->get_expr() );
+			stmtsToAddBefore.push_back(new ExprStmt(noLabels, assign));
+
+			returnStmt->set_expr( new VariableExpr( newObj ) );
+		} // if
+		return returnStmt;
+	}
+
+	DeclarationWithType* RemoveInit::mutate( FunctionDecl *functionDecl ) {
+		std::list<DeclarationWithType*> oldReturnVals = returnVals;
+		std::string oldFuncName = funcName;
+		
+		FunctionType * type = functionDecl->get_functionType();
+		returnVals = type->get_returnVals();
+		funcName = functionDecl->get_name();
+		DeclarationWithType * decl = Mutator::mutate( functionDecl );
+		returnVals = oldReturnVals;
+		funcName = oldFuncName;
+		return decl;
+	}
 } // namespace InitTweak
 
Index: src/InitTweak/RemoveInit.h
===================================================================
--- src/InitTweak/RemoveInit.h	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/InitTweak/RemoveInit.h	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -10,6 +10,6 @@
 // Created On       : Mon May 18 07:44:20 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Tue May 19 16:40:11 2015
-// Update Count     : 1
+// Last Modified On : Fri Nov 27 17:00:47 2015
+// Update Count     : 2
 //
 
@@ -27,14 +27,4 @@
 	/// Adds assignment statements for polymorphic type initializers
 	void tweak( std::list< Declaration * > translationUnit );
-
-	class RemoveInit : public Mutator {
-	  public:
-		// RemoveInit();
-		virtual ObjectDecl *mutate(ObjectDecl *objDecl);
-		virtual CompoundStmt *mutate(CompoundStmt *compoundStmt);
-	  protected:
-		std::list< Statement* > stmtsToAddAfter;
-		void mutateStatementList( std::list< Statement* > &statements );
-	};
 } // namespace 
 
Index: src/Makefile.in
===================================================================
--- src/Makefile.in	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/Makefile.in	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -122,4 +122,5 @@
 	GenPoly/cfa_cpp-FindFunction.$(OBJEXT) \
 	GenPoly/cfa_cpp-InstantiateGeneric.$(OBJEXT) \
+	GenPoly/cfa_cpp-DeclMutator.$(OBJEXT) \
 	InitTweak/cfa_cpp-InitModel.$(OBJEXT) \
 	InitTweak/cfa_cpp-InitExpander.$(OBJEXT) \
@@ -348,12 +349,13 @@
 	GenPoly/ScrubTyVars.cc GenPoly/Lvalue.cc GenPoly/Specialize.cc \
 	GenPoly/CopyParams.cc GenPoly/FindFunction.cc \
-	GenPoly/InstantiateGeneric.cc InitTweak/InitModel.cc \
-	InitTweak/InitExpander.cc InitTweak/Mutate.cc \
-	InitTweak/Association.cc InitTweak/RemoveInit.cc \
-	Parser/parser.yy Parser/lex.ll Parser/TypedefTable.cc \
-	Parser/ParseNode.cc Parser/DeclarationNode.cc \
-	Parser/ExpressionNode.cc Parser/StatementNode.cc \
-	Parser/InitializerNode.cc Parser/TypeData.cc \
-	Parser/LinkageSpec.cc Parser/parseutility.cc Parser/Parser.cc \
+	GenPoly/InstantiateGeneric.cc GenPoly/DeclMutator.cc \
+	InitTweak/InitModel.cc InitTweak/InitExpander.cc \
+	InitTweak/Mutate.cc InitTweak/Association.cc \
+	InitTweak/RemoveInit.cc Parser/parser.yy Parser/lex.ll \
+	Parser/TypedefTable.cc Parser/ParseNode.cc \
+	Parser/DeclarationNode.cc Parser/ExpressionNode.cc \
+	Parser/StatementNode.cc Parser/InitializerNode.cc \
+	Parser/TypeData.cc Parser/LinkageSpec.cc \
+	Parser/parseutility.cc Parser/Parser.cc \
 	ResolvExpr/AlternativeFinder.cc ResolvExpr/Alternative.cc \
 	ResolvExpr/Unify.cc ResolvExpr/PtrsAssignable.cc \
@@ -411,7 +413,7 @@
 	  esac; \
 	done; \
-	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/Makefile'; \
 	$(am__cd) $(top_srcdir) && \
-	  $(AUTOMAKE) --gnu src/Makefile
+	  $(AUTOMAKE) --foreign src/Makefile
 .PRECIOUS: Makefile
 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@@ -556,4 +558,6 @@
 	GenPoly/$(DEPDIR)/$(am__dirstamp)
 GenPoly/cfa_cpp-InstantiateGeneric.$(OBJEXT): GenPoly/$(am__dirstamp) \
+	GenPoly/$(DEPDIR)/$(am__dirstamp)
+GenPoly/cfa_cpp-DeclMutator.$(OBJEXT): GenPoly/$(am__dirstamp) \
 	GenPoly/$(DEPDIR)/$(am__dirstamp)
 InitTweak/$(am__dirstamp):
@@ -785,4 +789,5 @@
 	-rm -f GenPoly/cfa_cpp-Box.$(OBJEXT)
 	-rm -f GenPoly/cfa_cpp-CopyParams.$(OBJEXT)
+	-rm -f GenPoly/cfa_cpp-DeclMutator.$(OBJEXT)
 	-rm -f GenPoly/cfa_cpp-FindFunction.$(OBJEXT)
 	-rm -f GenPoly/cfa_cpp-GenPoly.$(OBJEXT)
@@ -895,4 +900,5 @@
 @AMDEP_TRUE@@am__include@ @am__quote@GenPoly/$(DEPDIR)/cfa_cpp-Box.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@GenPoly/$(DEPDIR)/cfa_cpp-CopyParams.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@GenPoly/$(DEPDIR)/cfa_cpp-DeclMutator.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@GenPoly/$(DEPDIR)/cfa_cpp-FindFunction.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@GenPoly/$(DEPDIR)/cfa_cpp-GenPoly.Po@am__quote@
@@ -1376,4 +1382,18 @@
 @am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o GenPoly/cfa_cpp-InstantiateGeneric.obj `if test -f 'GenPoly/InstantiateGeneric.cc'; then $(CYGPATH_W) 'GenPoly/InstantiateGeneric.cc'; else $(CYGPATH_W) '$(srcdir)/GenPoly/InstantiateGeneric.cc'; fi`
 
+GenPoly/cfa_cpp-DeclMutator.o: GenPoly/DeclMutator.cc
+@am__fastdepCXX_TRUE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT GenPoly/cfa_cpp-DeclMutator.o -MD -MP -MF GenPoly/$(DEPDIR)/cfa_cpp-DeclMutator.Tpo -c -o GenPoly/cfa_cpp-DeclMutator.o `test -f 'GenPoly/DeclMutator.cc' || echo '$(srcdir)/'`GenPoly/DeclMutator.cc
+@am__fastdepCXX_TRUE@	$(am__mv) GenPoly/$(DEPDIR)/cfa_cpp-DeclMutator.Tpo GenPoly/$(DEPDIR)/cfa_cpp-DeclMutator.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='GenPoly/DeclMutator.cc' object='GenPoly/cfa_cpp-DeclMutator.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o GenPoly/cfa_cpp-DeclMutator.o `test -f 'GenPoly/DeclMutator.cc' || echo '$(srcdir)/'`GenPoly/DeclMutator.cc
+
+GenPoly/cfa_cpp-DeclMutator.obj: GenPoly/DeclMutator.cc
+@am__fastdepCXX_TRUE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT GenPoly/cfa_cpp-DeclMutator.obj -MD -MP -MF GenPoly/$(DEPDIR)/cfa_cpp-DeclMutator.Tpo -c -o GenPoly/cfa_cpp-DeclMutator.obj `if test -f 'GenPoly/DeclMutator.cc'; then $(CYGPATH_W) 'GenPoly/DeclMutator.cc'; else $(CYGPATH_W) '$(srcdir)/GenPoly/DeclMutator.cc'; fi`
+@am__fastdepCXX_TRUE@	$(am__mv) GenPoly/$(DEPDIR)/cfa_cpp-DeclMutator.Tpo GenPoly/$(DEPDIR)/cfa_cpp-DeclMutator.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='GenPoly/DeclMutator.cc' object='GenPoly/cfa_cpp-DeclMutator.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o GenPoly/cfa_cpp-DeclMutator.obj `if test -f 'GenPoly/DeclMutator.cc'; then $(CYGPATH_W) 'GenPoly/DeclMutator.cc'; else $(CYGPATH_W) '$(srcdir)/GenPoly/DeclMutator.cc'; fi`
+
 InitTweak/cfa_cpp-InitModel.o: InitTweak/InitModel.cc
 @am__fastdepCXX_TRUE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT InitTweak/cfa_cpp-InitModel.o -MD -MP -MF InitTweak/$(DEPDIR)/cfa_cpp-InitModel.Tpo -c -o InitTweak/cfa_cpp-InitModel.o `test -f 'InitTweak/InitModel.cc' || echo '$(srcdir)/'`InitTweak/InitModel.cc
Index: src/Parser/ExpressionNode.cc
===================================================================
--- src/Parser/ExpressionNode.cc	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/Parser/ExpressionNode.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -586,8 +586,13 @@
 		}
 	  case OperatorNode::AlignOf:
+		{
+			if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()) ) {
+				return new AlignofExpr( arg->get_decl()->buildType());
+			} else {
+				return new AlignofExpr( args.front());
+			} // if
+		}
 	  case OperatorNode::SizeOf:
 		{
-/// 	bool isSizeOf = ( op->get_type() == OperatorNode::SizeOf );
-
 			if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()) ) {
 				return new SizeofExpr( arg->get_decl()->buildType());
Index: src/ResolvExpr/AlternativeFinder.cc
===================================================================
--- src/ResolvExpr/AlternativeFinder.cc	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/ResolvExpr/AlternativeFinder.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -792,4 +792,23 @@
 	}
 
+	void AlternativeFinder::visit( AlignofExpr *alignofExpr ) {
+		if ( alignofExpr->get_isType() ) {
+			alternatives.push_back( Alternative( alignofExpr->clone(), env, Cost::zero ) );
+		} else {
+			// find all alternatives for the argument to sizeof
+			AlternativeFinder finder( indexer, env );
+			finder.find( alignofExpr->get_expr() );
+			// find the lowest cost alternative among the alternatives, otherwise ambiguous
+			AltList winners;
+			findMinCost( finder.alternatives.begin(), finder.alternatives.end(), back_inserter( winners ) );
+			if ( winners.size() != 1 ) {
+				throw SemanticError( "Ambiguous expression in alignof operand: ", alignofExpr->get_expr() );
+			} // if
+			// return the lowest cost alternative for the argument
+			Alternative &choice = winners.front();
+			alternatives.push_back( Alternative( new AlignofExpr( choice.expr->clone() ), choice.env, Cost::zero ) );
+		} // if
+	}
+
 	void AlternativeFinder::resolveAttr( DeclarationWithType *funcDecl, FunctionType *function, Type *argType, const TypeEnvironment &env ) {
 		// assume no polymorphism
Index: src/ResolvExpr/AlternativeFinder.h
===================================================================
--- src/ResolvExpr/AlternativeFinder.h	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/ResolvExpr/AlternativeFinder.h	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -56,4 +56,5 @@
 		virtual void visit( ConstantExpr *constantExpr ); 
 		virtual void visit( SizeofExpr *sizeofExpr );
+		virtual void visit( AlignofExpr *sizeofExpr );
 		virtual void visit( AttrExpr *attrExpr );
 		virtual void visit( LogicalExpr *logicalExpr );
Index: src/SymTab/Indexer.cc
===================================================================
--- src/SymTab/Indexer.cc	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/SymTab/Indexer.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -215,4 +215,13 @@
 		} else {
 			maybeAccept( sizeofExpr->get_expr(), *this );
+		}
+	}
+
+	void Indexer::visit( AlignofExpr *alignofExpr ) {
+		acceptAllNewScope( alignofExpr->get_results(), *this );
+		if ( alignofExpr->get_isType() ) {
+			maybeAccept( alignofExpr->get_type(), *this );
+		} else {
+			maybeAccept( alignofExpr->get_expr(), *this );
 		}
 	}
Index: src/SymTab/Indexer.h
===================================================================
--- src/SymTab/Indexer.h	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/SymTab/Indexer.h	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -54,4 +54,5 @@
 		virtual void visit( ConstantExpr *constantExpr ); 
 		virtual void visit( SizeofExpr *sizeofExpr );
+		virtual void visit( AlignofExpr *alignofExpr );
 		virtual void visit( AttrExpr *attrExpr );
 		virtual void visit( LogicalExpr *logicalExpr );
Index: src/SymTab/Mangler.cc
===================================================================
--- src/SymTab/Mangler.cc	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/SymTab/Mangler.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -30,11 +30,13 @@
 
 namespace SymTab {
-	Mangler::Mangler( bool mangleOverridable ) : nextVarNum( 0 ), isTopLevel( true ), mangleOverridable( mangleOverridable ) {
-	}
-
-//Mangler::Mangler( const Mangler & )
-//  : mangleName(), varNums( varNums ), nextVarNum( nextVarNum ), isTopLevel( isTopLevel )
-//{
-//}
+	std::string Mangler::mangleType( Type *ty ) {
+		Mangler mangler( false, true );
+		maybeAccept( ty, mangler );
+		return mangler.get_mangleName();
+	}
+	
+	Mangler::Mangler( bool mangleOverridable, bool typeMode )
+		: nextVarNum( 0 ), isTopLevel( true ), mangleOverridable( mangleOverridable ), typeMode( typeMode ) {}
+		
 	Mangler::Mangler( const Mangler &rhs ) : mangleName() {
 		varNums = rhs.varNums;
@@ -42,4 +44,5 @@
 		isTopLevel = rhs.isTopLevel;
 		mangleOverridable = rhs.mangleOverridable;
+		typeMode = rhs.typeMode;
 	}
 
@@ -152,13 +155,39 @@
 	void Mangler::mangleRef( ReferenceToType *refType, std::string prefix ) {
 		printQualifiers( refType );
+
 		mangleName << ( refType->get_name().length() + prefix.length() ) << prefix << refType->get_name();
 	}
 
+	void Mangler::mangleGenericRef( ReferenceToType *refType, std::string prefix ) {
+		printQualifiers( refType );
+
+		std::ostringstream oldName( mangleName.str() );
+		mangleName.clear();
+
+		mangleName << prefix << refType->get_name();
+
+		std::list< Expression* >& params = refType->get_parameters();
+		if ( ! params.empty() ) {
+			mangleName << "_";
+			for ( std::list< Expression* >::const_iterator param = params.begin(); param != params.end(); ++param ) {
+				TypeExpr *paramType = dynamic_cast< TypeExpr* >( *param );
+				assert(paramType && "Aggregate parameters should be type expressions");
+				maybeAccept( paramType->get_type(), *this );
+			}
+			mangleName << "_";
+		}
+
+		oldName << mangleName.str().length() << mangleName.str();
+		mangleName.str( oldName.str() );
+	}
+
 	void Mangler::visit( StructInstType *aggregateUseType ) {
-		mangleRef( aggregateUseType, "s" );
+		if ( typeMode ) mangleGenericRef( aggregateUseType, "s" );
+		else mangleRef( aggregateUseType, "s" );
 	}
 
 	void Mangler::visit( UnionInstType *aggregateUseType ) {
-		mangleRef( aggregateUseType, "u" );
+		if ( typeMode ) mangleGenericRef( aggregateUseType, "u" );
+		else mangleRef( aggregateUseType, "u" );
 	}
 
@@ -209,4 +238,7 @@
 
 	void Mangler::printQualifiers( Type *type ) {
+		// skip if not including qualifiers
+		if ( typeMode ) return;
+		
 		if ( ! type->get_forall().empty() ) {
 			std::list< std::string > assertionNames;
@@ -227,5 +259,5 @@
 				varNums[ (*i )->get_name() ] = std::pair< int, int >( nextVarNum++, (int )(*i )->get_kind() );
 				for ( std::list< DeclarationWithType* >::iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) {
-					Mangler sub_mangler( mangleOverridable );
+					Mangler sub_mangler( mangleOverridable, typeMode );
 					sub_mangler.nextVarNum = nextVarNum;
 					sub_mangler.isTopLevel = false;
Index: src/SymTab/Mangler.h
===================================================================
--- src/SymTab/Mangler.h	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/SymTab/Mangler.h	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -22,10 +22,13 @@
 
 namespace SymTab {
+	/// Mangles names to a unique C identifier
 	class Mangler : public Visitor {
 	  public:
+		/// Mangle syntax tree object; primary interface to clients
 		template< typename SynTreeClass >
-	    static std::string mangle( SynTreeClass *decl, bool mangleOverridable = true ); // interface to clients
+	    static std::string mangle( SynTreeClass *decl, bool mangleOverridable = true );
+		/// Mangle a type name; secondary interface
+		static std::string mangleType( Type* ty );
 
-///   using Visitor::visit;
 		virtual void visit( ObjectDecl *declaration );
 		virtual void visit( FunctionDecl *declaration );
@@ -45,16 +48,18 @@
 		std::string get_mangleName() { return mangleName.str(); }
 	  private:
-		std::ostringstream mangleName;
+		std::ostringstream mangleName;  ///< Mangled name being constructed
 		typedef std::map< std::string, std::pair< int, int > > VarMapType;
-		VarMapType varNums;
-		int nextVarNum;
-		bool isTopLevel;
-		bool mangleOverridable;
+		VarMapType varNums;             ///< Map of type variables to indices
+		int nextVarNum;                 ///< Next type variable index
+		bool isTopLevel;                ///< Is the Mangler at the top level
+		bool mangleOverridable;         ///< Specially mangle overridable built-in methods
+		bool typeMode;                  ///< Produce a unique mangled name for a type
   
-		Mangler( bool mangleOverridable );
+		Mangler( bool mangleOverridable, bool typeMode );
 		Mangler( const Mangler & );
   
 		void mangleDecl( DeclarationWithType *declaration );
 		void mangleRef( ReferenceToType *refType, std::string prefix );
+		void mangleGenericRef( ReferenceToType *refType, std::string prefix );
   
 		void printQualifiers( Type *type );
@@ -63,5 +68,5 @@
 	template< typename SynTreeClass >
 	std::string Mangler::mangle( SynTreeClass *decl, bool mangleOverridable ) {
-		Mangler mangler( mangleOverridable );
+		Mangler mangler( mangleOverridable, false );
 		maybeAccept( decl, mangler );
 		return mangler.get_mangleName();
Index: src/SymTab/Validate.cc
===================================================================
--- src/SymTab/Validate.cc	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/SymTab/Validate.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -10,6 +10,6 @@
 // Created On       : Sun May 17 21:50:04 2015
 // Last Modified By : Rob Schluntz
-// Last Modified On : Fri Dec 18 14:32:59 2015
-// Update Count     : 268
+// Last Modified On : Thu Jan 07 11:27:49 2016
+// Update Count     : 269
 //
 
@@ -86,5 +86,5 @@
 	};
 
-	/// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers
+	/// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers.
 	class Pass1 : public Visitor {
 		typedef Visitor Parent;
@@ -161,8 +161,22 @@
 	};
 
+	class ReturnChecker : public Visitor {
+	  public:
+		/// Checks that return statements return nothing if their return type is void
+		/// and return something if the return type is non-void.
+		static void checkFunctionReturns( std::list< Declaration * > & translationUnit );
+
+	  private:
+		virtual void visit( FunctionDecl * functionDecl );
+
+		virtual void visit( ReturnStmt * returnStmt );
+
+		std::list< DeclarationWithType * > returnVals;
+	};
+
 	class EliminateTypedef : public Mutator {
 	  public:
-	  EliminateTypedef() : scopeLevel( 0 ) {}
-	    /// Replaces typedefs by forward declarations
+		EliminateTypedef() : scopeLevel( 0 ) {}
+		/// Replaces typedefs by forward declarations
 		static void eliminateTypedef( std::list< Declaration * > &translationUnit );
 	  private:
@@ -209,4 +223,5 @@
 		acceptAll( translationUnit, pass1 );
 		acceptAll( translationUnit, pass2 );
+		ReturnChecker::checkFunctionReturns( translationUnit );
 		AutogenerateRoutines::autogenerateRoutines( translationUnit );
 		acceptAll( translationUnit, pass3 );
@@ -850,4 +865,25 @@
 	}
 
+	void ReturnChecker::checkFunctionReturns( std::list< Declaration * > & translationUnit ) {
+		ReturnChecker checker;
+		acceptAll( translationUnit, checker );
+	}
+
+	void ReturnChecker::visit( FunctionDecl * functionDecl ) {
+		std::list< DeclarationWithType * > oldReturnVals = returnVals;
+		returnVals = functionDecl->get_functionType()->get_returnVals();
+		Visitor::visit( functionDecl );
+		returnVals = oldReturnVals;
+	}
+
+	void ReturnChecker::visit( ReturnStmt * returnStmt ) {
+		if ( returnStmt->get_expr() == NULL && returnVals.size() != 0 ) {
+			throw SemanticError( "Non-void function returns no values: " , returnStmt );
+		} else if ( returnStmt->get_expr() != NULL && returnVals.size() == 0 ) {
+			throw SemanticError( "void function returns values: " , returnStmt );
+		}
+	}
+
+
 	bool isTypedef( Declaration *decl ) {
 		return dynamic_cast< TypedefDecl * >( decl );
Index: src/SynTree/Declaration.cc
===================================================================
--- src/SynTree/Declaration.cc	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/SynTree/Declaration.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -9,7 +9,7 @@
 // Author           : Richard C. Bilson
 // Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Mon Jul 13 17:58:38 2015
-// Update Count     : 10
+// Last Modified By : Rob Schluntz
+// Last Modified On : Wed Dec 09 14:08:29 2015
+// Update Count     : 12
 //
 
@@ -55,4 +55,10 @@
 }
 
+std::ostream & operator<<( std::ostream & out, Declaration * decl ) {
+	decl->print( out );
+	return out;
+}
+
+
 // Local Variables: //
 // tab-width: 4 //
Index: src/SynTree/Declaration.h
===================================================================
--- src/SynTree/Declaration.h	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/SynTree/Declaration.h	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -9,7 +9,7 @@
 // Author           : Richard C. Bilson
 // Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Mon Jul 13 18:15:59 2015
-// Update Count     : 28
+// Last Modified By : Rob Schluntz
+// Last Modified On : Wed Dec 09 14:08:22 2015
+// Update Count     : 32
 //
 
@@ -259,4 +259,6 @@
 };
 
+std::ostream & operator<<( std::ostream & out, Declaration * decl );
+
 #endif // DECLARATION_H
 
Index: src/SynTree/Expression.cc
===================================================================
--- src/SynTree/Expression.cc	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/SynTree/Expression.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -10,6 +10,6 @@
 // Created On       : Mon May 18 07:44:20 2015
 // Last Modified By : Rob Schluntz
-// Last Modified On : Wed Sep 02 12:07:10 2015
-// Update Count     : 33
+// Last Modified On : Wed Dec 09 14:10:29 2015
+// Update Count     : 34
 //
 
@@ -122,4 +122,35 @@
 void SizeofExpr::print( std::ostream &os, int indent) const {
 	os << std::string( indent, ' ' ) << "Sizeof Expression on: ";
+
+	if (isType)
+		type->print(os, indent + 2);
+	else
+		expr->print(os, indent + 2);
+
+	os << std::endl;
+	Expression::print( os, indent );
+}
+
+AlignofExpr::AlignofExpr( Expression *expr_, Expression *_aname ) :
+		Expression( _aname ), expr(expr_), type(0), isType(false) {
+	add_result( new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ) );
+}
+
+AlignofExpr::AlignofExpr( Type *type_, Expression *_aname ) :
+		Expression( _aname ), expr(0), type(type_), isType(true) {
+	add_result( new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ) );
+}
+
+AlignofExpr::AlignofExpr( const AlignofExpr &other ) :
+	Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) {
+}
+
+AlignofExpr::~AlignofExpr() {
+	delete expr;
+	delete type;
+}
+
+void AlignofExpr::print( std::ostream &os, int indent) const {
+	os << std::string( indent, ' ' ) << "Alignof Expression on: ";
 
 	if (isType)
@@ -345,4 +376,9 @@
 }
 
+std::ostream & operator<<( std::ostream & out, Expression * expr ) {
+	expr->print( out );
+	return out;
+}
+
 // Local Variables: //
 // tab-width: 4 //
Index: src/SynTree/Expression.h
===================================================================
--- src/SynTree/Expression.h	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/SynTree/Expression.h	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -9,7 +9,7 @@
 // Author           : Richard C. Bilson
 // Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Fri Jul 24 13:49:28 2015
-// Update Count     : 18
+// Last Modified By : Rob Schluntz
+// Last Modified On : Wed Dec 09 14:10:21 2015
+// Update Count     : 19
 //
 
@@ -23,4 +23,5 @@
 #include "Constant.h"
 
+/// Expression is the root type for all expressions
 class Expression {
   public:
@@ -47,7 +48,6 @@
 };
 
-// ParamEntry contains the i.d. of a declaration and a type that is derived from that declaration,
-// but subject to decay-to-pointer and type parameter renaming
-
+/// ParamEntry contains the i.d. of a declaration and a type that is derived from that declaration,
+/// but subject to decay-to-pointer and type parameter renaming
 struct ParamEntry {
 	ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ) {}
@@ -65,7 +65,6 @@
 typedef std::map< UniqueId, ParamEntry > InferredParams;
 
-// ApplicationExpr represents the application of a function to a set of parameters.  This is the
-// result of running an UntypedExpr through the expression analyzer.
-
+/// ApplicationExpr represents the application of a function to a set of parameters.  This is the
+/// result of running an UntypedExpr through the expression analyzer.
 class ApplicationExpr : public Expression {
   public:
@@ -89,8 +88,7 @@
 };
 
-// UntypedExpr represents the application of a function to a set of parameters, but where the
-// particular overload for the function name has not yet been determined.  Most operators are
-// converted into functional form automatically, to permit operator overloading.
-
+/// UntypedExpr represents the application of a function to a set of parameters, but where the
+/// particular overload for the function name has not yet been determined.  Most operators are
+/// converted into functional form automatically, to permit operator overloading.
 class UntypedExpr : public Expression {
   public:
@@ -118,5 +116,5 @@
 };
 
-// this class contains a name whose meaning is still not determined
+/// NameExpr contains a name whose meaning is still not determined
 class NameExpr : public Expression {
   public:
@@ -139,5 +137,5 @@
 // function-call format.
 
-// AddressExpr represents a address-of expression, e.g. &e
+/// AddressExpr represents a address-of expression, e.g. &e
 class AddressExpr : public Expression {
   public:
@@ -174,5 +172,5 @@
 };
 
-// CastExpr represents a type cast expression, e.g. (int)e
+/// CastExpr represents a type cast expression, e.g. (int)e
 class CastExpr : public Expression {
   public:
@@ -193,5 +191,5 @@
 };
 
-// UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer
+/// UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer
 class UntypedMemberExpr : public Expression {
   public:
@@ -214,5 +212,5 @@
 };
 
-// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer
+/// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer
 class MemberExpr : public Expression {
   public:
@@ -235,5 +233,5 @@
 };
 
-// VariableExpr represents an expression that simply refers to the value of a named variable
+/// VariableExpr represents an expression that simply refers to the value of a named variable
 class VariableExpr : public Expression {
   public:
@@ -253,5 +251,5 @@
 };
 
-// ConstantExpr represents an expression that simply refers to the value of a constant 
+/// ConstantExpr represents an expression that simply refers to the value of a constant 
 class ConstantExpr : public Expression {
   public:
@@ -271,5 +269,5 @@
 };
 
-// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)
+/// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)
 class SizeofExpr : public Expression {
   public:
@@ -296,5 +294,30 @@
 };
 
-// AttrExpr represents an @attribute expression (like sizeof, but user-defined)
+/// AlignofExpr represents an alignof expression
+class AlignofExpr : public Expression {
+  public:
+	AlignofExpr( Expression *expr, Expression *_aname = 0 );
+	AlignofExpr( const AlignofExpr &other );
+	AlignofExpr( Type *type, Expression *_aname = 0 );
+	virtual ~AlignofExpr();
+
+	Expression *get_expr() const { return expr; }
+	void set_expr( Expression *newValue ) { expr = newValue; }
+	Type *get_type() const { return type; }
+	void set_type( Type *newValue ) { type = newValue; }
+	bool get_isType() const { return isType; }
+	void set_isType( bool newValue ) { isType = newValue; }
+
+	virtual AlignofExpr *clone() const { return new AlignofExpr( *this ); }
+	virtual void accept( Visitor &v ) { v.visit( this ); }
+	virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
+	virtual void print( std::ostream &os, int indent = 0 ) const;
+  private:
+	Expression *expr;
+	Type *type;
+	bool isType;
+};
+
+/// AttrExpr represents an @attribute expression (like sizeof, but user-defined)
 class AttrExpr : public Expression {
   public:
@@ -324,5 +347,5 @@
 };
 
-// LogicalExpr represents a short-circuit boolean expression (&& or ||)
+/// LogicalExpr represents a short-circuit boolean expression (&& or ||)
 class LogicalExpr : public Expression {
   public:
@@ -347,5 +370,5 @@
 };
 
-// ConditionalExpr represents the three-argument conditional ( p ? a : b )
+/// ConditionalExpr represents the three-argument conditional ( p ? a : b )
 class ConditionalExpr : public Expression {
   public:
@@ -371,5 +394,5 @@
 };
 
-// CommaExpr represents the sequence operator ( a, b )
+/// CommaExpr represents the sequence operator ( a, b )
 class CommaExpr : public Expression {
   public:
@@ -392,5 +415,5 @@
 };
 
-// TupleExpr represents a tuple expression ( [a, b, c] )
+/// TupleExpr represents a tuple expression ( [a, b, c] )
 class TupleExpr : public Expression {
   public:
@@ -410,5 +433,5 @@
 };
 
-// SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on
+/// SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on
 class SolvedTupleExpr : public Expression {
   public:
@@ -428,5 +451,5 @@
 };
 
-// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
+/// TypeExpr represents a type used in an expression (e.g. as a type generator parameter)
 class TypeExpr : public Expression {
   public:
@@ -446,5 +469,5 @@
 };
 
-// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)
+/// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)
 class AsmExpr : public Expression {
   public:
@@ -472,5 +495,5 @@
 };
 
-// ValofExpr represents a GCC 'lambda expression'
+/// ValofExpr represents a GCC 'lambda expression'
 class UntypedValofExpr : public Expression {
   public:
@@ -488,4 +511,6 @@
 	Statement *body;
 };
+
+std::ostream & operator<<( std::ostream & out, Expression * expr );
 
 #endif // EXPRESSION_H
Index: src/SynTree/Mutator.cc
===================================================================
--- src/SynTree/Mutator.cc	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/SynTree/Mutator.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -251,4 +251,14 @@
 }
 
+Expression *Mutator::mutate( AlignofExpr *alignofExpr ) {
+	mutateAll( alignofExpr->get_results(), *this );
+	if ( alignofExpr->get_isType() ) {
+		alignofExpr->set_type( maybeMutate( alignofExpr->get_type(), *this ) );
+	} else {
+		alignofExpr->set_expr( maybeMutate( alignofExpr->get_expr(), *this ) );
+	}
+	return alignofExpr;
+}
+
 Expression *Mutator::mutate( AttrExpr *attrExpr ) {
 	mutateAll( attrExpr->get_results(), *this );
Index: src/SynTree/Mutator.h
===================================================================
--- src/SynTree/Mutator.h	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/SynTree/Mutator.h	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -64,4 +64,5 @@
 	virtual Expression* mutate( ConstantExpr *constantExpr ); 
 	virtual Expression* mutate( SizeofExpr *sizeofExpr );
+	virtual Expression* mutate( AlignofExpr *alignofExpr );
 	virtual Expression* mutate( AttrExpr *attrExpr );
 	virtual Expression* mutate( LogicalExpr *logicalExpr );
Index: src/SynTree/PointerType.cc
===================================================================
--- src/SynTree/PointerType.cc	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/SynTree/PointerType.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -10,6 +10,6 @@
 // Created On       : Mon May 18 07:44:20 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Mon May 18 10:15:16 2015
-// Update Count     : 2
+// Last Modified On : Tue Dec 15 15:39:10 2015
+// Update Count     : 5
 //
 
@@ -20,10 +20,8 @@
 PointerType::PointerType( const Type::Qualifiers &tq, Type *base )
 	: Type( tq ), base( base ), dimension( 0 ), isVarLen( false ), isStatic( false ) {
-	base->set_isLvalue( false );
 }
 
 PointerType::PointerType( const Type::Qualifiers &tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic )
 	: Type( tq ), base( base ), dimension( dimension ), isVarLen( isVarLen ), isStatic( isStatic ) {
-	base->set_isLvalue( false );
 }
 
Index: src/SynTree/Statement.cc
===================================================================
--- src/SynTree/Statement.cc	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/SynTree/Statement.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -9,7 +9,7 @@
 // Author           : Richard C. Bilson
 // Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Sat Jul 25 12:19:50 2015
-// Update Count     : 53
+// Last Modified By : Rob Schluntz
+// Last Modified On : Wed Dec 09 14:09:34 2015
+// Update Count     : 54
 //
 
@@ -337,4 +337,9 @@
 }
 
+std::ostream & operator<<( std::ostream & out, Statement * statement ) {
+	statement->print( out );
+	return out;
+}
+
 // Local Variables: //
 // tab-width: 4 //
Index: src/SynTree/Statement.h
===================================================================
--- src/SynTree/Statement.h	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/SynTree/Statement.h	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -9,7 +9,7 @@
 // Author           : Richard C. Bilson
 // Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Sat Jul 25 18:25:37 2015
-// Update Count     : 44
+// Last Modified By : Rob Schluntz
+// Last Modified On : Wed Dec 09 14:09:24 2015
+// Update Count     : 46
 //
 
@@ -396,4 +396,6 @@
 };
 
+std::ostream & operator<<( std::ostream & out, Statement * statement );
+
 #endif // STATEMENT_H
 
Index: src/SynTree/SynTree.h
===================================================================
--- src/SynTree/SynTree.h	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/SynTree/SynTree.h	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -69,4 +69,5 @@
 class ConstantExpr;
 class SizeofExpr;
+class AlignofExpr;
 class AttrExpr;
 class LogicalExpr;
Index: src/SynTree/Type.cc
===================================================================
--- src/SynTree/Type.cc	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/SynTree/Type.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -9,7 +9,7 @@
 // Author           : Richard C. Bilson
 // Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Thu Jul  9 16:45:13 2015
-// Update Count     : 3
+// Last Modified By : Rob Schluntz
+// Last Modified On : Wed Dec 09 14:08:48 2015
+// Update Count     : 4
 //
 
@@ -80,4 +80,9 @@
 }
 
+std::ostream & operator<<( std::ostream & out, Type * type ) {
+	type->print( out );
+	return out;
+}
+
 // Local Variables: //
 // tab-width: 4 //
Index: src/SynTree/Type.h
===================================================================
--- src/SynTree/Type.h	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/SynTree/Type.h	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -5,11 +5,11 @@
 // file "LICENCE" distributed with Cforall.
 //
-// Type.h -- 
+// Type.h --
 //
 // Author           : Richard C. Bilson
 // Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Fri Nov 20 12:54:09 2015
-// Update Count     : 15
+// Last Modified By : Rob Schluntz
+// Last Modified On : Fri Dec 18 14:46:18 2015
+// Update Count     : 18
 //
 
@@ -23,8 +23,8 @@
 class Type {
   public:
-	struct Qualifiers {  
+	struct Qualifiers {
 		Qualifiers(): isConst( false ), isVolatile( false ), isRestrict( false ), isLvalue( false ), isAtomic( false ), isAttribute( false ) {}
 		Qualifiers( bool isConst, bool isVolatile, bool isRestrict, bool isLvalue, bool isAtomic, bool isAttribute ): isConst( isConst ), isVolatile( isVolatile ), isRestrict( isRestrict ), isLvalue( isLvalue ), isAtomic( isAtomic ), isAttribute( isAttribute ) {}
-	
+
 		Qualifiers &operator+=( const Qualifiers &other );
 		Qualifiers &operator-=( const Qualifiers &other );
@@ -36,5 +36,5 @@
 		bool operator<( const Qualifiers &other );
 		bool operator>( const Qualifiers &other );
-	
+
 		bool isConst;
 		bool isVolatile;
@@ -43,5 +43,5 @@
 		bool isAtomic;
 		bool isAttribute;
-	};	
+	};
 
 	Type( const Qualifiers &tq );
@@ -85,5 +85,5 @@
 class BasicType : public Type {
   public:
-	enum Kind {  
+	enum Kind {
 		Bool,
 		Char,
@@ -108,5 +108,5 @@
 		LongDoubleImaginary,
 		NUMBER_OF_BASIC_TYPES
-	};  
+	};
 
 	static const char *typeNames[];						// string names for basic types, MUST MATCH with Kind
@@ -149,5 +149,5 @@
   private:
 	Type *base;
-	
+
 	// In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] )
 	Expression *dimension;
@@ -188,6 +188,6 @@
 	virtual ~FunctionType();
 
-	std::list<DeclarationWithType*>& get_returnVals() { return returnVals; }
-	std::list<DeclarationWithType*>& get_parameters() { return parameters; }
+	std::list<DeclarationWithType*> & get_returnVals() { return returnVals; }
+	std::list<DeclarationWithType*> & get_parameters() { return parameters; }
 	bool get_isVarArgs() { return isVarArgs; }
 	void set_isVarArgs( bool newValue ) { isVarArgs = newValue; }
@@ -217,5 +217,5 @@
 	void set_name( std::string newValue ) { name = newValue; }
 	std::list< Expression* >& get_parameters() { return parameters; }
-	
+
 	virtual ReferenceToType *clone() const = 0;
 	virtual void accept( Visitor &v ) = 0;
@@ -240,5 +240,5 @@
 	/// Accesses generic parameters of base struct (NULL if none such)
 	std::list<TypeDecl*> * get_baseParameters();
-	
+
 	/// Looks up the members of this struct named "name" and places them into "foundDecls".
 	/// Clones declarations into "foundDecls", caller responsible for freeing
@@ -250,5 +250,5 @@
   private:
 	virtual std::string typeString() const;
-	
+
 	// this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree,
 	// where the structure used in this type is actually defined
@@ -267,5 +267,5 @@
 	/// Accesses generic parameters of base union (NULL if none such)
 	std::list<TypeDecl*> * get_baseParameters();
-	
+
 	/// looks up the members of this union named "name" and places them into "foundDecls"
 	/// Clones declarations into "foundDecls", caller responsible for freeing
@@ -277,5 +277,5 @@
   private:
 	virtual std::string typeString() const;
-	
+
 	// this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
 	// where the union used in this type is actually defined
@@ -310,5 +310,5 @@
   private:
 	virtual std::string typeString() const;
-	
+
 	// this member is filled in by the validate pass, which instantiates the members of the correponding
 	// aggregate with the actual type parameters specified for this use of the context
@@ -327,5 +327,5 @@
 	bool get_isFtype() const { return isFtype; }
 	void set_isFtype( bool newValue ) { isFtype = newValue; }
-	
+
 	virtual TypeInstType *clone() const { return new TypeInstType( *this ); }
 	virtual void accept( Visitor &v ) { v.visit( this ); }
@@ -463,4 +463,6 @@
 }
 
+std::ostream & operator<<( std::ostream & out, Type * type );
+
 #endif // TYPE_H
 
Index: src/SynTree/Visitor.cc
===================================================================
--- src/SynTree/Visitor.cc	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/SynTree/Visitor.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -210,4 +210,13 @@
 }
 
+void Visitor::visit( AlignofExpr *alignofExpr ) {
+	acceptAll( alignofExpr->get_results(), *this );
+	if ( alignofExpr->get_isType() ) {
+		maybeAccept( alignofExpr->get_type(), *this );
+	} else {
+		maybeAccept( alignofExpr->get_expr(), *this );
+	}
+}
+
 void Visitor::visit( AttrExpr *attrExpr ) {
 	acceptAll( attrExpr->get_results(), *this );
Index: src/SynTree/Visitor.h
===================================================================
--- src/SynTree/Visitor.h	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/SynTree/Visitor.h	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -64,4 +64,5 @@
 	virtual void visit( ConstantExpr *constantExpr ); 
 	virtual void visit( SizeofExpr *sizeofExpr );
+	virtual void visit( AlignofExpr *alignofExpr );
 	virtual void visit( AttrExpr *attrExpr );
 	virtual void visit( LogicalExpr *logicalExpr );
Index: src/Tuples/FlattenTuple.cc
===================================================================
--- src/Tuples/FlattenTuple.cc	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/Tuples/FlattenTuple.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -46,4 +46,5 @@
 	void FlattenTuple::CollectArgs::visit( ConstantExpr      *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
 	void FlattenTuple::CollectArgs::visit( SizeofExpr        *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
+	void FlattenTuple::CollectArgs::visit( AlignofExpr       *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
 	void FlattenTuple::CollectArgs::visit( AttrExpr          *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
 	void FlattenTuple::CollectArgs::visit( LogicalExpr       *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
Index: src/Tuples/FlattenTuple.h
===================================================================
--- src/Tuples/FlattenTuple.h	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/Tuples/FlattenTuple.h	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -42,4 +42,5 @@
 			virtual void visit( ConstantExpr * ); 
 			virtual void visit( SizeofExpr * );
+			virtual void visit( AlignofExpr * );
 			virtual void visit( AttrExpr * );
 			virtual void visit( LogicalExpr * );
Index: src/driver/Makefile.in
===================================================================
--- src/driver/Makefile.in	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/driver/Makefile.in	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -195,7 +195,7 @@
 	  esac; \
 	done; \
-	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/driver/Makefile'; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/driver/Makefile'; \
 	$(am__cd) $(top_srcdir) && \
-	  $(AUTOMAKE) --gnu src/driver/Makefile
+	  $(AUTOMAKE) --foreign src/driver/Makefile
 .PRECIOUS: Makefile
 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
Index: src/examples/Makefile.in
===================================================================
--- src/examples/Makefile.in	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/examples/Makefile.in	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -191,7 +191,7 @@
 	  esac; \
 	done; \
-	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/examples/Makefile'; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/examples/Makefile'; \
 	$(am__cd) $(top_srcdir) && \
-	  $(AUTOMAKE) --gnu src/examples/Makefile
+	  $(AUTOMAKE) --foreign src/examples/Makefile
 .PRECIOUS: Makefile
 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
Index: src/examples/fstream_test.c
===================================================================
--- src/examples/fstream_test.c	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/examples/fstream_test.c	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -10,6 +10,6 @@
 // Created On       : Wed May 27 17:56:53 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Wed May 27 18:13:43 2015
-// Update Count     : 2
+// Last Modified On : Mon Nov 23 14:43:32 2015
+// Update Count     : 40
 //
 
@@ -20,7 +20,18 @@
 	ifstream *sin = ifstream_stdin();
 	int nombre;
-	sout << "Appuyez un nombre, s'il vous plâit:\n";
-	sin >> &nombre;
-	sout << "Vous avez appuyé: " << nombre << "\n";
+	sout | "Entrez un nombre, s'il vous plaît:\n";
+	sin  | &nombre;
+	sout | "Vous avez entré " | nombre | " stocké à l'adresse " | &nombre | endl;
+	sout | "nombre " | nombre | " est "
+		 | (nombre > 0 ? "plus grand que" :
+		   nombre == 0 ? "égal à" : "moins de")
+		 | " zéro" | endl;
+
+	sout | "Entrez trois nombres, s'il vous plaît:\n";
+	int i, j, k;
+	sin  | &i | &j | &k;
+	sout | "Vous avez entré " | "i:" | i | " j:" | j | " k:" | k | endl;
+
+	sout | 3 | ' ' | 3.5 | ' ' | 'a' | ' ' | "abc" | endl;
 }
 
Index: src/examples/hello.c
===================================================================
--- src/examples/hello.c	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/examples/hello.c	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -10,6 +10,6 @@
 // Created On       : Wed May 27 17:56:53 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Fri Nov 20 16:02:50 2015
-// Update Count     : 3
+// Last Modified On : Sun Nov 22 17:40:37 2015
+// Update Count     : 5
 //
 
@@ -19,9 +19,5 @@
 	ofstream *sout = ofstream_stdout();
 	ifstream *sin = ifstream_stdin();
-	sout << "Bonjour au monde!\n";
-	sout << 3 << " " << 3.5 << " " << 'a' << " " << "abc" << "\n";
-	int i, j, k;
-	sin >> &i >> &j >> &k;
-	sout << "i:" << i << " j:" << j << " k:" << k << "\n";
+	sout | "Bonjour au monde!\n";
 }
 
Index: src/examples/iostream.c
===================================================================
--- src/examples/iostream.c	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/examples/iostream.c	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -10,6 +10,6 @@
 // Created On       : Wed May 27 17:56:53 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Fri Nov 20 13:19:19 2015
-// Update Count     : 9
+// Last Modified On : Mon Dec  7 23:08:02 2015
+// Update Count     : 24
 //
 
@@ -21,33 +21,46 @@
 
 forall( dtype ostype | ostream( ostype ) )
-ostype * ?<<?( ostype *os, char c ) {
+ostype * ?|?( ostype *os, char c ) {
 	return write( os, &c, 1 );
-} // ?<<?
+} // ?|?
 
 forall( dtype ostype | ostream( ostype ) )
-ostype * ?<<?( ostype *os, int i ) {
+ostype * ?|?( ostype *os, int i ) {
 	char buffer[32];									// larger than the largest integer
 	sprintf( buffer, "%d", i );
 	return write( os, buffer, strlen( buffer ) );
-} // ?<<?
+} // ?|?
 
 forall( dtype ostype | ostream( ostype ) )
-ostype * ?<<?( ostype *os, double d ) {
+ostype * ?|?( ostype *os, double d ) {
 	char buffer[32];									// larger than the largest double
 	sprintf( buffer, "%g", d );
 	return write( os, buffer, strlen( buffer ) );
-} // ?<<?
+} // ?|?
 
 forall( dtype ostype | ostream( ostype ) )
-ostype * ?<<?( ostype *os, const char *cp ) {
+ostype * ?|?( ostype *os, const char *cp ) {
 	return write( os, cp, strlen( cp ) );
-} // ?<<?
+} // ?|?
 
 forall( dtype ostype | ostream( ostype ) )
-ostype * ?<<?( ostype *os, const void *p ) {
+ostype * ?|?( ostype *os, const void *p ) {
 	char buffer[32];									// larger than the largest pointer
 	sprintf( buffer, "%p", p );
 	return write( os, buffer, strlen( buffer ) );
-} // ?<<?
+} // ?|?
+
+
+forall( dtype ostype, dtype retostype | ostream( ostype ) | ostream( retostype ) ) 
+retostype * ?|?( ostype *os, retostype * (*manip)(ostype*) ) {
+  return manip(os);
+}
+
+forall( dtype ostype | ostream( ostype ) ) 
+ostype * endl( ostype * os ) {
+  os | "\n";
+  // flush
+  return os;
+} // endl
 
 forall( type elt_type | writeable( elt_type ),
@@ -56,8 +69,8 @@
 void write( iterator_type begin, iterator_type end, os_type *os ) {
 	void print( elt_type i ) {
-		os << i << ' ';
+		os | i | ' ';
 	}
 	for_each( begin, end, print );
-} // ?<<?
+} // ?|?
 
 forall( type elt_type | writeable( elt_type ),
@@ -65,23 +78,21 @@
 		dtype os_type | ostream( os_type ) )
 void write_reverse( iterator_type begin, iterator_type end, os_type *os ) {
-	void print( elt_type i ) {
-		os << i << ' ';
-	}
+	void print( elt_type i ) { os | i | ' '; }
 	for_each_reverse( begin, end, print );
-} // ?<<?
+} // ?|?
 
 
 forall( dtype istype | istream( istype ) )
-istype * ?>>?( istype *is, char *cp ) {
+istype * ?|?( istype *is, char *cp ) {
 	return read( is, cp, 1 );
-} // ?>>?
+} // ?|?
 
 forall( dtype istype | istream( istype ) )
-istype * ?>>?( istype *is, int *ip ) {
+istype * ?|?( istype *is, int *ip ) {
 	char cur;
   
 	// skip some whitespace
 	do {
-		is >> &cur;
+		is | &cur;
 		if ( fail( is ) || eof( is ) ) return is;
 	} while ( !( cur >= '0' && cur <= '9' ) );
@@ -91,5 +102,5 @@
 	while ( cur >= '0' && cur <= '9' ) {
 		*ip = *ip * 10 + ( cur - '0' );
-		is >> &cur;
+		is | &cur;
 		if ( fail( is ) || eof( is ) ) return is;
 	}
@@ -97,5 +108,5 @@
 	unread( is, cur );
 	return is;
-} // ?>>?
+} // ?|?
 
 // Local Variables: //
Index: src/examples/iostream.h
===================================================================
--- src/examples/iostream.h	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/examples/iostream.h	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -10,6 +10,6 @@
 // Created On       : Wed May 27 17:56:53 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Thu Nov 19 17:56:51 2015
-// Update Count     : 5
+// Last Modified On : Mon Nov 23 14:15:25 2015
+// Update Count     : 17
 //
 
@@ -27,14 +27,17 @@
 
 context writeable( type T ) {
-	forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, T );
+	forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, T );
 };
 
 // implement writable for some intrinsic types
 
-forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, char );
-forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, int );
-forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, double );
-forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, const char * );
-forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, void * );
+forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, char );
+forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, int );
+forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, double );
+forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, const char * );
+forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, const void * );
+
+forall( dtype ostype, dtype retostype | ostream( ostype ) | ostream( retostype ) ) retostype * ?|?( ostype *os, retostype * (* manip)(ostype*) );
+forall( dtype ostype | ostream( ostype ) ) ostype * endl( ostype * );
 
 // writes the range [begin, end) to the given stream
@@ -49,4 +52,5 @@
 void write_reverse( iterator_type begin, iterator_type end, os_type *os );
 
+//******************************************************************************
 
 context istream( dtype istype ) {
@@ -58,12 +62,12 @@
 
 context readable( type T ) {
-	forall( dtype istype | istream( istype ) ) istype * ?<<?( istype *, T );
+	forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, T );
 };
 
 forall( dtype istype | istream( istype ) )
-istype * ?>>?( istype *, char * );
+istype * ?|?( istype *, char * );
 
 forall( dtype istype | istream( istype ) )
-istype * ?>>?( istype *, int * );
+istype * ?|?( istype *, int * );
 
 #endif // IOSTREAM_H
Index: src/examples/sum.c
===================================================================
--- src/examples/sum.c	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/examples/sum.c	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -10,6 +10,6 @@
 // Created On       : Wed May 27 17:56:53 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Mon Sep 28 15:09:55 2015
-// Update Count     : 118
+// Last Modified On : Sat Nov 21 18:08:18 2015
+// Update Count     : 119
 //
 
@@ -53,5 +53,5 @@
 	}
 	sout << "sum from " << low << " to " << High << " is "
-		 << (int)sum( size, a ) << ", check " << (int)s << "\n";
+		 << (int)sum( size, a ) << ", check " << (int)s << endl;
 
 	int s = 0, a[size];
@@ -62,5 +62,5 @@
 	}
 	sout << "sum from " << low << " to " << High << " is "
-		 << sum( size, (int *)a ) << ", check " << (int)s << "\n";
+		 << sum( size, (int *)a ) << ", check " << (int)s << endl;
 
 	double s = 0.0, a[size];
@@ -72,5 +72,5 @@
 	printf( "%g\n", sum( size, (double *)a ) );
 //	sout << "sum from " << low / 10.0 << " to " << High / 10.0 << " is "
-//		 << sum( size, (double *)a ) << ", check " << (double)s << "\n";
+//		 << sum( size, (double *)a ) << ", check " << (double)s << endl;
 
 	float s = 0.0, a[size];
@@ -82,5 +82,5 @@
 	printf( "%g\n", sum( size, (float *)a ) );
 //	sout << "sum from " << low / 10.0 << " to " << High / 10.0 << " is "
-//		 << sum( size, (float *)a ) << ", check " << (float)s << "\n";
+//		 << sum( size, (float *)a ) << ", check " << (float)s << endl;
 }
 
Index: src/examples/vector_test.c
===================================================================
--- src/examples/vector_test.c	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/examples/vector_test.c	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -10,6 +10,6 @@
 // Created On       : Wed May 27 17:56:53 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Thu Nov 19 17:54:34 2015
-// Update Count     : 9
+// Last Modified On : Tue Dec 15 16:02:56 2015
+// Update Count     : 13
 //
 
@@ -27,7 +27,7 @@
 	int num;
 
-	sout << "enter N elements and C-d on a separate line:\n";
+	sout | "enter N elements and C-d on a separate line:" | endl;
 	for ( ;; ) {
-		sin >> &num;
+		sin | &num;
 	  if ( fail( sin ) || eof( sin ) ) break;
 		append( &vec, num );
@@ -35,11 +35,11 @@
 	// write out the numbers
 
-	sout << "Array elements:\n";
+	sout | "Array elements:" | endl;
 	write( begin( vec ), end( vec ), sout );
-	sout << "\n";
+	sout | endl;
 
-	sout << "Array elements reversed:\n";
+	sout | "Array elements reversed:" | endl;
 	write_reverse( begin( vec ), end( vec ), sout );
-	sout << "\n";
+	sout | endl;
 }
 
Index: src/libcfa/Makefile.am
===================================================================
--- src/libcfa/Makefile.am	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/libcfa/Makefile.am	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -11,6 +11,6 @@
 ## Created On       : Sun May 31 08:54:01 2015
 ## Last Modified By : Peter A. Buhr
-## Last Modified On : Thu Jun  4 22:49:16 2015
-## Update Count     : 7
+## Last Modified On : Wed Dec 16 22:58:17 2015
+## Update Count     : 9
 ###############################################################################
 
@@ -44,5 +44,5 @@
 
 libcfa-prelude.c : ${srcdir}/prelude.cf
-	${libdir}/cfa-cpp -l ${srcdir}/prelude.cf $@
+	../cfa-cpp -l ${srcdir}/prelude.cf $@  # use src/cfa-cpp as not in lib until after install
 
 libcfa-prelude.o : libcfa-prelude.c
Index: src/libcfa/Makefile.in
===================================================================
--- src/libcfa/Makefile.in	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/libcfa/Makefile.in	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -220,7 +220,7 @@
 	  esac; \
 	done; \
-	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/libcfa/Makefile'; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/libcfa/Makefile'; \
 	$(am__cd) $(top_srcdir) && \
-	  $(AUTOMAKE) --gnu src/libcfa/Makefile
+	  $(AUTOMAKE) --foreign src/libcfa/Makefile
 .PRECIOUS: Makefile
 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@@ -542,5 +542,5 @@
 
 libcfa-prelude.c : ${srcdir}/prelude.cf
-	${libdir}/cfa-cpp -l ${srcdir}/prelude.cf $@
+	../cfa-cpp -l ${srcdir}/prelude.cf $@  # use src/cfa-cpp as not in lib until after install
 
 libcfa-prelude.o : libcfa-prelude.c
Index: src/main.cc
===================================================================
--- src/main.cc	(revision 267cb3dd82e30767dcf559734fc52fec82cce964)
+++ src/main.cc	(revision 083cf3181fe3a210bc837e36dd40f9dc8d3ae198)
@@ -10,6 +10,6 @@
 // Created On       : Fri May 15 23:12:02 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Thu Nov 19 22:31:40 2015
-// Update Count     : 168
+// Last Modified On : Thu Dec 17 12:59:06 2015
+// Update Count     : 179
 //
 
@@ -187,5 +187,6 @@
 		// read in the builtins and the prelude
 		if ( ! nopreludep ) {							// include gcc builtins
-			FILE * builtins = fopen( CFA_LIBDIR "/builtins.cf", "r" );
+			// -l is for initial build ONLY and builtins.cf is not in the lib directory so access it here.
+			FILE * builtins = fopen( libcfap ? "./builtins.cf" : CFA_LIBDIR "/builtins.cf", "r" );
 			if ( builtins == NULL ) {
 				std::cerr << "Error: can't open builtins" << std::endl;
@@ -196,5 +197,5 @@
 
 			if ( ! libcfap ) {
-				// read the prelude in, if we're not generating the cfa library
+				// read the prelude in, if not generating the cfa library
 				FILE * prelude = fopen( CFA_LIBDIR "/prelude.cf", "r" );
 				if ( prelude == NULL ) {
@@ -203,13 +204,9 @@
 				} // if
 		    
-		    parse( prelude, LinkageSpec::Intrinsic );
+				parse( prelude, LinkageSpec::Intrinsic );
 			} // if
 		} // if
 
-		if ( libcfap ) {
-			parse( input, LinkageSpec::Intrinsic );	
-		} else {
-			parse( input, LinkageSpec::Cforall, grammarp );	
-		}
+		parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, grammarp );	
   
 		if ( parsep ) {
