summaryrefslogtreecommitdiff
path: root/compiler/main/GhcMonad.hs
diff options
context:
space:
mode:
authorsimonpj@microsoft.com <unknown>2011-01-25 16:16:32 +0000
committersimonpj@microsoft.com <unknown>2011-01-25 16:16:32 +0000
commita79a531965cd1f0d04dd3e0250b076037bf9ff4e (patch)
treeef0be88551fded7af6cb2a3969b083adbcaf2158 /compiler/main/GhcMonad.hs
parent45bc009da2922cf8d5181d79d01c1c61e8d603fa (diff)
downloadhaskell-a79a531965cd1f0d04dd3e0250b076037bf9ff4e.tar.gz
Split main/GHC into GHC and GhcMake
There are two things going on in main/GHC.hs. * It's the root module of the GHC package * It contains lots of stuff for --make It is also gigantic (2.7k lines) This patch splits it into two * GHC.hs is the root module for the GHC package (1.3k lines) * GhcMake.hs contains the stuff for --make (1.4k lines) Happily the functional split divided it almost exactly in half. This is a pure refactoring. There should be no behavioural change.
Diffstat (limited to 'compiler/main/GhcMonad.hs')
-rw-r--r--compiler/main/GhcMonad.hs23
1 files changed, 22 insertions, 1 deletions
diff --git a/compiler/main/GhcMonad.hs b/compiler/main/GhcMonad.hs
index c62ea4c093..711259c9ba 100644
--- a/compiler/main/GhcMonad.hs
+++ b/compiler/main/GhcMonad.hs
@@ -18,7 +18,8 @@ module GhcMonad (
Session(..), withSession, modifySession, withTempSession,
-- ** Warnings
- logWarnings
+ logWarnings, printException, printExceptionAndWarnings,
+ WarnErrLogger, defaultWarnErrLogger
) where
import MonadUtils
@@ -175,3 +176,23 @@ instance ExceptionMonad m => ExceptionMonad (GhcT m) where
instance (Functor m, ExceptionMonad m, MonadIO m) => GhcMonad (GhcT m) where
getSession = GhcT $ \(Session r) -> liftIO $ readIORef r
setSession s' = GhcT $ \(Session r) -> liftIO $ writeIORef r s'
+
+
+-- | Print the error message and all warnings. Useful inside exception
+-- handlers. Clears warnings after printing.
+printException :: GhcMonad m => SourceError -> m ()
+printException err = do
+ dflags <- getSessionDynFlags
+ liftIO $ printBagOfErrors dflags (srcErrorMessages err)
+
+{-# DEPRECATED printExceptionAndWarnings "use printException instead" #-}
+printExceptionAndWarnings :: GhcMonad m => SourceError -> m ()
+printExceptionAndWarnings = printException
+
+-- | A function called to log warnings and errors.
+type WarnErrLogger = GhcMonad m => Maybe SourceError -> m ()
+
+defaultWarnErrLogger :: WarnErrLogger
+defaultWarnErrLogger Nothing = return ()
+defaultWarnErrLogger (Just e) = printException e
+