From f9a811e775ffb4f2143472e5e5cce0ffc6026223 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Sat, 18 Aug 2007 18:10:51 +0000 Subject: [PATCH] Rain: implemented the pass for recording inferred types, and added one more test for it --- RainPassTest.hs | 6 ++++++ RainPasses.hs | 22 +++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/RainPassTest.hs b/RainPassTest.hs index 23ecd1e..f9901a9 100644 --- a/RainPassTest.hs +++ b/RainPassTest.hs @@ -220,6 +220,11 @@ testRecordInfNames2 = testPassWithStateCheck "testRecordInfNames2" exp (recordIn assertVarDef "testRecordInfNames2" state "d" (tag7 A.NameDef DontCare "d" "d" A.VariableName (A.Declaration m A.Byte) A.Original A.Unplaced) +-- | checks that doing a foreach over a non-array type is barred: +testRecordInfNames3 :: Test +testRecordInfNames3 = testPassShouldFail "testRecordInfNames3" (recordInfNameTypes orig) (return ()) + where + orig = A.Rep m (A.ForEach m (simpleName "c") (intLiteral 0)) skipP --Returns the list of tests: tests :: Test @@ -234,6 +239,7 @@ tests = TestList ,testRecordInfNames0 ,testRecordInfNames1 ,testRecordInfNames2 + ,testRecordInfNames3 ] diff --git a/RainPasses.hs b/RainPasses.hs index fffa3d4..575a72d 100644 --- a/RainPasses.hs +++ b/RainPasses.hs @@ -6,10 +6,7 @@ import Pass import Data.Generics import Types import CompState - ---TODO add passes for: --- Typing the variables - +import Errors rainPasses :: A.Process -> PassM A.Process rainPasses = runPasses passes @@ -46,7 +43,22 @@ recordDeclNameTypes = everywhereM (mkM recordDeclNameTypes') recordDeclNameTypes' s = return s recordInfNameTypes :: Data t => t -> PassM t -recordInfNameTypes = return +recordInfNameTypes = everywhereM (mkM recordInfNameTypes') + where + recordInfNameTypes' :: A.Replicator -> PassM A.Replicator + recordInfNameTypes' input@(A.ForEach m n e) + = do arrType <- typeOfExpression e + innerT <- case arrType of + A.Array (_:innerDims) t -> + return $ case innerDims of + [] -> t + _ -> A.Array innerDims t + _ -> dieP m "Cannot do a foreach loop over a non-array type (or array with zero dimensions)" + defineName n A.NameDef {A.ndMeta = m, A.ndName = A.nameName n, A.ndOrigName = A.nameName n, + A.ndNameType = A.VariableName, A.ndType = (A.Declaration m innerT), + A.ndAbbrevMode = A.Original, A.ndPlacement = A.Unplaced} + return input + recordInfNameTypes' r = return r transformEach :: Data t => t -> PassM t