[project @ 1997-03-14 07:52:06 by simonpj]
[ghc-hetmet.git] / ghc / compiler / basicTypes / SrcLoc.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1994
3 %
4 %************************************************************************
5 %*                                                                      *
6 \section[SrcLoc]{The @SrcLoc@ type}
7 %*                                                                      *
8 %************************************************************************
9
10 \begin{code}
11 #include "HsVersions.h"
12
13 module SrcLoc (
14         SrcLoc,                 -- Abstract
15
16         mkSrcLoc,
17         noSrcLoc, isNoSrcLoc,   -- "I'm sorry, I haven't a clue"
18
19         mkIfaceSrcLoc,          -- Unknown place in an interface
20                                 -- (this one can die eventually ToDo)
21
22         mkBuiltinSrcLoc,        -- Something wired into the compiler
23
24         mkGeneratedSrcLoc       -- Code generated within the compiler
25     ) where
26
27 IMP_Ubiq()
28
29 import PprStyle         ( PprStyle(..) )
30 import Pretty
31 \end{code}
32
33 %************************************************************************
34 %*                                                                      *
35 \subsection[SrcLoc-SrcLocations]{Source-location information}
36 %*                                                                      *
37 %************************************************************************
38
39 We keep information about the {\em definition} point for each entity;
40 this is the obvious stuff:
41 \begin{code}
42 data SrcLoc
43   = NoSrcLoc
44
45   | SrcLoc      FAST_STRING     -- A precise location
46                 FAST_INT
47
48   | UnhelpfulSrcLoc FAST_STRING -- Just a general indication
49 \end{code}
50
51 Note that an entity might be imported via more than one route, and
52 there could be more than one ``definition point'' --- in two or more
53 \tr{.hi} files.  We deemed it probably-unworthwhile to cater for this
54 rare case.
55
56 %************************************************************************
57 %*                                                                      *
58 \subsection[SrcLoc-access-fns]{Access functions for names}
59 %*                                                                      *
60 %************************************************************************
61
62 Things to make 'em:
63 \begin{code}
64 noSrcLoc            = NoSrcLoc
65 mkSrcLoc x IBOX(y)  = SrcLoc x y
66
67 mkIfaceSrcLoc       = UnhelpfulSrcLoc SLIT("<an interface file>")
68 mkBuiltinSrcLoc     = UnhelpfulSrcLoc SLIT("<built-into-the-compiler>")
69 mkGeneratedSrcLoc   = UnhelpfulSrcLoc SLIT("<compiler-generated-code>")
70
71 isNoSrcLoc NoSrcLoc = True
72 isNoSrcLoc other    = False
73 \end{code}
74
75 %************************************************************************
76 %*                                                                      *
77 \subsection[SrcLoc-instances]{Instance declarations for various names}
78 %*                                                                      *
79 %************************************************************************
80
81 \begin{code}
82 instance Outputable SrcLoc where
83     ppr PprForUser (SrcLoc src_file src_line)
84       = ppBesides [ ppPStr src_file, ppChar ':', ppStr (show IBOX(src_line)) ]
85
86     ppr sty (SrcLoc src_file src_line)
87       = ppBesides [ppStr "{-# LINE ", ppStr (show IBOX(src_line)), ppSP,
88                    ppChar '\"', ppPStr src_file, ppStr " #-}"]
89     ppr sty (UnhelpfulSrcLoc s) = ppPStr s
90
91     ppr sty NoSrcLoc = ppStr "<NoSrcLoc>"
92 \end{code}
93
94 {-
95       = ppBesides [ppPStr SLIT("{-# LINE "), ppStr (show IBOX(src_line)), ppSP,
96                    ppChar '"', ppPStr src_file, ppPStr SLIT(" #-}")]
97  --ppPStr SLIT("\" #-}")]
98 -}