Index: src/GenPoly/Box.cc
===================================================================
--- src/GenPoly/Box.cc	(revision 69911c112f8ee63e5b034a4052592b8607062c40)
+++ src/GenPoly/Box.cc	(revision ae63a185a34928dad284a49a9cd4c4d0d7655bb2)
@@ -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 : Peter A. Buhr
-// Last Modified On : Tue Dec 15 15:30:31 2015
-// Update Count     : 215
+// Last Modified By : Rob Schluntz
+// Last Modified On : Fri Dec 18 14:53:08 2015
+// Update Count     : 217
 //
 
@@ -65,5 +65,5 @@
 			virtual Type *mutate( PointerType *pointerType );
 			virtual Type * mutate( FunctionType *functionType );
-  
+
 			virtual void doBeginScope();
 			virtual void doEndScope();
@@ -103,5 +103,5 @@
 		  private:
 			void addAdapters( FunctionType *functionType );
-  
+
 			std::map< UniqueId, std::string > adapterName;
 		};
@@ -151,6 +151,6 @@
 			// 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 ) {
@@ -167,5 +167,5 @@
 					name << "P";
 				} else {
-					name << "M";				
+					name << "M";
 				}
 			} // for
@@ -185,4 +185,5 @@
 		}
 
+		// returns true if the given declaration is: (*?=?)(T *, T) for some T (return not checked, but maybe should be)
 		bool checkAssignment( DeclarationWithType *decl, std::string &name ) {
 			if ( decl->get_name() == "?=?" ) {
@@ -233,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() == "" ) {
@@ -240,5 +241,5 @@
 					} // if
 				} // if
-	
+
 				FunctionType *functionType = functionDecl->get_functionType();
 				makeTyVarMap( functionDecl->get_functionType(), scopeTyVars );
@@ -265,5 +266,5 @@
 
 				functionDecl->set_statements( functionDecl->get_statements()->acceptMutator( *this ) );
-  
+
 				scopeTyVars = oldtyVars;
 				assignOps = oldassignOps;
@@ -328,5 +329,5 @@
 			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;
@@ -405,5 +406,5 @@
 			appExpr->get_args().push_front( appExpr->get_function() );
 			appExpr->set_function( new NameExpr( adapterName ) );
-  
+
 			return ret;
 		}
@@ -528,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();
@@ -542,5 +543,5 @@
 				} // for
 			} // for
-  
+
 			std::list< DeclarationWithType *>::iterator arg = realType->get_parameters().begin();
 			std::list< DeclarationWithType *>::iterator param = adapterType->get_parameters().begin();
@@ -599,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 );
 
@@ -654,7 +655,7 @@
 						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 );
+						assert( ! baseType1 || ! baseType2 ); // the arguments cannot both be polymorphic pointers
 						UntypedExpr *ret = 0;
-						if ( baseType1 || baseType2 ) {
+						if ( baseType1 || baseType2 ) { // one of the arguments is a polymorphic pointer
 							ret = new UntypedExpr( new NameExpr( "?+?" ) );
 						} // if
@@ -777,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() );
@@ -783,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 ) ) {
@@ -806,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 );
 
@@ -874,5 +875,5 @@
 				// ***** 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() ) {
-				// a cast expr on a polymorphic return value is either redundant or invalid
+				// 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() );
@@ -909,7 +910,7 @@
 			TyVarMap oldtyVars = scopeTyVars;
 			makeTyVarMap( pointerType, scopeTyVars );
-  
+
 			Type *ret = Mutator::mutate( pointerType );
-  
+
 			scopeTyVars = oldtyVars;
 			return ret;
@@ -919,7 +920,7 @@
 			TyVarMap oldtyVars = scopeTyVars;
 			makeTyVarMap( functionType, scopeTyVars );
-  
+
 			Type *ret = Mutator::mutate( functionType );
-  
+
 			scopeTyVars = oldtyVars;
 			return ret;
@@ -988,7 +989,7 @@
 			TyVarMap oldtyVars = scopeTyVars;
 			makeTyVarMap( pointerType, scopeTyVars );
-  
+
 			Type *ret = Mutator::mutate( pointerType );
-  
+
 			scopeTyVars = oldtyVars;
 			return ret;
@@ -1018,5 +1019,5 @@
 				if ( (*tyParm)->get_kind() == TypeDecl::Any ) {
 					TypeInstType parmType( Type::Qualifiers(), (*tyParm)->get_name(), *tyParm );
-					
+
 					sizeParm = newObj.clone();
 					sizeParm->set_name( sizeofName( &parmType ) );
@@ -1044,5 +1045,5 @@
 					std::string sizeName = sizeofName( parmType );
 					if ( seenTypes.count( sizeName ) ) continue;
-					
+
 					ObjectDecl *sizeParm, *alignParm;
 					sizeParm = newObj.clone();
@@ -1065,5 +1066,5 @@
 			mutateAll( funcType->get_returnVals(), *this );
 			mutateAll( funcType->get_parameters(), *this );
-  
+
 			scopeTyVars = oldtyVars;
 			return funcType;
@@ -1076,5 +1077,5 @@
 			TyVarMap oldtyVars = scopeTyVars;
 			makeTyVarMap( type, scopeTyVars );
-  
+
 			DeclClass *ret = static_cast< DeclClass *>( Mutator::mutate( decl ) );
 			ScrubTyVars::scrub( decl, scopeTyVars );
@@ -1112,7 +1113,7 @@
 			TyVarMap oldtyVars = scopeTyVars;
 			makeTyVarMap( pointerType, scopeTyVars );
-  
+
 			Type *ret = Mutator::mutate( pointerType );
-  
+
 			scopeTyVars = oldtyVars;
 			return ret;
@@ -1122,7 +1123,7 @@
 			TyVarMap oldtyVars = scopeTyVars;
 			makeTyVarMap( functionType, scopeTyVars );
-  
+
 			Type *ret = Mutator::mutate( functionType );
-  
+
 			scopeTyVars = oldtyVars;
 			return ret;
