- if codeStyle sty then
- ppr mod <> underscore <> ppr occ
- else
- pp_mod_dot sty <> ppr occ <> pp_global_debug sty uniq prov
- where
- mod = nameSortModule sort
-
- pp_mod_dot sty
- = case prov of
- SystemProv -> pp_qual mod dot user_sty
- -- Hack alert! Omit the qualifier on SystemProv things, which I claim
- -- will also be WiredIn things. We can't get the omit flag right
- -- on wired in tycons etc (sigh) so we just leave it out in user style,
- -- and hope that leaving it out isn't too consfusing.
- -- (e.g. if the programmer hides Bool and redefines it. If so, use -dppr-debug.)
-
- LocalDef _ _ -> pp_qual mod dot (user_sty || iface_sty)
-
- NonLocalDef (UserImport imp_mod _ _) omit
- | user_sty -> pp_qual imp_mod pp_sep omit
- | otherwise -> pp_qual mod pp_sep False
- NonLocalDef ImplicitImport omit -> pp_qual mod pp_sep (user_sty && omit)
- where
- user_sty = userStyle sty
- iface_sty = ifaceStyle sty
-
- pp_qual mod sep omit_qual
- | omit_qual = empty
- | otherwise = pprModule mod <> sep
-
- pp_sep | bootFlavour (moduleIfaceFlavour mod) = text "!" -- M!t indicates a name imported
- -- from a .hi-boot interface
- | otherwise = dot -- Vanilla case
-
- pp_global_debug sty uniq prov
- | debugStyle sty = hcat [text "{-", pprUnique uniq, prov_p prov, text "-}"]
- | otherwise = empty
-
- prov_p prov | opt_PprStyle_NoPrags = empty
- | otherwise = comma <> pp_prov prov
-
-pp_prov (LocalDef _ Exported) = char 'x'
-pp_prov (LocalDef _ NotExported) = char 'l'
-pp_prov (NonLocalDef ImplicitImport _) = char 'j'
-pp_prov (NonLocalDef (UserImport _ _ True ) _) = char 'I' -- Imported by name
-pp_prov (NonLocalDef (UserImport _ _ False) _) = char 'i' -- Imported by ..
-pp_prov SystemProv = char 's'
-\end{code}
+ case sort of
+ WiredIn mod _ _ builtin -> pprExternal sty uniq mod occ True builtin
+ External mod _ -> pprExternal sty uniq mod occ False UserSyntax
+ System -> pprSystem sty uniq occ
+ Internal -> pprInternal sty uniq occ
+
+pprExternal sty uniq mod occ is_wired is_builtin
+ | codeStyle sty = ppr_z_module mod <> char '_' <> ppr_z_occ_name occ
+ -- In code style, always qualify
+ -- ToDo: maybe we could print all wired-in things unqualified
+ -- in code style, to reduce symbol table bloat?
+ | debugStyle sty = ppr mod <> dot <> ppr_occ_name occ
+ <> braces (hsep [if is_wired then ptext SLIT("(w)") else empty,
+ pprNameSpaceBrief (occNameSpace occ),
+ pprUnique uniq])
+ | BuiltInSyntax <- is_builtin = ppr_occ_name occ
+ -- never qualify builtin syntax
+ | unqualStyle sty mod occ = ppr_occ_name occ
+ | otherwise = ppr mod <> dot <> ppr_occ_name occ
+
+pprInternal sty uniq occ
+ | codeStyle sty = pprUnique uniq
+ | debugStyle sty = ppr_occ_name occ <> braces (hsep [pprNameSpaceBrief (occNameSpace occ),
+ pprUnique uniq])
+ | dumpStyle sty = ppr_occ_name occ <> char '_' <> pprUnique uniq
+ -- For debug dumps, we're not necessarily dumping
+ -- tidied code, so we need to print the uniques.
+ | otherwise = ppr_occ_name occ -- User style
+
+-- Like Internal, except that we only omit the unique in Iface style
+pprSystem sty uniq occ
+ | codeStyle sty = pprUnique uniq
+ | debugStyle sty = ppr_occ_name occ <> char '_' <> pprUnique uniq
+ <> braces (pprNameSpaceBrief (occNameSpace occ))
+ | otherwise = ppr_occ_name occ <> char '_' <> pprUnique uniq
+ -- If the tidy phase hasn't run, the OccName
+ -- is unlikely to be informative (like 's'),
+ -- so print the unique
+
+ppr_occ_name occ = ftext (occNameFS occ)
+ -- Don't use pprOccName; instead, just print the string of the OccName;
+ -- we print the namespace in the debug stuff above
+
+-- 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))
+ppr_z_module mod = ftext (zEncodeFS (moduleFS mod))