2 % (c) The AQUA Project, Glasgow University, 1994-1995
4 \section[ErrsUtils]{Utilities for error reporting}
7 #include "HsVersions.h"
10 SYN_IE(Error), SYN_IE(Warning), SYN_IE(Message),
12 addShortErrLocLine, addShortWarnLocLine,
21 import CmdLineOpts ( opt_PprUserLength )
22 import Bag --( bagToList )
23 import Outputable ( PprStyle(..), Outputable(..), printErrs )
25 import SrcLoc ( noSrcLoc, SrcLoc{-instance-} )
29 type Error = PprStyle -> Doc
30 type Warning = PprStyle -> Doc
31 type Message = PprStyle -> Doc
33 addErrLoc :: SrcLoc -> String -> Error -> Error
34 addErrLoc locn title rest_of_err_msg sty
35 = hang (hcat [ppr (PprForUser opt_PprUserLength) locn,
36 if null title then empty else text (": " ++ title),
38 4 (rest_of_err_msg sty)
40 addShortErrLocLine, addShortWarnLocLine :: SrcLoc -> Error -> Error
42 addShortErrLocLine locn rest_of_err_msg sty
43 = hang ((<>) (ppr (PprForUser opt_PprUserLength) locn) (char ':'))
44 4 (rest_of_err_msg sty)
46 addShortWarnLocLine locn rest_of_err_msg sty
47 = hang ((<>) (ppr (PprForUser opt_PprUserLength) locn) (ptext SLIT(":warning:")))
48 4 (rest_of_err_msg sty)
50 dontAddErrLoc :: String -> Error -> Error
51 dontAddErrLoc title rest_of_err_msg sty
52 = hang (hcat [text title, char ':'])
53 4 (rest_of_err_msg sty)
55 pprBagOfErrors :: PprStyle -> Bag Error -> Doc
56 pprBagOfErrors sty bag_of_errors
57 = let pretties = map ( \ e -> e sty ) (bagToList bag_of_errors)
59 vcat (map (\ p -> ($$) space p) pretties)
63 ghcExit :: Int -> IO ()
67 then error "Compilation had errors\n"
72 doIfSet :: Bool -> IO () -> IO ()
73 doIfSet flag action | flag = action
74 | otherwise = return ()
78 dumpIfSet :: Bool -> String -> Doc -> IO ()
79 dumpIfSet flag hdr doc
80 | not flag = return ()
81 | otherwise = printErrs dump
83 dump = (line <+> text hdr <+> line)
88 line = text (take 20 (repeat '='))