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,
20 import CmdLineOpts ( opt_PprUserLength )
21 import Bag --( bagToList )
22 import Outputable ( PprStyle(..), Outputable(..) )
24 import SrcLoc ( noSrcLoc, SrcLoc{-instance-} )
28 type Error = PprStyle -> Doc
29 type Warning = PprStyle -> Doc
30 type Message = PprStyle -> Doc
32 addErrLoc :: SrcLoc -> String -> Error -> Error
33 addErrLoc locn title rest_of_err_msg sty
34 = hang (hcat [ppr (PprForUser opt_PprUserLength) locn,
35 if null title then empty else text (": " ++ title),
37 4 (rest_of_err_msg sty)
39 addShortErrLocLine, addShortWarnLocLine :: SrcLoc -> Error -> Error
41 addShortErrLocLine locn rest_of_err_msg sty
42 = hang ((<>) (ppr (PprForUser opt_PprUserLength) locn) (char ':'))
43 4 (rest_of_err_msg sty)
45 addShortWarnLocLine locn rest_of_err_msg sty
46 = hang ((<>) (ppr (PprForUser opt_PprUserLength) locn) (ptext SLIT(":warning:")))
47 4 (rest_of_err_msg sty)
49 dontAddErrLoc :: String -> Error -> Error
50 dontAddErrLoc title rest_of_err_msg sty
51 = hang (hcat [text title, char ':'])
52 4 (rest_of_err_msg sty)
54 pprBagOfErrors :: PprStyle -> Bag Error -> Doc
55 pprBagOfErrors sty bag_of_errors
56 = let pretties = map ( \ e -> e sty ) (bagToList bag_of_errors) in
57 vcat (map (\ p -> ($$) space p) pretties)
61 ghcExit :: Int -> IO ()
65 then error "Compilation had errors\n"