e50ded59a7c0d126b172387a56a99374f41a10bb
[ghc-hetmet.git] / ghc / compiler / main / ErrUtils.lhs
1 %
2 % (c) The AQUA Project, Glasgow University, 1994-1995
3 %
4 \section[ErrsUtils]{Utilities for error reporting}
5
6 \begin{code}
7 #include "HsVersions.h"
8
9 module ErrUtils (
10         Error(..), Warning(..), Message(..),
11         addErrLoc,
12         addShortErrLocLine,
13         dontAddErrLoc,
14         pprBagOfErrors,
15         ghcExit
16     ) where
17
18 import Ubiq{-uitous-}
19
20 import Bag              ( bagToList )
21 import PprStyle         ( PprStyle(..) )
22 import Pretty
23 import SrcLoc           ( mkUnknownSrcLoc, SrcLoc{-instance-} )
24 \end{code}
25
26 \begin{code}
27 type Error   = PprStyle -> Pretty
28 type Warning = PprStyle -> Pretty
29 type Message = PprStyle -> Pretty
30
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),
35                        ppChar ':'])
36          4 (rest_of_err_msg sty)
37
38 addShortErrLocLine :: SrcLoc -> Error -> Error
39 addShortErrLocLine locn rest_of_err_msg sty
40   = ppHang (ppBeside (ppr PprForUser locn) (ppChar ':'))
41          4 (rest_of_err_msg sty)
42
43 dontAddErrLoc :: String -> Error -> Error
44 dontAddErrLoc title rest_of_err_msg sty
45   = ppHang (ppBesides [ppStr title, ppChar ':'])
46          4 (rest_of_err_msg sty)
47
48 pprBagOfErrors :: PprStyle -> Bag Error -> Pretty
49 pprBagOfErrors sty bag_of_errors
50   = let  pretties = map ( \ e -> e sty ) (bagToList bag_of_errors)  in
51     ppAboves (map (\ p -> ppAbove ppSP p) pretties)
52 \end{code}
53
54 \begin{code}
55 ghcExit :: Int -> IO ()
56
57 ghcExit val
58   = if val /= 0
59     then error "Compilation had errors\n"
60     else return ()
61 \end{code}