ErrMsg module.

This commit is contained in:
Kazu Yamamoto
2011-08-24 16:50:26 +09:00
parent dbdcf9841e
commit 1790c5f327
5 changed files with 98 additions and 59 deletions

View File

@@ -1,20 +1,12 @@
{-# LANGUAGE CPP #-}
module Types where
import Control.Applicative
import Control.Monad
import CoreMonad
import Data.IORef
import DynFlags
import ErrUtils
import ErrMsg
import Exception
import FastString
import GHC
import GHC.Paths (libdir)
import Outputable
import System.FilePath
import Pretty
----------------------------------------------------------------
@@ -76,44 +68,6 @@ setPackageConfFlags
----------------------------------------------------------------
type LogReader = IO [String]
setLogger :: Bool -> DynFlags -> IO (DynFlags, LogReader)
setLogger False df = return (newdf, undefined)
where
newdf = df { log_action = \_ _ _ _ -> return () }
setLogger True df = do
ref <- newIORef [] :: IO (IORef [String])
let newdf = df { log_action = appendLog ref }
return (newdf, reverse <$> readIORef ref)
where
appendLog ref _ src _ msg = modifyIORef ref (\ls -> ppMsg src msg : ls)
ppMsg :: SrcSpan -> Message -> String
#if __GLASGOW_HASKELL__ >= 702
ppMsg (UnhelpfulSpan _) _ = undefined
ppMsg (RealSrcSpan src) msg
#else
ppMsg src msg
#endif
= file ++ ":" ++ line ++ ":" ++ col ++ ":" ++ cts ++ "\0" -- xxx
where
file = takeFileName $ unpackFS (srcSpanFile src)
line = show (srcSpanStartLine src)
col = show (srcSpanStartCol src)
cts = showMsg msg
style :: PprStyle
style = mkUserStyle neverQualify AllTheWay
showMsg :: SDoc -> String
showMsg d = map toNull . Pretty.showDocWith PageMode $ d style
where
toNull '\n' = '\0'
toNull x = x
----------------------------------------------------------------
setTargetFile :: (GhcMonad m) => String -> m ()
setTargetFile file = do
target <- guessTarget file Nothing