X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2FbasicTypes%2FSrcLoc.lhs;h=a8d037c0524361297d65b0c9b20815b796b687ea;hb=5f6ed0dad13261fd14e5edb4147d1e8f732c3969;hp=8d02e03ace127a85dc02f6b3c0c77e2bc0b404d1;hpb=c556f115ca05c6aec7327d3a5ee920dea3176f97;p=ghc-hetmet.git diff --git a/ghc/compiler/basicTypes/SrcLoc.lhs b/ghc/compiler/basicTypes/SrcLoc.lhs index 8d02e03..a8d037c 100644 --- a/ghc/compiler/basicTypes/SrcLoc.lhs +++ b/ghc/compiler/basicTypes/SrcLoc.lhs @@ -23,7 +23,7 @@ module SrcLoc ( srcLocFile, -- return the file name part srcLocLine, -- return the line part srcLocCol, -- return the column part - + pprDefnLoc, SrcSpan, -- Abstract noSrcSpan, @@ -161,7 +161,7 @@ instance Outputable SrcLoc where hcat [text "{-# LINE ", int src_line, space, char '\"', ftext src_path, text " #-}"] - ppr (ImportedLoc mod) = ptext SLIT("Imported from") <+> quotes (text mod) + ppr (ImportedLoc mod) = ptext SLIT("Imported from") <+> text mod ppr (UnhelpfulLoc s) = ftext s \end{code} @@ -284,21 +284,31 @@ mkSrcSpan loc1 loc2 file = srcLocFile loc1 combineSrcSpans :: SrcSpan -> SrcSpan -> SrcSpan +-- Assumes the 'file' part is the same in both combineSrcSpans (ImportedSpan str) _ = ImportedSpan str combineSrcSpans (UnhelpfulSpan str) r = r -- this seems more useful combineSrcSpans _ (ImportedSpan str) = ImportedSpan str combineSrcSpans l (UnhelpfulSpan str) = l combineSrcSpans start end - | line1 == line2 = if col1 == col2 - then SrcSpanPoint file line1 col1 - else SrcSpanOneLine file line1 col1 col2 - | otherwise = SrcSpanMultiLine file line1 col1 line2 col2 + = case line1 `compare` line2 of + EQ -> case col1 `compare` col2 of + EQ -> SrcSpanPoint file line1 col1 + LT -> SrcSpanOneLine file line1 col1 col2 + GT -> SrcSpanOneLine file line1 col2 col1 + LT -> SrcSpanMultiLine file line1 col1 line2 col2 + GT -> SrcSpanMultiLine file line2 col2 line1 col1 where line1 = srcSpanStartLine start + col1 = srcSpanStartCol start line2 = srcSpanEndLine end - col1 = srcSpanStartCol start - col2 = srcSpanEndCol end - file = srcSpanFile start + col2 = srcSpanEndCol end + file = srcSpanFile start + +pprDefnLoc :: SrcLoc -> SDoc +-- "defined at ..." or "imported from ..." +pprDefnLoc loc + | isGoodSrcLoc loc = ptext SLIT("Defined at") <+> ppr loc + | otherwise = ppr loc instance Outputable SrcSpan where ppr span