From 83f654a2739c970363d1f2395d947aa4b8fada22 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Wed, 24 Oct 2007 20:54:37 +0000 Subject: [PATCH] Implemented the code for ClearMobile in the C and C++ backends --- backends/GenerateC.hs | 13 +++++++++++++ backends/GenerateCPPCSP.hs | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/backends/GenerateC.hs b/backends/GenerateC.hs index 17e0984..8b932e2 100644 --- a/backends/GenerateC.hs +++ b/backends/GenerateC.hs @@ -197,6 +197,7 @@ cgenOps = GenOps { genBytesIn = cgenBytesIn, genCase = cgenCase, genCheckedConversion = cgenCheckedConversion, + genClearMobile = cgenClearMobile, genConversion = cgenConversion, genConversionSymbol = cgenConversionSymbol, genDecl = cgenDecl, @@ -1855,4 +1856,16 @@ cgenAllocMobile ops m (A.Mobile t) Nothing = tell ["malloc("] >> call genBytesIn -- into a subsequent assignment cgenAllocMobile ops _ _ _ = call genMissing ops "Mobile allocation with initialising-expression" +cgenClearMobile :: GenOps -> Meta -> A.Variable -> CGen () +cgenClearMobile ops _ v + = do tell ["if("] + genVar + tell ["!=NULL){free("] + genVar + tell [");"] + genVar + tell ["=NULL;}"] + where + genVar = call genVariable ops v + --}}} diff --git a/backends/GenerateCPPCSP.hs b/backends/GenerateCPPCSP.hs index 8d1c884..be8ee85 100644 --- a/backends/GenerateCPPCSP.hs +++ b/backends/GenerateCPPCSP.hs @@ -103,6 +103,7 @@ cppgenOps = cgenOps { genArraySizesLiteral = cppgenArraySizesLiteral, genArrayStoreName = cppgenArrayStoreName, genArraySubscript = cppgenArraySubscript, + genClearMobile = cppgenClearMobile, genDeclType = cppgenDeclType, genDeclaration = cppgenDeclaration, genDirectedVariable = cppgenDirectedVariable, @@ -1115,3 +1116,15 @@ cppgenAllocMobile ops m (A.Mobile t) me case me of Just e -> tell ["("] >> call genExpression ops e >> tell [")"] Nothing -> return () + +cppgenClearMobile :: GenOps -> Meta -> A.Variable -> CGen () +cppgenClearMobile ops _ v + = do tell ["if("] + genVar + tell ["!=NULL){delete "] + genVar + tell [";"] + genVar + tell ["=NULL;}"] + where + genVar = call genVariable ops v