X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2FbasicTypes%2FSrcLoc.lhs;h=1c3cc687e595fdc32ccf6bae09efaa1619de2b6a;hb=9adbdb312507dcc7d5777e36376535918549103b;hp=5ebb9e6801771672cec275ade31a528a72a3923d;hpb=18976e614fd90a8d81ced2c3e9cd8e38d72a1f40;p=ghc-hetmet.git diff --git a/ghc/compiler/basicTypes/SrcLoc.lhs b/ghc/compiler/basicTypes/SrcLoc.lhs index 5ebb9e6..1c3cc68 100644 --- a/ghc/compiler/basicTypes/SrcLoc.lhs +++ b/ghc/compiler/basicTypes/SrcLoc.lhs @@ -11,19 +11,17 @@ module SrcLoc ( SrcLoc, -- Abstract - mkSrcLoc, - noSrcLoc, isNoSrcLoc, -- "I'm sorry, I haven't a clue" + mkSrcLoc, isGoodSrcLoc, + noSrcLoc, -- "I'm sorry, I haven't a clue" - mkIfaceSrcLoc, -- Unknown place in an interface - -- (this one can die eventually ToDo) + importedSrcLoc, -- Unknown place in an interface + builtinSrcLoc, -- Something wired into the compiler + generatedSrcLoc, -- Code generated within the compiler - mkBuiltinSrcLoc, -- Something wired into the compiler - - mkGeneratedSrcLoc, -- Code generated within the compiler - - incSrcLine, + incSrcLine, replaceSrcLine, - srcLocFile -- return the file name part. + srcLocFile, -- return the file name part. + srcLocLine -- return the line part. ) where #include "HsVersions.h" @@ -31,6 +29,7 @@ module SrcLoc ( import Util ( thenCmp ) import Outputable import FastString ( unpackFS ) +import FastTypes import GlaExts ( Int(..), (+#) ) \end{code} @@ -44,12 +43,12 @@ We keep information about the {\em definition} point for each entity; this is the obvious stuff: \begin{code} data SrcLoc - = NoSrcLoc - - | SrcLoc FAST_STRING -- A precise location (file name) - FAST_INT + = SrcLoc FAST_STRING -- A precise location (file name) + FastInt | UnhelpfulSrcLoc FAST_STRING -- Just a general indication + + | NoSrcLoc \end{code} Note that an entity might be imported via more than one route, and @@ -65,22 +64,27 @@ rare case. Things to make 'em: \begin{code} -noSrcLoc = NoSrcLoc -mkSrcLoc x IBOX(y) = SrcLoc x y - -mkIfaceSrcLoc = UnhelpfulSrcLoc SLIT("") -mkBuiltinSrcLoc = UnhelpfulSrcLoc SLIT("") -mkGeneratedSrcLoc = UnhelpfulSrcLoc SLIT("") +mkSrcLoc x y = SrcLoc x (iUnbox y) +noSrcLoc = NoSrcLoc +importedSrcLoc = UnhelpfulSrcLoc SLIT("") +builtinSrcLoc = UnhelpfulSrcLoc SLIT("") +generatedSrcLoc = UnhelpfulSrcLoc SLIT("") -isNoSrcLoc NoSrcLoc = True -isNoSrcLoc other = False +isGoodSrcLoc (SrcLoc _ _) = True +isGoodSrcLoc other = False srcLocFile :: SrcLoc -> FAST_STRING srcLocFile (SrcLoc fname _) = fname +srcLocLine :: SrcLoc -> FastInt +srcLocLine (SrcLoc _ l) = l + incSrcLine :: SrcLoc -> SrcLoc incSrcLine (SrcLoc s l) = SrcLoc s (l +# 1#) incSrcLine loc = loc + +replaceSrcLine :: SrcLoc -> FastInt -> SrcLoc +replaceSrcLine (SrcLoc s _) l = SrcLoc s l \end{code} %************************************************************************ @@ -117,22 +121,16 @@ instance Outputable SrcLoc where ppr (SrcLoc src_path src_line) = getPprStyle $ \ sty -> if userStyle sty then - hcat [ text src_file, char ':', int IBOX(src_line) ] + hcat [ text src_file, char ':', int (iBox src_line) ] else if debugStyle sty then - hcat [ ptext src_path, char ':', int IBOX(src_line) ] + hcat [ ptext src_path, char ':', int (iBox src_line) ] else - hcat [text "{-# LINE ", int IBOX(src_line), space, + hcat [text "{-# LINE ", int (iBox src_line), space, char '\"', ptext src_path, text " #-}"] where - src_file = remove_directory_prefix (unpackFS src_path) - - remove_directory_prefix path = case break (== '/') path of - (filename, []) -> filename - (prefix, slash : rest) -> ASSERT( slash == '/' ) - remove_directory_prefix rest + src_file = unpackFS src_path -- Leave the directory prefix intact, + -- so emacs can find the file ppr (UnhelpfulSrcLoc s) = ptext s - - ppr NoSrcLoc = text "" \end{code}