X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Fmain%2FErrUtils.lhs;h=c5abb68aff12fb915f4a4ef4fd35cc9b13eec00b;hb=f629db724575a3b9e1a26ab3937c701a02722b7d;hp=aba852bb0937daaee3d3a6dd6060aefcea4fb949;hpb=dcef38bab91d45b56f7cf3ceeec96303d93728bb;p=ghc-hetmet.git diff --git a/ghc/compiler/main/ErrUtils.lhs b/ghc/compiler/main/ErrUtils.lhs index aba852b..c5abb68 100644 --- a/ghc/compiler/main/ErrUtils.lhs +++ b/ghc/compiler/main/ErrUtils.lhs @@ -1,62 +1,73 @@ % -% (c) The AQUA Project, Glasgow University, 1994-1995 +% (c) The AQUA Project, Glasgow University, 1994-1998 % \section[ErrsUtils]{Utilities for error reporting} \begin{code} -#include "HsVersions.h" - module ErrUtils ( - SYN_IE(Error), SYN_IE(Warning), SYN_IE(Message), - addErrLoc, + ErrMsg, WarnMsg, Message, addShortErrLocLine, addShortWarnLocLine, + addErrLocHdrLine, dontAddErrLoc, - pprBagOfErrors, - ghcExit + pprBagOfErrors, pprBagOfWarnings, + ghcExit, + doIfSet, dumpIfSet ) where -IMP_Ubiq(){-uitous-} +#include "HsVersions.h" -import Bag --( bagToList ) -import PprStyle ( PprStyle(..) ) -import Pretty -import SrcLoc ( noSrcLoc, SrcLoc{-instance-} ) -#if __GLASGOW_HASKELL__ >= 202 +import Bag ( Bag, bagToList ) +import SrcLoc ( SrcLoc, noSrcLoc ) +import Util ( sortLt ) import Outputable -#endif \end{code} \begin{code} -type Error = PprStyle -> Doc -type Warning = PprStyle -> Doc -type Message = PprStyle -> Doc - -addErrLoc :: SrcLoc -> String -> Error -> Error -addErrLoc locn title rest_of_err_msg sty - = hang (hcat [ppr PprForUser locn, - if null title then empty else text (": " ++ title), - char ':']) - 4 (rest_of_err_msg sty) - -addShortErrLocLine, addShortWarnLocLine :: SrcLoc -> Error -> Error - -addShortErrLocLine locn rest_of_err_msg sty - = hang ((<>) (ppr PprForUser locn) (char ':')) - 4 (rest_of_err_msg sty) - -addShortWarnLocLine locn rest_of_err_msg sty - = hang ((<>) (ppr PprForUser locn) (ptext SLIT(":warning:"))) - 4 (rest_of_err_msg sty) - -dontAddErrLoc :: String -> Error -> Error -dontAddErrLoc title rest_of_err_msg sty - = hang (hcat [text title, char ':']) - 4 (rest_of_err_msg sty) - -pprBagOfErrors :: PprStyle -> Bag Error -> Doc -pprBagOfErrors sty bag_of_errors - = let pretties = map ( \ e -> e sty ) (bagToList bag_of_errors) in - vcat (map (\ p -> ($$) space p) pretties) +type MsgWithLoc = (SrcLoc, SDoc) + +type ErrMsg = MsgWithLoc +type WarnMsg = MsgWithLoc +type Message = SDoc + +addShortErrLocLine :: SrcLoc -> Message -> ErrMsg +addErrLocHdrLine :: SrcLoc -> Message -> Message -> ErrMsg +addShortWarnLocLine :: SrcLoc -> Message -> WarnMsg + +addShortErrLocLine locn rest_of_err_msg + = ( locn + , hang (ppr locn <> colon) + 4 rest_of_err_msg + ) + +addErrLocHdrLine locn hdr rest_of_err_msg + = ( locn + , hang (ppr locn <> colon<+> hdr) + 4 rest_of_err_msg + ) + +addShortWarnLocLine locn rest_of_err_msg + = ( locn + , hang (ppr locn <> colon) + 4 (ptext SLIT("Warning:") <+> 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 ) + +pprBagOfErrors :: Bag ErrMsg -> SDoc +pprBagOfErrors bag_of_errors + = vcat [text "" $$ p | (_,p) <- sorted_errs ] + where + bag_ls = bagToList bag_of_errors + sorted_errs = sortLt occ'ed_before bag_ls + + occ'ed_before (a,_) (b,_) = LT == compare a b + +pprBagOfWarnings :: Bag WarnMsg -> SDoc +pprBagOfWarnings bag_of_warns = pprBagOfErrors bag_of_warns \end{code} \begin{code} @@ -67,3 +78,22 @@ ghcExit val then error "Compilation had errors\n" else return () \end{code} + +\begin{code} +doIfSet :: Bool -> IO () -> IO () +doIfSet flag action | flag = action + | otherwise = return () +\end{code} + +\begin{code} +dumpIfSet :: Bool -> String -> SDoc -> IO () +dumpIfSet flag hdr doc + | not flag = return () + | otherwise = printDump dump + where + dump = vcat [text "", + line <+> text hdr <+> line, + doc, + text ""] + line = text (take 20 (repeat '=')) +\end{code}