{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}

module Skeletest.Internal.GHC.Compat_9_10 (
  module Skeletest.Internal.GHC.Compat_9_10,
) where

import Data.Data (toConstr)
import GHC hiding (FieldOcc (..), mkPrefixFunRhs)
import GHC qualified
import GHC.Types.Name.Reader (getRdrName)

import Skeletest.Internal.Error (invariantViolation)

hsLamSingle :: MatchGroup (GhcPass p) (LHsExpr (GhcPass p)) -> HsExpr (GhcPass p)
hsLamSingle :: forall (p :: Pass).
MatchGroup (GhcPass p) (LHsExpr (GhcPass p)) -> HsExpr (GhcPass p)
hsLamSingle = XLam (GhcPass p)
-> HsLamVariant
-> MatchGroup (GhcPass p) (LHsExpr (GhcPass p))
-> HsExpr (GhcPass p)
forall p.
XLam p -> HsLamVariant -> MatchGroup p (LHsExpr p) -> HsExpr p
HsLam [AddEpAnn]
XLam (GhcPass p)
forall a. NoAnn a => a
noAnn HsLamVariant
LamSingle

lamAltSingle :: HsMatchContext fn
lamAltSingle :: forall fn. HsMatchContext fn
lamAltSingle = HsLamVariant -> HsMatchContext fn
forall fn. HsLamVariant -> HsMatchContext fn
LamAlt HsLamVariant
LamSingle

hsLit :: HsLit (GhcPass p) -> HsExpr (GhcPass p)
hsLit :: forall (p :: Pass). HsLit (GhcPass p) -> HsExpr (GhcPass p)
hsLit = XLitE (GhcPass p) -> HsLit (GhcPass p) -> HsExpr (GhcPass p)
forall p. XLitE p -> HsLit p -> HsExpr p
HsLit XLitE (GhcPass p)
NoExtField
noExtField

hsPar :: forall p. (IsPass p) => LHsExpr (GhcPass p) -> HsExpr (GhcPass p)
hsPar :: forall (p :: Pass).
IsPass p =>
LHsExpr (GhcPass p) -> HsExpr (GhcPass p)
hsPar =
  XPar (GhcPass p) -> LHsExpr (GhcPass p) -> HsExpr (GhcPass p)
forall p. XPar p -> LHsExpr p -> HsExpr p
HsPar (XPar (GhcPass p) -> LHsExpr (GhcPass p) -> HsExpr (GhcPass p))
-> XPar (GhcPass p) -> LHsExpr (GhcPass p) -> HsExpr (GhcPass p)
forall a b. (a -> b) -> a -> b
$
    case forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p of
      GhcPass p
GhcPs -> (EpToken "(", EpToken ")")
XPar (GhcPass p)
forall a. NoAnn a => a
noAnn
      GhcPass p
GhcRn -> XPar (GhcPass p)
NoExtField
noExtField
      GhcPass p
GhcTc -> String -> NoExtField
forall a. String -> a
invariantViolation String
"hsPar called in GhcTc"

unHsPar :: HsExpr GhcRn -> LHsExpr GhcRn
unHsPar :: HsExpr GhcRn -> LHsExpr GhcRn
unHsPar = \case
  HsPar XPar GhcRn
_ LHsExpr GhcRn
e -> LHsExpr GhcRn
e
  HsExpr GhcRn
e -> String -> LHsExpr GhcRn
forall a. String -> a
invariantViolation (String -> LHsExpr GhcRn) -> String -> LHsExpr GhcRn
forall a b. (a -> b) -> a -> b
$ String
"unHsPar called on " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> (Constr -> String
forall a. Show a => a -> String
show (Constr -> String)
-> (HsExpr GhcRn -> Constr) -> HsExpr GhcRn -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsExpr GhcRn -> Constr
forall a. Data a => a -> Constr
toConstr) HsExpr GhcRn
e

hsTupPresent :: LHsExpr (GhcPass p) -> HsTupArg (GhcPass p)
hsTupPresent :: forall (p :: Pass). LHsExpr (GhcPass p) -> HsTupArg (GhcPass p)
hsTupPresent = XPresent (GhcPass p) -> LHsExpr (GhcPass p) -> HsTupArg (GhcPass p)
forall id. XPresent id -> LHsExpr id -> HsTupArg id
Present XPresent (GhcPass p)
NoExtField
noExtField

