[project @ 1996-01-08 20:28:12 by partain]
[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 This is an internal module---access to these functions is through
7 @Errors@.
8
9 DPH errors are in here, too.
10
11 \begin{code}
12 #include "HsVersions.h"
13
14 module ErrUtils where
15
16 import Bag              ( Bag, bagToList )
17 import Outputable
18 import Pretty           -- to pretty-print error messages
19 import SrcLoc           ( mkUnknownSrcLoc, SrcLoc )
20 import Util
21 \end{code}
22
23 \begin{code}
24 type Error = PprStyle -> Pretty
25
26 addErrLoc :: SrcLoc -> String -> Error -> Error
27 addErrLoc locn title rest_of_err_msg sty
28   = ppHang (ppBesides [ppr PprForUser locn,
29                        if null title then ppNil else ppStr (": " ++ title),
30                        ppChar ':'])
31          4 (rest_of_err_msg sty)
32
33 addShortErrLocLine :: SrcLoc -> Error -> Error
34 addShortErrLocLine locn rest_of_err_msg sty
35   = ppHang (ppBeside (ppr PprForUser locn) (ppChar ':'))
36          4 (rest_of_err_msg sty)
37
38 dontAddErrLoc :: String -> Error -> Error
39 dontAddErrLoc title rest_of_err_msg sty
40   = ppHang (ppBesides [ppStr title, ppChar ':'])
41          4 (rest_of_err_msg sty)
42
43 pprBagOfErrors :: PprStyle -> Bag Error -> Pretty
44 pprBagOfErrors sty bag_of_errors
45   = let  pretties = map ( \ e -> e sty ) (bagToList bag_of_errors)  in
46     ppAboves (map (\ p -> ppAbove ppSP p) pretties)
47
48 #ifdef DPH
49 addWarningLoc :: SrcLoc -> Error -> Error
50 addWarningLoc locn rest_of_err_msg sty
51   = ppHang (ppBesides [ppStr "*** Warning *** ",
52                        ppr PprForUser locn,ppStr ": "])
53          4 (ppAbove (rest_of_err_msg sty)
54                     (ppSP))
55
56 addWarning :: Error -> Error
57 addWarning rest_of_err_msg sty
58   = ppBeside (ppStr "*** Warning *** : ")
59              (rest_of_err_msg sty)
60 #endif {- Data Parallel Haskell -}
61 \end{code}