\section[Name]{@Name@: to transmit name info from renamer to typechecker}
\begin{code}
+{-# OPTIONS -w #-}
+-- The above warning supression flag is a temporary kludge.
+-- While working on this module you are encouraged to remove it and fix
+-- any warnings in the module. See
+-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
+-- for details
+
module Name (
-- Re-export the OccName stuff
module OccName,
tidyNameOcc,
hashName, localiseName,
- nameSrcLoc, nameSrcSpan,
+ nameSrcLoc, nameSrcSpan, pprNameLoc,
isSystemName, isInternalName, isExternalName,
isTyVarName, isTyConName, isWiredInName, isBuiltInSyntax,
pprUnique uniq])
| BuiltInSyntax <- is_builtin = ppr_occ_name occ
-- never qualify builtin syntax
- | Just mod <- qualName sty mod occ = ppr mod <> dot <> ppr_occ_name occ
- -- the PrintUnqualified tells us how to qualify this Name, if at all
+ | NameQual modname <- qual_name = ppr modname <> dot <> ppr_occ_name occ
+ -- see HscTypes.mkPrintUnqualified and Outputable.QualifyName:
+ | NameNotInScope1 <- qual_name = ppr mod <> dot <> ppr_occ_name occ
+ | NameNotInScope2 <- qual_name = ppr (modulePackageId mod) <> char ':' <>
+ ppr (moduleName mod) <> dot <> ppr_occ_name occ
| otherwise = ppr_occ_name occ
+ where qual_name = qualName sty mod occ
pprInternal sty uniq occ
| codeStyle sty = pprUnique uniq
-- In code style, we Z-encode the strings. The results of Z-encoding each FastString are
-- cached behind the scenes in the FastString implementation.
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
+ | isGoodSrcSpan loc = pprDefnLoc loc
+ | isInternalName name || isSystemName name
+ = ptext SLIT("<no location info>")
+ | otherwise = ptext SLIT("Defined in ") <> ppr (nameModule name)
+ where loc = nameSrcSpan name
\end{code}
%************************************************************************