xMatch :: XCMatch (GhcPass p) b
xMatch :: forall (p :: Pass) b. XCMatch (GhcPass p) b
xMatch = [AddEpAnn]
XCMatch (GhcPass p) b
forall a. NoAnn a => a
noAnn

mkHsRecFields :: [LHsRecField (GhcPass p) arg] -> HsRecFields (GhcPass p) arg
mkHsRecFields :: forall (p :: Pass) arg.
[LHsRecField (GhcPass p) arg] -> HsRecFields (GhcPass p) arg
mkHsRecFields [LHsRecField (GhcPass p) arg]
fields =
  GHC.HsRecFields
    { rec_flds :: [LHsRecField (GhcPass p) arg]
rec_flds = [LHsRecField (GhcPass p) arg]
fields
    , rec_dotdot :: Maybe (XRec (GhcPass p) RecFieldsDotDot)
rec_dotdot = Maybe (XRec (GhcPass p) RecFieldsDotDot)
Maybe (GenLocated EpaLocation RecFieldsDotDot)
forall a. Maybe a
Nothing
    }

foLabel :: GHC.FieldOcc GhcRn -> LIdP GhcRn
foLabel :: FieldOcc GhcRn -> LIdP GhcRn
foLabel = Name -> GenLocated SrcSpanAnnN Name
forall ann e. NoAnn ann => e -> GenLocated ann e
genLoc (Name -> GenLocated SrcSpanAnnN Name)
-> (FieldOcc GhcRn -> Name)
-> FieldOcc GhcRn
-> GenLocated SrcSpanAnnN Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FieldOcc GhcRn -> XCFieldOcc GhcRn
FieldOcc GhcRn -> Name
forall pass. FieldOcc pass -> XCFieldOcc pass
GHC.foExt

fieldOccRn :: Name -> GHC.FieldOcc GhcRn
fieldOccRn :: Name -> FieldOcc GhcRn
fieldOccRn Name
name =
  GHC.FieldOcc
    { foExt :: XCFieldOcc GhcRn
GHC.foExt = XCFieldOcc GhcRn
Name
name
    , foLabel :: XRec GhcRn RdrName
GHC.foLabel = RdrName -> GenLocated SrcSpanAnnN RdrName
forall ann e. NoAnn ann => e -> GenLocated ann e
genLoc (RdrName -> GenLocated SrcSpanAnnN RdrName)
-> RdrName -> GenLocated SrcSpanAnnN RdrName
forall a b. (a -> b) -> a -> b
$ Name -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName Name
name
    }

hsApp :: LHsExpr (GhcPass p) -> LHsExpr (GhcPass p) -> HsExpr (GhcPass p)
hsApp :: forall (p :: Pass).
LHsExpr (GhcPass p) -> LHsExpr (GhcPass p) -> HsExpr (GhcPass p)
hsApp = XApp (GhcPass p)
-> LHsExpr (GhcPass p) -> LHsExpr (GhcPass p) -> HsExpr (GhcPass p)
forall p. XApp p -> LHsExpr p -> LHsExpr p -> HsExpr p
HsApp XApp (GhcPass p)
NoExtField
noExtField

genLoc :: (NoAnn ann) => e -> GenLocated ann e
genLoc :: forall ann e. NoAnn ann => e -> GenLocated ann e
genLoc = ann -> e -> GenLocated ann e
forall l e. l -> e -> GenLocated l e
L ann
forall a. NoAnn a => a
noAnn

mkPrefixFunRhs :: fn -> [ann] -> HsMatchContext fn
mkPrefixFunRhs :: forall fn ann. fn -> [ann] -> HsMatchContext fn
mkPrefixFunRhs fn
fn [ann]
_ = fn -> HsMatchContext fn
forall fn. fn -> HsMatchContext fn
GHC.mkPrefixFunRhs fn
fn

toMatchArgs :: [LPat p] -> [LPat p]
toMatchArgs :: forall p. [LPat p] -> [LPat p]
toMatchArgs = [XRec p (Pat p)] -> [XRec p (Pat p)]
forall a. a -> a
id