Added a test for genIf in the C and C++ backends
This commit is contained in:
parent
af74ac1039
commit
1f8a5555ac
|
@ -109,6 +109,7 @@ data GenOps = GenOps {
|
|||
genFuncMonadic :: GenOps -> Meta -> String -> A.Expression -> CGen (),
|
||||
-- | Gets the current time into the given variable
|
||||
genGetTime :: GenOps -> Meta -> A.Variable -> CGen (),
|
||||
-- | Generates an IF statement (which can have replicators, specifications and such things inside it).
|
||||
genIf :: GenOps -> Meta -> A.Structured -> CGen (),
|
||||
genInput :: GenOps -> A.Variable -> A.InputMode -> CGen (),
|
||||
genInputCase :: GenOps -> Meta -> A.Variable -> A.Structured -> CGen (),
|
||||
|
@ -1613,9 +1614,10 @@ cgenSeq ops s = call genStructured ops s doP
|
|||
cgenIf :: GenOps -> Meta -> A.Structured -> CGen ()
|
||||
cgenIf ops m s
|
||||
= do label <- makeNonce "if_end"
|
||||
tell ["/*",label,"*/"]
|
||||
genIfBody label s
|
||||
call genStop ops m "no choice matched in IF process"
|
||||
tell [label, ":\n;\n"]
|
||||
tell [label, ":;"]
|
||||
where
|
||||
genIfBody :: String -> A.Structured -> CGen ()
|
||||
genIfBody label s = call genStructured ops s doC
|
||||
|
@ -1623,10 +1625,10 @@ cgenIf ops m s
|
|||
doC (A.OnlyC m (A.Choice m' e p))
|
||||
= do tell ["if("]
|
||||
call genExpression ops e
|
||||
tell [") {\n"]
|
||||
tell ["){"]
|
||||
call genProcess ops p
|
||||
tell ["goto ", label, ";\n"]
|
||||
tell ["}\n"]
|
||||
tell ["goto ", label, ";"]
|
||||
tell ["}"]
|
||||
--}}}
|
||||
--{{{ case
|
||||
cgenCase :: GenOps -> Meta -> A.Expression -> A.Structured -> CGen ()
|
||||
|
|
|
@ -1186,9 +1186,9 @@ cppgenIf ops m s
|
|||
doC (A.OnlyC m (A.Choice m' e p))
|
||||
= do tell ["if("]
|
||||
call genExpression ops e
|
||||
tell [") {\n"]
|
||||
tell ["){"]
|
||||
call genProcess ops p
|
||||
tell ["throw ",ifExc, "(); }\n"]
|
||||
tell ["throw ",ifExc, "();}"]
|
||||
--}}}
|
||||
|
||||
|
||||
|
|
|
@ -148,12 +148,16 @@ testBothSameS ::
|
|||
-> Test
|
||||
testBothSameS n e a s = testBothS n e e a s
|
||||
|
||||
testBothSameR ::
|
||||
testBothR ::
|
||||
String -- ^ Test Name
|
||||
-> String -- ^ C and C++ expected
|
||||
-> String -- ^ C expected
|
||||
-> String -- ^ C++ expected
|
||||
-> (GenOps -> CGen ()) -- ^ Actual
|
||||
-> Test
|
||||
testBothSameR n e a = TestCase $ (testRS n e (a cgenOps) (return ())) >> (testRS n e (a cppgenOps) (return ())) >> (return ())
|
||||
testBothR n eC eCPP a = TestList [TestCase $ (testRS n eC (a cgenOps) (return ())) >> return (), TestCase $ (testRS n eCPP (a cppgenOps) (return ())) >> (return ())]
|
||||
|
||||
testBothSameR :: String -> String -> (GenOps -> CGen ()) -> Test
|
||||
testBothSameR n e a = testBothR n e e a
|
||||
|
||||
testBothFail :: String -> (GenOps -> CGen ()) -> Test
|
||||
testBothFail a b = testBothFailS a b (return ())
|
||||
|
@ -553,6 +557,22 @@ testGetTime = testBoth "testGetTime 0" "ProcTime(&@);" "csp::CurrentTime(&@);" (
|
|||
where
|
||||
over ops = ops {genVariable = override1 at}
|
||||
|
||||
testIf :: Test
|
||||
testIf = TestList
|
||||
[
|
||||
testBothR "testIf 0" "/\\*([[:alnum:]_]+)\\*/\\^\\1:;" "class ([[:alnum:]_]+)\\{\\};try\\{\\^\\}catch\\(\\1\\)\\{\\}"
|
||||
((tcall2 genIf emptyMeta (A.Several emptyMeta [])) . over)
|
||||
,testBothR "testIf 1" "/\\*([[:alnum:]_]+)\\*/if\\(\\$\\)\\{@goto \\1;\\}\\^\\1:;"
|
||||
"class ([[:alnum:]_]+)\\{\\};try\\{if\\(\\$\\)\\{@throw \\1\\(\\);\\}\\^\\}catch\\(\\1\\)\\{\\}"
|
||||
((tcall2 genIf emptyMeta (A.OnlyC emptyMeta $ A.Choice emptyMeta e p)) . over)
|
||||
]
|
||||
where
|
||||
e :: A.Expression
|
||||
e = undefined
|
||||
p :: A.Process
|
||||
p = undefined
|
||||
over ops = ops {genExpression = override1 dollar, genProcess = override1 at, genStop = override2 caret, genSpec = override2 hash}
|
||||
|
||||
---Returns the list of tests:
|
||||
tests :: Test
|
||||
tests = TestList
|
||||
|
@ -567,6 +587,7 @@ tests = TestList
|
|||
,testGenType
|
||||
,testGenVariable
|
||||
,testGetTime
|
||||
,testIf
|
||||
,testOverArray
|
||||
,testReplicator
|
||||
,testStop
|
||||
|
|
Loading…
Reference in New Issue
Block a user