Corrected the C++ tests and implementation of arrays inside records -- the dimensions of the tockArrayView were not being set, but they should be.

This commit is contained in:
Neil Brown 2007-10-05 17:52:37 +00:00
parent 8cd20b9906
commit 34609f1fee
2 changed files with 22 additions and 2 deletions

View File

@ -85,6 +85,7 @@ import Pass
import ShowCode
import TLP
import Types
import Utils
--{{{ generator ops
-- | Operations for the C++CSP backend.
@ -671,6 +672,25 @@ cppgenDeclaration ops t n
-- | Changed because we don't need any initialisation in C++
cppdeclareInit :: GenOps -> Meta -> A.Type -> A.Variable -> Maybe (CGen ())
cppdeclareInit ops m t@(A.Array ds t') var
= Just $ do init <- return (\sub -> call declareInit ops m t' (sub var))
call genOverArray ops m var init
cppdeclareInit ops m rt@(A.Record _) var
= Just $ do fs <- recordFields m rt
sequence_ [initField t (A.SubscriptedVariable m (A.SubscriptField m n) var)
| (n, t) <- fs]
where
initField :: A.Type -> A.Variable -> CGen ()
-- An array as a record field; we must initialise the sizes.
initField t@(A.Array ds _) v
= do call genVariableUnchecked ops v
tell ["=tockArrayView("]
call genVariableUnchecked ops v
tell ["_actual,tockDims("]
infixComma [tell [show n] | (A.Dimension n) <- ds]
tell ["));"]
doMaybe $ call declareInit ops m t v
initField t v = doMaybe $ call declareInit ops m t v
cppdeclareInit _ _ _ _ = Nothing
-- | Changed because we don't need any de-initialisation in C++, regardless of whether C does.

View File

@ -418,9 +418,9 @@ testDeclareInitFree = TestList
-- Plain records:
,testAllR 100 ("","") ("","") A.Int
-- Records containing an array:
,testAllR 101 ("(&foo)->bar_sizes[0]=4;","") ("","") $ A.Array [A.Dimension 4] A.Int
,testAllR 101 ("(&foo)->bar_sizes[0]=4;(&foo)->bar_sizes[1]=5;","") ("(&foo)->bar=tockArrayView((&foo)->bar_actual,tockDims(4,5));","") $ A.Array [A.Dimension 4,A.Dimension 5] A.Int
-- Arrays of records containing an array:
,testAllRA 200 ("^(&foo[0])->bar_sizes[0]=4;^","") ("","") $ A.Array [A.Dimension 4] A.Int
,testAllRA 200 ("^(&foo[0])->bar_sizes[0]=4;(&foo[0])->bar_sizes[1]=5;^","") ("^(&foo[0].access())->bar=tockArrayView((&foo[0].access())->bar_actual,tockDims(4,5));^","") $ A.Array [A.Dimension 4,A.Dimension 5] A.Int
]
where
testAll :: Int -> (String,String) -> (String,String) -> A.Type -> Test