Added a test for genReplicator
This commit is contained in:
parent
25e7e0ef2b
commit
8b95ae00f0
|
@ -122,7 +122,9 @@ data GenOps = GenOps {
|
||||||
genPar :: GenOps -> A.ParMode -> A.Structured -> CGen (),
|
genPar :: GenOps -> A.ParMode -> A.Structured -> CGen (),
|
||||||
genProcCall :: GenOps -> A.Name -> [A.Actual] -> CGen (),
|
genProcCall :: GenOps -> A.Name -> [A.Actual] -> CGen (),
|
||||||
genProcess :: GenOps -> A.Process -> CGen (),
|
genProcess :: GenOps -> A.Process -> CGen (),
|
||||||
|
-- | Generates a replicator loop, given the replicator and body
|
||||||
genReplicator :: GenOps -> A.Replicator -> CGen () -> CGen (),
|
genReplicator :: GenOps -> A.Replicator -> CGen () -> CGen (),
|
||||||
|
-- | Generates the three bits of a for loop (e.g. "int i=0;i<10;i++" for the given replicator
|
||||||
genReplicatorLoop :: GenOps -> A.Replicator -> CGen (),
|
genReplicatorLoop :: GenOps -> A.Replicator -> CGen (),
|
||||||
genRetypeSizes :: GenOps -> Meta -> A.AbbrevMode -> A.Type -> A.Name -> A.Type -> A.Variable -> CGen (),
|
genRetypeSizes :: GenOps -> Meta -> A.AbbrevMode -> A.Type -> A.Name -> A.Type -> A.Variable -> CGen (),
|
||||||
genSeq :: GenOps -> A.Structured -> CGen (),
|
genSeq :: GenOps -> A.Structured -> CGen (),
|
||||||
|
@ -985,9 +987,9 @@ cgenReplicator :: GenOps -> A.Replicator -> CGen () -> CGen ()
|
||||||
cgenReplicator ops rep body
|
cgenReplicator ops rep body
|
||||||
= do tell ["for("]
|
= do tell ["for("]
|
||||||
call genReplicatorLoop ops rep
|
call genReplicatorLoop ops rep
|
||||||
tell [") {\n"]
|
tell ["){"]
|
||||||
body
|
body
|
||||||
tell ["}\n"]
|
tell ["}"]
|
||||||
|
|
||||||
isZero :: A.Expression -> Bool
|
isZero :: A.Expression -> Bool
|
||||||
isZero (A.Literal _ A.Int (A.IntLiteral _ "0")) = True
|
isZero (A.Literal _ A.Int (A.IntLiteral _ "0")) = True
|
||||||
|
|
|
@ -65,7 +65,7 @@ assertGenR n exp act
|
||||||
Right ss ->
|
Right ss ->
|
||||||
case matchRegex (mkRegex exp) (subRegex (mkRegex "/\\*\\*/") (concat ss) "") of
|
case matchRegex (mkRegex exp) (subRegex (mkRegex "/\\*\\*/") (concat ss) "") of
|
||||||
Just matches -> return matches
|
Just matches -> return matches
|
||||||
Nothing -> (assertFailure $ n ++ " regex match failed, regex: \"" ++ show exp ++ "\" text: " ++ (concat ss)) >> return []
|
Nothing -> (assertFailure $ n ++ " regex match failed, regex: \"" ++ exp ++ "\" text: " ++ (concat ss)) >> return []
|
||||||
|
|
||||||
|
|
||||||
-- | Asserts that the given output of a CGen pass is a failure
|
-- | Asserts that the given output of a CGen pass is a failure
|
||||||
|
@ -129,6 +129,13 @@ testBothSameS ::
|
||||||
-> Test
|
-> Test
|
||||||
testBothSameS n e a s = testBothS n e e a s
|
testBothSameS n e a s = testBothS n e e a s
|
||||||
|
|
||||||
|
testBothSameR ::
|
||||||
|
String -- ^ Test Name
|
||||||
|
-> String -- ^ C and C++ expected
|
||||||
|
-> (GenOps -> CGen ()) -- ^ Actual
|
||||||
|
-> Test
|
||||||
|
testBothSameR n e a = TestCase $ (testRS n e (a cgenOps) (return ())) >> (testRS n e (a cppgenOps) (return ())) >> (return ())
|
||||||
|
|
||||||
testBothFail :: String -> (GenOps -> CGen ()) -> Test
|
testBothFail :: String -> (GenOps -> CGen ()) -> Test
|
||||||
testBothFail a b = testBothFailS a b (return ())
|
testBothFail a b = testBothFailS a b (return ())
|
||||||
|
|
||||||
|
@ -291,6 +298,13 @@ testOverArray = TestList $ map testOverArray'
|
||||||
state1 = defineName (simpleName "foo") $ simpleDefDecl "foo" (A.Array [A.Dimension 7] A.Int)
|
state1 = defineName (simpleName "foo") $ simpleDefDecl "foo" (A.Array [A.Dimension 7] A.Int)
|
||||||
state3 = defineName (simpleName "foo") $ simpleDefDecl "foo" (A.Array [A.Dimension 7, A.Dimension 8, A.Dimension 9] A.Int)
|
state3 = defineName (simpleName "foo") $ simpleDefDecl "foo" (A.Array [A.Dimension 7, A.Dimension 8, A.Dimension 9] A.Int)
|
||||||
|
|
||||||
|
testReplicator :: Test
|
||||||
|
testReplicator = TestList
|
||||||
|
[
|
||||||
|
testBothSame "testReplicator 0" "for(int foo=0;foo<10;foo++){@}" (tcall2 genReplicator (A.For emptyMeta foo (intLiteral 0) (intLiteral 10)) at)
|
||||||
|
,testBothSameR "testReplicator 1" "for\\(int ([[:alnum:]_]+)=10,foo=1;\\1>0;\\1--,foo\\+\\+\\)\\{@\\}" (tcall2 genReplicator (A.For emptyMeta foo (intLiteral 1) (intLiteral 10)) at)
|
||||||
|
]
|
||||||
|
|
||||||
testDeclaration :: Test
|
testDeclaration :: Test
|
||||||
testDeclaration = TestList
|
testDeclaration = TestList
|
||||||
[
|
[
|
||||||
|
@ -343,5 +357,6 @@ tests = TestList
|
||||||
,testDeclaration
|
,testDeclaration
|
||||||
,testGenType
|
,testGenType
|
||||||
,testOverArray
|
,testOverArray
|
||||||
|
,testReplicator
|
||||||
,testStop
|
,testStop
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user