Moved the comma-related helper functions to the GenerateCBased module

This commit is contained in:
Neil Brown 2009-03-20 19:24:20 +00:00
parent 3a7b2aaaf4
commit bbabef868c
3 changed files with 12 additions and 21 deletions

View File

@ -25,7 +25,6 @@ module GenerateC
, cintroduceSpec , cintroduceSpec
, cPreReq , cPreReq
, cremoveSpec , cremoveSpec
, genComma
, genCPasses , genCPasses
, generate , generate
, generateC , generateC
@ -34,7 +33,6 @@ module GenerateC
, genName , genName
, genRightB , genRightB
, justOnly , justOnly
, seqComma
, withIf , withIf
) where ) where
@ -245,12 +243,6 @@ cgenMissing :: String -> CGen ()
cgenMissing s = tell ["\n#error Unimplemented: ", s, "\n"] cgenMissing s = tell ["\n#error Unimplemented: ", s, "\n"]
--{{{ simple punctuation --{{{ simple punctuation
genComma :: CGen ()
genComma = tell [","]
seqComma :: [CGen ()] -> CGen ()
seqComma ps = sequence_ $ intersperse genComma ps
genLeftB :: CGen () genLeftB :: CGen ()
genLeftB = tell ["{"] genLeftB = tell ["{"]

View File

@ -21,9 +21,8 @@ module GenerateCBased where
import Control.Monad.Reader import Control.Monad.Reader
import Control.Monad.State import Control.Monad.State
import Control.Monad.Writer hiding (tell) import Control.Monad.Writer
import Data.Generics import Data.Generics
import Data.List
import System.IO import System.IO
import qualified AST as A import qualified AST as A
@ -228,6 +227,12 @@ fget = asks
generate :: GenOps -> Handle -> A.AST -> PassM () generate :: GenOps -> Handle -> A.AST -> PassM ()
generate ops h ast = evalStateT (runReaderT (call genTopLevel ast) ops) (Right h) generate ops h ast = evalStateT (runReaderT (call genTopLevel ast) ops) (Right h)
genComma :: CGen ()
genComma = tell [","]
seqComma :: [CGen ()] -> CGen ()
seqComma ps = sequence_ $ intersperse genComma ps
-- C or C++ type, really. -- C or C++ type, really.
data CType data CType
= Plain String = Plain String

View File

@ -40,7 +40,7 @@ import System.IO
import qualified AST as A import qualified AST as A
import CompState import CompState
import GenerateC (cgenOps, cgenReplicatorLoop, cgetCType, cintroduceSpec, import GenerateC (cgenOps, cgenReplicatorLoop, cgetCType, cintroduceSpec,
generate, genComma, genLeftB, genMeta, genName, genRightB, justOnly, seqComma, withIf) generate, genLeftB, genMeta, genName, genRightB, justOnly, withIf)
import GenerateCBased import GenerateCBased
import Errors import Errors
import Metadata import Metadata
@ -157,7 +157,7 @@ cppgenTopLevel s
"(csp::InSequenceOneThread ( new proc_"] "(csp::InSequenceOneThread ( new proc_"]
genName name genName name
tell ["("] tell ["("]
infixComma $ map tlpChannel chans seqComma $ map tlpChannel chans
tell [")) (new LethalProcess()) ) );", tell [")) (new LethalProcess()) ) );",
"csp::End_CPPCSP(); return 0;}\n"] "csp::End_CPPCSP(); return 0;}\n"]
where where
@ -361,12 +361,6 @@ isPoint (A.Record _) = True
isPoint (A.Array _ _) = True isPoint (A.Array _ _) = True
isPoint _ = False isPoint _ = False
-- FIXME Should be a generic helper somewhere (along with the others from GenerateC)
-- | Helper function to place a comma between items, but not before or after
infixComma :: [CGen ()] -> CGen ()
infixComma (c0:cs) = c0 >> sequence_ [genComma >> c | c <- cs]
infixComma [] = return ()
cppgenOutputCase :: A.Variable -> A.Name -> [A.OutputItem] -> CGen () cppgenOutputCase :: A.Variable -> A.Name -> [A.OutputItem] -> CGen ()
cppgenOutputCase c tag ois cppgenOutputCase c tag ois
= do t <- astTypeOf c = do t <- astTypeOf c
@ -470,7 +464,7 @@ cppgenAlt _ s
-- | In GenerateC this uses prefixComma (because "Process * me" is always the first argument), but here we use infixComma. -- | In GenerateC this uses prefixComma (because "Process * me" is always the first argument), but here we use infixComma.
cppgenActuals :: [A.Formal] -> [A.Actual] -> CGen () cppgenActuals :: [A.Formal] -> [A.Actual] -> CGen ()
cppgenActuals fs as = infixComma [call genActual f a | (f, a) <- zip fs as] cppgenActuals fs as = seqComma [call genActual f a | (f, a) <- zip fs as]
-- | The only change from GenerateC is that passing "me" is not necessary in C++CSP -- | The only change from GenerateC is that passing "me" is not necessary in C++CSP
cppgenProcCall :: A.Name -> [A.Actual] -> CGen () cppgenProcCall :: A.Name -> [A.Actual] -> CGen ()
@ -516,7 +510,7 @@ cppdeclareFree _ _ _ = Nothing
--Therefore these functions are not part of GenOps. They are called directly by cppgenForwardDeclaration and cppintroduceSpec. --Therefore these functions are not part of GenOps. They are called directly by cppgenForwardDeclaration and cppintroduceSpec.
--To use for a constructor list, pass prefixUnderscore as the function, otherwise pass the identity function --To use for a constructor list, pass prefixUnderscore as the function, otherwise pass the identity function
cppgenFormals :: (A.Name -> A.Name) -> [A.Formal] -> CGen () cppgenFormals :: (A.Name -> A.Name) -> [A.Formal] -> CGen ()
cppgenFormals nameFunc list = infixComma (map (cppgenFormal nameFunc) list) cppgenFormals nameFunc list = seqComma (map (cppgenFormal nameFunc) list)
--Changed as genFormals --Changed as genFormals
cppgenFormal :: (A.Name -> A.Name) -> A.Formal -> CGen () cppgenFormal :: (A.Name -> A.Name) -> A.Formal -> CGen ()
@ -606,7 +600,7 @@ cppintroduceSpec (A.Specification _ n (A.Proc _ (sm, _) fs p))
--A helper function for calling the wrapped functions: --A helper function for calling the wrapped functions:
genParamList :: [A.Formal] -> CGen() genParamList :: [A.Formal] -> CGen()
genParamList fs = infixComma $ map genParam fs genParamList fs = seqComma $ map genParam fs
cppintroduceSpec (A.Specification _ n (A.Is _ am t@(A.Array ds c@(A.ChanEnd {})) dirV@(A.DirectedVariable cppintroduceSpec (A.Specification _ n (A.Is _ am t@(A.Array ds c@(A.ChanEnd {})) dirV@(A.DirectedVariable
m dir v))) m dir v)))
= do t' <- if A.UnknownDimension `elem` ds = do t' <- if A.UnknownDimension `elem` ds