Changed the transformation of array constructors so that it also pulls out all the specs that were pulled up to be just inside them
This commit is contained in:
parent
ebf8ae2d83
commit
96934c871d
|
@ -217,6 +217,7 @@ transformConstr = pass "Transform array constructors into initialisation code"
|
||||||
A.Array {} ->
|
A.Array {} ->
|
||||||
do indexVarSpec@(A.Specification _ indexName _) <- makeNonceVariable "array_constr_index" m'' A.Int A.Original
|
do indexVarSpec@(A.Specification _ indexName _) <- makeNonceVariable "array_constr_index" m'' A.Int A.Original
|
||||||
let indexVar = A.Variable m'' indexName
|
let indexVar = A.Variable m'' indexName
|
||||||
|
(repExp', specs) = stripSpecs repExp
|
||||||
|
|
||||||
tInner <- trivialSubscriptType m t
|
tInner <- trivialSubscriptType m t
|
||||||
|
|
||||||
|
@ -230,8 +231,8 @@ transformConstr = pass "Transform array constructors into initialisation code"
|
||||||
(A.Seq m'' $ A.Spec m'' indexVarSpec $
|
(A.Seq m'' $ A.Spec m'' indexVarSpec $
|
||||||
A.Several m'' [assignIndex0 indexVar,
|
A.Several m'' [assignIndex0 indexVar,
|
||||||
replicateCode $ A.Only m'' $ A.Seq m'' $
|
replicateCode $ A.Only m'' $ A.Seq m'' $
|
||||||
A.Several m''
|
specs $ A.Several m''
|
||||||
[ assignItem tInner indexVar
|
[ assignItem tInner indexVar repExp'
|
||||||
, incrementIndex indexVar ]
|
, incrementIndex indexVar ]
|
||||||
])
|
])
|
||||||
scope
|
scope
|
||||||
|
@ -241,6 +242,13 @@ transformConstr = pass "Transform array constructors into initialisation code"
|
||||||
scope
|
scope
|
||||||
_ -> diePC m $ formatCode "Unsupported type for array constructor: %" t
|
_ -> diePC m $ formatCode "Unsupported type for array constructor: %" t
|
||||||
where
|
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 :: Data a => A.Structured a -> A.Structured a
|
||||||
declDest = A.Spec m (A.Specification m' n (A.Declaration m' t))
|
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] $
|
incrementIndex indexVar = A.Only m'' $ A.Assign m'' [indexVar] $
|
||||||
A.ExpressionList m'' [addOne $ A.ExprVariable m'' indexVar]
|
A.ExpressionList m'' [addOne $ A.ExprVariable m'' indexVar]
|
||||||
|
|
||||||
assignItem :: A.Type -> A.Variable -> A.Structured A.Process
|
assignItem :: A.Type -> A.Variable -> A.Structured A.Expression -> A.Structured A.Process
|
||||||
assignItem t' indexVar = A.Only m'' $ A.Assign m'' [A.SubscriptedVariable m''
|
assignItem t' indexVar repExp' = A.Only m'' $ A.Assign m'' [A.SubscriptedVariable m''
|
||||||
(A.Subscript m'' A.NoCheck $ A.ExprVariable m'' indexVar) $
|
(A.Subscript m'' A.NoCheck $ A.ExprVariable m'' indexVar) $
|
||||||
A.Variable m'' n] $ A.ExpressionList m'' [
|
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.Structured A.Process
|
||||||
appendItem = A.Only m'' $ A.Assign m'' [A.Variable m'' n] $
|
appendItem = A.Only m'' $ A.Assign m'' [A.Variable m'' n] $
|
||||||
|
|
Loading…
Reference in New Issue
Block a user