From c3fad80f063070c3354e83f4cd5d93c74a53833a Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Sat, 6 Oct 2007 12:49:30 +0000 Subject: [PATCH] Changed the behaviour of the C++ version of declareArraySizes, moving towards potentially merging more of the C++ array handling with the C array handling --- backends/GenerateCPPCSP.hs | 9 ++++----- backends/GenerateCTest.hs | 17 +++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/backends/GenerateCPPCSP.hs b/backends/GenerateCPPCSP.hs index 1fff758..93d738b 100644 --- a/backends/GenerateCPPCSP.hs +++ b/backends/GenerateCPPCSP.hs @@ -676,14 +676,13 @@ cppgenDeclaration ops t n _ cppdeclareArraySizes :: GenOps -> A.Type -> A.Name -> CGen () cppdeclareArraySizes ops arrType@(A.Array ds _) n = do + tell ["const "] call genType ops arrType tell [" "] genName n - tell ["("] - genName n - tell ["_actual,tockDims("] - genDims ds - tell ["));"] + tell ["="] + call genArraySizesLiteral ops n arrType + tell [";"] cppgenArraySizesLiteral :: GenOps -> A.Name -> A.Type -> CGen () cppgenArraySizesLiteral ops n t@(A.Array ds _) = diff --git a/backends/GenerateCTest.hs b/backends/GenerateCTest.hs index 5145bf5..c78e464 100644 --- a/backends/GenerateCTest.hs +++ b/backends/GenerateCTest.hs @@ -364,11 +364,11 @@ testDeclaration = TestList ,testBoth "genDeclaration 8" "Channel* foo;" "csp::Chanout foo;" (tcall3 genDeclaration (A.Chan A.DirOutput (A.ChanAttributes True False) A.Int) foo False) --Arrays (of simple): - ,testBoth "genDeclaration 100" "int foo[8];const int foo_sizes[]={8};" "int foo_actual[8];tockArrayView foo(foo_actual,tockDims(8));" + ,testBoth "genDeclaration 100" "int foo[8];const int foo_sizes[]={8};" "int foo_actual[8];const tockArrayView foo=tockArrayView(foo_actual,tockDims(8));" (tcall3 genDeclaration (A.Array [A.Dimension 8] A.Int) foo False) - ,testBoth "genDeclaration 101" "int foo[8*9];const int foo_sizes[]={8,9};" "int foo_actual[8*9];tockArrayView foo(foo_actual,tockDims(8,9));" + ,testBoth "genDeclaration 101" "int foo[8*9];const int foo_sizes[]={8,9};" "int foo_actual[8*9];const tockArrayView foo=tockArrayView(foo_actual,tockDims(8,9));" (tcall3 genDeclaration (A.Array [A.Dimension 8,A.Dimension 9] A.Int) foo False) - ,testBoth "genDeclaration 102" "int foo[8*9*10];const int foo_sizes[]={8,9,10};" "int foo_actual[8*9*10];tockArrayView foo(foo_actual,tockDims(8,9,10));" + ,testBoth "genDeclaration 102" "int foo[8*9*10];const int foo_sizes[]={8,9,10};" "int foo_actual[8*9*10];const tockArrayView foo=tockArrayView(foo_actual,tockDims(8,9,10));" (tcall3 genDeclaration (A.Array [A.Dimension 8,A.Dimension 9,A.Dimension 10] A.Int) foo False) --Arrays (of simple) inside records: @@ -381,19 +381,19 @@ testDeclaration = TestList --Arrays of channels and channel-ends: ,testBoth "genDeclaration 200" "Channel foo[8];const int foo_sizes[]={8};" - "csp::One2OneChannel foo_actual[8];tockArrayView,1> foo(foo_actual,tockDims(8));" + "csp::One2OneChannel foo_actual[8];const tockArrayView,1> foo=tockArrayView,1>(foo_actual,tockDims(8));" (tcall3 genDeclaration (A.Array [A.Dimension 8] $ A.Chan A.DirUnknown (A.ChanAttributes False False) A.Int) foo False) ,testBoth "genDeclaration 201" "Channel foo[8*9];const int foo_sizes[]={8,9};" - "csp::One2OneChannel foo_actual[8*9];tockArrayView,2> foo(foo_actual,tockDims(8,9));" + "csp::One2OneChannel foo_actual[8*9];const tockArrayView,2> foo=tockArrayView,2>(foo_actual,tockDims(8,9));" (tcall3 genDeclaration (A.Array [A.Dimension 8, A.Dimension 9] $ A.Chan A.DirUnknown (A.ChanAttributes False False) A.Int) foo False) ,testBoth "genDeclaration 202" "Channel* foo[8];const int foo_sizes[]={8};" - "csp::Chanin foo_actual[8];tockArrayView,1> foo(foo_actual,tockDims(8));" + "csp::Chanin foo_actual[8];const tockArrayView,1> foo=tockArrayView,1>(foo_actual,tockDims(8));" (tcall3 genDeclaration (A.Array [A.Dimension 8] $ A.Chan A.DirInput (A.ChanAttributes False False) A.Int) foo False) ,testBoth "genDeclaration 203" "Channel* foo[8*9];const int foo_sizes[]={8,9};" - "csp::Chanout foo_actual[8*9];tockArrayView,2> foo(foo_actual,tockDims(8,9));" + "csp::Chanout foo_actual[8*9];const tockArrayView,2> foo=tockArrayView,2>(foo_actual,tockDims(8,9));" (tcall3 genDeclaration (A.Array [A.Dimension 8, A.Dimension 9] $ A.Chan A.DirOutput (A.ChanAttributes False False) A.Int) foo False) @@ -479,7 +479,8 @@ testSpec = TestList --IsChannelArray: ,testAll 500 ("$(" ++ show chanInt ++ ")*foo[]={(&c),(&c)};const int foo_sizes[]={2};","") - ("$(" ++ show chanInt ++ ")*foo_actual[]={(&c),(&c)};$(" ++ show (A.Array [A.Dimension 2] $ chanInt) ++ ") foo(foo_actual,tockDims(2));","") + ("$(" ++ show chanInt ++ ")*foo_actual[]={(&c),(&c)};const $(" ++ show (A.Array [A.Dimension 2] $ chanInt) ++ ") foo=$(" + ++ show (A.Array [A.Dimension 2] $ chanInt) ++ ")(foo_actual,tockDims(2));","") $ A.IsChannelArray emptyMeta (A.Array [A.Dimension 2] $ chanInt) [A.Variable emptyMeta $ simpleName "c",A.Variable emptyMeta $ simpleName "c"]