+
+%*********************************************************
+%* *
+\subsection{Export list}
+%* *
+%*********************************************************
+
+\begin{code}
+rnExports :: [Module]
+ -> Bag (Module,(RnName,ExportFlag))
+ -> Maybe [RdrNameIE]
+ -> RnM s (Name -> ExportFlag)
+
+rnExports mods unqual_imps Nothing
+ = returnRn (\n -> if isLocallyDefined n then ExportAll else NotExported)
+
+rnExports mods unqual_imps (Just exps)
+ = mapAndUnzipRn (rnIE mods) exps `thenRn` \ (mod_maybes, exp_bags) ->
+ let
+ exp_mods = catMaybes mod_maybes
+ exp_names = unionManyBags exp_bags
+
+ -- check for duplicate names
+ -- check for duplicate modules
+
+ -- check for duplicate local names
+ -- add in module contents checking for duplicate local names
+
+ -- build export flag lookup function
+ exp_fn n = if isLocallyDefined n then ExportAll else NotExported
+ in
+ returnRn exp_fn
+
+rnIE mods (IEVar name)
+ = lookupValue name `thenRn` \ rn ->
+ checkIEVar rn `thenRn` \ exps ->
+ returnRn (Nothing, exps)
+ where
+ checkIEVar (RnName n) = returnRn (unitBag (n,ExportAbs))
+ checkIEVar (RnUnbound _) = returnRn emptyBag
+ checkIEVar rn@(RnClassOp _ _) = getSrcLocRn `thenRn` \ src_loc ->
+ failButContinueRn emptyBag (classOpExportErr rn src_loc)
+ checkIEVar rn = panic "checkIEVar"
+
+rnIE mods (IEThingAbs name)
+ = lookupTyConOrClass name `thenRn` \ rn ->
+ checkIEAbs rn `thenRn` \ exps ->
+ returnRn (Nothing, exps)
+ where
+ checkIEAbs (RnSyn n) = returnRn (unitBag (n,ExportAbs))
+ checkIEAbs (RnData n _) = returnRn (unitBag (n,ExportAbs))
+ checkIEAbs (RnClass n _) = returnRn (unitBag (n,ExportAbs))
+ checkIEAbs (RnUnbound _) = returnRn emptyBag
+ checkIEAbs rn = panic "checkIEAbs"
+
+rnIE mods (IEThingAll name)
+ = lookupTyConOrClass name `thenRn` \ rn ->
+ checkIEAll rn `thenRn` \ exps ->
+ returnRn (Nothing, exps)
+ where
+ checkIEAll (RnData n cons) = returnRn (consBag (exp_all n) (listToBag (map exp_all cons)))
+ checkIEAll (RnClass n ops) = returnRn (consBag (exp_all n) (listToBag (map exp_all ops)))
+ checkIEAll (RnUnbound _) = returnRn emptyBag
+ checkIEAll rn@(RnSyn _) = getSrcLocRn `thenRn` \ src_loc ->
+ warnAndContinueRn emptyBag (synAllExportErr rn src_loc)
+ checkIEAll rn = panic "checkIEAll"
+
+ exp_all n = (n, ExportAll)
+
+rnIE mods (IEThingWith name names)
+ = lookupTyConOrClass name `thenRn` \ rn ->
+ mapRn lookupValue names `thenRn` \ rns ->
+ checkIEWith rn rns `thenRn` \ exps ->
+ returnRn (Nothing, exps)
+ where
+ checkIEWith rn@(RnData n cons) rns
+ | same_names cons rns = returnRn (consBag (exp_all n) (listToBag (map exp_all cons)))
+ | otherwise = rnWithErr "constructrs" rn cons rns
+ checkIEWith rn@(RnClass n ops) rns
+ | same_names ops rns = returnRn (consBag (exp_all n) (listToBag (map exp_all ops)))
+ | otherwise = rnWithErr "class ops" rn ops rns
+ checkIEWith (RnUnbound _) rns = returnRn emptyBag
+ checkIEWith rn@(RnSyn _) rns = getSrcLocRn `thenRn` \ src_loc ->
+ failButContinueRn emptyBag (synAllExportErr rn src_loc)
+ checkIEWith rn rns = panic "checkIEWith"
+
+ exp_all n = (n, ExportAll)
+
+ same_names has rns
+ = all (not.isRnUnbound) rns &&
+ sortLt (<) (map uniqueOf has) == sortLt (<) (map uniqueOf rns)
+
+ rnWithErr str rn has rns
+ = getSrcLocRn `thenRn` \ src_loc ->
+ failButContinueRn emptyBag (withExportErr str rn has rns src_loc)
+
+rnIE mods (IEModuleContents mod)
+ | isIn "IEModule" mod mods = returnRn (Just mod, emptyBag)
+ | otherwise = getSrcLocRn `thenRn` \ src_loc ->
+ failButContinueRn (Nothing,emptyBag) (badModExportErr mod src_loc)
+\end{code}
+