ghc-lib-parser-0.20200301: The GHC API, decoupled from GHC versions

Safe HaskellNone
LanguageHaskell2010

GHC.Driver.Monad

Contents

Synopsis

Ghc monad stuff

class (Functor m, MonadIO m, ExceptionMonad m, HasDynFlags m) => GhcMonad m where Source #

A monad that has all the features needed by GHC API calls.

In short, a GHC monad

  • allows embedding of IO actions,
  • can log warnings,
  • allows handling of (extensible) exceptions, and
  • maintains a current session.

If you do not use Ghc or GhcT, make sure to call initGhcMonad before any call to the GHC API functions can occur.

Instances
GhcMonad Ghc Source # 
Instance details

Defined in GHC.Driver.Monad

ExceptionMonad m => GhcMonad (GhcT m) Source # 
Instance details

Defined in GHC.Driver.Monad

newtype Ghc a Source #

A minimal implementation of a GhcMonad. If you need a custom monad, e.g., to maintain additional state consider wrapping this monad or using GhcT.

Constructors

Ghc 

Fields

Instances
Monad Ghc Source # 
Instance details

Defined in GHC.Driver.Monad

Methods

(>>=) :: Ghc a -> (a -> Ghc b) -> Ghc b #

(>>) :: Ghc a -> Ghc b -> Ghc b #

return :: a -> Ghc a #

fail :: String -> Ghc a #

Functor Ghc Source # 
Instance details

Defined in GHC.Driver.Monad

Methods

fmap :: (a -> b) -> Ghc a -> Ghc b #

(<$) :: a -> Ghc b -> Ghc a #

MonadFix Ghc Source # 
Instance details

Defined in GHC.Driver.Monad

Methods

mfix :: (a -> Ghc a) -> Ghc a #

Applicative Ghc Source # 
Instance details

Defined in GHC.Driver.Monad

Methods

pure :: a -> Ghc a #

(<*>) :: Ghc (a -> b) -> Ghc a -> Ghc b #

liftA2 :: (a -> b -> c) -> Ghc a -> Ghc b -> Ghc c #

(*>) :: Ghc a -> Ghc b -> Ghc b #

(<*) :: Ghc a -> Ghc b -> Ghc a #

MonadIO Ghc Source # 
Instance details

Defined in GHC.Driver.Monad

Methods

liftIO :: IO a -> Ghc a #

ExceptionMonad Ghc Source # 
Instance details

Defined in GHC.Driver.Monad

Methods

gcatch :: Exception e => Ghc a -> (e -> Ghc a) -> Ghc a Source #

gmask :: ((Ghc a -> Ghc a) -> Ghc b) -> Ghc b Source #

gbracket :: Ghc a -> (a -> Ghc b) -> (a -> Ghc c) -> Ghc c Source #

gfinally :: Ghc a -> Ghc b -> Ghc a Source #

HasDynFlags Ghc Source # 
Instance details

Defined in GHC.Driver.Monad

GhcMonad Ghc Source # 
Instance details

Defined in GHC.Driver.Monad

newtype GhcT m a Source #

A monad transformer to add GHC specific features to another monad.

Note that the wrapped monad must support IO and handling of exceptions.

Constructors

GhcT 

Fields

Instances
Monad m => Monad (GhcT m) Source # 
Instance details

Defined in GHC.Driver.Monad

Methods

(>>=) :: GhcT m a -> (a -> GhcT m b) -> GhcT m b #

(>>) :: GhcT m a -> GhcT m b -> GhcT m b #

return :: a -> GhcT m a #

fail :: String -> GhcT m a #

Functor m => Functor (GhcT m) Source # 
Instance details

Defined in GHC.Driver.Monad

Methods

fmap :: (a -> b) -> GhcT m a -> GhcT m b #

(<$) :: a -> GhcT m b -> GhcT m a #

Applicative m => Applicative (GhcT m) Source # 
Instance details

Defined in GHC.Driver.Monad

Methods

pure :: a -> GhcT m a #

(<*>) :: GhcT m (a -> b) -> GhcT m a -> GhcT m b #

liftA2 :: (a -> b -> c) -> GhcT m a -> GhcT m b -> GhcT m c #

(*>) :: GhcT m a -> GhcT m b -> GhcT m b #

(<*) :: GhcT m a -> GhcT m b -> GhcT m a #

MonadIO m => MonadIO (GhcT m) Source # 
Instance details

Defined in GHC.Driver.Monad

Methods

liftIO :: IO a -> GhcT m a #

ExceptionMonad m => ExceptionMonad (GhcT m) Source # 
Instance details

Defined in GHC.Driver.Monad

Methods

gcatch :: Exception e => GhcT m a -> (e -> GhcT m a) -> GhcT m a Source #

gmask :: ((GhcT m a -> GhcT m a) -> GhcT m b) -> GhcT m b Source #

gbracket :: GhcT m a -> (a -> GhcT m b) -> (a -> GhcT m c) -> GhcT m c Source #

gfinally :: GhcT m a -> GhcT m b -> GhcT m a Source #

MonadIO m => HasDynFlags (GhcT m) Source # 
Instance details

Defined in GHC.Driver.Monad

ExceptionMonad m => GhcMonad (GhcT m) Source # 
Instance details

Defined in GHC.Driver.Monad

liftGhcT :: m a -> GhcT m a Source #

reflectGhc :: Ghc a -> Session -> IO a Source #

Reflect a computation in the Ghc monad into the IO monad.

You can use this to call functions returning an action in the Ghc monad inside an IO action. This is needed for some (too restrictive) callback arguments of some library functions:

libFunc :: String -> (Int -> IO a) -> IO a
ghcFunc :: Int -> Ghc a

ghcFuncUsingLibFunc :: String -> Ghc a -> Ghc a
ghcFuncUsingLibFunc str =
  reifyGhc $ \s ->
    libFunc $ \i -> do
      reflectGhc (ghcFunc i) s

reifyGhc :: (Session -> IO a) -> Ghc a Source #

getSessionDynFlags :: GhcMonad m => m DynFlags Source #

Grabs the DynFlags from the Session

liftIO :: MonadIO m => IO a -> m a #

Lift a computation from the IO monad.

data Session Source #

The Session is a handle to the complete state of a compilation session. A compilation session consists of a set of modules constituting the current program or library, the context for interactive evaluation, and various caches.

Constructors

Session !(IORef HscEnv) 

withSession :: GhcMonad m => (HscEnv -> m a) -> m a Source #

Call the argument with the current session.

modifySession :: GhcMonad m => (HscEnv -> HscEnv) -> m () Source #

Set the current session to the result of applying the current session to the argument.

withTempSession :: GhcMonad m => (HscEnv -> HscEnv) -> m a -> m a Source #

Call an action with a temporarily modified Session.

Warnings

logWarnings :: GhcMonad m => WarningMessages -> m () Source #

A monad that allows logging of warnings.

printException :: GhcMonad m => SourceError -> m () Source #

Print the error message and all warnings. Useful inside exception handlers. Clears warnings after printing.

type WarnErrLogger = forall m. GhcMonad m => Maybe SourceError -> m () Source #

A function called to log warnings and errors.