module GHC.Types.Fixity.Env
( FixityEnv
, FixItem (..)
, emptyFixityEnv
, lookupFixity
, mkIfaceFixCache
, emptyIfaceFixCache
)
where
import GHC.Prelude
import GHC.Types.Fixity
import GHC.Types.Name
import GHC.Types.Name.Env
import GHC.Utils.Outputable
type FixityEnv = NameEnv FixItem
data FixItem = FixItem OccName Fixity
instance Outputable FixItem where
ppr :: FixItem -> SDoc
ppr (FixItem OccName
occ Fixity
fix) = forall a. Outputable a => a -> SDoc
ppr Fixity
fix SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr OccName
occ
emptyFixityEnv :: FixityEnv
emptyFixityEnv :: FixityEnv
emptyFixityEnv = forall a. NameEnv a
emptyNameEnv
lookupFixity :: FixityEnv -> Name -> Fixity
lookupFixity :: FixityEnv -> Name -> Fixity
lookupFixity FixityEnv
env Name
n = case forall a. NameEnv a -> Name -> Maybe a
lookupNameEnv FixityEnv
env Name
n of
Just (FixItem OccName
_ Fixity
fix) -> Fixity
fix
Maybe FixItem
Nothing -> Fixity
defaultFixity
mkIfaceFixCache :: [(OccName, Fixity)] -> OccName -> Maybe Fixity
mkIfaceFixCache :: [(OccName, Fixity)] -> OccName -> Maybe Fixity
mkIfaceFixCache [(OccName, Fixity)]
pairs
= \OccName
n -> forall a. OccEnv a -> OccName -> Maybe a
lookupOccEnv OccEnv Fixity
env OccName
n
where
env :: OccEnv Fixity
env = forall a. [(OccName, a)] -> OccEnv a
mkOccEnv [(OccName, Fixity)]
pairs
emptyIfaceFixCache :: OccName -> Maybe Fixity
emptyIfaceFixCache :: OccName -> Maybe Fixity
emptyIfaceFixCache OccName
_ = forall a. Maybe a
Nothing