toRdrName, hashName,
isUserExportedName,
- nameSrcLoc, isLocallyDefinedName, isDllName,
+ nameSrcLoc, nameIsLocallyDefined, isDllName, nameIsFrom, nameIsLocalOrFrom,
isSystemName, isLocalName, isGlobalName, isExternallyVisibleName,
isTyVarName,
-- Environment
NameEnv, mkNameEnv,
emptyNameEnv, unitNameEnv, nameEnvElts,
- extendNameEnv_C, extendNameEnv,
+ extendNameEnv_C, extendNameEnv, foldNameEnv,
plusNameEnv, plusNameEnv_C, extendNameEnv, extendNameEnvList,
lookupNameEnv, lookupNameEnv_NF, delFromNameEnv, elemNameEnv,
-- Class NamedThing and overloaded friends
NamedThing(..),
- getSrcLoc, isLocallyDefined, getOccString, toRdrName
+ getSrcLoc, isLocallyDefined, getOccString, toRdrName,
+ isFrom, isLocalOrFrom
) where
#include "HsVersions.h"
import OccName -- All of it
import Module ( Module, moduleName, mkVanillaModule,
printModulePrefix, isModuleInThisPackage )
-import RdrName ( RdrName, mkRdrQual, mkRdrUnqual, rdrNameOcc, rdrNameModule )
+import RdrName ( RdrName, mkRdrOrig, mkRdrUnqual, rdrNameOcc, rdrNameModule )
import CmdLineOpts ( opt_Static, opt_OmitInterfacePragmas, opt_EnsureSplittableC )
import SrcLoc ( builtinSrcLoc, noSrcLoc, SrcLoc )
import Unique ( Unique, Uniquable(..), u2i, pprUnique, pprUnique10 )
-import Maybes ( expectJust )
import FastTypes
+import Maybes ( expectJust )
import UniqFM
import Outputable
\end{code}
\end{code}
\begin{code}
-isLocallyDefinedName :: Name -> Bool
+nameIsLocallyDefined :: Name -> Bool
+nameIsFrom :: Module -> Name -> Bool
+nameIsLocalOrFrom :: Module -> Name -> Bool
isUserExportedName :: Name -> Bool
isLocalName :: Name -> Bool -- Not globals
isGlobalName :: Name -> Bool
isLocalName name = not (isGlobalName name)
-isLocallyDefinedName name = isLocalName name
+nameIsLocallyDefined name = isLocalName name
+
+nameIsLocalOrFrom from (Name {n_sort = Global mod}) = mod == from
+nameIsLocalOrFrom from other = True
+
+nameIsFrom from (Name {n_sort = Global mod}) = mod == from
+nameIsFrom from other = pprPanic "nameIsFrom" (ppr other)
-- 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).
+-- does not mean visible at the source level (that's isUserExported).
isExternallyVisibleName name = isGlobalName name
+-- Constructors, selectors and suchlike Globals, and are all exported
+-- Other Local things may or may not be exported
isUserExportedName (Name { n_sort = Exported }) = True
+isUserExportedName (Name { n_sort = Global _ }) = True
isUserExportedName other = False
isSystemName (Name {n_sort = System}) = True
System -> localise -- System local Ids
Local -> localise -- User non-exported Ids
Exported -> globalise -- User-exported things
- Global _ -> no_op -- Constructors, class selectors etc
+ Global _ -> no_op -- Constructors, class selectors, default methods
where
no_op = (env, name)
nameRdrName :: Name -> RdrName
-- Makes a qualified name for top-level (Global) names, whether locally defined or not
-- and an unqualified name just for Locals
-nameRdrName (Name { n_occ = occ, n_sort = Global mod }) = mkRdrQual (moduleName mod) occ
+nameRdrName (Name { n_occ = occ, n_sort = Global mod }) = mkRdrOrig (moduleName mod) occ
nameRdrName (Name { n_occ = occ }) = mkRdrUnqual occ
-ifaceNameRdrName :: Name -> RdrName
--- Makes a qualified naem for imported things,
--- and an unqualified one for local things
-ifaceNameRdrName n | isLocallyDefined n = mkRdrUnqual (nameOccName n)
- | otherwise = mkRdrQual (moduleName (nameModule n)) (nameOccName n)
-
isDllName :: Name -> Bool
-- Does this name refer to something in a different DLL?
isDllName nm = not opt_Static &&
- not (isLocallyDefinedName nm) && -- isLocallyDefinedName test needed 'cos
+ not (nameIsLocallyDefined nm) && -- isLocallyDefinedName test needed 'cos
not (isModuleInThisPackage (nameModule nm)) -- nameModule won't work on local names
lookupNameEnv :: NameEnv a -> Name -> Maybe a
lookupNameEnv_NF :: NameEnv a -> Name -> a
mapNameEnv :: (a->b) -> NameEnv a -> NameEnv b
+foldNameEnv :: (a -> b -> b) -> b -> NameEnv a -> b
emptyNameEnv = emptyUFM
+foldNameEnv = foldUFM
mkNameEnv = listToUFM
nameEnvElts = eltsUFM
extendNameEnv_C = addToUFM_C
| otherwise = pprOccName occ
pprGlobal sty uniq mod occ
- | codeStyle sty = ppr (moduleName mod) <> char '_' <> pprOccName occ
+ | codeStyle sty = ppr (moduleName mod) <> char '_' <> pprOccName occ
+
| debugStyle sty = ppr (moduleName mod) <> dot <> pprOccName occ <>
text "{-" <> pprUnique10 uniq <> text "-}"
- | printModulePrefix mod = ppr (moduleName mod) <> dot <> pprOccName occ
- | otherwise = pprOccName occ
+
+ | ifaceStyle sty
+ || printModulePrefix mod = ppr (moduleName mod) <> dot <> pprOccName occ
+
+ | otherwise = pprOccName occ
pprSysLocal sty uniq occ
| codeStyle sty = pprUnique uniq
isLocallyDefined :: NamedThing a => a -> Bool
getOccString :: NamedThing a => a -> String
toRdrName :: NamedThing a => a -> RdrName
+isFrom :: NamedThing a => Module -> a -> Bool
+isLocalOrFrom :: NamedThing a => Module -> a -> Bool
getSrcLoc = nameSrcLoc . getName
-isLocallyDefined = isLocallyDefinedName . getName
+isLocallyDefined = nameIsLocallyDefined . getName
getOccString = occNameString . getOccName
-toRdrName = ifaceNameRdrName . getName
+toRdrName = nameRdrName . getName
+isFrom mod x = nameIsFrom mod (getName x)
+isLocalOrFrom mod x = nameIsLocalOrFrom mod ( getName x)
\end{code}
\begin{code}