{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
module GHC.Tc.Types.TH (
SpliceType(..)
, SpliceOrBracket(..)
, ThLevel(.., TypedBrack, UntypedBrack)
, PendingStuff(..)
, ThLevelIndex
, topLevel
, topAnnLevel
, topSpliceLevel
, thLevelIndex
, topLevelIndex
, spliceLevelIndex
, quoteLevelIndex
, thLevelIndexFromImportLevel
) where
import GHC.Prelude
import GHCi.RemoteTypes
import qualified GHC.Boot.TH.Syntax as TH
import GHC.Tc.Types.Evidence
import GHC.Utils.Outputable
import GHC.Tc.Types.TcRef
import GHC.Tc.Types.Constraint
import GHC.Hs.Expr ( PendingTcSplice, PendingRnSplice )
import GHC.Types.ThLevelIndex
data SpliceType = Typed | Untyped
data SpliceOrBracket = IsSplice | IsBracket
data ThLevel
= Splice SpliceType ThLevel
| RunSplice (TcRef [ForeignRef (TH.Q ())])
| Comp
| Brack
ThLevel
PendingStuff
data PendingStuff
= RnPending
(TcRef [PendingRnSplice])
| RnPendingTyped
| TcPending
(TcRef [PendingTcSplice])
(TcRef WantedConstraints)
QuoteWrapper
isTypedPending :: PendingStuff -> Bool
isTypedPending :: PendingStuff -> Bool
isTypedPending (RnPending TcRef [PendingRnSplice]
_) = Bool
False
isTypedPending (PendingStuff
RnPendingTyped) = Bool
True
isTypedPending (TcPending TcRef [PendingTcSplice]
_ TcRef WantedConstraints
_ QuoteWrapper
_) = Bool
True
pattern UntypedBrack :: ThLevel -> TcRef [PendingRnSplice] -> ThLevel
pattern $mUntypedBrack :: forall {r}.
ThLevel
-> (ThLevel -> TcRef [PendingRnSplice] -> r) -> ((# #) -> r) -> r
$bUntypedBrack :: ThLevel -> TcRef [PendingRnSplice] -> ThLevel
UntypedBrack lvl tc_ref = Brack lvl (RnPending tc_ref)
pattern TypedBrack :: ThLevel -> ThLevel
pattern $mTypedBrack :: forall {r}. ThLevel -> (ThLevel -> r) -> ((# #) -> r) -> r
TypedBrack lvl <- Brack lvl (isTypedPending -> True)
topLevel, topAnnLevel, topSpliceLevel :: ThLevel
topLevel :: ThLevel
topLevel = ThLevel
Comp
topAnnLevel :: ThLevel
topAnnLevel = SpliceType -> ThLevel -> ThLevel
Splice SpliceType
Untyped ThLevel
Comp
topSpliceLevel :: ThLevel
topSpliceLevel = SpliceType -> ThLevel -> ThLevel
Splice SpliceType
Untyped ThLevel
Comp
instance Outputable ThLevel where
ppr :: ThLevel -> SDoc
ppr (Splice SpliceType
_ ThLevel
s) = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Splice" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens (ThLevel -> SDoc
forall a. Outputable a => a -> SDoc
ppr ThLevel
s)
ppr (RunSplice TcRef [ForeignRef (Q ())]
_) = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"RunSplice"
ppr ThLevel
Comp = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Comp"
ppr (Brack ThLevel
s PendingStuff
_) = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Brack" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens (ThLevel -> SDoc
forall a. Outputable a => a -> SDoc
ppr ThLevel
s)
thLevelIndex :: ThLevel -> ThLevelIndex
thLevelIndex :: ThLevel -> ThLevelIndex
thLevelIndex (Splice SpliceType
_ ThLevel
s) = ThLevelIndex -> ThLevelIndex
decThLevelIndex (ThLevel -> ThLevelIndex
thLevelIndex ThLevel
s)
thLevelIndex ThLevel
Comp = ThLevelIndex
topLevelIndex
thLevelIndex (Brack ThLevel
s PendingStuff
_) = ThLevelIndex -> ThLevelIndex
incThLevelIndex (ThLevel -> ThLevelIndex
thLevelIndex ThLevel
s)
thLevelIndex (RunSplice TcRef [ForeignRef (Q ())]
_) = ThLevel -> ThLevelIndex
thLevelIndex (SpliceType -> ThLevel -> ThLevel
Splice SpliceType
Untyped ThLevel
Comp)