[project @ 2000-05-23 11:35:36 by simonpj]
[ghc-hetmet.git] / ghc / compiler / basicTypes / Name.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
3 %
4 \section[Name]{@Name@: to transmit name info from renamer to typechecker}
5
6 \begin{code}
7 module Name (
8         -- Re-export the OccName stuff
9         module OccName,
10
11         -- The Name type
12         Name,                                   -- Abstract
13         mkLocalName, mkImportedLocalName, mkSysLocalName, mkCCallName,
14         mkTopName, mkIPName,
15         mkDerivedName, mkGlobalName, mkKnownKeyGlobal,
16         mkWiredInIdName,   mkWiredInTyConName,
17         mkUnboundName, isUnboundName,
18
19         maybeWiredInIdName, maybeWiredInTyConName,
20         isWiredInName, hashName,
21
22         nameUnique, setNameUnique, setNameProvenance, getNameProvenance, setNameImportReason,
23         tidyTopName, 
24         nameOccName, nameModule, setNameOcc, nameRdrName, setNameModule,
25
26         isUserExportedName, isUserImportedName, isUserImportedExplicitlyName, 
27         maybeUserImportedFrom,
28         nameSrcLoc, isLocallyDefinedName, isDllName,
29
30         isSystemName, isLocalName, isGlobalName, isExternallyVisibleName,
31         
32
33         -- Provenance
34         Provenance(..), ImportReason(..), pprProvenance,
35         ExportFlag(..), PrintUnqualified,
36         pprNameProvenance, hasBetterProv,
37
38         -- Class NamedThing and overloaded friends
39         NamedThing(..),
40         getSrcLoc, isLocallyDefined, getOccString, toRdrName
41     ) where
42
43 #include "HsVersions.h"
44
45 import {-# SOURCE #-} Var   ( Id, setIdName )
46 import {-# SOURCE #-} TyCon ( TyCon, setTyConName )
47
48 import OccName          -- All of it
49 import Module           ( Module, moduleName, pprModule, mkVanillaModule, isLocalModule )
50 import RdrName          ( RdrName, mkRdrQual, mkRdrUnqual, rdrNameOcc, rdrNameModule )
51 import CmdLineOpts      ( opt_Static, opt_PprStyle_NoPrags, opt_OmitInterfacePragmas, opt_EnsureSplittableC )
52
53 import SrcLoc           ( noSrcLoc, mkBuiltinSrcLoc, SrcLoc )
54 import Unique           ( pprUnique, Unique, Uniquable(..), unboundKey, u2i )
55 import Outputable
56 import GlaExts
57 \end{code}
58
59
60 %************************************************************************
61 %*                                                                      *
62 \subsection[Name-datatype]{The @Name@ datatype, and name construction}
63 %*                                                                      *
64 %************************************************************************
65  
66 \begin{code}
67 data Name = Name {
68                 n_sort :: NameSort,     -- What sort of name it is
69                 n_uniq :: Unique,
70                 n_occ  :: OccName,      -- Its occurrence name
71                 n_prov :: Provenance    -- How it was made
72             }
73
74 data NameSort
75   = Local
76   | Global Module
77   | WiredInId Module Id
78   | WiredInTyCon Module TyCon
79 \end{code}
80
81 Things with a @Global@ name are given C static labels, so they finally
82 appear in the .o file's symbol table.  They appear in the symbol table
83 in the form M.n.  If originally-local things have this property they
84 must be made @Global@ first.
85
86 \begin{code}
87 mkLocalName :: Unique -> OccName -> SrcLoc -> Name
88 mkLocalName uniq occ loc = Name { n_uniq = uniq, n_sort = Local, n_occ = occ, 
89                                   n_prov = LocalDef loc NotExported }
90         -- NB: You might worry that after lots of huffing and
91         -- puffing we might end up with two local names with distinct
92         -- uniques, but the same OccName.  Indeed we can, but that's ok
93         --      * the insides of the compiler don't care: they use the Unique
94         --      * when printing for -ddump-xxx you can switch on -dppr-debug to get the
95         --        uniques if you get confused
96         --      * for interface files we tidyCore first, which puts the uniques
97         --        into the print name (see setNameVisibility below)
98
99 mkImportedLocalName :: Unique -> OccName -> SrcLoc -> Name
100         -- Just the same as mkLocalName, except the provenance is different
101         -- Reason: this flags the name as one that came in from an interface file.
102         -- This is useful when trying to decide which of two type variables
103         -- should 'win' when unifying them.
104         -- NB: this is only for non-top-level names, so we use ImplicitImport
105 mkImportedLocalName uniq occ loc = Name { n_uniq = uniq, n_sort = Local, n_occ = occ, 
106                                           n_prov = NonLocalDef ImplicitImport True }
107
108
109 mkGlobalName :: Unique -> Module -> OccName -> Provenance -> Name
110 mkGlobalName uniq mod occ prov = Name { n_uniq = uniq, n_sort = Global mod,
111                                         n_occ = occ, n_prov = prov }
112                                 
113
114 mkKnownKeyGlobal :: (RdrName, Unique) -> Name
115 mkKnownKeyGlobal (rdr_name, uniq)
116   = mkGlobalName uniq (mkVanillaModule (rdrNameModule rdr_name))
117                       (rdrNameOcc rdr_name)
118                       systemProvenance
119
120 mkSysLocalName :: Unique -> UserFS -> Name
121 mkSysLocalName uniq fs = Name { n_uniq = uniq, n_sort = Local, 
122                                 n_occ = mkSrcVarOcc fs, n_prov = systemProvenance }
123
124 mkCCallName :: Unique -> EncodedString -> Name
125         -- The encoded string completely describes the ccall
126 mkCCallName uniq str =  Name { n_uniq = uniq, n_sort = Local, 
127                                n_occ = mkCCallOcc str, 
128                                n_prov = NonLocalDef ImplicitImport True }
129
130 mkTopName :: Unique -> Module -> FAST_STRING -> Name
131         -- Make a top-level name; make it Global if top-level
132         -- things should be externally visible; Local otherwise
133         -- This chap is only used *after* the tidyCore phase
134         -- Notably, it is used during STG lambda lifting
135         --
136         -- We have to make sure that the name is globally unique
137         -- and we don't have tidyCore to help us. So we append
138         -- the unique.  Hack!  Hack!
139 mkTopName uniq mod fs
140   = Name { n_uniq = uniq, 
141            n_sort = mk_top_sort mod,
142            n_occ  = mkSrcVarOcc (_PK_ ((_UNPK_ fs) ++ show uniq)),
143            n_prov = LocalDef noSrcLoc NotExported }
144
145 mkIPName :: Unique -> OccName -> Name
146 mkIPName uniq occ
147   = Name { n_uniq = uniq,
148            n_sort = Local,
149            n_occ  = occ,
150            -- ZZ is this an appropriate provinence?
151            n_prov = SystemProv }
152
153 ------------------------- Wired in names -------------------------
154
155 mkWiredInIdName :: Unique -> Module -> OccName -> Id -> Name
156 mkWiredInIdName uniq mod occ id = Name { n_uniq = uniq, n_sort = WiredInId mod id,
157                                          n_occ = occ, n_prov = SystemProv }
158
159 -- mkWiredInTyConName takes a FAST_STRING instead of
160 -- an OccName, which is a bit yukky but that's what the 
161 -- clients find easiest.
162 mkWiredInTyConName :: Unique -> Module -> FAST_STRING -> TyCon -> Name
163 mkWiredInTyConName uniq mod fs tycon
164   = Name { n_uniq = uniq, n_sort = WiredInTyCon mod tycon,
165            n_occ = mkSrcOccFS tcName fs, n_prov = SystemProv }
166
167
168 ---------------------------------------------------------------------
169 mkDerivedName :: (OccName -> OccName)
170               -> Name           -- Base name
171               -> Unique         -- New unique
172               -> Name           -- Result is always a value name
173
174 mkDerivedName f name uniq = name {n_uniq = uniq, n_occ = f (n_occ name)}
175
176 -- mkUnboundName makes a place-holder Name; it shouldn't be looked at except possibly
177 -- during compiler debugging.
178 mkUnboundName :: RdrName -> Name
179 mkUnboundName rdr_name = mkLocalName unboundKey (rdrNameOcc rdr_name) noSrcLoc
180
181 isUnboundName :: Name -> Bool
182 isUnboundName name = getUnique name == unboundKey
183 \end{code}
184
185 \begin{code}
186 -- When we renumber/rename things, we need to be
187 -- able to change a Name's Unique to match the cached
188 -- one in the thing it's the name of.  If you know what I mean.
189 setNameUnique name uniq = name {n_uniq = uniq}
190
191 setNameOcc :: Name -> OccName -> Name
192         -- Give the thing a new OccName, *and*
193         -- record that it's no longer a sys-local
194         -- This is used by the tidy-up pass
195 setNameOcc name occ = name {n_occ = occ}
196
197 setNameModule :: Name -> Module -> Name
198 setNameModule name mod = name {n_sort = set (n_sort name)}
199                        where
200                          set (Global _)             = Global mod
201                          set (WiredInId _ id)       = WiredInId mod id
202                          set (WiredInTyCon _ tycon) = WiredInTyCon mod tycon
203 \end{code}
204
205
206 %************************************************************************
207 %*                                                                      *
208 \subsection{Setting provenance and visibility
209 %*                                                                      *
210 %************************************************************************
211
212 tidyTopName is applied to top-level names in the final program
213
214 For top-level things, it globalises Local names 
215                                 (if all top-level things should be visible)
216                          and localises non-exported Global names
217                                  (if only exported things should be visible)
218
219 In all cases except an exported global, it gives it a new occurrence name.
220
221 The "visibility" here concerns whether the .o file's symbol table
222 mentions the thing; if so, it needs a module name in its symbol.
223 The Global things are "visible" and the Local ones are not
224
225 Why should things be "visible"?  Certainly they must be if they
226 are exported.  But also:
227
228 (a) In certain (prelude only) modules we split up the .hc file into
229     lots of separate little files, which are separately compiled by the C
230     compiler.  That gives lots of little .o files.  The idea is that if
231     you happen to mention one of them you don't necessarily pull them all
232     in.  (Pulling in a piece you don't need can be v bad, because it may
233     mention other pieces you don't need either, and so on.)
234     
235     Sadly, splitting up .hc files means that local names (like s234) are
236     now globally visible, which can lead to clashes between two .hc
237     files. So unlocaliseWhatnot goes through making all the local things
238     into global things, essentially by giving them full names so when they
239     are printed they'll have their module name too.  Pretty revolting
240     really.
241
242 (b) When optimisation is on we want to make all the internal
243     top-level defns externally visible
244
245 \begin{code}
246 tidyTopName :: Module -> TidyOccEnv -> Name -> (TidyOccEnv, Name)
247 tidyTopName mod env name
248   = (env', name')
249   where
250     (env', occ') = tidyOccName env (n_occ name)
251
252     name'        = Name { n_uniq = n_uniq name, n_sort = mk_top_sort mod,
253                           n_occ = occ', n_prov = LocalDef noSrcLoc NotExported }
254
255 mk_top_sort mod | all_toplev_ids_visible = Global mod
256                 | otherwise              = Local
257
258 all_toplev_ids_visible = 
259         not opt_OmitInterfacePragmas ||  -- Pragmas can make them visible
260         opt_EnsureSplittableC            -- Splitting requires visiblilty
261 \end{code}
262
263
264 \begin{code}
265 setNameProvenance :: Name -> Provenance -> Name 
266         -- setNameProvenance used to only change the provenance of 
267         -- Implicit-provenance things, but that gives bad error messages 
268         -- for names defined twice in the same module, so I changed it to 
269         -- set the provenance of *any* global (SLPJ Jun 97)
270 setNameProvenance name prov = name {n_prov = prov}
271
272 getNameProvenance :: Name -> Provenance
273 getNameProvenance name = n_prov name
274
275 setNameImportReason :: Name -> ImportReason -> Name
276 setNameImportReason name reason
277   = name { n_prov = new_prov }
278   where
279         -- It's important that we don't do the pattern matching
280         -- in the top-level clause, else we get a black hole in 
281         -- the renamer.  Rather a yukky constraint.  There's only
282         -- one call, in RnNames
283     old_prov = n_prov name
284     new_prov = case old_prov of
285                   NonLocalDef _ omit -> NonLocalDef reason omit
286                   other              -> old_prov
287 \end{code}
288
289
290 %************************************************************************
291 %*                                                                      *
292 \subsection{Provenance and export info}
293 %*                                                                      *
294 %************************************************************************
295
296 \begin{code}
297 data Provenance
298   = LocalDef                    -- Defined locally
299         SrcLoc                  -- Defn site
300         ExportFlag              -- Whether it's exported
301
302   | NonLocalDef                 -- Defined non-locally
303         ImportReason
304         PrintUnqualified
305
306   | SystemProv                  -- Either (a) a system-generated local with 
307                                 --            a v short name OccName
308                                 -- or     (b) a known-key global which should have a proper
309                                 --            provenance attached by the renamer
310 \end{code}
311
312 Sys-provs are only used internally.  When the compiler generates (say)
313 a fresh desguar variable it always calls it "ds", and of course it gets
314 a fresh unique.  But when printing -ddump-xx dumps, we must print it with
315 its unique, because there'll be a lot of "ds" variables.
316
317 Names with SystemProv differ in the following ways:
318         a) locals have unique attached when printing dumps
319         b) unifier eliminates sys tyvars in favour of user provs where possible
320         c) renamer replaces SystemProv with a better one
321
322 Before anything gets printed in interface files or output code, it's
323 fed through a 'tidy' processor, which zaps the OccNames to have
324 unique names; and converts all sys-locals to user locals
325 If any desugarer sys-locals have survived that far, they get changed to
326 "ds1", "ds2", etc.
327
328 \begin{code}
329 data ImportReason
330   = UserImport Module SrcLoc Bool       -- Imported from module M on line L
331                                         -- Note the M may well not be the defining module
332                                         -- for this thing!
333         -- The Bool is true iff the thing was named *explicitly* in the import spec,
334         -- rather than being imported as part of a group; e.g.
335         --      import B
336         --      import C( T(..) )
337         -- Here, everything imported by B, and the constructors of T
338         -- are not named explicitly; only T is named explicitly.
339         -- This info is used when warning of unused names.
340
341   | ImplicitImport                      -- Imported implicitly for some other reason
342                         
343
344 type PrintUnqualified = Bool    -- True <=> the unqualified name of this thing is
345                                 -- in scope in this module, so print it 
346                                 -- unqualified in error messages
347
348 data ExportFlag = Exported  | NotExported
349 \end{code}
350
351 Something is "Exported" if it may be mentioned by another module without
352 warning.  The crucial thing about Exported things is that they must
353 never be dropped as dead code, even if they aren't used in this module.
354 Furthermore, being Exported means that we can't see all call sites of the thing.
355
356 Exported things include:
357
358         - explicitly exported Ids, including data constructors, 
359           class method selectors
360
361         - dfuns from instance decls
362
363 Being Exported is *not* the same as finally appearing in the .o file's 
364 symbol table.  For example, a local Id may be mentioned in an Exported
365 Id's unfolding in the interface file, in which case the local Id goes
366 out too.
367
368
369 \begin{code}
370 systemProvenance :: Provenance
371 systemProvenance = SystemProv
372
373 -- pprNameProvenance is used in error messages to say where a name came from
374 pprNameProvenance :: Name -> SDoc
375 pprNameProvenance name = pprProvenance (getNameProvenance name)
376
377 pprProvenance :: Provenance -> SDoc
378 pprProvenance SystemProv             = ptext SLIT("System")
379 pprProvenance (LocalDef loc _)       = ptext SLIT("defined at")    <+> ppr loc
380 pprProvenance (NonLocalDef ImplicitImport _)
381   = ptext SLIT("implicitly imported")
382 pprProvenance (NonLocalDef (UserImport mod loc _) _) 
383   =  ptext SLIT("imported from") <+> ppr mod <+> ptext SLIT("at") <+> ppr loc
384 \end{code}
385
386
387 %************************************************************************
388 %*                                                                      *
389 \subsection{Predicates and selectors}
390 %*                                                                      *
391 %************************************************************************
392
393 \begin{code}
394 nameUnique              :: Name -> Unique
395 nameOccName             :: Name -> OccName 
396 nameModule              :: Name -> Module
397 nameSrcLoc              :: Name -> SrcLoc
398 isLocallyDefinedName    :: Name -> Bool
399 isUserExportedName      :: Name -> Bool
400 isWiredInName           :: Name -> Bool
401 isLocalName             :: Name -> Bool
402 isGlobalName            :: Name -> Bool
403 isExternallyVisibleName :: Name -> Bool
404
405
406
407 hashName :: Name -> Int
408 hashName name = IBOX( u2i (nameUnique name) )
409
410 nameUnique name = n_uniq name
411 nameOccName name = n_occ name
412
413 nameModule name =
414   case n_sort name of
415     Local -> pprPanic "nameModule" (ppr name)
416     x     -> nameSortModule x
417
418 nameSortModule (Global       mod)   = mod
419 nameSortModule (WiredInId    mod _) = mod
420 nameSortModule (WiredInTyCon mod _) = mod
421
422 nameRdrName :: Name -> RdrName
423 nameRdrName (Name { n_sort = Local, n_occ = occ }) = mkRdrUnqual occ
424 nameRdrName (Name { n_sort = sort,  n_occ = occ }) = mkRdrQual (moduleName (nameSortModule sort)) occ
425
426 ifaceNameRdrName :: Name -> RdrName
427 -- Makes a qualified naem for imported things, 
428 -- and an unqualified one for local things
429 ifaceNameRdrName n | isLocallyDefined n = mkRdrUnqual (nameOccName n)
430                    | otherwise          = mkRdrQual   (moduleName (nameModule n)) (nameOccName n) 
431
432 isUserExportedName (Name { n_prov = LocalDef _ Exported }) = True
433 isUserExportedName other                                   = False
434
435 isUserImportedExplicitlyName (Name { n_prov = NonLocalDef (UserImport _ _ explicit) _ }) = explicit
436 isUserImportedExplicitlyName other                                                       = False
437
438 isUserImportedName (Name { n_prov = NonLocalDef (UserImport _ _ _) _ }) = True
439 isUserImportedName other                                                = False
440
441 maybeUserImportedFrom (Name { n_prov = NonLocalDef (UserImport m _ _) _ }) = Just m
442 maybeUserImportedFrom other                                                = Nothing
443
444 isDllName :: Name -> Bool
445         -- Does this name refer to something in a different DLL?
446 isDllName nm = not opt_Static &&
447                not (isLocallyDefinedName nm) && 
448                not (isLocalModule (nameModule nm))
449
450 nameSrcLoc name = provSrcLoc (n_prov name)
451
452 provSrcLoc (LocalDef loc _)                     = loc        
453 provSrcLoc (NonLocalDef (UserImport _ loc _) _) = loc
454 provSrcLoc other                                = noSrcLoc   
455   
456 isLocallyDefinedName (Name {n_sort = Local})        = True      -- Local (might have SystemProv)
457 isLocallyDefinedName (Name {n_prov = LocalDef _ _}) = True      -- Global, but defined here
458 isLocallyDefinedName other                          = False     -- Other
459
460 -- Things the compiler "knows about" are in some sense
461 -- "imported".  When we are compiling the module where
462 -- the entities are defined, we need to be able to pick
463 -- them out, often in combination with isLocallyDefined.
464 isWiredInName (Name {n_sort = WiredInTyCon _ _}) = True
465 isWiredInName (Name {n_sort = WiredInId    _ _}) = True
466 isWiredInName _                                  = False
467
468 maybeWiredInIdName :: Name -> Maybe Id
469 maybeWiredInIdName (Name {n_sort = WiredInId _ id}) = Just id
470 maybeWiredInIdName other                            = Nothing
471
472 maybeWiredInTyConName :: Name -> Maybe TyCon
473 maybeWiredInTyConName (Name {n_sort = WiredInTyCon _ tc}) = Just tc
474 maybeWiredInTyConName other                               = Nothing
475
476
477 isLocalName (Name {n_sort = Local}) = True
478 isLocalName _                       = False
479
480 isGlobalName (Name {n_sort = Local}) = False
481 isGlobalName other                   = True
482
483 -- Global names are by definition those that are visible
484 -- outside the module, *as seen by the linker*.  Externally visible
485 -- does not mean visible at the source level (that's isExported).
486 isExternallyVisibleName name = isGlobalName name
487
488 hasBetterProv :: Name -> Name -> Bool
489 hasBetterProv name1 name2
490   = case n_prov name1 of
491         LocalDef _ _    -> True
492         SystemProv      -> False
493         NonLocalDef _ _ -> case n_prov name2 of
494                                 LocalDef _ _ -> False
495                                 other        -> True
496
497 isSystemName (Name {n_prov = SystemProv}) = True
498 isSystemName other                        = False
499 \end{code}
500
501
502 %************************************************************************
503 %*                                                                      *
504 \subsection[Name-instances]{Instance declarations}
505 %*                                                                      *
506 %************************************************************************
507
508 \begin{code}
509 cmpName n1 n2 = n_uniq n1 `compare` n_uniq n2
510 \end{code}
511
512 \begin{code}
513 instance Eq Name where
514     a == b = case (a `compare` b) of { EQ -> True;  _ -> False }
515     a /= b = case (a `compare` b) of { EQ -> False; _ -> True }
516
517 instance Ord Name where
518     a <= b = case (a `compare` b) of { LT -> True;  EQ -> True;  GT -> False }
519     a <  b = case (a `compare` b) of { LT -> True;  EQ -> False; GT -> False }
520     a >= b = case (a `compare` b) of { LT -> False; EQ -> True;  GT -> True  }
521     a >  b = case (a `compare` b) of { LT -> False; EQ -> False; GT -> True  }
522     compare a b = cmpName a b
523
524 instance Uniquable Name where
525     getUnique = nameUnique
526
527 instance NamedThing Name where
528     getName n = n
529 \end{code}
530
531
532 %************************************************************************
533 %*                                                                      *
534 \subsection{Pretty printing}
535 %*                                                                      *
536 %************************************************************************
537
538 \begin{code}
539 instance Outputable Name where
540         -- When printing interfaces, all Locals have been given nice print-names
541     ppr name = pprName name
542
543 pprName (Name {n_sort = Local, n_uniq = uniq, n_occ = occ, n_prov = prov})
544         -- Locals
545   = getPprStyle $ \ sty ->
546     if codeStyle sty then
547         pprUnique uniq          -- When printing in code we required all names to 
548                                 -- be globally unique; for example, we use this identifier
549                                 -- for the closure name.  So we just print the unique alone.
550     else
551         pprOccName occ <> pp_local_extra sty uniq
552   where
553     sys_local = case prov of
554                   SystemProv -> True
555                   other      -> False
556
557     pp_local_extra sty uniq
558         | sys_local      = underscore <> pprUnique uniq         -- Must print uniques for sys_locals
559         | debugStyle sty = text "{-" <> pprUnique uniq <> text "-}"
560         | otherwise      = empty
561
562
563 pprName (Name {n_sort = sort, n_uniq = uniq, n_occ = occ, n_prov = prov})
564         -- Globals, and wired in things
565   = getPprStyle $ \ sty ->
566     if codeStyle sty then
567         ppr mod <> underscore <> ppr occ
568     else
569         pp_mod_dot sty <> ppr occ <> pp_global_debug sty uniq prov
570   where
571     mod = nameSortModule sort
572
573     pp_mod_dot sty
574       = case prov of
575            SystemProv                                -> pp_qual mod user_sty
576                 -- Hack alert!  Omit the qualifier on SystemProv things in user style
577                 -- I claim such SystemProv things will also be WiredIn things.
578                 -- We can't get the omit flag right
579                 -- on wired in tycons etc (sigh) so we just leave it out in user style, 
580                 -- and hope that leaving it out isn't too consfusing.
581                 -- (e.g. if the programmer hides Bool and  redefines it.  If so, use -dppr-debug.)
582
583            LocalDef _ _                              -> pp_qual mod (user_sty || iface_sty)
584
585            NonLocalDef (UserImport imp_mod _ _) omit 
586                 | user_sty                           -> pp_qual imp_mod omit
587                 | otherwise                          -> pp_qual mod     False
588            NonLocalDef ImplicitImport           omit -> pp_qual mod     (user_sty && omit)
589       where
590         user_sty  = userStyle sty
591         iface_sty = ifaceStyle sty
592     
593     pp_qual mod omit_qual
594         | omit_qual  = empty
595         | otherwise  = pprModule mod <> dot
596     
597     pp_global_debug sty uniq prov
598       | debugStyle sty = hcat [text "{-", pprUnique uniq, prov_p prov, text "-}"]
599       | otherwise      = empty
600
601     prov_p prov | opt_PprStyle_NoPrags = empty
602                 | otherwise            = comma <> pp_prov prov
603
604 pp_prov (LocalDef _ Exported)          = char 'x'
605 pp_prov (LocalDef _ NotExported)       = char 'l'
606 pp_prov (NonLocalDef ImplicitImport _) = char 'j'
607 pp_prov (NonLocalDef (UserImport _ _ True ) _) = char 'I'       -- Imported by name
608 pp_prov (NonLocalDef (UserImport _ _ False) _) = char 'i'       -- Imported by ..
609 pp_prov SystemProv                     = char 's'
610 \end{code}
611
612
613 %************************************************************************
614 %*                                                                      *
615 \subsection{Overloaded functions related to Names}
616 %*                                                                      *
617 %************************************************************************
618
619 \begin{code}
620 class NamedThing a where
621     getOccName :: a -> OccName
622     getName    :: a -> Name
623
624     getOccName n = nameOccName (getName n)      -- Default method
625 \end{code}
626
627 \begin{code}
628 getSrcLoc           :: NamedThing a => a -> SrcLoc
629 isLocallyDefined    :: NamedThing a => a -> Bool
630 getOccString        :: NamedThing a => a -> String
631 toRdrName           :: NamedThing a => a -> RdrName
632
633 getSrcLoc           = nameSrcLoc           . getName
634 isLocallyDefined    = isLocallyDefinedName . getName
635 getOccString x      = occNameString (getOccName x)
636 toRdrName           = ifaceNameRdrName     . getName
637 \end{code}
638
639 \begin{code}
640 {-# SPECIALIZE isLocallyDefined :: Name -> Bool #-}
641 \end{code}