- ppr PprQuote name@(Local _ _ _) = quotes (ppr (PprForUser 1) name)
-
- -- When printing interfaces, all Locals have been given nice print-names
- ppr (PprForUser _) (Local _ n _) = ptext (occNameString n)
- ppr PprInterface (Local _ n _) = ptext (occNameString n)
-
- ppr sty (Local u n _) | codeStyle sty = pprUnique u
-
- ppr sty (Local u n _) = hcat [ptext (occNameString n), ptext SLIT("_"), pprUnique u]
-
- ppr PprQuote name@(Global _ _ _ _) = quotes (ppr (PprForUser 1) name)
-
- ppr sty name@(Global u m n _)
- | codeStyle sty
- = identToC (m _APPEND_ SLIT(".") _APPEND_ occNameString n)
-
- ppr sty name@(Global u m n prov)
- = hcat [pp_mod_dot, ptext (occNameString n), pp_debug sty name]
- where
- pp_mod = pprModule (PprForUser 1) m
- pp_mod_dot = case prov of --- Omit home module qualifier
- LocalDef _ _ -> empty
- Imported _ _ hif -> pp_mod <> pp_dot hif
- Implicit hif -> pp_mod <> pp_dot hif
- other -> pp_mod <> text "."
-
- pp_dot HiFile = text "." -- Vanilla case
- pp_dot HiBootFile = text "!" -- M!t indicates a name imported from a .hi-boot interface
-
-
-pp_debug PprDebug (Global uniq m n prov) = hcat [text "{-", pprUnique uniq, char ',',
- pp_prov prov, text "-}"]
- where
- pp_prov (LocalDef Exported _) = char 'x'
- pp_prov (LocalDef NotExported _) = char 'l'
- pp_prov (Imported _ _ _) = char 'i'
- pp_prov (Implicit _) = char 'p'
- pp_prov (WiredInTyCon _) = char 'W'
- pp_prov (WiredInId _) = char 'w'
-pp_debug other name = empty
-
--- pprNameProvenance is used in error messages to say where a name came from
-pprNameProvenance :: PprStyle -> Name -> Doc
-pprNameProvenance sty (Local _ _ loc) = pprProvenance sty (LocalDef NotExported loc)
-pprNameProvenance sty (Global _ _ _ prov) = pprProvenance sty prov
-
-pprProvenance :: PprStyle -> Provenance -> Doc
-pprProvenance sty (Imported mod loc _)
- = sep [ptext SLIT("Imported from"), pprModule sty mod, ptext SLIT("at"), ppr sty loc]
-pprProvenance sty (LocalDef _ loc) = sep [ptext SLIT("Defined at"), ppr sty loc]
-pprProvenance sty (Implicit _) = panic "pprNameProvenance: Implicit"
-pprProvenance sty (WiredInTyCon tc) = ptext SLIT("Wired-in tycon")
-pprProvenance sty (WiredInId id) = ptext SLIT("Wired-in id")
-\end{code}
-
-
-%************************************************************************
-%* *
-\subsection[Sets of names}
-%* *
-%************************************************************************
-
-\begin{code}
-type NameSet = UniqSet Name
-emptyNameSet :: NameSet
-unitNameSet :: Name -> NameSet
-addListToNameSet :: NameSet -> [Name] -> NameSet
-addOneToNameSet :: NameSet -> Name -> NameSet
-mkNameSet :: [Name] -> NameSet
-unionNameSets :: NameSet -> NameSet -> NameSet
-unionManyNameSets :: [NameSet] -> NameSet
-minusNameSet :: NameSet -> NameSet -> NameSet
-elemNameSet :: Name -> NameSet -> Bool
-nameSetToList :: NameSet -> [Name]
-isEmptyNameSet :: NameSet -> Bool
-
-isEmptyNameSet = isEmptyUniqSet
-emptyNameSet = emptyUniqSet
-unitNameSet = unitUniqSet
-mkNameSet = mkUniqSet
-addListToNameSet = addListToUniqSet
-addOneToNameSet = addOneToUniqSet
-unionNameSets = unionUniqSets
-unionManyNameSets = unionManyUniqSets
-minusNameSet = minusUniqSet
-elemNameSet = elementOfUniqSet
-nameSetToList = uniqSetToList
+ -- When printing interfaces, all Internals have been given nice print-names
+ ppr name = pprName name
+
+instance OutputableBndr Name where
+ pprBndr _ name = pprName name
+
+pprName (Name {n_sort = sort, n_uniq = uniq, n_occ = occ})
+ = getPprStyle $ \ sty ->
+ case sort of
+ WiredIn mod _ _ BuiltInSyntax -> pprOccName occ -- Built-in syntax is never qualified
+ WiredIn mod _ _ UserSyntax -> pprExternal sty uniq mod occ True
+ External mod _ -> pprExternal sty uniq mod occ False
+ System -> pprSystem sty uniq occ
+ Internal -> pprInternal sty uniq occ
+
+pprExternal sty uniq mod occ is_wired
+ | unqualStyle sty mod_name occ = pprOccName occ
+ | codeStyle sty = ppr mod_name <> char '_' <> pprOccName occ
+ | debugStyle sty = sep [ppr mod_name <> dot <> pprOccName occ,
+ hsep [text "{-"
+ , if is_wired then ptext SLIT("(w)") else empty
+ , pprUnique uniq
+-- (overkill) , case mb_p of
+-- Nothing -> empty
+-- Just n -> brackets (ppr n)
+ , text "-}"]]
+ | otherwise = ppr mod_name <> dot <> pprOccName occ
+ where
+ mod_name = moduleName mod
+
+pprInternal sty uniq occ
+ | codeStyle sty = pprUnique uniq
+ | debugStyle sty = pprOccName occ <> text "{-" <> pprUnique uniq <> text "-}"
+ | otherwise = pprOccName occ -- User style
+
+-- Like Internal, except that we only omit the unique in Iface style
+pprSystem sty uniq occ
+ | codeStyle sty = pprUnique uniq
+ | otherwise = pprOccName occ <> char '_' <> pprUnique uniq
+ -- If the tidy phase hasn't run, the OccName
+ -- is unlikely to be informative (like 's'),
+ -- so print the unique