-type ImportNameInfo = (GlobalNameInfo,
- FiniteMap (Module,FAST_STRING) RnName, -- values imported so far
- FiniteMap (Module,FAST_STRING) RnName, -- tycons/classes imported so far
- Name -> (ExportFlag, [SrcLoc])) -- import flag and src locns
-
-type RnM_IInfo s r = RnMonad ImportNameInfo s r
-
-doImportDecls ::
- IfaceCache
- -> GlobalNameInfo -- builtin and knot name info
- -> UniqSupply
- -> [RdrNameImportDecl] -- import declarations
- -> IO (Bag (RdrName,RnName), -- imported values in scope
- Bag (RdrName,RnName), -- imported tycons/classes in scope
- [Module], -- directly imported modules
- Bag (Module,RnName), -- unqualified import from module
- Bag RenamedFixityDecl, -- fixity info for imported names
- Bag Error,
- Bag Warning)
-
-doImportDecls iface_cache g_info us src_imps
- = fixIO ( \ ~(_, _, _, _, _, _, rec_imp_stuff) ->
- let
- rec_imp_fm = addListToUFM_C add_stuff emptyUFM (bagToList rec_imp_stuff)
- add_stuff (imp1,locns1) (imp2,locns2) = (lubExportFlag imp1 imp2, locns1 `unionBags` locns2)
-
- rec_imp_fn :: Name -> (ExportFlag, [SrcLoc])
- rec_imp_fn n = case lookupUFM rec_imp_fm n of
- Nothing -> panic "RnNames:rec_imp_fn"
- Just (flag, locns) -> (flag, bagToList locns)
-
- i_info = (g_info, emptyFM, emptyFM, rec_imp_fn)
- in
- -- cache the imported modules
- -- this ensures that all directly imported modules
- -- will have their original name iface in scope
- accumulate (map (cachedIface False iface_cache) imp_mods) >>
-
- -- process the imports
- doImports iface_cache i_info us all_imps
-
- ) >>= \ (vals, tcs, unquals, fixes, errs, warns, _) ->
-
- return (vals, tcs, imp_mods, unquals, fixes,
- imp_errs `unionBags` errs,
- imp_warns `unionBags` warns)
- where
- the_imps = implicit_prel ++ src_imps
- all_imps = implicit_qprel ++ the_imps
-
- implicit_qprel = if opt_NoImplicitPrelude
- then [{- no "import qualified Prelude" -}]
- else [ImportDecl pRELUDE True Nothing Nothing prel_loc]
-
- explicit_prelude_imp = not (null [ () | (ImportDecl mod qual _ _ _) <- src_imps,
- mod == pRELUDE ])
-
- implicit_prel = if explicit_prelude_imp || opt_NoImplicitPrelude
- then [{- no "import Prelude" -}]
- else [ImportDecl pRELUDE False Nothing Nothing prel_loc]
-
- prel_loc = mkBuiltinSrcLoc
-
- (uniq_imps, imp_dups) = removeDups cmp_mod the_imps
- cmp_mod (ImportDecl m1 _ _ _ _) (ImportDecl m2 _ _ _ _) = cmpPString m1 m2
-
- qprel_imps = [ imp | imp@(ImportDecl mod True Nothing _ _) <- src_imps,
- fromPrelude mod ]
-
- qual_mods = [ (qual_name mod as_mod, imp) | imp@(ImportDecl mod True as_mod _ _) <- src_imps ]
- qual_name mod (Just as_mod) = as_mod
- qual_name mod Nothing = mod
-
- (_, qual_dups) = removeDups cmp_qual qual_mods
- bad_qual_dups = filter (not . all_same_mod) qual_dups
-
- cmp_qual (q1,_) (q2,_) = cmpPString q1 q2
- all_same_mod ((q,ImportDecl mod _ _ _ _):rest)
- = all has_same_mod rest
- where
- has_same_mod (q,ImportDecl mod2 _ _ _ _) = mod == mod2
-