From bfacb526fbeb519abe3501b5fee10883506f2817 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Sun, 16 Nov 2008 18:25:53 +0000 Subject: [PATCH] Converted one of the tests for pullRepCounts to use the new mechanism, which in turn exposed that the pass was not altering the definition in the state (which it may as well) --- common/OccamEDSL.hs | 15 ++++++++++++++- transformations/PassTest.hs | 19 ++++++++++++++++++- transformations/SimplifyExprs.hs | 5 +++-- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/common/OccamEDSL.hs b/common/OccamEDSL.hs index 85ab34f..6d96f30 100644 --- a/common/OccamEDSL.hs +++ b/common/OccamEDSL.hs @@ -19,7 +19,9 @@ with this program. If not, see . -- | The necessary components for using an occam EDSL (for building test-cases). module OccamEDSL (ExpInp, ExpInpT, oSEQ, oPAR, oPROC, oSKIP, oINT, oCASE, oCASEinput, oALT, guard, - Occ, oA, oB, oC, oX, oY, oZ, p0, p1, p2, (*?), (*!), (*:=), decl, decl', oempty, testOccamPass, + Occ, oA, oB, oC, oX, oY, oZ, p0, p1, p2, (*?), (*!), (*:=), decl, decl', decl'', + oempty, testOccamPass, + oprocess, testOccamPassTransform, ExpInpC(shouldComeFrom), caseOption, inputCaseOption, becomes) where @@ -273,6 +275,14 @@ decl' n sp scope = do return $ A.Spec emptyMeta (A.Specification emptyMeta n sp) (singlify $ A.Several emptyMeta s) +decl'' :: Data a => A.Name -> A.SpecType -> A.AbbrevMode -> + [O (A.Structured a)] -> O (A.Structured a) +decl'' n sp am scope = do + defineThing (A.nameName n) sp am + s <- sequence scope + return $ A.Spec emptyMeta (A.Specification emptyMeta n sp) + (singlify $ A.Several emptyMeta s) + -- | A type-class to finesse the difference between components of expressions (such -- as variables, literals) and actual expressions @@ -309,6 +319,9 @@ instance CanBeInput A.InputMode where oempty :: Data a => O (A.Structured a) oempty = return $ A.Several emptyMeta [] +oprocess :: O (A.Structured A.Process) -> O (A.Structured A.Process) +oprocess = id + testOccamPass :: Data a => String -> O a -> Pass -> Test testOccamPass str code pass = let ExpInpT expm inpm = code diff --git a/transformations/PassTest.hs b/transformations/PassTest.hs index 6e817fb..5ac7540 100644 --- a/transformations/PassTest.hs +++ b/transformations/PassTest.hs @@ -570,7 +570,24 @@ testPullRepCounts = TestList ,testUnchanged 2 $ A.Alt emptyMeta False ,testUnchanged 3 $ A.Alt emptyMeta True ,testUnchanged 4 $ A.If emptyMeta - + + ,testOccamPassTransform "testPullRepCounts 5" (nameAndStopCaringPattern "nonce" "A") + (oprocess $ oSEQ + [decl' (simpleName "X") + (A.Rep emptyMeta (A.For emptyMeta (intLiteral 0) (intLiteral 6))) + [] + ] + `becomes` + oSEQ + [decl'' (simpleName "A") + (A.IsExpr emptyMeta A.ValAbbrev A.Int $ intLiteral 6) A.ValAbbrev + [decl' (simpleName "X") + (A.Rep emptyMeta (A.For emptyMeta (intLiteral 0) (exprVariable "A"))) + [] + ] + ] + ) pullRepCounts + ,TestCase $ testPass "testPullRepCounts 5" (nameAndStopCaringPattern "nonce" "nonce" $ mkPattern $ A.Seq emptyMeta $ A.Spec emptyMeta (A.Specification emptyMeta (simpleName "nonce") (A.IsExpr emptyMeta A.ValAbbrev A.Int $ intLiteral 6)) $ diff --git a/transformations/SimplifyExprs.hs b/transformations/SimplifyExprs.hs index 3194d55..265652e 100644 --- a/transformations/SimplifyExprs.hs +++ b/transformations/SimplifyExprs.hs @@ -174,9 +174,10 @@ pullRepCounts = pass "Pull up replicator counts for SEQs" = do t <- astTypeOf for spec@(A.Specification _ nonceName _) <- makeNonceIsExpr "rep_for" mspec t for scope' <- pullRepCountSeq scope + let newSpec = (A.Rep mrep (A.For mfor from (A.ExprVariable mspec $ A.Variable mspec nonceName))) + modifyName n $ \nd -> nd { A.ndSpecType = newSpec } return $ A.Spec mspec spec $ - A.Spec m (A.Specification mspec n (A.Rep mrep - (A.For mfor from (A.ExprVariable mspec $ A.Variable mspec nonceName)))) scope' + A.Spec m (A.Specification mspec n newSpec) scope' pullRepCountSeq (A.Spec m sp str) = do str' <- pullRepCountSeq str return $ A.Spec m sp str'