From e1fd001322472e4a7fcf8e417ee09cceb476d7f4 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Sat, 8 Mar 2008 13:42:36 +0000 Subject: [PATCH] Fixed a bug relating to not initialising C channel arrays properly (an over-enthusiastic trimming earlier) --- backends/GenerateC.hs | 12 +++++++++--- backends/GenerateCTest.hs | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/backends/GenerateC.hs b/backends/GenerateC.hs index 0f9faa7..e389356 100644 --- a/backends/GenerateC.hs +++ b/backends/GenerateC.hs @@ -230,12 +230,15 @@ cgenOverArray m var func tell ["=0;"] call genVariable i tell ["<"] - call genVariable var - call genSizeSuffix (show v) + case d of + A.UnknownDimension -> + do call genVariable var + call genSizeSuffix (show v) + A.Dimension n -> tell [show n] tell [";"] call genVariable i tell ["++){"] - | (v :: Integer, i) <- zip [0..] indices] + | (v :: Integer, i, d) <- zip3 [0..] indices ds] p sequence_ [tell ["}"] | _ <- indices] Nothing -> return () @@ -1126,6 +1129,9 @@ cdeclareInit m t@(A.Array ds t') var _ sequence_ $ intersperse (tell ["*"]) [case dim of A.Dimension d -> tell [show d] | dim <- ds] tell [");"] _ -> return () + fdeclareInit <- fget declareInit + init <- return (\sub -> fdeclareInit m t' (sub var) Nothing) + call genOverArray m var init cdeclareInit m rt@(A.Record _) var _ = Just $ do fs <- recordFields m rt sequence_ [initField t (A.SubscriptedVariable m (A.SubscriptField m n) var) diff --git a/backends/GenerateCTest.hs b/backends/GenerateCTest.hs index 63fe3bb..cc23071 100644 --- a/backends/GenerateCTest.hs +++ b/backends/GenerateCTest.hs @@ -370,6 +370,7 @@ testArraySlice = TestList checkSlice s e sub = "occam_check_slice(" ++ s ++ "," ++ e ++ "," ++ sub ++ "," ++ m ++ ")" +-- TODO fix this test so that it tests fixed dimensions properly testOverArray :: Test testOverArray = TestList $ map testOverArray' [(cSize,cIndex,"", cgenOps) @@ -491,7 +492,7 @@ testDeclareInitFree = TestLabel "testDeclareInitFree" $ TestList -- Records containing an array: ,testAllR 101 ("","") ("","") (A.Array [A.Dimension 4,A.Dimension 5] A.Int) id -- Arrays of records containing an array: - ,testAllRA 200 ("^^","") ("^^","") (A.Array [A.Dimension 4,A.Dimension 5] A.Int) id + ,testAllRA 200 ("^^","") ("","") (A.Array [A.Dimension 4,A.Dimension 5] A.Int) id -- Mobile versions ,testAllSame 1003 ("","") $ A.Mobile $ A.Array [A.Dimension 4] A.Int