From 3d1d5e35ef3c69405badc69b263d98fc7bec04b1 Mon Sep 17 00:00:00 2001
From: Neil Brown <neil@twistedsquare.com>
Date: Thu, 16 Aug 2007 13:16:04 +0000
Subject: [PATCH] Changed the rain foreach-pass test to actually run the
 transformEach pass it was meant to be testing, and also got the transformEach
 test to compile

---
 RainPassTest.hs |  5 ++++-
 RainPasses.hs   | 19 ++++++++++++-------
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/RainPassTest.hs b/RainPassTest.hs
index 78492d2..30c608b 100644
--- a/RainPassTest.hs
+++ b/RainPassTest.hs
@@ -6,9 +6,12 @@ import qualified Data.Map as Map
 import qualified AST as A
 import TestUtil
 import TreeUtil
+import RainPasses
+import CompState
+import Control.Monad.Error (runErrorT)
 
 testEachPass0 :: Test
-testEachPass0 = TestCase $ assertPatternMatch "testEachPass0" exp orig
+testEachPass0 = TestCase $ assertPatternMatch "testEachPass0" exp (evalStateT (runErrorT (transformEach orig)) emptyState)
   where
     orig = A.Seq m 
              (A.Rep m 
diff --git a/RainPasses.hs b/RainPasses.hs
index 74596e1..51229f1 100644
--- a/RainPasses.hs
+++ b/RainPasses.hs
@@ -1,6 +1,11 @@
 module RainPasses where
 
 import TestUtil
+import qualified AST as A
+import Pass
+import Data.Generics
+import Types
+import CompState
 
 --TODO add passes for:
 --  Typing the variables
@@ -11,25 +16,25 @@ rainPasses :: A.Process -> PassM A.Process
 rainPasses = runPasses passes
   where
     passes = 
-    [ ("Convert seqeach/pareach loops into classic replicated SEQ/PAR",transformEach)
-    ]
+     [ ("Convert seqeach/pareach loops into classic replicated SEQ/PAR",transformEach)
+     ]
 
 --TODO test this pass and then tidy it up
 transformEach :: Data t => t -> PassM t
-transformEach = everywhere (mkM transformEach')
+transformEach = everywhereM (mkM transformEach')
   where
-    transformEach' :: A.Structured -> A.Structured
+    transformEach' :: A.Structured -> PassM A.Structured
     transformEach' (A.Rep m (A.ForEach m' loopVar loopExp) s)
       = do (spec,var) <- case loopExp of
              (A.ExprVariable _ v) -> return (\x -> x,v)
              _ -> do t <- typeOfExpression loopExp
                      spec@(A.Specification _ n' _) <- makeNonceIsExpr "loopVar" m t loopExp 
-                     return (\x -> A.Specification m spec x,A.Variable m n')
+                     return (\x -> A.Spec m spec x,A.Variable m n')
            --spec is a function A.Structured -> A.Structured, var is an A.Variable
            
-           loopVarType <- typeOfVariable loopVar
+           loopVarType <- typeOfName loopVar
            loopIndex <- makeNonce "loopIndex"
            let newRep = A.For m' (simpleName loopIndex) (intLiteral 0) (A.SizeVariable m' var)
            let s' = A.Spec m' (A.Specification m' loopVar (A.Is m' A.Abbrev loopVarType (A.SubscriptedVariable m' (A.Subscript m' (A.ExprVariable m' (variable loopIndex)))  var) )) s           
            return (spec (A.Rep m newRep s'))             
-    transformEach' s = s
+    transformEach' s = return s