2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
4 \section[RnNames]{Extracting imported and top-level names in scope}
7 #include "HsVersions.h"
14 import PreludeGlaST ( MutableVar(..) )
23 import RnIfaces ( IfaceCache(..), cachedIface, cachedDecl )
24 import RnUtils ( RnEnv(..), emptyRnEnv, extendGlobalRnEnv,
25 lubExportFlag, qualNameErr, dupNamesErr )
26 import ParseUtils ( ParsedIface(..), RdrIfaceDecl(..), RdrIfaceInst )
29 import Bag ( emptyBag, unitBag, consBag, unionBags, unionManyBags,
30 mapBag, listToBag, bagToList )
31 import CmdLineOpts ( opt_NoImplicitPrelude )
32 import ErrUtils ( Error(..), Warning(..), addShortErrLocLine )
33 import FiniteMap ( emptyFM, addListToFM, lookupFM, fmToList, eltsFM, delListFromFM )
35 import Maybes ( maybeToBool, catMaybes, MaybeErr(..) )
36 import Name ( RdrName(..), Name, isQual, mkTopLevName,
37 mkImportedName, nameExportFlag, nameImportFlag,
38 getLocalName, getSrcLoc, pprNonSym, moduleNamePair,
39 isLexCon, isRdrLexCon, ExportFlag(..)
41 import PrelInfo ( BuiltinNames(..), BuiltinKeys(..) )
42 import PrelMods ( fromPrelude, pRELUDE )
44 import SrcLoc ( SrcLoc, mkIfaceSrcLoc )
45 import TyCon ( tyConDataCons )
46 import UniqFM ( emptyUFM, addListToUFM_C, lookupUFM )
47 import UniqSupply ( splitUniqSupply )
48 import Util ( isIn, cmpPString, sortLt, removeDups, equivClasses, panic, assertPanic )
53 type GlobalNameInfo = (BuiltinNames,
55 Name -> ExportFlag, -- export flag
56 Name -> [RdrName]) -- occurence names
58 type RnM_Info s r = RnMonad GlobalNameInfo s r
66 [Module], -- directly imported modules
67 Bag (Module,RnName), -- unqualified imports from module
68 Bag RenamedFixityDecl, -- imported fixity decls
72 getGlobalNames iface_cache info us
73 (HsModule mod _ _ imports _ ty_decls _ cls_decls _ _ _ binds _ _)
74 = case initRn True mod emptyRnEnv us1
76 getSourceNames ty_decls cls_decls binds)
77 of { ((src_vals, src_tcs), src_errs, src_warns) ->
79 doImportDecls iface_cache info us2 imports >>=
80 \ (imp_vals, imp_tcs, imp_mods, unqual_imps, imp_fixes, imp_errs, imp_warns) ->
83 unqual_vals = mapBag (\rn -> (Unqual (getLocalName rn), rn)) src_vals
84 unqual_tcs = mapBag (\rn -> (Unqual (getLocalName rn), rn)) src_tcs
86 all_vals = bagToList (unqual_vals `unionBags` imp_vals)
87 all_tcs = bagToList (unqual_tcs `unionBags` imp_tcs)
89 (all_env, dups) = extendGlobalRnEnv emptyRnEnv all_vals all_tcs
91 dup_errs = map dup_err (equivClasses cmp_rdr (bagToList dups))
92 cmp_rdr (rdr1,_,_) (rdr2,_,_) = cmp rdr1 rdr2
93 dup_err ((rdr,rn,rn'):rest) = globalDupNamesErr rdr (rn:rn': [rn|(_,_,rn)<-rest])
95 all_errs = src_errs `unionBags` imp_errs `unionBags` listToBag dup_errs
96 all_warns = src_warns `unionBags` imp_warns
98 return (all_env, imp_mods, unqual_imps, imp_fixes, all_errs, all_warns)
101 (us1, us2) = splitUniqSupply us
104 *********************************************************
106 \subsection{Top-level source names}
108 *********************************************************
113 -> [RdrNameClassDecl]
115 -> RnM_Info s (Bag RnName, -- values
116 Bag RnName) -- tycons/classes
118 getSourceNames ty_decls cls_decls binds
119 = mapAndUnzipRn getTyDeclNames ty_decls `thenRn` \ (tycon_s, constrs_s) ->
120 mapAndUnzipRn getClassNames cls_decls `thenRn` \ (cls_s, cls_ops_s) ->
121 getTopBindsNames binds `thenRn` \ bind_names ->
122 returnRn (unionManyBags constrs_s `unionBags`
123 unionManyBags cls_ops_s `unionBags` bind_names,
124 listToBag tycon_s `unionBags` listToBag cls_s)
127 getTyDeclNames :: RdrNameTyDecl
128 -> RnM_Info s (RnName, Bag RnName) -- tycon and constrs
130 getTyDeclNames (TyData _ tycon _ condecls _ _ src_loc)
131 = newGlobalName src_loc Nothing tycon `thenRn` \ tycon_name ->
132 mapRn (getConDeclName (Just (nameExportFlag tycon_name)))
133 condecls `thenRn` \ con_names ->
134 returnRn (RnData tycon_name con_names,
135 listToBag (map (\ n -> RnConstr n tycon_name) con_names))
137 getTyDeclNames (TyNew _ tycon _ condecls _ _ src_loc)
138 = newGlobalName src_loc Nothing tycon `thenRn` \ tycon_name ->
139 mapRn (getConDeclName (Just (nameExportFlag tycon_name)))
140 condecls `thenRn` \ con_names ->
141 returnRn (RnData tycon_name con_names,
142 listToBag (map (\ n -> RnConstr n tycon_name) con_names))
144 getTyDeclNames (TySynonym tycon _ _ src_loc)
145 = newGlobalName src_loc Nothing tycon `thenRn` \ tycon_name ->
146 returnRn (RnSyn tycon_name, emptyBag)
148 getConDeclName exp (ConDecl con _ src_loc)
149 = newGlobalName src_loc exp con
150 getConDeclName exp (ConOpDecl _ op _ src_loc)
151 = newGlobalName src_loc exp op
152 getConDeclName exp (NewConDecl con _ src_loc)
153 = newGlobalName src_loc exp con
154 getConDeclName exp (RecConDecl con fields src_loc)
155 = panic "getConDeclName:RecConDecl"
156 newGlobalName src_loc exp con
159 getClassNames :: RdrNameClassDecl
160 -> RnM_Info s (RnName, Bag RnName) -- class and class ops
162 getClassNames (ClassDecl _ cname _ sigs _ _ src_loc)
163 = newGlobalName src_loc Nothing cname `thenRn` \ class_name ->
164 getClassOpNames (Just (nameExportFlag class_name))
165 sigs `thenRn` \ op_names ->
166 returnRn (RnClass class_name op_names,
167 listToBag (map (\ n -> RnClassOp n class_name) op_names))
169 getClassOpNames exp []
171 getClassOpNames exp (ClassOpSig op _ _ src_loc : sigs)
172 = newGlobalName src_loc exp op `thenRn` \ op_name ->
173 getClassOpNames exp sigs `thenRn` \ op_names ->
174 returnRn (op_name : op_names)
175 getClassOpNames exp (_ : sigs)
176 = getClassOpNames exp sigs
179 *********************************************************
181 \subsection{Bindings}
183 *********************************************************
186 getTopBindsNames :: RdrNameHsBinds
187 -> RnM_Info s (Bag RnName)
189 getTopBindsNames binds = doBinds binds
191 doBinds EmptyBinds = returnRn emptyBag
192 doBinds (SingleBind bind) = doBind bind
193 doBinds (BindWith bind sigs) = doBind bind
194 doBinds (ThenBinds binds1 binds2)
195 = andRn unionBags (doBinds binds1) (doBinds binds2)
197 doBind EmptyBind = returnRn emptyBag
198 doBind (NonRecBind mbind) = doMBinds mbind
199 doBind (RecBind mbind) = doMBinds mbind
201 doMBinds EmptyMonoBinds = returnRn emptyBag
202 doMBinds (PatMonoBind pat grhss_and_binds locn) = doPat locn pat
203 doMBinds (FunMonoBind p_name _ _ locn) = doName locn p_name
204 doMBinds (AndMonoBinds mbinds1 mbinds2)
205 = andRn unionBags (doMBinds mbinds1) (doMBinds mbinds2)
208 = mapRn (doPat locn) pats `thenRn` \ pats_s ->
209 returnRn (unionManyBags pats_s)
211 doPat locn WildPatIn = returnRn emptyBag
212 doPat locn (LitPatIn _) = returnRn emptyBag
213 doPat locn (LazyPatIn pat) = doPat locn pat
214 doPat locn (VarPatIn var) = doName locn var
215 doPat locn (NegPatIn pat) = doPat locn pat
216 doPat locn (ParPatIn pat) = doPat locn pat
217 doPat locn (ListPatIn pats) = doPats locn pats
218 doPat locn (TuplePatIn pats) = doPats locn pats
219 doPat locn (ConPatIn name pats) = doPats locn pats
220 doPat locn (ConOpPatIn p1 op p2)
221 = andRn unionBags (doPat locn p1) (doPat locn p2)
222 doPat locn (AsPatIn as_name pat)
223 = andRn unionBags (doName locn as_name) (doPat locn pat)
224 doPat locn (RecPatIn name fields)
225 = mapRn (doField locn) fields `thenRn` \ fields_s ->
226 returnRn (unionManyBags fields_s)
228 doField locn (_, pat, _) = doPat locn pat
231 = newGlobalName locn Nothing rdr `thenRn` \ name ->
232 returnRn (unitBag (RnName name))
235 *********************************************************
237 \subsection{Creating a new global name}
239 *********************************************************
242 newGlobalName :: SrcLoc -> Maybe ExportFlag
243 -> RdrName -> RnM_Info s Name
245 newGlobalName locn maybe_exp rdr
246 = getExtraRn `thenRn` \ (_,b_keys,exp_fn,occ_fn) ->
247 getModuleRn `thenRn` \ mod ->
248 rnGetUnique `thenRn` \ u ->
253 Unqual n -> case (lookupFM b_keys n) of
255 Just (key,_) -> (key, n)
257 orig = if fromPrelude mod
259 else (Qual mod unqual)
261 exp = case maybe_exp of
265 n = mkTopLevName uniq orig locn exp (occ_fn n)
267 addErrIfRn (isQual rdr) (qualNameErr "name in definition" (rdr, locn)) `thenRn_`
271 *********************************************************
273 \subsection{Imported names}
275 *********************************************************
278 type ImportNameInfo = (GlobalNameInfo,
279 FiniteMap (Module,FAST_STRING) RnName, -- values imported so far
280 FiniteMap (Module,FAST_STRING) RnName, -- tycons/classes imported so far
281 Name -> ExportFlag) -- import flag
283 type RnM_IInfo s r = RnMonad ImportNameInfo s r
287 -> GlobalNameInfo -- builtin and knot name info
289 -> [RdrNameImportDecl] -- import declarations
290 -> IO (Bag (RdrName,RnName), -- imported values in scope
291 Bag (RdrName,RnName), -- imported tycons/classes in scope
292 [Module], -- directly imported modules
293 Bag (Module,RnName), -- unqualified import from module
294 Bag RenamedFixityDecl, -- fixity info for imported names
298 doImportDecls iface_cache g_info us src_imps
299 = fixIO ( \ ~(_, _, _, _, _, _, rec_imp_flags) ->
301 rec_imp_fm = addListToUFM_C lubExportFlag emptyUFM (bagToList rec_imp_flags)
303 rec_imp_fn :: Name -> ExportFlag
304 rec_imp_fn n = case lookupUFM rec_imp_fm n of
305 Nothing -> panic "RnNames:rec_imp_fn"
308 i_info = (g_info, emptyFM, emptyFM, rec_imp_fn)
310 doImports iface_cache i_info us (qprel_imp ++ prel_imp ++ src_imps)
311 ) >>= \ (vals, tcs, unquals, fixes, errs, warns, _) ->
313 imp_mods = [ mod | ImportDecl mod _ _ _ _ <- src_imps ]
314 imp_warns = listToBag (map dupImportWarn imp_dups)
315 prel_warns = listToBag (map qualPreludeImportWarn qual_prels)
317 (_, imp_dups) = removeDups cmp_mod src_imps
318 cmp_mod (ImportDecl m1 _ _ _ _) (ImportDecl m2 _ _ _ _) = cmpPString m1 m2
319 qual_prels = [imp | imp@(ImportDecl mod qual _ _ _) <- src_imps,
320 fromPrelude mod && qual]
322 return (vals, tcs, imp_mods, unquals, fixes, errs,
323 prel_warns `unionBags` imp_warns `unionBags` warns)
325 explicit_prelude_import
326 = null [() | (ImportDecl mod qual _ _ _) <- src_imps,
327 fromPrelude mod && not qual]
329 qprel_imp = if opt_NoImplicitPrelude
330 then [{-the flag really means it: *NO* implicit "import Prelude" -}]
331 else [ImportDecl pRELUDE True Nothing Nothing mkIfaceSrcLoc]
333 prel_imp = if not explicit_prelude_import || opt_NoImplicitPrelude
335 [ {-prelude imported explicitly => no import Prelude-} ]
337 [ImportDecl pRELUDE False Nothing Nothing mkIfaceSrcLoc]
339 doImports iface_cache i_info us []
340 = return (emptyBag, emptyBag, emptyBag, emptyBag, emptyBag, emptyBag, emptyBag)
341 doImports iface_cache i_info@(g_info,done_vals,done_tcs,imp_fn) us (imp:imps)
342 = doImport iface_cache i_info us1 imp
343 >>= \ (vals1, tcs1, unquals1, fixes1, errs1, warns1, imps1) ->
345 new_vals = [ (moduleNamePair rn, rn) | (_,rn) <- bagToList vals1,
346 not (maybeToBool (lookupFM done_vals (moduleNamePair rn))) ]
347 -- moduleNamePair computed twice
348 ext_vals = addListToFM done_vals new_vals
350 new_tcs = [ (moduleNamePair rn, rn) | (_,rn) <- bagToList tcs1,
351 not (maybeToBool (lookupFM done_tcs (moduleNamePair rn))) ]
352 ext_tcs = addListToFM done_tcs new_tcs
354 doImports iface_cache (g_info,ext_vals,ext_tcs,imp_fn) us2 imps
355 >>= \ (vals2, tcs2, unquals2, fixes2, errs2, warns2, imps2) ->
356 return (vals1 `unionBags` vals2,
357 tcs1 `unionBags` tcs2,
358 unquals1 `unionBags` unquals2,
359 fixes1 `unionBags` fixes2,
360 errs1 `unionBags` errs2,
361 warns1 `unionBags` warns2,
362 imps1 `unionBags` imps2)
364 (us1, us2) = splitUniqSupply us
367 doImport :: IfaceCache
371 -> IO (Bag (RdrName,RnName), -- values
372 Bag (RdrName,RnName), -- tycons/classes
373 Bag (Module,RnName), -- unqual imports
374 Bag RenamedFixityDecl,
377 Bag (RnName,ExportFlag)) -- import flags
379 doImport iface_cache info us (ImportDecl mod qual maybe_as maybe_spec src_loc)
380 = cachedIface iface_cache mod >>= \ maybe_iface ->
383 return (emptyBag, emptyBag, emptyBag, emptyBag,
384 unitBag err, emptyBag, emptyBag)
387 (b_vals, b_tcs, maybe_spec') = getBuiltins info mod maybe_spec
388 (ies, chk_ies, get_errs) = getOrigIEs iface maybe_spec'
390 doOrigIEs iface_cache info mod src_loc us ies
391 >>= \ (ie_vals, ie_tcs, imp_flags, errs, warns) ->
392 accumulate (map (checkOrigIE iface_cache) chk_ies)
393 >>= \ chk_errs_warns ->
394 accumulate (map (getFixityDecl iface_cache) (bagToList ie_vals))
395 >>= \ fix_maybes_errs ->
397 (chk_errs, chk_warns) = unzip chk_errs_warns
398 (fix_maybes, fix_errs) = unzip fix_maybes_errs
400 final_vals = mapBag fst_occ b_vals `unionBags` mapBag pair_occ ie_vals
401 final_tcs = mapBag fst_occ b_tcs `unionBags` mapBag pair_occ ie_tcs
403 unquals = if qual then emptyBag
404 else mapBag pair_as (ie_vals `unionBags` ie_tcs)
406 final_fixes = listToBag (catMaybes fix_maybes)
408 final_errs = mapBag (\ err -> err mod src_loc) (unionManyBags (get_errs:chk_errs))
409 `unionBags` errs `unionBags` unionManyBags fix_errs
410 final_warns = mapBag (\ warn -> warn mod src_loc) (unionManyBags chk_warns)
413 return (final_vals, final_tcs, unquals, final_fixes,
414 final_errs, final_warns, imp_flags)
416 as_mod = case maybe_as of {Nothing -> mod; Just as_this -> as_this}
417 mk_occ str = if qual then Qual as_mod str else Unqual str
419 fst_occ (str, rn) = (mk_occ str, rn)
420 pair_occ rn = (mk_occ (getLocalName rn), rn)
421 pair_as rn = (as_mod, rn)
424 getBuiltins info mod maybe_spec
425 | not (fromPrelude mod)
426 = (emptyBag, emptyBag, maybe_spec)
428 getBuiltins (((b_val_names,b_tc_names),_,_,_),_,_,_) mod maybe_spec
430 Nothing -> (all_vals, all_tcs, Nothing)
432 Just (True, ies) -> -- hiding does not work for builtin names
433 (all_vals, all_tcs, maybe_spec)
435 Just (False, ies) -> let
436 (vals,tcs,ies_left) = do_builtin ies
438 (vals, tcs, Just (False, ies_left))
440 all_vals = do_all_builtin (fmToList b_val_names)
441 all_tcs = do_all_builtin (fmToList b_tc_names)
443 do_all_builtin [] = emptyBag
444 do_all_builtin ((str,rn):rest)
445 = (str, rn) `consBag` do_all_builtin rest
447 do_builtin [] = (emptyBag,emptyBag,[])
449 = let str = unqual_str (ie_name ie)
451 case (lookupFM b_tc_names str) of -- NB: we favour the tycon/class FM...
452 Just rn -> case (ie,rn) of
453 (IEThingAbs _, WiredInTyCon tc)
454 -> (vals, (str, rn) `consBag` tcs, ies_left)
455 (IEThingAll _, WiredInTyCon tc)
456 -> (listToBag (map (\ id -> (getLocalName id, WiredInId id))
459 (str,rn) `consBag` tcs, ies_left)
460 _ -> panic "importing builtin names (1)"
463 case (lookupFM b_val_names str) of
464 Nothing -> (vals, tcs, ie:ies_left)
465 Just rn -> case (ie,rn) of
466 (IEVar _, WiredInId _)
467 -> ((str, rn) `consBag` vals, tcs, ies_left)
468 _ -> panic "importing builtin names (2)"
470 (vals, tcs, ies_left) = do_builtin ies
473 getOrigIEs (ParsedIface _ _ _ _ exps _ _ _ _ _ _) Nothing -- import all
474 = (map mkAllIE (eltsFM exps), [], emptyBag)
476 getOrigIEs (ParsedIface _ _ _ _ exps _ _ _ _ _ _) (Just (True, ies)) -- import hiding
477 = (map mkAllIE (eltsFM exps_left), found_ies, errs)
479 (found_ies, errs) = lookupIEs exps ies
480 exps_left = delListFromFM exps (map (getLocalName.ie_name.fst) found_ies)
482 getOrigNames (ParsedIface _ _ _ _ exps _ _ _ _ _ _) (Just (False, ies))
483 = (map fst found_ies, found_ies, errs)
485 (found_ies, errs) = lookupIEs exps ies
488 mkAllIE (orig,ExportAbs)
489 = ASSERT(isLexCon (getLocalName orig))
491 mkAllIE (orig, ExportAll)
492 | isLexCon (getLocalName orig)
500 lookupIEs exps (ie:ies)
501 = case lookupFM exps (unqual_str (ie_name ie)) of
503 (orig_ies, unknownImpSpecErr ie `consBag` errs)
505 (orig_ie orig flag ie ++ orig_ies,
506 adderr_if (seen_ie orig orig_ies) (duplicateImpSpecErr ie) errs)
508 (orig_ies, errs) = lookupIEs exps ies
510 orig_ie orig flag (IEVar n) = [(IEVar orig, flag)]
511 orig_ie orig flag (IEThingAbs n) = [(IEThingAbs orig, flag)]
512 orig_ie orig flag (IEThingAll n) = [(IEThingAll orig, flag)]
513 orig_ie orig flag (IEThingWith n ns) = [(IEThingWith orig ns, flag)]
515 seen_ie orig seen_ies = any (\ (ie,_) -> orig == ie_name ie) seen_ies
518 doOrigIEs iface_cache info mod src_loc us []
519 = return (emptyBag,emptyBag,emptyBag,emptyBag,emptyBag)
521 doOrigIEs iface_cache info mod src_loc us (ie:ies)
522 = doOrigIE iface_cache info mod src_loc us1 ie
523 >>= \ (vals1, tcs1, errs1, warns1, imps1) ->
524 doOrigIEs iface_cache info mod src_loc us2 ies
525 >>= \ (vals2, tcs2, errs2, warns2, imps2) ->
526 return (vals1 `unionBags` vals2,
527 tcs1 `unionBags` tcs2,
528 errs1 `unionBags` errs2,
529 warns1 `unionBags` warns2,
530 imps1 `unionBags` imps2)
532 (us1, us2) = splitUniqSupply us
534 doOrigIE iface_cache info mod src_loc us ie
535 = with_decl iface_cache (ie_name ie)
536 (\ err -> (emptyBag, emptyBag, emptyBag, unitBag err, emptyBag))
537 (\ decl -> case initRn True mod emptyRnEnv us
539 pushSrcLocRn src_loc $
540 getIfaceDeclNames ie decl)
542 ((vals, tcs, imps), errs, warns) -> (vals, tcs, imps, errs, warns))
544 checkOrigIE iface_cache (IEThingAll n, ExportAbs)
545 = with_decl iface_cache n
546 (\ err -> (unitBag (\ mod locn -> err), emptyBag))
547 (\ decl -> case decl of
548 TypeSig _ _ _ -> (emptyBag, unitBag (allWhenSynImpSpecWarn n))
549 other -> (unitBag (allWhenAbsImpSpecErr n), emptyBag))
551 checkOrigIE iface_cache (IEThingWith n ns, ExportAbs)
552 = return (unitBag (withWhenAbsImpSpecErr n), emptyBag)
554 checkOrigIE iface_cache (IEThingWith n ns, ExportAll)
555 = with_decl iface_cache n
556 (\ err -> (unitBag (\ mod locn -> err), emptyBag))
557 (\ decl -> case decl of
558 NewTypeSig _ con _ _ -> (check_with "constructrs" [con] ns, emptyBag)
559 DataSig _ cons _ _ -> (check_with "constructrs" cons ns, emptyBag)
560 ClassSig _ ops _ _ -> (check_with "class ops" ops ns, emptyBag))
562 check_with str has rdrs
563 | sortLt (<) (map getLocalName has) == sortLt (<) (map unqual_str rdrs)
566 = unitBag (withImpSpecErr str n has rdrs)
568 checkOrigIE iface_cache other
569 = return (emptyBag, emptyBag)
572 with_decl iface_cache n do_err do_decl
573 = cachedDecl iface_cache (isRdrLexCon n) n >>= \ maybe_decl ->
575 Failed err -> return (do_err err)
576 Succeeded decl -> return (do_decl decl)
579 getFixityDecl iface_cache rn
581 (mod, str) = moduleNamePair rn
583 cachedIface iface_cache mod >>= \ maybe_iface ->
586 return (Nothing, unitBag err)
587 Succeeded (ParsedIface _ _ _ _ _ _ fixes _ _ _ _) ->
588 case lookupFM fixes str of
589 Nothing -> return (Nothing, emptyBag)
590 Just (InfixL _ i) -> return (Just (InfixL rn i), emptyBag)
591 Just (InfixR _ i) -> return (Just (InfixR rn i), emptyBag)
592 Just (InfixN _ i) -> return (Just (InfixN rn i), emptyBag)
594 ie_name (IEVar n) = n
595 ie_name (IEThingAbs n) = n
596 ie_name (IEThingAll n) = n
597 ie_name (IEThingWith n _) = n
599 unqual_str (Unqual str) = str
600 unqual_str q@(Qual _ _) = panic "unqual_str"
602 adderr_if True err errs = err `consBag` errs
603 adderr_if False err errs = errs
606 *********************************************************
608 \subsection{Actually creating the imported names}
610 *********************************************************
613 getIfaceDeclNames :: RdrNameIE -> RdrIfaceDecl
614 -> RnM_IInfo s (Bag RnName, -- values
615 Bag RnName, -- tycons/classes
616 Bag (RnName,ExportFlag)) -- import flags
618 getIfaceDeclNames ie (ValSig val src_loc _)
619 = newImportedName False src_loc Nothing Nothing val `thenRn` \ val_name ->
620 returnRn (unitBag (RnName val_name),
622 unitBag (RnName val_name, ExportAll))
624 getIfaceDeclNames ie (TypeSig tycon src_loc _)
625 = newImportedName True src_loc Nothing Nothing tycon `thenRn` \ tycon_name ->
627 unitBag (RnSyn tycon_name),
628 unitBag (RnSyn tycon_name, ExportAll))
630 getIfaceDeclNames ie (NewTypeSig tycon con src_loc _)
631 = newImportedName True src_loc Nothing Nothing tycon `thenRn` \ tycon_name ->
632 mapRn (newImportedName False src_loc (Just (nameExportFlag tycon_name))
633 (Just (nameImportFlag tycon_name)))
634 [con] `thenRn` \ con_names ->
635 returnRn (if imp_all (imp_flag ie) then
636 listToBag (map (\ n -> RnConstr n tycon_name) con_names)
639 unitBag (RnData tycon_name con_names),
640 unitBag (RnData tycon_name con_names, imp_flag ie))
642 getIfaceDeclNames ie (DataSig tycon cons src_loc _)
643 = newImportedName True src_loc Nothing Nothing tycon `thenRn` \ tycon_name ->
644 mapRn (newImportedName False src_loc (Just (nameExportFlag tycon_name))
645 (Just (nameImportFlag tycon_name)))
646 cons `thenRn` \ con_names ->
647 returnRn (if imp_all (imp_flag ie) then
648 listToBag (map (\ n -> RnConstr n tycon_name) con_names)
651 unitBag (RnData tycon_name con_names),
652 unitBag (RnData tycon_name con_names, imp_flag ie))
654 getIfaceDeclNames ie (ClassSig cls ops src_loc _)
655 = newImportedName True src_loc Nothing Nothing cls `thenRn` \ cls_name ->
656 mapRn (newImportedName False src_loc (Just (nameExportFlag cls_name))
657 (Just (nameImportFlag cls_name)))
658 ops `thenRn` \ op_names ->
659 returnRn (if imp_all (imp_flag ie) then
660 listToBag (map (\ n -> RnClassOp n cls_name) op_names)
663 unitBag (RnClass cls_name op_names),
664 unitBag (RnClass cls_name op_names, imp_flag ie))
667 imp_all ExportAll = True
670 imp_flag (IEThingAbs _) = ExportAbs
671 imp_flag (IEThingAll _) = ExportAll
672 imp_flag (IEThingWith _ _) = ExportAll
675 *********************************************************
677 \subsection{Creating a new imported name}
679 *********************************************************
682 newImportedName :: Bool -- True => tycon or class
684 -> Maybe ExportFlag -- maybe export flag
685 -> Maybe ExportFlag -- maybe import flag
686 -> RdrName -- orig name
689 newImportedName tycon_or_class locn maybe_exp maybe_imp rdr
690 = getExtraRn `thenRn` \ ((_,b_keys,exp_fn,occ_fn),done_vals,done_tcs,imp_fn) ->
691 case if tycon_or_class
692 then lookupFM done_tcs (moduleNamePair rdr)
693 else lookupFM done_vals (moduleNamePair rdr)
695 Just rn -> returnRn (getName rn)
697 rnGetUnique `thenRn` \ u ->
701 Unqual n -> case lookupFM b_keys n of
705 exp = case maybe_exp of
709 imp = case maybe_imp of
713 n = mkImportedName uniq rdr imp locn exp (occ_fn n)
719 globalDupNamesErr rdr rns sty
720 = ppHang (ppBesides [pprNonSym sty rdr, ppStr " multiply defined:"])
721 4 (ppAboves (map pp_def rns))
723 pp_def rn = addShortErrLocLine (getSrcLoc rn) (\ sty -> ppr sty rn) sty
725 dupImportWarn dup_imps sty
726 = ppStr "dupImportWarn"
728 qualPreludeImportWarn imp sty
729 = ppStr "qualPreludeImportWarn"
731 unknownImpSpecErr ie imp_mod locn sty
732 = ppStr "unknownImpSpecErr"
734 duplicateImpSpecErr ie imp_mod locn sty
735 = ppStr "duplicateImpSpecErr"
737 allWhenSynImpSpecWarn n imp_mod locn sty
738 = ppStr "allWhenSynImpSpecWarn"
740 allWhenAbsImpSpecErr n imp_mod locn sty
741 = ppStr "allWhenAbsImpSpecErr"
743 withWhenAbsImpSpecErr n imp_mod locn sty
744 = ppStr "withWhenAbsImpSpecErr"
746 withImpSpecErr str n has ns imp_mod locn sty
747 = ppStr "withImpSpecErr"