+gresFromIE :: ImpDeclSpec -> (LIE Name, AvailInfo) -> [GlobalRdrElt]
+gresFromIE decl_spec (L loc ie, avail)
+ = gresFromAvail prov_fn avail
+ where
+ is_explicit = case ie of
+ IEThingAll name -> \n -> n==name
+ other -> \n -> True
+ prov_fn name = Imported [imp_spec]
+ where
+ imp_spec = ImpSpec { is_decl = decl_spec, is_item = item_spec }
+ item_spec = ImpSome { is_explicit = is_explicit name, is_iloc = loc }
+
+mkChildEnv :: [GlobalRdrElt] -> NameEnv [Name]
+mkChildEnv gres = foldr add emptyNameEnv gres
+ where
+ add (GRE { gre_name = n, gre_par = ParentIs p }) env = extendNameEnv_C (++) env p [n]
+ add other_gre env = env
+
+findChildren :: NameEnv [Name] -> Name -> [Name]
+findChildren env n = lookupNameEnv env n `orElse` []
+\end{code}
+
+---------------------------------------
+ AvailEnv and friends
+
+All this AvailEnv stuff is hardly used; only in a very small
+part of RnNames. Todo: remove?
+---------------------------------------
+
+\begin{code}
+type AvailEnv = NameEnv AvailInfo -- Maps a Name to the AvailInfo that contains it
+
+emptyAvailEnv :: AvailEnv
+emptyAvailEnv = emptyNameEnv
+
+unitAvailEnv :: AvailInfo -> AvailEnv
+unitAvailEnv a = unitNameEnv (availName a) a
+
+plusAvailEnv :: AvailEnv -> AvailEnv -> AvailEnv
+plusAvailEnv = plusNameEnv_C plusAvail
+
+availEnvElts :: AvailEnv -> [AvailInfo]
+availEnvElts = nameEnvElts
+
+addAvail :: AvailEnv -> AvailInfo -> AvailEnv
+addAvail avails avail = extendNameEnv_C plusAvail avails (availName avail) avail
+
+mkAvailEnv :: [AvailInfo] -> AvailEnv
+ -- 'avails' may have several items with the same availName
+ -- E.g import Ix( Ix(..), index )
+ -- will give Ix(Ix,index,range) and Ix(index)
+ -- We want to combine these; addAvail does that
+mkAvailEnv avails = foldl addAvail emptyAvailEnv avails
+
+-- After combining the avails, we need to ensure that the parent name is the
+-- first entry in the list of subnames, if it is included at all. (Subsequent
+-- functions rely on that.)
+normaliseAvail :: AvailInfo -> AvailInfo
+normaliseAvail avail@(Avail _) = avail
+normaliseAvail (AvailTC name subs) = AvailTC name subs'