From 48c1bea7241a3f27a63080690be719a916b9b79a Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Wed, 24 Oct 2007 19:44:50 +0000 Subject: [PATCH] Added tests for the AllocMobile item in the C and C++ backends --- backends/GenerateC.hs | 3 +++ backends/GenerateCTest.hs | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/backends/GenerateC.hs b/backends/GenerateC.hs index c0ba821..b94f6a5 100644 --- a/backends/GenerateC.hs +++ b/backends/GenerateC.hs @@ -72,6 +72,7 @@ data GenOps = GenOps { genActual :: GenOps -> A.Actual -> CGen (), -- | Generates the list of actual parameters to a function\/proc. genActuals :: GenOps -> [A.Actual] -> CGen (), + genAllocMobile :: GenOps -> Meta -> A.Type -> Maybe A.Expression -> CGen(), genAlt :: GenOps -> Bool -> A.Structured -> CGen (), -- | Generates the given array element expressions as a flattened (one-dimensional) list of literals genArrayLiteralElems :: GenOps -> [A.ArrayElem] -> CGen (), @@ -869,6 +870,8 @@ cgenExpression ops (A.IntrinsicFunctionCall m s es) = call genIntrinsicFunction --cgenExpression ops (A.BytesInExpr m e) cgenExpression ops (A.BytesInType m t) = call genBytesIn ops t (Left False) --cgenExpression ops (A.OffsetOf m t n) +--cgenExpression ops (A.ExprConstr {}) +cgenExpression ops (A.AllocMobile m t me) = call genAllocMobile ops m t me cgenExpression ops t = call genMissing ops $ "genExpression " ++ show t cgenSizeSuffix :: GenOps -> String -> CGen () diff --git a/backends/GenerateCTest.hs b/backends/GenerateCTest.hs index b4d16a1..e0a95a1 100644 --- a/backends/GenerateCTest.hs +++ b/backends/GenerateCTest.hs @@ -1050,6 +1050,17 @@ testBytesIn = TestList where over ops = ops {genVariable = override1 dollar, genSizeSuffix = (\_ n -> tell["(@",n,")"])} +testMobile :: Test +testMobile = TestList + [ + testBoth "testMobile 0" "malloc(#(Int Left False))" "new Int" ((tcall3 genAllocMobile emptyMeta (A.Mobile A.Int) Nothing) . over) + ,TestCase $ assertGen "testMobile 1/C++" "new Int($)" $ (evalStateT (runErrorT (execWriterT $ call genAllocMobile (over cppgenOps) emptyMeta (A.Mobile A.Int) (Just undefined))) emptyState) + ] + where + showBytesInParams _ t (Right _) = tell ["#(" ++ show t ++ " Right)"] + showBytesInParams _ t v = tell ["#(" ++ show t ++ " " ++ show v ++ ")"] + over ops = ops {genBytesIn = showBytesInParams, genType = (\_ t -> tell [show t]), genExpression = override1 dollar} + ---Returns the list of tests: tests :: Test tests = TestList @@ -1068,6 +1079,7 @@ tests = TestList ,testGetTime ,testIf ,testInput + ,testMobile ,testOutput ,testOverArray ,testReplicator