From 6a3452f8cd706a98c24015d6bc831c158f7d1222 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Sat, 23 Feb 2008 18:32:29 +0000 Subject: [PATCH] Added a useful function to Pass for applying a modification function to the Only parts of a Structured --- common/Pass.hs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/common/Pass.hs b/common/Pass.hs index 1eea42f..751922c 100644 --- a/common/Pass.hs +++ b/common/Pass.hs @@ -34,6 +34,7 @@ import Errors import Metadata import PrettyShow import TreeUtils +import Utils -- | The monad in which AST-mangling passes operate. type PassM = ErrorT ErrorReport (StateT CompState (WriterT [WarningReport] IO)) @@ -137,6 +138,13 @@ debugAST p veryDebug $ pshow ps veryDebug $ "}}}" +applyToOnly :: (Monad m, Data a) => (a -> m a) -> A.Structured a -> m (A.Structured a) +applyToOnly f (A.Rep m r s) = applyToOnly f s >>* A.Rep m r +applyToOnly f (A.Spec m sp s) = applyToOnly f s >>* A.Spec m sp +applyToOnly f (A.ProcThen m p s) = applyToOnly f s >>* A.ProcThen m p +applyToOnly f (A.Several m ss) = mapM (applyToOnly f) ss >>* A.Several m +applyToOnly f (A.Only m o) = f o >>* A.Only m + -- | Make a generic rule for a pass. makeGeneric :: (Data t) => (forall s. Data s => s -> PassM s) -> t -> PassM t makeGeneric top