{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE OverloadedStrings #-}
module GHC.Types.Name.Occurrence (
NameSpace,
tcName, clsName, tcClsName, dataName, varName,
tvName, srcDataName,
pprNameSpace, pprNonVarNameSpace, pprNameSpaceBrief,
OccName,
pprOccName,
mkOccName, mkOccNameFS,
mkVarOcc, mkVarOccFS,
mkDataOcc, mkDataOccFS,
mkTyVarOcc, mkTyVarOccFS,
mkTcOcc, mkTcOccFS,
mkClsOcc, mkClsOccFS,
mkDFunOcc,
setOccNameSpace,
demoteOccName,
promoteOccName,
HasOccName(..),
isDerivedOccName,
mkDataConWrapperOcc, mkWorkerOcc,
mkMatcherOcc, mkBuilderOcc,
mkDefaultMethodOcc, isDefaultMethodOcc, isTypeableBindOcc,
mkNewTyCoOcc, mkClassOpAuxOcc,
mkCon2TagOcc, mkTag2ConOcc, mkMaxTagOcc,
mkClassDataConOcc, mkDictOcc, mkIPOcc,
mkSpecOcc, mkForeignExportOcc, mkRepEqOcc,
mkGenR, mkGen1R,
mkDataTOcc, mkDataCOcc, mkDataConWorkerOcc,
mkSuperDictSelOcc, mkSuperDictAuxOcc,
mkLocalOcc, mkMethodOcc, mkInstTyTcOcc,
mkInstTyCoOcc, mkEqPredCoOcc,
mkRecFldSelOcc,
mkTyConRepOcc,
occNameFS, occNameString, occNameSpace,
isVarOcc, isTvOcc, isTcOcc, isDataOcc, isDataSymOcc, isSymOcc, isValOcc,
parenSymOcc, startsWithUnderscore,
isTcClsNameSpace, isTvNameSpace, isDataConNameSpace, isVarNameSpace, isValNameSpace,
OccEnv, emptyOccEnv, unitOccEnv, extendOccEnv, mapOccEnv,
lookupOccEnv, mkOccEnv, mkOccEnv_C, extendOccEnvList, elemOccEnv,
nonDetOccEnvElts, foldOccEnv, plusOccEnv, plusOccEnv_C, extendOccEnv_C,
extendOccEnv_Acc, filterOccEnv, delListFromOccEnv, delFromOccEnv,
alterOccEnv, minusOccEnv, minusOccEnv_C, pprOccEnv,
OccSet, emptyOccSet, unitOccSet, mkOccSet, extendOccSet,
extendOccSetList,
unionOccSets, unionManyOccSets, minusOccSet, elemOccSet,
isEmptyOccSet, intersectOccSet,
filterOccSet, occSetToEnv,
TidyOccEnv, emptyTidyOccEnv, initTidyOccEnv,
tidyOccName, avoidClashesOccEnv, delTidyOccEnvList,
FastStringEnv, emptyFsEnv, lookupFsEnv, extendFsEnv, mkFsEnv
) where
import GHC.Prelude
import GHC.Utils.Misc
import GHC.Types.Unique
import GHC.Builtin.Uniques
import GHC.Types.Unique.FM
import GHC.Types.Unique.Set
import GHC.Data.FastString
import GHC.Data.FastString.Env
import GHC.Utils.Outputable
import GHC.Utils.Lexeme
import GHC.Utils.Binary
import Control.DeepSeq
import Data.Char
import Data.Data
import qualified Data.Semigroup as S
data NameSpace = VarName
| DataName
| TvName
| TcClsName
deriving( NameSpace -> NameSpace -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NameSpace -> NameSpace -> Bool
$c/= :: NameSpace -> NameSpace -> Bool
== :: NameSpace -> NameSpace -> Bool
$c== :: NameSpace -> NameSpace -> Bool
Eq, Eq NameSpace
NameSpace -> NameSpace -> Bool
NameSpace -> NameSpace -> Ordering
NameSpace -> NameSpace -> NameSpace
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: NameSpace -> NameSpace -> NameSpace
$cmin :: NameSpace -> NameSpace -> NameSpace
max :: NameSpace -> NameSpace -> NameSpace
$cmax :: NameSpace -> NameSpace -> NameSpace
>= :: NameSpace -> NameSpace -> Bool
$c>= :: NameSpace -> NameSpace -> Bool
> :: NameSpace -> NameSpace -> Bool
$c> :: NameSpace -> NameSpace -> Bool
<= :: NameSpace -> NameSpace -> Bool
$c<= :: NameSpace -> NameSpace -> Bool
< :: NameSpace -> NameSpace -> Bool
$c< :: NameSpace -> NameSpace -> Bool
compare :: NameSpace -> NameSpace -> Ordering
$ccompare :: NameSpace -> NameSpace -> Ordering
Ord )
tcName, clsName, tcClsName :: NameSpace
dataName, srcDataName :: NameSpace
tvName, varName :: NameSpace
tcName :: NameSpace
tcName = NameSpace
TcClsName
clsName :: NameSpace
clsName = NameSpace
TcClsName
tcClsName :: NameSpace
tcClsName = NameSpace
TcClsName
dataName :: NameSpace
dataName = NameSpace
DataName
srcDataName :: NameSpace
srcDataName = NameSpace
DataName
tvName :: NameSpace
tvName = NameSpace
TvName
varName :: NameSpace
varName = NameSpace
VarName
isDataConNameSpace :: NameSpace -> Bool
isDataConNameSpace :: NameSpace -> Bool
isDataConNameSpace NameSpace
DataName = Bool
True
isDataConNameSpace NameSpace
_ = Bool
False
isTcClsNameSpace :: NameSpace -> Bool
isTcClsNameSpace :: NameSpace -> Bool
isTcClsNameSpace NameSpace
TcClsName = Bool
True
isTcClsNameSpace NameSpace
_ = Bool
False
isTvNameSpace :: NameSpace -> Bool
isTvNameSpace :: NameSpace -> Bool
isTvNameSpace NameSpace
TvName = Bool
True
isTvNameSpace NameSpace
_ = Bool
False
isVarNameSpace :: NameSpace -> Bool
isVarNameSpace :: NameSpace -> Bool
isVarNameSpace NameSpace
TvName = Bool
True
isVarNameSpace NameSpace
VarName = Bool
True
isVarNameSpace NameSpace
_ = Bool
False
isValNameSpace :: NameSpace -> Bool
isValNameSpace :: NameSpace -> Bool
isValNameSpace NameSpace
DataName = Bool
True
isValNameSpace NameSpace
VarName = Bool
True
isValNameSpace NameSpace
_ = Bool
False
pprNameSpace :: NameSpace -> SDoc
pprNameSpace :: NameSpace -> SDoc
pprNameSpace NameSpace
DataName = forall doc. IsLine doc => [Char] -> doc
text [Char]
"data constructor"
pprNameSpace NameSpace
VarName = forall doc. IsLine doc => [Char] -> doc
text [Char]
"variable"
pprNameSpace NameSpace
TvName = forall doc. IsLine doc => [Char] -> doc
text [Char]
"type variable"
pprNameSpace NameSpace
TcClsName = forall doc. IsLine doc => [Char] -> doc
text [Char]
"type constructor or class"
pprNonVarNameSpace :: NameSpace -> SDoc
pprNonVarNameSpace :: NameSpace -> SDoc
pprNonVarNameSpace NameSpace
VarName = forall doc. IsOutput doc => doc
empty
pprNonVarNameSpace NameSpace
ns = NameSpace -> SDoc
pprNameSpace NameSpace
ns
pprNameSpaceBrief :: IsLine doc => NameSpace -> doc
pprNameSpaceBrief :: forall doc. IsLine doc => NameSpace -> doc
pprNameSpaceBrief NameSpace
DataName = forall doc. IsLine doc => Char -> doc
char Char
'd'
pprNameSpaceBrief NameSpace
VarName = forall doc. IsLine doc => Char -> doc
char Char
'v'
pprNameSpaceBrief NameSpace
TvName = forall doc. IsLine doc => [Char] -> doc
text [Char]
"tv"
pprNameSpaceBrief NameSpace
TcClsName = forall doc. IsLine doc => [Char] -> doc
text [Char]
"tc"
demoteNameSpace :: NameSpace -> Maybe NameSpace
demoteNameSpace :: NameSpace -> Maybe NameSpace
demoteNameSpace NameSpace
VarName = forall a. Maybe a
Nothing
demoteNameSpace NameSpace
DataName = forall a. Maybe a
Nothing
demoteNameSpace NameSpace
TvName = forall a. Maybe a
Nothing
demoteNameSpace NameSpace
TcClsName = forall a. a -> Maybe a
Just NameSpace
DataName
promoteNameSpace :: NameSpace -> Maybe NameSpace
promoteNameSpace :: NameSpace -> Maybe NameSpace
promoteNameSpace NameSpace
DataName = forall a. a -> Maybe a
Just NameSpace
TcClsName
promoteNameSpace NameSpace
VarName = forall a. a -> Maybe a
Just NameSpace
TvName
promoteNameSpace NameSpace
TcClsName = forall a. Maybe a
Nothing
promoteNameSpace NameSpace
TvName = forall a. Maybe a
Nothing
data OccName = OccName
{ OccName -> NameSpace
occNameSpace :: !NameSpace
, OccName -> FastString
occNameFS :: !FastString
}
instance Eq OccName where
(OccName NameSpace
sp1 FastString
s1) == :: OccName -> OccName -> Bool
== (OccName NameSpace
sp2 FastString
s2) = FastString
s1 forall a. Eq a => a -> a -> Bool
== FastString
s2 Bool -> Bool -> Bool
&& NameSpace
sp1 forall a. Eq a => a -> a -> Bool
== NameSpace
sp2
instance Ord OccName where
compare :: OccName -> OccName -> Ordering
compare (OccName NameSpace
sp1 FastString
s1) (OccName NameSpace
sp2 FastString
s2) = FastString -> FastString -> Ordering
lexicalCompareFS FastString
s1 FastString
s2 forall a. Semigroup a => a -> a -> a
S.<> forall a. Ord a => a -> a -> Ordering
compare NameSpace
sp1 NameSpace
sp2
instance Data OccName where
toConstr :: OccName -> Constr
toConstr OccName
_ = [Char] -> Constr
abstractConstr [Char]
"OccName"
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OccName
gunfold forall b r. Data b => c (b -> r) -> c r
_ forall r. r -> c r
_ = forall a. HasCallStack => [Char] -> a
error [Char]
"gunfold"
dataTypeOf :: OccName -> DataType
dataTypeOf OccName
_ = [Char] -> DataType
mkNoRepType [Char]
"OccName"
instance HasOccName OccName where
occName :: OccName -> OccName
occName = forall a. a -> a
id
instance NFData OccName where
rnf :: OccName -> ()
rnf OccName
x = OccName
x seq :: forall a b. a -> b -> b
`seq` ()
instance Outputable OccName where
ppr :: OccName -> SDoc
ppr = forall doc. IsLine doc => OccName -> doc
pprOccName
instance OutputableBndr OccName where
pprBndr :: BindingSite -> OccName -> SDoc
pprBndr BindingSite
_ = forall a. Outputable a => a -> SDoc
ppr
pprInfixOcc :: OccName -> SDoc
pprInfixOcc OccName
n = Bool -> SDoc -> SDoc
pprInfixVar (OccName -> Bool
isSymOcc OccName
n) (forall a. Outputable a => a -> SDoc
ppr OccName
n)
pprPrefixOcc :: OccName -> SDoc
pprPrefixOcc OccName
n = Bool -> SDoc -> SDoc
pprPrefixVar (OccName -> Bool
isSymOcc OccName
n) (forall a. Outputable a => a -> SDoc
ppr OccName
n)
pprOccName :: IsLine doc => OccName -> doc
pprOccName :: forall doc. IsLine doc => OccName -> doc
pprOccName (OccName NameSpace
sp FastString
occ)
= forall doc. IsOutput doc => (SDocContext -> doc) -> doc
docWithContext forall a b. (a -> b) -> a -> b
$ \ SDocContext
sty ->
if PprStyle -> Bool
codeStyle (SDocContext -> PprStyle
sdocStyle SDocContext
sty)
then forall doc. IsLine doc => FastZString -> doc
ztext (FastString -> FastZString
zEncodeFS FastString
occ)
else forall doc. IsLine doc => FastString -> doc
ftext FastString
occ forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsOutput doc => doc -> doc
whenPprDebug (forall doc. IsLine doc => doc -> doc
braces (forall doc. IsLine doc => NameSpace -> doc
pprNameSpaceBrief NameSpace
sp))
mkOccName :: NameSpace -> String -> OccName
mkOccName :: NameSpace -> [Char] -> OccName
mkOccName NameSpace
occ_sp [Char]
str = NameSpace -> FastString -> OccName
OccName NameSpace
occ_sp ([Char] -> FastString
mkFastString [Char]
str)
mkOccNameFS :: NameSpace -> FastString -> OccName
mkOccNameFS :: NameSpace -> FastString -> OccName
mkOccNameFS NameSpace
occ_sp FastString
fs = NameSpace -> FastString -> OccName
OccName NameSpace
occ_sp FastString
fs
mkVarOcc :: String -> OccName
mkVarOcc :: [Char] -> OccName
mkVarOcc [Char]
s = NameSpace -> [Char] -> OccName
mkOccName NameSpace
varName [Char]
s
mkVarOccFS :: FastString -> OccName
mkVarOccFS :: FastString -> OccName
mkVarOccFS FastString
fs = NameSpace -> FastString -> OccName
mkOccNameFS NameSpace
varName FastString
fs
mkDataOcc :: String -> OccName
mkDataOcc :: [Char] -> OccName
mkDataOcc = NameSpace -> [Char] -> OccName
mkOccName NameSpace
dataName
mkDataOccFS :: FastString -> OccName
mkDataOccFS :: FastString -> OccName
mkDataOccFS = NameSpace -> FastString -> OccName
mkOccNameFS NameSpace
dataName
mkTyVarOcc :: String -> OccName
mkTyVarOcc :: [Char] -> OccName
mkTyVarOcc = NameSpace -> [Char] -> OccName
mkOccName NameSpace
tvName
mkTyVarOccFS :: FastString -> OccName
mkTyVarOccFS :: FastString -> OccName
mkTyVarOccFS FastString
fs = NameSpace -> FastString -> OccName
mkOccNameFS NameSpace
tvName FastString
fs
mkTcOcc :: String -> OccName
mkTcOcc :: [Char] -> OccName
mkTcOcc = NameSpace -> [Char] -> OccName
mkOccName NameSpace
tcName
mkTcOccFS :: FastString -> OccName
mkTcOccFS :: FastString -> OccName
mkTcOccFS = NameSpace -> FastString -> OccName
mkOccNameFS NameSpace
tcName
mkClsOcc :: String -> OccName
mkClsOcc :: [Char] -> OccName
mkClsOcc = NameSpace -> [Char] -> OccName
mkOccName NameSpace
clsName
mkClsOccFS :: FastString -> OccName
mkClsOccFS :: FastString -> OccName
mkClsOccFS = NameSpace -> FastString -> OccName
mkOccNameFS NameSpace
clsName
demoteOccName :: OccName -> Maybe OccName
demoteOccName :: OccName -> Maybe OccName
demoteOccName (OccName NameSpace
space FastString
name) = do
NameSpace
space' <- NameSpace -> Maybe NameSpace
demoteNameSpace NameSpace
space
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ NameSpace -> FastString -> OccName
OccName NameSpace
space' FastString
name
promoteOccName :: OccName -> Maybe OccName
promoteOccName :: OccName -> Maybe OccName
promoteOccName (OccName NameSpace
space FastString
name) = do
NameSpace
space' <- NameSpace -> Maybe NameSpace
promoteNameSpace NameSpace
space
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ NameSpace -> FastString -> OccName
OccName NameSpace
space' FastString
name
class HasOccName name where
occName :: name -> OccName
instance Uniquable OccName where
getUnique :: OccName -> Unique
getUnique (OccName NameSpace
VarName FastString
fs) = FastString -> Unique
mkVarOccUnique FastString
fs
getUnique (OccName NameSpace
DataName FastString
fs) = FastString -> Unique
mkDataOccUnique FastString
fs
getUnique (OccName NameSpace
TvName FastString
fs) = FastString -> Unique
mkTvOccUnique FastString
fs
getUnique (OccName NameSpace
TcClsName FastString
fs) = FastString -> Unique
mkTcOccUnique FastString
fs
newtype OccEnv a = A (UniqFM OccName a)
deriving OccEnv a -> DataType
OccEnv a -> Constr
forall {a}. Data a => Typeable (OccEnv a)
forall a. Data a => OccEnv a -> DataType
forall a. Data a => OccEnv a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> OccEnv a -> OccEnv a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> OccEnv a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> OccEnv a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OccEnv a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OccEnv a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> OccEnv a -> m (OccEnv a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> OccEnv a -> m (OccEnv a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (OccEnv a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OccEnv a -> c (OccEnv a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (OccEnv a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (OccEnv a))
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (OccEnv a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OccEnv a -> c (OccEnv a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (OccEnv a))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OccEnv a -> m (OccEnv a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> OccEnv a -> m (OccEnv a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OccEnv a -> m (OccEnv a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> OccEnv a -> m (OccEnv a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> OccEnv a -> m (OccEnv a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> OccEnv a -> m (OccEnv a)
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> OccEnv a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> OccEnv a -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> OccEnv a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> OccEnv a -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OccEnv a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OccEnv a -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OccEnv a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OccEnv a -> r
gmapT :: (forall b. Data b => b -> b) -> OccEnv a -> OccEnv a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> OccEnv a -> OccEnv a
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (OccEnv a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (OccEnv a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (OccEnv a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (OccEnv a))
dataTypeOf :: OccEnv a -> DataType
$cdataTypeOf :: forall a. Data a => OccEnv a -> DataType
toConstr :: OccEnv a -> Constr
$ctoConstr :: forall a. Data a => OccEnv a -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (OccEnv a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (OccEnv a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OccEnv a -> c (OccEnv a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OccEnv a -> c (OccEnv a)
Data
emptyOccEnv :: OccEnv a
unitOccEnv :: OccName -> a -> OccEnv a
extendOccEnv :: OccEnv a -> OccName -> a -> OccEnv a
extendOccEnvList :: OccEnv a -> [(OccName, a)] -> OccEnv a
lookupOccEnv :: OccEnv a -> OccName -> Maybe a
mkOccEnv :: [(OccName,a)] -> OccEnv a
mkOccEnv_C :: (a -> a -> a) -> [(OccName,a)] -> OccEnv a
elemOccEnv :: OccName -> OccEnv a -> Bool
foldOccEnv :: (a -> b -> b) -> b -> OccEnv a -> b
nonDetOccEnvElts :: OccEnv a -> [a]
extendOccEnv_C :: (a->a->a) -> OccEnv a -> OccName -> a -> OccEnv a
extendOccEnv_Acc :: (a->b->b) -> (a->b) -> OccEnv b -> OccName -> a -> OccEnv b
plusOccEnv :: OccEnv a -> OccEnv a -> OccEnv a
plusOccEnv_C :: (a->a->a) -> OccEnv a -> OccEnv a -> OccEnv a
mapOccEnv :: (a->b) -> OccEnv a -> OccEnv b
delFromOccEnv :: OccEnv a -> OccName -> OccEnv a
delListFromOccEnv :: OccEnv a -> [OccName] -> OccEnv a
filterOccEnv :: (elt -> Bool) -> OccEnv elt -> OccEnv elt
alterOccEnv :: (Maybe elt -> Maybe elt) -> OccEnv elt -> OccName -> OccEnv elt
minusOccEnv :: OccEnv a -> OccEnv b -> OccEnv a
minusOccEnv_C :: (a -> b -> Maybe a) -> OccEnv a -> OccEnv b -> OccEnv a
emptyOccEnv :: forall a. OccEnv a
emptyOccEnv = forall a. UniqFM OccName a -> OccEnv a
A forall key elt. UniqFM key elt
emptyUFM
unitOccEnv :: forall a. OccName -> a -> OccEnv a
unitOccEnv OccName
x a
y = forall a. UniqFM OccName a -> OccEnv a
A forall a b. (a -> b) -> a -> b
$ forall key elt. Uniquable key => key -> elt -> UniqFM key elt
unitUFM OccName
x a
y
extendOccEnv :: forall a. OccEnv a -> OccName -> a -> OccEnv a
extendOccEnv (A UniqFM OccName a
x) OccName
y a
z = forall a. UniqFM OccName a -> OccEnv a
A forall a b. (a -> b) -> a -> b
$ forall key elt.
Uniquable key =>
UniqFM key elt -> key -> elt -> UniqFM key elt
addToUFM UniqFM OccName a
x OccName
y a
z
extendOccEnvList :: forall a. OccEnv a -> [(OccName, a)] -> OccEnv a
extendOccEnvList (A UniqFM OccName a
x) [(OccName, a)]
l = forall a. UniqFM OccName a -> OccEnv a
A forall a b. (a -> b) -> a -> b
$ forall key elt.
Uniquable key =>
UniqFM key elt -> [(key, elt)] -> UniqFM key elt
addListToUFM UniqFM OccName a
x [(OccName, a)]
l
lookupOccEnv :: forall a. OccEnv a -> OccName -> Maybe a
lookupOccEnv (A UniqFM OccName a
x) OccName
y = forall key elt. Uniquable key => UniqFM key elt -> key -> Maybe elt
lookupUFM UniqFM OccName a
x OccName
y
mkOccEnv :: forall a. [(OccName, a)] -> OccEnv a
mkOccEnv [(OccName, a)]
l = forall a. UniqFM OccName a -> OccEnv a
A forall a b. (a -> b) -> a -> b
$ forall key elt. Uniquable key => [(key, elt)] -> UniqFM key elt
listToUFM [(OccName, a)]
l
elemOccEnv :: forall a. OccName -> OccEnv a -> Bool
elemOccEnv OccName
x (A UniqFM OccName a
y) = forall key elt. Uniquable key => key -> UniqFM key elt -> Bool
elemUFM OccName
x UniqFM OccName a
y
foldOccEnv :: forall a b. (a -> b -> b) -> b -> OccEnv a -> b
foldOccEnv a -> b -> b
a b
b (A UniqFM OccName a
c) = forall elt a key. (elt -> a -> a) -> a -> UniqFM key elt -> a
foldUFM a -> b -> b
a b
b UniqFM OccName a
c
nonDetOccEnvElts :: forall a. OccEnv a -> [a]
nonDetOccEnvElts (A UniqFM OccName a
x) = forall key elt. UniqFM key elt -> [elt]
nonDetEltsUFM UniqFM OccName a
x
plusOccEnv :: forall a. OccEnv a -> OccEnv a -> OccEnv a
plusOccEnv (A UniqFM OccName a
x) (A UniqFM OccName a
y) = forall a. UniqFM OccName a -> OccEnv a
A forall a b. (a -> b) -> a -> b
$ forall key elt. UniqFM key elt -> UniqFM key elt -> UniqFM key elt
plusUFM UniqFM OccName a
x UniqFM OccName a
y
plusOccEnv_C :: forall a. (a -> a -> a) -> OccEnv a -> OccEnv a -> OccEnv a
plusOccEnv_C a -> a -> a
f (A UniqFM OccName a
x) (A UniqFM OccName a
y) = forall a. UniqFM OccName a -> OccEnv a
A forall a b. (a -> b) -> a -> b
$ forall elt key.
(elt -> elt -> elt)
-> UniqFM key elt -> UniqFM key elt -> UniqFM key elt
plusUFM_C a -> a -> a
f UniqFM OccName a
x UniqFM OccName a
y
extendOccEnv_C :: forall a. (a -> a -> a) -> OccEnv a -> OccName -> a -> OccEnv a
extendOccEnv_C a -> a -> a
f (A UniqFM OccName a
x) OccName
y a
z = forall a. UniqFM OccName a -> OccEnv a
A forall a b. (a -> b) -> a -> b
$ forall key elt.
Uniquable key =>
(elt -> elt -> elt)
-> UniqFM key elt -> key -> elt -> UniqFM key elt
addToUFM_C a -> a -> a
f UniqFM OccName a
x OccName
y a
z
extendOccEnv_Acc :: forall a b.
(a -> b -> b) -> (a -> b) -> OccEnv b -> OccName -> a -> OccEnv b
extendOccEnv_Acc a -> b -> b
f a -> b
g (A UniqFM OccName b
x) OccName
y a
z = forall a. UniqFM OccName a -> OccEnv a
A forall a b. (a -> b) -> a -> b
$ forall key elt elts.
Uniquable key =>
(elt -> elts -> elts)
-> (elt -> elts)
-> UniqFM key elts
-> key
-> elt
-> UniqFM key elts
addToUFM_Acc a -> b -> b
f a -> b
g UniqFM OccName b
x OccName
y a
z
mapOccEnv :: forall a b. (a -> b) -> OccEnv a -> OccEnv b
mapOccEnv a -> b
f (A UniqFM OccName a
x) = forall a. UniqFM OccName a -> OccEnv a
A forall a b. (a -> b) -> a -> b
$ forall elt1 elt2 key.
(elt1 -> elt2) -> UniqFM key elt1 -> UniqFM key elt2
mapUFM a -> b
f UniqFM OccName a
x
mkOccEnv_C :: forall a. (a -> a -> a) -> [(OccName, a)] -> OccEnv a
mkOccEnv_C a -> a -> a
comb [(OccName, a)]
l = forall a. UniqFM OccName a -> OccEnv a
A forall a b. (a -> b) -> a -> b
$ forall key elt.
Uniquable key =>
(elt -> elt -> elt)
-> UniqFM key elt -> [(key, elt)] -> UniqFM key elt
addListToUFM_C a -> a -> a
comb forall key elt. UniqFM key elt
emptyUFM [(OccName, a)]
l
delFromOccEnv :: forall a. OccEnv a -> OccName -> OccEnv a
delFromOccEnv (A UniqFM OccName a
x) OccName
y = forall a. UniqFM OccName a -> OccEnv a
A forall a b. (a -> b) -> a -> b
$ forall key elt.
Uniquable key =>
UniqFM key elt -> key -> UniqFM key elt
delFromUFM UniqFM OccName a
x OccName
y
delListFromOccEnv :: forall a. OccEnv a -> [OccName] -> OccEnv a
delListFromOccEnv (A UniqFM OccName a
x) [OccName]
y = forall a. UniqFM OccName a -> OccEnv a
A forall a b. (a -> b) -> a -> b
$ forall key elt.
Uniquable key =>
UniqFM key elt -> [key] -> UniqFM key elt
delListFromUFM UniqFM OccName a
x [OccName]
y
filterOccEnv :: forall elt. (elt -> Bool) -> OccEnv elt -> OccEnv elt
filterOccEnv elt -> Bool
x (A UniqFM OccName elt
y) = forall a. UniqFM OccName a -> OccEnv a
A forall a b. (a -> b) -> a -> b
$ forall elt key. (elt -> Bool) -> UniqFM key elt -> UniqFM key elt
filterUFM elt -> Bool
x UniqFM OccName elt
y
alterOccEnv :: forall elt.
(Maybe elt -> Maybe elt) -> OccEnv elt -> OccName -> OccEnv elt
alterOccEnv Maybe elt -> Maybe elt
fn (A UniqFM OccName elt
y) OccName
k = forall a. UniqFM OccName a -> OccEnv a
A forall a b. (a -> b) -> a -> b
$ forall key elt.
Uniquable key =>
(Maybe elt -> Maybe elt) -> UniqFM key elt -> key -> UniqFM key elt
alterUFM Maybe elt -> Maybe elt
fn UniqFM OccName elt
y OccName
k
minusOccEnv :: forall a b. OccEnv a -> OccEnv b -> OccEnv a
minusOccEnv (A UniqFM OccName a
x) (A UniqFM OccName b
y) = forall a. UniqFM OccName a -> OccEnv a
A forall a b. (a -> b) -> a -> b
$ forall key elt1 elt2.
UniqFM key elt1 -> UniqFM key elt2 -> UniqFM key elt1
minusUFM UniqFM OccName a
x UniqFM OccName b
y
minusOccEnv_C :: forall a b. (a -> b -> Maybe a) -> OccEnv a -> OccEnv b -> OccEnv a
minusOccEnv_C a -> b -> Maybe a
fn (A UniqFM OccName a
x) (A UniqFM OccName b
y) = forall a. UniqFM OccName a -> OccEnv a
A forall a b. (a -> b) -> a -> b
$ forall elt1 elt2 key.
(elt1 -> elt2 -> Maybe elt1)
-> UniqFM key elt1 -> UniqFM key elt2 -> UniqFM key elt1
minusUFM_C a -> b -> Maybe a
fn UniqFM OccName a
x UniqFM OccName b
y
instance Outputable a => Outputable (OccEnv a) where
ppr :: OccEnv a -> SDoc
ppr OccEnv a
x = forall a. (a -> SDoc) -> OccEnv a -> SDoc
pprOccEnv forall a. Outputable a => a -> SDoc
ppr OccEnv a
x
pprOccEnv :: (a -> SDoc) -> OccEnv a -> SDoc
pprOccEnv :: forall a. (a -> SDoc) -> OccEnv a -> SDoc
pprOccEnv a -> SDoc
ppr_elt (A UniqFM OccName a
env) = forall a key. (a -> SDoc) -> UniqFM key a -> SDoc
pprUniqFM a -> SDoc
ppr_elt UniqFM OccName a
env
type OccSet = UniqSet OccName
emptyOccSet :: OccSet
unitOccSet :: OccName -> OccSet
mkOccSet :: [OccName] -> OccSet
extendOccSet :: OccSet -> OccName -> OccSet
extendOccSetList :: OccSet -> [OccName] -> OccSet
unionOccSets :: OccSet -> OccSet -> OccSet
unionManyOccSets :: [OccSet] -> OccSet
minusOccSet :: OccSet -> OccSet -> OccSet
elemOccSet :: OccName -> OccSet -> Bool
isEmptyOccSet :: OccSet -> Bool
intersectOccSet :: OccSet -> OccSet -> OccSet
filterOccSet :: (OccName -> Bool) -> OccSet -> OccSet
occSetToEnv :: OccSet -> OccEnv OccName
emptyOccSet :: OccSet
emptyOccSet = forall a. UniqSet a
emptyUniqSet
unitOccSet :: OccName -> OccSet
unitOccSet = forall a. Uniquable a => a -> UniqSet a
unitUniqSet
mkOccSet :: [OccName] -> OccSet
mkOccSet = forall a. Uniquable a => [a] -> UniqSet a
mkUniqSet
extendOccSet :: OccSet -> OccName -> OccSet
extendOccSet = forall a. Uniquable a => UniqSet a -> a -> UniqSet a
addOneToUniqSet
extendOccSetList :: OccSet -> [OccName] -> OccSet
extendOccSetList = forall a. Uniquable a => UniqSet a -> [a] -> UniqSet a
addListToUniqSet
unionOccSets :: OccSet -> OccSet -> OccSet
unionOccSets = forall a. UniqSet a -> UniqSet a -> UniqSet a
unionUniqSets
unionManyOccSets :: [OccSet] -> OccSet
unionManyOccSets = forall a. [UniqSet a] -> UniqSet a
unionManyUniqSets
minusOccSet :: OccSet -> OccSet -> OccSet
minusOccSet = forall a. UniqSet a -> UniqSet a -> UniqSet a
minusUniqSet
elemOccSet :: OccName -> OccSet -> Bool
elemOccSet = forall a. Uniquable a => a -> UniqSet a -> Bool
elementOfUniqSet
isEmptyOccSet :: OccSet -> Bool
isEmptyOccSet = forall a. UniqSet a -> Bool
isEmptyUniqSet
intersectOccSet :: OccSet -> OccSet -> OccSet
intersectOccSet = forall a. UniqSet a -> UniqSet a -> UniqSet a
intersectUniqSets
filterOccSet :: (OccName -> Bool) -> OccSet -> OccSet
filterOccSet = forall a. (a -> Bool) -> UniqSet a -> UniqSet a
filterUniqSet
occSetToEnv :: OccSet -> OccEnv OccName
occSetToEnv = forall a. UniqFM OccName a -> OccEnv a
A forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. UniqSet a -> UniqFM a a
getUniqSet
occNameString :: OccName -> String
occNameString :: OccName -> [Char]
occNameString (OccName NameSpace
_ FastString
s) = FastString -> [Char]
unpackFS FastString
s
setOccNameSpace :: NameSpace -> OccName -> OccName
setOccNameSpace :: NameSpace -> OccName -> OccName
setOccNameSpace NameSpace
sp (OccName NameSpace
_ FastString
occ) = NameSpace -> FastString -> OccName
OccName NameSpace
sp FastString
occ
isVarOcc, isTvOcc, isTcOcc, isDataOcc :: OccName -> Bool
isVarOcc :: OccName -> Bool
isVarOcc (OccName NameSpace
VarName FastString
_) = Bool
True
isVarOcc OccName
_ = Bool
False
isTvOcc :: OccName -> Bool
isTvOcc (OccName NameSpace
TvName FastString
_) = Bool
True
isTvOcc OccName
_ = Bool
False
isTcOcc :: OccName -> Bool
isTcOcc (OccName NameSpace
TcClsName FastString
_) = Bool
True
isTcOcc OccName
_ = Bool
False
isValOcc :: OccName -> Bool
isValOcc :: OccName -> Bool
isValOcc (OccName NameSpace
VarName FastString
_) = Bool
True
isValOcc (OccName NameSpace
DataName FastString
_) = Bool
True
isValOcc OccName
_ = Bool
False
isDataOcc :: OccName -> Bool
isDataOcc (OccName NameSpace
DataName FastString
_) = Bool
True
isDataOcc OccName
_ = Bool
False
isDataSymOcc :: OccName -> Bool
isDataSymOcc :: OccName -> Bool
isDataSymOcc (OccName NameSpace
DataName FastString
s) = FastString -> Bool
isLexConSym FastString
s
isDataSymOcc OccName
_ = Bool
False
isSymOcc :: OccName -> Bool
isSymOcc :: OccName -> Bool
isSymOcc (OccName NameSpace
DataName FastString
s) = FastString -> Bool
isLexConSym FastString
s
isSymOcc (OccName NameSpace
TcClsName FastString
s) = FastString -> Bool
isLexSym FastString
s
isSymOcc (OccName NameSpace
VarName FastString
s) = FastString -> Bool
isLexSym FastString
s
isSymOcc (OccName NameSpace
TvName FastString
s) = FastString -> Bool
isLexSym FastString
s
parenSymOcc :: OccName -> SDoc -> SDoc
parenSymOcc :: OccName -> SDoc -> SDoc
parenSymOcc OccName
occ SDoc
doc | OccName -> Bool
isSymOcc OccName
occ = forall doc. IsLine doc => doc -> doc
parens SDoc
doc
| Bool
otherwise = SDoc
doc
startsWithUnderscore :: OccName -> Bool
startsWithUnderscore :: OccName -> Bool
startsWithUnderscore OccName
occ = case FastString -> [Char]
unpackFS (OccName -> FastString
occNameFS OccName
occ) of
Char
'_':[Char]
_ -> Bool
True
[Char]
_ -> Bool
False
mk_deriv :: NameSpace
-> FastString
-> [FastString]
-> OccName
mk_deriv :: NameSpace -> FastString -> [FastString] -> OccName
mk_deriv NameSpace
occ_sp FastString
sys_prefix [FastString]
str =
NameSpace -> FastString -> OccName
mkOccNameFS NameSpace
occ_sp ([FastString] -> FastString
concatFS forall a b. (a -> b) -> a -> b
$ FastString
sys_prefix forall a. a -> [a] -> [a]
: [FastString]
str)
isDerivedOccName :: OccName -> Bool
isDerivedOccName :: OccName -> Bool
isDerivedOccName OccName
occ =
case OccName -> [Char]
occNameString OccName
occ of
Char
'$':Char
c:[Char]
_ | Char -> Bool
isAlphaNum Char
c -> Bool
True
Char
c:Char
':':[Char]
_ | Char -> Bool
isAlphaNum Char
c -> Bool
True
[Char]
_other -> Bool
False
isDefaultMethodOcc :: OccName -> Bool
isDefaultMethodOcc :: OccName -> Bool
isDefaultMethodOcc OccName
occ =
case OccName -> [Char]
occNameString OccName
occ of
Char
'$':Char
'd':Char
'm':[Char]
_ -> Bool
True
[Char]
_ -> Bool
False
isTypeableBindOcc :: OccName -> Bool
isTypeableBindOcc :: OccName -> Bool
isTypeableBindOcc OccName
occ =
case OccName -> [Char]
occNameString OccName
occ of
Char
'$':Char
't':Char
'c':[Char]
_ -> Bool
True
Char
'$':Char
't':Char
'r':[Char]
_ -> Bool
True
[Char]
_ -> Bool
False
mkDataConWrapperOcc, mkWorkerOcc,
mkMatcherOcc, mkBuilderOcc,
mkDefaultMethodOcc,
mkClassDataConOcc, mkDictOcc,
mkIPOcc, mkSpecOcc, mkForeignExportOcc, mkRepEqOcc,
mkGenR, mkGen1R,
mkDataConWorkerOcc, mkNewTyCoOcc,
mkInstTyCoOcc, mkEqPredCoOcc, mkClassOpAuxOcc,
mkCon2TagOcc, mkTag2ConOcc, mkMaxTagOcc, mkDataTOcc, mkDataCOcc,
mkTyConRepOcc
:: OccName -> OccName
mkDataConWrapperOcc :: OccName -> OccName
mkDataConWrapperOcc = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
varName FastString
"$W"
mkWorkerOcc :: OccName -> OccName
mkWorkerOcc = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
varName FastString
"$w"
mkMatcherOcc :: OccName -> OccName
mkMatcherOcc = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
varName FastString
"$m"
mkBuilderOcc :: OccName -> OccName
mkBuilderOcc = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
varName FastString
"$b"
mkDefaultMethodOcc :: OccName -> OccName
mkDefaultMethodOcc = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
varName FastString
"$dm"
mkClassOpAuxOcc :: OccName -> OccName
mkClassOpAuxOcc = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
varName FastString
"$c"
mkDictOcc :: OccName -> OccName
mkDictOcc = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
varName FastString
"$d"
mkIPOcc :: OccName -> OccName
mkIPOcc = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
varName FastString
"$i"
mkSpecOcc :: OccName -> OccName
mkSpecOcc = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
varName FastString
"$s"
mkForeignExportOcc :: OccName -> OccName
mkForeignExportOcc = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
varName FastString
"$f"
mkRepEqOcc :: OccName -> OccName
mkRepEqOcc = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
tvName FastString
"$r"
mkClassDataConOcc :: OccName -> OccName
mkClassDataConOcc = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
dataName FastString
"C:"
mkNewTyCoOcc :: OccName -> OccName
mkNewTyCoOcc = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
tcName FastString
"N:"
mkInstTyCoOcc :: OccName -> OccName
mkInstTyCoOcc = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
tcName FastString
"D:"
mkEqPredCoOcc :: OccName -> OccName
mkEqPredCoOcc = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
tcName FastString
"$co"
mkCon2TagOcc :: OccName -> OccName
mkCon2TagOcc = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
varName FastString
"$con2tag_"
mkTag2ConOcc :: OccName -> OccName
mkTag2ConOcc = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
varName FastString
"$tag2con_"
mkMaxTagOcc :: OccName -> OccName
mkMaxTagOcc = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
varName FastString
"$maxtag_"
mkDataTOcc :: OccName -> OccName
mkDataTOcc = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
varName FastString
"$t"
mkDataCOcc :: OccName -> OccName
mkDataCOcc = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
varName FastString
"$c"
mkTyConRepOcc :: OccName -> OccName
mkTyConRepOcc OccName
occ = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
varName FastString
prefix OccName
occ
where
prefix :: FastString
prefix | OccName -> Bool
isDataOcc OccName
occ = FastString
"$tc'"
| Bool
otherwise = FastString
"$tc"
mkGenR :: OccName -> OccName
mkGenR = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
tcName FastString
"Rep_"
mkGen1R :: OccName -> OccName
mkGen1R = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
tcName FastString
"Rep1_"
mkRecFldSelOcc :: FastString -> OccName
mkRecFldSelOcc :: FastString -> OccName
mkRecFldSelOcc FastString
s = NameSpace -> FastString -> [FastString] -> OccName
mk_deriv NameSpace
varName FastString
"$sel" [FastString
s]
mk_simple_deriv :: NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv :: NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
sp FastString
px OccName
occ = NameSpace -> FastString -> [FastString] -> OccName
mk_deriv NameSpace
sp FastString
px [OccName -> FastString
occNameFS OccName
occ]
mkDataConWorkerOcc :: OccName -> OccName
mkDataConWorkerOcc OccName
datacon_occ = NameSpace -> OccName -> OccName
setOccNameSpace NameSpace
varName OccName
datacon_occ
mkSuperDictAuxOcc :: Int -> OccName -> OccName
mkSuperDictAuxOcc :: Int -> OccName -> OccName
mkSuperDictAuxOcc Int
index OccName
cls_tc_occ
= NameSpace -> FastString -> [FastString] -> OccName
mk_deriv NameSpace
varName FastString
"$cp" [[Char] -> FastString
fsLit forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> [Char]
show Int
index, OccName -> FastString
occNameFS OccName
cls_tc_occ]
mkSuperDictSelOcc :: Int
-> OccName
-> OccName
mkSuperDictSelOcc :: Int -> OccName -> OccName
mkSuperDictSelOcc Int
index OccName
cls_tc_occ
= NameSpace -> FastString -> [FastString] -> OccName
mk_deriv NameSpace
varName FastString
"$p" [[Char] -> FastString
fsLit forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> [Char]
show Int
index, OccName -> FastString
occNameFS OccName
cls_tc_occ]
mkLocalOcc :: Unique
-> OccName
-> OccName
mkLocalOcc :: Unique -> OccName -> OccName
mkLocalOcc Unique
uniq OccName
occ
= NameSpace -> FastString -> [FastString] -> OccName
mk_deriv NameSpace
varName FastString
"$L" [[Char] -> FastString
fsLit forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> [Char]
show Unique
uniq, OccName -> FastString
occNameFS OccName
occ]
mkInstTyTcOcc :: String
-> OccSet
-> OccName
mkInstTyTcOcc :: [Char] -> OccSet -> OccName
mkInstTyTcOcc [Char]
str = NameSpace -> [Char] -> OccSet -> OccName
chooseUniqueOcc NameSpace
tcName (Char
'R' forall a. a -> [a] -> [a]
: Char
':' forall a. a -> [a] -> [a]
: [Char]
str)
mkDFunOcc :: String
-> Bool
-> OccSet
-> OccName
mkDFunOcc :: [Char] -> Bool -> OccSet -> OccName
mkDFunOcc [Char]
info_str Bool
is_boot OccSet
set
= NameSpace -> [Char] -> OccSet -> OccName
chooseUniqueOcc NameSpace
VarName ([Char]
prefix forall a. [a] -> [a] -> [a]
++ [Char]
info_str) OccSet
set
where
prefix :: [Char]
prefix | Bool
is_boot = [Char]
"$fx"
| Bool
otherwise = [Char]
"$f"
chooseUniqueOcc :: NameSpace -> String -> OccSet -> OccName
chooseUniqueOcc :: NameSpace -> [Char] -> OccSet -> OccName
chooseUniqueOcc NameSpace
ns [Char]
str OccSet
set = OccName -> Int -> OccName
loop (NameSpace -> [Char] -> OccName
mkOccName NameSpace
ns [Char]
str) (Int
0::Int)
where
loop :: OccName -> Int -> OccName
loop OccName
occ Int
n
| OccName
occ OccName -> OccSet -> Bool
`elemOccSet` OccSet
set = OccName -> Int -> OccName
loop (NameSpace -> [Char] -> OccName
mkOccName NameSpace
ns ([Char]
str forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show Int
n)) (Int
nforall a. Num a => a -> a -> a
+Int
1)
| Bool
otherwise = OccName
occ
mkMethodOcc :: OccName -> OccName
mkMethodOcc :: OccName -> OccName
mkMethodOcc occ :: OccName
occ@(OccName NameSpace
VarName FastString
_) = OccName
occ
mkMethodOcc OccName
occ = NameSpace -> FastString -> OccName -> OccName
mk_simple_deriv NameSpace
varName FastString
"$m" OccName
occ
type TidyOccEnv = UniqFM FastString Int
emptyTidyOccEnv :: TidyOccEnv
emptyTidyOccEnv :: TidyOccEnv
emptyTidyOccEnv = forall key elt. UniqFM key elt
emptyUFM
initTidyOccEnv :: [OccName] -> TidyOccEnv
initTidyOccEnv :: [OccName] -> TidyOccEnv
initTidyOccEnv = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' forall {elt}.
Num elt =>
UniqFM FastString elt -> OccName -> UniqFM FastString elt
add forall key elt. UniqFM key elt
emptyUFM
where
add :: UniqFM FastString elt -> OccName -> UniqFM FastString elt
add UniqFM FastString elt
env (OccName NameSpace
_ FastString
fs) = forall key elt.
Uniquable key =>
UniqFM key elt -> key -> elt -> UniqFM key elt
addToUFM UniqFM FastString elt
env FastString
fs elt
1
delTidyOccEnvList :: TidyOccEnv -> [FastString] -> TidyOccEnv
delTidyOccEnvList :: TidyOccEnv -> [FastString] -> TidyOccEnv
delTidyOccEnvList = forall key elt.
Uniquable key =>
UniqFM key elt -> [key] -> UniqFM key elt
delListFromUFM
avoidClashesOccEnv :: TidyOccEnv -> [OccName] -> TidyOccEnv
avoidClashesOccEnv :: TidyOccEnv -> [OccName] -> TidyOccEnv
avoidClashesOccEnv TidyOccEnv
env [OccName]
occs = forall {elt}.
Num elt =>
UniqFM FastString elt
-> UniqFM FastString () -> [OccName] -> UniqFM FastString elt
go TidyOccEnv
env forall key elt. UniqFM key elt
emptyUFM [OccName]
occs
where
go :: UniqFM FastString elt
-> UniqFM FastString () -> [OccName] -> UniqFM FastString elt
go UniqFM FastString elt
env UniqFM FastString ()
_ [] = UniqFM FastString elt
env
go UniqFM FastString elt
env UniqFM FastString ()
seenOnce ((OccName NameSpace
_ FastString
fs):[OccName]
occs)
| FastString
fs forall key elt. Uniquable key => key -> UniqFM key elt -> Bool
`elemUFM` UniqFM FastString elt
env = UniqFM FastString elt
-> UniqFM FastString () -> [OccName] -> UniqFM FastString elt
go UniqFM FastString elt
env UniqFM FastString ()
seenOnce [OccName]
occs
| FastString
fs forall key elt. Uniquable key => key -> UniqFM key elt -> Bool
`elemUFM` UniqFM FastString ()
seenOnce = UniqFM FastString elt
-> UniqFM FastString () -> [OccName] -> UniqFM FastString elt
go (forall key elt.
Uniquable key =>
UniqFM key elt -> key -> elt -> UniqFM key elt
addToUFM UniqFM FastString elt
env FastString
fs elt
1) UniqFM FastString ()
seenOnce [OccName]
occs
| Bool
otherwise = UniqFM FastString elt
-> UniqFM FastString () -> [OccName] -> UniqFM FastString elt
go UniqFM FastString elt
env (forall key elt.
Uniquable key =>
UniqFM key elt -> key -> elt -> UniqFM key elt
addToUFM UniqFM FastString ()
seenOnce FastString
fs ()) [OccName]
occs
tidyOccName :: TidyOccEnv -> OccName -> (TidyOccEnv, OccName)
tidyOccName :: TidyOccEnv -> OccName -> (TidyOccEnv, OccName)
tidyOccName TidyOccEnv
env occ :: OccName
occ@(OccName NameSpace
occ_sp FastString
fs)
| Bool -> Bool
not (FastString
fs forall key elt. Uniquable key => key -> UniqFM key elt -> Bool
`elemUFM` TidyOccEnv
env)
=
(forall key elt.
Uniquable key =>
UniqFM key elt -> key -> elt -> UniqFM key elt
addToUFM TidyOccEnv
env FastString
fs Int
1, OccName
occ)
| Bool
otherwise
= case forall key elt. Uniquable key => UniqFM key elt -> key -> Maybe elt
lookupUFM TidyOccEnv
env FastString
base1 of
Maybe Int
Nothing -> (forall key elt.
Uniquable key =>
UniqFM key elt -> key -> elt -> UniqFM key elt
addToUFM TidyOccEnv
env FastString
base1 Int
2, NameSpace -> FastString -> OccName
OccName NameSpace
occ_sp FastString
base1)
Just Int
n -> Int -> Int -> (TidyOccEnv, OccName)
find Int
1 Int
n
where
base :: String
base :: [Char]
base = forall a. (a -> Bool) -> [a] -> [a]
dropWhileEndLE Char -> Bool
isDigit (FastString -> [Char]
unpackFS FastString
fs)
base1 :: FastString
base1 = [Char] -> FastString
mkFastString ([Char]
base forall a. [a] -> [a] -> [a]
++ [Char]
"1")
find :: Int -> Int -> (TidyOccEnv, OccName)
find !Int
k !Int
n
= case forall key elt. Uniquable key => key -> UniqFM key elt -> Bool
elemUFM FastString
new_fs TidyOccEnv
env of
Bool
True -> Int -> Int -> (TidyOccEnv, OccName)
find (Int
kforall a. Num a => a -> a -> a
+Int
1 :: Int) (Int
nforall a. Num a => a -> a -> a
+Int
k)
Bool
False -> (TidyOccEnv
new_env, NameSpace -> FastString -> OccName
OccName NameSpace
occ_sp FastString
new_fs)
where
new_fs :: FastString
new_fs = [Char] -> FastString
mkFastString ([Char]
base forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show Int
n)
new_env :: TidyOccEnv
new_env = forall key elt.
Uniquable key =>
UniqFM key elt -> key -> elt -> UniqFM key elt
addToUFM (forall key elt.
Uniquable key =>
UniqFM key elt -> key -> elt -> UniqFM key elt
addToUFM TidyOccEnv
env FastString
new_fs Int
1) FastString
base1 (Int
nforall a. Num a => a -> a -> a
+Int
1)
instance Binary NameSpace where
put_ :: BinHandle -> NameSpace -> IO ()
put_ BinHandle
bh NameSpace
VarName =
BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
0
put_ BinHandle
bh NameSpace
DataName =
BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
1
put_ BinHandle
bh NameSpace
TvName =
BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
2
put_ BinHandle
bh NameSpace
TcClsName =
BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
3
get :: BinHandle -> IO NameSpace
get BinHandle
bh = do
Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
case Word8
h of
Word8
0 -> forall (m :: * -> *) a. Monad m => a -> m a
return NameSpace
VarName
Word8
1 -> forall (m :: * -> *) a. Monad m => a -> m a
return NameSpace
DataName
Word8
2 -> forall (m :: * -> *) a. Monad m => a -> m a
return NameSpace
TvName
Word8
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return NameSpace
TcClsName
instance Binary OccName where
put_ :: BinHandle -> OccName -> IO ()
put_ BinHandle
bh (OccName NameSpace
aa FastString
ab) = do
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh NameSpace
aa
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh FastString
ab
get :: BinHandle -> IO OccName
get BinHandle
bh = do
NameSpace
aa <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
FastString
ab <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
forall (m :: * -> *) a. Monad m => a -> m a
return (NameSpace -> FastString -> OccName
OccName NameSpace
aa FastString
ab)