Moved the definition of record types into the forward declarations

This commit is contained in:
Neil Brown 2008-02-27 18:25:14 +00:00
parent cfc3577c21
commit 9ab4563a2c
3 changed files with 17 additions and 16 deletions

View File

@ -109,6 +109,7 @@ cgenOps = GenOps {
genPar = cgenPar,
genProcCall = cgenProcCall,
genProcess = cgenProcess,
genRecordTypeSpec = cgenRecordTypeSpec,
genReplicator = cgenReplicator,
genReplicatorLoop = cgenReplicatorLoop,
genRetypeSizes = cgenRetypeSizes,
@ -1288,13 +1289,7 @@ cintroduceSpec (A.Specification _ n (A.IsChannelArray _ (A.Array _ c) cs))
tell ["};"]
call declareArraySizes (A.Array [A.Dimension $ length cs] c) n
cintroduceSpec (A.Specification _ _ (A.DataType _ _)) = return ()
cintroduceSpec (A.Specification _ n (A.RecordType _ b fs))
= do tell ["typedef struct{"]
sequence_ [call genDeclaration t n True | (n, t) <- fs]
tell ["}"]
when b $ tell [" occam_struct_packed "]
genName n
tell [";"]
cintroduceSpec (A.Specification _ _ (A.RecordType _ _ _)) = return ()
cintroduceSpec (A.Specification _ n (A.Protocol _ _)) = return ()
cintroduceSpec (A.Specification _ n (A.ProtocolCase _ ts))
= do tell ["typedef enum{"]
@ -1338,6 +1333,16 @@ cintroduceSpec (A.Specification _ n (A.Retypes m am t v))
--cintroduceSpec (A.Specification _ n (A.RetypesExpr _ am t e))
cintroduceSpec n = call genMissing $ "introduceSpec " ++ show n
cgenRecordTypeSpec :: A.Name -> Bool -> [(A.Name, A.Type)] -> CGen ()
cgenRecordTypeSpec n b fs
= do tell ["typedef struct{"]
sequence_ [call genDeclaration t n True | (n, t) <- fs]
tell ["}"]
when b $ tell [" occam_struct_packed "]
genName n
tell [";"]
cgenForwardDeclaration :: A.Specification -> CGen ()
cgenForwardDeclaration (A.Specification _ n (A.Proc _ sm fs _))
= do call genSpecMode sm
@ -1346,6 +1351,8 @@ cgenForwardDeclaration (A.Specification _ n (A.Proc _ sm fs _))
tell [" (Process *me"]
call genFormals fs
tell [");"]
cgenForwardDeclaration (A.Specification _ n (A.RecordType _ b fs))
= call genRecordTypeSpec n b fs
cgenForwardDeclaration _ = return ()
cremoveSpec :: A.Specification -> CGen ()

View File

@ -145,6 +145,7 @@ data GenOps = GenOps {
genPar :: A.ParMode -> A.Structured A.Process -> CGen (),
genProcCall :: A.Name -> [A.Actual] -> CGen (),
genProcess :: A.Process -> CGen (),
genRecordTypeSpec :: A.Name -> Bool -> [(A.Name, A.Type)] -> CGen (),
-- | Generates a replicator loop, given the replicator and body
genReplicator :: A.Replicator -> CGen () -> CGen (),
-- | Generates the three bits of a for loop (e.g. "int i=0;i<10;i++" for the given replicator

View File

@ -725,6 +725,8 @@ cppgenForwardDeclaration (A.Specification _ n (A.Proc _ sm fs _))
genConstructorList :: [A.Formal] -> CGen ()
genConstructorList fs = mapM_ genConsItem fs
cppgenForwardDeclaration (A.Specification _ n (A.RecordType _ b fs))
= call genRecordTypeSpec n b fs
cppgenForwardDeclaration _ = return ()
cppintroduceSpec :: A.Specification -> CGen ()
@ -805,15 +807,6 @@ cppintroduceSpec (A.Specification _ n (A.IsExpr _ am t e))
rhs
tell [";\n"]
--This clause was simplified, because we don't need separate array sizes in C++:
cppintroduceSpec (A.Specification _ n (A.RecordType _ b fs))
= do tell ["typedef struct{"]
sequence_ [call genDeclaration t n True
| (n, t) <- fs]
tell ["}"]
when b $ tell [" occam_struct_packed "]
genName n
tell [";"]
--Clause changed to handle array retyping
cppintroduceSpec (A.Specification _ n (A.Retypes m am t v))
= do origT <- typeOfVariable v