Move everywhereASTM into Pass.

This commit is contained in:
Adam Sampson 2008-03-19 18:11:49 +00:00
parent 79eefd5e98
commit b8caf7c3b6
2 changed files with 11 additions and 9 deletions

View File

@ -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

View File

@ -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)