X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Fmain%2FErrUtils.lhs;h=dcf2934f7a9094882e0483033fc5c9700fbcad55;hb=438596897ebbe25a07e1c82085cfbc5bdb00f09e;hp=04ae96f182155b3d00b74fe193bc17cb27431b89;hpb=e7498a3ee1d0484d02a9e86633cc179c76ebf36e;p=ghc-hetmet.git diff --git a/ghc/compiler/main/ErrUtils.lhs b/ghc/compiler/main/ErrUtils.lhs index 04ae96f..dcf2934 100644 --- a/ghc/compiler/main/ErrUtils.lhs +++ b/ghc/compiler/main/ErrUtils.lhs @@ -1,59 +1,51 @@ % -% (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 ( - Error(..), Warning(..), Message(..), - addErrLoc, + ErrMsg, WarnMsg, Message, addShortErrLocLine, addShortWarnLocLine, 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 ( mkUnknownSrcLoc, SrcLoc{-instance-} ) +import Bag ( Bag, bagToList ) +import SrcLoc ( SrcLoc ) +import Outputable \end{code} \begin{code} -type Error = PprStyle -> Pretty -type Warning = PprStyle -> Pretty -type Message = PprStyle -> Pretty +type ErrMsg = SDoc +type WarnMsg = SDoc +type Message = SDoc -addErrLoc :: SrcLoc -> String -> Error -> Error -addErrLoc locn title rest_of_err_msg sty - = ppHang (ppBesides [ppr PprForUser locn, - if null title then ppNil else ppStr (": " ++ title), - ppChar ':']) - 4 (rest_of_err_msg sty) +addShortErrLocLine, addShortWarnLocLine :: SrcLoc -> ErrMsg -> ErrMsg -addShortErrLocLine, addShortWarnLocLine :: SrcLoc -> Error -> Error +addShortErrLocLine locn rest_of_err_msg + = hang (ppr locn <> colon) + 4 rest_of_err_msg -addShortErrLocLine locn rest_of_err_msg sty - = ppHang (ppBeside (ppr PprForUser locn) (ppChar ':')) - 4 (rest_of_err_msg sty) +addShortWarnLocLine locn rest_of_err_msg + = hang (ppr locn <> ptext SLIT(": Warning:")) + 4 rest_of_err_msg -addShortWarnLocLine locn rest_of_err_msg sty - = ppHang (ppBeside (ppr PprForUser locn) (ppPStr SLIT(":warning:"))) - 4 (rest_of_err_msg sty) +dontAddErrLoc :: String -> ErrMsg -> ErrMsg +dontAddErrLoc title rest_of_err_msg + = hang (hcat [text title, char ':']) + 4 rest_of_err_msg -dontAddErrLoc :: String -> Error -> Error -dontAddErrLoc title rest_of_err_msg sty - = ppHang (ppBesides [ppStr title, ppChar ':']) - 4 (rest_of_err_msg sty) +pprBagOfErrors :: Bag ErrMsg -> SDoc +pprBagOfErrors bag_of_errors + = vcat [space $$ p | p <- bagToList bag_of_errors] -pprBagOfErrors :: PprStyle -> Bag Error -> Pretty -pprBagOfErrors sty bag_of_errors - = let pretties = map ( \ e -> e sty ) (bagToList bag_of_errors) in - ppAboves (map (\ p -> ppAbove ppSP p) pretties) +pprBagOfWarnings :: Bag ErrMsg -> SDoc +pprBagOfWarnings bag_of_warns = pprBagOfErrors bag_of_warns \end{code} \begin{code} @@ -64,3 +56,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}