{-# LANGUAGE CPP #-}
module GHC.SourceGen.Binds
(
HsBind'
, HasValBind
, typeSig
, typeSigs
, funBind
, funBinds
, funBindsWithFixity
, valBind
, valBindGRHSs
, HasPatBind
, patBind
, patBindGRHSs
, RawMatch
, match
, matchGRHSs
, RawGRHSs
, rhs
, guardedRhs
, GuardedExpr
, GRHS'
, guards
, guard
, where'
, RawValBind
, stmt
, (<--)
) where
#if MIN_VERSION_ghc(9,0,0)
import GHC (LexicalFixity(..))
#else
import GHC.Types.Basic (LexicalFixity(..))
#endif
import Data.Bool (bool)
import Data.Maybe (fromMaybe)
import GHC.Hs.Binds
import GHC.Hs.Expr
import GHC.Hs.Type
import GHC.Plugins (isSymOcc)
#if !MIN_VERSION_ghc(9,0,1)
import GHC.Tc.Types.Evidence (HsWrapper(WpHole))
#endif
import GHC.SourceGen.Binds.Internal
import GHC.SourceGen.Name
import GHC.SourceGen.Name.Internal
import GHC.SourceGen.Syntax.Internal
import GHC.SourceGen.Type.Internal (sigWcType)
typeSigs :: HasValBind t => [OccNameStr] -> HsType' -> t
typeSigs :: forall t. HasValBind t => [OccNameStr] -> HsType' -> t
typeSigs [OccNameStr]
names HsType'
t =
forall t. HasValBind t => Sig' -> t
sigB forall a b. (a -> b) -> a -> b
$ forall ann a. (EpAnn ann -> a) -> a
withEpAnnNotUsed forall pass.
XTypeSig pass -> [LIdP pass] -> LHsSigWcType pass -> Sig pass
TypeSig (forall a b. (a -> b) -> [a] -> [b]
map (RdrNameStr -> LocatedN RdrName
typeRdrName forall b c a. (b -> c) -> (a -> b) -> a -> c
. OccNameStr -> RdrNameStr
unqual) [OccNameStr]
names)
forall a b. (a -> b) -> a -> b
$ HsType' -> LHsSigWcType'
sigWcType HsType'
t
typeSig :: HasValBind t => OccNameStr -> HsType' -> t
typeSig :: forall t. HasValBind t => OccNameStr -> HsType' -> t
typeSig OccNameStr
n = forall t. HasValBind t => [OccNameStr] -> HsType' -> t
typeSigs [OccNameStr
n]
funBindsWithFixity :: HasValBind t => Maybe LexicalFixity -> OccNameStr -> [RawMatch] -> t
funBindsWithFixity :: forall t.
HasValBind t =>
Maybe LexicalFixity -> OccNameStr -> [RawMatch] -> t
funBindsWithFixity Maybe LexicalFixity
fixity OccNameStr
name [RawMatch]
matches = forall t. HasValBind t => HsBind' -> t
bindB forall a b. (a -> b) -> a -> b
$ forall a. a -> a
withPlaceHolder
(forall a. (NoExtField -> a) -> a
noExt forall idL idR.
XFunBind idL idR
-> LIdP idL
-> MatchGroup idR (LHsExpr idR)
-> [CoreTickish]
-> HsBindLR idL idR
FunBind LocatedN RdrName
name'
(HsMatchContext' -> [RawMatch] -> MatchGroup' LHsExpr'
matchGroup HsMatchContext'
context [RawMatch]
matches)
#if !MIN_VERSION_ghc(9,0,1)
WpHole
#endif
)
#if !MIN_VERSION_ghc(9,6,0)
[]
#endif
where
name' :: LocatedN RdrName
name' = RdrNameStr -> LocatedN RdrName
valueRdrName forall a b. (a -> b) -> a -> b
$ OccNameStr -> RdrNameStr
unqual OccNameStr
name
occ :: OccName
occ = OccNameStr -> OccName
valueOccName OccNameStr
name
fixity' :: LexicalFixity
fixity' = forall a. a -> Maybe a -> a
fromMaybe (forall a. a -> a -> Bool -> a
bool LexicalFixity
Prefix LexicalFixity
Infix forall a b. (a -> b) -> a -> b
$ OccName -> Bool
isSymOcc OccName
occ) Maybe LexicalFixity
fixity
context :: HsMatchContext'
context = forall p.
LIdP p -> LexicalFixity -> SrcStrictness -> HsMatchContext p
FunRhs LocatedN RdrName
name' LexicalFixity
fixity' SrcStrictness
NoSrcStrict
funBinds :: HasValBind t => OccNameStr -> [RawMatch] -> t
funBinds :: forall t. HasValBind t => OccNameStr -> [RawMatch] -> t
funBinds = forall t.
HasValBind t =>
Maybe LexicalFixity -> OccNameStr -> [RawMatch] -> t
funBindsWithFixity (forall a. a -> Maybe a
Just LexicalFixity
Prefix)
funBind :: HasValBind t => OccNameStr -> RawMatch -> t
funBind :: forall t. HasValBind t => OccNameStr -> RawMatch -> t
funBind OccNameStr
name RawMatch
m = forall t. HasValBind t => OccNameStr -> [RawMatch] -> t
funBinds OccNameStr
name [RawMatch
m]
valBindGRHSs :: HasValBind t => OccNameStr -> RawGRHSs -> t
valBindGRHSs :: forall t. HasValBind t => OccNameStr -> RawGRHSs -> t
valBindGRHSs OccNameStr
name = forall t. HasValBind t => OccNameStr -> RawMatch -> t
funBind OccNameStr
name forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Pat'] -> RawGRHSs -> RawMatch
matchGRHSs []
valBind :: HasValBind t => OccNameStr -> HsExpr' -> t
valBind :: forall t. HasValBind t => OccNameStr -> HsExpr' -> t
valBind OccNameStr
name = forall t. HasValBind t => OccNameStr -> RawGRHSs -> t
valBindGRHSs OccNameStr
name forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsExpr' -> RawGRHSs
rhs
patBindGRHSs :: HasPatBind t => Pat' -> RawGRHSs -> t
patBindGRHSs :: forall t. HasPatBind t => Pat' -> RawGRHSs -> t
patBindGRHSs Pat'
p RawGRHSs
g =
forall t. HasValBind t => HsBind' -> t
bindB
forall a b. (a -> b) -> a -> b
$ forall a. a -> a
withPlaceHolder
(forall a. a -> a
withPlaceHolder
(forall ann a. (EpAnn ann -> a) -> a
withEpAnnNotUsed forall idL idR.
XPatBind idL idR
-> LPat idL
-> GRHSs idR (LHsExpr idR)
-> ([CoreTickish], [[CoreTickish]])
-> HsBindLR idL idR
PatBind (Pat' -> LPat'
builtPat Pat'
p) (RawGRHSs -> GRHSs' LHsExpr'
mkGRHSs RawGRHSs
g)))
#if !MIN_VERSION_ghc(9,6,0)
forall a b. (a -> b) -> a -> b
$ ([],[])
#endif
patBind :: HasPatBind t => Pat' -> HsExpr' -> t
patBind :: forall t. HasPatBind t => Pat' -> HsExpr' -> t
patBind Pat'
p = forall t. HasPatBind t => Pat' -> RawGRHSs -> t
patBindGRHSs Pat'
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsExpr' -> RawGRHSs
rhs
matchGRHSs :: [Pat'] -> RawGRHSs -> RawMatch
matchGRHSs :: [Pat'] -> RawGRHSs -> RawMatch
matchGRHSs = [Pat'] -> RawGRHSs -> RawMatch
RawMatch
match :: [Pat'] -> HsExpr' -> RawMatch
match :: [Pat'] -> HsExpr' -> RawMatch
match [Pat']
ps = [Pat'] -> RawGRHSs -> RawMatch
matchGRHSs [Pat']
ps forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsExpr' -> RawGRHSs
rhs
where' :: RawGRHSs -> [RawValBind] -> RawGRHSs
where' :: RawGRHSs -> [RawValBind] -> RawGRHSs
where' RawGRHSs
r [RawValBind]
vbs = RawGRHSs
r { rawGRHSWhere :: [RawValBind]
rawGRHSWhere = RawGRHSs -> [RawValBind]
rawGRHSWhere RawGRHSs
r forall a. [a] -> [a] -> [a]
++ [RawValBind]
vbs }
rhs :: HsExpr' -> RawGRHSs
rhs :: HsExpr' -> RawGRHSs
rhs HsExpr'
e = [GuardedExpr] -> RawGRHSs
guardedRhs [[Stmt'] -> HsExpr' -> GuardedExpr
guards [] HsExpr'
e]
guardedRhs :: [GuardedExpr] -> RawGRHSs
guardedRhs :: [GuardedExpr] -> RawGRHSs
guardedRhs [GuardedExpr]
ss = [GuardedExpr] -> [RawValBind] -> RawGRHSs
RawGRHSs [GuardedExpr]
ss []
guard :: HsExpr' -> HsExpr' -> GuardedExpr
guard :: HsExpr' -> HsExpr' -> GuardedExpr
guard HsExpr'
s = [Stmt'] -> HsExpr' -> GuardedExpr
guards [HsExpr' -> Stmt'
stmt HsExpr'
s]
guards :: [Stmt'] -> HsExpr' -> GuardedExpr
guards :: [Stmt'] -> HsExpr' -> GuardedExpr
guards [Stmt']
stmts HsExpr'
e = forall ann a. (EpAnn ann -> a) -> a
withEpAnnNotUsed forall p body.
XCGRHS p body -> [GuardLStmt p] -> body -> GRHS p body
GRHS (forall a b. (a -> b) -> [a] -> [b]
map forall a ann. a -> GenLocated (SrcSpanAnn ann) a
mkLocated [Stmt']
stmts) (forall a ann. a -> GenLocated (SrcSpanAnn ann) a
mkLocated HsExpr'
e)
stmt :: HsExpr' -> Stmt'
stmt :: HsExpr' -> Stmt'
stmt HsExpr'
e =
forall a. a -> a
withPlaceHolder forall a b. (a -> b) -> a -> b
$ forall a. (NoExtField -> a) -> a
noExt forall idL idR body.
XBodyStmt idL idR body
-> body -> SyntaxExpr idR -> SyntaxExpr idR -> StmtLR idL idR body
BodyStmt (forall a ann. a -> GenLocated (SrcSpanAnn ann) a
mkLocated HsExpr'
e) forall (p :: Pass). IsPass p => SyntaxExpr (GhcPass p)
noSyntaxExpr forall (p :: Pass). IsPass p => SyntaxExpr (GhcPass p)
noSyntaxExpr
(<--) :: Pat' -> HsExpr' -> Stmt'
Pat'
p <-- :: Pat' -> HsExpr' -> Stmt'
<-- HsExpr'
e = forall a. a -> a
withPlaceHolder forall a b. (a -> b) -> a -> b
$ forall ann a. (EpAnn ann -> a) -> a
withEpAnnNotUsed forall idL idR body.
XBindStmt idL idR body -> LPat idL -> body -> StmtLR idL idR body
BindStmt (Pat' -> LPat'
builtPat Pat'
p) (forall a ann. a -> GenLocated (SrcSpanAnn ann) a
mkLocated HsExpr'
e)
#if !MIN_VERSION_ghc(9,0,0)
noSyntaxExpr noSyntaxExpr
#endif
infixl 1 <--
class HasValBind t => HasPatBind t where
instance HasPatBind RawValBind where
instance HasPatBind HsDecl' where