diff --git a/backends/GenerateC.hs b/backends/GenerateC.hs index 6ab60ff..7e7ec21 100644 --- a/backends/GenerateC.hs +++ b/backends/GenerateC.hs @@ -1431,6 +1431,10 @@ cgenRecordTypeSpec n attr fs when (A.packedRecord attr || A.mobileRecord attr) $ tell [" occam_struct_packed "] genName n tell [";"] + tell ["typedef "] + genName n + origN <- lookupName n >>* A.ndOrigName + tell [" ", nameString $ A.Name emptyMeta origN, ";"] if null [t | (_, A.Mobile t) <- fs] then do genStatic TopLevel n tell ["const word "] @@ -1593,10 +1597,18 @@ genProcSpec lvl n (A.Proc _ (sm, rm) fs (Just p)) forwardDecl genName n tell [" (Workspace wptr"] sequence_ [do tell [", "] - t + case origT of + A.Record rn | forwardDecl + -> do origN <- lookupName rn >>* A.ndOrigName + ct <- call getCType (A.nameMeta rn) + (A.Record rn) am + tell [show $ replacePlainType (nameString rn) + (nameString $ A.Name emptyMeta origN) ct + ] + _ -> t tell [" "] n - | (t, n) <- rfs] + | (A.Formal am origT _, (t, n)) <- zip fs rfs] tell [")"] -- For externals, do nothing here: genProcSpec _ _ (A.Proc _ _ _ Nothing) _ = return () diff --git a/backends/GenerateCBased.hs b/backends/GenerateCBased.hs index 1695d44..690cdc6 100644 --- a/backends/GenerateCBased.hs +++ b/backends/GenerateCBased.hs @@ -270,6 +270,15 @@ instance Show CType where show (Template wr cts) = wr ++ "<" ++ concat (intersperse "," $ map (either show show) cts) ++ ">/**/" -- show (Subscript t) = "(" ++ show t ++ "[n])" +replacePlainType :: String -> String -> CType -> CType +replacePlainType old new (Const ct) = Const $ replacePlainType old new ct +replacePlainType old new (Pointer ct) = Pointer $ replacePlainType old new ct +replacePlainType old new (Template t xs) + = Template t $ [transformEither (replacePlainType old new) id x | x <- xs] +replacePlainType old new (Plain t) + | old == t = Plain new + | otherwise = Plain t + stripPointers :: CType -> CType stripPointers (Pointer t) = t stripPointers (Const (Pointer t)) = t