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)

This commit is contained in:
Neil Brown 2008-11-16 18:25:53 +00:00
parent 771297632d
commit bfacb526fb
3 changed files with 35 additions and 4 deletions

View File

@ -19,7 +19,9 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
-- | The necessary components for using an occam EDSL (for building test-cases). -- | The necessary components for using an occam EDSL (for building test-cases).
module OccamEDSL (ExpInp, ExpInpT, oSEQ, oPAR, oPROC, oSKIP, oINT, module OccamEDSL (ExpInp, ExpInpT, oSEQ, oPAR, oPROC, oSKIP, oINT,
oCASE, oCASEinput, oALT, guard, 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), testOccamPassTransform, ExpInpC(shouldComeFrom),
caseOption, inputCaseOption, caseOption, inputCaseOption,
becomes) where becomes) where
@ -273,6 +275,14 @@ decl' n sp scope = do
return $ A.Spec emptyMeta (A.Specification emptyMeta n sp) return $ A.Spec emptyMeta (A.Specification emptyMeta n sp)
(singlify $ A.Several emptyMeta s) (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 -- | A type-class to finesse the difference between components of expressions (such
-- as variables, literals) and actual expressions -- as variables, literals) and actual expressions
@ -309,6 +319,9 @@ instance CanBeInput A.InputMode where
oempty :: Data a => O (A.Structured a) oempty :: Data a => O (A.Structured a)
oempty = return $ A.Several emptyMeta [] 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 :: Data a => String -> O a -> Pass -> Test
testOccamPass str code pass testOccamPass str code pass
= let ExpInpT expm inpm = code = let ExpInpT expm inpm = code

View File

@ -571,6 +571,23 @@ testPullRepCounts = TestList
,testUnchanged 3 $ A.Alt emptyMeta True ,testUnchanged 3 $ A.Alt emptyMeta True
,testUnchanged 4 $ A.If emptyMeta ,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" ,TestCase $ testPass "testPullRepCounts 5"
(nameAndStopCaringPattern "nonce" "nonce" $ mkPattern $ A.Seq emptyMeta $ (nameAndStopCaringPattern "nonce" "nonce" $ mkPattern $ A.Seq emptyMeta $
A.Spec emptyMeta (A.Specification emptyMeta (simpleName "nonce") (A.IsExpr emptyMeta A.ValAbbrev A.Int $ intLiteral 6)) $ A.Spec emptyMeta (A.Specification emptyMeta (simpleName "nonce") (A.IsExpr emptyMeta A.ValAbbrev A.Int $ intLiteral 6)) $

View File

@ -174,9 +174,10 @@ pullRepCounts = pass "Pull up replicator counts for SEQs"
= do t <- astTypeOf for = do t <- astTypeOf for
spec@(A.Specification _ nonceName _) <- makeNonceIsExpr "rep_for" mspec t for spec@(A.Specification _ nonceName _) <- makeNonceIsExpr "rep_for" mspec t for
scope' <- pullRepCountSeq scope 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 $ return $ A.Spec mspec spec $
A.Spec m (A.Specification mspec n (A.Rep mrep A.Spec m (A.Specification mspec n newSpec) scope'
(A.For mfor from (A.ExprVariable mspec $ A.Variable mspec nonceName)))) scope'
pullRepCountSeq (A.Spec m sp str) pullRepCountSeq (A.Spec m sp str)
= do str' <- pullRepCountSeq str = do str' <- pullRepCountSeq str
return $ A.Spec m sp str' return $ A.Spec m sp str'