X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2FbasicTypes%2FName.lhs;h=9f23f969e48083f1fadd476a132d6bd5ae889377;hb=6d65a616ca845f7d574af8da8a8c183f24f40caa;hp=cf212aee29065220b5f2ac998d84d50fce1e3194;hpb=703a9c113f4770958d659411011456742cd695a6;p=ghc-hetmet.git diff --git a/compiler/basicTypes/Name.lhs b/compiler/basicTypes/Name.lhs index cf212ae..9f23f96 100644 --- a/compiler/basicTypes/Name.lhs +++ b/compiler/basicTypes/Name.lhs @@ -63,7 +63,7 @@ module Name ( NamedThing(..), getSrcLoc, getSrcSpan, getOccString, - pprInfixName, pprPrefixName, + pprInfixName, pprPrefixName, pprModulePrefix, -- Re-export the OccName stuff module OccName @@ -77,6 +77,7 @@ import SrcLoc import Unique import Maybes import Binary +import StaticFlags import FastTypes import FastString import Outputable @@ -395,30 +396,23 @@ pprName (Name {n_sort = sort, n_uniq = u, n_occ = occ}) pprExternal :: PprStyle -> Unique -> Module -> OccName -> Bool -> BuiltInSyntax -> SDoc pprExternal sty uniq mod occ is_wired is_builtin - | codeStyle sty = ppr mod <> char '_' <> ppr_z_occ_name occ + | codeStyle sty = ppr 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 - | 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 + | 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 + | otherwise = pprModulePrefix sty mod occ <> ppr_occ_name occ pprInternal :: PprStyle -> Unique -> OccName -> SDoc 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 + | dumpStyle sty = ppr_occ_name occ <> ppr_underscore_unique 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 @@ -427,13 +421,32 @@ pprInternal sty uniq occ pprSystem :: PprStyle -> Unique -> OccName -> SDoc pprSystem sty uniq occ | codeStyle sty = pprUnique uniq - | debugStyle sty = ppr_occ_name occ <> char '_' <> pprUnique uniq + | debugStyle sty = ppr_occ_name occ <> ppr_underscore_unique uniq <> braces (pprNameSpaceBrief (occNameSpace occ)) - | otherwise = ppr_occ_name occ <> char '_' <> pprUnique uniq + | otherwise = ppr_occ_name occ <> ppr_underscore_unique uniq -- If the tidy phase hasn't run, the OccName -- is unlikely to be informative (like 's'), -- so print the unique + +pprModulePrefix :: PprStyle -> Module -> OccName -> SDoc +-- Print the "M." part of a name, based on whether it's in scope or not +-- See Note [Printing original names] in HscTypes +pprModulePrefix sty mod occ + = case qualName sty mod occ of -- See Outputable.QualifyName: + NameQual modname -> ppr modname <> dot -- Name is in scope + NameNotInScope1 -> ppr mod <> dot -- Not in scope + NameNotInScope2 -> ppr (modulePackageId mod) <> colon -- Module not in + <> ppr (moduleName mod) <> dot -- scope eithber + _otherwise -> empty + +ppr_underscore_unique :: Unique -> SDoc +-- Print an underscore separating the name from its unique +-- But suppress it if we aren't printing the uniques anyway +ppr_underscore_unique uniq + | opt_SuppressUniques = empty + | otherwise = char '_' <> pprUnique uniq + ppr_occ_name :: OccName -> SDoc ppr_occ_name occ = ftext (occNameFS occ) -- Don't use pprOccName; instead, just print the string of the OccName;