[project @ 2000-04-13 11:56:35 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
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 isUserExportedName (Name { n_prov = LocalDef _ Exported }) = True
427 isUserExportedName other                                   = False
428
429 isUserImportedExplicitlyName (Name { n_prov = NonLocalDef (UserImport _ _ explicit) _ }) = explicit
430 isUserImportedExplicitlyName other                                                       = False
431
432 isUserImportedName (Name { n_prov = NonLocalDef (UserImport _ _ _) _ }) = True
433 isUserImportedName other                                                = False
434
435 maybeUserImportedFrom (Name { n_prov = NonLocalDef (UserImport m _ _) _ }) = Just m
436 maybeUserImportedFrom other                                                = Nothing
437
438 isDllName :: Name -> Bool
439         -- Does this name refer to something in a different DLL?
440 isDllName nm = not opt_Static &&
441                not (isLocallyDefinedName nm) && 
442                not (isLocalModule (nameModule nm))
443
444 nameSrcLoc name = provSrcLoc (n_prov name)
445
446 provSrcLoc (LocalDef loc _)                     = loc        
447 provSrcLoc (NonLocalDef (UserImport _ loc _) _) = loc
448 provSrcLoc other                                = noSrcLoc   
449   
450 isLocallyDefinedName (Name {n_sort = Local})        = True      -- Local (might have SystemProv)
451 isLocallyDefinedName (Name {n_prov = LocalDef _ _}) = True      -- Global, but defined here
452 isLocallyDefinedName other                          = False     -- Other
453
454 -- Things the compiler "knows about" are in some sense
455 -- "imported".  When we are compiling the module where
456 -- the entities are defined, we need to be able to pick
457 -- them out, often in combination with isLocallyDefined.
458 isWiredInName (Name {n_sort = WiredInTyCon _ _}) = True
459 isWiredInName (Name {n_sort = WiredInId    _ _}) = True
460 isWiredInName _                                  = False
461
462 maybeWiredInIdName :: Name -> Maybe Id
463 maybeWiredInIdName (Name {n_sort = WiredInId _ id}) = Just id
464 maybeWiredInIdName other                            = Nothing
465
466 maybeWiredInTyConName :: Name -> Maybe TyCon
467 maybeWiredInTyConName (Name {n_sort = WiredInTyCon _ tc}) = Just tc
468 maybeWiredInTyConName other                               = Nothing
469
470
471 isLocalName (Name {n_sort = Local}) = True
472 isLocalName _                       = False
473
474 isGlobalName (Name {n_sort = Local}) = False
475 isGlobalName other                   = True
476
477 -- Global names are by definition those that are visible
478 -- outside the module, *as seen by the linker*.  Externally visible
479 -- does not mean visible at the source level (that's isExported).
480 isExternallyVisibleName name = isGlobalName name
481
482 hasBetterProv :: Name -> Name -> Bool
483 hasBetterProv name1 name2
484   = case n_prov name1 of
485         LocalDef _ _    -> True
486         SystemProv      -> False
487         NonLocalDef _ _ -> case n_prov name2 of
488                                 LocalDef _ _ -> False
489                                 other        -> True
490
491 isSystemName (Name {n_prov = SystemProv}) = True
492 isSystemName other                        = False
493 \end{code}
494
495
496 %************************************************************************
497 %*                                                                      *
498 \subsection[Name-instances]{Instance declarations}
499 %*                                                                      *
500 %************************************************************************
501
502 \begin{code}
503 cmpName n1 n2 = n_uniq n1 `compare` n_uniq n2
504 \end{code}
505
506 \begin{code}
507 instance Eq Name where
508     a == b = case (a `compare` b) of { EQ -> True;  _ -> False }
509     a /= b = case (a `compare` b) of { EQ -> False; _ -> True }
510
511 instance Ord Name where
512     a <= b = case (a `compare` b) of { LT -> True;  EQ -> True;  GT -> False }
513     a <  b = case (a `compare` b) of { LT -> True;  EQ -> False; GT -> False }
514     a >= b = case (a `compare` b) of { LT -> False; EQ -> True;  GT -> True  }
515     a >  b = case (a `compare` b) of { LT -> False; EQ -> False; GT -> True  }
516     compare a b = cmpName a b
517
518 instance Uniquable Name where
519     getUnique = nameUnique
520
521 instance NamedThing Name where
522     getName n = n
523 \end{code}
524
525
526 %************************************************************************
527 %*                                                                      *
528 \subsection{Pretty printing}
529 %*                                                                      *
530 %************************************************************************
531
532 \begin{code}
533 instance Outputable Name where
534         -- When printing interfaces, all Locals have been given nice print-names
535     ppr name = pprName name
536
537 pprName (Name {n_sort = Local, n_uniq = uniq, n_occ = occ, n_prov = prov})
538         -- Locals
539   = getPprStyle $ \ sty ->
540     if codeStyle sty then
541         pprUnique uniq          -- When printing in code we required all names to 
542                                 -- be globally unique; for example, we use this identifier
543                                 -- for the closure name.  So we just print the unique alone.
544     else
545         pprOccName occ <> pp_local_extra sty uniq
546   where
547     sys_local = case prov of
548                   SystemProv -> True
549                   other      -> False
550
551     pp_local_extra sty uniq
552         | sys_local      = underscore <> pprUnique uniq         -- Must print uniques for sys_locals
553         | debugStyle sty = text "{-" <> pprUnique uniq <> text "-}"
554         | otherwise      = empty
555
556
557 pprName (Name {n_sort = sort, n_uniq = uniq, n_occ = occ, n_prov = prov})
558         -- Globals, and wired in things
559   = getPprStyle $ \ sty ->
560     if codeStyle sty then
561         ppr mod <> underscore <> ppr occ
562     else
563         pp_mod_dot sty <> ppr occ <> pp_global_debug sty uniq prov
564   where
565     mod = nameSortModule sort
566
567     pp_mod_dot sty
568       = case prov of
569            SystemProv                                -> pp_qual mod user_sty
570                 -- Hack alert!  Omit the qualifier on SystemProv things in user style
571                 -- I claim such SystemProv things will also be WiredIn things.
572                 -- We can't get the omit flag right
573                 -- on wired in tycons etc (sigh) so we just leave it out in user style, 
574                 -- and hope that leaving it out isn't too consfusing.
575                 -- (e.g. if the programmer hides Bool and  redefines it.  If so, use -dppr-debug.)
576
577            LocalDef _ _                              -> pp_qual mod (user_sty || iface_sty)
578
579            NonLocalDef (UserImport imp_mod _ _) omit 
580                 | user_sty                           -> pp_qual imp_mod omit
581                 | otherwise                          -> pp_qual mod     False
582            NonLocalDef ImplicitImport           omit -> pp_qual mod     (user_sty && omit)
583       where
584         user_sty  = userStyle sty
585         iface_sty = ifaceStyle sty
586     
587     pp_qual mod omit_qual
588         | omit_qual  = empty
589         | otherwise  = pprModule mod <> dot
590     
591     pp_global_debug sty uniq prov
592       | debugStyle sty = hcat [text "{-", pprUnique uniq, prov_p prov, text "-}"]
593       | otherwise      = empty
594
595     prov_p prov | opt_PprStyle_NoPrags = empty
596                 | otherwise            = comma <> pp_prov prov
597
598 pp_prov (LocalDef _ Exported)          = char 'x'
599 pp_prov (LocalDef _ NotExported)       = char 'l'
600 pp_prov (NonLocalDef ImplicitImport _) = char 'j'
601 pp_prov (NonLocalDef (UserImport _ _ True ) _) = char 'I'       -- Imported by name
602 pp_prov (NonLocalDef (UserImport _ _ False) _) = char 'i'       -- Imported by ..
603 pp_prov SystemProv                     = char 's'
604 \end{code}
605
606
607 %************************************************************************
608 %*                                                                      *
609 \subsection{Overloaded functions related to Names}
610 %*                                                                      *
611 %************************************************************************
612
613 \begin{code}
614 class NamedThing a where
615     getOccName :: a -> OccName
616     getName    :: a -> Name
617
618     getOccName n = nameOccName (getName n)      -- Default method
619 \end{code}
620
621 \begin{code}
622 getSrcLoc           :: NamedThing a => a -> SrcLoc
623 isLocallyDefined    :: NamedThing a => a -> Bool
624 getOccString        :: NamedThing a => a -> String
625
626 getSrcLoc           = nameSrcLoc           . getName
627 isLocallyDefined    = isLocallyDefinedName . getName
628 getOccString x      = occNameString (getOccName x)
629 \end{code}
630
631 \begin{code}
632 {-# SPECIALIZE isLocallyDefined :: Name -> Bool #-}
633 \end{code}