From 5280bb4fc6160fb014bb1a4be5d00aab37e1f506 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Mon, 29 Oct 2007 18:29:29 +0000 Subject: [PATCH] Added support for output statements to the usage checker --- transformations/RainUsageCheck.hs | 10 +++++++++- transformations/RainUsageCheckTest.hs | 10 +++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/transformations/RainUsageCheck.hs b/transformations/RainUsageCheck.hs index 65dfdfb..6ee446b 100644 --- a/transformations/RainUsageCheck.hs +++ b/transformations/RainUsageCheck.hs @@ -68,6 +68,9 @@ unionVars (Vars mr mw dw u) (Vars mr' mw' dw' u') = Vars (mr `Set.union` mr') (m foldUnionVars :: [Vars] -> Vars foldUnionVars = foldl unionVars emptyVars +mapUnionVars :: (a -> Vars) -> [a] -> Vars +mapUnionVars f = foldUnionVars . (map f) + nameToString :: A.Name -> String nameToString = A.nameName @@ -86,7 +89,12 @@ getVarProc (A.Assign _ vars expList) (getVarExpList expList) getVarProc (A.GetTime _ v) = processVarW v getVarProc (A.Wait _ _ e) = getVarExp e ---TODO output input etc (all other processes that directly write to/read from variables) +getVarProc (A.Output _ chanVar outItems) = (processVarUsed chanVar) `unionVars` (mapUnionVars getVarOutputItem outItems) + where + getVarOutputItem :: A.OutputItem -> Vars + getVarOutputItem (A.OutExpression _ e) = getVarExp e + getVarOutputItem (A.OutCounted _ ce ae) = (getVarExp ce) `unionVars` (getVarExp ae) +--TODO input etc (all other processes that directly write to/read from variables) getVarProc _ = emptyVars {- diff --git a/transformations/RainUsageCheckTest.hs b/transformations/RainUsageCheckTest.hs index 2efc4c7..f5107b8 100644 --- a/transformations/RainUsageCheckTest.hs +++ b/transformations/RainUsageCheckTest.hs @@ -31,7 +31,7 @@ import RainUsageCheck --Shorthands for some variables to simplify the list of tests in this file vA = variable "a" vB = A.DerefVariable emptyMeta $ variable "b" -vC = variable "c" +vC = A.DirectedVariable emptyMeta A.DirInput $ variable "c" vD = variable "d" vL = variable "l" l0 = intLiteral 0 @@ -39,7 +39,7 @@ l1 = intLiteral 1 tvA = Plain "a" tvB = Deref "b" -tvC = Plain "c" +tvC = Dir A.DirInput "c" tvD = Plain "d" tvL = Plain "l" @@ -81,7 +81,11 @@ testGetVarProc = TestList (map doTest tests) ,(300,[],[tvB],[tvB],[],A.GetTime emptyMeta vB) ,(301,[tvA],[],[],[],A.Wait emptyMeta A.WaitFor $ A.ExprVariable emptyMeta vA) - + -- Test simple outputs: + ,(400,[tvA],[],[],[tvC],A.Output emptyMeta vC [A.OutExpression emptyMeta $ A.ExprVariable emptyMeta vA]) + ,(401,[tvA,tvB],[],[],[tvC],A.Output emptyMeta vC $ map ((A.OutExpression emptyMeta) . (A.ExprVariable emptyMeta)) [vA,vB]) + ,(402,[tvA,tvB],[],[],[tvC],A.Output emptyMeta vC + [A.OutCounted emptyMeta (A.ExprVariable emptyMeta vA) (A.ExprVariable emptyMeta vB)]) ] doTest :: (Int,[Var],[Var],[Var],[Var],A.Process) -> Test