HaRe-0.7.1.3: the Haskell Refactorer.

Safe HaskellNone

Language.Haskell.Refact.Utils.GhcUtils

Contents

Description

This module contains routines used to perform generic traversals of the GHC AST, avoiding the traps resulting from certain fields being populated with values defined to trigger an error if ever evaluated.

This is a useful feature for tracking down bugs in GHC, but makes use of the GHC library problematic.

Synopsis

SYB versions

everythingButStaged :: Stage -> (r -> r -> r) -> r -> GenericQ (r, Bool) -> GenericQ rSource

somethingStaged :: Stage -> Maybe u -> GenericQ (Maybe u) -> GenericQ (Maybe u)Source

Look up a subterm by means of a maybe-typed filter

everythingStaged :: Stage -> (r -> r -> r) -> r -> GenericQ r -> GenericQ rSource

Staged variation of SYB.everything The stage must be provided to avoid trying to modify elements which may not be present at all stages of AST processing. Note: Top-down order

somewhereMStaged :: MonadPlus m => Stage -> GenericM m -> GenericM mSource

Apply a monadic transformation at least somewhere

somewhereMStagedBu :: MonadPlus m => Stage -> GenericM m -> GenericM mSource

Apply a monadic transformation at least somewhere, in bottom up order

everywhereMStaged :: Monad m => Stage -> GenericM m -> GenericM mSource

Monadic variation on everywhere

everywhereMStaged' :: Monad m => Stage -> GenericM m -> GenericM mSource

Monadic variation on everywhere'

everywhereStaged :: Stage -> (forall a. Data a => a -> a) -> forall a. Data a => a -> aSource

Bottom-up transformation

everywhereStaged' :: Stage -> (forall a. Data a => a -> a) -> forall a. Data a => a -> aSource

Top-down version of everywhereStaged

onelayerStaged :: Stage -> r -> GenericQ r -> GenericQ [r]Source

Perform a query on the immediate subterms only, avoiding holes

listifyStaged :: (Data a, Typeable a1) => Stage -> (a1 -> Bool) -> a -> [a1]Source

Staged variation of SYB.listify The stage must be provided to avoid trying to modify elements which may not be present at all stages of AST processing.

SYB Utility

Strafunski StrategyLib versions

full_tdTUGhc :: (MonadPlus m, Monoid a) => TU a m -> TU a mSource

Full type-unifying traversal in top-down order.

stop_tdTUGhc :: (MonadPlus m, Monoid a) => TU a m -> TU a mSource

Top-down type-unifying traversal that is cut of below nodes where the argument strategy succeeds.

allTUGhc' :: (MonadPlus m, Monoid a) => TU a m -> TU a mSource

once_tdTPGhc :: MonadPlus m => TP m -> TP mSource

Top-down type-preserving traversal that performs its argument strategy at most once.

once_buTPGhc :: MonadPlus m => TP m -> TP mSource

Bottom-up type-preserving traversal that performs its argument strategy at most once.

oneTPGhc :: MonadPlus m => TP m -> TP mSource

allTUGhc :: MonadPlus m => (a -> a -> a) -> a -> TU a m -> TU a mSource

Strafunski utility

checkItemStage' :: forall m. MonadPlus m => Stage -> TU () mSource

Scrap Your Zipper versions

zeverywhereStaged :: Typeable a => Stage -> GenericT -> Zipper a -> Zipper aSource

Apply a generic transformation everywhere in a bottom-up manner.

zopenStaged :: Typeable a => Stage -> GenericQ Bool -> Zipper a -> [Zipper a]Source

Open a zipper to the point where the Geneneric query passes. returns the original zipper if the query does not pass (check this)

zsomewhereStaged :: MonadPlus m => Stage -> GenericM m -> Zipper a -> m (Zipper a)Source

Apply a generic monadic transformation once at the topmost leftmost successful location, avoiding holes in the GHC structures

transZ :: Stage -> GenericQ Bool -> (Stage -> Zipper a -> Zipper a) -> Zipper a -> Zipper aSource

Transform a zipper opened with a given generic query

transZM :: Monad m => Stage -> GenericQ Bool -> (Stage -> Zipper a -> m (Zipper a)) -> Zipper a -> m (Zipper a)Source

Monadic transform of a zipper opened with a given generic query

zopenStaged' :: Typeable a => Stage -> GenericQ (Maybe b) -> Zipper a -> [(Zipper a, b)]Source

Open a zipper to the point where the Generic query passes, returning the zipper and a value from the specific part of the GenericQ that matched. This allows the components of the query to return a specific transformation routine, to apply to the returned zipper

ztransformStagedM :: (Typeable a, Monad m) => Stage -> GenericQ (Maybe (Stage -> Zipper a -> m (Zipper a))) -> Zipper a -> m (Zipper a)Source

Open a zipper to the point where the Generic query passes, and apply the transformation returned from the specific part of the GenericQ that matched.

SYZ utilities

upUntil :: GenericQ Bool -> Zipper a -> Maybe (Zipper a)Source

Climb the tree until a predicate holds

findAbove :: Data a => (a -> Bool) -> Zipper a -> Maybe aSource

Up the zipper until a predicate holds, and then return the zipper hole