{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE PatternSynonyms #-}
module Name (
Name,
BuiltInSyntax(..),
mkSystemName, mkSystemNameAt,
mkInternalName, mkClonedInternalName, mkDerivedInternalName,
mkSystemVarName, mkSysTvName,
mkFCallName,
mkExternalName, mkWiredInName,
nameUnique, setNameUnique,
nameOccName, nameModule, nameModule_maybe,
setNameLoc,
tidyNameOcc,
localiseName,
nameSrcLoc, nameSrcSpan, pprNameDefnLoc, pprDefinedAt,
isSystemName, isInternalName, isExternalName,
isTyVarName, isTyConName, isDataConName,
isValName, isVarName,
isWiredInName, isBuiltInSyntax,
isHoleName,
wiredInNameTyThing_maybe,
nameIsLocalOrFrom, nameIsHomePackage,
nameIsHomePackageImport, nameIsFromExternalPackage,
stableNameCmp,
NamedThing(..),
getSrcLoc, getSrcSpan, getOccString, getOccFS,
pprInfixName, pprPrefixName, pprModulePrefix, pprNameUnqualified,
nameStableString,
module OccName
) where
import GhcPrelude
import {-# SOURCE #-} TyCoRep( TyThing )
import OccName
import Module
import SrcLoc
import Unique
import Util
import Maybes
import Binary
import DynFlags
import FastString
import Outputable
import Control.DeepSeq
import Data.Data
data Name = Name {
Name -> NameSort
n_sort :: NameSort,
Name -> OccName
n_occ :: !OccName,
Name -> Unique
n_uniq :: {-# UNPACK #-} !Unique,
Name -> SrcSpan
n_loc :: !SrcSpan
}
data NameSort
= External Module
| WiredIn Module TyThing BuiltInSyntax
| Internal
| System
instance Outputable NameSort where
ppr :: NameSort -> SDoc
ppr (External _) = String -> SDoc
text "external"
ppr (WiredIn _ _ _) = String -> SDoc
text "wired-in"
ppr Internal = String -> SDoc
text "internal"
ppr System = String -> SDoc
text "system"
instance NFData Name where
rnf :: Name -> ()
rnf Name{..} = NameSort -> ()
forall a. NFData a => a -> ()
rnf NameSort
n_sort
instance NFData NameSort where
rnf :: NameSort -> ()
rnf (External m :: Module
m) = Module -> ()
forall a. NFData a => a -> ()
rnf Module
m
rnf (WiredIn m :: Module
m t :: TyThing
t b :: BuiltInSyntax
b) = Module -> ()
forall a. NFData a => a -> ()
rnf Module
m () -> () -> ()
forall a b. a -> b -> b
`seq` TyThing
t TyThing -> () -> ()
forall a b. a -> b -> b
`seq` BuiltInSyntax
b BuiltInSyntax -> () -> ()
forall a b. a -> b -> b
`seq` ()
rnf Internal = ()
rnf System = ()
data BuiltInSyntax = BuiltInSyntax | UserSyntax
instance HasOccName Name where
occName :: Name -> OccName
occName = Name -> OccName
nameOccName
nameUnique :: Name -> Unique
nameOccName :: Name -> OccName
nameModule :: HasDebugCallStack => Name -> Module
nameSrcLoc :: Name -> SrcLoc
nameSrcSpan :: Name -> SrcSpan
nameUnique :: Name -> Unique
nameUnique name :: Name
name = Name -> Unique
n_uniq Name
name
nameOccName :: Name -> OccName
nameOccName name :: Name
name = Name -> OccName
n_occ Name
name
nameSrcLoc :: Name -> SrcLoc
nameSrcLoc name :: Name
name = SrcSpan -> SrcLoc
srcSpanStart (Name -> SrcSpan
n_loc Name
name)
nameSrcSpan :: Name -> SrcSpan
nameSrcSpan name :: Name
name = Name -> SrcSpan
n_loc Name
name
type instance SrcSpanLess Name = Name
instance HasSrcSpan Name where
composeSrcSpan :: Located (SrcSpanLess Name) -> Name
composeSrcSpan (L sp :: SrcSpan
sp n :: SrcSpanLess Name
n) = Name
SrcSpanLess Name
n {n_loc :: SrcSpan
n_loc = SrcSpan
sp}
decomposeSrcSpan :: Name -> Located (SrcSpanLess Name)
decomposeSrcSpan n :: Name
n = SrcSpan -> Name -> GenLocated SrcSpan Name
forall l e. l -> e -> GenLocated l e
L (Name -> SrcSpan
n_loc Name
n) Name
n
isInternalName :: Name -> Bool
isExternalName :: Name -> Bool
isSystemName :: Name -> Bool
isWiredInName :: Name -> Bool
isWiredInName :: Name -> Bool
isWiredInName (Name {n_sort :: Name -> NameSort
n_sort = WiredIn _ _ _}) = Bool
True
isWiredInName _ = Bool
False
wiredInNameTyThing_maybe :: Name -> Maybe TyThing
wiredInNameTyThing_maybe :: Name -> Maybe TyThing
wiredInNameTyThing_maybe (Name {n_sort :: Name -> NameSort
n_sort = WiredIn _ thing :: TyThing
thing _}) = TyThing -> Maybe TyThing
forall a. a -> Maybe a
Just TyThing
thing
wiredInNameTyThing_maybe _ = Maybe TyThing
forall a. Maybe a
Nothing
isBuiltInSyntax :: Name -> Bool
isBuiltInSyntax :: Name -> Bool
isBuiltInSyntax (Name {n_sort :: Name -> NameSort
n_sort = WiredIn _ _ BuiltInSyntax}) = Bool
True
isBuiltInSyntax _ = Bool
False
isExternalName :: Name -> Bool
isExternalName (Name {n_sort :: Name -> NameSort
n_sort = External _}) = Bool
True
isExternalName (Name {n_sort :: Name -> NameSort
n_sort = WiredIn _ _ _}) = Bool
True
isExternalName _ = Bool
False
isInternalName :: Name -> Bool
isInternalName name :: Name
name = Bool -> Bool
not (Name -> Bool
isExternalName Name
name)
isHoleName :: Name -> Bool
isHoleName :: Name -> Bool
isHoleName = Module -> Bool
isHoleModule (Module -> Bool) -> (Name -> Module) -> Name -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasDebugCallStack => Name -> Module
Name -> Module
nameModule
nameModule :: Name -> Module
nameModule name :: Name
name =
Name -> Maybe Module
nameModule_maybe Name
name Maybe Module -> Module -> Module
forall a. Maybe a -> a -> a
`orElse`
String -> SDoc -> Module
forall a. HasCallStack => String -> SDoc -> a
pprPanic "nameModule" (NameSort -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Name -> NameSort
n_sort Name
name) SDoc -> SDoc -> SDoc
<+> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name)
nameModule_maybe :: Name -> Maybe Module
nameModule_maybe :: Name -> Maybe Module
nameModule_maybe (Name { n_sort :: Name -> NameSort
n_sort = External mod :: Module
mod}) = Module -> Maybe Module
forall a. a -> Maybe a
Just Module
mod
nameModule_maybe (Name { n_sort :: Name -> NameSort
n_sort = WiredIn mod :: Module
mod _ _}) = Module -> Maybe Module
forall a. a -> Maybe a
Just Module
mod
nameModule_maybe _ = Maybe Module
forall a. Maybe a
Nothing
nameIsLocalOrFrom :: Module -> Name -> Bool
nameIsLocalOrFrom :: Module -> Name -> Bool
nameIsLocalOrFrom from :: Module
from name :: Name
name
| Just mod :: Module
mod <- Name -> Maybe Module
nameModule_maybe Name
name = Module
from Module -> Module -> Bool
forall a. Eq a => a -> a -> Bool
== Module
mod Bool -> Bool -> Bool
|| Module -> Bool
isInteractiveModule Module
mod
| Bool
otherwise = Bool
True
nameIsHomePackage :: Module -> Name -> Bool
nameIsHomePackage :: Module -> Name -> Bool
nameIsHomePackage this_mod :: Module
this_mod
= \nm :: Name
nm -> case Name -> NameSort
n_sort Name
nm of
External nm_mod :: Module
nm_mod -> Module -> UnitId
moduleUnitId Module
nm_mod UnitId -> UnitId -> Bool
forall a. Eq a => a -> a -> Bool
== UnitId
this_pkg
WiredIn nm_mod :: Module
nm_mod _ _ -> Module -> UnitId
moduleUnitId Module
nm_mod UnitId -> UnitId -> Bool
forall a. Eq a => a -> a -> Bool
== UnitId
this_pkg
Internal -> Bool
True
System -> Bool
False
where
this_pkg :: UnitId
this_pkg = Module -> UnitId
moduleUnitId Module
this_mod
nameIsHomePackageImport :: Module -> Name -> Bool
nameIsHomePackageImport :: Module -> Name -> Bool
nameIsHomePackageImport this_mod :: Module
this_mod
= \nm :: Name
nm -> case Name -> Maybe Module
nameModule_maybe Name
nm of
Nothing -> Bool
False
Just nm_mod :: Module
nm_mod -> Module
nm_mod Module -> Module -> Bool
forall a. Eq a => a -> a -> Bool
/= Module
this_mod
Bool -> Bool -> Bool
&& Module -> UnitId
moduleUnitId Module
nm_mod UnitId -> UnitId -> Bool
forall a. Eq a => a -> a -> Bool
== UnitId
this_pkg
where
this_pkg :: UnitId
this_pkg = Module -> UnitId
moduleUnitId Module
this_mod
nameIsFromExternalPackage :: UnitId -> Name -> Bool
nameIsFromExternalPackage :: UnitId -> Name -> Bool
nameIsFromExternalPackage this_pkg :: UnitId
this_pkg name :: Name
name
| Just mod :: Module
mod <- Name -> Maybe Module
nameModule_maybe Name
name
, Module -> UnitId
moduleUnitId Module
mod UnitId -> UnitId -> Bool
forall a. Eq a => a -> a -> Bool
/= UnitId
this_pkg
, Bool -> Bool
not (Module -> Bool
isInteractiveModule Module
mod)
= Bool
True
| Bool
otherwise
= Bool
False
isTyVarName :: Name -> Bool
isTyVarName :: Name -> Bool
isTyVarName name :: Name
name = OccName -> Bool
isTvOcc (Name -> OccName
nameOccName Name
name)
isTyConName :: Name -> Bool
isTyConName :: Name -> Bool
isTyConName name :: Name
name = OccName -> Bool
isTcOcc (Name -> OccName
nameOccName Name
name)
isDataConName :: Name -> Bool
isDataConName :: Name -> Bool
isDataConName name :: Name
name = OccName -> Bool
isDataOcc (Name -> OccName
nameOccName Name
name)
isValName :: Name -> Bool
isValName :: Name -> Bool
isValName name :: Name
name = OccName -> Bool
isValOcc (Name -> OccName
nameOccName Name
name)
isVarName :: Name -> Bool
isVarName :: Name -> Bool
isVarName = OccName -> Bool
isVarOcc (OccName -> Bool) -> (Name -> OccName) -> Name -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> OccName
nameOccName
isSystemName :: Name -> Bool
isSystemName (Name {n_sort :: Name -> NameSort
n_sort = NameSort
System}) = Bool
True
isSystemName _ = Bool
False
mkInternalName :: Unique -> OccName -> SrcSpan -> Name
mkInternalName :: Unique -> OccName -> SrcSpan -> Name
mkInternalName uniq :: Unique
uniq occ :: OccName
occ loc :: SrcSpan
loc = $WName :: NameSort -> OccName -> Unique -> SrcSpan -> Name
Name { n_uniq :: Unique
n_uniq = Unique
uniq
, n_sort :: NameSort
n_sort = NameSort
Internal
, n_occ :: OccName
n_occ = OccName
occ
, n_loc :: SrcSpan
n_loc = SrcSpan
loc }
mkClonedInternalName :: Unique -> Name -> Name
mkClonedInternalName :: Unique -> Name -> Name
mkClonedInternalName uniq :: Unique
uniq (Name { n_occ :: Name -> OccName
n_occ = OccName
occ, n_loc :: Name -> SrcSpan
n_loc = SrcSpan
loc })
= $WName :: NameSort -> OccName -> Unique -> SrcSpan -> Name
Name { n_uniq :: Unique
n_uniq = Unique
uniq, n_sort :: NameSort
n_sort = NameSort
Internal
, n_occ :: OccName
n_occ = OccName
occ, n_loc :: SrcSpan
n_loc = SrcSpan
loc }
mkDerivedInternalName :: (OccName -> OccName) -> Unique -> Name -> Name
mkDerivedInternalName :: (OccName -> OccName) -> Unique -> Name -> Name
mkDerivedInternalName derive_occ :: OccName -> OccName
derive_occ uniq :: Unique
uniq (Name { n_occ :: Name -> OccName
n_occ = OccName
occ, n_loc :: Name -> SrcSpan
n_loc = SrcSpan
loc })
= $WName :: NameSort -> OccName -> Unique -> SrcSpan -> Name
Name { n_uniq :: Unique
n_uniq = Unique
uniq, n_sort :: NameSort
n_sort = NameSort
Internal
, n_occ :: OccName
n_occ = OccName -> OccName
derive_occ OccName
occ, n_loc :: SrcSpan
n_loc = SrcSpan
loc }
mkExternalName :: Unique -> Module -> OccName -> SrcSpan -> Name
mkExternalName :: Unique -> Module -> OccName -> SrcSpan -> Name
mkExternalName uniq :: Unique
uniq mod :: Module
mod occ :: OccName
occ loc :: SrcSpan
loc
= $WName :: NameSort -> OccName -> Unique -> SrcSpan -> Name
Name { n_uniq :: Unique
n_uniq = Unique
uniq, n_sort :: NameSort
n_sort = Module -> NameSort
External Module
mod,
n_occ :: OccName
n_occ = OccName
occ, n_loc :: SrcSpan
n_loc = SrcSpan
loc }
mkWiredInName :: Module -> OccName -> Unique -> TyThing -> BuiltInSyntax -> Name
mkWiredInName :: Module -> OccName -> Unique -> TyThing -> BuiltInSyntax -> Name
mkWiredInName mod :: Module
mod occ :: OccName
occ uniq :: Unique
uniq thing :: TyThing
thing built_in :: BuiltInSyntax
built_in
= $WName :: NameSort -> OccName -> Unique -> SrcSpan -> Name
Name { n_uniq :: Unique
n_uniq = Unique
uniq,
n_sort :: NameSort
n_sort = Module -> TyThing -> BuiltInSyntax -> NameSort
WiredIn Module
mod TyThing
thing BuiltInSyntax
built_in,
n_occ :: OccName
n_occ = OccName
occ, n_loc :: SrcSpan
n_loc = SrcSpan
wiredInSrcSpan }
mkSystemName :: Unique -> OccName -> Name
mkSystemName :: Unique -> OccName -> Name
mkSystemName uniq :: Unique
uniq occ :: OccName
occ = Unique -> OccName -> SrcSpan -> Name
mkSystemNameAt Unique
uniq OccName
occ SrcSpan
noSrcSpan
mkSystemNameAt :: Unique -> OccName -> SrcSpan -> Name
mkSystemNameAt :: Unique -> OccName -> SrcSpan -> Name
mkSystemNameAt uniq :: Unique
uniq occ :: OccName
occ loc :: SrcSpan
loc = $WName :: NameSort -> OccName -> Unique -> SrcSpan -> Name
Name { n_uniq :: Unique
n_uniq = Unique
uniq, n_sort :: NameSort
n_sort = NameSort
System
, n_occ :: OccName
n_occ = OccName
occ, n_loc :: SrcSpan
n_loc = SrcSpan
loc }
mkSystemVarName :: Unique -> FastString -> Name
mkSystemVarName :: Unique -> FastString -> Name
mkSystemVarName uniq :: Unique
uniq fs :: FastString
fs = Unique -> OccName -> Name
mkSystemName Unique
uniq (FastString -> OccName
mkVarOccFS FastString
fs)
mkSysTvName :: Unique -> FastString -> Name
mkSysTvName :: Unique -> FastString -> Name
mkSysTvName uniq :: Unique
uniq fs :: FastString
fs = Unique -> OccName -> Name
mkSystemName Unique
uniq (FastString -> OccName
mkTyVarOccFS FastString
fs)
mkFCallName :: Unique -> String -> Name
mkFCallName :: Unique -> String -> Name
mkFCallName uniq :: Unique
uniq str :: String
str = Unique -> OccName -> SrcSpan -> Name
mkInternalName Unique
uniq (String -> OccName
mkVarOcc String
str) SrcSpan
noSrcSpan
setNameUnique :: Name -> Unique -> Name
setNameUnique :: Name -> Unique -> Name
setNameUnique name :: Name
name uniq :: Unique
uniq = Name
name {n_uniq :: Unique
n_uniq = Unique
uniq}
setNameLoc :: Name -> SrcSpan -> Name
setNameLoc :: Name -> SrcSpan -> Name
setNameLoc name :: Name
name loc :: SrcSpan
loc = Name
name {n_loc :: SrcSpan
n_loc = SrcSpan
loc}
tidyNameOcc :: Name -> OccName -> Name
tidyNameOcc :: Name -> OccName -> Name
tidyNameOcc name :: Name
name@(Name { n_sort :: Name -> NameSort
n_sort = NameSort
System }) occ :: OccName
occ = Name
name { n_occ :: OccName
n_occ = OccName
occ, n_sort :: NameSort
n_sort = NameSort
Internal}
tidyNameOcc name :: Name
name occ :: OccName
occ = Name
name { n_occ :: OccName
n_occ = OccName
occ }
localiseName :: Name -> Name
localiseName :: Name -> Name
localiseName n :: Name
n = Name
n { n_sort :: NameSort
n_sort = NameSort
Internal }
cmpName :: Name -> Name -> Ordering
cmpName :: Name -> Name -> Ordering
cmpName n1 :: Name
n1 n2 :: Name
n2 = Name -> Unique
n_uniq Name
n1 Unique -> Unique -> Ordering
`nonDetCmpUnique` Name -> Unique
n_uniq Name
n2
stableNameCmp :: Name -> Name -> Ordering
stableNameCmp :: Name -> Name -> Ordering
stableNameCmp (Name { n_sort :: Name -> NameSort
n_sort = NameSort
s1, n_occ :: Name -> OccName
n_occ = OccName
occ1 })
(Name { n_sort :: Name -> NameSort
n_sort = NameSort
s2, n_occ :: Name -> OccName
n_occ = OccName
occ2 })
= (NameSort
s1 NameSort -> NameSort -> Ordering
`sort_cmp` NameSort
s2) Ordering -> Ordering -> Ordering
`thenCmp` (OccName
occ1 OccName -> OccName -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` OccName
occ2)
where
sort_cmp :: NameSort -> NameSort -> Ordering
sort_cmp (External m1 :: Module
m1) (External m2 :: Module
m2) = Module
m1 Module -> Module -> Ordering
`stableModuleCmp` Module
m2
sort_cmp (External {}) _ = Ordering
LT
sort_cmp (WiredIn {}) (External {}) = Ordering
GT
sort_cmp (WiredIn m1 :: Module
m1 _ _) (WiredIn m2 :: Module
m2 _ _) = Module
m1 Module -> Module -> Ordering
`stableModuleCmp` Module
m2
sort_cmp (WiredIn {}) _ = Ordering
LT
sort_cmp Internal (External {}) = Ordering
GT
sort_cmp Internal (WiredIn {}) = Ordering
GT
sort_cmp Internal Internal = Ordering
EQ
sort_cmp Internal System = Ordering
LT
sort_cmp System System = Ordering
EQ
sort_cmp System _ = Ordering
GT
instance Eq Name where
a :: Name
a == :: Name -> Name -> Bool
== b :: Name
b = case (Name
a Name -> Name -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Name
b) of { EQ -> Bool
True; _ -> Bool
False }
a :: Name
a /= :: Name -> Name -> Bool
/= b :: Name
b = case (Name
a Name -> Name -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Name
b) of { EQ -> Bool
False; _ -> Bool
True }
instance Ord Name where
a :: Name
a <= :: Name -> Name -> Bool
<= b :: Name
b = case (Name
a Name -> Name -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Name
b) of { LT -> Bool
True; EQ -> Bool
True; GT -> Bool
False }
a :: Name
a < :: Name -> Name -> Bool
< b :: Name
b = case (Name
a Name -> Name -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Name
b) of { LT -> Bool
True; EQ -> Bool
False; GT -> Bool
False }
a :: Name
a >= :: Name -> Name -> Bool
>= b :: Name
b = case (Name
a Name -> Name -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Name
b) of { LT -> Bool
False; EQ -> Bool
True; GT -> Bool
True }
a :: Name
a > :: Name -> Name -> Bool
> b :: Name
b = case (Name
a Name -> Name -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Name
b) of { LT -> Bool
False; EQ -> Bool
False; GT -> Bool
True }
compare :: Name -> Name -> Ordering
compare a :: Name
a b :: Name
b = Name -> Name -> Ordering
cmpName Name
a Name
b
instance Uniquable Name where
getUnique :: Name -> Unique
getUnique = Name -> Unique
nameUnique
instance NamedThing Name where
getName :: Name -> Name
getName n :: Name
n = Name
n
instance Data Name where
toConstr :: Name -> Constr
toConstr _ = String -> Constr
abstractConstr "Name"
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Name
gunfold _ _ = String -> Constr -> c Name
forall a. HasCallStack => String -> a
error "gunfold"
dataTypeOf :: Name -> DataType
dataTypeOf _ = String -> DataType
mkNoRepType "Name"
instance Binary Name where
put_ :: BinHandle -> Name -> IO ()
put_ bh :: BinHandle
bh name :: Name
name =
case BinHandle -> UserData
getUserData BinHandle
bh of
UserData{ ud_put_nonbinding_name :: UserData -> BinHandle -> Name -> IO ()
ud_put_nonbinding_name = BinHandle -> Name -> IO ()
put_name } -> BinHandle -> Name -> IO ()
put_name BinHandle
bh Name
name
get :: BinHandle -> IO Name
get bh :: BinHandle
bh =
case BinHandle -> UserData
getUserData BinHandle
bh of
UserData { ud_get_name :: UserData -> BinHandle -> IO Name
ud_get_name = BinHandle -> IO Name
get_name } -> BinHandle -> IO Name
get_name BinHandle
bh
instance Outputable Name where
ppr :: Name -> SDoc
ppr name :: Name
name = Name -> SDoc
pprName Name
name
instance OutputableBndr Name where
pprBndr :: BindingSite -> Name -> SDoc
pprBndr _ name :: Name
name = Name -> SDoc
pprName Name
name
pprInfixOcc :: Name -> SDoc
pprInfixOcc = Name -> SDoc
forall a. (Outputable a, NamedThing a) => a -> SDoc
pprInfixName
pprPrefixOcc :: Name -> SDoc
pprPrefixOcc = Name -> SDoc
forall a. NamedThing a => a -> SDoc
pprPrefixName
pprName :: Name -> SDoc
pprName :: Name -> SDoc
pprName (Name {n_sort :: Name -> NameSort
n_sort = NameSort
sort, n_uniq :: Name -> Unique
n_uniq = Unique
uniq, n_occ :: Name -> OccName
n_occ = OccName
occ})
= (PprStyle -> SDoc) -> SDoc
getPprStyle ((PprStyle -> SDoc) -> SDoc) -> (PprStyle -> SDoc) -> SDoc
forall a b. (a -> b) -> a -> b
$ \ sty :: PprStyle
sty ->
case NameSort
sort of
WiredIn mod :: Module
mod _ builtin :: BuiltInSyntax
builtin -> PprStyle
-> Unique -> Module -> OccName -> Bool -> BuiltInSyntax -> SDoc
pprExternal PprStyle
sty Unique
uniq Module
mod OccName
occ Bool
True BuiltInSyntax
builtin
External mod :: Module
mod -> PprStyle
-> Unique -> Module -> OccName -> Bool -> BuiltInSyntax -> SDoc
pprExternal PprStyle
sty Unique
uniq Module
mod OccName
occ Bool
False BuiltInSyntax
UserSyntax
System -> PprStyle -> Unique -> OccName -> SDoc
pprSystem PprStyle
sty Unique
uniq OccName
occ
Internal -> PprStyle -> Unique -> OccName -> SDoc
pprInternal PprStyle
sty Unique
uniq OccName
occ
pprNameUnqualified :: Name -> SDoc
pprNameUnqualified :: Name -> SDoc
pprNameUnqualified Name { n_occ :: Name -> OccName
n_occ = OccName
occ } = OccName -> SDoc
ppr_occ_name OccName
occ
pprExternal :: PprStyle -> Unique -> Module -> OccName -> Bool -> BuiltInSyntax -> SDoc
pprExternal :: PprStyle
-> Unique -> Module -> OccName -> Bool -> BuiltInSyntax -> SDoc
pprExternal sty :: PprStyle
sty uniq :: Unique
uniq mod :: Module
mod occ :: OccName
occ is_wired :: Bool
is_wired is_builtin :: BuiltInSyntax
is_builtin
| PprStyle -> Bool
codeStyle PprStyle
sty = Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod SDoc -> SDoc -> SDoc
<> Char -> SDoc
char '_' SDoc -> SDoc -> SDoc
<> OccName -> SDoc
ppr_z_occ_name OccName
occ
| PprStyle -> Bool
debugStyle PprStyle
sty = SDoc
pp_mod SDoc -> SDoc -> SDoc
<> OccName -> SDoc
ppr_occ_name OccName
occ
SDoc -> SDoc -> SDoc
<> SDoc -> SDoc
braces ([SDoc] -> SDoc
hsep [if Bool
is_wired then String -> SDoc
text "(w)" else SDoc
empty,
NameSpace -> SDoc
pprNameSpaceBrief (OccName -> NameSpace
occNameSpace OccName
occ),
Unique -> SDoc
pprUnique Unique
uniq])
| BuiltInSyntax
BuiltInSyntax <- BuiltInSyntax
is_builtin = OccName -> SDoc
ppr_occ_name OccName
occ
| Bool
otherwise =
if Module -> Bool
isHoleModule Module
mod
then case PprStyle -> QueryQualifyName
qualName PprStyle
sty Module
mod OccName
occ of
NameUnqual -> OccName -> SDoc
ppr_occ_name OccName
occ
_ -> SDoc -> SDoc
braces (ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Module -> ModuleName
moduleName Module
mod) SDoc -> SDoc -> SDoc
<> SDoc
dot SDoc -> SDoc -> SDoc
<> OccName -> SDoc
ppr_occ_name OccName
occ)
else PprStyle -> Module -> OccName -> SDoc
pprModulePrefix PprStyle
sty Module
mod OccName
occ SDoc -> SDoc -> SDoc
<> OccName -> SDoc
ppr_occ_name OccName
occ
where
pp_mod :: SDoc
pp_mod = (DynFlags -> SDoc) -> SDoc
sdocWithDynFlags ((DynFlags -> SDoc) -> SDoc) -> (DynFlags -> SDoc) -> SDoc
forall a b. (a -> b) -> a -> b
$ \dflags :: DynFlags
dflags ->
if GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_SuppressModulePrefixes DynFlags
dflags
then SDoc
empty
else Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod SDoc -> SDoc -> SDoc
<> SDoc
dot
pprInternal :: PprStyle -> Unique -> OccName -> SDoc
pprInternal :: PprStyle -> Unique -> OccName -> SDoc
pprInternal sty :: PprStyle
sty uniq :: Unique
uniq occ :: OccName
occ
| PprStyle -> Bool
codeStyle PprStyle
sty = Unique -> SDoc
pprUniqueAlways Unique
uniq
| PprStyle -> Bool
debugStyle PprStyle
sty = OccName -> SDoc
ppr_occ_name OccName
occ SDoc -> SDoc -> SDoc
<> SDoc -> SDoc
braces ([SDoc] -> SDoc
hsep [NameSpace -> SDoc
pprNameSpaceBrief (OccName -> NameSpace
occNameSpace OccName
occ),
Unique -> SDoc
pprUnique Unique
uniq])
| PprStyle -> Bool
dumpStyle PprStyle
sty = OccName -> SDoc
ppr_occ_name OccName
occ SDoc -> SDoc -> SDoc
<> Unique -> SDoc
ppr_underscore_unique Unique
uniq
| Bool
otherwise = OccName -> SDoc
ppr_occ_name OccName
occ
pprSystem :: PprStyle -> Unique -> OccName -> SDoc
pprSystem :: PprStyle -> Unique -> OccName -> SDoc
pprSystem sty :: PprStyle
sty uniq :: Unique
uniq occ :: OccName
occ
| PprStyle -> Bool
codeStyle PprStyle
sty = Unique -> SDoc
pprUniqueAlways Unique
uniq
| PprStyle -> Bool
debugStyle PprStyle
sty = OccName -> SDoc
ppr_occ_name OccName
occ SDoc -> SDoc -> SDoc
<> Unique -> SDoc
ppr_underscore_unique Unique
uniq
SDoc -> SDoc -> SDoc
<> SDoc -> SDoc
braces (NameSpace -> SDoc
pprNameSpaceBrief (OccName -> NameSpace
occNameSpace OccName
occ))
| Bool
otherwise = OccName -> SDoc
ppr_occ_name OccName
occ SDoc -> SDoc -> SDoc
<> Unique -> SDoc
ppr_underscore_unique Unique
uniq
pprModulePrefix :: PprStyle -> Module -> OccName -> SDoc
pprModulePrefix :: PprStyle -> Module -> OccName -> SDoc
pprModulePrefix sty :: PprStyle
sty mod :: Module
mod occ :: OccName
occ = (DynFlags -> SDoc) -> SDoc
sdocWithDynFlags ((DynFlags -> SDoc) -> SDoc) -> (DynFlags -> SDoc) -> SDoc
forall a b. (a -> b) -> a -> b
$ \dflags :: DynFlags
dflags ->
if GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_SuppressModulePrefixes DynFlags
dflags
then SDoc
empty
else
case PprStyle -> QueryQualifyName
qualName PprStyle
sty Module
mod OccName
occ of
NameQual modname :: ModuleName
modname -> ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
modname SDoc -> SDoc -> SDoc
<> SDoc
dot
NameNotInScope1 -> Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod SDoc -> SDoc -> SDoc
<> SDoc
dot
NameNotInScope2 -> UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Module -> UnitId
moduleUnitId Module
mod) SDoc -> SDoc -> SDoc
<> SDoc
colon
SDoc -> SDoc -> SDoc
<> ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Module -> ModuleName
moduleName Module
mod) SDoc -> SDoc -> SDoc
<> SDoc
dot
NameUnqual -> SDoc
empty
pprUnique :: Unique -> SDoc
pprUnique :: Unique -> SDoc
pprUnique uniq :: Unique
uniq
= (DynFlags -> SDoc) -> SDoc
sdocWithDynFlags ((DynFlags -> SDoc) -> SDoc) -> (DynFlags -> SDoc) -> SDoc
forall a b. (a -> b) -> a -> b
$ \dflags :: DynFlags
dflags ->
Bool -> SDoc -> SDoc
ppUnless (GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_SuppressUniques DynFlags
dflags) (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$
Unique -> SDoc
pprUniqueAlways Unique
uniq
ppr_underscore_unique :: Unique -> SDoc
ppr_underscore_unique :: Unique -> SDoc
ppr_underscore_unique uniq :: Unique
uniq
= (DynFlags -> SDoc) -> SDoc
sdocWithDynFlags ((DynFlags -> SDoc) -> SDoc) -> (DynFlags -> SDoc) -> SDoc
forall a b. (a -> b) -> a -> b
$ \dflags :: DynFlags
dflags ->
Bool -> SDoc -> SDoc
ppUnless (GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_SuppressUniques DynFlags
dflags) (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$
Char -> SDoc
char '_' SDoc -> SDoc -> SDoc
<> Unique -> SDoc
pprUniqueAlways Unique
uniq
ppr_occ_name :: OccName -> SDoc
ppr_occ_name :: OccName -> SDoc
ppr_occ_name occ :: OccName
occ = FastString -> SDoc
ftext (OccName -> FastString
occNameFS OccName
occ)
ppr_z_occ_name :: OccName -> SDoc
ppr_z_occ_name :: OccName -> SDoc
ppr_z_occ_name occ :: OccName
occ = FastZString -> SDoc
ztext (FastString -> FastZString
zEncodeFS (OccName -> FastString
occNameFS OccName
occ))
pprDefinedAt :: Name -> SDoc
pprDefinedAt :: Name -> SDoc
pprDefinedAt name :: Name
name = String -> SDoc
text "Defined" SDoc -> SDoc -> SDoc
<+> Name -> SDoc
pprNameDefnLoc Name
name
pprNameDefnLoc :: Name -> SDoc
pprNameDefnLoc :: Name -> SDoc
pprNameDefnLoc name :: Name
name
= case Name -> SrcLoc
nameSrcLoc Name
name of
RealSrcLoc s :: RealSrcLoc
s -> String -> SDoc
text "at" SDoc -> SDoc -> SDoc
<+> RealSrcLoc -> SDoc
forall a. Outputable a => a -> SDoc
ppr RealSrcLoc
s
UnhelpfulLoc s :: FastString
s
| Name -> Bool
isInternalName Name
name Bool -> Bool -> Bool
|| Name -> Bool
isSystemName Name
name
-> String -> SDoc
text "at" SDoc -> SDoc -> SDoc
<+> FastString -> SDoc
ftext FastString
s
| Bool
otherwise
-> String -> SDoc
text "in" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr (HasDebugCallStack => Name -> Module
Name -> Module
nameModule Name
name))
nameStableString :: Name -> String
nameStableString :: Name -> String
nameStableString Name{..} =
NameSort -> String
nameSortStableString NameSort
n_sort String -> String -> String
forall a. [a] -> [a] -> [a]
++ "$" String -> String -> String
forall a. [a] -> [a] -> [a]
++ OccName -> String
occNameString OccName
n_occ
nameSortStableString :: NameSort -> String
nameSortStableString :: NameSort -> String
nameSortStableString System = "$_sys"
nameSortStableString Internal = "$_in"
nameSortStableString (External mod :: Module
mod) = Module -> String
moduleStableString Module
mod
nameSortStableString (WiredIn mod :: Module
mod _ _) = Module -> String
moduleStableString Module
mod
class NamedThing a where
getOccName :: a -> OccName
getName :: a -> Name
getOccName n :: a
n = Name -> OccName
nameOccName (a -> Name
forall a. NamedThing a => a -> Name
getName a
n)
instance NamedThing e => NamedThing (Located e) where
getName :: Located e -> Name
getName = e -> Name
forall a. NamedThing a => a -> Name
getName (e -> Name) -> (Located e -> e) -> Located e -> Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Located e -> e
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc
getSrcLoc :: NamedThing a => a -> SrcLoc
getSrcSpan :: NamedThing a => a -> SrcSpan
getOccString :: NamedThing a => a -> String
getOccFS :: NamedThing a => a -> FastString
getSrcLoc :: a -> SrcLoc
getSrcLoc = Name -> SrcLoc
nameSrcLoc (Name -> SrcLoc) -> (a -> Name) -> a -> SrcLoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Name
forall a. NamedThing a => a -> Name
getName
getSrcSpan :: a -> SrcSpan
getSrcSpan = Name -> SrcSpan
nameSrcSpan (Name -> SrcSpan) -> (a -> Name) -> a -> SrcSpan
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Name
forall a. NamedThing a => a -> Name
getName
getOccString :: a -> String
getOccString = OccName -> String
occNameString (OccName -> String) -> (a -> OccName) -> a -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> OccName
forall a. NamedThing a => a -> OccName
getOccName
getOccFS :: a -> FastString
getOccFS = OccName -> FastString
occNameFS (OccName -> FastString) -> (a -> OccName) -> a -> FastString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> OccName
forall a. NamedThing a => a -> OccName
getOccName
pprInfixName :: (Outputable a, NamedThing a) => a -> SDoc
pprInfixName :: a -> SDoc
pprInfixName n :: a
n = Bool -> SDoc -> SDoc
pprInfixVar (OccName -> Bool
isSymOcc (a -> OccName
forall a. NamedThing a => a -> OccName
getOccName a
n)) (a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
n)
pprPrefixName :: NamedThing a => a -> SDoc
pprPrefixName :: a -> SDoc
pprPrefixName thing :: a
thing = Bool -> SDoc -> SDoc
pprPrefixVar (OccName -> Bool
isSymOcc (Name -> OccName
nameOccName Name
name)) (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name)
where
name :: Name
name = a -> Name
forall a. NamedThing a => a -> Name
getName a
thing