- -- Build finite map of exported names to export flag
- exp_map0 = addListToUFM_C lub_expflag emptyUFM (map pair_fst uniq_exp_names)
- (exp_map1, empty_mods) = foldl add_mod_names (exp_map0, []) uniq_exp_mods
-
- mod_fm = addListToFM_C unionBags emptyFM
- [(mod, unitBag (getName rn, nameImportFlag (getName rn)))
- | (mod,rn) <- bagToList unqual_imps, isRnDecl rn]
+ (uniq_mods, dup_mods) = removeDups cmpPString exp_mods
+ (expmods_this, expmods_imps) = partition (== this_mod) uniq_mods
+
+ -- Get names for "module This_Mod" export
+ (this_tcs, this_vals)
+ = if null expmods_this
+ then ([], [])
+ else getLocalsFromRnEnv rn_env
+
+ -- Get names for exported imported modules
+ (mod_tcs, mod_vals, empty_mods)
+ = case mapAndUnzip3 get_mod_names expmods_imps of
+ (tcs, vals, emptys) -> (concat tcs, concat vals, catMaybes emptys)
+
+ (unqual_tcs, unqual_vals) = partition (isRnTyConOrClass.snd) (bagToList unqual_imps)
+
+ get_mod_names mod
+ = --pprTrace "get_mod_names" (ppAboves [ppPStr mod, interpp'SP PprDebug (map fst tcs), interpp'SP PprDebug (map fst vals)]) $
+ (tcs, vals, empty_mod)
+ where
+ tcs = [(getName rn, nameImportFlag (getName rn))
+ | (mod',rn) <- unqual_tcs, mod == mod']
+ vals = [(getName rn, nameImportFlag (getName rn))
+ | (mod',rn) <- unqual_vals, mod == mod', fun_looking rn]
+ empty_mod = if null tcs && null vals
+ then Just mod
+ else Nothing
+
+ -- fun_looking: must avoid class ops and data constructors
+ -- and record fieldnames
+ fun_looking (RnName _) = True
+ fun_looking (WiredInId i) = not (isDataCon i)
+ fun_looking _ = False