From e117422c31f5957d28cb9463b5df4618048bafc6 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Thu, 20 Nov 2008 15:06:36 +0000 Subject: [PATCH] Added a couple more tests for checkUnusedVar which has revealed two bugs One of these bugs is that array variables are counted as unused when they are used subscripted. I think that should be solved when we flip back to the listify approach. The second bug is more interesting, as it is triggered only in a certain arrangement with an IF. It's either a bug in the flow-graph building or in the varsTouchedAfter code. --- checks/CheckTest.hs | 33 +++++++++++++++++++++++++++++++++ common/OccamEDSL.hs | 5 +++++ 2 files changed, 38 insertions(+) diff --git a/checks/CheckTest.hs b/checks/CheckTest.hs index 14bdc5f..0520753 100644 --- a/checks/CheckTest.hs +++ b/checks/CheckTest.hs @@ -54,6 +54,39 @@ testUnusedVar = TestList [decl (return A.Int) oX []] `becomes` oSEQ [] + + ,testSame "Used array variable" $ wrap $ + oSEQ [ + decl (return $ A.Array [A.Dimension $ intLiteral 2] A.Int) oX + [oX `sub` 0 *:= (return (0::Int))] + ] + + ,testSame "One variable, used in one IF branch" $ wrap $ + oSEQ [ + decl (return A.Int) oX + [oIF + [ifChoice (True, oX *:= (return (0::Int))) + ,ifChoice (True, oSKIP) + ] + ] + ] + ,testSame "One variable, declared in an IF and used in one IF branch" $ wrap $ + oIF + [ + decl (return A.Int) oX + [ifChoice (True, oX *:= (return (0::Int))) + ,ifChoice (True, oSKIP) + ] + ] + ,testSame "One variable, declared in an IF and used in second IF branch" $ wrap $ + oIF + [ + decl (return A.Int) oX + [ifChoice (True, oSKIP) + ,ifChoice (True, oX *:= (return (0::Int))) + ] + ] + ] where wrap x = oPROC "foo" [] x oempty diff --git a/common/OccamEDSL.hs b/common/OccamEDSL.hs index e552653..d74e119 100644 --- a/common/OccamEDSL.hs +++ b/common/OccamEDSL.hs @@ -23,6 +23,7 @@ module OccamEDSL (ExpInp, ExpInpT, oALT, guard, oIF, ifChoice, Occ, oA, oB, oC, oX, oY, oZ, p0, p1, p2, (*?), (*!), (*:=), (*+), decl, decl', decl'', + sub, oempty, testOccamPass, oprocess, testOccamPassWarn, testOccamPassTransform, ExpInpC(shouldComeFrom), @@ -292,6 +293,10 @@ infix 8 *:= return (A.Dyadic emptyMeta A.Add x' y') +sub :: ExpInp A.Variable -> Int -> ExpInp A.Variable +sub v n = liftM (A.SubscriptedVariable emptyMeta (A.Subscript emptyMeta A.CheckBoth + $ intLiteral $ toInteger n)) v + decl :: Data a => ExpInp A.Type -> ExpInp A.Variable -> [O (A.Structured a)] -> O (A.Structured a) decl bty bvar scope = do