2 % (c) The AQUA Project, Glasgow University, 1994-1995
4 \section[ErrsUtils]{Utilities for error reporting}
8 ErrMsg, WarnMsg, Message,
9 addShortErrLocLine, addShortWarnLocLine,
11 pprBagOfErrors, pprBagOfWarnings,
16 #include "HsVersions.h"
18 import Bag ( Bag, bagToList )
19 import SrcLoc ( SrcLoc )
28 addShortErrLocLine, addShortWarnLocLine :: SrcLoc -> ErrMsg -> ErrMsg
30 addShortErrLocLine locn rest_of_err_msg
31 = hang (ppr locn <> colon)
34 addShortWarnLocLine locn rest_of_err_msg
35 = hang (ppr locn <> ptext SLIT(": Warning:"))
38 dontAddErrLoc :: String -> ErrMsg -> ErrMsg
39 dontAddErrLoc title rest_of_err_msg
40 = hang (hcat [text title, char ':'])
43 pprBagOfErrors :: Bag ErrMsg -> SDoc
44 pprBagOfErrors bag_of_errors
45 = vcat [space $$ p | p <- bagToList bag_of_errors]
47 pprBagOfWarnings :: Bag ErrMsg -> SDoc
48 pprBagOfWarnings bag_of_warns = pprBagOfErrors bag_of_warns
52 ghcExit :: Int -> IO ()
56 then error "Compilation had errors\n"
61 doIfSet :: Bool -> IO () -> IO ()
62 doIfSet flag action | flag = action
63 | otherwise = return ()
67 dumpIfSet :: Bool -> String -> SDoc -> IO ()
68 dumpIfSet flag hdr doc
69 | not flag = return ()
70 | otherwise = printDump dump
73 line <+> text hdr <+> line,
76 line = text (take 20 (repeat '='))