From 96934c871d8dba3e6c148ce2e83eff7a50b11c12 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Mon, 2 Feb 2009 17:36:14 +0000 Subject: [PATCH] Changed the transformation of array constructors so that it also pulls out all the specs that were pulled up to be just inside them --- transformations/SimplifyExprs.hs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/transformations/SimplifyExprs.hs b/transformations/SimplifyExprs.hs index 9d0b19d..81f52f4 100644 --- a/transformations/SimplifyExprs.hs +++ b/transformations/SimplifyExprs.hs @@ -217,6 +217,7 @@ transformConstr = pass "Transform array constructors into initialisation code" A.Array {} -> do indexVarSpec@(A.Specification _ indexName _) <- makeNonceVariable "array_constr_index" m'' A.Int A.Original let indexVar = A.Variable m'' indexName + (repExp', specs) = stripSpecs repExp tInner <- trivialSubscriptType m t @@ -230,8 +231,8 @@ transformConstr = pass "Transform array constructors into initialisation code" (A.Seq m'' $ A.Spec m'' indexVarSpec $ A.Several m'' [assignIndex0 indexVar, replicateCode $ A.Only m'' $ A.Seq m'' $ - A.Several m'' - [ assignItem tInner indexVar + specs $ A.Several m'' + [ assignItem tInner indexVar repExp' , incrementIndex indexVar ] ]) scope @@ -241,6 +242,13 @@ transformConstr = pass "Transform array constructors into initialisation code" scope _ -> diePC m $ formatCode "Unsupported type for array constructor: %" t where + 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 se = (se, id) + declDest :: Data a => A.Structured a -> A.Structured a declDest = A.Spec m (A.Specification m' n (A.Declaration m' t)) @@ -252,11 +260,14 @@ transformConstr = pass "Transform array constructors into initialisation code" incrementIndex indexVar = A.Only m'' $ A.Assign m'' [indexVar] $ A.ExpressionList m'' [addOne $ A.ExprVariable m'' indexVar] - assignItem :: A.Type -> A.Variable -> A.Structured A.Process - assignItem t' indexVar = A.Only m'' $ A.Assign m'' [A.SubscriptedVariable m'' + assignItem :: A.Type -> A.Variable -> A.Structured A.Expression -> A.Structured A.Process + assignItem t' indexVar repExp' = A.Only m'' $ A.Assign m'' [A.SubscriptedVariable m'' (A.Subscript m'' A.NoCheck $ A.ExprVariable m'' indexVar) $ A.Variable m'' n] $ A.ExpressionList m'' [ - A.Literal m'' t' $ A.ArrayListLiteral m'' repExp] + case repExp' of + A.Only _ e -> e + _ -> A.Literal m'' t' $ A.ArrayListLiteral m'' repExp' + ] appendItem :: A.Structured A.Process appendItem = A.Only m'' $ A.Assign m'' [A.Variable m'' n] $