[project @ 2000-10-13 15:08:10 by simonpj]
[ghc-hetmet.git] / ghc / compiler / basicTypes / Name.lhs
index d066626..aa72a0c 100644 (file)
@@ -12,22 +12,19 @@ module Name (
        Name,                                   -- Abstract
        mkLocalName, mkImportedLocalName, mkSysLocalName, mkCCallName,
        mkTopName, mkIPName,
-       mkDerivedName, mkGlobalName, mkKnownKeyGlobal,
-       mkWiredInIdName,   mkWiredInTyConName,
-       mkUnboundName, isUnboundName,
+       mkDerivedName, mkGlobalName, mkKnownKeyGlobal, mkWiredInName,
 
-       maybeWiredInIdName, maybeWiredInTyConName,
-       isWiredInName, hashName,
-
-       nameUnique, setNameUnique, setNameProvenance, getNameProvenance, setNameImportReason,
-       tidyTopName, 
-       nameOccName, nameModule, setNameOcc, nameRdrName, setNameModule, toRdrName,
+       nameUnique, setNameUnique, setNameProvenance, getNameProvenance, 
+       setNameImportReason, tidyTopName, 
+       nameOccName, nameModule, setNameOcc, nameRdrName, setNameModule, 
+       toRdrName, hashName,
 
        isUserExportedName, isUserImportedName, isUserImportedExplicitlyName, 
        maybeUserImportedFrom,
        nameSrcLoc, isLocallyDefinedName, isDllName,
 
        isSystemName, isLocalName, isGlobalName, isExternallyVisibleName,
+       isTyVarName,
        
        -- Environment
        NameEnv, mkNameEnv,
@@ -49,23 +46,22 @@ module Name (
 
 #include "HsVersions.h"
 
-import {-# SOURCE #-} Var   ( Id, setIdName )
-import {-# SOURCE #-} TyCon ( TyCon, setTyConName )
-
 import OccName         -- All of it
-import Module          ( Module, moduleName, pprModule, mkVanillaModule, isLocalModule )
-import RdrName         ( RdrName, mkRdrQual, mkRdrUnqual, rdrNameOcc, rdrNameModule )
-import CmdLineOpts     ( opt_Static, opt_PprStyle_NoPrags, opt_OmitInterfacePragmas, opt_EnsureSplittableC )
-
-import SrcLoc          ( noSrcLoc, mkBuiltinSrcLoc, SrcLoc )
-import Unique          ( pprUnique, Unique, Uniquable(..), hasKey, unboundKey, u2i )
+import Module          ( Module, moduleName, pprModule, mkVanillaModule, 
+                         isLocalModule )
+import RdrName         ( RdrName, mkRdrQual, mkRdrUnqual, rdrNameOcc, 
+                         rdrNameModule )
+import CmdLineOpts     ( opt_Static, opt_PprStyle_NoPrags, 
+                         opt_OmitInterfacePragmas, opt_EnsureSplittableC )
+
+import SrcLoc          ( noSrcLoc, SrcLoc )
+import Unique          ( Unique, Uniquable(..), u2i, pprUnique )
 import Maybes          ( expectJust )
+import FastTypes
 import UniqFM
 import Outputable
-import GlaExts
 \end{code}
 
-
 %************************************************************************
 %*                                                                     *
 \subsection[Name-datatype]{The @Name@ datatype, and name construction}
@@ -83,8 +79,6 @@ data Name = Name {
 data NameSort
   = Local
   | Global Module
-  | WiredInId Module Id
-  | WiredInTyCon Module TyCon
 \end{code}
 
 Things with a @Global@ name are given C static labels, so they finally
@@ -107,9 +101,9 @@ mkLocalName uniq occ loc = Name { n_uniq = uniq, n_sort = Local, n_occ = occ,
 
 mkImportedLocalName :: Unique -> OccName -> SrcLoc -> Name
        -- Just the same as mkLocalName, except the provenance is different
-       -- Reason: this flags the name as one that came in from an interface file.
-       -- This is useful when trying to decide which of two type variables
-       -- should 'win' when unifying them.
+       -- Reason: this flags the name as one that came in from an interface 
+       -- file. This is useful when trying to decide which of two type
+       -- variables should 'win' when unifying them.
        -- NB: this is only for non-top-level names, so we use ImplicitImport
 mkImportedLocalName uniq occ loc = Name { n_uniq = uniq, n_sort = Local, n_occ = occ, 
                                          n_prov = NonLocalDef ImplicitImport True }
@@ -120,15 +114,18 @@ mkGlobalName uniq mod occ prov = Name { n_uniq = uniq, n_sort = Global mod,
                                        n_occ = occ, n_prov = prov }
                                
 
-mkKnownKeyGlobal :: (RdrName, Unique) -> Name
-mkKnownKeyGlobal (rdr_name, uniq)
+mkKnownKeyGlobal :: RdrName -> Unique -> Name
+mkKnownKeyGlobal rdr_name uniq
   = mkGlobalName uniq (mkVanillaModule (rdrNameModule rdr_name))
                      (rdrNameOcc rdr_name)
                      systemProvenance
 
+mkWiredInName :: Module -> OccName -> Unique -> Name
+mkWiredInName mod occ uniq = mkGlobalName uniq mod occ systemProvenance
+
 mkSysLocalName :: Unique -> UserFS -> Name
 mkSysLocalName uniq fs = Name { n_uniq = uniq, n_sort = Local, 
-                               n_occ = mkSrcVarOcc fs, n_prov = systemProvenance }
+                               n_occ = mkVarOcc fs, n_prov = systemProvenance }
 
 mkCCallName :: Unique -> EncodedString -> Name
        -- The encoded string completely describes the ccall
@@ -148,7 +145,7 @@ mkTopName :: Unique -> Module -> FAST_STRING -> Name
 mkTopName uniq mod fs
   = Name { n_uniq = uniq, 
           n_sort = mk_top_sort mod,
-          n_occ  = mkSrcVarOcc (_PK_ ((_UNPK_ fs) ++ show uniq)),
+          n_occ  = mkVarOcc (_PK_ ((_UNPK_ fs) ++ show uniq)),
           n_prov = LocalDef noSrcLoc NotExported }
 
 mkIPName :: Unique -> OccName -> Name
@@ -159,21 +156,6 @@ mkIPName uniq occ
           -- ZZ is this an appropriate provinence?
           n_prov = SystemProv }
 
-------------------------- Wired in names -------------------------
-
-mkWiredInIdName :: Unique -> Module -> OccName -> Id -> Name
-mkWiredInIdName uniq mod occ id = Name { n_uniq = uniq, n_sort = WiredInId mod id,
-                                        n_occ = occ, n_prov = SystemProv }
-
--- mkWiredInTyConName takes a FAST_STRING instead of
--- an OccName, which is a bit yukky but that's what the 
--- clients find easiest.
-mkWiredInTyConName :: Unique -> Module -> FAST_STRING -> TyCon -> Name
-mkWiredInTyConName uniq mod fs tycon
-  = Name { n_uniq = uniq, n_sort = WiredInTyCon mod tycon,
-          n_occ = mkSrcOccFS tcName fs, n_prov = SystemProv }
-
-
 ---------------------------------------------------------------------
 mkDerivedName :: (OccName -> OccName)
              -> Name           -- Base name
@@ -181,14 +163,6 @@ mkDerivedName :: (OccName -> OccName)
              -> Name           -- Result is always a value name
 
 mkDerivedName f name uniq = name {n_uniq = uniq, n_occ = f (n_occ name)}
-
--- mkUnboundName makes a place-holder Name; it shouldn't be looked at except possibly
--- during compiler debugging.
-mkUnboundName :: RdrName -> Name
-mkUnboundName rdr_name = mkLocalName unboundKey (rdrNameOcc rdr_name) noSrcLoc
-
-isUnboundName :: Name -> Bool
-isUnboundName name = name `hasKey` unboundKey
 \end{code}
 
 \begin{code}
@@ -207,8 +181,6 @@ setNameModule :: Name -> Module -> Name
 setNameModule name mod = name {n_sort = set (n_sort name)}
                       where
                         set (Global _)             = Global mod
-                        set (WiredInId _ id)       = WiredInId mod id
-                        set (WiredInTyCon _ tycon) = WiredInTyCon mod tycon
 \end{code}
 
 
@@ -406,7 +378,6 @@ nameModule          :: Name -> Module
 nameSrcLoc             :: Name -> SrcLoc
 isLocallyDefinedName   :: Name -> Bool
 isUserExportedName     :: Name -> Bool
-isWiredInName          :: Name -> Bool
 isLocalName            :: Name -> Bool
 isGlobalName           :: Name -> Bool
 isExternallyVisibleName :: Name -> Bool
@@ -414,7 +385,7 @@ isExternallyVisibleName :: Name -> Bool
 
 
 hashName :: Name -> Int
-hashName name = IBOX( u2i (nameUnique name) )
+hashName name = iBox (u2i (nameUnique name))
 
 nameUnique name = n_uniq name
 nameOccName name = n_occ name
@@ -425,8 +396,6 @@ nameModule name =
     x     -> nameSortModule x
 
 nameSortModule (Global       mod)   = mod
-nameSortModule (WiredInId    mod _) = mod
-nameSortModule (WiredInTyCon mod _) = mod
 
 nameRdrName :: Name -> RdrName
 -- Makes a qualified name for top-level (Global) names, whether locally defined or not
@@ -469,29 +438,15 @@ isLocallyDefinedName (Name {n_sort = Local})        = True        -- Local (might have
 isLocallyDefinedName (Name {n_prov = LocalDef _ _}) = True     -- Global, but defined here
 isLocallyDefinedName other                         = False     -- Other
 
--- Things the compiler "knows about" are in some sense
--- "imported".  When we are compiling the module where
--- the entities are defined, we need to be able to pick
--- them out, often in combination with isLocallyDefined.
-isWiredInName (Name {n_sort = WiredInTyCon _ _}) = True
-isWiredInName (Name {n_sort = WiredInId    _ _}) = True
-isWiredInName _                                         = False
-
-maybeWiredInIdName :: Name -> Maybe Id
-maybeWiredInIdName (Name {n_sort = WiredInId _ id}) = Just id
-maybeWiredInIdName other                           = Nothing
-
-maybeWiredInTyConName :: Name -> Maybe TyCon
-maybeWiredInTyConName (Name {n_sort = WiredInTyCon _ tc}) = Just tc
-maybeWiredInTyConName other                              = Nothing
-
-
 isLocalName (Name {n_sort = Local}) = True
 isLocalName _                      = False
 
 isGlobalName (Name {n_sort = Local}) = False
 isGlobalName other                  = True
 
+isTyVarName :: Name -> Bool
+isTyVarName name = isTvOcc (nameOccName name)
+
 -- Global names are by definition those that are visible
 -- outside the module, *as seen by the linker*.  Externally visible
 -- does not mean visible at the source level (that's isExported).
@@ -566,6 +521,7 @@ elemNameEnv          :: Name -> NameEnv a -> Bool
 unitNameEnv             :: Name -> a -> NameEnv a
 lookupNameEnv           :: NameEnv a -> Name -> Maybe a
 lookupNameEnv_NF :: NameEnv a -> Name -> a
+mapNameEnv      :: (a->b) -> NameEnv a -> NameEnv b
 
 emptyNameEnv            = emptyUFM
 mkNameEnv       = listToUFM
@@ -577,6 +533,7 @@ plusNameEnv_C        = plusUFM_C
 extendNameEnvList= addListToUFM
 delFromNameEnv          = delFromUFM
 elemNameEnv             = elemUFM
+mapNameEnv      = mapUFM
 unitNameEnv             = unitUFM
 
 lookupNameEnv                 = lookupUFM
@@ -627,15 +584,20 @@ pprName (Name {n_sort = sort, n_uniq = uniq, n_occ = occ, n_prov = prov})
 
     pp_mod_dot sty
       = case prov of
-          SystemProv                                -> pp_qual mod user_sty
-               -- Hack alert!  Omit the qualifier on SystemProv things in user style
-                -- I claim such SystemProv things will also be WiredIn things.
-               -- We can't get the omit flag right
-               -- on wired in tycons etc (sigh) so we just leave it out in user style, 
-               -- and hope that leaving it out isn't too consfusing.
-               -- (e.g. if the programmer hides Bool and  redefines it.  If so, use -dppr-debug.)
-
-          LocalDef _ _                              -> pp_qual mod (user_sty || iface_sty)
+          SystemProv -> pp_qual mod user_sty
+               -- ToDo (SDM): the following comment is out of date - do
+               -- we need to do anything different now that WiredInNames
+               -- don't exist any more?
+
+               -- Hack alert!  Omit the qualifier on SystemProv things in 
+               -- user style.  I claim such SystemProv things will also be 
+               -- WiredIn things. We can't get the omit flag right
+               -- on wired in tycons etc (sigh) so we just leave it out in 
+               -- user style, and hope that leaving it out isn't too 
+               -- consfusing. (e.g. if the programmer hides Bool and  
+               -- redefines it.  If so, use -dppr-debug.)
+
+          LocalDef _ _ -> pp_qual mod (user_sty || iface_sty)
 
           NonLocalDef (UserImport imp_mod _ _) omit 
                | user_sty                           -> pp_qual imp_mod omit