summaryrefslogtreecommitdiff
path: root/compiler/basicTypes
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2011-09-02 09:25:25 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2011-09-02 09:25:25 +0100
commit0ccf2c3bd1eb30f265f93e36ff4364f3c5bdda63 (patch)
treecee1e0824a49a2ec10838202026cb04cb02dda04 /compiler/basicTypes
parentfaadd61ef05e8f84a2ad7e0fb6b6d873a7b8c232 (diff)
downloadhaskell-0ccf2c3bd1eb30f265f93e36ff4364f3c5bdda63.tar.gz
Some minor wibbling in printing source locations
I found that an imported instance was getting printed with <no location info>. Fixing this pushed me into a bit more refactoring than I intended, but it's all small aesthetic stuff, nothing fundamental. Caused some error message to change as a result. I removed pprDefnLoc from the GHC API because it doesn't seem to be used. Name.pprNamedefnLoc and pprDefinedAt are probably more useful anyway.
Diffstat (limited to 'compiler/basicTypes')
-rw-r--r--compiler/basicTypes/Name.lhs38
-rw-r--r--compiler/basicTypes/SrcLoc.lhs7
2 files changed, 25 insertions, 20 deletions
diff --git a/compiler/basicTypes/Name.lhs b/compiler/basicTypes/Name.lhs
index c82a06c2f3..94ad72dade 100644
--- a/compiler/basicTypes/Name.lhs
+++ b/compiler/basicTypes/Name.lhs
@@ -37,7 +37,8 @@ module Name (
BuiltInSyntax(..),
-- ** Creating 'Name's
- mkInternalName, mkSystemName, mkDerivedInternalName,
+ mkSystemName, mkSystemNameAt,
+ mkInternalName, mkDerivedInternalName,
mkSystemVarName, mkSysTvName,
mkFCallName, mkIPName,
mkTickBoxOpName,
@@ -50,7 +51,7 @@ module Name (
hashName, localiseName,
mkLocalisedOccName,
- nameSrcLoc, nameSrcSpan, pprNameLoc,
+ nameSrcLoc, nameSrcSpan, pprNameDefnLoc, pprDefinedAt,
-- ** Predicates on 'Name's
isSystemName, isInternalName, isExternalName,
@@ -278,8 +279,11 @@ mkWiredInName mod occ uniq thing built_in
-- | Create a name brought into being by the compiler
mkSystemName :: Unique -> OccName -> Name
-mkSystemName uniq occ = Name { n_uniq = getKeyFastInt uniq, n_sort = System,
- n_occ = occ, n_loc = noSrcSpan }
+mkSystemName uniq occ = mkSystemNameAt uniq occ noSrcSpan
+
+mkSystemNameAt :: Unique -> OccName -> SrcSpan -> Name
+mkSystemNameAt uniq occ loc = Name { n_uniq = getKeyFastInt uniq, n_sort = System
+ , n_occ = occ, n_loc = loc }
mkSystemVarName :: Unique -> FastString -> Name
mkSystemVarName uniq fs = mkSystemName uniq (mkVarOccFS fs)
@@ -519,15 +523,23 @@ ppr_z_occ_name occ = ftext (zEncodeFS (occNameFS occ))
-- Prints (if mod information is available) "Defined at <loc>" or
-- "Defined in <mod>" information for a Name.
-pprNameLoc :: Name -> SDoc
-pprNameLoc name = case nameSrcSpan name of
- RealSrcSpan s ->
- pprDefnLoc s
- UnhelpfulSpan _
- | isInternalName name || isSystemName name ->
- ptext (sLit "<no location info>")
- | otherwise ->
- ptext (sLit "Defined in ") <> ppr (nameModule name)
+pprDefinedAt :: Name -> SDoc
+pprDefinedAt name = ptext (sLit "Defined") <+> pprNameDefnLoc name
+
+pprNameDefnLoc :: Name -> SDoc
+-- Prints "at <loc>" or
+-- or "in <mod>" depending on what info is available
+pprNameDefnLoc name
+ = case nameSrcLoc name of
+ -- nameSrcLoc rather than nameSrcSpan
+ -- It seems less cluttered to show a location
+ -- rather than a span for the definition point
+ RealSrcLoc s -> ptext (sLit "at") <+> ppr s
+ UnhelpfulLoc s
+ | isInternalName name || isSystemName name
+ -> ptext (sLit "at") <+> ftext s
+ | otherwise
+ -> ptext (sLit "in") <+> quotes (ppr (nameModule name))
\end{code}
%************************************************************************
diff --git a/compiler/basicTypes/SrcLoc.lhs b/compiler/basicTypes/SrcLoc.lhs
index f15d0da292..b89d55e62b 100644
--- a/compiler/basicTypes/SrcLoc.lhs
+++ b/compiler/basicTypes/SrcLoc.lhs
@@ -31,9 +31,6 @@ module SrcLoc (
srcLocLine, -- return the line part
srcLocCol, -- return the column part
- -- ** Misc. operations on SrcLoc
- pprDefnLoc,
-
-- * SrcSpan
RealSrcSpan, -- Abstract
SrcSpan(..),
@@ -481,10 +478,6 @@ pprUserRealSpan show_path (SrcSpanMultiLine src_path sline scol eline ecol)
pprUserRealSpan show_path (SrcSpanPoint src_path line col)
= hcat [ ppWhen show_path $ (pprFastFilePath src_path <> colon)
, int line, char ':', int col ]
-
-pprDefnLoc :: RealSrcSpan -> SDoc
--- ^ Pretty prints information about the 'SrcSpan' in the style "defined at ..."
-pprDefnLoc loc = ptext (sLit "Defined at") <+> ppr loc
\end{code}
%************************************************************************