From 062851dabfa79a49f1875d0b5ab9cdbf4ce1f9fb Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Sat, 6 Oct 2007 15:55:18 +0000 Subject: [PATCH] Added tests for introduceSpec and Is, for all types except arrays --- backends/GenerateC.hs | 11 ++++++----- backends/GenerateCPPCSP.hs | 16 ++++++++-------- backends/GenerateCTest.hs | 24 ++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/backends/GenerateC.hs b/backends/GenerateC.hs index c859bc3..de2e48a 100644 --- a/backends/GenerateC.hs +++ b/backends/GenerateC.hs @@ -450,9 +450,10 @@ cgenDeclType ops am t call genType ops t case t of A.Array _ _ -> return () - A.Chan {} -> return () - A.Record _ -> tell [" *"] - _ -> when (am == A.Abbrev) $ tell [" *"] + A.Chan A.DirInput _ _ -> return () + A.Chan A.DirOutput _ _ -> return () + A.Record _ -> tell ["*const"] + _ -> when (am == A.Abbrev) $ tell ["*const"] cgenDecl :: GenOps -> A.AbbrevMode -> A.Type -> A.Name -> CGen () cgenDecl ops am t n @@ -1281,9 +1282,9 @@ cintroduceSpec ops (A.Specification m n (A.Declaration _ t)) cintroduceSpec ops (A.Specification _ n (A.Is _ am t v)) = do let (rhs, rhsSizes) = abbrevVariable ops am t v call genDecl ops am t n - tell [" = "] + tell ["="] rhs - tell [";\n"] + tell [";"] rhsSizes n cintroduceSpec ops (A.Specification _ n (A.IsExpr _ am t e)) = do let (rhs, rhsSizes) = abbrevExpression ops am t e diff --git a/backends/GenerateCPPCSP.hs b/backends/GenerateCPPCSP.hs index 93d738b..b7e1a39 100644 --- a/backends/GenerateCPPCSP.hs +++ b/backends/GenerateCPPCSP.hs @@ -888,15 +888,14 @@ cppintroduceSpec ops (A.Specification _ n (A.Proc _ sm fs p)) genParamList :: [A.Formal] -> CGen() genParamList fs = infixComma $ map genParam fs --- FIXME: We could just fall through to cintroduceSpec as the last clause... ---This clause is unchanged from GenerateC: +-- Changed because we use cppabbrevVariable instead of abbrevVariable: cppintroduceSpec ops (A.Specification _ n (A.Is _ am t v)) = do let rhs = cppabbrevVariable ops am t v call genDecl ops am t n - tell [" = "] + tell ["="] rhs - tell [";\n"] ---Clause only changed to use Blitz++ rather than C arrays: + tell [";"] +--Clause only changed to use C++ rather than C arrays: cppintroduceSpec ops (A.Specification _ n (A.IsExpr _ am t e)) = do let rhs = cppabbrevExpression ops am t e case (am, t, e) of @@ -1210,9 +1209,10 @@ cppgenDeclType ops am t do when (am == A.ValAbbrev) $ tell ["const "] call genType ops t case t of - A.Chan {} -> return () - A.Record _ -> tell [" *"] - _ -> when (am == A.Abbrev) $ tell [" *"] + A.Chan A.DirInput _ _ -> return () + A.Chan A.DirOutput _ _ -> return () + A.Record _ -> tell ["*const"] + _ -> when (am == A.Abbrev) $ tell ["*const"] -- | Changed because C++CSP has channel-ends as concepts (whereas CCSP does not) cppgenDirectedVariable :: GenOps -> CGen () -> A.Direction -> CGen () diff --git a/backends/GenerateCTest.hs b/backends/GenerateCTest.hs index 5e89c43..7ca6ec3 100644 --- a/backends/GenerateCTest.hs +++ b/backends/GenerateCTest.hs @@ -483,8 +483,23 @@ testSpec = TestList $ A.IsChannelArray emptyMeta (A.Array [A.Dimension 2] $ chanInt) [A.Variable undefined undefined,A.Variable undefined undefined] - - --TODO Is + --Is: + + -- Plain types require you to take an address to get the pointer: + ,testAllSameForTypes 600 (\t -> ("$(" ++ show t ++ ")*const foo=&@;","")) (\t -> A.Is emptyMeta A.Abbrev t (A.Variable undefined undefined)) [A.Int,A.Time] + -- Arrays and records are already pointers, so no need to take the address: + ,testAllSameForTypes 610 (\t -> ("$(" ++ show t ++ ")*const foo=@;","")) (\t -> A.Is emptyMeta A.Abbrev t (A.Variable undefined undefined)) [chanInt,A.Record foo] + --Abbreviations of channel-ends in C++ should just copy the channel-end, rather than trying to take the address of the temporary returned by writer()/reader() + --C abbreviations will be of type Channel*, so they can just copy the channel address. + ,testAllSameForTypes 620 (\t -> ("$(" ++ show t ++ ") foo=@;","")) (\t -> A.Is emptyMeta A.Abbrev t (A.Variable undefined undefined)) [chanIntIn,chanIntOut] + + ,testAllSameForTypes 700 (\t -> ("const $(" ++ show t ++ ") foo=@;","")) (\t -> A.Is emptyMeta A.ValAbbrev t (A.Variable undefined undefined)) [A.Int,A.Time] + ,testAllSameForTypes 710 (\t -> ("const $(" ++ show t ++ ")*const foo=@;","")) (\t -> A.Is emptyMeta A.ValAbbrev t (A.Variable undefined undefined)) [A.Record foo] + -- I don't think ValAbbrev of channels/channel-ends makes much sense (occam doesn't support it, certainly) so they are not tested here. + + --TODO test Is more (involving subscripts, arrays and slices) + + --TODO IsExpr --TODO Protocol --TODO ProtocolCase @@ -492,7 +507,12 @@ testSpec = TestList --TODO Retypes ] where + testAllSameForTypes :: Int -> (A.Type -> (String, String)) -> (A.Type -> A.SpecType) -> [A.Type] -> Test + testAllSameForTypes n te spec ts = TestList [testAllSame (n+i) (te t) (spec t) | (i,t) <- zip [0..] ts] + chanInt = A.Chan A.DirUnknown (A.ChanAttributes False False) A.Int + chanIntIn = A.Chan A.DirInput (A.ChanAttributes False False) A.Int + chanIntOut = A.Chan A.DirOutput (A.ChanAttributes False False) A.Int testAll :: Int -> (String,String) -> (String,String) -> A.SpecType -> Test testAll n (eCI,eCR) (eCPPI,eCPPR) spec = TestList