- pair_occ :: RnName -> Bag (RdrName, RnName)
- pair_occ rn
- = let
- str = getLocalName rn
- qual_bag = unitBag (Qual as_mod str, rn)
- in
- if qual
- then qual_bag
- else qual_bag -- the qualified name is *also* visible
- `snocBag` (Unqual str, rn)
-
-
- pair_as :: RnName -> (Module, RnName)
- pair_as rn = (as_mod, rn)
-
------------------------------
-{-
-getBuiltins :: ImportNameInfo
- -> Module
- -> Maybe (Bool, [RdrNameIE])
- -> (Bag (FAST_STRING, RnName),
- Bag (FAST_STRING, RnName),
- Maybe (Bool, [RdrNameIE]) -- return IEs that had no effect
- )
-
-getBuiltins _ modname maybe_spec
--- | modname `notElem` modulesWithBuiltins
- = (emptyBag, emptyBag, maybe_spec)
-
-getBuiltins (((b_val_names,b_tc_names),_,_,_),_,_,_) modname maybe_spec
- = case maybe_spec of
- Nothing -> (all_vals, all_tcs, Nothing)
-
- Just (True, ies) -> -- hiding does not work for builtin names
- trace "NOTE: `import Prelude hiding ...' does not hide built-in names" $
- (all_vals, all_tcs, maybe_spec)
-
- Just (False, ies) -> let
- (vals,tcs,ies_left) = do_builtin ies
- in
- (vals, tcs, Just (False, ies_left))
- where
- all_vals = do_all_builtin (fmToList b_val_names)
- all_tcs = do_all_builtin (fmToList b_tc_names)
-
- do_all_builtin [] = emptyBag
- do_all_builtin (((OrigName mod str),rn):rest)
- = --pprTrace "do_all_builtin:" (ppCat [ppPStr modname, ppPStr mod, ppPStr str]) $
- (if mod == modname then consBag (str, rn) else id) (do_all_builtin rest)
-
- do_builtin [] = (emptyBag,emptyBag,[])
- do_builtin (ie:ies)
- = let
- (str, orig)
- = case (ie_name ie) of
- Unqual s -> (s, OrigName modname s)
- Qual m s -> --pprTrace "do_builtin:surprising qual!" (ppCat [ppPStr m, ppPStr s]) $
- (s, OrigName modname s)
- in
- case (lookupFM b_tc_names orig) of -- NB: we favour the tycon/class FM...
- Just rn -> case (ie,rn) of
- (IEThingAbs _, WiredInTyCon tc)
- -> (vals, (str, rn) `consBag` tcs, ies_left)
- (IEThingAll _, WiredInTyCon tc)
- -> (listToBag (map (\ id -> (getLocalName id, WiredInId id))
- (tyConDataCons tc))
- `unionBags` vals,
- (str,rn) `consBag` tcs, ies_left)
- (IEThingWith _ _, WiredInTyCon tc) -- No checking of With...
- -> (listToBag (map (\ id -> (nameOf (origName "IEThingWith" id), WiredInId id))
- (tyConDataCons tc))
- `unionBags` vals,
- (str,rn) `consBag` tcs, ies_left)
- _ -> panic "importing builtin names (1)"
-
- Nothing ->
- case (lookupFM b_val_names orig) of
- Nothing -> (vals, tcs, ie:ies_left)
- Just rn -> case (ie,rn) of
- (IEVar _, WiredInId _)
- -> ((str, rn) `consBag` vals, tcs, ies_left)
- _ -> panic "importing builtin names (2)"
- where
- (vals, tcs, ies_left) = do_builtin ies
--}
+\begin{code}
+qualifyImports :: ModuleName -- Imported module
+ -> Bool -- True <=> want unqualified import
+ -> Maybe ModuleName -- Optional "as M" part
+ -> [AvailInfo] -- What's to be hidden
+ -> Avails -- Whats imported and how
+ -> (Name -> Name) -- Improves the provenance on imported things
+ -> RnMG (GlobalRdrEnv, ExportAvails)
+ -- NB: the Names in ExportAvails don't have the improve-provenance
+ -- function applied to them
+ -- We could fix that, but I don't think it matters
+
+qualifyImports this_mod unqual_imp as_mod hides
+ avails improve_prov
+ =
+ -- Make the name environment. We're talking about a
+ -- single module here, so there must be no name clashes.
+ -- In practice there only ever will be if it's the module
+ -- being compiled.
+ let
+ -- Add the things that are available
+ name_env1 = foldl add_avail emptyRdrEnv avails