Corrected genVariable to obey checkValid when working out the types for array slices
This commit is contained in:
parent
ffc4594604
commit
fdef3b1924
|
@ -696,9 +696,11 @@ cgenVariable' checkValid v
|
||||||
inner ind (A.DirectedVariable _ dir v) mt
|
inner ind (A.DirectedVariable _ dir v) mt
|
||||||
= do (cg,n) <- (inner ind v mt)
|
= do (cg,n) <- (inner ind v mt)
|
||||||
return (call genDirectedVariable (addPrefix cg n) dir, 0)
|
return (call genDirectedVariable (addPrefix cg n) dir, 0)
|
||||||
inner ind sv@(A.SubscriptedVariable _ (A.Subscript _ _) _) mt
|
inner ind sv@(A.SubscriptedVariable m (A.Subscript _ _) _) mt
|
||||||
= do let (es, v) = collectSubs sv
|
= do (es, v, t') <- collectSubs sv
|
||||||
t <- typeOfVariable sv
|
t <- if checkValid
|
||||||
|
then typeOfVariable sv
|
||||||
|
else return t'
|
||||||
(cg, n) <- inner ind v (Just t)
|
(cg, n) <- inner ind v (Just t)
|
||||||
return (cg >> call genArraySubscript checkValid v es, n)
|
return (cg >> call genArraySubscript checkValid v es, n)
|
||||||
inner ind sv@(A.SubscriptedVariable _ (A.SubscriptField m n) v) mt
|
inner ind sv@(A.SubscriptedVariable _ (A.SubscriptField m n) v) mt
|
||||||
|
@ -729,12 +731,13 @@ cgenVariable' checkValid v
|
||||||
getPrefix n = if n > 0 then replicate n '*' else "#error Negative prefix lower than -1"
|
getPrefix n = if n > 0 then replicate n '*' else "#error Negative prefix lower than -1"
|
||||||
|
|
||||||
-- | Collect all the plain subscripts on a variable, so we can combine them.
|
-- | Collect all the plain subscripts on a variable, so we can combine them.
|
||||||
collectSubs :: A.Variable -> ([A.Expression], A.Variable)
|
collectSubs :: A.Variable -> CGen ([A.Expression], A.Variable, A.Type)
|
||||||
collectSubs (A.SubscriptedVariable _ (A.Subscript _ e) v)
|
collectSubs (A.SubscriptedVariable m (A.Subscript _ e) v)
|
||||||
= (es' ++ [e], v')
|
= do (es', v', t') <- collectSubs v
|
||||||
where
|
t <- trivialSubscriptType m t'
|
||||||
(es', v') = collectSubs v
|
return (es' ++ [e], v', t)
|
||||||
collectSubs v = ([], v)
|
collectSubs v = do t <- typeOfVariable v
|
||||||
|
return ([], v, t)
|
||||||
|
|
||||||
|
|
||||||
cgenDirectedVariable :: CGen () -> A.Direction -> CGen ()
|
cgenDirectedVariable :: CGen () -> A.Direction -> CGen ()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user