-data NameSort
- = Local
- | Global Module
- | WiredInId Module Id
- | WiredInTyCon Module TyCon
-\end{code}
-
-Things with a @Global@ name are given C static labels, so they finally
-appear in the .o file's symbol table. They appear in the symbol table
-in the form M.n. If originally-local things have this property they
-must be made @Global@ first.
-
-\begin{code}
-mkLocalName :: Unique -> OccName -> SrcLoc -> Name
-mkLocalName uniq occ loc = Name { n_uniq = uniq, n_sort = Local, n_occ = occ,
- n_prov = LocalDef loc NotExported }
- -- NB: You might worry that after lots of huffing and
- -- puffing we might end up with two local names with distinct
- -- uniques, but the same OccName. Indeed we can, but that's ok
- -- * the insides of the compiler don't care: they use the Unique
- -- * when printing for -ddump-xxx you can switch on -dppr-debug to get the
- -- uniques if you get confused
- -- * for interface files we tidyCore first, which puts the uniques
- -- into the print name (see setNameVisibility below)
-
-mkGlobalName :: Unique -> Module -> OccName -> Provenance -> Name
-mkGlobalName uniq mod occ prov = Name { n_uniq = uniq, n_sort = Global mod,
- n_occ = occ, n_prov = prov }
-
-
-mkSysLocalName :: Unique -> FAST_STRING -> Name
-mkSysLocalName uniq fs = Name { n_uniq = uniq, n_sort = Local,
- n_occ = mkSrcVarOcc fs, n_prov = SystemProv }
-
-mkTopName :: Unique -> Module -> FAST_STRING -> Name
- -- Make a top-level name; make it Global if top-level
- -- things should be externally visible; Local otherwise
- -- This chap is only used *after* the tidyCore phase
- -- Notably, it is used during STG lambda lifting
- --
- -- We have to make sure that the name is globally unique
- -- and we don't have tidyCore to help us. So we append
- -- the unique. Hack! Hack!
-mkTopName uniq mod fs
- = Name { n_uniq = uniq,
- n_sort = mk_top_sort mod,
- n_occ = mkSrcVarOcc (_PK_ ((_UNPK_ fs) ++ show uniq)),
- n_prov = LocalDef noSrcLoc NotExported }
-
-------------------------- Wired in names -------------------------
-
-mkWiredInIdName :: Unique -> Module -> OccName -> Id -> Name
-mkWiredInIdName uniq mod occ id = Name { n_uniq = uniq, n_sort = WiredInId mod id,
- n_occ = occ, n_prov = SystemProv }
-
--- mkWiredInTyConName takes a FAST_STRING instead of
--- an OccName, which is a bit yukky but that's what the
--- clients find easiest.
-mkWiredInTyConName :: Unique -> Module -> FAST_STRING -> TyCon -> Name
-mkWiredInTyConName uniq mod fs tycon
- = Name { n_uniq = uniq, n_sort = WiredInTyCon mod tycon,
- n_occ = mkSrcOccFS tcName fs, n_prov = SystemProv }
-
-fixupSystemName :: Name -> Module -> Provenance -> Name
- -- Give the SystemProv name an appropriate provenance, and
- -- perhaps change the Moulde too (so that its HiFlag is right)
- -- There is a painful hack in that we want to push this
- -- better name into an WiredInId/TyCon so that it prints
- -- nicely in error messages
-fixupSystemName name@(Name {n_sort = Global _}) mod' prov'
- = name {n_sort = Global mod', n_prov = prov'}
-
-fixupSystemName name@(Name {n_sort = WiredInId _ id}) mod' prov'
- = name'
- where
- name' = name {n_sort = WiredInId mod' id', n_prov = prov'}
- id' = setIdName id name'
-
-fixupSystemName name@(Name {n_sort = WiredInTyCon _ tc}) mod' prov'
- = name'
- where
- name' = name {n_sort = WiredInTyCon mod' tc', n_prov = prov'}
- tc' = setTyConName tc name'
-
----------------------------------------------------------------------
-mkDerivedName :: (OccName -> OccName)
- -> Name -- Base name
- -> Unique -- New unique
- -> Name -- Result is always a value name