-mkName ns str
- = split [] (reverse str)
- where
- split occ [] = mkRdrUnqual (mk_occ occ)
- split occ (c:d:rev) -- 'd' is the last char before the separator
- | is_sep c -- E.g. Fo.x d='o'
- && isAlphaNum d -- Fo.+: d='+' perhaps
- = mk_qual (reverse (d:rev)) c occ
- split occ (c:rev) = split (c:occ) rev
-
- mk_qual mod '.' occ = mkRdrQual (mk_mod mod) (mk_occ occ)
- mk_qual mod ':' occ = mkOrig (mk_mod mod) (mk_occ occ)
-
- mk_occ occ = mkOccFS ns (mkFastString occ)
- mk_mod mod = mkModuleName mod
-
- is_sep '.' = True
- is_sep ':' = True
- is_sep other = False
+-- This turns a Name into a RdrName
+-- The last case is slightly interesting. It constructs a
+-- unique name from the unique in the TH thingy, so that the renamer
+-- won't mess about. I hope. (Another possiblity would be to generate
+-- "x_77" etc, but that could conceivably clash.)
+
+mk_name ns (TH.Name occ (TH.NameG ns' mod)) = mkOrig (mk_mod mod) (mk_occ ns occ)
+mk_name ns (TH.Name occ TH.NameS) = mkRdrUnqual (mk_occ ns occ)
+mk_name ns (TH.Name occ (TH.NameU uniq)) = nameRdrName (mkInternalName (mk_uniq uniq) (mk_occ ns occ) noSrcLoc)
+
+mk_uniq :: Int# -> Unique
+mk_uniq u = mkUniqueGrimily (I# u)
+
+-- The packing and unpacking is rather turgid :-(
+mk_occ :: OccName.NameSpace -> TH.OccName -> OccName.OccName
+mk_occ ns occ = OccName.mkOccFS ns (mkFastString (TH.occString occ))
+
+mk_mod :: TH.ModName -> ModuleName
+mk_mod mod = mkModuleName (TH.modString mod)