X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Fmain%2FErrUtils.lhs;h=c8beedd89f271ca7f4bb05b6e3e600d02e47f365;hb=2ac92d88dfb9a8864fb619225cb997bd23b1b8e1;hp=79e43ac1fad03327b9d204dd43e3feab951329c3;hpb=087fdd53c7d6bb6cb17574133abc2de4f1816c7e;p=ghc-hetmet.git diff --git a/ghc/compiler/main/ErrUtils.lhs b/ghc/compiler/main/ErrUtils.lhs index 79e43ac..c8beedd 100644 --- a/ghc/compiler/main/ErrUtils.lhs +++ b/ghc/compiler/main/ErrUtils.lhs @@ -5,25 +5,31 @@ \begin{code} module ErrUtils ( - ErrMsg, WarnMsg, Message, + ErrMsg, WarnMsg, Message, Messages, errorsFound, warningsFound, + addShortErrLocLine, addShortWarnLocLine, - addErrLocHdrLine, - dontAddErrLoc, + addErrLocHdrLine, addWarnLocHdrLine, dontAddErrLoc, + printErrorsAndWarnings, pprBagOfErrors, pprBagOfWarnings, + + printError, ghcExit, - doIfSet, doIfSet_dyn, dumpIfSet, dumpIfSet_dyn + doIfSet, doIfSet_dyn, + dumpIfSet, dumpIfSet_core, dumpIfSet_dyn, dumpIfSet_dyn_or, + showPass ) where #include "HsVersions.h" import Bag ( Bag, bagToList, isEmptyBag ) -import SrcLoc ( SrcLoc, noSrcLoc ) +import SrcLoc ( SrcLoc, noSrcLoc, isGoodSrcLoc ) import Util ( sortLt ) import Outputable -import CmdLineOpts ( DynFlags ) +import CmdLineOpts ( DynFlags(..), DynFlag(..), dopt ) +import List ( replicate ) import System ( ExitCode(..), exitWith ) -import IO ( hPutStr, stderr ) +import IO ( hPutStr, hPutStrLn, stderr, stdout ) \end{code} \begin{code} @@ -35,13 +41,13 @@ type Message = SDoc addShortErrLocLine :: SrcLoc -> Message -> ErrMsg addErrLocHdrLine :: SrcLoc -> Message -> Message -> ErrMsg +addWarnLocHdrLine :: SrcLoc -> Message -> Message -> ErrMsg addShortWarnLocLine :: SrcLoc -> Message -> WarnMsg addShortErrLocLine locn rest_of_err_msg - = ( locn - , hang (ppr locn <> colon) - 4 rest_of_err_msg - ) + | isGoodSrcLoc locn = (locn, hang (ppr locn <> colon) 4 + rest_of_err_msg) + | otherwise = (locn, rest_of_err_msg) addErrLocHdrLine locn hdr rest_of_err_msg = ( locn @@ -49,24 +55,42 @@ addErrLocHdrLine locn hdr rest_of_err_msg 4 rest_of_err_msg ) -addShortWarnLocLine locn rest_of_err_msg +addWarnLocHdrLine locn hdr rest_of_err_msg = ( locn - , hang (ppr locn <> colon) - 4 (ptext SLIT("Warning:") <+> rest_of_err_msg) + , hang (ppr locn <> colon <+> ptext SLIT("Warning:") <+> hdr) + 4 (rest_of_err_msg) ) -dontAddErrLoc :: String -> Message -> ErrMsg -dontAddErrLoc title rest_of_err_msg - | null title = (noSrcLoc, rest_of_err_msg) - | otherwise = - ( noSrcLoc, hang (text title <> colon) 4 rest_of_err_msg ) +addShortWarnLocLine locn rest_of_err_msg + | isGoodSrcLoc locn = (locn, hang (ppr locn <> colon) 4 + (ptext SLIT("Warning:") <+> rest_of_err_msg)) + | otherwise = (locn, rest_of_err_msg) + +dontAddErrLoc :: Message -> ErrMsg +dontAddErrLoc msg = (noSrcLoc, msg) + +\end{code} + +\begin{code} +printError :: String -> IO () +printError str = hPutStrLn stderr str +\end{code} + +\begin{code} +type Messages = (Bag WarnMsg, Bag ErrMsg) + +errorsFound :: Messages -> Bool +errorsFound (warns, errs) = not (isEmptyBag errs) + +warningsFound :: Messages -> Bool +warningsFound (warns, errs) = not (isEmptyBag warns) -printErrorsAndWarnings :: (Bag WarnMsg, Bag ErrMsg) -> IO () +printErrorsAndWarnings :: PrintUnqualified -> Messages -> IO () -- Don't print any warnings if there are errors -printErrorsAndWarnings (warns, errs) +printErrorsAndWarnings unqual (warns, errs) | no_errs && no_warns = return () - | no_errs = printErrs (pprBagOfWarnings warns) - | otherwise = printErrs (pprBagOfErrors errs) + | no_errs = printErrs unqual (pprBagOfWarnings warns) + | otherwise = printErrs unqual (pprBagOfErrors errs) where no_warns = isEmptyBag warns no_errs = isEmptyBag errs @@ -97,21 +121,44 @@ doIfSet :: Bool -> IO () -> IO () doIfSet flag action | flag = action | otherwise = return () -doIfSet_dyn :: DynFlags -> (DynFlags -> Bool) -> IO () -> IO() -doIfSet_dyn dflags flag action | flag dflags = action - | otherwise = return () +doIfSet_dyn :: DynFlags -> DynFlag -> IO () -> IO() +doIfSet_dyn dflags flag action | dopt flag dflags = action + | otherwise = return () \end{code} \begin{code} +showPass :: DynFlags -> String -> IO () +showPass dflags what + | verbosity dflags >= 2 = hPutStr stderr ("*** "++what++":\n") + | otherwise = return () + dumpIfSet :: Bool -> String -> SDoc -> IO () dumpIfSet flag hdr doc | not flag = return () | otherwise = printDump (dump hdr doc) -dumpIfSet_dyn :: DynFlags -> (DynFlags -> Bool) -> String -> SDoc -> IO () +dumpIfSet_core :: DynFlags -> DynFlag -> String -> SDoc -> IO () +dumpIfSet_core dflags flag hdr doc + | dopt flag dflags + || verbosity dflags >= 4 + || dopt Opt_D_verbose_core2core dflags = printDump (dump hdr doc) + | otherwise = return () + +dumpIfSet_dyn :: DynFlags -> DynFlag -> String -> SDoc -> IO () dumpIfSet_dyn dflags flag hdr doc - | not (flag dflags) = return () - | otherwise = printDump (dump hdr doc) + | dopt flag dflags || verbosity dflags >= 4 + = if flag `elem` [Opt_D_dump_stix, Opt_D_dump_asm] + then printForC stdout (dump hdr doc) + else printDump (dump hdr doc) + | otherwise + = return () + +dumpIfSet_dyn_or :: DynFlags -> [DynFlag] -> String -> SDoc -> IO () +dumpIfSet_dyn_or dflags flags hdr doc + | or [dopt flag dflags | flag <- flags] + || verbosity dflags >= 4 + = printDump (dump hdr doc) + | otherwise = return () dump hdr doc = vcat [text "", @@ -119,5 +166,5 @@ dump hdr doc doc, text ""] where - line = text (take 20 (repeat '=')) + line = text (replicate 20 '=') \end{code}