From b8caf7c3b6fd1106da6f8237843158f1aa303342 Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Wed, 19 Mar 2008 18:11:49 +0000 Subject: [PATCH] Move everywhereASTM into Pass. --- frontends/RainTypes.hs | 9 --------- pass/Pass.hs | 11 +++++++++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/frontends/RainTypes.hs b/frontends/RainTypes.hs index 1573ba8..e4c8949 100644 --- a/frontends/RainTypes.hs +++ b/frontends/RainTypes.hs @@ -47,15 +47,6 @@ recordInfNameTypes = everywhereM (mkM recordInfNameTypes') return input recordInfNameTypes' r = return r -everywhereASTM :: (Data s, Data t) => (s -> PassM s) -> t -> PassM t -everywhereASTM f = doGeneric `extM` (doSpecific f) - where - doGeneric :: Data t => t -> PassM t - doGeneric = makeGeneric (everywhereASTM f) - - doSpecific :: Data t => (t -> PassM t) -> t -> PassM t - doSpecific f x = (doGeneric x >>= f) - -- | Folds all constants. constantFoldPass :: Data t => t -> PassM t constantFoldPass = everywhereASTM doExpression diff --git a/pass/Pass.hs b/pass/Pass.hs index 26b5e0d..f967512 100644 --- a/pass/Pass.hs +++ b/pass/Pass.hs @@ -194,6 +194,17 @@ makeGeneric top `extM` (return :: String -> m String) `extM` (return :: Meta -> m Meta) +-- | Apply a monadic operation everywhere that it matches in the AST, going +-- depth-first. +everywhereASTM :: (Data s, Data t) => (s -> PassM s) -> t -> PassM t +everywhereASTM f = doGeneric `extM` (doSpecific f) + where + doGeneric :: Data t => t -> PassM t + doGeneric = makeGeneric (everywhereASTM f) + + doSpecific :: Data t => (t -> PassM t) -> t -> PassM t + doSpecific f x = (doGeneric x >>= f) + excludeConstr :: (Data a, CSMR m) => [Constr] -> a -> m a excludeConstr cons x = if null items then return x else dieInternal (Nothing, "Excluded item still remains in source tree: " ++ (show $ head items) ++ " tree is: " ++ pshow x)