From bf365ee41ac532624de4efdcc81c3f238c32448a Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Mon, 2 Feb 2009 18:27:38 +0000 Subject: [PATCH] Fixed the pass that turns array constructors into replicated loops so that it handles nested array constructors and inner-procthens properly cgtest80 now compiles and passes --- transformations/SimplifyExprs.hs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/transformations/SimplifyExprs.hs b/transformations/SimplifyExprs.hs index 81f52f4..3f753ee 100644 --- a/transformations/SimplifyExprs.hs +++ b/transformations/SimplifyExprs.hs @@ -226,14 +226,16 @@ transformConstr = pass "Transform array constructors into initialisation code" -- to Original, since we are now actually declaring it and assigning -- to it: modifyName n $ \nd -> nd {A.ndAbbrevMode = A.Original} - + + let body = specs $ A.Several m'' + [ assignItem tInner indexVar repExp' + , incrementIndex indexVar ] + body' <- applyDepthSM doStructured body + return $ declDest $ A.ProcThen m'' (A.Seq m'' $ A.Spec m'' indexVarSpec $ A.Several m'' [assignIndex0 indexVar, - replicateCode $ A.Only m'' $ A.Seq m'' $ - specs $ A.Several m'' - [ assignItem tInner indexVar repExp' - , incrementIndex indexVar ] + replicateCode $ body' ]) scope A.List {} -> @@ -242,11 +244,15 @@ transformConstr = pass "Transform array constructors into initialisation code" scope _ -> diePC m $ formatCode "Unsupported type for array constructor: %" t where + -- Also strips ProcThen stripSpecs :: A.Structured A.Expression -> (A.Structured A.Expression, A.Structured A.Process -> A.Structured A.Process) stripSpecs (A.Spec m spec scope) = let (result, innerSpecs) = stripSpecs scope in (result, A.Spec m spec . innerSpecs) + stripSpecs (A.ProcThen m proc body) + = let (result, innerSpecs) = stripSpecs body in + (result, A.ProcThen m proc . innerSpecs) stripSpecs se = (se, id) declDest :: Data a => A.Structured a -> A.Structured a