Added tests for introduceSpec and Is, for all types except arrays
This commit is contained in:
parent
683757d293
commit
062851dabf
|
@ -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
|
||||
|
|
|
@ -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 ()
|
||||
|
|
|
@ -483,8 +483,23 @@ testSpec = TestList
|
|||
$ A.IsChannelArray emptyMeta (A.Array [A.Dimension 2] $ chanInt)
|
||||
[A.Variable undefined undefined,A.Variable undefined undefined]
|
||||
|
||||
--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 Is
|
||||
--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
|
||||
|
|
Loading…
Reference in New Issue
Block a user