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