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 Bag ( bagToList )
21 import PprStyle ( PprStyle(..) )
23 import SrcLoc ( noSrcLoc, SrcLoc{-instance-} )
27 type Error = PprStyle -> Pretty
28 type Warning = PprStyle -> Pretty
29 type Message = PprStyle -> Pretty
31 addErrLoc :: SrcLoc -> String -> Error -> Error
32 addErrLoc locn title rest_of_err_msg sty
33 = ppHang (ppBesides [ppr PprForUser locn,
34 if null title then ppNil else ppStr (": " ++ title),
36 4 (rest_of_err_msg sty)
38 addShortErrLocLine, addShortWarnLocLine :: SrcLoc -> Error -> Error
40 addShortErrLocLine locn rest_of_err_msg sty
41 = ppHang (ppBeside (ppr PprForUser locn) (ppChar ':'))
42 4 (rest_of_err_msg sty)
44 addShortWarnLocLine locn rest_of_err_msg sty
45 = ppHang (ppBeside (ppr PprForUser locn) (ppPStr SLIT(":warning:")))
46 4 (rest_of_err_msg sty)
48 dontAddErrLoc :: String -> Error -> Error
49 dontAddErrLoc title rest_of_err_msg sty
50 = ppHang (ppBesides [ppStr title, ppChar ':'])
51 4 (rest_of_err_msg sty)
53 pprBagOfErrors :: PprStyle -> Bag Error -> Pretty
54 pprBagOfErrors sty bag_of_errors
55 = let pretties = map ( \ e -> e sty ) (bagToList bag_of_errors) in
56 ppAboves (map (\ p -> ppAbove ppSP p) pretties)
60 ghcExit :: Int -> IO ()
64 then error "Compilation had errors\n"