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
27 #include "HsVersions.h"
30 import FastString ( unpackFS )
31 import GlaExts ( Int(..), Int#, (+#) )
34 %************************************************************************
36 \subsection[SrcLoc-SrcLocations]{Source-location information}
38 %************************************************************************
40 We keep information about the {\em definition} point for each entity;
41 this is the obvious stuff:
46 | SrcLoc FAST_STRING -- A precise location (file name)
49 | UnhelpfulSrcLoc FAST_STRING -- Just a general indication
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
57 %************************************************************************
59 \subsection[SrcLoc-access-fns]{Access functions for names}
61 %************************************************************************
66 mkSrcLoc x IBOX(y) = SrcLoc x y
68 mkIfaceSrcLoc = UnhelpfulSrcLoc SLIT("<an interface file>")
69 mkBuiltinSrcLoc = UnhelpfulSrcLoc SLIT("<built-into-the-compiler>")
70 mkGeneratedSrcLoc = UnhelpfulSrcLoc SLIT("<compiler-generated-code>")
72 isNoSrcLoc NoSrcLoc = True
73 isNoSrcLoc other = False
75 incSrcLine :: SrcLoc -> SrcLoc
76 incSrcLine (SrcLoc s l) = SrcLoc s (l +# 1#)
80 %************************************************************************
82 \subsection[SrcLoc-instances]{Instance declarations for various names}
84 %************************************************************************
87 instance Outputable SrcLoc where
88 ppr (SrcLoc src_path src_line)
89 = getPprStyle $ \ sty ->
91 hcat [ text src_file, char ':', int IBOX(src_line) ]
93 if debugStyle sty then
94 hcat [ ptext src_path, char ':', int IBOX(src_line) ]
96 hcat [text "{-# LINE ", int IBOX(src_line), space,
97 char '\"', ptext src_path, text " #-}"]
99 src_file = remove_directory_prefix (unpackFS src_path)
101 remove_directory_prefix path = case break (== '/') path of
102 (filename, []) -> filename
103 (prefix, slash : rest) -> ASSERT( slash == '/' )
104 remove_directory_prefix rest
106 ppr (UnhelpfulSrcLoc s) = ptext s
108 ppr NoSrcLoc = text "<NoSrcLoc>"