-mkGlobalNameFun this_module prel_nf alist
- = the_fun
- where
- the_fun (Prel n) = Just n
- the_fun (Unk s) = case (unk_fun s) of
- Just n -> Just n
- Nothing -> prel_nf s
- the_fun (Imp m d _ _) = imp_fun (d, m) -- NB: module-name 2nd!
-
- -- Things in the domain of the prelude function shouldn't be put
- -- in the unk_fun; because the prel_nf will catch them.
- -- This can arise if, for example, an interface gives a signature
- -- for a prelude thing.
- --
- -- Neither should they be in the domain of the imp_fun, because
- -- prelude things will have been converted to Prel x rather than
- -- Imp p q r s.
- --
- -- So we strip out prelude things from the alist; this is not just
- -- desirable, it's essential because get_orig and get_local don't handle
- -- prelude things.
-
- non_prel_alist = filter non_prel alist
-
- non_prel (Prel _, _) = False
- non_prel other = True
-
- -- unk_fun looks up local names (just strings),
- -- imp_fun looks up original names: (string,string) pairs
- unk_fun = lookupFM (listToFM [(get_local pn,n) | (pn,n) <- non_prel_alist])
- imp_fun = lookupFM (listToFM [(get_orig pn,n) | (pn,n) <- non_prel_alist])
-
- -- the lists *are* sorted by *some* ordering (by local
- -- names), but not generally, and not in some way we
- -- are going to rely on.
-
- get_local :: ProtoName -> FAST_STRING
- get_local (Unk s) = s
- get_local (Imp _ _ _ l) = l
- get_local (Prel n) = pprPanic "get_local: " (ppr PprShowAll n)
-
- get_orig :: ProtoName -> (FAST_STRING, FAST_STRING) -- **NB**! module-name 2nd!
- get_orig (Unk s) = (s, this_module)
- get_orig (Imp m d _ _) = (d, m)
- get_orig (Prel n) = pprPanic "get_orig: " (ppr PprShowAll n)
+Seperate FiniteMaps are kept for lookup up Qual names,
+Unqual names and Local names.
+
+\begin{code}
+type RnEnv = ((QualNames, UnqualNames, QualNames, UnqualNames), ScopeStack)
+
+type QualNames = FiniteMap (FAST_STRING,Module) RnName
+type UnqualNames = FiniteMap FAST_STRING RnName
+type ScopeStack = FiniteMap FAST_STRING RnName
+
+emptyRnEnv :: RnEnv
+extendGlobalRnEnv :: RnEnv -> [(RdrName,RnName)] -> [(RdrName,RnName)]
+ -> (RnEnv, Bag (RdrName, RnName, RnName))
+extendLocalRnEnv :: Bool -> RnEnv -> [RnName] -> (RnEnv, [RnName])
+lookupRnEnv :: RnEnv -> RdrName -> Maybe RnName
+lookupTcRnEnv :: RnEnv -> RdrName -> Maybe RnName