Corrected some problems caused by moving the direction specifiers up to the whole array (the array wasn't then being pulled up)

This commit is contained in:
Neil Brown 2009-02-10 00:28:45 +00:00
parent 93af6b85a4
commit 14df1e09b7
4 changed files with 22 additions and 6 deletions

View File

@ -176,6 +176,7 @@ declareSizesArray = occamOnlyPass "Declare array-size arrays"
A.SubscriptField {} -> (Nothing, wv)
A.SubscriptFromFor _ _ _ for -> (Just for, snd $ findInnerVar v) -- Keep the outer most
A.Subscript {} -> findInnerVar v
findInnerVar (A.DirectedVariable _ _ v) = findInnerVar v
findInnerVar v = (Nothing, v)
-- | Generate the @_sizes@ array for a 'Retypes' expression.
@ -237,6 +238,7 @@ declareSizesArray = occamOnlyPass "Declare array-size arrays"
return (A.Variable m $ A.Name m $ A.nameName recordName ++ A.nameName fieldName ++ "_sizes")
A.DirectedVariable _ _ (A.Variable _ srcN) -> return (A.Variable m
$ append_sizes srcN)
_ -> diePC m $ formatCode "Cannot handle variable % in abbrevVarSizes" innerV
-- Get the dimensions of the source variable:
innerVT <- astTypeOf innerV
srcDs <- case innerVT of

View File

@ -891,6 +891,13 @@ cgenArraySubscript check v es
genChunks = map genDim subs
--}}}
countSubscripts :: A.Variable -> (Int, A.Variable)
countSubscripts (A.SubscriptedVariable _ (A.Subscript {}) v)
= let (n, v') = countSubscripts v in (1+n, v')
countSubscripts (A.SubscriptedVariable _ _ v) = countSubscripts v
countSubscripts (A.DirectedVariable _ _ v) = countSubscripts v
countSubscripts v@(A.Variable _ _) = (0, v)
--{{{ expressions
cgenExpression :: A.Expression -> CGen ()
cgenExpression (A.Monadic m op e) = call genMonadic m op e
@ -907,8 +914,10 @@ cgenExpression (A.SizeVariable m v)
A.Array (d:_) _ ->
case d of
A.Dimension n -> call genExpression n
A.UnknownDimension -> do call genVariable v
call genSizeSuffix "0"
A.UnknownDimension ->
let (n, v') = countSubscripts v
in do call genVariable v'
call genSizeSuffix (show n)
A.List _ ->
call genListSize v
cgenExpression (A.Conversion m cm t e) = call genConversion m cm t e

View File

@ -636,8 +636,7 @@ cppintroduceSpec (A.Specification _ n (A.Is _ am t@(A.Array ds c@(A.ChanEnd {}))
tell [","]
genName n
tell [","]
call genVariableAM v am
call genSizeSuffix "0"
call genExpression (A.SizeVariable m $ A.Variable m n)
tell [");"]
--For all other cases, use the C implementation:
cppintroduceSpec n = cintroduceSpec n

View File

@ -451,8 +451,14 @@ pullUp pullUpArraysInsideRecords = pass "Pull up definitions"
= do t <- astTypeOf innerV
case t of
A.Array ds (A.Chan attr innerT) ->
do spec@(A.Specification _ n _) <- makeNonceIs "dir_array" m
(A.Array ds $ A.ChanEnd dir attr innerT) A.Abbrev v
do let ds' = [case d of
A.Dimension {} -> d
A.UnknownDimension -> A.Dimension $ A.SizeVariable m $
foldr (\n v -> A.SubscriptedVariable m (A.Subscript m A.CheckBoth
n) v) innerV (replicate i $ makeConstant m 0)
| (d, i) <- zip ds [0..]]
spec@(A.Specification _ n _) <- makeNonceIs "dir_array" m
(A.Array ds' $ A.ChanEnd dir attr innerT) A.Abbrev v
addPulled $ (m, Left spec)
return $ A.Variable m n
_ -> descend v