From 2941cbd04975c4996032f4ca5a86268189b3ecc6 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Tue, 31 Mar 2009 16:50:42 +0000 Subject: [PATCH] Fixed a problem with record abbreviations being pulled all the way up to the top (which C doesn't like) --- backends/GenerateC.hs | 2 +- transformations/Unnest.hs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/backends/GenerateC.hs b/backends/GenerateC.hs index abd9e8d..85758dc 100644 --- a/backends/GenerateC.hs +++ b/backends/GenerateC.hs @@ -792,7 +792,7 @@ cgetCType m origT am (A.Record n, _, False, A.Original) -> return $ Plain $ nameString n -- Abbrev and ValAbbrev, and mobile: - (A.Record n, _, False, _) -> return $ Pointer $ const $ Plain $ nameString n + (A.Record n, _, False, _) -> return $ Const . Pointer $ const $ Plain $ nameString n (A.Record n, _, True, A.Abbrev) -> return $ Pointer $ Pointer $ Plain $ nameString n (A.Record n, _, True, _) -> return $ Pointer $ const $ Plain $ nameString n diff --git a/transformations/Unnest.hs b/transformations/Unnest.hs index 24965a6..8be69f8 100644 --- a/transformations/Unnest.hs +++ b/transformations/Unnest.hs @@ -218,7 +218,7 @@ removeNesting = pass "Pull nested definitions to top level" doStructured s@(A.Spec m spec subS) = do spec'@(A.Specification _ n st) <- recurse spec isConst <- isConstantName n - if isConst || canPull st then + if (isConst && not (abbrevRecord st)) || canPull st then do debug $ "removeNesting: pulling up " ++ show n addPulled $ (m, Left spec') doStructured subS @@ -232,3 +232,9 @@ removeNesting = pass "Pull nested definitions to top level" canPull (A.ProtocolCase _ _) = True canPull _ = False + -- C doesn't allow us to pull up pointers to records to the top-level + abbrevRecord :: A.SpecType -> Bool + abbrevRecord (A.Is _ _ (A.Record {}) _) = True + abbrevRecord _ = False + +