2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1994
4 %************************************************************************
6 \section[SrcLoc]{The @SrcLoc@ type}
8 %************************************************************************
15 noSrcLoc, isNoSrcLoc, -- "I'm sorry, I haven't a clue"
17 mkIfaceSrcLoc, -- Unknown place in an interface
18 -- (this one can die eventually ToDo)
20 mkBuiltinSrcLoc, -- Something wired into the compiler
22 mkGeneratedSrcLoc, -- Code generated within the compiler
26 srcLocFile -- return the file name part.
29 #include "HsVersions.h"
32 import FastString ( unpackFS )
33 import GlaExts ( Int(..), Int#, (+#) )
36 %************************************************************************
38 \subsection[SrcLoc-SrcLocations]{Source-location information}
40 %************************************************************************
42 We keep information about the {\em definition} point for each entity;
43 this is the obvious stuff:
48 | SrcLoc FAST_STRING -- A precise location (file name)
51 | UnhelpfulSrcLoc FAST_STRING -- Just a general indication
54 Note that an entity might be imported via more than one route, and
55 there could be more than one ``definition point'' --- in two or more
56 \tr{.hi} files. We deemed it probably-unworthwhile to cater for this
59 %************************************************************************
61 \subsection[SrcLoc-access-fns]{Access functions for names}
63 %************************************************************************
68 mkSrcLoc x IBOX(y) = SrcLoc x y
70 mkIfaceSrcLoc = UnhelpfulSrcLoc SLIT("<an interface file>")
71 mkBuiltinSrcLoc = UnhelpfulSrcLoc SLIT("<built-into-the-compiler>")
72 mkGeneratedSrcLoc = UnhelpfulSrcLoc SLIT("<compiler-generated-code>")
74 isNoSrcLoc NoSrcLoc = True
75 isNoSrcLoc other = False
77 srcLocFile :: SrcLoc -> FAST_STRING
78 srcLocFile (SrcLoc fname _) = fname
80 incSrcLine :: SrcLoc -> SrcLoc
81 incSrcLine (SrcLoc s l) = SrcLoc s (l +# 1#)
85 %************************************************************************
87 \subsection[SrcLoc-instances]{Instance declarations for various names}
89 %************************************************************************
92 instance Outputable SrcLoc where
93 ppr (SrcLoc src_path src_line)
94 = getPprStyle $ \ sty ->
96 hcat [ text src_file, char ':', int IBOX(src_line) ]
98 if debugStyle sty then
99 hcat [ ptext src_path, char ':', int IBOX(src_line) ]
101 hcat [text "{-# LINE ", int IBOX(src_line), space,
102 char '\"', ptext src_path, text " #-}"]
104 src_file = remove_directory_prefix (unpackFS src_path)
106 remove_directory_prefix path = case break (== '/') path of
107 (filename, []) -> filename
108 (prefix, slash : rest) -> ASSERT( slash == '/' )
109 remove_directory_prefix rest
111 ppr (UnhelpfulSrcLoc s) = ptext s
113 ppr NoSrcLoc = text "<NoSrcLoc>"