[project @ 1997-05-26 04:56:00 by sof]
[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 Outputable
30 import Pretty
31
32 \end{code}
33
34 %************************************************************************
35 %*                                                                      *
36 \subsection[SrcLoc-SrcLocations]{Source-location information}
37 %*                                                                      *
38 %************************************************************************
39
40 We keep information about the {\em definition} point for each entity;
41 this is the obvious stuff:
42 \begin{code}
43 data SrcLoc
44   = NoSrcLoc
45
46   | SrcLoc      FAST_STRING     -- A precise location
47                 FAST_INT
48
49   | UnhelpfulSrcLoc FAST_STRING -- Just a general indication
50 \end{code}
51
52 Note that an entity might be imported via more than one route, and
53 there could be more than one ``definition point'' --- in two or more
54 \tr{.hi} files.  We deemed it probably-unworthwhile to cater for this
55 rare case.
56
57 %************************************************************************
58 %*                                                                      *
59 \subsection[SrcLoc-access-fns]{Access functions for names}
60 %*                                                                      *
61 %************************************************************************
62
63 Things to make 'em:
64 \begin{code}
65 noSrcLoc            = NoSrcLoc
66 mkSrcLoc x IBOX(y)  = SrcLoc x y
67
68 mkIfaceSrcLoc       = UnhelpfulSrcLoc SLIT("<an interface file>")
69 mkBuiltinSrcLoc     = UnhelpfulSrcLoc SLIT("<built-into-the-compiler>")
70 mkGeneratedSrcLoc   = UnhelpfulSrcLoc SLIT("<compiler-generated-code>")
71
72 isNoSrcLoc NoSrcLoc = True
73 isNoSrcLoc other    = False
74 \end{code}
75
76 %************************************************************************
77 %*                                                                      *
78 \subsection[SrcLoc-instances]{Instance declarations for various names}
79 %*                                                                      *
80 %************************************************************************
81
82 \begin{code}
83 instance Outputable SrcLoc where
84     ppr sty (SrcLoc src_file src_line)
85       | userStyle sty
86       = hcat [ ptext src_file, char ':', text (show IBOX(src_line)) ]
87
88       | otherwise
89       = hcat [text "{-# LINE ", text (show IBOX(src_line)), space,
90                    char '\"', ptext src_file, text " #-}"]
91     ppr sty (UnhelpfulSrcLoc s) = ptext s
92
93     ppr sty NoSrcLoc = text "<NoSrcLoc>"
94 \end{code}
95
96 {-
97       = hcat [ptext SLIT("{-# LINE "), text (show IBOX(src_line)), space,
98                    char '"', ptext src_file, ptext SLIT(" #-}")]
99  --ptext SLIT("\" #-}")]
100 -}