From 02c444be95ee5f25d04b8f3e728c44231627740f Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Tue, 10 Jun 2008 13:57:01 +0000 Subject: [PATCH] Update abbrevation types in the state too. This makes cgtest82 work, although I'm not very happy with it as a fix. I'd rather have a way of ensuring the state's definitions are kept up to date when we change something in the AST. --- transformations/SimplifyAbbrevs.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/transformations/SimplifyAbbrevs.hs b/transformations/SimplifyAbbrevs.hs index 4a0c92b..aa03c06 100644 --- a/transformations/SimplifyAbbrevs.hs +++ b/transformations/SimplifyAbbrevs.hs @@ -27,6 +27,7 @@ import Data.Generics import qualified AST as A import CompState +import Control.Monad.State import Metadata import Pass import qualified Properties as Prop @@ -37,6 +38,7 @@ simplifyAbbrevs :: [Pass] simplifyAbbrevs = [ removeInitial , removeResult + , updateAbbrevsInState ] -- | Rewrite 'InitialAbbrev' into a variable and an assignment. @@ -168,3 +170,15 @@ removeResult doAbbrevMode A.ResultAbbrev = A.Abbrev doAbbrevMode s = s +-- | Rewrite abbreviation modes in the state. +updateAbbrevsInState :: Pass +updateAbbrevsInState + = pass "Update INITIAL and RESULT abbreviations in state" + [Prop.initialRemoved, Prop.resultRemoved] + [] + (\v -> get >>= applyDepthM (return . doAbbrevMode) >>= put >> return v) + where + doAbbrevMode :: A.AbbrevMode -> A.AbbrevMode + doAbbrevMode A.InitialAbbrev = A.Original + doAbbrevMode A.ResultAbbrev = A.Abbrev + doAbbrevMode s = s