{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE DataKinds #-}
module GHC.Parser.PostProcess (
mkRdrGetField, mkRdrProjection, Fbind,
mkHsOpApp,
mkHsIntegral, mkHsFractional, mkHsIsString,
mkHsDo, mkSpliceDecl,
mkRoleAnnotDecl,
mkClassDecl,
mkTyData, mkDataFamInst,
mkTySynonym, mkTyFamInstEqn,
mkStandaloneKindSig,
mkTyFamInst,
mkFamDecl,
mkInlinePragma,
mkOpaquePragma,
mkPatSynMatchGroup,
mkRecConstrOrUpdate,
mkTyClD, mkInstD,
mkRdrRecordCon, mkRdrRecordUpd,
setRdrNameSpace,
fromSpecTyVarBndr, fromSpecTyVarBndrs,
annBinds,
fixValbindsAnn,
stmtsAnchor, stmtsLoc,
cvBindGroup,
cvBindsAndSigs,
cvTopDecls,
placeHolderPunRhs,
mkImport,
parseCImport,
mkExport,
mkExtName,
mkGadtDecl,
mkConDeclH98,
checkImportDecl,
checkExpBlockArguments, checkCmdBlockArguments,
checkPrecP,
checkContext,
checkPattern,
checkPattern_details,
incompleteDoBlock,
ParseContext(..),
checkMonadComp,
checkValDef,
checkValSigLhs,
LRuleTyTmVar, RuleTyTmVar(..),
mkRuleBndrs, mkRuleTyVarBndrs,
checkRuleTyVarBndrNames,
checkRecordSyntax,
checkEmptyGADTs,
addFatalError, hintBangPat,
mkBangTy,
UnpackednessPragma(..),
mkMultTy,
mkTokenLocation,
ImpExpSubSpec(..),
ImpExpQcSpec(..),
mkModuleImpExp,
mkTypeImpExp,
mkImpExpSubSpec,
checkImportSpec,
starSym,
warnStarIsType,
warnPrepositiveQualifiedModule,
failOpFewArgs,
failNotEnabledImportQualifiedPost,
failImportQualifiedTwice,
SumOrTuple (..),
PV,
runPV,
ECP(ECP, unECP),
DisambInfixOp(..),
DisambECP(..),
ecpFromExp,
ecpFromCmd,
PatBuilder,
DisambTD(..),
addUnpackednessP,
dataConBuilderCon,
dataConBuilderDetails,
) where
import GHC.Prelude
import GHC.Hs
import GHC.Core.TyCon ( TyCon, isTupleTyCon, tyConSingleDataCon_maybe )
import GHC.Core.DataCon ( DataCon, dataConTyCon )
import GHC.Core.ConLike ( ConLike(..) )
import GHC.Core.Coercion.Axiom ( Role, fsFromRole )
import GHC.Types.Name.Reader
import GHC.Types.Name
import GHC.Types.Basic
import GHC.Types.Error
import GHC.Types.Fixity
import GHC.Types.Hint
import GHC.Types.SourceText
import GHC.Parser.Types
import GHC.Parser.Lexer
import GHC.Parser.Errors.Types
import GHC.Parser.Errors.Ppr ()
import GHC.Utils.Lexeme ( okConOcc )
import GHC.Types.TyThing
import GHC.Core.Type ( Specificity(..) )
import GHC.Builtin.Types( cTupleTyConName, tupleTyCon, tupleDataCon,
nilDataConName, nilDataConKey,
listTyConName, listTyConKey,
unrestrictedFunTyCon )
import GHC.Types.ForeignCall
import GHC.Types.SrcLoc
import GHC.Types.Unique ( hasKey )
import GHC.Data.OrdList
import GHC.Utils.Outputable as Outputable
import GHC.Data.FastString
import GHC.Data.Maybe
import GHC.Utils.Error
import GHC.Utils.Misc
import Data.Either
import Data.List ( findIndex )
import Data.Foldable
import qualified Data.Semigroup as Semi
import GHC.Utils.Panic
import GHC.Utils.Panic.Plain
import qualified GHC.Data.Strict as Strict
import Language.Haskell.Syntax.Basic (FieldLabelString(..))
import Control.Monad
import Text.ParserCombinators.ReadP as ReadP
import Data.Char
import Data.Data ( dataTypeOf, fromConstr, dataTypeConstrs )
import Data.Kind ( Type )
import Data.List.NonEmpty (NonEmpty)
mkTyClD :: LTyClDecl (GhcPass p) -> LHsDecl (GhcPass p)
mkTyClD :: forall (p :: Pass). LTyClDecl (GhcPass p) -> LHsDecl (GhcPass p)
mkTyClD (L SrcSpanAnnA
loc TyClDecl (GhcPass p)
d) = forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc (forall p. XTyClD p -> TyClDecl p -> HsDecl p
TyClD NoExtField
noExtField TyClDecl (GhcPass p)
d)
mkInstD :: LInstDecl (GhcPass p) -> LHsDecl (GhcPass p)
mkInstD :: forall (p :: Pass). LInstDecl (GhcPass p) -> LHsDecl (GhcPass p)
mkInstD (L SrcSpanAnnA
loc InstDecl (GhcPass p)
d) = forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc (forall p. XInstD p -> InstDecl p -> HsDecl p
InstD NoExtField
noExtField InstDecl (GhcPass p)
d)
mkClassDecl :: SrcSpan
-> Located (Maybe (LHsContext GhcPs), LHsType GhcPs)
-> Located (a,[LHsFunDep GhcPs])
-> OrdList (LHsDecl GhcPs)
-> LayoutInfo GhcPs
-> [AddEpAnn]
-> P (LTyClDecl GhcPs)
mkClassDecl :: forall a.
SrcSpan
-> Located (Maybe (LHsContext GhcPs), LHsType GhcPs)
-> Located (a, [LHsFunDep GhcPs])
-> OrdList (LHsDecl GhcPs)
-> LayoutInfo GhcPs
-> [AddEpAnn]
-> P (LTyClDecl GhcPs)
mkClassDecl SrcSpan
loc' (L SrcSpan
_ (Maybe (LHsContext GhcPs)
mcxt, LHsType GhcPs
tycl_hdr)) Located (a, [LHsFunDep GhcPs])
fds OrdList (LHsDecl GhcPs)
where_cls LayoutInfo GhcPs
layoutInfo [AddEpAnn]
annsIn
= do { let loc :: SrcSpanAnnA
loc = forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
loc'
; (Bag (GenLocated SrcSpanAnnA (HsBindLR GhcPs GhcPs))
binds, [GenLocated SrcSpanAnnA (Sig GhcPs)]
sigs, [GenLocated SrcSpanAnnA (FamilyDecl GhcPs)]
ats, [GenLocated SrcSpanAnnA (TyFamInstDecl GhcPs)]
at_defs, [GenLocated SrcSpanAnnA (DataFamInstDecl GhcPs)]
_, [GenLocated SrcSpanAnnA (DocDecl GhcPs)]
docs) <- OrdList (LHsDecl GhcPs)
-> P (LHsBinds GhcPs, [LSig GhcPs], [LFamilyDecl GhcPs],
[LTyFamInstDecl GhcPs], [LDataFamInstDecl GhcPs], [LDocDecl GhcPs])
cvBindsAndSigs OrdList (LHsDecl GhcPs)
where_cls
; (GenLocated SrcSpanAnnN RdrName
cls, [HsArg
(GenLocated SrcSpanAnnA (HsType GhcPs))
(GenLocated SrcSpanAnnA (HsType GhcPs))]
tparams, LexicalFixity
fixity, [AddEpAnn]
ann) <- Bool
-> LHsType GhcPs
-> P (GenLocated SrcSpanAnnN RdrName, [LHsTypeArg GhcPs],
LexicalFixity, [AddEpAnn])
checkTyClHdr Bool
True LHsType GhcPs
tycl_hdr
; LHsQTyVars GhcPs
tyvars <- SDoc
-> SDoc
-> GenLocated SrcSpanAnnN RdrName
-> [LHsTypeArg GhcPs]
-> P (LHsQTyVars GhcPs)
checkTyVars (forall doc. IsLine doc => String -> doc
text String
"class") SDoc
whereDots GenLocated SrcSpanAnnN RdrName
cls [HsArg
(GenLocated SrcSpanAnnA (HsType GhcPs))
(GenLocated SrcSpanAnnA (HsType GhcPs))]
tparams
; EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc)
; let anns' :: EpAnn [AddEpAnn]
anns' = EpAnn [AddEpAnn] -> [AddEpAnn] -> EpAnnComments -> EpAnn [AddEpAnn]
addAnns (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor forall a b. (a -> b) -> a -> b
$ forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc) [AddEpAnn]
annsIn EpAnnComments
emptyComments) [AddEpAnn]
ann EpAnnComments
cs
; forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc (ClassDecl { tcdCExt :: XClassDecl GhcPs
tcdCExt = (EpAnn [AddEpAnn]
anns', AnnSortKey
NoAnnSortKey)
, tcdLayout :: LayoutInfo GhcPs
tcdLayout = LayoutInfo GhcPs
layoutInfo
, tcdCtxt :: Maybe (LHsContext GhcPs)
tcdCtxt = Maybe (LHsContext GhcPs)
mcxt
, tcdLName :: XRec GhcPs (IdP GhcPs)
tcdLName = GenLocated SrcSpanAnnN RdrName
cls, tcdTyVars :: LHsQTyVars GhcPs
tcdTyVars = LHsQTyVars GhcPs
tyvars
, tcdFixity :: LexicalFixity
tcdFixity = LexicalFixity
fixity
, tcdFDs :: [LHsFunDep GhcPs]
tcdFDs = forall a b. (a, b) -> b
snd (forall l e. GenLocated l e -> e
unLoc Located (a, [LHsFunDep GhcPs])
fds)
, tcdSigs :: [LSig GhcPs]
tcdSigs = [LSig GhcPs] -> [LSig GhcPs]
mkClassOpSigs [GenLocated SrcSpanAnnA (Sig GhcPs)]
sigs
, tcdMeths :: LHsBinds GhcPs
tcdMeths = Bag (GenLocated SrcSpanAnnA (HsBindLR GhcPs GhcPs))
binds
, tcdATs :: [LFamilyDecl GhcPs]
tcdATs = [GenLocated SrcSpanAnnA (FamilyDecl GhcPs)]
ats, tcdATDefs :: [LTyFamInstDecl GhcPs]
tcdATDefs = [GenLocated SrcSpanAnnA (TyFamInstDecl GhcPs)]
at_defs
, tcdDocs :: [LDocDecl GhcPs]
tcdDocs = [GenLocated SrcSpanAnnA (DocDecl GhcPs)]
docs })) }
mkTyData :: SrcSpan
-> Bool
-> NewOrData
-> Maybe (LocatedP CType)
-> Located (Maybe (LHsContext GhcPs), LHsType GhcPs)
-> Maybe (LHsKind GhcPs)
-> [LConDecl GhcPs]
-> Located (HsDeriving GhcPs)
-> [AddEpAnn]
-> P (LTyClDecl GhcPs)
mkTyData :: SrcSpan
-> Bool
-> NewOrData
-> Maybe (LocatedP CType)
-> Located (Maybe (LHsContext GhcPs), LHsType GhcPs)
-> Maybe (LHsType GhcPs)
-> [LConDecl GhcPs]
-> Located (HsDeriving GhcPs)
-> [AddEpAnn]
-> P (LTyClDecl GhcPs)
mkTyData SrcSpan
loc' Bool
is_type_data NewOrData
new_or_data Maybe (LocatedP CType)
cType (L SrcSpan
_ (Maybe (LHsContext GhcPs)
mcxt, LHsType GhcPs
tycl_hdr))
Maybe (LHsType GhcPs)
ksig [LConDecl GhcPs]
data_cons (L SrcSpan
_ HsDeriving GhcPs
maybe_deriv) [AddEpAnn]
annsIn
= do { let loc :: SrcSpanAnnA
loc = forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
loc'
; (GenLocated SrcSpanAnnN RdrName
tc, [HsArg
(GenLocated SrcSpanAnnA (HsType GhcPs))
(GenLocated SrcSpanAnnA (HsType GhcPs))]
tparams, LexicalFixity
fixity, [AddEpAnn]
ann) <- Bool
-> LHsType GhcPs
-> P (GenLocated SrcSpanAnnN RdrName, [LHsTypeArg GhcPs],
LexicalFixity, [AddEpAnn])
checkTyClHdr Bool
False LHsType GhcPs
tycl_hdr
; LHsQTyVars GhcPs
tyvars <- SDoc
-> SDoc
-> GenLocated SrcSpanAnnN RdrName
-> [LHsTypeArg GhcPs]
-> P (LHsQTyVars GhcPs)
checkTyVars (forall a. Outputable a => a -> SDoc
ppr NewOrData
new_or_data) SDoc
equalsDots GenLocated SrcSpanAnnN RdrName
tc [HsArg
(GenLocated SrcSpanAnnA (HsType GhcPs))
(GenLocated SrcSpanAnnA (HsType GhcPs))]
tparams
; EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc)
; let anns' :: EpAnn [AddEpAnn]
anns' = EpAnn [AddEpAnn] -> [AddEpAnn] -> EpAnnComments -> EpAnn [AddEpAnn]
addAnns (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor forall a b. (a -> b) -> a -> b
$ forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc) [AddEpAnn]
annsIn EpAnnComments
emptyComments) [AddEpAnn]
ann EpAnnComments
cs
; DataDefnCons (GenLocated SrcSpanAnnA (ConDecl GhcPs))
data_cons <- SrcSpan
-> RdrName
-> Bool
-> NewOrData
-> [LConDecl GhcPs]
-> P (DataDefnCons (LConDecl GhcPs))
checkNewOrData (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc) (forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnN RdrName
tc) Bool
is_type_data NewOrData
new_or_data [LConDecl GhcPs]
data_cons
; HsDataDefn GhcPs
defn <- Maybe (LocatedP CType)
-> Maybe (LHsContext GhcPs)
-> Maybe (LHsType GhcPs)
-> DataDefnCons (LConDecl GhcPs)
-> HsDeriving GhcPs
-> P (HsDataDefn GhcPs)
mkDataDefn Maybe (LocatedP CType)
cType Maybe (LHsContext GhcPs)
mcxt Maybe (LHsType GhcPs)
ksig DataDefnCons (GenLocated SrcSpanAnnA (ConDecl GhcPs))
data_cons HsDeriving GhcPs
maybe_deriv
; forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc (DataDecl { tcdDExt :: XDataDecl GhcPs
tcdDExt = EpAnn [AddEpAnn]
anns',
tcdLName :: XRec GhcPs (IdP GhcPs)
tcdLName = GenLocated SrcSpanAnnN RdrName
tc, tcdTyVars :: LHsQTyVars GhcPs
tcdTyVars = LHsQTyVars GhcPs
tyvars,
tcdFixity :: LexicalFixity
tcdFixity = LexicalFixity
fixity,
tcdDataDefn :: HsDataDefn GhcPs
tcdDataDefn = HsDataDefn GhcPs
defn })) }
mkDataDefn :: Maybe (LocatedP CType)
-> Maybe (LHsContext GhcPs)
-> Maybe (LHsKind GhcPs)
-> DataDefnCons (LConDecl GhcPs)
-> HsDeriving GhcPs
-> P (HsDataDefn GhcPs)
mkDataDefn :: Maybe (LocatedP CType)
-> Maybe (LHsContext GhcPs)
-> Maybe (LHsType GhcPs)
-> DataDefnCons (LConDecl GhcPs)
-> HsDeriving GhcPs
-> P (HsDataDefn GhcPs)
mkDataDefn Maybe (LocatedP CType)
cType Maybe (LHsContext GhcPs)
mcxt Maybe (LHsType GhcPs)
ksig DataDefnCons (LConDecl GhcPs)
data_cons HsDeriving GhcPs
maybe_deriv
= do { Maybe (LHsContext GhcPs) -> P ()
checkDatatypeContext Maybe (LHsContext GhcPs)
mcxt
; forall (m :: * -> *) a. Monad m => a -> m a
return (HsDataDefn { dd_ext :: XCHsDataDefn GhcPs
dd_ext = NoExtField
noExtField
, dd_cType :: Maybe (XRec GhcPs CType)
dd_cType = Maybe (LocatedP CType)
cType
, dd_ctxt :: Maybe (LHsContext GhcPs)
dd_ctxt = Maybe (LHsContext GhcPs)
mcxt
, dd_cons :: DataDefnCons (LConDecl GhcPs)
dd_cons = DataDefnCons (LConDecl GhcPs)
data_cons
, dd_kindSig :: Maybe (LHsType GhcPs)
dd_kindSig = Maybe (LHsType GhcPs)
ksig
, dd_derivs :: HsDeriving GhcPs
dd_derivs = HsDeriving GhcPs
maybe_deriv }) }
mkTySynonym :: SrcSpan
-> LHsType GhcPs
-> LHsType GhcPs
-> [AddEpAnn]
-> P (LTyClDecl GhcPs)
mkTySynonym :: SrcSpan
-> LHsType GhcPs
-> LHsType GhcPs
-> [AddEpAnn]
-> P (LTyClDecl GhcPs)
mkTySynonym SrcSpan
loc LHsType GhcPs
lhs LHsType GhcPs
rhs [AddEpAnn]
annsIn
= do { (GenLocated SrcSpanAnnN RdrName
tc, [HsArg
(GenLocated SrcSpanAnnA (HsType GhcPs))
(GenLocated SrcSpanAnnA (HsType GhcPs))]
tparams, LexicalFixity
fixity, [AddEpAnn]
ann) <- Bool
-> LHsType GhcPs
-> P (GenLocated SrcSpanAnnN RdrName, [LHsTypeArg GhcPs],
LexicalFixity, [AddEpAnn])
checkTyClHdr Bool
False LHsType GhcPs
lhs
; EpAnnComments
cs1 <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
loc
; LHsQTyVars GhcPs
tyvars <- SDoc
-> SDoc
-> GenLocated SrcSpanAnnN RdrName
-> [LHsTypeArg GhcPs]
-> P (LHsQTyVars GhcPs)
checkTyVars (forall doc. IsLine doc => String -> doc
text String
"type") SDoc
equalsDots GenLocated SrcSpanAnnN RdrName
tc [HsArg
(GenLocated SrcSpanAnnA (HsType GhcPs))
(GenLocated SrcSpanAnnA (HsType GhcPs))]
tparams
; EpAnnComments
cs2 <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
loc
; let anns' :: EpAnn [AddEpAnn]
anns' = EpAnn [AddEpAnn] -> [AddEpAnn] -> EpAnnComments -> EpAnn [AddEpAnn]
addAnns (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
loc) [AddEpAnn]
annsIn EpAnnComments
emptyComments) [AddEpAnn]
ann (EpAnnComments
cs1 forall a. Semigroup a => a -> a -> a
Semi.<> EpAnnComments
cs2)
; forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
loc) (SynDecl
{ tcdSExt :: XSynDecl GhcPs
tcdSExt = EpAnn [AddEpAnn]
anns'
, tcdLName :: XRec GhcPs (IdP GhcPs)
tcdLName = GenLocated SrcSpanAnnN RdrName
tc, tcdTyVars :: LHsQTyVars GhcPs
tcdTyVars = LHsQTyVars GhcPs
tyvars
, tcdFixity :: LexicalFixity
tcdFixity = LexicalFixity
fixity
, tcdRhs :: LHsType GhcPs
tcdRhs = LHsType GhcPs
rhs })) }
mkStandaloneKindSig
:: SrcSpan
-> Located [LocatedN RdrName]
-> LHsSigType GhcPs
-> [AddEpAnn]
-> P (LStandaloneKindSig GhcPs)
mkStandaloneKindSig :: SrcSpan
-> Located [GenLocated SrcSpanAnnN RdrName]
-> LHsSigType GhcPs
-> [AddEpAnn]
-> P (LStandaloneKindSig GhcPs)
mkStandaloneKindSig SrcSpan
loc Located [GenLocated SrcSpanAnnN RdrName]
lhs LHsSigType GhcPs
rhs [AddEpAnn]
anns =
do { [GenLocated SrcSpanAnnN RdrName]
vs <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM forall {m :: * -> *} {a}.
MonadP m =>
GenLocated (SrcSpanAnn' a) RdrName
-> m (GenLocated (SrcSpanAnn' a) RdrName)
check_lhs_name (forall l e. GenLocated l e -> e
unLoc Located [GenLocated SrcSpanAnnN RdrName]
lhs)
; GenLocated SrcSpanAnnN RdrName
v <- [GenLocated SrcSpanAnnN RdrName]
-> P (GenLocated SrcSpanAnnN RdrName)
check_singular_lhs (forall a. [a] -> [a]
reverse [GenLocated SrcSpanAnnN RdrName]
vs)
; EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
loc
; forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
loc)
forall a b. (a -> b) -> a -> b
$ forall pass.
XStandaloneKindSig pass
-> LIdP pass -> LHsSigType pass -> StandaloneKindSig pass
StandaloneKindSig (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
loc) [AddEpAnn]
anns EpAnnComments
cs) GenLocated SrcSpanAnnN RdrName
v LHsSigType GhcPs
rhs }
where
check_lhs_name :: GenLocated (SrcSpanAnn' a) RdrName
-> m (GenLocated (SrcSpanAnn' a) RdrName)
check_lhs_name v :: GenLocated (SrcSpanAnn' a) RdrName
v@(forall l e. GenLocated l e -> e
unLoc->RdrName
name) =
if RdrName -> Bool
isUnqual RdrName
name Bool -> Bool -> Bool
&& OccName -> Bool
isTcOcc (RdrName -> OccName
rdrNameOcc RdrName
name)
then forall (m :: * -> *) a. Monad m => a -> m a
return GenLocated (SrcSpanAnn' a) RdrName
v
else forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
getLocA GenLocated (SrcSpanAnn' a) RdrName
v) forall a b. (a -> b) -> a -> b
$
(RdrName -> PsMessage
PsErrUnexpectedQualifiedConstructor (forall l e. GenLocated l e -> e
unLoc GenLocated (SrcSpanAnn' a) RdrName
v))
check_singular_lhs :: [GenLocated SrcSpanAnnN RdrName]
-> P (GenLocated SrcSpanAnnN RdrName)
check_singular_lhs [GenLocated SrcSpanAnnN RdrName]
vs =
case [GenLocated SrcSpanAnnN RdrName]
vs of
[] -> forall a. HasCallStack => String -> a
panic String
"mkStandaloneKindSig: empty left-hand side"
[GenLocated SrcSpanAnnN RdrName
v] -> forall (m :: * -> *) a. Monad m => a -> m a
return GenLocated SrcSpanAnnN RdrName
v
[GenLocated SrcSpanAnnN RdrName]
_ -> forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall l e. GenLocated l e -> l
getLoc Located [GenLocated SrcSpanAnnN RdrName]
lhs) forall a b. (a -> b) -> a -> b
$
([XRec GhcPs (IdP GhcPs)] -> PsMessage
PsErrMultipleNamesInStandaloneKindSignature [GenLocated SrcSpanAnnN RdrName]
vs)
mkTyFamInstEqn :: SrcSpan
-> HsOuterFamEqnTyVarBndrs GhcPs
-> LHsType GhcPs
-> LHsType GhcPs
-> [AddEpAnn]
-> P (LTyFamInstEqn GhcPs)
mkTyFamInstEqn :: SrcSpan
-> HsOuterFamEqnTyVarBndrs GhcPs
-> LHsType GhcPs
-> LHsType GhcPs
-> [AddEpAnn]
-> P (LTyFamInstEqn GhcPs)
mkTyFamInstEqn SrcSpan
loc HsOuterFamEqnTyVarBndrs GhcPs
bndrs LHsType GhcPs
lhs LHsType GhcPs
rhs [AddEpAnn]
anns
= do { (GenLocated SrcSpanAnnN RdrName
tc, [HsArg
(GenLocated SrcSpanAnnA (HsType GhcPs))
(GenLocated SrcSpanAnnA (HsType GhcPs))]
tparams, LexicalFixity
fixity, [AddEpAnn]
ann) <- Bool
-> LHsType GhcPs
-> P (GenLocated SrcSpanAnnN RdrName, [LHsTypeArg GhcPs],
LexicalFixity, [AddEpAnn])
checkTyClHdr Bool
False LHsType GhcPs
lhs
; EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
loc
; forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
loc) forall a b. (a -> b) -> a -> b
$ FamEqn
{ feqn_ext :: XCFamEqn GhcPs (GenLocated SrcSpanAnnA (HsType GhcPs))
feqn_ext = forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
loc) ([AddEpAnn]
anns forall a. Monoid a => a -> a -> a
`mappend` [AddEpAnn]
ann) EpAnnComments
cs
, feqn_tycon :: XRec GhcPs (IdP GhcPs)
feqn_tycon = GenLocated SrcSpanAnnN RdrName
tc
, feqn_bndrs :: HsOuterFamEqnTyVarBndrs GhcPs
feqn_bndrs = HsOuterFamEqnTyVarBndrs GhcPs
bndrs
, feqn_pats :: [LHsTypeArg GhcPs]
feqn_pats = [HsArg
(GenLocated SrcSpanAnnA (HsType GhcPs))
(GenLocated SrcSpanAnnA (HsType GhcPs))]
tparams
, feqn_fixity :: LexicalFixity
feqn_fixity = LexicalFixity
fixity
, feqn_rhs :: GenLocated SrcSpanAnnA (HsType GhcPs)
feqn_rhs = LHsType GhcPs
rhs })}
mkDataFamInst :: SrcSpan
-> NewOrData
-> Maybe (LocatedP CType)
-> (Maybe ( LHsContext GhcPs), HsOuterFamEqnTyVarBndrs GhcPs
, LHsType GhcPs)
-> Maybe (LHsKind GhcPs)
-> [LConDecl GhcPs]
-> Located (HsDeriving GhcPs)
-> [AddEpAnn]
-> P (LInstDecl GhcPs)
mkDataFamInst :: SrcSpan
-> NewOrData
-> Maybe (LocatedP CType)
-> (Maybe (LHsContext GhcPs), HsOuterFamEqnTyVarBndrs GhcPs,
LHsType GhcPs)
-> Maybe (LHsType GhcPs)
-> [LConDecl GhcPs]
-> Located (HsDeriving GhcPs)
-> [AddEpAnn]
-> P (LInstDecl GhcPs)
mkDataFamInst SrcSpan
loc NewOrData
new_or_data Maybe (LocatedP CType)
cType (Maybe (LHsContext GhcPs)
mcxt, HsOuterFamEqnTyVarBndrs GhcPs
bndrs, LHsType GhcPs
tycl_hdr)
Maybe (LHsType GhcPs)
ksig [LConDecl GhcPs]
data_cons (L SrcSpan
_ HsDeriving GhcPs
maybe_deriv) [AddEpAnn]
anns
= do { (GenLocated SrcSpanAnnN RdrName
tc, [HsArg
(GenLocated SrcSpanAnnA (HsType GhcPs))
(GenLocated SrcSpanAnnA (HsType GhcPs))]
tparams, LexicalFixity
fixity, [AddEpAnn]
ann) <- Bool
-> LHsType GhcPs
-> P (GenLocated SrcSpanAnnN RdrName, [LHsTypeArg GhcPs],
LexicalFixity, [AddEpAnn])
checkTyClHdr Bool
False LHsType GhcPs
tycl_hdr
; EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
loc
; let fam_eqn_ans :: EpAnn [AddEpAnn]
fam_eqn_ans = EpAnn [AddEpAnn] -> [AddEpAnn] -> EpAnnComments -> EpAnn [AddEpAnn]
addAnns (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
loc) [AddEpAnn]
ann EpAnnComments
cs) [AddEpAnn]
anns EpAnnComments
emptyComments
; DataDefnCons (GenLocated SrcSpanAnnA (ConDecl GhcPs))
data_cons <- SrcSpan
-> RdrName
-> Bool
-> NewOrData
-> [LConDecl GhcPs]
-> P (DataDefnCons (LConDecl GhcPs))
checkNewOrData SrcSpan
loc (forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnN RdrName
tc) Bool
False NewOrData
new_or_data [LConDecl GhcPs]
data_cons
; HsDataDefn GhcPs
defn <- Maybe (LocatedP CType)
-> Maybe (LHsContext GhcPs)
-> Maybe (LHsType GhcPs)
-> DataDefnCons (LConDecl GhcPs)
-> HsDeriving GhcPs
-> P (HsDataDefn GhcPs)
mkDataDefn Maybe (LocatedP CType)
cType Maybe (LHsContext GhcPs)
mcxt Maybe (LHsType GhcPs)
ksig DataDefnCons (GenLocated SrcSpanAnnA (ConDecl GhcPs))
data_cons HsDeriving GhcPs
maybe_deriv
; forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
loc) (forall pass.
XDataFamInstD pass -> DataFamInstDecl pass -> InstDecl pass
DataFamInstD NoExtField
noExtField (forall pass. FamEqn pass (HsDataDefn pass) -> DataFamInstDecl pass
DataFamInstDecl
(FamEqn { feqn_ext :: XCFamEqn GhcPs (HsDataDefn GhcPs)
feqn_ext = EpAnn [AddEpAnn]
fam_eqn_ans
, feqn_tycon :: XRec GhcPs (IdP GhcPs)
feqn_tycon = GenLocated SrcSpanAnnN RdrName
tc
, feqn_bndrs :: HsOuterFamEqnTyVarBndrs GhcPs
feqn_bndrs = HsOuterFamEqnTyVarBndrs GhcPs
bndrs
, feqn_pats :: [LHsTypeArg GhcPs]
feqn_pats = [HsArg
(GenLocated SrcSpanAnnA (HsType GhcPs))
(GenLocated SrcSpanAnnA (HsType GhcPs))]
tparams
, feqn_fixity :: LexicalFixity
feqn_fixity = LexicalFixity
fixity
, feqn_rhs :: HsDataDefn GhcPs
feqn_rhs = HsDataDefn GhcPs
defn })))) }
mkTyFamInst :: SrcSpan
-> TyFamInstEqn GhcPs
-> [AddEpAnn]
-> P (LInstDecl GhcPs)
mkTyFamInst :: SrcSpan -> TyFamInstEqn GhcPs -> [AddEpAnn] -> P (LInstDecl GhcPs)
mkTyFamInst SrcSpan
loc TyFamInstEqn GhcPs
eqn [AddEpAnn]
anns = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
loc
forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
loc) (forall pass.
XTyFamInstD pass -> TyFamInstDecl pass -> InstDecl pass
TyFamInstD NoExtField
noExtField
(forall pass.
XCTyFamInstDecl pass -> TyFamInstEqn pass -> TyFamInstDecl pass
TyFamInstDecl (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
loc) [AddEpAnn]
anns EpAnnComments
cs) TyFamInstEqn GhcPs
eqn)))
mkFamDecl :: SrcSpan
-> FamilyInfo GhcPs
-> TopLevelFlag
-> LHsType GhcPs
-> LFamilyResultSig GhcPs
-> Maybe (LInjectivityAnn GhcPs)
-> [AddEpAnn]
-> P (LTyClDecl GhcPs)
mkFamDecl :: SrcSpan
-> FamilyInfo GhcPs
-> TopLevelFlag
-> LHsType GhcPs
-> LFamilyResultSig GhcPs
-> Maybe (LInjectivityAnn GhcPs)
-> [AddEpAnn]
-> P (LTyClDecl GhcPs)
mkFamDecl SrcSpan
loc FamilyInfo GhcPs
info TopLevelFlag
topLevel LHsType GhcPs
lhs LFamilyResultSig GhcPs
ksig Maybe (LInjectivityAnn GhcPs)
injAnn [AddEpAnn]
annsIn
= do { (GenLocated SrcSpanAnnN RdrName
tc, [HsArg
(GenLocated SrcSpanAnnA (HsType GhcPs))
(GenLocated SrcSpanAnnA (HsType GhcPs))]
tparams, LexicalFixity
fixity, [AddEpAnn]
ann) <- Bool
-> LHsType GhcPs
-> P (GenLocated SrcSpanAnnN RdrName, [LHsTypeArg GhcPs],
LexicalFixity, [AddEpAnn])
checkTyClHdr Bool
False LHsType GhcPs
lhs
; EpAnnComments
cs1 <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
loc
; LHsQTyVars GhcPs
tyvars <- SDoc
-> SDoc
-> GenLocated SrcSpanAnnN RdrName
-> [LHsTypeArg GhcPs]
-> P (LHsQTyVars GhcPs)
checkTyVars (forall a. Outputable a => a -> SDoc
ppr FamilyInfo GhcPs
info) SDoc
equals_or_where GenLocated SrcSpanAnnN RdrName
tc [HsArg
(GenLocated SrcSpanAnnA (HsType GhcPs))
(GenLocated SrcSpanAnnA (HsType GhcPs))]
tparams
; EpAnnComments
cs2 <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
loc
; let anns' :: EpAnn [AddEpAnn]
anns' = EpAnn [AddEpAnn] -> [AddEpAnn] -> EpAnnComments -> EpAnn [AddEpAnn]
addAnns (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
loc) [AddEpAnn]
annsIn EpAnnComments
emptyComments) [AddEpAnn]
ann (EpAnnComments
cs1 forall a. Semigroup a => a -> a -> a
Semi.<> EpAnnComments
cs2)
; forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
loc) (forall pass. XFamDecl pass -> FamilyDecl pass -> TyClDecl pass
FamDecl NoExtField
noExtField
(FamilyDecl
{ fdExt :: XCFamilyDecl GhcPs
fdExt = EpAnn [AddEpAnn]
anns'
, fdTopLevel :: TopLevelFlag
fdTopLevel = TopLevelFlag
topLevel
, fdInfo :: FamilyInfo GhcPs
fdInfo = FamilyInfo GhcPs
info, fdLName :: XRec GhcPs (IdP GhcPs)
fdLName = GenLocated SrcSpanAnnN RdrName
tc
, fdTyVars :: LHsQTyVars GhcPs
fdTyVars = LHsQTyVars GhcPs
tyvars
, fdFixity :: LexicalFixity
fdFixity = LexicalFixity
fixity
, fdResultSig :: LFamilyResultSig GhcPs
fdResultSig = LFamilyResultSig GhcPs
ksig
, fdInjectivityAnn :: Maybe (LInjectivityAnn GhcPs)
fdInjectivityAnn = Maybe (LInjectivityAnn GhcPs)
injAnn }))) }
where
equals_or_where :: SDoc
equals_or_where = case FamilyInfo GhcPs
info of
FamilyInfo GhcPs
DataFamily -> forall doc. IsOutput doc => doc
empty
FamilyInfo GhcPs
OpenTypeFamily -> forall doc. IsOutput doc => doc
empty
ClosedTypeFamily {} -> SDoc
whereDots
mkSpliceDecl :: LHsExpr GhcPs -> P (LHsDecl GhcPs)
mkSpliceDecl :: LHsExpr GhcPs -> P (LHsDecl GhcPs)
mkSpliceDecl lexpr :: LHsExpr GhcPs
lexpr@(L SrcSpanAnnA
loc HsExpr GhcPs
expr)
| HsUntypedSplice XUntypedSplice GhcPs
_ splice :: HsUntypedSplice GhcPs
splice@(HsUntypedSpliceExpr {}) <- HsExpr GhcPs
expr = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. Monoid ann => SrcAnn ann -> EpAnnComments -> SrcAnn ann
addCommentsToSrcAnn SrcSpanAnnA
loc EpAnnComments
cs) forall a b. (a -> b) -> a -> b
$ forall p. XSpliceD p -> SpliceDecl p -> HsDecl p
SpliceD NoExtField
noExtField (forall p.
XSpliceDecl p
-> XRec p (HsUntypedSplice p) -> SpliceDecoration -> SpliceDecl p
SpliceDecl NoExtField
noExtField (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc HsUntypedSplice GhcPs
splice) SpliceDecoration
DollarSplice)
| HsUntypedSplice XUntypedSplice GhcPs
_ splice :: HsUntypedSplice GhcPs
splice@(HsQuasiQuote {}) <- HsExpr GhcPs
expr = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. Monoid ann => SrcAnn ann -> EpAnnComments -> SrcAnn ann
addCommentsToSrcAnn SrcSpanAnnA
loc EpAnnComments
cs) forall a b. (a -> b) -> a -> b
$ forall p. XSpliceD p -> SpliceDecl p -> HsDecl p
SpliceD NoExtField
noExtField (forall p.
XSpliceDecl p
-> XRec p (HsUntypedSplice p) -> SpliceDecoration -> SpliceDecl p
SpliceDecl NoExtField
noExtField (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc HsUntypedSplice GhcPs
splice) SpliceDecoration
DollarSplice)
| Bool
otherwise = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. Monoid ann => SrcAnn ann -> EpAnnComments -> SrcAnn ann
addCommentsToSrcAnn SrcSpanAnnA
loc EpAnnComments
cs) forall a b. (a -> b) -> a -> b
$ forall p. XSpliceD p -> SpliceDecl p -> HsDecl p
SpliceD NoExtField
noExtField (forall p.
XSpliceDecl p
-> XRec p (HsUntypedSplice p) -> SpliceDecoration -> SpliceDecl p
SpliceDecl NoExtField
noExtField
(forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc (forall id.
XUntypedSpliceExpr id -> LHsExpr id -> HsUntypedSplice id
HsUntypedSpliceExpr forall a. EpAnn a
noAnn LHsExpr GhcPs
lexpr))
SpliceDecoration
BareSplice)
mkRoleAnnotDecl :: SrcSpan
-> LocatedN RdrName
-> [Located (Maybe FastString)]
-> [AddEpAnn]
-> P (LRoleAnnotDecl GhcPs)
mkRoleAnnotDecl :: SrcSpan
-> GenLocated SrcSpanAnnN RdrName
-> [Located (Maybe FastString)]
-> [AddEpAnn]
-> P (LRoleAnnotDecl GhcPs)
mkRoleAnnotDecl SrcSpan
loc GenLocated SrcSpanAnnN RdrName
tycon [Located (Maybe FastString)]
roles [AddEpAnn]
anns
= do { [GenLocated (SrcAnn NoEpAnns) (Maybe Role)]
roles' <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Located (Maybe FastString)
-> P (GenLocated (SrcAnn NoEpAnns) (Maybe Role))
parse_role [Located (Maybe FastString)]
roles
; EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
loc
; forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
loc)
forall a b. (a -> b) -> a -> b
$ forall pass.
XCRoleAnnotDecl pass
-> LIdP pass -> [XRec pass (Maybe Role)] -> RoleAnnotDecl pass
RoleAnnotDecl (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
loc) [AddEpAnn]
anns EpAnnComments
cs) GenLocated SrcSpanAnnN RdrName
tycon [GenLocated (SrcAnn NoEpAnns) (Maybe Role)]
roles' }
where
role_data_type :: DataType
role_data_type = forall a. Data a => a -> DataType
dataTypeOf (forall a. HasCallStack => a
undefined :: Role)
all_roles :: [Role]
all_roles = forall a b. (a -> b) -> [a] -> [b]
map forall a. Data a => Constr -> a
fromConstr forall a b. (a -> b) -> a -> b
$ DataType -> [Constr]
dataTypeConstrs DataType
role_data_type
possible_roles :: [(FastString, Role)]
possible_roles = [(Role -> FastString
fsFromRole Role
role, Role
role) | Role
role <- [Role]
all_roles]
parse_role :: Located (Maybe FastString)
-> P (GenLocated (SrcAnn NoEpAnns) (Maybe Role))
parse_role (L SrcSpan
loc_role Maybe FastString
Nothing) = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
loc_role) forall a. Maybe a
Nothing
parse_role (L SrcSpan
loc_role (Just FastString
role))
= case forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup FastString
role [(FastString, Role)]
possible_roles of
Just Role
found_role -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
loc_role) forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just Role
found_role
Maybe Role
Nothing ->
let nearby :: [Role]
nearby = forall a. String -> [(String, a)] -> [a]
fuzzyLookup (FastString -> String
unpackFS FastString
role)
(forall (f :: * -> *) a c b.
Functor f =>
(a -> c) -> f (a, b) -> f (c, b)
mapFst FastString -> String
unpackFS [(FastString, Role)]
possible_roles)
in
forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
loc_role forall a b. (a -> b) -> a -> b
$
(FastString -> [Role] -> PsMessage
PsErrIllegalRoleName FastString
role [Role]
nearby)
fromSpecTyVarBndrs :: [LHsTyVarBndr Specificity GhcPs] -> P [LHsTyVarBndr () GhcPs]
fromSpecTyVarBndrs :: [LHsTyVarBndr Specificity GhcPs] -> P [LHsTyVarBndr () GhcPs]
fromSpecTyVarBndrs = forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LHsTyVarBndr Specificity GhcPs -> P (LHsTyVarBndr () GhcPs)
fromSpecTyVarBndr
fromSpecTyVarBndr :: LHsTyVarBndr Specificity GhcPs -> P (LHsTyVarBndr () GhcPs)
fromSpecTyVarBndr :: LHsTyVarBndr Specificity GhcPs -> P (LHsTyVarBndr () GhcPs)
fromSpecTyVarBndr LHsTyVarBndr Specificity GhcPs
bndr = case LHsTyVarBndr Specificity GhcPs
bndr of
(L SrcSpanAnnA
loc (UserTyVar XUserTyVar GhcPs
xtv Specificity
flag XRec GhcPs (IdP GhcPs)
idp)) -> (Specificity -> SrcSpanAnnA -> P ()
check_spec Specificity
flag SrcSpanAnnA
loc)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc forall a b. (a -> b) -> a -> b
$ forall flag pass.
XUserTyVar pass -> flag -> LIdP pass -> HsTyVarBndr flag pass
UserTyVar XUserTyVar GhcPs
xtv () XRec GhcPs (IdP GhcPs)
idp)
(L SrcSpanAnnA
loc (KindedTyVar XKindedTyVar GhcPs
xtv Specificity
flag XRec GhcPs (IdP GhcPs)
idp LHsType GhcPs
k)) -> (Specificity -> SrcSpanAnnA -> P ()
check_spec Specificity
flag SrcSpanAnnA
loc)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc forall a b. (a -> b) -> a -> b
$ forall flag pass.
XKindedTyVar pass
-> flag -> LIdP pass -> LHsKind pass -> HsTyVarBndr flag pass
KindedTyVar XKindedTyVar GhcPs
xtv () XRec GhcPs (IdP GhcPs)
idp LHsType GhcPs
k)
where
check_spec :: Specificity -> SrcSpanAnnA -> P ()
check_spec :: Specificity -> SrcSpanAnnA -> P ()
check_spec Specificity
SpecifiedSpec SrcSpanAnnA
_ = forall (m :: * -> *) a. Monad m => a -> m a
return ()
check_spec Specificity
InferredSpec SrcSpanAnnA
loc = forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc) forall a b. (a -> b) -> a -> b
$
PsMessage
PsErrInferredTypeVarNotAllowed
annBinds :: AddEpAnn -> EpAnnComments -> HsLocalBinds GhcPs
-> (HsLocalBinds GhcPs, Maybe EpAnnComments)
annBinds :: AddEpAnn
-> EpAnnComments
-> HsLocalBinds GhcPs
-> (HsLocalBinds GhcPs, Maybe EpAnnComments)
annBinds AddEpAnn
a EpAnnComments
cs (HsValBinds XHsValBinds GhcPs GhcPs
an HsValBindsLR GhcPs GhcPs
bs) = (forall idL idR.
XHsValBinds idL idR
-> HsValBindsLR idL idR -> HsLocalBindsLR idL idR
HsValBinds (AddEpAnn -> EpAnn AnnList -> EpAnnComments -> EpAnn AnnList
add_where AddEpAnn
a XHsValBinds GhcPs GhcPs
an EpAnnComments
cs) HsValBindsLR GhcPs GhcPs
bs, forall a. Maybe a
Nothing)
annBinds AddEpAnn
a EpAnnComments
cs (HsIPBinds XHsIPBinds GhcPs GhcPs
an HsIPBinds GhcPs
bs) = (forall idL idR.
XHsIPBinds idL idR -> HsIPBinds idR -> HsLocalBindsLR idL idR
HsIPBinds (AddEpAnn -> EpAnn AnnList -> EpAnnComments -> EpAnn AnnList
add_where AddEpAnn
a XHsIPBinds GhcPs GhcPs
an EpAnnComments
cs) HsIPBinds GhcPs
bs, forall a. Maybe a
Nothing)
annBinds AddEpAnn
_ EpAnnComments
cs (EmptyLocalBinds XEmptyLocalBinds GhcPs GhcPs
x) = (forall idL idR. XEmptyLocalBinds idL idR -> HsLocalBindsLR idL idR
EmptyLocalBinds XEmptyLocalBinds GhcPs GhcPs
x, forall a. a -> Maybe a
Just EpAnnComments
cs)
add_where :: AddEpAnn -> EpAnn AnnList -> EpAnnComments -> EpAnn AnnList
add_where :: AddEpAnn -> EpAnn AnnList -> EpAnnComments -> EpAnn AnnList
add_where an :: AddEpAnn
an@(AddEpAnn AnnKeywordId
_ (EpaSpan RealSrcSpan
rs Maybe BufSpan
_)) (EpAnn Anchor
a (AnnList Maybe Anchor
anc Maybe AddEpAnn
o Maybe AddEpAnn
c [AddEpAnn]
r [TrailingAnn]
t) EpAnnComments
cs) EpAnnComments
cs2
| RealSrcSpan -> Bool
valid_anchor (Anchor -> RealSrcSpan
anchor Anchor
a)
= forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (Anchor -> [AddEpAnn] -> Anchor
widenAnchor Anchor
a [AddEpAnn
an]) (Maybe Anchor
-> Maybe AddEpAnn
-> Maybe AddEpAnn
-> [AddEpAnn]
-> [TrailingAnn]
-> AnnList
AnnList Maybe Anchor
anc Maybe AddEpAnn
o Maybe AddEpAnn
c (AddEpAnn
anforall a. a -> [a] -> [a]
:[AddEpAnn]
r) [TrailingAnn]
t) (EpAnnComments
cs forall a. Semigroup a => a -> a -> a
Semi.<> EpAnnComments
cs2)
| Bool
otherwise
= forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (RealSrcSpan -> Anchor -> Anchor
patch_anchor RealSrcSpan
rs Anchor
a)
(Maybe Anchor
-> Maybe AddEpAnn
-> Maybe AddEpAnn
-> [AddEpAnn]
-> [TrailingAnn]
-> AnnList
AnnList (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (RealSrcSpan -> Anchor -> Anchor
patch_anchor RealSrcSpan
rs) Maybe Anchor
anc) Maybe AddEpAnn
o Maybe AddEpAnn
c (AddEpAnn
anforall a. a -> [a] -> [a]
:[AddEpAnn]
r) [TrailingAnn]
t) (EpAnnComments
cs forall a. Semigroup a => a -> a -> a
Semi.<> EpAnnComments
cs2)
add_where an :: AddEpAnn
an@(AddEpAnn AnnKeywordId
_ (EpaSpan RealSrcSpan
rs Maybe BufSpan
_)) EpAnn AnnList
EpAnnNotUsed EpAnnComments
cs
= forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (RealSrcSpan -> AnchorOperation -> Anchor
Anchor RealSrcSpan
rs AnchorOperation
UnchangedAnchor)
(Maybe Anchor
-> Maybe AddEpAnn
-> Maybe AddEpAnn
-> [AddEpAnn]
-> [TrailingAnn]
-> AnnList
AnnList (forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ RealSrcSpan -> AnchorOperation -> Anchor
Anchor RealSrcSpan
rs AnchorOperation
UnchangedAnchor) forall a. Maybe a
Nothing forall a. Maybe a
Nothing [AddEpAnn
an] []) EpAnnComments
cs
add_where (AddEpAnn AnnKeywordId
_ (EpaDelta DeltaPos
_ [LEpaComment]
_)) EpAnn AnnList
_ EpAnnComments
_ = forall a. HasCallStack => String -> a
panic String
"add_where"
valid_anchor :: RealSrcSpan -> Bool
valid_anchor :: RealSrcSpan -> Bool
valid_anchor RealSrcSpan
r = RealSrcSpan -> Int
srcSpanStartLine RealSrcSpan
r forall a. Ord a => a -> a -> Bool
>= Int
0
patch_anchor :: RealSrcSpan -> Anchor -> Anchor
patch_anchor :: RealSrcSpan -> Anchor -> Anchor
patch_anchor RealSrcSpan
r1 (Anchor RealSrcSpan
r0 AnchorOperation
op) = RealSrcSpan -> AnchorOperation -> Anchor
Anchor RealSrcSpan
r AnchorOperation
op
where
r :: RealSrcSpan
r = if RealSrcSpan -> Int
srcSpanStartLine RealSrcSpan
r0 forall a. Ord a => a -> a -> Bool
< Int
0 then RealSrcSpan
r1 else RealSrcSpan
r0
fixValbindsAnn :: EpAnn AnnList -> EpAnn AnnList
fixValbindsAnn :: EpAnn AnnList -> EpAnn AnnList
fixValbindsAnn EpAnn AnnList
EpAnnNotUsed = forall a. EpAnn a
EpAnnNotUsed
fixValbindsAnn (EpAnn Anchor
anchor (AnnList Maybe Anchor
ma Maybe AddEpAnn
o Maybe AddEpAnn
c [AddEpAnn]
r [TrailingAnn]
t) EpAnnComments
cs)
= (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (Anchor -> [AddEpAnn] -> Anchor
widenAnchor Anchor
anchor (forall a b. (a -> b) -> [a] -> [b]
map TrailingAnn -> AddEpAnn
trailingAnnToAddEpAnn [TrailingAnn]
t)) (Maybe Anchor
-> Maybe AddEpAnn
-> Maybe AddEpAnn
-> [AddEpAnn]
-> [TrailingAnn]
-> AnnList
AnnList Maybe Anchor
ma Maybe AddEpAnn
o Maybe AddEpAnn
c [AddEpAnn]
r [TrailingAnn]
t) EpAnnComments
cs)
stmtsAnchor :: Located (OrdList AddEpAnn,a) -> Anchor
stmtsAnchor :: forall a. Located (OrdList AddEpAnn, a) -> Anchor
stmtsAnchor (L SrcSpan
l ((ConsOL (AddEpAnn AnnKeywordId
_ (EpaSpan RealSrcSpan
r Maybe BufSpan
_)) OrdList AddEpAnn
_), a
_))
= Anchor -> RealSrcSpan -> Anchor
widenAnchorR (RealSrcSpan -> AnchorOperation -> Anchor
Anchor (SrcSpan -> RealSrcSpan
realSrcSpan SrcSpan
l) AnchorOperation
UnchangedAnchor) RealSrcSpan
r
stmtsAnchor (L SrcSpan
l (OrdList AddEpAnn, a)
_) = RealSrcSpan -> AnchorOperation -> Anchor
Anchor (SrcSpan -> RealSrcSpan
realSrcSpan SrcSpan
l) AnchorOperation
UnchangedAnchor
stmtsLoc :: Located (OrdList AddEpAnn,a) -> SrcSpan
stmtsLoc :: forall a. Located (OrdList AddEpAnn, a) -> SrcSpan
stmtsLoc (L SrcSpan
l ((ConsOL AddEpAnn
aa OrdList AddEpAnn
_), a
_))
= SrcSpan -> [AddEpAnn] -> SrcSpan
widenSpan SrcSpan
l [AddEpAnn
aa]
stmtsLoc (L SrcSpan
l (OrdList AddEpAnn, a)
_) = SrcSpan
l
cvTopDecls :: OrdList (LHsDecl GhcPs) -> [LHsDecl GhcPs]
cvTopDecls :: OrdList (LHsDecl GhcPs) -> [LHsDecl GhcPs]
cvTopDecls OrdList (LHsDecl GhcPs)
decls = [LHsDecl GhcPs] -> [LHsDecl GhcPs]
getMonoBindAll (forall a. OrdList a -> [a]
fromOL OrdList (LHsDecl GhcPs)
decls)
cvBindGroup :: OrdList (LHsDecl GhcPs) -> P (HsValBinds GhcPs)
cvBindGroup :: OrdList (LHsDecl GhcPs) -> P (HsValBindsLR GhcPs GhcPs)
cvBindGroup OrdList (LHsDecl GhcPs)
binding
= do { (Bag (GenLocated SrcSpanAnnA (HsBindLR GhcPs GhcPs))
mbs, [GenLocated SrcSpanAnnA (Sig GhcPs)]
sigs, [GenLocated SrcSpanAnnA (FamilyDecl GhcPs)]
fam_ds, [GenLocated SrcSpanAnnA (TyFamInstDecl GhcPs)]
tfam_insts
, [GenLocated SrcSpanAnnA (DataFamInstDecl GhcPs)]
dfam_insts, [GenLocated SrcSpanAnnA (DocDecl GhcPs)]
_) <- OrdList (LHsDecl GhcPs)
-> P (LHsBinds GhcPs, [LSig GhcPs], [LFamilyDecl GhcPs],
[LTyFamInstDecl GhcPs], [LDataFamInstDecl GhcPs], [LDocDecl GhcPs])
cvBindsAndSigs OrdList (LHsDecl GhcPs)
binding
; forall (m :: * -> *). (HasCallStack, Applicative m) => Bool -> m ()
massert (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [GenLocated SrcSpanAnnA (FamilyDecl GhcPs)]
fam_ds Bool -> Bool -> Bool
&& forall (t :: * -> *) a. Foldable t => t a -> Bool
null [GenLocated SrcSpanAnnA (TyFamInstDecl GhcPs)]
tfam_insts Bool -> Bool -> Bool
&& forall (t :: * -> *) a. Foldable t => t a -> Bool
null [GenLocated SrcSpanAnnA (DataFamInstDecl GhcPs)]
dfam_insts)
; forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall idL idR.
XValBinds idL idR
-> LHsBindsLR idL idR -> [LSig idR] -> HsValBindsLR idL idR
ValBinds AnnSortKey
NoAnnSortKey Bag (GenLocated SrcSpanAnnA (HsBindLR GhcPs GhcPs))
mbs [GenLocated SrcSpanAnnA (Sig GhcPs)]
sigs }
cvBindsAndSigs :: OrdList (LHsDecl GhcPs)
-> P (LHsBinds GhcPs, [LSig GhcPs], [LFamilyDecl GhcPs]
, [LTyFamInstDecl GhcPs], [LDataFamInstDecl GhcPs], [LDocDecl GhcPs])
cvBindsAndSigs :: OrdList (LHsDecl GhcPs)
-> P (LHsBinds GhcPs, [LSig GhcPs], [LFamilyDecl GhcPs],
[LTyFamInstDecl GhcPs], [LDataFamInstDecl GhcPs], [LDocDecl GhcPs])
cvBindsAndSigs OrdList (LHsDecl GhcPs)
fb = do
[GenLocated SrcSpanAnnA (HsDecl GhcPs)]
fb' <- forall {m :: * -> *} {a}.
MonadP m =>
[GenLocated (SrcSpanAnn' a) (HsDecl GhcPs)]
-> m [GenLocated (SrcSpanAnn' a) (HsDecl GhcPs)]
drop_bad_decls (forall a. OrdList a -> [a]
fromOL OrdList (LHsDecl GhcPs)
fb)
forall (m :: * -> *) a. Monad m => a -> m a
return ([LHsDecl GhcPs]
-> (LHsBinds GhcPs, [LSig GhcPs], [LFamilyDecl GhcPs],
[LTyFamInstDecl GhcPs], [LDataFamInstDecl GhcPs], [LDocDecl GhcPs])
partitionBindsAndSigs ([LHsDecl GhcPs] -> [LHsDecl GhcPs]
getMonoBindAll [GenLocated SrcSpanAnnA (HsDecl GhcPs)]
fb'))
where
drop_bad_decls :: [GenLocated (SrcSpanAnn' a) (HsDecl GhcPs)]
-> m [GenLocated (SrcSpanAnn' a) (HsDecl GhcPs)]
drop_bad_decls [] = forall (m :: * -> *) a. Monad m => a -> m a
return []
drop_bad_decls (L SrcSpanAnn' a
l (SpliceD XSpliceD GhcPs
_ SpliceDecl GhcPs
d) : [GenLocated (SrcSpanAnn' a) (HsDecl GhcPs)]
ds) = do
forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnn' a
l) forall a b. (a -> b) -> a -> b
$ SpliceDecl GhcPs -> PsMessage
PsErrDeclSpliceNotAtTopLevel SpliceDecl GhcPs
d
[GenLocated (SrcSpanAnn' a) (HsDecl GhcPs)]
-> m [GenLocated (SrcSpanAnn' a) (HsDecl GhcPs)]
drop_bad_decls [GenLocated (SrcSpanAnn' a) (HsDecl GhcPs)]
ds
drop_bad_decls (GenLocated (SrcSpanAnn' a) (HsDecl GhcPs)
d:[GenLocated (SrcSpanAnn' a) (HsDecl GhcPs)]
ds) = (GenLocated (SrcSpanAnn' a) (HsDecl GhcPs)
dforall a. a -> [a] -> [a]
:) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [GenLocated (SrcSpanAnn' a) (HsDecl GhcPs)]
-> m [GenLocated (SrcSpanAnn' a) (HsDecl GhcPs)]
drop_bad_decls [GenLocated (SrcSpanAnn' a) (HsDecl GhcPs)]
ds
getMonoBind :: LHsBind GhcPs -> [LHsDecl GhcPs]
-> (LHsBind GhcPs, [LHsDecl GhcPs])
getMonoBind :: LHsBind GhcPs
-> [LHsDecl GhcPs] -> (LHsBind GhcPs, [LHsDecl GhcPs])
getMonoBind (L SrcSpanAnnA
loc1 (FunBind { fun_id :: forall idL idR. HsBindLR idL idR -> LIdP idL
fun_id = fun_id1 :: XRec GhcPs (IdP GhcPs)
fun_id1@(L SrcSpanAnnN
_ RdrName
f1)
, fun_matches :: forall idL idR. HsBindLR idL idR -> MatchGroup idR (LHsExpr idR)
fun_matches =
MG { mg_alts :: forall p body. MatchGroup p body -> XRec p [LMatch p body]
mg_alts = (L SrcSpanAnnL
_ m1 :: [GenLocated
SrcSpanAnnA (Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
m1@[L SrcSpanAnnA
_ Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mtchs1]) } }))
[LHsDecl GhcPs]
binds
| [LMatch GhcPs (LHsExpr GhcPs)] -> Bool
has_args [GenLocated
SrcSpanAnnA (Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
m1
= [LMatch GhcPs (LHsExpr GhcPs)]
-> SrcSpanAnnA
-> [LHsDecl GhcPs]
-> [LHsDecl GhcPs]
-> (LHsBind GhcPs, [LHsDecl GhcPs])
go [forall l e. l -> e -> GenLocated l e
L (forall ann. SrcAnn ann -> SrcAnn ann
removeCommentsA SrcSpanAnnA
loc1) Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mtchs1] (forall ann. Monoid ann => SrcAnn ann -> SrcAnn ann
commentsOnlyA SrcSpanAnnA
loc1) [LHsDecl GhcPs]
binds []
where
go :: [LMatch GhcPs (LHsExpr GhcPs)] -> SrcSpanAnnA
-> [LHsDecl GhcPs] -> [LHsDecl GhcPs]
-> (LHsBind GhcPs,[LHsDecl GhcPs])
go :: [LMatch GhcPs (LHsExpr GhcPs)]
-> SrcSpanAnnA
-> [LHsDecl GhcPs]
-> [LHsDecl GhcPs]
-> (LHsBind GhcPs, [LHsDecl GhcPs])
go [LMatch GhcPs (LHsExpr GhcPs)]
mtchs SrcSpanAnnA
loc
((L SrcSpanAnnA
loc2 (ValD XValD GhcPs
_ (FunBind { fun_id :: forall idL idR. HsBindLR idL idR -> LIdP idL
fun_id = (L SrcSpanAnnN
_ RdrName
f2)
, fun_matches :: forall idL idR. HsBindLR idL idR -> MatchGroup idR (LHsExpr idR)
fun_matches =
MG { mg_alts :: forall p body. MatchGroup p body -> XRec p [LMatch p body]
mg_alts = (L SrcSpanAnnL
_ [L SrcSpanAnnA
lm2 Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mtchs2]) } })))
: [LHsDecl GhcPs]
binds) [LHsDecl GhcPs]
_
| RdrName
f1 forall a. Eq a => a -> a -> Bool
== RdrName
f2 =
let (SrcSpanAnnA
loc2', SrcSpanAnnA
lm2') = SrcSpanAnnA -> SrcSpanAnnA -> (SrcSpanAnnA, SrcSpanAnnA)
transferAnnsA SrcSpanAnnA
loc2 SrcSpanAnnA
lm2
in [LMatch GhcPs (LHsExpr GhcPs)]
-> SrcSpanAnnA
-> [LHsDecl GhcPs]
-> [LHsDecl GhcPs]
-> (LHsBind GhcPs, [LHsDecl GhcPs])
go (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
lm2' Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mtchs2 forall a. a -> [a] -> [a]
: [LMatch GhcPs (LHsExpr GhcPs)]
mtchs)
(forall a. Semigroup a => SrcAnn a -> SrcAnn a -> SrcAnn a
combineSrcSpansA SrcSpanAnnA
loc SrcSpanAnnA
loc2') [LHsDecl GhcPs]
binds []
go [LMatch GhcPs (LHsExpr GhcPs)]
mtchs SrcSpanAnnA
loc (doc_decl :: LHsDecl GhcPs
doc_decl@(L SrcSpanAnnA
loc2 (DocD {})) : [LHsDecl GhcPs]
binds) [LHsDecl GhcPs]
doc_decls
= let doc_decls' :: [GenLocated SrcSpanAnnA (HsDecl GhcPs)]
doc_decls' = LHsDecl GhcPs
doc_decl forall a. a -> [a] -> [a]
: [LHsDecl GhcPs]
doc_decls
in [LMatch GhcPs (LHsExpr GhcPs)]
-> SrcSpanAnnA
-> [LHsDecl GhcPs]
-> [LHsDecl GhcPs]
-> (LHsBind GhcPs, [LHsDecl GhcPs])
go [LMatch GhcPs (LHsExpr GhcPs)]
mtchs (forall a. Semigroup a => SrcAnn a -> SrcAnn a -> SrcAnn a
combineSrcSpansA SrcSpanAnnA
loc SrcSpanAnnA
loc2) [LHsDecl GhcPs]
binds [GenLocated SrcSpanAnnA (HsDecl GhcPs)]
doc_decls'
go [LMatch GhcPs (LHsExpr GhcPs)]
mtchs SrcSpanAnnA
loc [LHsDecl GhcPs]
binds [LHsDecl GhcPs]
doc_decls
= ( forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc (GenLocated SrcSpanAnnN RdrName
-> LocatedL [LMatch GhcPs (LHsExpr GhcPs)] -> HsBindLR GhcPs GhcPs
makeFunBind XRec GhcPs (IdP GhcPs)
fun_id1 (forall a e2 an.
Semigroup a =>
[GenLocated (SrcAnn a) e2]
-> LocatedAn an [GenLocated (SrcAnn a) e2]
mkLocatedList forall a b. (a -> b) -> a -> b
$ forall a. [a] -> [a]
reverse [LMatch GhcPs (LHsExpr GhcPs)]
mtchs))
, (forall a. [a] -> [a]
reverse [LHsDecl GhcPs]
doc_decls) forall a. [a] -> [a] -> [a]
++ [LHsDecl GhcPs]
binds)
getMonoBind LHsBind GhcPs
bind [LHsDecl GhcPs]
binds = (LHsBind GhcPs
bind, [LHsDecl GhcPs]
binds)
getMonoBindAll :: [LHsDecl GhcPs] -> [LHsDecl GhcPs]
getMonoBindAll :: [LHsDecl GhcPs] -> [LHsDecl GhcPs]
getMonoBindAll [] = []
getMonoBindAll (L SrcSpanAnnA
l (ValD XValD GhcPs
_ HsBindLR GhcPs GhcPs
b) : [LHsDecl GhcPs]
ds) =
let (L SrcSpanAnnA
l' HsBindLR GhcPs GhcPs
b', [LHsDecl GhcPs]
ds') = LHsBind GhcPs
-> [LHsDecl GhcPs] -> (LHsBind GhcPs, [LHsDecl GhcPs])
getMonoBind (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l HsBindLR GhcPs GhcPs
b) [LHsDecl GhcPs]
ds
in forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l' (forall p. XValD p -> HsBind p -> HsDecl p
ValD NoExtField
noExtField HsBindLR GhcPs GhcPs
b') forall a. a -> [a] -> [a]
: [LHsDecl GhcPs] -> [LHsDecl GhcPs]
getMonoBindAll [LHsDecl GhcPs]
ds'
getMonoBindAll (LHsDecl GhcPs
d : [LHsDecl GhcPs]
ds) = LHsDecl GhcPs
d forall a. a -> [a] -> [a]
: [LHsDecl GhcPs] -> [LHsDecl GhcPs]
getMonoBindAll [LHsDecl GhcPs]
ds
has_args :: [LMatch GhcPs (LHsExpr GhcPs)] -> Bool
has_args :: [LMatch GhcPs (LHsExpr GhcPs)] -> Bool
has_args [] = forall a. HasCallStack => String -> a
panic String
"GHC.Parser.PostProcess.has_args"
has_args (L SrcSpanAnnA
_ (Match { m_pats :: forall p body. Match p body -> [LPat p]
m_pats = [LPat GhcPs]
args }) : [LMatch GhcPs (LHsExpr GhcPs)]
_) = Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LPat GhcPs]
args)
tyConToDataCon :: LocatedN RdrName -> Either (MsgEnvelope PsMessage) (LocatedN RdrName)
tyConToDataCon :: GenLocated SrcSpanAnnN RdrName
-> Either (MsgEnvelope PsMessage) (GenLocated SrcSpanAnnN RdrName)
tyConToDataCon (L SrcSpanAnnN
loc RdrName
tc)
| String -> Bool
okConOcc (OccName -> String
occNameString OccName
occ)
= forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
loc (RdrName -> NameSpace -> RdrName
setRdrNameSpace RdrName
tc NameSpace
srcDataName))
| Bool
otherwise
= forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnN
loc) forall a b. (a -> b) -> a -> b
$ (RdrName -> PsMessage
PsErrNotADataCon RdrName
tc)
where
occ :: OccName
occ = RdrName -> OccName
rdrNameOcc RdrName
tc
mkPatSynMatchGroup :: LocatedN RdrName
-> LocatedL (OrdList (LHsDecl GhcPs))
-> P (MatchGroup GhcPs (LHsExpr GhcPs))
mkPatSynMatchGroup :: GenLocated SrcSpanAnnN RdrName
-> LocatedL (OrdList (LHsDecl GhcPs))
-> P (MatchGroup GhcPs (LHsExpr GhcPs))
mkPatSynMatchGroup (L SrcSpanAnnN
loc RdrName
patsyn_name) (L SrcSpanAnnL
ld OrdList (LHsDecl GhcPs)
decls) =
do { [GenLocated
SrcSpanAnnA (Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
matches <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM GenLocated SrcSpanAnnA (HsDecl GhcPs)
-> P (GenLocated
SrcSpanAnnA (Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
fromDecl (forall a. OrdList a -> [a]
fromOL OrdList (LHsDecl GhcPs)
decls)
; forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [GenLocated
SrcSpanAnnA (Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
matches) (SrcSpan -> P ()
wrongNumberErr (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnN
loc))
; forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall (p :: Pass) (body :: * -> *).
AnnoBody p body =>
Origin
-> LocatedL
[LocatedA (Match (GhcPass p) (LocatedA (body (GhcPass p))))]
-> MatchGroup (GhcPass p) (LocatedA (body (GhcPass p)))
mkMatchGroup Origin
FromSource (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnL
ld [GenLocated
SrcSpanAnnA (Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
matches) }
where
fromDecl :: GenLocated SrcSpanAnnA (HsDecl GhcPs)
-> P (GenLocated
SrcSpanAnnA (Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
fromDecl (L SrcSpanAnnA
loc decl :: HsDecl GhcPs
decl@(ValD XValD GhcPs
_ (PatBind XPatBind GhcPs GhcPs
_
pat :: LPat GhcPs
pat@(L SrcSpanAnnA
_ (ConPat XConPat GhcPs
noAnn ln :: XRec GhcPs (ConLikeP GhcPs)
ln@(L SrcSpanAnnN
_ RdrName
name) HsConPatDetails GhcPs
details))
GRHSs GhcPs (LHsExpr GhcPs)
rhs))) =
do { forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (RdrName
name forall a. Eq a => a -> a -> Bool
== RdrName
patsyn_name) forall a b. (a -> b) -> a -> b
$
SrcSpan -> HsDecl GhcPs -> P ()
wrongNameBindingErr (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc) HsDecl GhcPs
decl
; Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
match <- case HsConPatDetails GhcPs
details of
PrefixCon [HsConPatTyArg (NoGhcTc GhcPs)]
_ [LPat GhcPs]
pats -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Match { m_ext :: XCMatch GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
m_ext = XConPat GhcPs
noAnn
, m_ctxt :: HsMatchContext GhcPs
m_ctxt = HsMatchContext GhcPs
ctxt, m_pats :: [LPat GhcPs]
m_pats = [LPat GhcPs]
pats
, m_grhss :: GRHSs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
m_grhss = GRHSs GhcPs (LHsExpr GhcPs)
rhs }
where
ctxt :: HsMatchContext GhcPs
ctxt = FunRhs { mc_fun :: LIdP (NoGhcTc GhcPs)
mc_fun = XRec GhcPs (ConLikeP GhcPs)
ln
, mc_fixity :: LexicalFixity
mc_fixity = LexicalFixity
Prefix
, mc_strictness :: SrcStrictness
mc_strictness = SrcStrictness
NoSrcStrict }
InfixCon LPat GhcPs
p1 LPat GhcPs
p2 -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Match { m_ext :: XCMatch GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
m_ext = XConPat GhcPs
noAnn
, m_ctxt :: HsMatchContext GhcPs
m_ctxt = HsMatchContext GhcPs
ctxt
, m_pats :: [LPat GhcPs]
m_pats = [LPat GhcPs
p1, LPat GhcPs
p2]
, m_grhss :: GRHSs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
m_grhss = GRHSs GhcPs (LHsExpr GhcPs)
rhs }
where
ctxt :: HsMatchContext GhcPs
ctxt = FunRhs { mc_fun :: LIdP (NoGhcTc GhcPs)
mc_fun = XRec GhcPs (ConLikeP GhcPs)
ln
, mc_fixity :: LexicalFixity
mc_fixity = LexicalFixity
Infix
, mc_strictness :: SrcStrictness
mc_strictness = SrcStrictness
NoSrcStrict }
RecCon{} -> forall a. SrcSpan -> LPat GhcPs -> P a
recordPatSynErr (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc) LPat GhcPs
pat
; forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
match }
fromDecl (L SrcSpanAnnA
loc HsDecl GhcPs
decl) = SrcSpan
-> HsDecl GhcPs
-> P (GenLocated
SrcSpanAnnA (Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
extraDeclErr (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc) HsDecl GhcPs
decl
extraDeclErr :: SrcSpan
-> HsDecl GhcPs
-> P (GenLocated
SrcSpanAnnA (Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))))
extraDeclErr SrcSpan
loc HsDecl GhcPs
decl =
forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
loc forall a b. (a -> b) -> a -> b
$
(RdrName -> HsDecl GhcPs -> PsMessage
PsErrNoSingleWhereBindInPatSynDecl RdrName
patsyn_name HsDecl GhcPs
decl)
wrongNameBindingErr :: SrcSpan -> HsDecl GhcPs -> P ()
wrongNameBindingErr SrcSpan
loc HsDecl GhcPs
decl =
forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
loc forall a b. (a -> b) -> a -> b
$
(RdrName -> HsDecl GhcPs -> PsMessage
PsErrInvalidWhereBindInPatSynDecl RdrName
patsyn_name HsDecl GhcPs
decl)
wrongNumberErr :: SrcSpan -> P ()
wrongNumberErr SrcSpan
loc =
forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
loc forall a b. (a -> b) -> a -> b
$
(RdrName -> PsMessage
PsErrEmptyWhereInPatSynDecl RdrName
patsyn_name)
recordPatSynErr :: SrcSpan -> LPat GhcPs -> P a
recordPatSynErr :: forall a. SrcSpan -> LPat GhcPs -> P a
recordPatSynErr SrcSpan
loc LPat GhcPs
pat =
forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
loc forall a b. (a -> b) -> a -> b
$
(LPat GhcPs -> PsMessage
PsErrRecordSyntaxInPatSynDecl LPat GhcPs
pat)
mkConDeclH98 :: EpAnn [AddEpAnn] -> LocatedN RdrName -> Maybe [LHsTyVarBndr Specificity GhcPs]
-> Maybe (LHsContext GhcPs) -> HsConDeclH98Details GhcPs
-> ConDecl GhcPs
mkConDeclH98 :: EpAnn [AddEpAnn]
-> GenLocated SrcSpanAnnN RdrName
-> Maybe [LHsTyVarBndr Specificity GhcPs]
-> Maybe (LHsContext GhcPs)
-> HsConDeclH98Details GhcPs
-> ConDecl GhcPs
mkConDeclH98 EpAnn [AddEpAnn]
ann GenLocated SrcSpanAnnN RdrName
name Maybe [LHsTyVarBndr Specificity GhcPs]
mb_forall Maybe (LHsContext GhcPs)
mb_cxt HsConDeclH98Details GhcPs
args
= ConDeclH98 { con_ext :: XConDeclH98 GhcPs
con_ext = EpAnn [AddEpAnn]
ann
, con_name :: XRec GhcPs (IdP GhcPs)
con_name = GenLocated SrcSpanAnnN RdrName
name
, con_forall :: Bool
con_forall = forall a. Maybe a -> Bool
isJust Maybe [LHsTyVarBndr Specificity GhcPs]
mb_forall
, con_ex_tvs :: [LHsTyVarBndr Specificity GhcPs]
con_ex_tvs = Maybe [LHsTyVarBndr Specificity GhcPs]
mb_forall forall a. Maybe a -> a -> a
`orElse` []
, con_mb_cxt :: Maybe (LHsContext GhcPs)
con_mb_cxt = Maybe (LHsContext GhcPs)
mb_cxt
, con_args :: HsConDeclH98Details GhcPs
con_args = HsConDeclH98Details GhcPs
args
, con_doc :: Maybe (LHsDoc GhcPs)
con_doc = forall a. Maybe a
Nothing }
mkGadtDecl :: SrcSpan
-> NonEmpty (LocatedN RdrName)
-> LHsUniToken "::" "∷" GhcPs
-> LHsSigType GhcPs
-> P (LConDecl GhcPs)
mkGadtDecl :: SrcSpan
-> NonEmpty (GenLocated SrcSpanAnnN RdrName)
-> LHsUniToken "::" "\8759" GhcPs
-> LHsSigType GhcPs
-> P (LConDecl GhcPs)
mkGadtDecl SrcSpan
loc NonEmpty (GenLocated SrcSpanAnnN RdrName)
names LHsUniToken "::" "\8759" GhcPs
dcol LHsSigType GhcPs
ty = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
loc
let l :: SrcSpanAnnA
l = forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
loc
(HsConDeclGADTDetails GhcPs
args, GenLocated SrcSpanAnnA (HsType GhcPs)
res_ty, [AddEpAnn]
annsa, EpAnnComments
csa) <-
case LHsType GhcPs
body_ty of
L SrcSpanAnnA
ll (HsFunTy XFunTy GhcPs
af HsArrow GhcPs
hsArr (L SrcSpanAnnA
loc' (HsRecTy XRecTy GhcPs
an [LConDeclField GhcPs]
rf)) LHsType GhcPs
res_ty) -> do
let an' :: EpAnn AnnList
an' = forall a.
Monoid a =>
SrcSpan -> EpAnn a -> EpAnnComments -> EpAnn a
addCommentsToEpAnn (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc') XRecTy GhcPs
an (forall ann. EpAnn ann -> EpAnnComments
comments XFunTy GhcPs
af)
GenLocated TokenLocation (HsUniToken "->" "\8594")
arr <- case HsArrow GhcPs
hsArr of
HsUnrestrictedArrow LHsUniToken "->" "\8594" GhcPs
arr -> forall (m :: * -> *) a. Monad m => a -> m a
return LHsUniToken "->" "\8594" GhcPs
arr
HsArrow GhcPs
_ -> do forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
getLocA LHsType GhcPs
body_ty) forall a b. (a -> b) -> a -> b
$
(HsArrow GhcPs -> PsMessage
PsErrIllegalGadtRecordMultiplicity HsArrow GhcPs
hsArr)
forall (m :: * -> *) a. Monad m => a -> m a
return forall (tok :: Symbol) (utok :: Symbol).
GenLocated TokenLocation (HsUniToken tok utok)
noHsUniTok
forall (m :: * -> *) a. Monad m => a -> m a
return ( forall pass.
XRec pass [LConDeclField pass]
-> LHsUniToken "->" "\8594" pass -> HsConDeclGADTDetails pass
RecConGADT (forall l e. l -> e -> GenLocated l e
L (forall a. a -> SrcSpan -> SrcSpanAnn' a
SrcSpanAnn EpAnn AnnList
an' (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc')) [LConDeclField GhcPs]
rf) GenLocated TokenLocation (HsUniToken "->" "\8594")
arr, LHsType GhcPs
res_ty
, [], forall ann. EpAnn ann -> EpAnnComments
epAnnComments (forall a. SrcSpanAnn' a -> a
ann SrcSpanAnnA
ll))
LHsType GhcPs
_ -> do
let ([AddEpAnn]
anns, EpAnnComments
cs, [HsScaled GhcPs (LHsType GhcPs)]
arg_types, LHsType GhcPs
res_type) = forall (p :: Pass).
LHsType (GhcPass p)
-> ([AddEpAnn], EpAnnComments,
[HsScaled (GhcPass p) (LHsType (GhcPass p))], LHsType (GhcPass p))
splitHsFunType LHsType GhcPs
body_ty
forall (m :: * -> *) a. Monad m => a -> m a
return (forall pass.
[HsScaled pass (LBangType pass)] -> HsConDeclGADTDetails pass
PrefixConGADT [HsScaled GhcPs (LHsType GhcPs)]
arg_types, LHsType GhcPs
res_type, [AddEpAnn]
anns, EpAnnComments
cs)
let an :: EpAnn [AddEpAnn]
an = forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
loc) [AddEpAnn]
annsa (EpAnnComments
cs forall a. Semigroup a => a -> a -> a
Semi.<> EpAnnComments
csa)
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l ConDeclGADT
{ con_g_ext :: XConDeclGADT GhcPs
con_g_ext = EpAnn [AddEpAnn]
an
, con_names :: NonEmpty (XRec GhcPs (IdP GhcPs))
con_names = NonEmpty (GenLocated SrcSpanAnnN RdrName)
names
, con_dcolon :: LHsUniToken "::" "\8759" GhcPs
con_dcolon = LHsUniToken "::" "\8759" GhcPs
dcol
, con_bndrs :: XRec GhcPs (HsOuterSigTyVarBndrs GhcPs)
con_bndrs = forall l e. l -> e -> GenLocated l e
L (forall l e. GenLocated l e -> l
getLoc LHsSigType GhcPs
ty) HsOuterSigTyVarBndrs GhcPs
outer_bndrs
, con_mb_cxt :: Maybe (LHsContext GhcPs)
con_mb_cxt = Maybe (LHsContext GhcPs)
mcxt
, con_g_args :: HsConDeclGADTDetails GhcPs
con_g_args = HsConDeclGADTDetails GhcPs
args
, con_res_ty :: LHsType GhcPs
con_res_ty = GenLocated SrcSpanAnnA (HsType GhcPs)
res_ty
, con_doc :: Maybe (LHsDoc GhcPs)
con_doc = forall a. Maybe a
Nothing }
where
(HsOuterSigTyVarBndrs GhcPs
outer_bndrs, Maybe (LHsContext GhcPs)
mcxt, LHsType GhcPs
body_ty) = LHsSigType GhcPs
-> (HsOuterSigTyVarBndrs GhcPs, Maybe (LHsContext GhcPs),
LHsType GhcPs)
splitLHsGadtTy LHsSigType GhcPs
ty
setRdrNameSpace :: RdrName -> NameSpace -> RdrName
setRdrNameSpace :: RdrName -> NameSpace -> RdrName
setRdrNameSpace (Unqual OccName
occ) NameSpace
ns = OccName -> RdrName
Unqual (NameSpace -> OccName -> OccName
setOccNameSpace NameSpace
ns OccName
occ)
setRdrNameSpace (Qual ModuleName
m OccName
occ) NameSpace
ns = ModuleName -> OccName -> RdrName
Qual ModuleName
m (NameSpace -> OccName -> OccName
setOccNameSpace NameSpace
ns OccName
occ)
setRdrNameSpace (Orig Module
m OccName
occ) NameSpace
ns = Module -> OccName -> RdrName
Orig Module
m (NameSpace -> OccName -> OccName
setOccNameSpace NameSpace
ns OccName
occ)
setRdrNameSpace (Exact Name
n) NameSpace
ns
| Just TyThing
thing <- Name -> Maybe TyThing
wiredInNameTyThing_maybe Name
n
= TyThing -> NameSpace -> RdrName
setWiredInNameSpace TyThing
thing NameSpace
ns
| Name -> Bool
isExternalName Name
n
= Module -> OccName -> RdrName
Orig (HasDebugCallStack => Name -> Module
nameModule Name
n) OccName
occ
| Bool
otherwise
= Name -> RdrName
Exact (Unique -> OccName -> SrcSpan -> Name
mkSystemNameAt (Name -> Unique
nameUnique Name
n) OccName
occ (Name -> SrcSpan
nameSrcSpan Name
n))
where
occ :: OccName
occ = NameSpace -> OccName -> OccName
setOccNameSpace NameSpace
ns (Name -> OccName
nameOccName Name
n)
setWiredInNameSpace :: TyThing -> NameSpace -> RdrName
setWiredInNameSpace :: TyThing -> NameSpace -> RdrName
setWiredInNameSpace (ATyCon TyCon
tc) NameSpace
ns
| NameSpace -> Bool
isDataConNameSpace NameSpace
ns
= TyCon -> RdrName
ty_con_data_con TyCon
tc
| NameSpace -> Bool
isTcClsNameSpace NameSpace
ns
= Name -> RdrName
Exact (forall a. NamedThing a => a -> Name
getName TyCon
tc)
setWiredInNameSpace (AConLike (RealDataCon DataCon
dc)) NameSpace
ns
| NameSpace -> Bool
isTcClsNameSpace NameSpace
ns
= DataCon -> RdrName
data_con_ty_con DataCon
dc
| NameSpace -> Bool
isDataConNameSpace NameSpace
ns
= Name -> RdrName
Exact (forall a. NamedThing a => a -> Name
getName DataCon
dc)
setWiredInNameSpace TyThing
thing NameSpace
ns
= forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"setWiredinNameSpace" (NameSpace -> SDoc
pprNameSpace NameSpace
ns forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr TyThing
thing)
ty_con_data_con :: TyCon -> RdrName
ty_con_data_con :: TyCon -> RdrName
ty_con_data_con TyCon
tc
| TyCon -> Bool
isTupleTyCon TyCon
tc
, Just DataCon
dc <- TyCon -> Maybe DataCon
tyConSingleDataCon_maybe TyCon
tc
= Name -> RdrName
Exact (forall a. NamedThing a => a -> Name
getName DataCon
dc)
| TyCon
tc forall a. Uniquable a => a -> Unique -> Bool
`hasKey` Unique
listTyConKey
= Name -> RdrName
Exact Name
nilDataConName
| Bool
otherwise
= OccName -> RdrName
Unqual (NameSpace -> OccName -> OccName
setOccNameSpace NameSpace
srcDataName (forall a. NamedThing a => a -> OccName
getOccName TyCon
tc))
data_con_ty_con :: DataCon -> RdrName
data_con_ty_con :: DataCon -> RdrName
data_con_ty_con DataCon
dc
| let tc :: TyCon
tc = DataCon -> TyCon
dataConTyCon DataCon
dc
, TyCon -> Bool
isTupleTyCon TyCon
tc
= Name -> RdrName
Exact (forall a. NamedThing a => a -> Name
getName TyCon
tc)
| DataCon
dc forall a. Uniquable a => a -> Unique -> Bool
`hasKey` Unique
nilDataConKey
= Name -> RdrName
Exact Name
listTyConName
| Bool
otherwise
= OccName -> RdrName
Unqual (NameSpace -> OccName -> OccName
setOccNameSpace NameSpace
tcClsName (forall a. NamedThing a => a -> OccName
getOccName DataCon
dc))
eitherToP :: MonadP m => Either (MsgEnvelope PsMessage) a -> m a
eitherToP :: forall (m :: * -> *) a.
MonadP m =>
Either (MsgEnvelope PsMessage) a -> m a
eitherToP (Left MsgEnvelope PsMessage
err) = forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError MsgEnvelope PsMessage
err
eitherToP (Right a
thing) = forall (m :: * -> *) a. Monad m => a -> m a
return a
thing
checkTyVars :: SDoc -> SDoc -> LocatedN RdrName -> [LHsTypeArg GhcPs]
-> P (LHsQTyVars GhcPs)
checkTyVars :: SDoc
-> SDoc
-> GenLocated SrcSpanAnnN RdrName
-> [LHsTypeArg GhcPs]
-> P (LHsQTyVars GhcPs)
checkTyVars SDoc
pp_what SDoc
equals_or_where GenLocated SrcSpanAnnN RdrName
tc [LHsTypeArg GhcPs]
tparms
= do { [GenLocated SrcSpanAnnA (HsTyVarBndr () GhcPs)]
tvs <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM HsArg
(GenLocated SrcSpanAnnA (HsType GhcPs))
(GenLocated SrcSpanAnnA (HsType GhcPs))
-> P (GenLocated SrcSpanAnnA (HsTyVarBndr () GhcPs))
check [LHsTypeArg GhcPs]
tparms
; forall (m :: * -> *) a. Monad m => a -> m a
return ([LHsTyVarBndr () GhcPs] -> LHsQTyVars GhcPs
mkHsQTvs [GenLocated SrcSpanAnnA (HsTyVarBndr () GhcPs)]
tvs) }
where
check :: HsArg
(GenLocated SrcSpanAnnA (HsType GhcPs))
(GenLocated SrcSpanAnnA (HsType GhcPs))
-> P (GenLocated SrcSpanAnnA (HsTyVarBndr () GhcPs))
check (HsTypeArg SrcSpan
_ ki :: GenLocated SrcSpanAnnA (HsType GhcPs)
ki@(L SrcSpanAnnA
loc HsType GhcPs
_)) = forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc) forall a b. (a -> b) -> a -> b
$
(LHsType GhcPs -> SDoc -> RdrName -> PsMessage
PsErrUnexpectedTypeAppInDecl GenLocated SrcSpanAnnA (HsType GhcPs)
ki SDoc
pp_what (forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnN RdrName
tc))
check (HsValArg GenLocated SrcSpanAnnA (HsType GhcPs)
ty) = [AddEpAnn]
-> [AddEpAnn]
-> EpAnnComments
-> LHsType GhcPs
-> P (LHsTyVarBndr () GhcPs)
chkParens [] [] EpAnnComments
emptyComments GenLocated SrcSpanAnnA (HsType GhcPs)
ty
check (HsArgPar SrcSpan
sp) = forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
sp forall a b. (a -> b) -> a -> b
$
(SDoc -> RdrName -> PsMessage
PsErrMalformedDecl SDoc
pp_what (forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnN RdrName
tc))
chkParens :: [AddEpAnn] -> [AddEpAnn] -> EpAnnComments -> LHsType GhcPs
-> P (LHsTyVarBndr () GhcPs)
chkParens :: [AddEpAnn]
-> [AddEpAnn]
-> EpAnnComments
-> LHsType GhcPs
-> P (LHsTyVarBndr () GhcPs)
chkParens [AddEpAnn]
ops [AddEpAnn]
cps EpAnnComments
cs (L SrcSpanAnnA
l (HsParTy XParTy GhcPs
an LHsType GhcPs
ty))
= let
(AddEpAnn
o,AddEpAnn
c) = RealSrcSpan -> (AddEpAnn, AddEpAnn)
mkParensEpAnn (SrcSpan -> RealSrcSpan
realSrcSpan forall a b. (a -> b) -> a -> b
$ forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l)
in
[AddEpAnn]
-> [AddEpAnn]
-> EpAnnComments
-> LHsType GhcPs
-> P (LHsTyVarBndr () GhcPs)
chkParens (AddEpAnn
oforall a. a -> [a] -> [a]
:[AddEpAnn]
ops) (AddEpAnn
cforall a. a -> [a] -> [a]
:[AddEpAnn]
cps) (EpAnnComments
cs forall a. Semigroup a => a -> a -> a
Semi.<> forall ann. EpAnn ann -> EpAnnComments
epAnnComments XParTy GhcPs
an) LHsType GhcPs
ty
chkParens [AddEpAnn]
ops [AddEpAnn]
cps EpAnnComments
cs LHsType GhcPs
ty = [AddEpAnn]
-> [AddEpAnn]
-> EpAnnComments
-> LHsType GhcPs
-> P (LHsTyVarBndr () GhcPs)
chk [AddEpAnn]
ops [AddEpAnn]
cps EpAnnComments
cs LHsType GhcPs
ty
chk :: [AddEpAnn] -> [AddEpAnn] -> EpAnnComments -> LHsType GhcPs -> P (LHsTyVarBndr () GhcPs)
chk :: [AddEpAnn]
-> [AddEpAnn]
-> EpAnnComments
-> LHsType GhcPs
-> P (LHsTyVarBndr () GhcPs)
chk [AddEpAnn]
ops [AddEpAnn]
cps EpAnnComments
cs (L SrcSpanAnnA
l (HsKindSig XKindSig GhcPs
annk (L SrcSpanAnnA
annt (HsTyVar XTyVar GhcPs
ann PromotionFlag
_ (L SrcSpanAnnN
lv RdrName
tv))) LHsType GhcPs
k))
| RdrName -> Bool
isRdrTyVar RdrName
tv
= let
an :: [AddEpAnn]
an = (forall a. [a] -> [a]
reverse [AddEpAnn]
ops) forall a. [a] -> [a] -> [a]
++ [AddEpAnn]
cps
in
forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L (forall an. SrcSpanAnn' an -> [AddEpAnn] -> SrcSpanAnn' an
widenLocatedAn (SrcSpanAnnA
l forall a. Semigroup a => a -> a -> a
Semi.<> SrcSpanAnnA
annt) [AddEpAnn]
an)
(forall flag pass.
XKindedTyVar pass
-> flag -> LIdP pass -> LHsKind pass -> HsTyVarBndr flag pass
KindedTyVar (EpAnn [AddEpAnn] -> [AddEpAnn] -> EpAnnComments -> EpAnn [AddEpAnn]
addAnns (XKindSig GhcPs
annk forall a. Semigroup a => a -> a -> a
Semi.<> XTyVar GhcPs
ann) [AddEpAnn]
an EpAnnComments
cs) () (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
lv RdrName
tv) LHsType GhcPs
k))
chk [AddEpAnn]
ops [AddEpAnn]
cps EpAnnComments
cs (L SrcSpanAnnA
l (HsTyVar XTyVar GhcPs
ann PromotionFlag
_ (L SrcSpanAnnN
ltv RdrName
tv)))
| RdrName -> Bool
isRdrTyVar RdrName
tv
= let
an :: [AddEpAnn]
an = (forall a. [a] -> [a]
reverse [AddEpAnn]
ops) forall a. [a] -> [a] -> [a]
++ [AddEpAnn]
cps
in
forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L (forall an. SrcSpanAnn' an -> [AddEpAnn] -> SrcSpanAnn' an
widenLocatedAn SrcSpanAnnA
l [AddEpAnn]
an)
(forall flag pass.
XUserTyVar pass -> flag -> LIdP pass -> HsTyVarBndr flag pass
UserTyVar (EpAnn [AddEpAnn] -> [AddEpAnn] -> EpAnnComments -> EpAnn [AddEpAnn]
addAnns XTyVar GhcPs
ann [AddEpAnn]
an EpAnnComments
cs) () (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
ltv RdrName
tv)))
chk [AddEpAnn]
_ [AddEpAnn]
_ EpAnnComments
_ t :: LHsType GhcPs
t@(L SrcSpanAnnA
loc HsType GhcPs
_)
= forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc) forall a b. (a -> b) -> a -> b
$
(LHsType GhcPs
-> SDoc -> RdrName -> [LHsTypeArg GhcPs] -> SDoc -> PsMessage
PsErrUnexpectedTypeInDecl LHsType GhcPs
t SDoc
pp_what (forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnN RdrName
tc) [LHsTypeArg GhcPs]
tparms SDoc
equals_or_where)
whereDots, equalsDots :: SDoc
whereDots :: SDoc
whereDots = forall doc. IsLine doc => String -> doc
text String
"where ..."
equalsDots :: SDoc
equalsDots = forall doc. IsLine doc => String -> doc
text String
"= ..."
checkDatatypeContext :: Maybe (LHsContext GhcPs) -> P ()
checkDatatypeContext :: Maybe (LHsContext GhcPs) -> P ()
checkDatatypeContext Maybe (LHsContext GhcPs)
Nothing = forall (m :: * -> *) a. Monad m => a -> m a
return ()
checkDatatypeContext (Just LHsContext GhcPs
c)
= do Bool
allowed <- forall (m :: * -> *). MonadP m => ExtBits -> m Bool
getBit ExtBits
DatatypeContextsBit
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
allowed forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
getLocA LHsContext GhcPs
c) forall a b. (a -> b) -> a -> b
$
(LHsContext GhcPs -> PsMessage
PsErrIllegalDataTypeContext LHsContext GhcPs
c)
type LRuleTyTmVar = LocatedAn NoEpAnns RuleTyTmVar
data RuleTyTmVar = RuleTyTmVar (EpAnn [AddEpAnn]) (LocatedN RdrName) (Maybe (LHsType GhcPs))
mkRuleBndrs :: [LRuleTyTmVar] -> [LRuleBndr GhcPs]
mkRuleBndrs :: [LRuleTyTmVar] -> [LRuleBndr GhcPs]
mkRuleBndrs = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap RuleTyTmVar -> RuleBndr GhcPs
cvt_one)
where cvt_one :: RuleTyTmVar -> RuleBndr GhcPs
cvt_one (RuleTyTmVar EpAnn [AddEpAnn]
ann GenLocated SrcSpanAnnN RdrName
v Maybe (LHsType GhcPs)
Nothing) = forall pass. XCRuleBndr pass -> LIdP pass -> RuleBndr pass
RuleBndr EpAnn [AddEpAnn]
ann GenLocated SrcSpanAnnN RdrName
v
cvt_one (RuleTyTmVar EpAnn [AddEpAnn]
ann GenLocated SrcSpanAnnN RdrName
v (Just LHsType GhcPs
sig)) =
forall pass.
XRuleBndrSig pass
-> LIdP pass -> HsPatSigType pass -> RuleBndr pass
RuleBndrSig EpAnn [AddEpAnn]
ann GenLocated SrcSpanAnnN RdrName
v (EpAnnCO -> LHsType GhcPs -> HsPatSigType GhcPs
mkHsPatSigType forall a. EpAnn a
noAnn LHsType GhcPs
sig)
mkRuleTyVarBndrs :: [LRuleTyTmVar] -> [LHsTyVarBndr () GhcPs]
mkRuleTyVarBndrs :: [LRuleTyTmVar] -> [LHsTyVarBndr () GhcPs]
mkRuleTyVarBndrs = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {a} {ann}.
GenLocated (SrcSpanAnn' a) RuleTyTmVar
-> GenLocated (SrcAnn ann) (HsTyVarBndr () GhcPs)
cvt_one
where cvt_one :: GenLocated (SrcSpanAnn' a) RuleTyTmVar
-> GenLocated (SrcAnn ann) (HsTyVarBndr () GhcPs)
cvt_one (L SrcSpanAnn' a
l (RuleTyTmVar EpAnn [AddEpAnn]
ann GenLocated SrcSpanAnnN RdrName
v Maybe (LHsType GhcPs)
Nothing))
= forall l e. l -> e -> GenLocated l e
L (forall a ann. SrcSpanAnn' a -> SrcAnn ann
l2l SrcSpanAnn' a
l) (forall flag pass.
XUserTyVar pass -> flag -> LIdP pass -> HsTyVarBndr flag pass
UserTyVar EpAnn [AddEpAnn]
ann () (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap RdrName -> RdrName
tm_to_ty GenLocated SrcSpanAnnN RdrName
v))
cvt_one (L SrcSpanAnn' a
l (RuleTyTmVar EpAnn [AddEpAnn]
ann GenLocated SrcSpanAnnN RdrName
v (Just LHsType GhcPs
sig)))
= forall l e. l -> e -> GenLocated l e
L (forall a ann. SrcSpanAnn' a -> SrcAnn ann
l2l SrcSpanAnn' a
l) (forall flag pass.
XKindedTyVar pass
-> flag -> LIdP pass -> LHsKind pass -> HsTyVarBndr flag pass
KindedTyVar EpAnn [AddEpAnn]
ann () (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap RdrName -> RdrName
tm_to_ty GenLocated SrcSpanAnnN RdrName
v) LHsType GhcPs
sig)
tm_to_ty :: RdrName -> RdrName
tm_to_ty (Unqual OccName
occ) = OccName -> RdrName
Unqual (NameSpace -> OccName -> OccName
setOccNameSpace NameSpace
tvName OccName
occ)
tm_to_ty RdrName
_ = forall a. HasCallStack => String -> a
panic String
"mkRuleTyVarBndrs"
checkRuleTyVarBndrNames :: [LHsTyVarBndr flag GhcPs] -> P ()
checkRuleTyVarBndrNames :: forall flag. [LHsTyVarBndr flag GhcPs] -> P ()
checkRuleTyVarBndrNames = forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (forall {f :: * -> *} {a}.
MonadP f =>
GenLocated (SrcSpanAnn' a) RdrName -> f ()
check forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall flag (p :: Pass).
HsTyVarBndr flag (GhcPass p) -> IdP (GhcPass p)
hsTyVarName)
where check :: GenLocated (SrcSpanAnn' a) RdrName -> f ()
check (L SrcSpanAnn' a
loc (Unqual OccName
occ)) =
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (OccName -> FastString
occNameFS OccName
occ forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [String -> FastString
fsLit String
"forall",String -> FastString
fsLit String
"family",String -> FastString
fsLit String
"role"])
(forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnn' a
loc) forall a b. (a -> b) -> a -> b
$
(OccName -> PsMessage
PsErrParseErrorOnInput OccName
occ))
check GenLocated (SrcSpanAnn' a) RdrName
_ = forall a. HasCallStack => String -> a
panic String
"checkRuleTyVarBndrNames"
checkRecordSyntax :: (MonadP m, Outputable a) => LocatedA a -> m (LocatedA a)
checkRecordSyntax :: forall (m :: * -> *) a.
(MonadP m, Outputable a) =>
LocatedA a -> m (LocatedA a)
checkRecordSyntax lr :: LocatedA a
lr@(L SrcSpanAnnA
loc a
r)
= do Bool
allowed <- forall (m :: * -> *). MonadP m => ExtBits -> m Bool
getBit ExtBits
TraditionalRecordSyntaxBit
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
allowed forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc) forall a b. (a -> b) -> a -> b
$
(SDoc -> PsMessage
PsErrIllegalTraditionalRecordSyntax (forall a. Outputable a => a -> SDoc
ppr a
r))
forall (m :: * -> *) a. Monad m => a -> m a
return LocatedA a
lr
checkEmptyGADTs :: Located ([AddEpAnn], [LConDecl GhcPs])
-> P (Located ([AddEpAnn], [LConDecl GhcPs]))
checkEmptyGADTs :: Located ([AddEpAnn], [LConDecl GhcPs])
-> P (Located ([AddEpAnn], [LConDecl GhcPs]))
checkEmptyGADTs gadts :: Located ([AddEpAnn], [LConDecl GhcPs])
gadts@(L SrcSpan
span ([AddEpAnn]
_, []))
= do Bool
gadtSyntax <- forall (m :: * -> *). MonadP m => ExtBits -> m Bool
getBit ExtBits
GadtSyntaxBit
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
gadtSyntax forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
span forall a b. (a -> b) -> a -> b
$
PsMessage
PsErrIllegalWhereInDataDecl
forall (m :: * -> *) a. Monad m => a -> m a
return Located ([AddEpAnn], [LConDecl GhcPs])
gadts
checkEmptyGADTs Located ([AddEpAnn], [LConDecl GhcPs])
gadts = forall (m :: * -> *) a. Monad m => a -> m a
return Located ([AddEpAnn], [LConDecl GhcPs])
gadts
checkTyClHdr :: Bool
-> LHsType GhcPs
-> P (LocatedN RdrName,
[LHsTypeArg GhcPs],
LexicalFixity,
[AddEpAnn])
checkTyClHdr :: Bool
-> LHsType GhcPs
-> P (GenLocated SrcSpanAnnN RdrName, [LHsTypeArg GhcPs],
LexicalFixity, [AddEpAnn])
checkTyClHdr Bool
is_cls LHsType GhcPs
ty
= GenLocated SrcSpanAnnA (HsType GhcPs)
-> [LHsTypeArg GhcPs]
-> [AddEpAnn]
-> [AddEpAnn]
-> LexicalFixity
-> P (GenLocated SrcSpanAnnN RdrName, [LHsTypeArg GhcPs],
LexicalFixity, [AddEpAnn])
goL LHsType GhcPs
ty [] [] [] LexicalFixity
Prefix
where
goL :: GenLocated SrcSpanAnnA (HsType GhcPs)
-> [LHsTypeArg GhcPs]
-> [AddEpAnn]
-> [AddEpAnn]
-> LexicalFixity
-> P (GenLocated SrcSpanAnnN RdrName, [LHsTypeArg GhcPs],
LexicalFixity, [AddEpAnn])
goL (L SrcSpanAnnA
l HsType GhcPs
ty) [LHsTypeArg GhcPs]
acc [AddEpAnn]
ops [AddEpAnn]
cps LexicalFixity
fix = SrcSpan
-> HsType GhcPs
-> [LHsTypeArg GhcPs]
-> [AddEpAnn]
-> [AddEpAnn]
-> LexicalFixity
-> P (GenLocated SrcSpanAnnN RdrName, [LHsTypeArg GhcPs],
LexicalFixity, [AddEpAnn])
go (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) HsType GhcPs
ty [LHsTypeArg GhcPs]
acc [AddEpAnn]
ops [AddEpAnn]
cps LexicalFixity
fix
go :: SrcSpan
-> HsType GhcPs
-> [LHsTypeArg GhcPs]
-> [AddEpAnn]
-> [AddEpAnn]
-> LexicalFixity
-> P (GenLocated SrcSpanAnnN RdrName, [LHsTypeArg GhcPs],
LexicalFixity, [AddEpAnn])
go SrcSpan
_ (HsParTy XParTy GhcPs
an (L SrcSpanAnnA
l (HsStarTy XStarTy GhcPs
_ Bool
isUni))) [LHsTypeArg GhcPs]
acc [AddEpAnn]
ops' [AddEpAnn]
cps' LexicalFixity
fix
= do { SrcSpan -> PsMessage -> P ()
addPsMessage (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) PsMessage
PsWarnStarBinder
; let name :: OccName
name = NameSpace -> FastString -> OccName
mkOccNameFS NameSpace
tcClsName (Bool -> FastString
starSym Bool
isUni)
; let a' :: SrcSpanAnnN
a' = SrcSpanAnnA -> EpAnn AnnParen -> SrcSpanAnnN
newAnns SrcSpanAnnA
l XParTy GhcPs
an
; forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
a' (OccName -> RdrName
Unqual OccName
name), [LHsTypeArg GhcPs]
acc, LexicalFixity
fix
, (forall a. [a] -> [a]
reverse [AddEpAnn]
ops') forall a. [a] -> [a] -> [a]
++ [AddEpAnn]
cps') }
go SrcSpan
_ (HsTyVar XTyVar GhcPs
_ PromotionFlag
_ ltc :: XRec GhcPs (IdP GhcPs)
ltc@(L SrcSpanAnnN
_ RdrName
tc)) [LHsTypeArg GhcPs]
acc [AddEpAnn]
ops [AddEpAnn]
cps LexicalFixity
fix
| RdrName -> Bool
isRdrTc RdrName
tc = forall (m :: * -> *) a. Monad m => a -> m a
return (XRec GhcPs (IdP GhcPs)
ltc, [LHsTypeArg GhcPs]
acc, LexicalFixity
fix, (forall a. [a] -> [a]
reverse [AddEpAnn]
ops) forall a. [a] -> [a] -> [a]
++ [AddEpAnn]
cps)
go SrcSpan
_ (HsOpTy XOpTy GhcPs
_ PromotionFlag
_ LHsType GhcPs
t1 ltc :: XRec GhcPs (IdP GhcPs)
ltc@(L SrcSpanAnnN
_ RdrName
tc) LHsType GhcPs
t2) [LHsTypeArg GhcPs]
acc [AddEpAnn]
ops [AddEpAnn]
cps LexicalFixity
_fix
| RdrName -> Bool
isRdrTc RdrName
tc = forall (m :: * -> *) a. Monad m => a -> m a
return (XRec GhcPs (IdP GhcPs)
ltc, forall tm ty. tm -> HsArg tm ty
HsValArg LHsType GhcPs
t1forall a. a -> [a] -> [a]
:forall tm ty. tm -> HsArg tm ty
HsValArg LHsType GhcPs
t2forall a. a -> [a] -> [a]
:[LHsTypeArg GhcPs]
acc, LexicalFixity
Infix, (forall a. [a] -> [a]
reverse [AddEpAnn]
ops) forall a. [a] -> [a] -> [a]
++ [AddEpAnn]
cps)
go SrcSpan
l (HsParTy XParTy GhcPs
_ LHsType GhcPs
ty) [LHsTypeArg GhcPs]
acc [AddEpAnn]
ops [AddEpAnn]
cps LexicalFixity
fix = GenLocated SrcSpanAnnA (HsType GhcPs)
-> [LHsTypeArg GhcPs]
-> [AddEpAnn]
-> [AddEpAnn]
-> LexicalFixity
-> P (GenLocated SrcSpanAnnN RdrName, [LHsTypeArg GhcPs],
LexicalFixity, [AddEpAnn])
goL LHsType GhcPs
ty [LHsTypeArg GhcPs]
acc (AddEpAnn
oforall a. a -> [a] -> [a]
:[AddEpAnn]
ops) (AddEpAnn
cforall a. a -> [a] -> [a]
:[AddEpAnn]
cps) LexicalFixity
fix
where
(AddEpAnn
o,AddEpAnn
c) = RealSrcSpan -> (AddEpAnn, AddEpAnn)
mkParensEpAnn (SrcSpan -> RealSrcSpan
realSrcSpan SrcSpan
l)
go SrcSpan
_ (HsAppTy XAppTy GhcPs
_ LHsType GhcPs
t1 LHsType GhcPs
t2) [LHsTypeArg GhcPs]
acc [AddEpAnn]
ops [AddEpAnn]
cps LexicalFixity
fix = GenLocated SrcSpanAnnA (HsType GhcPs)
-> [LHsTypeArg GhcPs]
-> [AddEpAnn]
-> [AddEpAnn]
-> LexicalFixity
-> P (GenLocated SrcSpanAnnN RdrName, [LHsTypeArg GhcPs],
LexicalFixity, [AddEpAnn])
goL LHsType GhcPs
t1 (forall tm ty. tm -> HsArg tm ty
HsValArg LHsType GhcPs
t2forall a. a -> [a] -> [a]
:[LHsTypeArg GhcPs]
acc) [AddEpAnn]
ops [AddEpAnn]
cps LexicalFixity
fix
go SrcSpan
_ (HsAppKindTy XAppKindTy GhcPs
l LHsType GhcPs
ty LHsType GhcPs
ki) [LHsTypeArg GhcPs]
acc [AddEpAnn]
ops [AddEpAnn]
cps LexicalFixity
fix = GenLocated SrcSpanAnnA (HsType GhcPs)
-> [LHsTypeArg GhcPs]
-> [AddEpAnn]
-> [AddEpAnn]
-> LexicalFixity
-> P (GenLocated SrcSpanAnnN RdrName, [LHsTypeArg GhcPs],
LexicalFixity, [AddEpAnn])
goL LHsType GhcPs
ty (forall tm ty. SrcSpan -> ty -> HsArg tm ty
HsTypeArg XAppKindTy GhcPs
l LHsType GhcPs
kiforall a. a -> [a] -> [a]
:[LHsTypeArg GhcPs]
acc) [AddEpAnn]
ops [AddEpAnn]
cps LexicalFixity
fix
go SrcSpan
l (HsTupleTy XTupleTy GhcPs
_ HsTupleSort
HsBoxedOrConstraintTuple [LHsType GhcPs]
ts) [] [AddEpAnn]
ops [AddEpAnn]
cps LexicalFixity
fix
= forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (Name -> RdrName
nameRdrName Name
tup_name)
, forall a b. (a -> b) -> [a] -> [b]
map forall tm ty. tm -> HsArg tm ty
HsValArg [LHsType GhcPs]
ts, LexicalFixity
fix, (forall a. [a] -> [a]
reverse [AddEpAnn]
ops)forall a. [a] -> [a] -> [a]
++[AddEpAnn]
cps)
where
arity :: Int
arity = forall (t :: * -> *) a. Foldable t => t a -> Int
length [LHsType GhcPs]
ts
tup_name :: Name
tup_name | Bool
is_cls = Int -> Name
cTupleTyConName Int
arity
| Bool
otherwise = forall a. NamedThing a => a -> Name
getName (Boxity -> Int -> TyCon
tupleTyCon Boxity
Boxed Int
arity)
go SrcSpan
l HsType GhcPs
_ [LHsTypeArg GhcPs]
_ [AddEpAnn]
_ [AddEpAnn]
_ LexicalFixity
_
= forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
l forall a b. (a -> b) -> a -> b
$
(LHsType GhcPs -> PsMessage
PsErrMalformedTyOrClDecl LHsType GhcPs
ty)
newAnns :: SrcSpanAnnA -> EpAnn AnnParen -> SrcSpanAnnN
newAnns :: SrcSpanAnnA -> EpAnn AnnParen -> SrcSpanAnnN
newAnns (SrcSpanAnn EpAnn AnnListItem
EpAnnNotUsed SrcSpan
l) (EpAnn Anchor
as (AnnParen ParenType
_ EpaLocation
o EpaLocation
c) EpAnnComments
cs) =
let
lr :: RealSrcSpan
lr = RealSrcSpan -> RealSrcSpan -> RealSrcSpan
combineRealSrcSpans (SrcSpan -> RealSrcSpan
realSrcSpan SrcSpan
l) (Anchor -> RealSrcSpan
anchor Anchor
as)
an :: EpAnn NameAnn
an = (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (RealSrcSpan -> AnchorOperation -> Anchor
Anchor RealSrcSpan
lr AnchorOperation
UnchangedAnchor) (NameAdornment
-> EpaLocation
-> EpaLocation
-> EpaLocation
-> [TrailingAnn]
-> NameAnn
NameAnn NameAdornment
NameParens EpaLocation
o (SrcSpan -> EpaLocation
srcSpan2e SrcSpan
l) EpaLocation
c []) EpAnnComments
cs)
in forall a. a -> SrcSpan -> SrcSpanAnn' a
SrcSpanAnn EpAnn NameAnn
an (RealSrcSpan -> Maybe BufSpan -> SrcSpan
RealSrcSpan RealSrcSpan
lr forall a. Maybe a
Strict.Nothing)
newAnns SrcSpanAnnA
_ EpAnn AnnParen
EpAnnNotUsed = forall a. HasCallStack => String -> a
panic String
"missing AnnParen"
newAnns (SrcSpanAnn (EpAnn Anchor
ap (AnnListItem [TrailingAnn]
ta) EpAnnComments
csp) SrcSpan
l) (EpAnn Anchor
as (AnnParen ParenType
_ EpaLocation
o EpaLocation
c) EpAnnComments
cs) =
let
lr :: RealSrcSpan
lr = RealSrcSpan -> RealSrcSpan -> RealSrcSpan
combineRealSrcSpans (Anchor -> RealSrcSpan
anchor Anchor
ap) (Anchor -> RealSrcSpan
anchor Anchor
as)
an :: EpAnn NameAnn
an = (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (RealSrcSpan -> AnchorOperation -> Anchor
Anchor RealSrcSpan
lr AnchorOperation
UnchangedAnchor) (NameAdornment
-> EpaLocation
-> EpaLocation
-> EpaLocation
-> [TrailingAnn]
-> NameAnn
NameAnn NameAdornment
NameParens EpaLocation
o (SrcSpan -> EpaLocation
srcSpan2e SrcSpan
l) EpaLocation
c [TrailingAnn]
ta) (EpAnnComments
csp forall a. Semigroup a => a -> a -> a
Semi.<> EpAnnComments
cs))
in forall a. a -> SrcSpan -> SrcSpanAnn' a
SrcSpanAnn EpAnn NameAnn
an (RealSrcSpan -> Maybe BufSpan -> SrcSpan
RealSrcSpan RealSrcSpan
lr forall a. Maybe a
Strict.Nothing)
checkExpBlockArguments :: LHsExpr GhcPs -> PV ()
checkCmdBlockArguments :: LHsCmd GhcPs -> PV ()
(LHsExpr GhcPs -> PV ()
GenLocated SrcSpanAnnA (HsExpr GhcPs) -> PV ()
checkExpBlockArguments, LHsCmd GhcPs -> PV ()
GenLocated SrcSpanAnnA (HsCmd GhcPs) -> PV ()
checkCmdBlockArguments) = (LHsExpr GhcPs -> PV ()
checkExpr, LHsCmd GhcPs -> PV ()
checkCmd)
where
checkExpr :: LHsExpr GhcPs -> PV ()
checkExpr :: LHsExpr GhcPs -> PV ()
checkExpr LHsExpr GhcPs
expr = case forall l e. GenLocated l e -> e
unLoc LHsExpr GhcPs
expr of
HsDo XDo GhcPs
_ (DoExpr Maybe ModuleName
m) XRec GhcPs [ExprLStmt GhcPs]
_ -> forall {m :: * -> *} {a} {e}.
MonadP m =>
(GenLocated (SrcSpanAnn' a) e -> PsMessage)
-> GenLocated (SrcSpanAnn' a) e -> m ()
check (Maybe ModuleName -> LHsExpr GhcPs -> PsMessage
PsErrDoInFunAppExpr Maybe ModuleName
m) LHsExpr GhcPs
expr
HsDo XDo GhcPs
_ (MDoExpr Maybe ModuleName
m) XRec GhcPs [ExprLStmt GhcPs]
_ -> forall {m :: * -> *} {a} {e}.
MonadP m =>
(GenLocated (SrcSpanAnn' a) e -> PsMessage)
-> GenLocated (SrcSpanAnn' a) e -> m ()
check (Maybe ModuleName -> LHsExpr GhcPs -> PsMessage
PsErrMDoInFunAppExpr Maybe ModuleName
m) LHsExpr GhcPs
expr
HsLam {} -> forall {m :: * -> *} {a} {e}.
MonadP m =>
(GenLocated (SrcSpanAnn' a) e -> PsMessage)
-> GenLocated (SrcSpanAnn' a) e -> m ()
check LHsExpr GhcPs -> PsMessage
PsErrLambdaInFunAppExpr LHsExpr GhcPs
expr
HsCase {} -> forall {m :: * -> *} {a} {e}.
MonadP m =>
(GenLocated (SrcSpanAnn' a) e -> PsMessage)
-> GenLocated (SrcSpanAnn' a) e -> m ()
check LHsExpr GhcPs -> PsMessage
PsErrCaseInFunAppExpr LHsExpr GhcPs
expr
HsLamCase XLamCase GhcPs
_ LamCaseVariant
lc_variant MatchGroup GhcPs (LHsExpr GhcPs)
_ -> forall {m :: * -> *} {a} {e}.
MonadP m =>
(GenLocated (SrcSpanAnn' a) e -> PsMessage)
-> GenLocated (SrcSpanAnn' a) e -> m ()
check (LamCaseVariant -> LHsExpr GhcPs -> PsMessage
PsErrLambdaCaseInFunAppExpr LamCaseVariant
lc_variant) LHsExpr GhcPs
expr
HsLet {} -> forall {m :: * -> *} {a} {e}.
MonadP m =>
(GenLocated (SrcSpanAnn' a) e -> PsMessage)
-> GenLocated (SrcSpanAnn' a) e -> m ()
check LHsExpr GhcPs -> PsMessage
PsErrLetInFunAppExpr LHsExpr GhcPs
expr
HsIf {} -> forall {m :: * -> *} {a} {e}.
MonadP m =>
(GenLocated (SrcSpanAnn' a) e -> PsMessage)
-> GenLocated (SrcSpanAnn' a) e -> m ()
check LHsExpr GhcPs -> PsMessage
PsErrIfInFunAppExpr LHsExpr GhcPs
expr
HsProc {} -> forall {m :: * -> *} {a} {e}.
MonadP m =>
(GenLocated (SrcSpanAnn' a) e -> PsMessage)
-> GenLocated (SrcSpanAnn' a) e -> m ()
check LHsExpr GhcPs -> PsMessage
PsErrProcInFunAppExpr LHsExpr GhcPs
expr
HsExpr GhcPs
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
checkCmd :: LHsCmd GhcPs -> PV ()
checkCmd :: LHsCmd GhcPs -> PV ()
checkCmd LHsCmd GhcPs
cmd = case forall l e. GenLocated l e -> e
unLoc LHsCmd GhcPs
cmd of
HsCmdLam {} -> forall {m :: * -> *} {a} {e}.
MonadP m =>
(GenLocated (SrcSpanAnn' a) e -> PsMessage)
-> GenLocated (SrcSpanAnn' a) e -> m ()
check LHsCmd GhcPs -> PsMessage
PsErrLambdaCmdInFunAppCmd LHsCmd GhcPs
cmd
HsCmdCase {} -> forall {m :: * -> *} {a} {e}.
MonadP m =>
(GenLocated (SrcSpanAnn' a) e -> PsMessage)
-> GenLocated (SrcSpanAnn' a) e -> m ()
check LHsCmd GhcPs -> PsMessage
PsErrCaseCmdInFunAppCmd LHsCmd GhcPs
cmd
HsCmdLamCase XCmdLamCase GhcPs
_ LamCaseVariant
lc_variant MatchGroup GhcPs (LHsCmd GhcPs)
_ -> forall {m :: * -> *} {a} {e}.
MonadP m =>
(GenLocated (SrcSpanAnn' a) e -> PsMessage)
-> GenLocated (SrcSpanAnn' a) e -> m ()
check (LamCaseVariant -> LHsCmd GhcPs -> PsMessage
PsErrLambdaCaseCmdInFunAppCmd LamCaseVariant
lc_variant) LHsCmd GhcPs
cmd
HsCmdIf {} -> forall {m :: * -> *} {a} {e}.
MonadP m =>
(GenLocated (SrcSpanAnn' a) e -> PsMessage)
-> GenLocated (SrcSpanAnn' a) e -> m ()
check LHsCmd GhcPs -> PsMessage
PsErrIfCmdInFunAppCmd LHsCmd GhcPs
cmd
HsCmdLet {} -> forall {m :: * -> *} {a} {e}.
MonadP m =>
(GenLocated (SrcSpanAnn' a) e -> PsMessage)
-> GenLocated (SrcSpanAnn' a) e -> m ()
check LHsCmd GhcPs -> PsMessage
PsErrLetCmdInFunAppCmd LHsCmd GhcPs
cmd
HsCmdDo {} -> forall {m :: * -> *} {a} {e}.
MonadP m =>
(GenLocated (SrcSpanAnn' a) e -> PsMessage)
-> GenLocated (SrcSpanAnn' a) e -> m ()
check LHsCmd GhcPs -> PsMessage
PsErrDoCmdInFunAppCmd LHsCmd GhcPs
cmd
HsCmd GhcPs
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
check :: (GenLocated (SrcSpanAnn' a) e -> PsMessage)
-> GenLocated (SrcSpanAnn' a) e -> m ()
check GenLocated (SrcSpanAnn' a) e -> PsMessage
err GenLocated (SrcSpanAnn' a) e
a = do
Bool
blockArguments <- forall (m :: * -> *). MonadP m => ExtBits -> m Bool
getBit ExtBits
BlockArgumentsBit
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
blockArguments forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
getLocA GenLocated (SrcSpanAnn' a) e
a) forall a b. (a -> b) -> a -> b
$ (GenLocated (SrcSpanAnn' a) e -> PsMessage
err GenLocated (SrcSpanAnn' a) e
a)
checkContext :: LHsType GhcPs -> P (LHsContext GhcPs)
checkContext :: LHsType GhcPs -> P (LHsContext GhcPs)
checkContext orig_t :: LHsType GhcPs
orig_t@(L (SrcSpanAnn EpAnn AnnListItem
_ SrcSpan
l) HsType GhcPs
_orig_t) =
([EpaLocation], [EpaLocation], EpAnnComments)
-> LHsType GhcPs -> P (LHsContext GhcPs)
check ([],[],EpAnnComments
emptyComments) LHsType GhcPs
orig_t
where
check :: ([EpaLocation],[EpaLocation],EpAnnComments)
-> LHsType GhcPs -> P (LHsContext GhcPs)
check :: ([EpaLocation], [EpaLocation], EpAnnComments)
-> LHsType GhcPs -> P (LHsContext GhcPs)
check ([EpaLocation]
oparens,[EpaLocation]
cparens,EpAnnComments
cs) (L SrcSpanAnnA
_l (HsTupleTy XTupleTy GhcPs
ann' HsTupleSort
HsBoxedOrConstraintTuple [LHsType GhcPs]
ts))
= do
let ([EpaLocation]
op,[EpaLocation]
cp,EpAnnComments
cs') = case XTupleTy GhcPs
ann' of
XTupleTy GhcPs
EpAnn AnnParen
EpAnnNotUsed -> ([],[],EpAnnComments
emptyComments)
EpAnn Anchor
_ (AnnParen ParenType
_ EpaLocation
o EpaLocation
c) EpAnnComments
cs -> ([EpaLocation
o],[EpaLocation
c],EpAnnComments
cs)
forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L (forall a. a -> SrcSpan -> SrcSpanAnn' a
SrcSpanAnn (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l)
(Maybe (IsUnicodeSyntax, EpaLocation)
-> [EpaLocation] -> [EpaLocation] -> AnnContext
AnnContext forall a. Maybe a
Nothing ([EpaLocation]
oparens forall a. [a] -> [a] -> [a]
++ [EpaLocation]
op) ([EpaLocation]
cp forall a. [a] -> [a] -> [a]
++ [EpaLocation]
cparens)) (EpAnnComments
cs forall a. Semigroup a => a -> a -> a
Semi.<> EpAnnComments
cs')) SrcSpan
l) [LHsType GhcPs]
ts)
check ([EpaLocation]
opi,[EpaLocation]
cpi,EpAnnComments
csi) (L SrcSpanAnnA
_lp1 (HsParTy XParTy GhcPs
ann' LHsType GhcPs
ty))
= do
let ([EpaLocation]
op,[EpaLocation]
cp,EpAnnComments
cs') = case XParTy GhcPs
ann' of
XParTy GhcPs
EpAnn AnnParen
EpAnnNotUsed -> ([],[],EpAnnComments
emptyComments)
EpAnn Anchor
_ (AnnParen ParenType
_ EpaLocation
open EpaLocation
close ) EpAnnComments
cs -> ([EpaLocation
open],[EpaLocation
close],EpAnnComments
cs)
([EpaLocation], [EpaLocation], EpAnnComments)
-> LHsType GhcPs -> P (LHsContext GhcPs)
check ([EpaLocation]
opforall a. [a] -> [a] -> [a]
++[EpaLocation]
opi,[EpaLocation]
cpforall a. [a] -> [a] -> [a]
++[EpaLocation]
cpi,EpAnnComments
cs' forall a. Semigroup a => a -> a -> a
Semi.<> EpAnnComments
csi) LHsType GhcPs
ty
check ([EpaLocation]
_opi,[EpaLocation]
_cpi,EpAnnComments
_csi) LHsType GhcPs
_t =
forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L (forall a. a -> SrcSpan -> SrcSpanAnn' a
SrcSpanAnn (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) (Maybe (IsUnicodeSyntax, EpaLocation)
-> [EpaLocation] -> [EpaLocation] -> AnnContext
AnnContext forall a. Maybe a
Nothing [] []) EpAnnComments
emptyComments) SrcSpan
l) [LHsType GhcPs
orig_t])
checkImportDecl :: Maybe EpaLocation
-> Maybe EpaLocation
-> P ()
checkImportDecl :: Maybe EpaLocation -> Maybe EpaLocation -> P ()
checkImportDecl Maybe EpaLocation
mPre Maybe EpaLocation
mPost = do
let whenJust :: Maybe a -> (a -> f ()) -> f ()
whenJust Maybe a
mg a -> f ()
f = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (f :: * -> *) a. Applicative f => a -> f a
pure ()) a -> f ()
f Maybe a
mg
Bool
importQualifiedPostEnabled <- forall (m :: * -> *). MonadP m => ExtBits -> m Bool
getBit ExtBits
ImportQualifiedPostBit
forall {f :: * -> *} {a}.
Applicative f =>
Maybe a -> (a -> f ()) -> f ()
whenJust Maybe EpaLocation
mPost forall a b. (a -> b) -> a -> b
$ \EpaLocation
post ->
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not Bool
importQualifiedPostEnabled) forall a b. (a -> b) -> a -> b
$
SrcSpan -> P ()
failNotEnabledImportQualifiedPost (RealSrcSpan -> Maybe BufSpan -> SrcSpan
RealSrcSpan (EpaLocation -> RealSrcSpan
epaLocationRealSrcSpan EpaLocation
post) forall a. Maybe a
Strict.Nothing)
forall {f :: * -> *} {a}.
Applicative f =>
Maybe a -> (a -> f ()) -> f ()
whenJust Maybe EpaLocation
mPost forall a b. (a -> b) -> a -> b
$ \EpaLocation
post ->
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (forall a. Maybe a -> Bool
isJust Maybe EpaLocation
mPre) forall a b. (a -> b) -> a -> b
$
SrcSpan -> P ()
failImportQualifiedTwice (RealSrcSpan -> Maybe BufSpan -> SrcSpan
RealSrcSpan (EpaLocation -> RealSrcSpan
epaLocationRealSrcSpan EpaLocation
post) forall a. Maybe a
Strict.Nothing)
forall {f :: * -> *} {a}.
Applicative f =>
Maybe a -> (a -> f ()) -> f ()
whenJust Maybe EpaLocation
mPre forall a b. (a -> b) -> a -> b
$ \EpaLocation
pre ->
SrcSpan -> P ()
warnPrepositiveQualifiedModule (RealSrcSpan -> Maybe BufSpan -> SrcSpan
RealSrcSpan (EpaLocation -> RealSrcSpan
epaLocationRealSrcSpan EpaLocation
pre) forall a. Maybe a
Strict.Nothing)
checkPattern :: LocatedA (PatBuilder GhcPs) -> P (LPat GhcPs)
checkPattern :: LocatedA (PatBuilder GhcPs) -> P (LPat GhcPs)
checkPattern = forall a. PV a -> P a
runPV forall b c a. (b -> c) -> (a -> b) -> a -> c
. LocatedA (PatBuilder GhcPs) -> PV (LPat GhcPs)
checkLPat
checkPattern_details :: ParseContext -> PV (LocatedA (PatBuilder GhcPs)) -> P (LPat GhcPs)
checkPattern_details :: ParseContext -> PV (LocatedA (PatBuilder GhcPs)) -> P (LPat GhcPs)
checkPattern_details ParseContext
extraDetails PV (LocatedA (PatBuilder GhcPs))
pp = forall a. ParseContext -> PV a -> P a
runPV_details ParseContext
extraDetails (PV (LocatedA (PatBuilder GhcPs))
pp forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= LocatedA (PatBuilder GhcPs) -> PV (LPat GhcPs)
checkLPat)
checkLPat :: LocatedA (PatBuilder GhcPs) -> PV (LPat GhcPs)
checkLPat :: LocatedA (PatBuilder GhcPs) -> PV (LPat GhcPs)
checkLPat e :: LocatedA (PatBuilder GhcPs)
e@(L SrcSpanAnnA
l PatBuilder GhcPs
_) = SrcSpanAnnA
-> LocatedA (PatBuilder GhcPs)
-> [HsConPatTyArg GhcPs]
-> [LPat GhcPs]
-> PV (LPat GhcPs)
checkPat SrcSpanAnnA
l LocatedA (PatBuilder GhcPs)
e [] []
checkPat :: SrcSpanAnnA -> LocatedA (PatBuilder GhcPs) -> [HsConPatTyArg GhcPs] -> [LPat GhcPs]
-> PV (LPat GhcPs)
checkPat :: SrcSpanAnnA
-> LocatedA (PatBuilder GhcPs)
-> [HsConPatTyArg GhcPs]
-> [LPat GhcPs]
-> PV (LPat GhcPs)
checkPat SrcSpanAnnA
loc (L SrcSpanAnnA
l e :: PatBuilder GhcPs
e@(PatBuilderVar (L SrcSpanAnnN
ln RdrName
c))) [HsConPatTyArg GhcPs]
tyargs [LPat GhcPs]
args
| RdrName -> Bool
isRdrDataCon RdrName
c = forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc forall a b. (a -> b) -> a -> b
$ ConPat
{ pat_con_ext :: XConPat GhcPs
pat_con_ext = forall a. EpAnn a
noAnn
, pat_con :: XRec GhcPs (ConLikeP GhcPs)
pat_con = forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
ln RdrName
c
, pat_args :: HsConPatDetails GhcPs
pat_args = forall tyarg arg rec.
[tyarg] -> [arg] -> HsConDetails tyarg arg rec
PrefixCon [HsConPatTyArg GhcPs]
tyargs [LPat GhcPs]
args
}
| Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [HsConPatTyArg GhcPs]
tyargs) =
forall a. SrcSpan -> PsMessage -> PV a
patFail (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatBuilder GhcPs -> PsErrInPatDetails -> PsMessage
PsErrInPat PatBuilder GhcPs
e forall a b. (a -> b) -> a -> b
$ [HsConPatTyArg GhcPs] -> PsErrInPatDetails
PEIP_TypeArgs [HsConPatTyArg GhcPs]
tyargs
| (Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LPat GhcPs]
args) Bool -> Bool -> Bool
&& RdrName -> Bool
patIsRec RdrName
c) = do
ParseContext
ctx <- PV ParseContext
askParseContext
forall a. SrcSpan -> PsMessage -> PV a
patFail (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) forall b c a. (b -> c) -> (a -> b) -> a -> c
. PatBuilder GhcPs -> PsErrInPatDetails -> PsMessage
PsErrInPat PatBuilder GhcPs
e forall a b. (a -> b) -> a -> b
$ [LPat GhcPs] -> PatIsRecursive -> ParseContext -> PsErrInPatDetails
PEIP_RecPattern [LPat GhcPs]
args PatIsRecursive
YesPatIsRecursive ParseContext
ctx
checkPat SrcSpanAnnA
loc (L SrcSpanAnnA
_ (PatBuilderAppType LocatedA (PatBuilder GhcPs)
f LHsToken "@" GhcPs
at HsPatSigType GhcPs
t)) [HsConPatTyArg GhcPs]
tyargs [LPat GhcPs]
args =
SrcSpanAnnA
-> LocatedA (PatBuilder GhcPs)
-> [HsConPatTyArg GhcPs]
-> [LPat GhcPs]
-> PV (LPat GhcPs)
checkPat SrcSpanAnnA
loc LocatedA (PatBuilder GhcPs)
f (forall p. LHsToken "@" p -> HsPatSigType p -> HsConPatTyArg p
HsConPatTyArg LHsToken "@" GhcPs
at HsPatSigType GhcPs
t forall a. a -> [a] -> [a]
: [HsConPatTyArg GhcPs]
tyargs) [LPat GhcPs]
args
checkPat SrcSpanAnnA
loc (L SrcSpanAnnA
_ (PatBuilderApp LocatedA (PatBuilder GhcPs)
f LocatedA (PatBuilder GhcPs)
e)) [] [LPat GhcPs]
args = do
GenLocated SrcSpanAnnA (Pat GhcPs)
p <- LocatedA (PatBuilder GhcPs) -> PV (LPat GhcPs)
checkLPat LocatedA (PatBuilder GhcPs)
e
SrcSpanAnnA
-> LocatedA (PatBuilder GhcPs)
-> [HsConPatTyArg GhcPs]
-> [LPat GhcPs]
-> PV (LPat GhcPs)
checkPat SrcSpanAnnA
loc LocatedA (PatBuilder GhcPs)
f [] (GenLocated SrcSpanAnnA (Pat GhcPs)
p forall a. a -> [a] -> [a]
: [LPat GhcPs]
args)
checkPat SrcSpanAnnA
loc (L SrcSpanAnnA
l PatBuilder GhcPs
e) [] [] = do
Pat GhcPs
p <- SrcSpanAnnA -> PatBuilder GhcPs -> PV (Pat GhcPs)
checkAPat SrcSpanAnnA
loc PatBuilder GhcPs
e
forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l Pat GhcPs
p)
checkPat SrcSpanAnnA
loc LocatedA (PatBuilder GhcPs)
e [HsConPatTyArg GhcPs]
_ [LPat GhcPs]
_ = do
PsErrInPatDetails
details <- ParseContext -> PsErrInPatDetails
fromParseContext forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PV ParseContext
askParseContext
forall a. SrcSpan -> PsMessage -> PV a
patFail (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc) (PatBuilder GhcPs -> PsErrInPatDetails -> PsMessage
PsErrInPat (forall l e. GenLocated l e -> e
unLoc LocatedA (PatBuilder GhcPs)
e) PsErrInPatDetails
details)
checkAPat :: SrcSpanAnnA -> PatBuilder GhcPs -> PV (Pat GhcPs)
checkAPat :: SrcSpanAnnA -> PatBuilder GhcPs -> PV (Pat GhcPs)
checkAPat SrcSpanAnnA
loc PatBuilder GhcPs
e0 = do
Bool
nPlusKPatterns <- forall (m :: * -> *). MonadP m => ExtBits -> m Bool
getBit ExtBits
NPlusKPatternsBit
case PatBuilder GhcPs
e0 of
PatBuilderPat Pat GhcPs
p -> forall (m :: * -> *) a. Monad m => a -> m a
return Pat GhcPs
p
PatBuilderVar GenLocated SrcSpanAnnN RdrName
x -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall p. XVarPat p -> LIdP p -> Pat p
VarPat NoExtField
noExtField GenLocated SrcSpanAnnN RdrName
x)
PatBuilderOverLit HsOverLit GhcPs
pos_lit -> forall (m :: * -> *) a. Monad m => a -> m a
return (LocatedAn NoEpAnns (HsOverLit GhcPs)
-> Maybe (SyntaxExpr GhcPs) -> EpAnn [AddEpAnn] -> Pat GhcPs
mkNPat (forall l e. l -> e -> GenLocated l e
L (forall a ann. SrcSpanAnn' a -> SrcAnn ann
l2l SrcSpanAnnA
loc) HsOverLit GhcPs
pos_lit) forall a. Maybe a
Nothing forall a. EpAnn a
noAnn)
PatBuilderOpApp
(L SrcSpanAnnA
_ (PatBuilderVar (L SrcSpanAnnN
nloc RdrName
n)))
(L SrcSpanAnnN
l RdrName
plus)
(L SrcSpanAnnA
lloc (PatBuilderOverLit lit :: HsOverLit GhcPs
lit@(OverLit {ol_val :: forall p. HsOverLit p -> OverLitVal
ol_val = HsIntegral {}})))
(EpAnn Anchor
anc [AddEpAnn]
_ EpAnnComments
cs)
| Bool
nPlusKPatterns Bool -> Bool -> Bool
&& (RdrName
plus forall a. Eq a => a -> a -> Bool
== RdrName
plus_RDR)
-> forall (m :: * -> *) a. Monad m => a -> m a
return (GenLocated SrcSpanAnnN RdrName
-> LocatedAn NoEpAnns (HsOverLit GhcPs)
-> EpAnn EpaLocation
-> Pat GhcPs
mkNPlusKPat (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
nloc RdrName
n) (forall l e. l -> e -> GenLocated l e
L (forall a ann. SrcSpanAnn' a -> SrcAnn ann
l2l SrcSpanAnnA
lloc) HsOverLit GhcPs
lit)
(forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn Anchor
anc (forall ann. SrcAnn ann -> EpaLocation
epaLocationFromSrcAnn SrcSpanAnnN
l) EpAnnComments
cs))
PatBuilderOpApp LocatedA (PatBuilder GhcPs)
_ GenLocated SrcSpanAnnN RdrName
op LocatedA (PatBuilder GhcPs)
_ EpAnn [AddEpAnn]
_ | RdrName -> Bool
opIsAt (forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnN RdrName
op) -> do
forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
getLocA GenLocated SrcSpanAnnN RdrName
op) PsMessage
PsErrAtInPatPos
forall (m :: * -> *) a. Monad m => a -> m a
return (forall p. XWildPat p -> Pat p
WildPat NoExtField
noExtField)
PatBuilderOpApp LocatedA (PatBuilder GhcPs)
l (L SrcSpanAnnN
cl RdrName
c) LocatedA (PatBuilder GhcPs)
r EpAnn [AddEpAnn]
anns
| RdrName -> Bool
isRdrDataCon RdrName
c -> do
GenLocated SrcSpanAnnA (Pat GhcPs)
l <- LocatedA (PatBuilder GhcPs) -> PV (LPat GhcPs)
checkLPat LocatedA (PatBuilder GhcPs)
l
GenLocated SrcSpanAnnA (Pat GhcPs)
r <- LocatedA (PatBuilder GhcPs) -> PV (LPat GhcPs)
checkLPat LocatedA (PatBuilder GhcPs)
r
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ConPat
{ pat_con_ext :: XConPat GhcPs
pat_con_ext = EpAnn [AddEpAnn]
anns
, pat_con :: XRec GhcPs (ConLikeP GhcPs)
pat_con = forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
cl RdrName
c
, pat_args :: HsConPatDetails GhcPs
pat_args = forall tyarg arg rec. arg -> arg -> HsConDetails tyarg arg rec
InfixCon GenLocated SrcSpanAnnA (Pat GhcPs)
l GenLocated SrcSpanAnnA (Pat GhcPs)
r
}
PatBuilderPar LHsToken "(" GhcPs
lpar LocatedA (PatBuilder GhcPs)
e LHsToken ")" GhcPs
rpar -> do
GenLocated SrcSpanAnnA (Pat GhcPs)
p <- LocatedA (PatBuilder GhcPs) -> PV (LPat GhcPs)
checkLPat LocatedA (PatBuilder GhcPs)
e
forall (m :: * -> *) a. Monad m => a -> m a
return (forall p.
XParPat p -> LHsToken "(" p -> LPat p -> LHsToken ")" p -> Pat p
ParPat (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc)) NoEpAnns
NoEpAnns EpAnnComments
emptyComments) LHsToken "(" GhcPs
lpar GenLocated SrcSpanAnnA (Pat GhcPs)
p LHsToken ")" GhcPs
rpar)
PatBuilder GhcPs
_ -> do
PsErrInPatDetails
details <- ParseContext -> PsErrInPatDetails
fromParseContext forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PV ParseContext
askParseContext
forall a. SrcSpan -> PsMessage -> PV a
patFail (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc) (PatBuilder GhcPs -> PsErrInPatDetails -> PsMessage
PsErrInPat PatBuilder GhcPs
e0 PsErrInPatDetails
details)
placeHolderPunRhs :: DisambECP b => PV (LocatedA b)
placeHolderPunRhs :: forall b. DisambECP b => PV (LocatedA b)
placeHolderPunRhs = forall b.
DisambECP b =>
GenLocated SrcSpanAnnN RdrName -> PV (LocatedA b)
mkHsVarPV (forall a an. a -> LocatedAn an a
noLocA RdrName
pun_RDR)
plus_RDR, pun_RDR :: RdrName
plus_RDR :: RdrName
plus_RDR = NameSpace -> FastString -> RdrName
mkUnqual NameSpace
varName (String -> FastString
fsLit String
"+")
pun_RDR :: RdrName
pun_RDR = NameSpace -> FastString -> RdrName
mkUnqual NameSpace
varName (String -> FastString
fsLit String
"pun-right-hand-side")
checkPatField :: LHsRecField GhcPs (LocatedA (PatBuilder GhcPs))
-> PV (LHsRecField GhcPs (LPat GhcPs))
checkPatField :: LHsRecField GhcPs (LocatedA (PatBuilder GhcPs))
-> PV (LHsRecField GhcPs (LPat GhcPs))
checkPatField (L SrcSpanAnnA
l HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs))
(LocatedA (PatBuilder GhcPs))
fld) = do GenLocated SrcSpanAnnA (Pat GhcPs)
p <- LocatedA (PatBuilder GhcPs) -> PV (LPat GhcPs)
checkLPat (forall lhs rhs. HsFieldBind lhs rhs -> rhs
hfbRHS HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs))
(LocatedA (PatBuilder GhcPs))
fld)
forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs))
(LocatedA (PatBuilder GhcPs))
fld { hfbRHS :: GenLocated SrcSpanAnnA (Pat GhcPs)
hfbRHS = GenLocated SrcSpanAnnA (Pat GhcPs)
p }))
patFail :: SrcSpan -> PsMessage -> PV a
patFail :: forall a. SrcSpan -> PsMessage -> PV a
patFail SrcSpan
loc PsMessage
msg = forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
loc forall a b. (a -> b) -> a -> b
$ PsMessage
msg
patIsRec :: RdrName -> Bool
patIsRec :: RdrName -> Bool
patIsRec RdrName
e = RdrName
e forall a. Eq a => a -> a -> Bool
== NameSpace -> FastString -> RdrName
mkUnqual NameSpace
varName (String -> FastString
fsLit String
"rec")
checkValDef :: SrcSpan
-> LocatedA (PatBuilder GhcPs)
-> Maybe (AddEpAnn, LHsType GhcPs)
-> Located (GRHSs GhcPs (LHsExpr GhcPs))
-> P (HsBind GhcPs)
checkValDef :: SrcSpan
-> LocatedA (PatBuilder GhcPs)
-> Maybe (AddEpAnn, LHsType GhcPs)
-> Located (GRHSs GhcPs (LHsExpr GhcPs))
-> P (HsBindLR GhcPs GhcPs)
checkValDef SrcSpan
loc LocatedA (PatBuilder GhcPs)
lhs (Just (AddEpAnn
sigAnn, LHsType GhcPs
sig)) Located (GRHSs GhcPs (LHsExpr GhcPs))
grhss
= do GenLocated SrcSpanAnnA (Pat GhcPs)
lhs' <- forall a. PV a -> P a
runPV forall a b. (a -> b) -> a -> b
$ forall b.
DisambECP b =>
SrcSpanAnnA
-> LocatedA b -> LHsType GhcPs -> [AddEpAnn] -> PV (LocatedA b)
mkHsTySigPV (forall a e1 e2.
Semigroup a =>
GenLocated (SrcAnn a) e1 -> GenLocated (SrcAnn a) e2 -> SrcAnn a
combineLocsA LocatedA (PatBuilder GhcPs)
lhs LHsType GhcPs
sig) LocatedA (PatBuilder GhcPs)
lhs LHsType GhcPs
sig [AddEpAnn
sigAnn]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= LocatedA (PatBuilder GhcPs) -> PV (LPat GhcPs)
checkLPat
SrcSpan
-> [AddEpAnn]
-> LPat GhcPs
-> Located (GRHSs GhcPs (LHsExpr GhcPs))
-> P (HsBindLR GhcPs GhcPs)
checkPatBind SrcSpan
loc [] GenLocated SrcSpanAnnA (Pat GhcPs)
lhs' Located (GRHSs GhcPs (LHsExpr GhcPs))
grhss
checkValDef SrcSpan
loc LocatedA (PatBuilder GhcPs)
lhs Maybe (AddEpAnn, LHsType GhcPs)
Nothing Located (GRHSs GhcPs (LHsExpr GhcPs))
g
= do { Maybe
(GenLocated SrcSpanAnnN RdrName, LexicalFixity,
[LocatedA (PatBuilder GhcPs)], [AddEpAnn])
mb_fun <- LocatedA (PatBuilder GhcPs)
-> P (Maybe
(GenLocated SrcSpanAnnN RdrName, LexicalFixity,
[LocatedA (PatBuilder GhcPs)], [AddEpAnn]))
isFunLhs LocatedA (PatBuilder GhcPs)
lhs
; case Maybe
(GenLocated SrcSpanAnnN RdrName, LexicalFixity,
[LocatedA (PatBuilder GhcPs)], [AddEpAnn])
mb_fun of
Just (GenLocated SrcSpanAnnN RdrName
fun, LexicalFixity
is_infix, [LocatedA (PatBuilder GhcPs)]
pats, [AddEpAnn]
ann) ->
SrcStrictness
-> SrcSpan
-> [AddEpAnn]
-> GenLocated SrcSpanAnnN RdrName
-> LexicalFixity
-> [LocatedA (PatBuilder GhcPs)]
-> Located (GRHSs GhcPs (LHsExpr GhcPs))
-> P (HsBindLR GhcPs GhcPs)
checkFunBind SrcStrictness
NoSrcStrict SrcSpan
loc [AddEpAnn]
ann
GenLocated SrcSpanAnnN RdrName
fun LexicalFixity
is_infix [LocatedA (PatBuilder GhcPs)]
pats Located (GRHSs GhcPs (LHsExpr GhcPs))
g
Maybe
(GenLocated SrcSpanAnnN RdrName, LexicalFixity,
[LocatedA (PatBuilder GhcPs)], [AddEpAnn])
Nothing -> do
GenLocated SrcSpanAnnA (Pat GhcPs)
lhs' <- LocatedA (PatBuilder GhcPs) -> P (LPat GhcPs)
checkPattern LocatedA (PatBuilder GhcPs)
lhs
SrcSpan
-> [AddEpAnn]
-> LPat GhcPs
-> Located (GRHSs GhcPs (LHsExpr GhcPs))
-> P (HsBindLR GhcPs GhcPs)
checkPatBind SrcSpan
loc [] GenLocated SrcSpanAnnA (Pat GhcPs)
lhs' Located (GRHSs GhcPs (LHsExpr GhcPs))
g }
checkFunBind :: SrcStrictness
-> SrcSpan
-> [AddEpAnn]
-> LocatedN RdrName
-> LexicalFixity
-> [LocatedA (PatBuilder GhcPs)]
-> Located (GRHSs GhcPs (LHsExpr GhcPs))
-> P (HsBind GhcPs)
checkFunBind :: SrcStrictness
-> SrcSpan
-> [AddEpAnn]
-> GenLocated SrcSpanAnnN RdrName
-> LexicalFixity
-> [LocatedA (PatBuilder GhcPs)]
-> Located (GRHSs GhcPs (LHsExpr GhcPs))
-> P (HsBindLR GhcPs GhcPs)
checkFunBind SrcStrictness
strictness SrcSpan
locF [AddEpAnn]
ann GenLocated SrcSpanAnnN RdrName
fun LexicalFixity
is_infix [LocatedA (PatBuilder GhcPs)]
pats (L SrcSpan
_ GRHSs GhcPs (LHsExpr GhcPs)
grhss)
= do [GenLocated SrcSpanAnnA (Pat GhcPs)]
ps <- forall a. ParseContext -> PV a -> P a
runPV_details ParseContext
extraDetails (forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LocatedA (PatBuilder GhcPs) -> PV (LPat GhcPs)
checkLPat [LocatedA (PatBuilder GhcPs)]
pats)
let match_span :: SrcSpanAnnA
match_span = forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan forall a b. (a -> b) -> a -> b
$ SrcSpan
locF
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
locF
forall (m :: * -> *) a. Monad m => a -> m a
return (GenLocated SrcSpanAnnN RdrName
-> LocatedL [LMatch GhcPs (LHsExpr GhcPs)] -> HsBindLR GhcPs GhcPs
makeFunBind GenLocated SrcSpanAnnN RdrName
fun (forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan forall a b. (a -> b) -> a -> b
$ forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
match_span)
[forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
match_span (Match { m_ext :: XCMatch GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
m_ext = forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
locF) [AddEpAnn]
ann EpAnnComments
cs
, m_ctxt :: HsMatchContext GhcPs
m_ctxt = FunRhs
{ mc_fun :: LIdP (NoGhcTc GhcPs)
mc_fun = GenLocated SrcSpanAnnN RdrName
fun
, mc_fixity :: LexicalFixity
mc_fixity = LexicalFixity
is_infix
, mc_strictness :: SrcStrictness
mc_strictness = SrcStrictness
strictness }
, m_pats :: [LPat GhcPs]
m_pats = [GenLocated SrcSpanAnnA (Pat GhcPs)]
ps
, m_grhss :: GRHSs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
m_grhss = GRHSs GhcPs (LHsExpr GhcPs)
grhss })]))
where
extraDetails :: ParseContext
extraDetails
| LexicalFixity
Infix <- LexicalFixity
is_infix = Maybe RdrName -> PatIncompleteDoBlock -> ParseContext
ParseContext (forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnN RdrName
fun) PatIncompleteDoBlock
NoIncompleteDoBlock
| Bool
otherwise = ParseContext
noParseContext
makeFunBind :: LocatedN RdrName -> LocatedL [LMatch GhcPs (LHsExpr GhcPs)]
-> HsBind GhcPs
makeFunBind :: GenLocated SrcSpanAnnN RdrName
-> LocatedL [LMatch GhcPs (LHsExpr GhcPs)] -> HsBindLR GhcPs GhcPs
makeFunBind GenLocated SrcSpanAnnN RdrName
fn LocatedL [LMatch GhcPs (LHsExpr GhcPs)]
ms
= FunBind { fun_ext :: XFunBind GhcPs GhcPs
fun_ext = NoExtField
noExtField,
fun_id :: XRec GhcPs (IdP GhcPs)
fun_id = GenLocated SrcSpanAnnN RdrName
fn,
fun_matches :: MatchGroup GhcPs (LHsExpr GhcPs)
fun_matches = forall (p :: Pass) (body :: * -> *).
AnnoBody p body =>
Origin
-> LocatedL
[LocatedA (Match (GhcPass p) (LocatedA (body (GhcPass p))))]
-> MatchGroup (GhcPass p) (LocatedA (body (GhcPass p)))
mkMatchGroup Origin
FromSource LocatedL [LMatch GhcPs (LHsExpr GhcPs)]
ms }
checkPatBind :: SrcSpan
-> [AddEpAnn]
-> LPat GhcPs
-> Located (GRHSs GhcPs (LHsExpr GhcPs))
-> P (HsBind GhcPs)
checkPatBind :: SrcSpan
-> [AddEpAnn]
-> LPat GhcPs
-> Located (GRHSs GhcPs (LHsExpr GhcPs))
-> P (HsBindLR GhcPs GhcPs)
checkPatBind SrcSpan
loc [AddEpAnn]
annsIn (L SrcSpanAnnA
_ (BangPat (EpAnn Anchor
_ [AddEpAnn]
ans EpAnnComments
cs) (L SrcSpanAnnA
_ (VarPat XVarPat GhcPs
_ XRec GhcPs (IdP GhcPs)
v))))
(L SrcSpan
_match_span GRHSs GhcPs (LHsExpr GhcPs)
grhss)
= forall (m :: * -> *) a. Monad m => a -> m a
return (GenLocated SrcSpanAnnN RdrName
-> LocatedL [LMatch GhcPs (LHsExpr GhcPs)] -> HsBindLR GhcPs GhcPs
makeFunBind XRec GhcPs (IdP GhcPs)
v (forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
loc)
[forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
loc) (EpAnn [AddEpAnn]
-> GenLocated SrcSpanAnnN RdrName
-> Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
m (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
loc) ([AddEpAnn]
ansforall a. [a] -> [a] -> [a]
++[AddEpAnn]
annsIn) EpAnnComments
cs) XRec GhcPs (IdP GhcPs)
v)]))
where
m :: EpAnn [AddEpAnn]
-> GenLocated SrcSpanAnnN RdrName
-> Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
m EpAnn [AddEpAnn]
a GenLocated SrcSpanAnnN RdrName
v = Match { m_ext :: XCMatch GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
m_ext = EpAnn [AddEpAnn]
a
, m_ctxt :: HsMatchContext GhcPs
m_ctxt = FunRhs { mc_fun :: LIdP (NoGhcTc GhcPs)
mc_fun = GenLocated SrcSpanAnnN RdrName
v
, mc_fixity :: LexicalFixity
mc_fixity = LexicalFixity
Prefix
, mc_strictness :: SrcStrictness
mc_strictness = SrcStrictness
SrcStrict }
, m_pats :: [LPat GhcPs]
m_pats = []
, m_grhss :: GRHSs GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
m_grhss = GRHSs GhcPs (LHsExpr GhcPs)
grhss }
checkPatBind SrcSpan
loc [AddEpAnn]
annsIn LPat GhcPs
lhs (L SrcSpan
_ GRHSs GhcPs (LHsExpr GhcPs)
grhss) = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
loc
forall (m :: * -> *) a. Monad m => a -> m a
return (forall idL idR.
XPatBind idL idR
-> LPat idL -> GRHSs idR (LHsExpr idR) -> HsBindLR idL idR
PatBind (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
loc) [AddEpAnn]
annsIn EpAnnComments
cs) LPat GhcPs
lhs GRHSs GhcPs (LHsExpr GhcPs)
grhss)
checkValSigLhs :: LHsExpr GhcPs -> P (LocatedN RdrName)
checkValSigLhs :: LHsExpr GhcPs -> P (GenLocated SrcSpanAnnN RdrName)
checkValSigLhs (L SrcSpanAnnA
_ (HsVar XVar GhcPs
_ lrdr :: XRec GhcPs (IdP GhcPs)
lrdr@(L SrcSpanAnnN
_ RdrName
v)))
| RdrName -> Bool
isUnqual RdrName
v
, Bool -> Bool
not (OccName -> Bool
isDataOcc (RdrName -> OccName
rdrNameOcc RdrName
v))
= forall (m :: * -> *) a. Monad m => a -> m a
return XRec GhcPs (IdP GhcPs)
lrdr
checkValSigLhs lhs :: LHsExpr GhcPs
lhs@(L SrcSpanAnnA
l HsExpr GhcPs
_)
= forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) forall a b. (a -> b) -> a -> b
$ LHsExpr GhcPs -> PsMessage
PsErrInvalidTypeSignature LHsExpr GhcPs
lhs
checkDoAndIfThenElse
:: (Outputable a, Outputable b, Outputable c)
=> (a -> Bool -> b -> Bool -> c -> PsMessage)
-> LocatedA a -> Bool -> LocatedA b -> Bool -> LocatedA c -> PV ()
checkDoAndIfThenElse :: forall a b c.
(Outputable a, Outputable b, Outputable c) =>
(a -> Bool -> b -> Bool -> c -> PsMessage)
-> LocatedA a -> Bool -> LocatedA b -> Bool -> LocatedA c -> PV ()
checkDoAndIfThenElse a -> Bool -> b -> Bool -> c -> PsMessage
err LocatedA a
guardExpr Bool
semiThen LocatedA b
thenExpr Bool
semiElse LocatedA c
elseExpr
| Bool
semiThen Bool -> Bool -> Bool
|| Bool
semiElse = do
Bool
doAndIfThenElse <- forall (m :: * -> *). MonadP m => ExtBits -> m Bool
getBit ExtBits
DoAndIfThenElseBit
let e :: PsMessage
e = a -> Bool -> b -> Bool -> c -> PsMessage
err (forall l e. GenLocated l e -> e
unLoc LocatedA a
guardExpr)
Bool
semiThen (forall l e. GenLocated l e -> e
unLoc LocatedA b
thenExpr)
Bool
semiElse (forall l e. GenLocated l e -> e
unLoc LocatedA c
elseExpr)
loc :: SrcSpan
loc = forall a b. Located a -> Located b -> SrcSpan
combineLocs (forall a e. LocatedAn a e -> Located e
reLoc LocatedA a
guardExpr) (forall a e. LocatedAn a e -> Located e
reLoc LocatedA c
elseExpr)
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
doAndIfThenElse forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError (forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
loc PsMessage
e)
| Bool
otherwise = forall (m :: * -> *) a. Monad m => a -> m a
return ()
isFunLhs :: LocatedA (PatBuilder GhcPs)
-> P (Maybe (LocatedN RdrName, LexicalFixity,
[LocatedA (PatBuilder GhcPs)],[AddEpAnn]))
isFunLhs :: LocatedA (PatBuilder GhcPs)
-> P (Maybe
(GenLocated SrcSpanAnnN RdrName, LexicalFixity,
[LocatedA (PatBuilder GhcPs)], [AddEpAnn]))
isFunLhs LocatedA (PatBuilder GhcPs)
e = forall {m :: * -> *} {p}.
Monad m =>
LocatedA (PatBuilder p)
-> [LocatedA (PatBuilder p)]
-> [AddEpAnn]
-> [AddEpAnn]
-> m (Maybe
(GenLocated SrcSpanAnnN RdrName, LexicalFixity,
[LocatedA (PatBuilder p)], [AddEpAnn]))
go LocatedA (PatBuilder GhcPs)
e [] [] []
where
go :: LocatedA (PatBuilder p)
-> [LocatedA (PatBuilder p)]
-> [AddEpAnn]
-> [AddEpAnn]
-> m (Maybe
(GenLocated SrcSpanAnnN RdrName, LexicalFixity,
[LocatedA (PatBuilder p)], [AddEpAnn]))
go (L SrcSpanAnnA
_ (PatBuilderVar (L SrcSpanAnnN
loc RdrName
f))) [LocatedA (PatBuilder p)]
es [AddEpAnn]
ops [AddEpAnn]
cps
| Bool -> Bool
not (RdrName -> Bool
isRdrDataCon RdrName
f) = forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> Maybe a
Just (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
loc RdrName
f, LexicalFixity
Prefix, [LocatedA (PatBuilder p)]
es, (forall a. [a] -> [a]
reverse [AddEpAnn]
ops) forall a. [a] -> [a] -> [a]
++ [AddEpAnn]
cps))
go (L SrcSpanAnnA
_ (PatBuilderApp LocatedA (PatBuilder p)
f LocatedA (PatBuilder p)
e)) [LocatedA (PatBuilder p)]
es [AddEpAnn]
ops [AddEpAnn]
cps = LocatedA (PatBuilder p)
-> [LocatedA (PatBuilder p)]
-> [AddEpAnn]
-> [AddEpAnn]
-> m (Maybe
(GenLocated SrcSpanAnnN RdrName, LexicalFixity,
[LocatedA (PatBuilder p)], [AddEpAnn]))
go LocatedA (PatBuilder p)
f (LocatedA (PatBuilder p)
eforall a. a -> [a] -> [a]
:[LocatedA (PatBuilder p)]
es) [AddEpAnn]
ops [AddEpAnn]
cps
go (L SrcSpanAnnA
l (PatBuilderPar LHsToken "(" p
_ LocatedA (PatBuilder p)
e LHsToken ")" p
_)) es :: [LocatedA (PatBuilder p)]
es@(LocatedA (PatBuilder p)
_:[LocatedA (PatBuilder p)]
_) [AddEpAnn]
ops [AddEpAnn]
cps
= let
(AddEpAnn
o,AddEpAnn
c) = RealSrcSpan -> (AddEpAnn, AddEpAnn)
mkParensEpAnn (SrcSpan -> RealSrcSpan
realSrcSpan forall a b. (a -> b) -> a -> b
$ forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l)
in
LocatedA (PatBuilder p)
-> [LocatedA (PatBuilder p)]
-> [AddEpAnn]
-> [AddEpAnn]
-> m (Maybe
(GenLocated SrcSpanAnnN RdrName, LexicalFixity,
[LocatedA (PatBuilder p)], [AddEpAnn]))
go LocatedA (PatBuilder p)
e [LocatedA (PatBuilder p)]
es (AddEpAnn
oforall a. a -> [a] -> [a]
:[AddEpAnn]
ops) (AddEpAnn
cforall a. a -> [a] -> [a]
:[AddEpAnn]
cps)
go (L SrcSpanAnnA
loc (PatBuilderOpApp LocatedA (PatBuilder p)
l (L SrcSpanAnnN
loc' RdrName
op) LocatedA (PatBuilder p)
r (EpAnn Anchor
loca [AddEpAnn]
anns EpAnnComments
cs))) [LocatedA (PatBuilder p)]
es [AddEpAnn]
ops [AddEpAnn]
cps
| Bool -> Bool
not (RdrName -> Bool
isRdrDataCon RdrName
op)
= forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> Maybe a
Just (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
loc' RdrName
op, LexicalFixity
Infix, (LocatedA (PatBuilder p)
lforall a. a -> [a] -> [a]
:LocatedA (PatBuilder p)
rforall a. a -> [a] -> [a]
:[LocatedA (PatBuilder p)]
es), ([AddEpAnn]
anns forall a. [a] -> [a] -> [a]
++ forall a. [a] -> [a]
reverse [AddEpAnn]
ops forall a. [a] -> [a] -> [a]
++ [AddEpAnn]
cps)))
| Bool
otherwise
= do { Maybe
(GenLocated SrcSpanAnnN RdrName, LexicalFixity,
[LocatedA (PatBuilder p)], [AddEpAnn])
mb_l <- LocatedA (PatBuilder p)
-> [LocatedA (PatBuilder p)]
-> [AddEpAnn]
-> [AddEpAnn]
-> m (Maybe
(GenLocated SrcSpanAnnN RdrName, LexicalFixity,
[LocatedA (PatBuilder p)], [AddEpAnn]))
go LocatedA (PatBuilder p)
l [LocatedA (PatBuilder p)]
es [AddEpAnn]
ops [AddEpAnn]
cps
; case Maybe
(GenLocated SrcSpanAnnN RdrName, LexicalFixity,
[LocatedA (PatBuilder p)], [AddEpAnn])
mb_l of
Just (GenLocated SrcSpanAnnN RdrName
op', LexicalFixity
Infix, LocatedA (PatBuilder p)
j : LocatedA (PatBuilder p)
k : [LocatedA (PatBuilder p)]
es', [AddEpAnn]
anns')
-> forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> Maybe a
Just (GenLocated SrcSpanAnnN RdrName
op', LexicalFixity
Infix, LocatedA (PatBuilder p)
j forall a. a -> [a] -> [a]
: LocatedA (PatBuilder p)
op_app forall a. a -> [a] -> [a]
: [LocatedA (PatBuilder p)]
es', [AddEpAnn]
anns'))
where
op_app :: LocatedA (PatBuilder p)
op_app = forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc (forall p.
LocatedA (PatBuilder p)
-> GenLocated SrcSpanAnnN RdrName
-> LocatedA (PatBuilder p)
-> EpAnn [AddEpAnn]
-> PatBuilder p
PatBuilderOpApp LocatedA (PatBuilder p)
k
(forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
loc' RdrName
op) LocatedA (PatBuilder p)
r (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn Anchor
loca (forall a. [a] -> [a]
reverse [AddEpAnn]
opsforall a. [a] -> [a] -> [a]
++[AddEpAnn]
cps) EpAnnComments
cs))
Maybe
(GenLocated SrcSpanAnnN RdrName, LexicalFixity,
[LocatedA (PatBuilder p)], [AddEpAnn])
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing }
go LocatedA (PatBuilder p)
_ [LocatedA (PatBuilder p)]
_ [AddEpAnn]
_ [AddEpAnn]
_ = forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
mkBangTy :: EpAnn [AddEpAnn] -> SrcStrictness -> LHsType GhcPs -> HsType GhcPs
mkBangTy :: EpAnn [AddEpAnn] -> SrcStrictness -> LHsType GhcPs -> HsType GhcPs
mkBangTy EpAnn [AddEpAnn]
anns SrcStrictness
strictness =
forall pass.
XBangTy pass -> HsSrcBang -> LHsType pass -> HsType pass
HsBangTy EpAnn [AddEpAnn]
anns (SourceText -> SrcUnpackedness -> SrcStrictness -> HsSrcBang
HsSrcBang SourceText
NoSourceText SrcUnpackedness
NoSrcUnpack SrcStrictness
strictness)
data UnpackednessPragma =
UnpackednessPragma [AddEpAnn] SourceText SrcUnpackedness
addUnpackednessP :: MonadP m => Located UnpackednessPragma -> LHsType GhcPs -> m (LHsType GhcPs)
addUnpackednessP :: forall (m :: * -> *).
MonadP m =>
Located UnpackednessPragma -> LHsType GhcPs -> m (LHsType GhcPs)
addUnpackednessP (L SrcSpan
lprag (UnpackednessPragma [AddEpAnn]
anns SourceText
prag SrcUnpackedness
unpk)) LHsType GhcPs
ty = do
let l' :: SrcSpan
l' = SrcSpan -> SrcSpan -> SrcSpan
combineSrcSpans SrcSpan
lprag (forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
getLocA LHsType GhcPs
ty)
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l'
let an :: EpAnn [AddEpAnn]
an = forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l') [AddEpAnn]
anns EpAnnComments
cs
t' :: HsType GhcPs
t' = EpAnn [AddEpAnn]
-> GenLocated SrcSpanAnnA (HsType GhcPs) -> HsType GhcPs
addUnpackedness EpAnn [AddEpAnn]
an LHsType GhcPs
ty
forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l') HsType GhcPs
t')
where
addUnpackedness :: EpAnn [AddEpAnn]
-> GenLocated SrcSpanAnnA (HsType GhcPs) -> HsType GhcPs
addUnpackedness EpAnn [AddEpAnn]
an (L SrcSpanAnnA
_ (HsBangTy XBangTy GhcPs
x HsSrcBang
bang LHsType GhcPs
t))
| HsSrcBang SourceText
NoSourceText SrcUnpackedness
NoSrcUnpack SrcStrictness
strictness <- HsSrcBang
bang
= forall pass.
XBangTy pass -> HsSrcBang -> LHsType pass -> HsType pass
HsBangTy (EpAnn [AddEpAnn] -> [AddEpAnn] -> EpAnnComments -> EpAnn [AddEpAnn]
addAnns EpAnn [AddEpAnn]
an (EpAnn [AddEpAnn] -> [AddEpAnn]
epAnnAnns XBangTy GhcPs
x) (forall ann. EpAnn ann -> EpAnnComments
epAnnComments XBangTy GhcPs
x)) (SourceText -> SrcUnpackedness -> SrcStrictness -> HsSrcBang
HsSrcBang SourceText
prag SrcUnpackedness
unpk SrcStrictness
strictness) LHsType GhcPs
t
addUnpackedness EpAnn [AddEpAnn]
an GenLocated SrcSpanAnnA (HsType GhcPs)
t
= forall pass.
XBangTy pass -> HsSrcBang -> LHsType pass -> HsType pass
HsBangTy EpAnn [AddEpAnn]
an (SourceText -> SrcUnpackedness -> SrcStrictness -> HsSrcBang
HsSrcBang SourceText
prag SrcUnpackedness
unpk SrcStrictness
NoSrcStrict) GenLocated SrcSpanAnnA (HsType GhcPs)
t
checkMonadComp :: PV HsDoFlavour
checkMonadComp :: PV HsDoFlavour
checkMonadComp = do
Bool
monadComprehensions <- forall (m :: * -> *). MonadP m => ExtBits -> m Bool
getBit ExtBits
MonadComprehensionsBit
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if Bool
monadComprehensions
then HsDoFlavour
MonadComp
else HsDoFlavour
ListComp
newtype ECP =
ECP { ECP -> forall b. DisambECP b => PV (LocatedA b)
unECP :: forall b. DisambECP b => PV (LocatedA b) }
ecpFromExp :: LHsExpr GhcPs -> ECP
ecpFromExp :: LHsExpr GhcPs -> ECP
ecpFromExp LHsExpr GhcPs
a = (forall b. DisambECP b => PV (LocatedA b)) -> ECP
ECP (forall b. DisambECP b => LHsExpr GhcPs -> PV (LocatedA b)
ecpFromExp' LHsExpr GhcPs
a)
ecpFromCmd :: LHsCmd GhcPs -> ECP
ecpFromCmd :: LHsCmd GhcPs -> ECP
ecpFromCmd LHsCmd GhcPs
a = (forall b. DisambECP b => PV (LocatedA b)) -> ECP
ECP (forall b. DisambECP b => LHsCmd GhcPs -> PV (LocatedA b)
ecpFromCmd' LHsCmd GhcPs
a)
type Fbind b = Either (LHsRecField GhcPs (LocatedA b)) (LHsRecProj GhcPs (LocatedA b))
class DisambInfixOp b where
mkHsVarOpPV :: LocatedN RdrName -> PV (LocatedN b)
mkHsConOpPV :: LocatedN RdrName -> PV (LocatedN b)
mkHsInfixHolePV :: SrcSpan -> (EpAnnComments -> EpAnn EpAnnUnboundVar) -> PV (Located b)
instance DisambInfixOp (HsExpr GhcPs) where
mkHsVarOpPV :: GenLocated SrcSpanAnnN RdrName -> PV (LocatedN (HsExpr GhcPs))
mkHsVarOpPV GenLocated SrcSpanAnnN RdrName
v = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall l e. GenLocated l e -> l
getLoc GenLocated SrcSpanAnnN RdrName
v) (forall p. XVar p -> LIdP p -> HsExpr p
HsVar NoExtField
noExtField GenLocated SrcSpanAnnN RdrName
v)
mkHsConOpPV :: GenLocated SrcSpanAnnN RdrName -> PV (LocatedN (HsExpr GhcPs))
mkHsConOpPV GenLocated SrcSpanAnnN RdrName
v = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall l e. GenLocated l e -> l
getLoc GenLocated SrcSpanAnnN RdrName
v) (forall p. XVar p -> LIdP p -> HsExpr p
HsVar NoExtField
noExtField GenLocated SrcSpanAnnN RdrName
v)
mkHsInfixHolePV :: SrcSpan
-> (EpAnnComments -> EpAnn EpAnnUnboundVar)
-> PV (Located (HsExpr GhcPs))
mkHsInfixHolePV SrcSpan
l EpAnnComments -> EpAnn EpAnnUnboundVar
ann = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpan
l (EpAnn EpAnnUnboundVar -> HsExpr GhcPs
hsHoleExpr (EpAnnComments -> EpAnn EpAnnUnboundVar
ann EpAnnComments
cs))
instance DisambInfixOp RdrName where
mkHsConOpPV :: GenLocated SrcSpanAnnN RdrName
-> PV (GenLocated SrcSpanAnnN RdrName)
mkHsConOpPV (L SrcSpanAnnN
l RdrName
v) = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
l RdrName
v
mkHsVarOpPV :: GenLocated SrcSpanAnnN RdrName
-> PV (GenLocated SrcSpanAnnN RdrName)
mkHsVarOpPV (L SrcSpanAnnN
l RdrName
v) = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
l RdrName
v
mkHsInfixHolePV :: SrcSpan
-> (EpAnnComments -> EpAnn EpAnnUnboundVar) -> PV (Located RdrName)
mkHsInfixHolePV SrcSpan
l EpAnnComments -> EpAnn EpAnnUnboundVar
_ = forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
l forall a b. (a -> b) -> a -> b
$ PsMessage
PsErrInvalidInfixHole
type AnnoBody b
= ( Anno (GRHS GhcPs (LocatedA (Body b GhcPs))) ~ SrcAnn NoEpAnns
, Anno [LocatedA (Match GhcPs (LocatedA (Body b GhcPs)))] ~ SrcSpanAnnL
, Anno (Match GhcPs (LocatedA (Body b GhcPs))) ~ SrcSpanAnnA
, Anno (StmtLR GhcPs GhcPs (LocatedA (Body (Body b GhcPs) GhcPs))) ~ SrcSpanAnnA
, Anno [LocatedA (StmtLR GhcPs GhcPs
(LocatedA (Body (Body (Body b GhcPs) GhcPs) GhcPs)))] ~ SrcSpanAnnL
)
class (b ~ (Body b) GhcPs, AnnoBody b) => DisambECP b where
type Body b :: Type -> Type
ecpFromCmd' :: LHsCmd GhcPs -> PV (LocatedA b)
ecpFromExp' :: LHsExpr GhcPs -> PV (LocatedA b)
mkHsProjUpdatePV :: SrcSpan -> Located [LocatedAn NoEpAnns (DotFieldOcc GhcPs)]
-> LocatedA b -> Bool -> [AddEpAnn] -> PV (LHsRecProj GhcPs (LocatedA b))
mkHsLamPV
:: SrcSpan -> (EpAnnComments -> MatchGroup GhcPs (LocatedA b)) -> PV (LocatedA b)
mkHsLetPV
:: SrcSpan
-> LHsToken "let" GhcPs
-> HsLocalBinds GhcPs
-> LHsToken "in" GhcPs
-> LocatedA b
-> PV (LocatedA b)
type InfixOp b
superInfixOp
:: (DisambInfixOp (InfixOp b) => PV (LocatedA b )) -> PV (LocatedA b)
mkHsOpAppPV :: SrcSpan -> LocatedA b -> LocatedN (InfixOp b) -> LocatedA b
-> PV (LocatedA b)
mkHsCasePV :: SrcSpan -> LHsExpr GhcPs -> (LocatedL [LMatch GhcPs (LocatedA b)])
-> EpAnnHsCase -> PV (LocatedA b)
mkHsLamCasePV :: SrcSpan -> LamCaseVariant
-> (LocatedL [LMatch GhcPs (LocatedA b)]) -> [AddEpAnn]
-> PV (LocatedA b)
type FunArg b
superFunArg :: (DisambECP (FunArg b) => PV (LocatedA b)) -> PV (LocatedA b)
mkHsAppPV :: SrcSpanAnnA -> LocatedA b -> LocatedA (FunArg b) -> PV (LocatedA b)
mkHsAppTypePV :: SrcSpanAnnA -> LocatedA b -> LHsToken "@" GhcPs -> LHsType GhcPs -> PV (LocatedA b)
mkHsIfPV :: SrcSpan
-> LHsExpr GhcPs
-> Bool
-> LocatedA b
-> Bool
-> LocatedA b
-> AnnsIf
-> PV (LocatedA b)
mkHsDoPV ::
SrcSpan ->
Maybe ModuleName ->
LocatedL [LStmt GhcPs (LocatedA b)] ->
AnnList ->
PV (LocatedA b)
mkHsParPV :: SrcSpan -> LHsToken "(" GhcPs -> LocatedA b -> LHsToken ")" GhcPs -> PV (LocatedA b)
mkHsVarPV :: LocatedN RdrName -> PV (LocatedA b)
mkHsLitPV :: Located (HsLit GhcPs) -> PV (Located b)
mkHsOverLitPV :: LocatedAn a (HsOverLit GhcPs) -> PV (LocatedAn a b)
mkHsWildCardPV :: SrcSpan -> PV (Located b)
mkHsTySigPV
:: SrcSpanAnnA -> LocatedA b -> LHsType GhcPs -> [AddEpAnn] -> PV (LocatedA b)
mkHsExplicitListPV :: SrcSpan -> [LocatedA b] -> AnnList -> PV (LocatedA b)
mkHsSplicePV :: Located (HsUntypedSplice GhcPs) -> PV (Located b)
mkHsRecordPV ::
Bool ->
SrcSpan ->
SrcSpan ->
LocatedA b ->
([Fbind b], Maybe SrcSpan) ->
[AddEpAnn] ->
PV (LocatedA b)
mkHsNegAppPV :: SrcSpan -> LocatedA b -> [AddEpAnn] -> PV (LocatedA b)
mkHsSectionR_PV
:: SrcSpan -> LocatedA (InfixOp b) -> LocatedA b -> PV (Located b)
mkHsViewPatPV
:: SrcSpan -> LHsExpr GhcPs -> LocatedA b -> [AddEpAnn] -> PV (LocatedA b)
mkHsAsPatPV
:: SrcSpan -> LocatedN RdrName -> LHsToken "@" GhcPs -> LocatedA b -> PV (LocatedA b)
mkHsLazyPatPV :: SrcSpan -> LocatedA b -> [AddEpAnn] -> PV (LocatedA b)
mkHsBangPatPV :: SrcSpan -> LocatedA b -> [AddEpAnn] -> PV (LocatedA b)
mkSumOrTuplePV
:: SrcSpanAnnA -> Boxity -> SumOrTuple b -> [AddEpAnn] -> PV (LocatedA b)
rejectPragmaPV :: LocatedA b -> PV ()
instance DisambECP (HsCmd GhcPs) where
type Body (HsCmd GhcPs) = HsCmd
ecpFromCmd' :: LHsCmd GhcPs -> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
ecpFromCmd' = forall (m :: * -> *) a. Monad m => a -> m a
return
ecpFromExp' :: LHsExpr GhcPs -> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
ecpFromExp' (L SrcSpanAnnA
l HsExpr GhcPs
e) = forall a. SrcSpan -> SDoc -> PV a
cmdFail (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) (forall a. Outputable a => a -> SDoc
ppr HsExpr GhcPs
e)
mkHsProjUpdatePV :: SrcSpan
-> Located [LocatedAn NoEpAnns (DotFieldOcc GhcPs)]
-> GenLocated SrcSpanAnnA (HsCmd GhcPs)
-> Bool
-> [AddEpAnn]
-> PV (LHsRecProj GhcPs (GenLocated SrcSpanAnnA (HsCmd GhcPs)))
mkHsProjUpdatePV SrcSpan
l Located [LocatedAn NoEpAnns (DotFieldOcc GhcPs)]
_ GenLocated SrcSpanAnnA (HsCmd GhcPs)
_ Bool
_ [AddEpAnn]
_ = forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
l forall a b. (a -> b) -> a -> b
$
PsMessage
PsErrOverloadedRecordDotInvalid
mkHsLamPV :: SrcSpan
-> (EpAnnComments
-> MatchGroup GhcPs (GenLocated SrcSpanAnnA (HsCmd GhcPs)))
-> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mkHsLamPV SrcSpan
l EpAnnComments
-> MatchGroup GhcPs (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mg = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (forall id. XCmdLam id -> MatchGroup id (LHsCmd id) -> HsCmd id
HsCmdLam NoExtField
NoExtField (EpAnnComments
-> MatchGroup GhcPs (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mg EpAnnComments
cs))
mkHsLetPV :: SrcSpan
-> LHsToken "let" GhcPs
-> HsLocalBinds GhcPs
-> LHsToken "in" GhcPs
-> GenLocated SrcSpanAnnA (HsCmd GhcPs)
-> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mkHsLetPV SrcSpan
l LHsToken "let" GhcPs
tkLet HsLocalBinds GhcPs
bs LHsToken "in" GhcPs
tkIn GenLocated SrcSpanAnnA (HsCmd GhcPs)
e = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (forall id.
XCmdLet id
-> LHsToken "let" id
-> HsLocalBinds id
-> LHsToken "in" id
-> LHsCmd id
-> HsCmd id
HsCmdLet (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) NoEpAnns
NoEpAnns EpAnnComments
cs) LHsToken "let" GhcPs
tkLet HsLocalBinds GhcPs
bs LHsToken "in" GhcPs
tkIn GenLocated SrcSpanAnnA (HsCmd GhcPs)
e)
type InfixOp (HsCmd GhcPs) = HsExpr GhcPs
superInfixOp :: (DisambInfixOp (InfixOp (HsCmd GhcPs)) =>
PV (GenLocated SrcSpanAnnA (HsCmd GhcPs)))
-> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
superInfixOp DisambInfixOp (InfixOp (HsCmd GhcPs)) =>
PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
m = DisambInfixOp (InfixOp (HsCmd GhcPs)) =>
PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
m
mkHsOpAppPV :: SrcSpan
-> GenLocated SrcSpanAnnA (HsCmd GhcPs)
-> LocatedN (InfixOp (HsCmd GhcPs))
-> GenLocated SrcSpanAnnA (HsCmd GhcPs)
-> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mkHsOpAppPV SrcSpan
l GenLocated SrcSpanAnnA (HsCmd GhcPs)
c1 LocatedN (InfixOp (HsCmd GhcPs))
op GenLocated SrcSpanAnnA (HsCmd GhcPs)
c2 = do
let cmdArg :: GenLocated (SrcSpanAnn' a) (HsCmd p)
-> GenLocated (SrcAnn ann) (HsCmdTop p)
cmdArg GenLocated (SrcSpanAnn' a) (HsCmd p)
c = forall l e. l -> e -> GenLocated l e
L (forall a ann. SrcSpanAnn' a -> SrcAnn ann
l2l forall a b. (a -> b) -> a -> b
$ forall l e. GenLocated l e -> l
getLoc GenLocated (SrcSpanAnn' a) (HsCmd p)
c) forall a b. (a -> b) -> a -> b
$ forall p. XCmdTop p -> LHsCmd p -> HsCmdTop p
HsCmdTop NoExtField
noExtField GenLocated (SrcSpanAnn' a) (HsCmd p)
c
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) forall a b. (a -> b) -> a -> b
$ forall id.
XCmdArrForm id
-> LHsExpr id
-> LexicalFixity
-> Maybe Fixity
-> [LHsCmdTop id]
-> HsCmd id
HsCmdArrForm (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) (Maybe Anchor
-> Maybe AddEpAnn
-> Maybe AddEpAnn
-> [AddEpAnn]
-> [TrailingAnn]
-> AnnList
AnnList forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing [] []) EpAnnComments
cs) (forall e. LocatedN e -> LocatedA e
reLocL LocatedN (InfixOp (HsCmd GhcPs))
op) LexicalFixity
Infix forall a. Maybe a
Nothing [forall {p} {a} {ann}.
(XCmdTop p ~ NoExtField,
XRec p (HsCmd p) ~ GenLocated (SrcSpanAnn' a) (HsCmd p)) =>
GenLocated (SrcSpanAnn' a) (HsCmd p)
-> GenLocated (SrcAnn ann) (HsCmdTop p)
cmdArg GenLocated SrcSpanAnnA (HsCmd GhcPs)
c1, forall {p} {a} {ann}.
(XCmdTop p ~ NoExtField,
XRec p (HsCmd p) ~ GenLocated (SrcSpanAnn' a) (HsCmd p)) =>
GenLocated (SrcSpanAnn' a) (HsCmd p)
-> GenLocated (SrcAnn ann) (HsCmdTop p)
cmdArg GenLocated SrcSpanAnnA (HsCmd GhcPs)
c2]
mkHsCasePV :: SrcSpan
-> LHsExpr GhcPs
-> LocatedL [LMatch GhcPs (GenLocated SrcSpanAnnA (HsCmd GhcPs))]
-> EpAnnHsCase
-> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mkHsCasePV SrcSpan
l LHsExpr GhcPs
c (L SrcSpanAnnL
lm [LMatch GhcPs (GenLocated SrcSpanAnnA (HsCmd GhcPs))]
m) EpAnnHsCase
anns = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
let mg :: MatchGroup GhcPs (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mg = forall (p :: Pass) (body :: * -> *).
AnnoBody p body =>
Origin
-> LocatedL
[LocatedA (Match (GhcPass p) (LocatedA (body (GhcPass p))))]
-> MatchGroup (GhcPass p) (LocatedA (body (GhcPass p)))
mkMatchGroup Origin
FromSource (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnL
lm [LMatch GhcPs (GenLocated SrcSpanAnnA (HsCmd GhcPs))]
m)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (forall id.
XCmdCase id -> LHsExpr id -> MatchGroup id (LHsCmd id) -> HsCmd id
HsCmdCase (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) EpAnnHsCase
anns EpAnnComments
cs) LHsExpr GhcPs
c MatchGroup GhcPs (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mg)
mkHsLamCasePV :: SrcSpan
-> LamCaseVariant
-> LocatedL [LMatch GhcPs (GenLocated SrcSpanAnnA (HsCmd GhcPs))]
-> [AddEpAnn]
-> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mkHsLamCasePV SrcSpan
l LamCaseVariant
lc_variant (L SrcSpanAnnL
lm [LMatch GhcPs (GenLocated SrcSpanAnnA (HsCmd GhcPs))]
m) [AddEpAnn]
anns = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
let mg :: MatchGroup GhcPs (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mg = forall (p :: Pass) (body :: * -> *).
AnnoBody p body =>
Origin
-> LamCaseVariant
-> LocatedL
[LocatedA (Match (GhcPass p) (LocatedA (body (GhcPass p))))]
-> MatchGroup (GhcPass p) (LocatedA (body (GhcPass p)))
mkLamCaseMatchGroup Origin
FromSource LamCaseVariant
lc_variant (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnL
lm [LMatch GhcPs (GenLocated SrcSpanAnnA (HsCmd GhcPs))]
m)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (forall id.
XCmdLamCase id
-> LamCaseVariant -> MatchGroup id (LHsCmd id) -> HsCmd id
HsCmdLamCase (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) [AddEpAnn]
anns EpAnnComments
cs) LamCaseVariant
lc_variant MatchGroup GhcPs (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mg)
type FunArg (HsCmd GhcPs) = HsExpr GhcPs
superFunArg :: (DisambECP (FunArg (HsCmd GhcPs)) =>
PV (GenLocated SrcSpanAnnA (HsCmd GhcPs)))
-> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
superFunArg DisambECP (FunArg (HsCmd GhcPs)) =>
PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
m = DisambECP (FunArg (HsCmd GhcPs)) =>
PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
m
mkHsAppPV :: SrcSpanAnnA
-> GenLocated SrcSpanAnnA (HsCmd GhcPs)
-> LocatedA (FunArg (HsCmd GhcPs))
-> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mkHsAppPV SrcSpanAnnA
l GenLocated SrcSpanAnnA (HsCmd GhcPs)
c LocatedA (FunArg (HsCmd GhcPs))
e = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l)
LHsCmd GhcPs -> PV ()
checkCmdBlockArguments GenLocated SrcSpanAnnA (HsCmd GhcPs)
c
LHsExpr GhcPs -> PV ()
checkExpBlockArguments LocatedA (FunArg (HsCmd GhcPs))
e
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (forall id. XCmdApp id -> LHsCmd id -> LHsExpr id -> HsCmd id
HsCmdApp (RealSrcSpan -> EpAnnComments -> EpAnnCO
comment (SrcSpan -> RealSrcSpan
realSrcSpan forall a b. (a -> b) -> a -> b
$ forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) EpAnnComments
cs) GenLocated SrcSpanAnnA (HsCmd GhcPs)
c LocatedA (FunArg (HsCmd GhcPs))
e)
mkHsAppTypePV :: SrcSpanAnnA
-> GenLocated SrcSpanAnnA (HsCmd GhcPs)
-> LHsToken "@" GhcPs
-> LHsType GhcPs
-> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mkHsAppTypePV SrcSpanAnnA
l GenLocated SrcSpanAnnA (HsCmd GhcPs)
c LHsToken "@" GhcPs
_ LHsType GhcPs
t = forall a. SrcSpan -> SDoc -> PV a
cmdFail (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) (forall a. Outputable a => a -> SDoc
ppr GenLocated SrcSpanAnnA (HsCmd GhcPs)
c forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"@" forall doc. IsLine doc => doc -> doc -> doc
<> forall a. Outputable a => a -> SDoc
ppr LHsType GhcPs
t)
mkHsIfPV :: SrcSpan
-> LHsExpr GhcPs
-> Bool
-> GenLocated SrcSpanAnnA (HsCmd GhcPs)
-> Bool
-> GenLocated SrcSpanAnnA (HsCmd GhcPs)
-> AnnsIf
-> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mkHsIfPV SrcSpan
l LHsExpr GhcPs
c Bool
semi1 GenLocated SrcSpanAnnA (HsCmd GhcPs)
a Bool
semi2 GenLocated SrcSpanAnnA (HsCmd GhcPs)
b AnnsIf
anns = do
forall a b c.
(Outputable a, Outputable b, Outputable c) =>
(a -> Bool -> b -> Bool -> c -> PsMessage)
-> LocatedA a -> Bool -> LocatedA b -> Bool -> LocatedA c -> PV ()
checkDoAndIfThenElse HsExpr GhcPs
-> Bool -> HsCmd GhcPs -> Bool -> HsCmd GhcPs -> PsMessage
PsErrSemiColonsInCondCmd LHsExpr GhcPs
c Bool
semi1 GenLocated SrcSpanAnnA (HsCmd GhcPs)
a Bool
semi2 GenLocated SrcSpanAnnA (HsCmd GhcPs)
b
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (LHsExpr GhcPs
-> LHsCmd GhcPs -> LHsCmd GhcPs -> EpAnn AnnsIf -> HsCmd GhcPs
mkHsCmdIf LHsExpr GhcPs
c GenLocated SrcSpanAnnA (HsCmd GhcPs)
a GenLocated SrcSpanAnnA (HsCmd GhcPs)
b (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) AnnsIf
anns EpAnnComments
cs))
mkHsDoPV :: SrcSpan
-> Maybe ModuleName
-> LocatedL [LStmt GhcPs (GenLocated SrcSpanAnnA (HsCmd GhcPs))]
-> AnnList
-> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mkHsDoPV SrcSpan
l Maybe ModuleName
Nothing LocatedL [LStmt GhcPs (GenLocated SrcSpanAnnA (HsCmd GhcPs))]
stmts AnnList
anns = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (forall id. XCmdDo id -> XRec id [CmdLStmt id] -> HsCmd id
HsCmdDo (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) AnnList
anns EpAnnComments
cs) LocatedL [LStmt GhcPs (GenLocated SrcSpanAnnA (HsCmd GhcPs))]
stmts)
mkHsDoPV SrcSpan
l (Just ModuleName
m) LocatedL [LStmt GhcPs (GenLocated SrcSpanAnnA (HsCmd GhcPs))]
_ AnnList
_ = forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
l forall a b. (a -> b) -> a -> b
$ ModuleName -> PsMessage
PsErrQualifiedDoInCmd ModuleName
m
mkHsParPV :: SrcSpan
-> LHsToken "(" GhcPs
-> GenLocated SrcSpanAnnA (HsCmd GhcPs)
-> LHsToken ")" GhcPs
-> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mkHsParPV SrcSpan
l LHsToken "(" GhcPs
lpar GenLocated SrcSpanAnnA (HsCmd GhcPs)
c LHsToken ")" GhcPs
rpar = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (forall id.
XCmdPar id
-> LHsToken "(" id -> LHsCmd id -> LHsToken ")" id -> HsCmd id
HsCmdPar (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) NoEpAnns
NoEpAnns EpAnnComments
cs) LHsToken "(" GhcPs
lpar GenLocated SrcSpanAnnA (HsCmd GhcPs)
c LHsToken ")" GhcPs
rpar)
mkHsVarPV :: GenLocated SrcSpanAnnN RdrName
-> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mkHsVarPV (L SrcSpanAnnN
l RdrName
v) = forall a. SrcSpan -> SDoc -> PV a
cmdFail (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnN
l) (forall a. Outputable a => a -> SDoc
ppr RdrName
v)
mkHsLitPV :: Located (HsLit GhcPs) -> PV (Located (HsCmd GhcPs))
mkHsLitPV (L SrcSpan
l HsLit GhcPs
a) = forall a. SrcSpan -> SDoc -> PV a
cmdFail SrcSpan
l (forall a. Outputable a => a -> SDoc
ppr HsLit GhcPs
a)
mkHsOverLitPV :: forall a.
LocatedAn a (HsOverLit GhcPs) -> PV (LocatedAn a (HsCmd GhcPs))
mkHsOverLitPV (L SrcAnn a
l HsOverLit GhcPs
a) = forall a. SrcSpan -> SDoc -> PV a
cmdFail (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcAnn a
l) (forall a. Outputable a => a -> SDoc
ppr HsOverLit GhcPs
a)
mkHsWildCardPV :: SrcSpan -> PV (Located (HsCmd GhcPs))
mkHsWildCardPV SrcSpan
l = forall a. SrcSpan -> SDoc -> PV a
cmdFail SrcSpan
l (forall doc. IsLine doc => String -> doc
text String
"_")
mkHsTySigPV :: SrcSpanAnnA
-> GenLocated SrcSpanAnnA (HsCmd GhcPs)
-> LHsType GhcPs
-> [AddEpAnn]
-> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mkHsTySigPV SrcSpanAnnA
l GenLocated SrcSpanAnnA (HsCmd GhcPs)
a LHsType GhcPs
sig [AddEpAnn]
_ = forall a. SrcSpan -> SDoc -> PV a
cmdFail (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) (forall a. Outputable a => a -> SDoc
ppr GenLocated SrcSpanAnnA (HsCmd GhcPs)
a forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"::" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr LHsType GhcPs
sig)
mkHsExplicitListPV :: SrcSpan
-> [GenLocated SrcSpanAnnA (HsCmd GhcPs)]
-> AnnList
-> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mkHsExplicitListPV SrcSpan
l [GenLocated SrcSpanAnnA (HsCmd GhcPs)]
xs AnnList
_ = forall a. SrcSpan -> SDoc -> PV a
cmdFail SrcSpan
l forall a b. (a -> b) -> a -> b
$
forall doc. IsLine doc => doc -> doc
brackets (forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas forall a. Outputable a => a -> SDoc
ppr [GenLocated SrcSpanAnnA (HsCmd GhcPs)]
xs)
mkHsSplicePV :: Located (HsUntypedSplice GhcPs) -> PV (Located (HsCmd GhcPs))
mkHsSplicePV (L SrcSpan
l HsUntypedSplice GhcPs
sp) = forall a. SrcSpan -> SDoc -> PV a
cmdFail SrcSpan
l (forall (p :: Pass).
OutputableBndrId p =>
Bool -> Maybe Name -> HsUntypedSplice (GhcPass p) -> SDoc
pprUntypedSplice Bool
True forall a. Maybe a
Nothing HsUntypedSplice GhcPs
sp)
mkHsRecordPV :: Bool
-> SrcSpan
-> SrcSpan
-> GenLocated SrcSpanAnnA (HsCmd GhcPs)
-> ([Fbind (HsCmd GhcPs)], Maybe SrcSpan)
-> [AddEpAnn]
-> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mkHsRecordPV Bool
_ SrcSpan
l SrcSpan
_ GenLocated SrcSpanAnnA (HsCmd GhcPs)
a ([Fbind (HsCmd GhcPs)]
fbinds, Maybe SrcSpan
ddLoc) [AddEpAnn]
_ = do
let ([GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs))
(GenLocated SrcSpanAnnA (HsCmd GhcPs)))]
fs, [GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldLabelStrings GhcPs))
(GenLocated SrcSpanAnnA (HsCmd GhcPs)))]
ps) = forall a b. [Either a b] -> ([a], [b])
partitionEithers [Fbind (HsCmd GhcPs)]
fbinds
if Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldLabelStrings GhcPs))
(GenLocated SrcSpanAnnA (HsCmd GhcPs)))]
ps)
then forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
l forall a b. (a -> b) -> a -> b
$ PsMessage
PsErrOverloadedRecordDotInvalid
else forall a. SrcSpan -> SDoc -> PV a
cmdFail SrcSpan
l forall a b. (a -> b) -> a -> b
$ forall a. Outputable a => a -> SDoc
ppr GenLocated SrcSpanAnnA (HsCmd GhcPs)
a forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr (forall (p :: Pass) arg.
[LocatedA (HsRecField (GhcPass p) arg)]
-> Maybe SrcSpan -> HsRecFields (GhcPass p) arg
mk_rec_fields [GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs))
(GenLocated SrcSpanAnnA (HsCmd GhcPs)))]
fs Maybe SrcSpan
ddLoc)
mkHsNegAppPV :: SrcSpan
-> GenLocated SrcSpanAnnA (HsCmd GhcPs)
-> [AddEpAnn]
-> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mkHsNegAppPV SrcSpan
l GenLocated SrcSpanAnnA (HsCmd GhcPs)
a [AddEpAnn]
_ = forall a. SrcSpan -> SDoc -> PV a
cmdFail SrcSpan
l (forall doc. IsLine doc => String -> doc
text String
"-" forall doc. IsLine doc => doc -> doc -> doc
<> forall a. Outputable a => a -> SDoc
ppr GenLocated SrcSpanAnnA (HsCmd GhcPs)
a)
mkHsSectionR_PV :: SrcSpan
-> LocatedA (InfixOp (HsCmd GhcPs))
-> GenLocated SrcSpanAnnA (HsCmd GhcPs)
-> PV (Located (HsCmd GhcPs))
mkHsSectionR_PV SrcSpan
l LocatedA (InfixOp (HsCmd GhcPs))
op GenLocated SrcSpanAnnA (HsCmd GhcPs)
c = forall a. SrcSpan -> SDoc -> PV a
cmdFail SrcSpan
l forall a b. (a -> b) -> a -> b
$
let pp_op :: SDoc
pp_op = forall a. a -> Maybe a -> a
fromMaybe (forall a. HasCallStack => String -> a
panic String
"cannot print infix operator")
(forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> Maybe SDoc
ppr_infix_expr (forall l e. GenLocated l e -> e
unLoc LocatedA (InfixOp (HsCmd GhcPs))
op))
in SDoc
pp_op forall doc. IsLine doc => doc -> doc -> doc
<> forall a. Outputable a => a -> SDoc
ppr GenLocated SrcSpanAnnA (HsCmd GhcPs)
c
mkHsViewPatPV :: SrcSpan
-> LHsExpr GhcPs
-> GenLocated SrcSpanAnnA (HsCmd GhcPs)
-> [AddEpAnn]
-> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mkHsViewPatPV SrcSpan
l LHsExpr GhcPs
a GenLocated SrcSpanAnnA (HsCmd GhcPs)
b [AddEpAnn]
_ = forall a. SrcSpan -> SDoc -> PV a
cmdFail SrcSpan
l forall a b. (a -> b) -> a -> b
$
forall a. Outputable a => a -> SDoc
ppr LHsExpr GhcPs
a forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"->" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr GenLocated SrcSpanAnnA (HsCmd GhcPs)
b
mkHsAsPatPV :: SrcSpan
-> GenLocated SrcSpanAnnN RdrName
-> LHsToken "@" GhcPs
-> GenLocated SrcSpanAnnA (HsCmd GhcPs)
-> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mkHsAsPatPV SrcSpan
l GenLocated SrcSpanAnnN RdrName
v LHsToken "@" GhcPs
_ GenLocated SrcSpanAnnA (HsCmd GhcPs)
c = forall a. SrcSpan -> SDoc -> PV a
cmdFail SrcSpan
l forall a b. (a -> b) -> a -> b
$
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnN RdrName
v) forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => String -> doc
text String
"@" forall doc. IsLine doc => doc -> doc -> doc
<> forall a. Outputable a => a -> SDoc
ppr GenLocated SrcSpanAnnA (HsCmd GhcPs)
c
mkHsLazyPatPV :: SrcSpan
-> GenLocated SrcSpanAnnA (HsCmd GhcPs)
-> [AddEpAnn]
-> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mkHsLazyPatPV SrcSpan
l GenLocated SrcSpanAnnA (HsCmd GhcPs)
c [AddEpAnn]
_ = forall a. SrcSpan -> SDoc -> PV a
cmdFail SrcSpan
l forall a b. (a -> b) -> a -> b
$
forall doc. IsLine doc => String -> doc
text String
"~" forall doc. IsLine doc => doc -> doc -> doc
<> forall a. Outputable a => a -> SDoc
ppr GenLocated SrcSpanAnnA (HsCmd GhcPs)
c
mkHsBangPatPV :: SrcSpan
-> GenLocated SrcSpanAnnA (HsCmd GhcPs)
-> [AddEpAnn]
-> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mkHsBangPatPV SrcSpan
l GenLocated SrcSpanAnnA (HsCmd GhcPs)
c [AddEpAnn]
_ = forall a. SrcSpan -> SDoc -> PV a
cmdFail SrcSpan
l forall a b. (a -> b) -> a -> b
$
forall doc. IsLine doc => String -> doc
text String
"!" forall doc. IsLine doc => doc -> doc -> doc
<> forall a. Outputable a => a -> SDoc
ppr GenLocated SrcSpanAnnA (HsCmd GhcPs)
c
mkSumOrTuplePV :: SrcSpanAnnA
-> Boxity
-> SumOrTuple (HsCmd GhcPs)
-> [AddEpAnn]
-> PV (GenLocated SrcSpanAnnA (HsCmd GhcPs))
mkSumOrTuplePV SrcSpanAnnA
l Boxity
boxity SumOrTuple (HsCmd GhcPs)
a [AddEpAnn]
_ = forall a. SrcSpan -> SDoc -> PV a
cmdFail (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) (forall b. Outputable b => Boxity -> SumOrTuple b -> SDoc
pprSumOrTuple Boxity
boxity SumOrTuple (HsCmd GhcPs)
a)
rejectPragmaPV :: GenLocated SrcSpanAnnA (HsCmd GhcPs) -> PV ()
rejectPragmaPV GenLocated SrcSpanAnnA (HsCmd GhcPs)
_ = forall (m :: * -> *) a. Monad m => a -> m a
return ()
cmdFail :: SrcSpan -> SDoc -> PV a
cmdFail :: forall a. SrcSpan -> SDoc -> PV a
cmdFail SrcSpan
loc SDoc
e = forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
loc forall a b. (a -> b) -> a -> b
$ SDoc -> PsMessage
PsErrParseErrorInCmd SDoc
e
checkLamMatchGroup :: SrcSpan -> MatchGroup GhcPs (LHsExpr GhcPs) -> PV ()
checkLamMatchGroup :: SrcSpan -> MatchGroup GhcPs (LHsExpr GhcPs) -> PV ()
checkLamMatchGroup SrcSpan
l (MG { mg_alts :: forall p body. MatchGroup p body -> XRec p [LMatch p body]
mg_alts = (L SrcSpanAnnL
_ (GenLocated
SrcSpanAnnA (Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
matches:[GenLocated
SrcSpanAnnA (Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
_))}) = do
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (forall (t :: * -> *) a. Foldable t => t a -> Bool
null (forall (id :: Pass) body.
LMatch (GhcPass id) body -> [LPat (GhcPass id)]
hsLMatchPats GenLocated
SrcSpanAnnA (Match GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
matches)) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
l PsMessage
PsErrEmptyLambda
checkLamMatchGroup SrcSpan
_ MatchGroup GhcPs (LHsExpr GhcPs)
_ = forall (m :: * -> *) a. Monad m => a -> m a
return ()
instance DisambECP (HsExpr GhcPs) where
type Body (HsExpr GhcPs) = HsExpr
ecpFromCmd' :: LHsCmd GhcPs -> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
ecpFromCmd' (L SrcSpanAnnA
l HsCmd GhcPs
c) = do
forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) forall a b. (a -> b) -> a -> b
$ HsCmd GhcPs -> PsMessage
PsErrArrowCmdInExpr HsCmd GhcPs
c
forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (EpAnn EpAnnUnboundVar -> HsExpr GhcPs
hsHoleExpr forall a. EpAnn a
noAnn))
ecpFromExp' :: LHsExpr GhcPs -> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
ecpFromExp' = forall (m :: * -> *) a. Monad m => a -> m a
return
mkHsProjUpdatePV :: SrcSpan
-> Located [LocatedAn NoEpAnns (DotFieldOcc GhcPs)]
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> Bool
-> [AddEpAnn]
-> PV (LHsRecProj GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
mkHsProjUpdatePV SrcSpan
l Located [LocatedAn NoEpAnns (DotFieldOcc GhcPs)]
fields GenLocated SrcSpanAnnA (HsExpr GhcPs)
arg Bool
isPun [AddEpAnn]
anns = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ SrcSpanAnnA
-> Located [LocatedAn NoEpAnns (DotFieldOcc GhcPs)]
-> LHsExpr GhcPs
-> Bool
-> EpAnn [AddEpAnn]
-> LHsRecProj GhcPs (LHsExpr GhcPs)
mkRdrProjUpdate (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) Located [LocatedAn NoEpAnns (DotFieldOcc GhcPs)]
fields GenLocated SrcSpanAnnA (HsExpr GhcPs)
arg Bool
isPun (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) [AddEpAnn]
anns EpAnnComments
cs)
mkHsLamPV :: SrcSpan
-> (EpAnnComments
-> MatchGroup GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
-> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mkHsLamPV SrcSpan
l EpAnnComments
-> MatchGroup GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mg = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
let mg' :: MatchGroup GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mg' = EpAnnComments
-> MatchGroup GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mg EpAnnComments
cs
SrcSpan -> MatchGroup GhcPs (LHsExpr GhcPs) -> PV ()
checkLamMatchGroup SrcSpan
l MatchGroup GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mg'
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (forall p. XLam p -> MatchGroup p (LHsExpr p) -> HsExpr p
HsLam NoExtField
NoExtField MatchGroup GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mg')
mkHsLetPV :: SrcSpan
-> LHsToken "let" GhcPs
-> HsLocalBinds GhcPs
-> LHsToken "in" GhcPs
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mkHsLetPV SrcSpan
l LHsToken "let" GhcPs
tkLet HsLocalBinds GhcPs
bs LHsToken "in" GhcPs
tkIn GenLocated SrcSpanAnnA (HsExpr GhcPs)
c = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (forall p.
XLet p
-> LHsToken "let" p
-> HsLocalBinds p
-> LHsToken "in" p
-> LHsExpr p
-> HsExpr p
HsLet (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) NoEpAnns
NoEpAnns EpAnnComments
cs) LHsToken "let" GhcPs
tkLet HsLocalBinds GhcPs
bs LHsToken "in" GhcPs
tkIn GenLocated SrcSpanAnnA (HsExpr GhcPs)
c)
type InfixOp (HsExpr GhcPs) = HsExpr GhcPs
superInfixOp :: (DisambInfixOp (InfixOp (HsExpr GhcPs)) =>
PV (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
-> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
superInfixOp DisambInfixOp (InfixOp (HsExpr GhcPs)) =>
PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
m = DisambInfixOp (InfixOp (HsExpr GhcPs)) =>
PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
m
mkHsOpAppPV :: SrcSpan
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> LocatedN (InfixOp (HsExpr GhcPs))
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mkHsOpAppPV SrcSpan
l GenLocated SrcSpanAnnA (HsExpr GhcPs)
e1 LocatedN (InfixOp (HsExpr GhcPs))
op GenLocated SrcSpanAnnA (HsExpr GhcPs)
e2 = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) forall a b. (a -> b) -> a -> b
$ forall p.
XOpApp p -> LHsExpr p -> LHsExpr p -> LHsExpr p -> HsExpr p
OpApp (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) [] EpAnnComments
cs) GenLocated SrcSpanAnnA (HsExpr GhcPs)
e1 (forall e. LocatedN e -> LocatedA e
reLocL LocatedN (InfixOp (HsExpr GhcPs))
op) GenLocated SrcSpanAnnA (HsExpr GhcPs)
e2
mkHsCasePV :: SrcSpan
-> LHsExpr GhcPs
-> LocatedL [LMatch GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))]
-> EpAnnHsCase
-> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mkHsCasePV SrcSpan
l LHsExpr GhcPs
e (L SrcSpanAnnL
lm [LMatch GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))]
m) EpAnnHsCase
anns = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
let mg :: MatchGroup GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mg = forall (p :: Pass) (body :: * -> *).
AnnoBody p body =>
Origin
-> LocatedL
[LocatedA (Match (GhcPass p) (LocatedA (body (GhcPass p))))]
-> MatchGroup (GhcPass p) (LocatedA (body (GhcPass p)))
mkMatchGroup Origin
FromSource (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnL
lm [LMatch GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))]
m)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (forall p.
XCase p -> LHsExpr p -> MatchGroup p (LHsExpr p) -> HsExpr p
HsCase (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) EpAnnHsCase
anns EpAnnComments
cs) LHsExpr GhcPs
e MatchGroup GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mg)
mkHsLamCasePV :: SrcSpan
-> LamCaseVariant
-> LocatedL [LMatch GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))]
-> [AddEpAnn]
-> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mkHsLamCasePV SrcSpan
l LamCaseVariant
lc_variant (L SrcSpanAnnL
lm [LMatch GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))]
m) [AddEpAnn]
anns = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
let mg :: MatchGroup GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mg = forall (p :: Pass) (body :: * -> *).
AnnoBody p body =>
Origin
-> LamCaseVariant
-> LocatedL
[LocatedA (Match (GhcPass p) (LocatedA (body (GhcPass p))))]
-> MatchGroup (GhcPass p) (LocatedA (body (GhcPass p)))
mkLamCaseMatchGroup Origin
FromSource LamCaseVariant
lc_variant (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnL
lm [LMatch GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))]
m)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (forall p.
XLamCase p
-> LamCaseVariant -> MatchGroup p (LHsExpr p) -> HsExpr p
HsLamCase (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) [AddEpAnn]
anns EpAnnComments
cs) LamCaseVariant
lc_variant MatchGroup GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mg)
type FunArg (HsExpr GhcPs) = HsExpr GhcPs
superFunArg :: (DisambECP (FunArg (HsExpr GhcPs)) =>
PV (GenLocated SrcSpanAnnA (HsExpr GhcPs)))
-> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
superFunArg DisambECP (FunArg (HsExpr GhcPs)) =>
PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
m = DisambECP (FunArg (HsExpr GhcPs)) =>
PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
m
mkHsAppPV :: SrcSpanAnnA
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> LocatedA (FunArg (HsExpr GhcPs))
-> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mkHsAppPV SrcSpanAnnA
l GenLocated SrcSpanAnnA (HsExpr GhcPs)
e1 LocatedA (FunArg (HsExpr GhcPs))
e2 = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l)
LHsExpr GhcPs -> PV ()
checkExpBlockArguments GenLocated SrcSpanAnnA (HsExpr GhcPs)
e1
LHsExpr GhcPs -> PV ()
checkExpBlockArguments LocatedA (FunArg (HsExpr GhcPs))
e2
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (forall p. XApp p -> LHsExpr p -> LHsExpr p -> HsExpr p
HsApp (RealSrcSpan -> EpAnnComments -> EpAnnCO
comment (SrcSpan -> RealSrcSpan
realSrcSpan forall a b. (a -> b) -> a -> b
$ forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) EpAnnComments
cs) GenLocated SrcSpanAnnA (HsExpr GhcPs)
e1 LocatedA (FunArg (HsExpr GhcPs))
e2)
mkHsAppTypePV :: SrcSpanAnnA
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> LHsToken "@" GhcPs
-> LHsType GhcPs
-> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mkHsAppTypePV SrcSpanAnnA
l GenLocated SrcSpanAnnA (HsExpr GhcPs)
e LHsToken "@" GhcPs
at LHsType GhcPs
t = do
LHsExpr GhcPs -> PV ()
checkExpBlockArguments GenLocated SrcSpanAnnA (HsExpr GhcPs)
e
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (forall p.
XAppTypeE p
-> LHsExpr p -> LHsToken "@" p -> LHsWcType (NoGhcTc p) -> HsExpr p
HsAppType NoExtField
noExtField GenLocated SrcSpanAnnA (HsExpr GhcPs)
e LHsToken "@" GhcPs
at (forall thing. thing -> HsWildCardBndrs GhcPs thing
mkHsWildCardBndrs LHsType GhcPs
t))
mkHsIfPV :: SrcSpan
-> LHsExpr GhcPs
-> Bool
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> Bool
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> AnnsIf
-> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mkHsIfPV SrcSpan
l LHsExpr GhcPs
c Bool
semi1 GenLocated SrcSpanAnnA (HsExpr GhcPs)
a Bool
semi2 GenLocated SrcSpanAnnA (HsExpr GhcPs)
b AnnsIf
anns = do
forall a b c.
(Outputable a, Outputable b, Outputable c) =>
(a -> Bool -> b -> Bool -> c -> PsMessage)
-> LocatedA a -> Bool -> LocatedA b -> Bool -> LocatedA c -> PV ()
checkDoAndIfThenElse HsExpr GhcPs
-> Bool -> HsExpr GhcPs -> Bool -> HsExpr GhcPs -> PsMessage
PsErrSemiColonsInCondExpr LHsExpr GhcPs
c Bool
semi1 GenLocated SrcSpanAnnA (HsExpr GhcPs)
a Bool
semi2 GenLocated SrcSpanAnnA (HsExpr GhcPs)
b
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (LHsExpr GhcPs
-> LHsExpr GhcPs -> LHsExpr GhcPs -> EpAnn AnnsIf -> HsExpr GhcPs
mkHsIf LHsExpr GhcPs
c GenLocated SrcSpanAnnA (HsExpr GhcPs)
a GenLocated SrcSpanAnnA (HsExpr GhcPs)
b (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) AnnsIf
anns EpAnnComments
cs))
mkHsDoPV :: SrcSpan
-> Maybe ModuleName
-> LocatedL [LStmt GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))]
-> AnnList
-> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mkHsDoPV SrcSpan
l Maybe ModuleName
mod LocatedL [LStmt GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))]
stmts AnnList
anns = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (forall p. XDo p -> HsDoFlavour -> XRec p [ExprLStmt p] -> HsExpr p
HsDo (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) AnnList
anns EpAnnComments
cs) (Maybe ModuleName -> HsDoFlavour
DoExpr Maybe ModuleName
mod) LocatedL [LStmt GhcPs (GenLocated SrcSpanAnnA (HsExpr GhcPs))]
stmts)
mkHsParPV :: SrcSpan
-> LHsToken "(" GhcPs
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> LHsToken ")" GhcPs
-> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mkHsParPV SrcSpan
l LHsToken "(" GhcPs
lpar GenLocated SrcSpanAnnA (HsExpr GhcPs)
e LHsToken ")" GhcPs
rpar = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (forall p.
XPar p -> LHsToken "(" p -> LHsExpr p -> LHsToken ")" p -> HsExpr p
HsPar (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) NoEpAnns
NoEpAnns EpAnnComments
cs) LHsToken "(" GhcPs
lpar GenLocated SrcSpanAnnA (HsExpr GhcPs)
e LHsToken ")" GhcPs
rpar)
mkHsVarPV :: GenLocated SrcSpanAnnN RdrName
-> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mkHsVarPV v :: GenLocated SrcSpanAnnN RdrName
v@(L SrcSpanAnnN
l RdrName
_) = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall a ann. SrcSpanAnn' a -> SrcAnn ann
na2la SrcSpanAnnN
l) (forall p. XVar p -> LIdP p -> HsExpr p
HsVar NoExtField
noExtField GenLocated SrcSpanAnnN RdrName
v)
mkHsLitPV :: Located (HsLit GhcPs) -> PV (Located (HsExpr GhcPs))
mkHsLitPV (L SrcSpan
l HsLit GhcPs
a) = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpan
l (forall p. XLitE p -> HsLit p -> HsExpr p
HsLit (RealSrcSpan -> EpAnnComments -> EpAnnCO
comment (SrcSpan -> RealSrcSpan
realSrcSpan SrcSpan
l) EpAnnComments
cs) HsLit GhcPs
a)
mkHsOverLitPV :: forall a.
LocatedAn a (HsOverLit GhcPs) -> PV (LocatedAn a (HsExpr GhcPs))
mkHsOverLitPV (L SrcAnn a
l HsOverLit GhcPs
a) = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcAnn a
l)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcAnn a
l (forall p. XOverLitE p -> HsOverLit p -> HsExpr p
HsOverLit (RealSrcSpan -> EpAnnComments -> EpAnnCO
comment (SrcSpan -> RealSrcSpan
realSrcSpan (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcAnn a
l)) EpAnnComments
cs) HsOverLit GhcPs
a)
mkHsWildCardPV :: SrcSpan -> PV (Located (HsExpr GhcPs))
mkHsWildCardPV SrcSpan
l = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpan
l (EpAnn EpAnnUnboundVar -> HsExpr GhcPs
hsHoleExpr forall a. EpAnn a
noAnn)
mkHsTySigPV :: SrcSpanAnnA
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> LHsType GhcPs
-> [AddEpAnn]
-> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mkHsTySigPV SrcSpanAnnA
l GenLocated SrcSpanAnnA (HsExpr GhcPs)
a LHsType GhcPs
sig [AddEpAnn]
anns = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (forall p.
XExprWithTySig p
-> LHsExpr p -> LHsSigWcType (NoGhcTc p) -> HsExpr p
ExprWithTySig (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor forall a b. (a -> b) -> a -> b
$ forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) [AddEpAnn]
anns EpAnnComments
cs) GenLocated SrcSpanAnnA (HsExpr GhcPs)
a (LHsType GhcPs -> LHsSigWcType GhcPs
hsTypeToHsSigWcType LHsType GhcPs
sig))
mkHsExplicitListPV :: SrcSpan
-> [GenLocated SrcSpanAnnA (HsExpr GhcPs)]
-> AnnList
-> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mkHsExplicitListPV SrcSpan
l [GenLocated SrcSpanAnnA (HsExpr GhcPs)]
xs AnnList
anns = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (forall p. XExplicitList p -> [LHsExpr p] -> HsExpr p
ExplicitList (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) AnnList
anns EpAnnComments
cs) [GenLocated SrcSpanAnnA (HsExpr GhcPs)]
xs)
mkHsSplicePV :: Located (HsUntypedSplice GhcPs) -> PV (Located (HsExpr GhcPs))
mkHsSplicePV sp :: Located (HsUntypedSplice GhcPs)
sp@(L SrcSpan
l HsUntypedSplice GhcPs
_) = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall p. XUntypedSplice p -> HsUntypedSplice p -> HsExpr p
HsUntypedSplice (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) NoEpAnns
NoEpAnns EpAnnComments
cs)) Located (HsUntypedSplice GhcPs)
sp
mkHsRecordPV :: Bool
-> SrcSpan
-> SrcSpan
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> ([Fbind (HsExpr GhcPs)], Maybe SrcSpan)
-> [AddEpAnn]
-> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mkHsRecordPV Bool
opts SrcSpan
l SrcSpan
lrec GenLocated SrcSpanAnnA (HsExpr GhcPs)
a ([Fbind (HsExpr GhcPs)]
fbinds, Maybe SrcSpan
ddLoc) [AddEpAnn]
anns = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
HsExpr GhcPs
r <- Bool
-> LHsExpr GhcPs
-> SrcSpan
-> ([Fbind (HsExpr GhcPs)], Maybe SrcSpan)
-> EpAnn [AddEpAnn]
-> PV (HsExpr GhcPs)
mkRecConstrOrUpdate Bool
opts GenLocated SrcSpanAnnA (HsExpr GhcPs)
a SrcSpan
lrec ([Fbind (HsExpr GhcPs)]
fbinds, Maybe SrcSpan
ddLoc) (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) [AddEpAnn]
anns EpAnnComments
cs)
forall (m :: * -> *) a.
(MonadP m, Outputable a) =>
LocatedA a -> m (LocatedA a)
checkRecordSyntax (forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) HsExpr GhcPs
r)
mkHsNegAppPV :: SrcSpan
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> [AddEpAnn]
-> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mkHsNegAppPV SrcSpan
l GenLocated SrcSpanAnnA (HsExpr GhcPs)
a [AddEpAnn]
anns = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (forall p. XNegApp p -> LHsExpr p -> SyntaxExpr p -> HsExpr p
NegApp (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) [AddEpAnn]
anns EpAnnComments
cs) GenLocated SrcSpanAnnA (HsExpr GhcPs)
a forall (p :: Pass). IsPass p => SyntaxExpr (GhcPass p)
noSyntaxExpr)
mkHsSectionR_PV :: SrcSpan
-> LocatedA (InfixOp (HsExpr GhcPs))
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> PV (Located (HsExpr GhcPs))
mkHsSectionR_PV SrcSpan
l LocatedA (InfixOp (HsExpr GhcPs))
op GenLocated SrcSpanAnnA (HsExpr GhcPs)
e = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpan
l (forall p. XSectionR p -> LHsExpr p -> LHsExpr p -> HsExpr p
SectionR (RealSrcSpan -> EpAnnComments -> EpAnnCO
comment (SrcSpan -> RealSrcSpan
realSrcSpan SrcSpan
l) EpAnnComments
cs) LocatedA (InfixOp (HsExpr GhcPs))
op GenLocated SrcSpanAnnA (HsExpr GhcPs)
e)
mkHsViewPatPV :: SrcSpan
-> LHsExpr GhcPs
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> [AddEpAnn]
-> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mkHsViewPatPV SrcSpan
l LHsExpr GhcPs
a GenLocated SrcSpanAnnA (HsExpr GhcPs)
b [AddEpAnn]
_ = forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError (forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
l forall a b. (a -> b) -> a -> b
$ LHsExpr GhcPs -> LHsExpr GhcPs -> PsMessage
PsErrViewPatInExpr LHsExpr GhcPs
a GenLocated SrcSpanAnnA (HsExpr GhcPs)
b)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (EpAnn EpAnnUnboundVar -> HsExpr GhcPs
hsHoleExpr forall a. EpAnn a
noAnn))
mkHsAsPatPV :: SrcSpan
-> GenLocated SrcSpanAnnN RdrName
-> LHsToken "@" GhcPs
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mkHsAsPatPV SrcSpan
l GenLocated SrcSpanAnnN RdrName
v LHsToken "@" GhcPs
_ GenLocated SrcSpanAnnA (HsExpr GhcPs)
e = forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError (forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
l forall a b. (a -> b) -> a -> b
$ RdrName -> LHsExpr GhcPs -> PsMessage
PsErrTypeAppWithoutSpace (forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnN RdrName
v) GenLocated SrcSpanAnnA (HsExpr GhcPs)
e)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (EpAnn EpAnnUnboundVar -> HsExpr GhcPs
hsHoleExpr forall a. EpAnn a
noAnn))
mkHsLazyPatPV :: SrcSpan
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> [AddEpAnn]
-> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mkHsLazyPatPV SrcSpan
l GenLocated SrcSpanAnnA (HsExpr GhcPs)
e [AddEpAnn]
_ = forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError (forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
l forall a b. (a -> b) -> a -> b
$ LHsExpr GhcPs -> PsMessage
PsErrLazyPatWithoutSpace GenLocated SrcSpanAnnA (HsExpr GhcPs)
e)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (EpAnn EpAnnUnboundVar -> HsExpr GhcPs
hsHoleExpr forall a. EpAnn a
noAnn))
mkHsBangPatPV :: SrcSpan
-> GenLocated SrcSpanAnnA (HsExpr GhcPs)
-> [AddEpAnn]
-> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mkHsBangPatPV SrcSpan
l GenLocated SrcSpanAnnA (HsExpr GhcPs)
e [AddEpAnn]
_ = forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError (forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
l forall a b. (a -> b) -> a -> b
$ LHsExpr GhcPs -> PsMessage
PsErrBangPatWithoutSpace GenLocated SrcSpanAnnA (HsExpr GhcPs)
e)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (EpAnn EpAnnUnboundVar -> HsExpr GhcPs
hsHoleExpr forall a. EpAnn a
noAnn))
mkSumOrTuplePV :: SrcSpanAnnA
-> Boxity
-> SumOrTuple (HsExpr GhcPs)
-> [AddEpAnn]
-> PV (GenLocated SrcSpanAnnA (HsExpr GhcPs))
mkSumOrTuplePV = SrcSpanAnnA
-> Boxity
-> SumOrTuple (HsExpr GhcPs)
-> [AddEpAnn]
-> PV (LHsExpr GhcPs)
mkSumOrTupleExpr
rejectPragmaPV :: GenLocated SrcSpanAnnA (HsExpr GhcPs) -> PV ()
rejectPragmaPV (L SrcSpanAnnA
_ (OpApp XOpApp GhcPs
_ LHsExpr GhcPs
_ LHsExpr GhcPs
_ LHsExpr GhcPs
e)) =
forall b. DisambECP b => LocatedA b -> PV ()
rejectPragmaPV LHsExpr GhcPs
e
rejectPragmaPV (L SrcSpanAnnA
l (HsPragE XPragE GhcPs
_ HsPragE GhcPs
prag LHsExpr GhcPs
_)) = forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) forall a b. (a -> b) -> a -> b
$
(HsPragE GhcPs -> PsMessage
PsErrUnallowedPragma HsPragE GhcPs
prag)
rejectPragmaPV GenLocated SrcSpanAnnA (HsExpr GhcPs)
_ = forall (m :: * -> *) a. Monad m => a -> m a
return ()
hsHoleExpr :: EpAnn EpAnnUnboundVar -> HsExpr GhcPs
hsHoleExpr :: EpAnn EpAnnUnboundVar -> HsExpr GhcPs
hsHoleExpr EpAnn EpAnnUnboundVar
anns = forall p. XUnboundVar p -> RdrName -> HsExpr p
HsUnboundVar EpAnn EpAnnUnboundVar
anns (OccName -> RdrName
mkRdrUnqual (FastString -> OccName
mkVarOccFS (String -> FastString
fsLit String
"_")))
type instance Anno (GRHS GhcPs (LocatedA (PatBuilder GhcPs))) = SrcAnn NoEpAnns
type instance Anno [LocatedA (Match GhcPs (LocatedA (PatBuilder GhcPs)))] = SrcSpanAnnL
type instance Anno (Match GhcPs (LocatedA (PatBuilder GhcPs))) = SrcSpanAnnA
type instance Anno (StmtLR GhcPs GhcPs (LocatedA (PatBuilder GhcPs))) = SrcSpanAnnA
instance DisambECP (PatBuilder GhcPs) where
type Body (PatBuilder GhcPs) = PatBuilder
ecpFromCmd' :: LHsCmd GhcPs -> PV (LocatedA (PatBuilder GhcPs))
ecpFromCmd' (L SrcSpanAnnA
l HsCmd GhcPs
c) = forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) forall a b. (a -> b) -> a -> b
$ HsCmd GhcPs -> PsMessage
PsErrArrowCmdInPat HsCmd GhcPs
c
ecpFromExp' :: LHsExpr GhcPs -> PV (LocatedA (PatBuilder GhcPs))
ecpFromExp' (L SrcSpanAnnA
l HsExpr GhcPs
e) = forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) forall a b. (a -> b) -> a -> b
$ HsExpr GhcPs -> PsMessage
PsErrArrowExprInPat HsExpr GhcPs
e
mkHsLamPV :: SrcSpan
-> (EpAnnComments
-> MatchGroup GhcPs (LocatedA (PatBuilder GhcPs)))
-> PV (LocatedA (PatBuilder GhcPs))
mkHsLamPV SrcSpan
l EpAnnComments -> MatchGroup GhcPs (LocatedA (PatBuilder GhcPs))
_ = forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
l PsMessage
PsErrLambdaInPat
mkHsLetPV :: SrcSpan
-> LHsToken "let" GhcPs
-> HsLocalBinds GhcPs
-> LHsToken "in" GhcPs
-> LocatedA (PatBuilder GhcPs)
-> PV (LocatedA (PatBuilder GhcPs))
mkHsLetPV SrcSpan
l LHsToken "let" GhcPs
_ HsLocalBinds GhcPs
_ LHsToken "in" GhcPs
_ LocatedA (PatBuilder GhcPs)
_ = forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
l PsMessage
PsErrLetInPat
mkHsProjUpdatePV :: SrcSpan
-> Located [LocatedAn NoEpAnns (DotFieldOcc GhcPs)]
-> LocatedA (PatBuilder GhcPs)
-> Bool
-> [AddEpAnn]
-> PV (LHsRecProj GhcPs (LocatedA (PatBuilder GhcPs)))
mkHsProjUpdatePV SrcSpan
l Located [LocatedAn NoEpAnns (DotFieldOcc GhcPs)]
_ LocatedA (PatBuilder GhcPs)
_ Bool
_ [AddEpAnn]
_ = forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
l PsMessage
PsErrOverloadedRecordDotInvalid
type InfixOp (PatBuilder GhcPs) = RdrName
superInfixOp :: (DisambInfixOp (InfixOp (PatBuilder GhcPs)) =>
PV (LocatedA (PatBuilder GhcPs)))
-> PV (LocatedA (PatBuilder GhcPs))
superInfixOp DisambInfixOp (InfixOp (PatBuilder GhcPs)) =>
PV (LocatedA (PatBuilder GhcPs))
m = DisambInfixOp (InfixOp (PatBuilder GhcPs)) =>
PV (LocatedA (PatBuilder GhcPs))
m
mkHsOpAppPV :: SrcSpan
-> LocatedA (PatBuilder GhcPs)
-> LocatedN (InfixOp (PatBuilder GhcPs))
-> LocatedA (PatBuilder GhcPs)
-> PV (LocatedA (PatBuilder GhcPs))
mkHsOpAppPV SrcSpan
l LocatedA (PatBuilder GhcPs)
p1 LocatedN (InfixOp (PatBuilder GhcPs))
op LocatedA (PatBuilder GhcPs)
p2 = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
let anns :: EpAnn [AddEpAnn]
anns = forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) [] EpAnnComments
cs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) forall a b. (a -> b) -> a -> b
$ forall p.
LocatedA (PatBuilder p)
-> GenLocated SrcSpanAnnN RdrName
-> LocatedA (PatBuilder p)
-> EpAnn [AddEpAnn]
-> PatBuilder p
PatBuilderOpApp LocatedA (PatBuilder GhcPs)
p1 LocatedN (InfixOp (PatBuilder GhcPs))
op LocatedA (PatBuilder GhcPs)
p2 EpAnn [AddEpAnn]
anns
mkHsCasePV :: SrcSpan
-> LHsExpr GhcPs
-> LocatedL [LMatch GhcPs (LocatedA (PatBuilder GhcPs))]
-> EpAnnHsCase
-> PV (LocatedA (PatBuilder GhcPs))
mkHsCasePV SrcSpan
l LHsExpr GhcPs
_ LocatedL [LMatch GhcPs (LocatedA (PatBuilder GhcPs))]
_ EpAnnHsCase
_ = forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
l PsMessage
PsErrCaseInPat
mkHsLamCasePV :: SrcSpan
-> LamCaseVariant
-> LocatedL [LMatch GhcPs (LocatedA (PatBuilder GhcPs))]
-> [AddEpAnn]
-> PV (LocatedA (PatBuilder GhcPs))
mkHsLamCasePV SrcSpan
l LamCaseVariant
lc_variant LocatedL [LMatch GhcPs (LocatedA (PatBuilder GhcPs))]
_ [AddEpAnn]
_ = forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
l (LamCaseVariant -> PsMessage
PsErrLambdaCaseInPat LamCaseVariant
lc_variant)
type FunArg (PatBuilder GhcPs) = PatBuilder GhcPs
superFunArg :: (DisambECP (FunArg (PatBuilder GhcPs)) =>
PV (LocatedA (PatBuilder GhcPs)))
-> PV (LocatedA (PatBuilder GhcPs))
superFunArg DisambECP (FunArg (PatBuilder GhcPs)) =>
PV (LocatedA (PatBuilder GhcPs))
m = DisambECP (FunArg (PatBuilder GhcPs)) =>
PV (LocatedA (PatBuilder GhcPs))
m
mkHsAppPV :: SrcSpanAnnA
-> LocatedA (PatBuilder GhcPs)
-> LocatedA (FunArg (PatBuilder GhcPs))
-> PV (LocatedA (PatBuilder GhcPs))
mkHsAppPV SrcSpanAnnA
l LocatedA (PatBuilder GhcPs)
p1 LocatedA (FunArg (PatBuilder GhcPs))
p2 = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (forall p.
LocatedA (PatBuilder p) -> LocatedA (PatBuilder p) -> PatBuilder p
PatBuilderApp LocatedA (PatBuilder GhcPs)
p1 LocatedA (FunArg (PatBuilder GhcPs))
p2)
mkHsAppTypePV :: SrcSpanAnnA
-> LocatedA (PatBuilder GhcPs)
-> LHsToken "@" GhcPs
-> LHsType GhcPs
-> PV (LocatedA (PatBuilder GhcPs))
mkHsAppTypePV SrcSpanAnnA
l LocatedA (PatBuilder GhcPs)
p LHsToken "@" GhcPs
at LHsType GhcPs
t = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l)
let anns :: EpAnnCO
anns = forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor (forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
getLocA LHsType GhcPs
t)) NoEpAnns
NoEpAnns EpAnnComments
cs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (forall p.
LocatedA (PatBuilder p)
-> LHsToken "@" p -> HsPatSigType GhcPs -> PatBuilder p
PatBuilderAppType LocatedA (PatBuilder GhcPs)
p LHsToken "@" GhcPs
at (EpAnnCO -> LHsType GhcPs -> HsPatSigType GhcPs
mkHsPatSigType EpAnnCO
anns LHsType GhcPs
t))
mkHsIfPV :: SrcSpan
-> LHsExpr GhcPs
-> Bool
-> LocatedA (PatBuilder GhcPs)
-> Bool
-> LocatedA (PatBuilder GhcPs)
-> AnnsIf
-> PV (LocatedA (PatBuilder GhcPs))
mkHsIfPV SrcSpan
l LHsExpr GhcPs
_ Bool
_ LocatedA (PatBuilder GhcPs)
_ Bool
_ LocatedA (PatBuilder GhcPs)
_ AnnsIf
_ = forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
l PsMessage
PsErrIfThenElseInPat
mkHsDoPV :: SrcSpan
-> Maybe ModuleName
-> LocatedL [LStmt GhcPs (LocatedA (PatBuilder GhcPs))]
-> AnnList
-> PV (LocatedA (PatBuilder GhcPs))
mkHsDoPV SrcSpan
l Maybe ModuleName
_ LocatedL [LStmt GhcPs (LocatedA (PatBuilder GhcPs))]
_ AnnList
_ = forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
l PsMessage
PsErrDoNotationInPat
mkHsParPV :: SrcSpan
-> LHsToken "(" GhcPs
-> LocatedA (PatBuilder GhcPs)
-> LHsToken ")" GhcPs
-> PV (LocatedA (PatBuilder GhcPs))
mkHsParPV SrcSpan
l LHsToken "(" GhcPs
lpar LocatedA (PatBuilder GhcPs)
p LHsToken ")" GhcPs
rpar = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (forall p.
LHsToken "(" p
-> LocatedA (PatBuilder p) -> LHsToken ")" p -> PatBuilder p
PatBuilderPar LHsToken "(" GhcPs
lpar LocatedA (PatBuilder GhcPs)
p LHsToken ")" GhcPs
rpar)
mkHsVarPV :: GenLocated SrcSpanAnnN RdrName -> PV (LocatedA (PatBuilder GhcPs))
mkHsVarPV v :: GenLocated SrcSpanAnnN RdrName
v@(forall l e. GenLocated l e -> l
getLoc -> SrcSpanAnnN
l) = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall a ann. SrcSpanAnn' a -> SrcAnn ann
na2la SrcSpanAnnN
l) (forall p. GenLocated SrcSpanAnnN RdrName -> PatBuilder p
PatBuilderVar GenLocated SrcSpanAnnN RdrName
v)
mkHsLitPV :: Located (HsLit GhcPs) -> PV (Located (PatBuilder GhcPs))
mkHsLitPV lit :: Located (HsLit GhcPs)
lit@(L SrcSpan
l HsLit GhcPs
a) = do
Located (HsLit GhcPs) -> PV ()
checkUnboxedLitPat Located (HsLit GhcPs)
lit
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpan
l (forall p. Pat p -> PatBuilder p
PatBuilderPat (forall p. XLitPat p -> HsLit p -> Pat p
LitPat NoExtField
noExtField HsLit GhcPs
a))
mkHsOverLitPV :: forall a.
LocatedAn a (HsOverLit GhcPs)
-> PV (LocatedAn a (PatBuilder GhcPs))
mkHsOverLitPV (L SrcAnn a
l HsOverLit GhcPs
a) = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcAnn a
l (forall p. HsOverLit GhcPs -> PatBuilder p
PatBuilderOverLit HsOverLit GhcPs
a)
mkHsWildCardPV :: SrcSpan -> PV (Located (PatBuilder GhcPs))
mkHsWildCardPV SrcSpan
l = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpan
l (forall p. Pat p -> PatBuilder p
PatBuilderPat (forall p. XWildPat p -> Pat p
WildPat NoExtField
noExtField))
mkHsTySigPV :: SrcSpanAnnA
-> LocatedA (PatBuilder GhcPs)
-> LHsType GhcPs
-> [AddEpAnn]
-> PV (LocatedA (PatBuilder GhcPs))
mkHsTySigPV SrcSpanAnnA
l LocatedA (PatBuilder GhcPs)
b LHsType GhcPs
sig [AddEpAnn]
anns = do
GenLocated SrcSpanAnnA (Pat GhcPs)
p <- LocatedA (PatBuilder GhcPs) -> PV (LPat GhcPs)
checkLPat LocatedA (PatBuilder GhcPs)
b
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (forall p. Pat p -> PatBuilder p
PatBuilderPat (forall p. XSigPat p -> LPat p -> HsPatSigType (NoGhcTc p) -> Pat p
SigPat (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor forall a b. (a -> b) -> a -> b
$ forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) [AddEpAnn]
anns EpAnnComments
cs) GenLocated SrcSpanAnnA (Pat GhcPs)
p (EpAnnCO -> LHsType GhcPs -> HsPatSigType GhcPs
mkHsPatSigType forall a. EpAnn a
noAnn LHsType GhcPs
sig)))
mkHsExplicitListPV :: SrcSpan
-> [LocatedA (PatBuilder GhcPs)]
-> AnnList
-> PV (LocatedA (PatBuilder GhcPs))
mkHsExplicitListPV SrcSpan
l [LocatedA (PatBuilder GhcPs)]
xs AnnList
anns = do
[GenLocated SrcSpanAnnA (Pat GhcPs)]
ps <- forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse LocatedA (PatBuilder GhcPs) -> PV (LPat GhcPs)
checkLPat [LocatedA (PatBuilder GhcPs)]
xs
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (forall p. Pat p -> PatBuilder p
PatBuilderPat (forall p. XListPat p -> [LPat p] -> Pat p
ListPat (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) AnnList
anns EpAnnComments
cs) [GenLocated SrcSpanAnnA (Pat GhcPs)]
ps)))
mkHsSplicePV :: Located (HsUntypedSplice GhcPs) -> PV (Located (PatBuilder GhcPs))
mkHsSplicePV (L SrcSpan
l HsUntypedSplice GhcPs
sp) = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpan
l (forall p. Pat p -> PatBuilder p
PatBuilderPat (forall p. XSplicePat p -> HsUntypedSplice p -> Pat p
SplicePat NoExtField
noExtField HsUntypedSplice GhcPs
sp))
mkHsRecordPV :: Bool
-> SrcSpan
-> SrcSpan
-> LocatedA (PatBuilder GhcPs)
-> ([Fbind (PatBuilder GhcPs)], Maybe SrcSpan)
-> [AddEpAnn]
-> PV (LocatedA (PatBuilder GhcPs))
mkHsRecordPV Bool
_ SrcSpan
l SrcSpan
_ LocatedA (PatBuilder GhcPs)
a ([Fbind (PatBuilder GhcPs)]
fbinds, Maybe SrcSpan
ddLoc) [AddEpAnn]
anns = do
let ([GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs))
(LocatedA (PatBuilder GhcPs)))]
fs, [GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldLabelStrings GhcPs))
(LocatedA (PatBuilder GhcPs)))]
ps) = forall a b. [Either a b] -> ([a], [b])
partitionEithers [Fbind (PatBuilder GhcPs)]
fbinds
if Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldLabelStrings GhcPs))
(LocatedA (PatBuilder GhcPs)))]
ps)
then forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
l PsMessage
PsErrOverloadedRecordDotInvalid
else do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
PatBuilder GhcPs
r <- LocatedA (PatBuilder GhcPs)
-> HsRecFields GhcPs (LocatedA (PatBuilder GhcPs))
-> EpAnn [AddEpAnn]
-> PV (PatBuilder GhcPs)
mkPatRec LocatedA (PatBuilder GhcPs)
a (forall (p :: Pass) arg.
[LocatedA (HsRecField (GhcPass p) arg)]
-> Maybe SrcSpan -> HsRecFields (GhcPass p) arg
mk_rec_fields [GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs))
(LocatedA (PatBuilder GhcPs)))]
fs Maybe SrcSpan
ddLoc) (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) [AddEpAnn]
anns EpAnnComments
cs)
forall (m :: * -> *) a.
(MonadP m, Outputable a) =>
LocatedA a -> m (LocatedA a)
checkRecordSyntax (forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) PatBuilder GhcPs
r)
mkHsNegAppPV :: SrcSpan
-> LocatedA (PatBuilder GhcPs)
-> [AddEpAnn]
-> PV (LocatedA (PatBuilder GhcPs))
mkHsNegAppPV SrcSpan
l (L SrcSpanAnnA
lp PatBuilder GhcPs
p) [AddEpAnn]
anns = do
LocatedAn NoEpAnns (HsOverLit GhcPs)
lit <- case PatBuilder GhcPs
p of
PatBuilderOverLit HsOverLit GhcPs
pos_lit -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall l e. l -> e -> GenLocated l e
L (forall a ann. SrcSpanAnn' a -> SrcAnn ann
l2l SrcSpanAnnA
lp) HsOverLit GhcPs
pos_lit)
PatBuilder GhcPs
_ -> forall a. SrcSpan -> PsMessage -> PV a
patFail SrcSpan
l forall a b. (a -> b) -> a -> b
$ PatBuilder GhcPs -> PsErrInPatDetails -> PsMessage
PsErrInPat PatBuilder GhcPs
p PsErrInPatDetails
PEIP_NegApp
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
let an :: EpAnn [AddEpAnn]
an = forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) [AddEpAnn]
anns EpAnnComments
cs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (forall p. Pat p -> PatBuilder p
PatBuilderPat (LocatedAn NoEpAnns (HsOverLit GhcPs)
-> Maybe (SyntaxExpr GhcPs) -> EpAnn [AddEpAnn] -> Pat GhcPs
mkNPat LocatedAn NoEpAnns (HsOverLit GhcPs)
lit (forall a. a -> Maybe a
Just forall (p :: Pass). IsPass p => SyntaxExpr (GhcPass p)
noSyntaxExpr) EpAnn [AddEpAnn]
an))
mkHsSectionR_PV :: SrcSpan
-> LocatedA (InfixOp (PatBuilder GhcPs))
-> LocatedA (PatBuilder GhcPs)
-> PV (Located (PatBuilder GhcPs))
mkHsSectionR_PV SrcSpan
l LocatedA (InfixOp (PatBuilder GhcPs))
op LocatedA (PatBuilder GhcPs)
p = forall a. SrcSpan -> PsMessage -> PV a
patFail SrcSpan
l (RdrName -> PatBuilder GhcPs -> PsMessage
PsErrParseRightOpSectionInPat (forall l e. GenLocated l e -> e
unLoc LocatedA (InfixOp (PatBuilder GhcPs))
op) (forall l e. GenLocated l e -> e
unLoc LocatedA (PatBuilder GhcPs)
p))
mkHsViewPatPV :: SrcSpan
-> LHsExpr GhcPs
-> LocatedA (PatBuilder GhcPs)
-> [AddEpAnn]
-> PV (LocatedA (PatBuilder GhcPs))
mkHsViewPatPV SrcSpan
l LHsExpr GhcPs
a LocatedA (PatBuilder GhcPs)
b [AddEpAnn]
anns = do
GenLocated SrcSpanAnnA (Pat GhcPs)
p <- LocatedA (PatBuilder GhcPs) -> PV (LPat GhcPs)
checkLPat LocatedA (PatBuilder GhcPs)
b
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (forall p. Pat p -> PatBuilder p
PatBuilderPat (forall p. XViewPat p -> LHsExpr p -> LPat p -> Pat p
ViewPat (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) [AddEpAnn]
anns EpAnnComments
cs) LHsExpr GhcPs
a GenLocated SrcSpanAnnA (Pat GhcPs)
p))
mkHsAsPatPV :: SrcSpan
-> GenLocated SrcSpanAnnN RdrName
-> LHsToken "@" GhcPs
-> LocatedA (PatBuilder GhcPs)
-> PV (LocatedA (PatBuilder GhcPs))
mkHsAsPatPV SrcSpan
l GenLocated SrcSpanAnnN RdrName
v LHsToken "@" GhcPs
at LocatedA (PatBuilder GhcPs)
e = do
GenLocated SrcSpanAnnA (Pat GhcPs)
p <- LocatedA (PatBuilder GhcPs) -> PV (LPat GhcPs)
checkLPat LocatedA (PatBuilder GhcPs)
e
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (forall p. Pat p -> PatBuilder p
PatBuilderPat (forall p. XAsPat p -> LIdP p -> LHsToken "@" p -> LPat p -> Pat p
AsPat (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) NoEpAnns
NoEpAnns EpAnnComments
cs) GenLocated SrcSpanAnnN RdrName
v LHsToken "@" GhcPs
at GenLocated SrcSpanAnnA (Pat GhcPs)
p))
mkHsLazyPatPV :: SrcSpan
-> LocatedA (PatBuilder GhcPs)
-> [AddEpAnn]
-> PV (LocatedA (PatBuilder GhcPs))
mkHsLazyPatPV SrcSpan
l LocatedA (PatBuilder GhcPs)
e [AddEpAnn]
a = do
GenLocated SrcSpanAnnA (Pat GhcPs)
p <- LocatedA (PatBuilder GhcPs) -> PV (LPat GhcPs)
checkLPat LocatedA (PatBuilder GhcPs)
e
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (forall p. Pat p -> PatBuilder p
PatBuilderPat (forall p. XLazyPat p -> LPat p -> Pat p
LazyPat (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) [AddEpAnn]
a EpAnnComments
cs) GenLocated SrcSpanAnnA (Pat GhcPs)
p))
mkHsBangPatPV :: SrcSpan
-> LocatedA (PatBuilder GhcPs)
-> [AddEpAnn]
-> PV (LocatedA (PatBuilder GhcPs))
mkHsBangPatPV SrcSpan
l LocatedA (PatBuilder GhcPs)
e [AddEpAnn]
an = do
GenLocated SrcSpanAnnA (Pat GhcPs)
p <- LocatedA (PatBuilder GhcPs) -> PV (LPat GhcPs)
checkLPat LocatedA (PatBuilder GhcPs)
e
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor SrcSpan
l
let pb :: Pat GhcPs
pb = forall p. XBangPat p -> LPat p -> Pat p
BangPat (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor SrcSpan
l) [AddEpAnn]
an EpAnnComments
cs) GenLocated SrcSpanAnnA (Pat GhcPs)
p
SrcSpan -> Pat GhcPs -> PV ()
hintBangPat SrcSpan
l Pat GhcPs
pb
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (forall p. Pat p -> PatBuilder p
PatBuilderPat Pat GhcPs
pb)
mkSumOrTuplePV :: SrcSpanAnnA
-> Boxity
-> SumOrTuple (PatBuilder GhcPs)
-> [AddEpAnn]
-> PV (LocatedA (PatBuilder GhcPs))
mkSumOrTuplePV = SrcSpanAnnA
-> Boxity
-> SumOrTuple (PatBuilder GhcPs)
-> [AddEpAnn]
-> PV (LocatedA (PatBuilder GhcPs))
mkSumOrTuplePat
rejectPragmaPV :: LocatedA (PatBuilder GhcPs) -> PV ()
rejectPragmaPV LocatedA (PatBuilder GhcPs)
_ = forall (m :: * -> *) a. Monad m => a -> m a
return ()
checkUnboxedLitPat :: Located (HsLit GhcPs) -> PV ()
checkUnboxedLitPat :: Located (HsLit GhcPs) -> PV ()
checkUnboxedLitPat (L SrcSpan
loc HsLit GhcPs
lit) =
case HsLit GhcPs
lit of
HsStringPrim {}
-> forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
loc forall a b. (a -> b) -> a -> b
$
(HsLit GhcPs -> PsMessage
PsErrIllegalUnboxedStringInPat HsLit GhcPs
lit)
HsLit GhcPs
_ | HsLit GhcPs -> Bool
is_floating_lit HsLit GhcPs
lit
-> forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
loc forall a b. (a -> b) -> a -> b
$
(HsLit GhcPs -> PsMessage
PsErrIllegalUnboxedFloatingLitInPat HsLit GhcPs
lit)
| Bool
otherwise
-> forall (m :: * -> *) a. Monad m => a -> m a
return ()
where
is_floating_lit :: HsLit GhcPs -> Bool
is_floating_lit :: HsLit GhcPs -> Bool
is_floating_lit (HsFloatPrim {}) = Bool
True
is_floating_lit (HsDoublePrim {}) = Bool
True
is_floating_lit HsLit GhcPs
_ = Bool
False
mkPatRec ::
LocatedA (PatBuilder GhcPs) ->
HsRecFields GhcPs (LocatedA (PatBuilder GhcPs)) ->
EpAnn [AddEpAnn] ->
PV (PatBuilder GhcPs)
mkPatRec :: LocatedA (PatBuilder GhcPs)
-> HsRecFields GhcPs (LocatedA (PatBuilder GhcPs))
-> EpAnn [AddEpAnn]
-> PV (PatBuilder GhcPs)
mkPatRec (forall l e. GenLocated l e -> e
unLoc -> PatBuilderVar GenLocated SrcSpanAnnN RdrName
c) (HsRecFields [LHsRecField GhcPs (LocatedA (PatBuilder GhcPs))]
fs Maybe (XRec GhcPs RecFieldsDotDot)
dd) EpAnn [AddEpAnn]
anns
| RdrName -> Bool
isRdrDataCon (forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnN RdrName
c)
= do [GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs))
(GenLocated SrcSpanAnnA (Pat GhcPs)))]
fs <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM LHsRecField GhcPs (LocatedA (PatBuilder GhcPs))
-> PV (LHsRecField GhcPs (LPat GhcPs))
checkPatField [LHsRecField GhcPs (LocatedA (PatBuilder GhcPs))]
fs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall p. Pat p -> PatBuilder p
PatBuilderPat forall a b. (a -> b) -> a -> b
$ ConPat
{ pat_con_ext :: XConPat GhcPs
pat_con_ext = EpAnn [AddEpAnn]
anns
, pat_con :: XRec GhcPs (ConLikeP GhcPs)
pat_con = GenLocated SrcSpanAnnN RdrName
c
, pat_args :: HsConPatDetails GhcPs
pat_args = forall tyarg arg rec. rec -> HsConDetails tyarg arg rec
RecCon (forall p arg.
[LHsRecField p arg]
-> Maybe (XRec p RecFieldsDotDot) -> HsRecFields p arg
HsRecFields [GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs))
(GenLocated SrcSpanAnnA (Pat GhcPs)))]
fs Maybe (XRec GhcPs RecFieldsDotDot)
dd)
}
mkPatRec LocatedA (PatBuilder GhcPs)
p HsRecFields GhcPs (LocatedA (PatBuilder GhcPs))
_ EpAnn [AddEpAnn]
_ =
forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
getLocA LocatedA (PatBuilder GhcPs)
p) forall a b. (a -> b) -> a -> b
$
(PatBuilder GhcPs -> PsMessage
PsErrInvalidRecordCon (forall l e. GenLocated l e -> e
unLoc LocatedA (PatBuilder GhcPs)
p))
class DisambTD b where
mkHsAppTyHeadPV :: LHsType GhcPs -> PV (LocatedA b)
mkHsAppTyPV :: LocatedA b -> LHsType GhcPs -> PV (LocatedA b)
mkHsAppKindTyPV :: LocatedA b -> SrcSpan -> LHsType GhcPs -> PV (LocatedA b)
mkHsOpTyPV :: PromotionFlag -> LHsType GhcPs -> LocatedN RdrName -> LHsType GhcPs -> PV (LocatedA b)
mkUnpackednessPV :: Located UnpackednessPragma -> LocatedA b -> PV (LocatedA b)
instance DisambTD (HsType GhcPs) where
mkHsAppTyHeadPV :: LHsType GhcPs -> PV (GenLocated SrcSpanAnnA (HsType GhcPs))
mkHsAppTyHeadPV = forall (m :: * -> *) a. Monad m => a -> m a
return
mkHsAppTyPV :: GenLocated SrcSpanAnnA (HsType GhcPs)
-> LHsType GhcPs -> PV (GenLocated SrcSpanAnnA (HsType GhcPs))
mkHsAppTyPV GenLocated SrcSpanAnnA (HsType GhcPs)
t1 LHsType GhcPs
t2 = forall (m :: * -> *) a. Monad m => a -> m a
return (forall (p :: Pass).
LHsType (GhcPass p) -> LHsType (GhcPass p) -> LHsType (GhcPass p)
mkHsAppTy GenLocated SrcSpanAnnA (HsType GhcPs)
t1 LHsType GhcPs
t2)
mkHsAppKindTyPV :: GenLocated SrcSpanAnnA (HsType GhcPs)
-> SrcSpan
-> LHsType GhcPs
-> PV (GenLocated SrcSpanAnnA (HsType GhcPs))
mkHsAppKindTyPV GenLocated SrcSpanAnnA (HsType GhcPs)
t SrcSpan
l_at LHsType GhcPs
ki = forall (m :: * -> *) a. Monad m => a -> m a
return (forall (p :: Pass).
XAppKindTy (GhcPass p)
-> LHsType (GhcPass p)
-> LHsType (GhcPass p)
-> LHsType (GhcPass p)
mkHsAppKindTy SrcSpan
l_at GenLocated SrcSpanAnnA (HsType GhcPs)
t LHsType GhcPs
ki)
mkHsOpTyPV :: PromotionFlag
-> LHsType GhcPs
-> GenLocated SrcSpanAnnN RdrName
-> LHsType GhcPs
-> PV (GenLocated SrcSpanAnnA (HsType GhcPs))
mkHsOpTyPV PromotionFlag
prom LHsType GhcPs
t1 GenLocated SrcSpanAnnN RdrName
op LHsType GhcPs
t2 = forall (m :: * -> *) a. Monad m => a -> m a
return (PromotionFlag
-> LHsType GhcPs
-> GenLocated SrcSpanAnnN RdrName
-> LHsType GhcPs
-> LHsType GhcPs
mkLHsOpTy PromotionFlag
prom LHsType GhcPs
t1 GenLocated SrcSpanAnnN RdrName
op LHsType GhcPs
t2)
mkUnpackednessPV :: Located UnpackednessPragma
-> GenLocated SrcSpanAnnA (HsType GhcPs)
-> PV (GenLocated SrcSpanAnnA (HsType GhcPs))
mkUnpackednessPV = forall (m :: * -> *).
MonadP m =>
Located UnpackednessPragma -> LHsType GhcPs -> m (LHsType GhcPs)
addUnpackednessP
dataConBuilderCon :: DataConBuilder -> LocatedN RdrName
dataConBuilderCon :: DataConBuilder -> GenLocated SrcSpanAnnN RdrName
dataConBuilderCon (PrefixDataConBuilder OrdList (LHsType GhcPs)
_ GenLocated SrcSpanAnnN RdrName
dc) = GenLocated SrcSpanAnnN RdrName
dc
dataConBuilderCon (InfixDataConBuilder LHsType GhcPs
_ GenLocated SrcSpanAnnN RdrName
dc LHsType GhcPs
_) = GenLocated SrcSpanAnnN RdrName
dc
dataConBuilderDetails :: DataConBuilder -> HsConDeclH98Details GhcPs
dataConBuilderDetails :: DataConBuilder -> HsConDeclH98Details GhcPs
dataConBuilderDetails (PrefixDataConBuilder OrdList (LHsType GhcPs)
flds GenLocated SrcSpanAnnN RdrName
_)
| [L SrcSpanAnnA
l_t (HsRecTy XRecTy GhcPs
an [LConDeclField GhcPs]
fields)] <- forall (t :: * -> *) a. Foldable t => t a -> [a]
toList OrdList (LHsType GhcPs)
flds
= forall tyarg arg rec. rec -> HsConDetails tyarg arg rec
RecCon (forall l e. l -> e -> GenLocated l e
L (forall a. a -> SrcSpan -> SrcSpanAnn' a
SrcSpanAnn XRecTy GhcPs
an (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l_t)) [LConDeclField GhcPs]
fields)
dataConBuilderDetails (PrefixDataConBuilder OrdList (LHsType GhcPs)
flds GenLocated SrcSpanAnnN RdrName
_)
= forall tyarg arg rec.
[tyarg] -> [arg] -> HsConDetails tyarg arg rec
PrefixCon [Void]
noTypeArgs (forall a b. (a -> b) -> [a] -> [b]
map forall a (p :: Pass). a -> HsScaled (GhcPass p) a
hsLinear (forall (t :: * -> *) a. Foldable t => t a -> [a]
toList OrdList (LHsType GhcPs)
flds))
dataConBuilderDetails (InfixDataConBuilder LHsType GhcPs
lhs GenLocated SrcSpanAnnN RdrName
_ LHsType GhcPs
rhs)
= forall tyarg arg rec. arg -> arg -> HsConDetails tyarg arg rec
InfixCon (forall a (p :: Pass). a -> HsScaled (GhcPass p) a
hsLinear LHsType GhcPs
lhs) (forall a (p :: Pass). a -> HsScaled (GhcPass p) a
hsLinear LHsType GhcPs
rhs)
instance DisambTD DataConBuilder where
mkHsAppTyHeadPV :: LHsType GhcPs -> PV (LocatedA DataConBuilder)
mkHsAppTyHeadPV = LHsType GhcPs -> PV (LocatedA DataConBuilder)
tyToDataConBuilder
mkHsAppTyPV :: LocatedA DataConBuilder
-> LHsType GhcPs -> PV (LocatedA DataConBuilder)
mkHsAppTyPV (L SrcSpanAnnA
l (PrefixDataConBuilder OrdList (LHsType GhcPs)
flds GenLocated SrcSpanAnnN RdrName
fn)) LHsType GhcPs
t =
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$
forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan forall a b. (a -> b) -> a -> b
$ SrcSpan -> SrcSpan -> SrcSpan
combineSrcSpans (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) (forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
getLocA LHsType GhcPs
t))
(OrdList (LHsType GhcPs)
-> GenLocated SrcSpanAnnN RdrName -> DataConBuilder
PrefixDataConBuilder (OrdList (LHsType GhcPs)
flds forall a. OrdList a -> a -> OrdList a
`snocOL` LHsType GhcPs
t) GenLocated SrcSpanAnnN RdrName
fn)
mkHsAppTyPV (L SrcSpanAnnA
_ InfixDataConBuilder{}) LHsType GhcPs
_ =
forall a. HasCallStack => String -> a
panic String
"mkHsAppTyPV: InfixDataConBuilder"
mkHsAppKindTyPV :: LocatedA DataConBuilder
-> SrcSpan -> LHsType GhcPs -> PV (LocatedA DataConBuilder)
mkHsAppKindTyPV LocatedA DataConBuilder
lhs SrcSpan
l_at LHsType GhcPs
ki =
forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
l_at forall a b. (a -> b) -> a -> b
$
(DataConBuilder -> HsType GhcPs -> PsMessage
PsErrUnexpectedKindAppInDataCon (forall l e. GenLocated l e -> e
unLoc LocatedA DataConBuilder
lhs) (forall l e. GenLocated l e -> e
unLoc LHsType GhcPs
ki))
mkHsOpTyPV :: PromotionFlag
-> LHsType GhcPs
-> GenLocated SrcSpanAnnN RdrName
-> LHsType GhcPs
-> PV (LocatedA DataConBuilder)
mkHsOpTyPV PromotionFlag
prom LHsType GhcPs
lhs GenLocated SrcSpanAnnN RdrName
tc LHsType GhcPs
rhs = do
HsType GhcPs -> PV ()
check_no_ops (forall l e. GenLocated l e -> e
unLoc LHsType GhcPs
rhs)
GenLocated SrcSpanAnnN RdrName
data_con <- forall (m :: * -> *) a.
MonadP m =>
Either (MsgEnvelope PsMessage) a -> m a
eitherToP forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnN RdrName
-> Either (MsgEnvelope PsMessage) (GenLocated SrcSpanAnnN RdrName)
tyConToDataCon GenLocated SrcSpanAnnN RdrName
tc
PromotionFlag -> GenLocated SrcSpanAnnN RdrName -> PV ()
checkNotPromotedDataCon PromotionFlag
prom GenLocated SrcSpanAnnN RdrName
data_con
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (LHsType GhcPs
-> GenLocated SrcSpanAnnN RdrName
-> LHsType GhcPs
-> DataConBuilder
InfixDataConBuilder LHsType GhcPs
lhs GenLocated SrcSpanAnnN RdrName
data_con LHsType GhcPs
rhs)
where
l :: SrcSpanAnnA
l = forall a e1 e2.
Semigroup a =>
GenLocated (SrcAnn a) e1 -> GenLocated (SrcAnn a) e2 -> SrcAnn a
combineLocsA LHsType GhcPs
lhs LHsType GhcPs
rhs
check_no_ops :: HsType GhcPs -> PV ()
check_no_ops (HsBangTy XBangTy GhcPs
_ HsSrcBang
_ LHsType GhcPs
t) = HsType GhcPs -> PV ()
check_no_ops (forall l e. GenLocated l e -> e
unLoc LHsType GhcPs
t)
check_no_ops (HsOpTy{}) =
forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) forall a b. (a -> b) -> a -> b
$
(HsType GhcPs -> RdrName -> HsType GhcPs -> PsMessage
PsErrInvalidInfixDataCon (forall l e. GenLocated l e -> e
unLoc LHsType GhcPs
lhs) (forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnN RdrName
tc) (forall l e. GenLocated l e -> e
unLoc LHsType GhcPs
rhs))
check_no_ops HsType GhcPs
_ = forall (m :: * -> *) a. Monad m => a -> m a
return ()
mkUnpackednessPV :: Located UnpackednessPragma
-> LocatedA DataConBuilder -> PV (LocatedA DataConBuilder)
mkUnpackednessPV Located UnpackednessPragma
unpk LocatedA DataConBuilder
constr_stuff
| L SrcSpanAnnA
_ (InfixDataConBuilder LHsType GhcPs
lhs GenLocated SrcSpanAnnN RdrName
data_con LHsType GhcPs
rhs) <- LocatedA DataConBuilder
constr_stuff
=
do GenLocated SrcSpanAnnA (HsType GhcPs)
lhs' <- forall (m :: * -> *).
MonadP m =>
Located UnpackednessPragma -> LHsType GhcPs -> m (LHsType GhcPs)
addUnpackednessP Located UnpackednessPragma
unpk LHsType GhcPs
lhs
let l :: SrcSpanAnnA
l = forall a e1 e2.
Semigroup a =>
GenLocated (SrcAnn a) e1 -> GenLocated (SrcAnn a) e2 -> SrcAnn a
combineLocsA (forall e ann. Located e -> LocatedAn ann e
reLocA Located UnpackednessPragma
unpk) LocatedA DataConBuilder
constr_stuff
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (LHsType GhcPs
-> GenLocated SrcSpanAnnN RdrName
-> LHsType GhcPs
-> DataConBuilder
InfixDataConBuilder GenLocated SrcSpanAnnA (HsType GhcPs)
lhs' GenLocated SrcSpanAnnN RdrName
data_con LHsType GhcPs
rhs)
| Bool
otherwise =
do forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall l e. GenLocated l e -> l
getLoc Located UnpackednessPragma
unpk) PsMessage
PsErrUnpackDataCon
forall (m :: * -> *) a. Monad m => a -> m a
return LocatedA DataConBuilder
constr_stuff
tyToDataConBuilder :: LHsType GhcPs -> PV (LocatedA DataConBuilder)
tyToDataConBuilder :: LHsType GhcPs -> PV (LocatedA DataConBuilder)
tyToDataConBuilder (L SrcSpanAnnA
l (HsTyVar XTyVar GhcPs
_ PromotionFlag
prom XRec GhcPs (IdP GhcPs)
v)) = do
GenLocated SrcSpanAnnN RdrName
data_con <- forall (m :: * -> *) a.
MonadP m =>
Either (MsgEnvelope PsMessage) a -> m a
eitherToP forall a b. (a -> b) -> a -> b
$ GenLocated SrcSpanAnnN RdrName
-> Either (MsgEnvelope PsMessage) (GenLocated SrcSpanAnnN RdrName)
tyConToDataCon XRec GhcPs (IdP GhcPs)
v
PromotionFlag -> GenLocated SrcSpanAnnN RdrName -> PV ()
checkNotPromotedDataCon PromotionFlag
prom GenLocated SrcSpanAnnN RdrName
data_con
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (OrdList (LHsType GhcPs)
-> GenLocated SrcSpanAnnN RdrName -> DataConBuilder
PrefixDataConBuilder forall a. OrdList a
nilOL GenLocated SrcSpanAnnN RdrName
data_con)
tyToDataConBuilder (L SrcSpanAnnA
l (HsTupleTy XTupleTy GhcPs
_ HsTupleSort
HsBoxedOrConstraintTuple [LHsType GhcPs]
ts)) = do
let data_con :: GenLocated SrcSpanAnnN RdrName
data_con = forall l e. l -> e -> GenLocated l e
L (forall a ann. SrcSpanAnn' a -> SrcAnn ann
l2l SrcSpanAnnA
l) (forall thing. NamedThing thing => thing -> RdrName
getRdrName (Boxity -> Int -> DataCon
tupleDataCon Boxity
Boxed (forall (t :: * -> *) a. Foldable t => t a -> Int
length [LHsType GhcPs]
ts)))
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (OrdList (LHsType GhcPs)
-> GenLocated SrcSpanAnnN RdrName -> DataConBuilder
PrefixDataConBuilder (forall a. [a] -> OrdList a
toOL [LHsType GhcPs]
ts) GenLocated SrcSpanAnnN RdrName
data_con)
tyToDataConBuilder LHsType GhcPs
t =
forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
getLocA LHsType GhcPs
t) forall a b. (a -> b) -> a -> b
$
(HsType GhcPs -> PsMessage
PsErrInvalidDataCon (forall l e. GenLocated l e -> e
unLoc LHsType GhcPs
t))
checkNotPromotedDataCon :: PromotionFlag -> LocatedN RdrName -> PV ()
checkNotPromotedDataCon :: PromotionFlag -> GenLocated SrcSpanAnnN RdrName -> PV ()
checkNotPromotedDataCon PromotionFlag
NotPromoted GenLocated SrcSpanAnnN RdrName
_ = forall (m :: * -> *) a. Monad m => a -> m a
return ()
checkNotPromotedDataCon PromotionFlag
IsPromoted (L SrcSpanAnnN
l RdrName
name) =
forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnN
l) forall a b. (a -> b) -> a -> b
$
RdrName -> PsMessage
PsErrIllegalPromotionQuoteDataCon RdrName
name
checkPrecP
:: Located (SourceText,Int)
-> Located (OrdList (LocatedN RdrName))
-> P ()
checkPrecP :: Located (SourceText, Int)
-> Located (OrdList (GenLocated SrcSpanAnnN RdrName)) -> P ()
checkPrecP (L SrcSpan
l (SourceText
_,Int
i)) (L SrcSpan
_ OrdList (GenLocated SrcSpanAnnN RdrName)
ol)
| Int
0 forall a. Ord a => a -> a -> Bool
<= Int
i, Int
i forall a. Ord a => a -> a -> Bool
<= Int
maxPrecedence = forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all forall {l}. GenLocated l RdrName -> Bool
specialOp OrdList (GenLocated SrcSpanAnnN RdrName)
ol = forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
| Bool
otherwise = forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
l (Int -> PsMessage
PsErrPrecedenceOutOfRange Int
i)
where
specialOp :: GenLocated l RdrName -> Bool
specialOp GenLocated l RdrName
op = forall l e. GenLocated l e -> e
unLoc GenLocated l RdrName
op forall a. Eq a => a -> a -> Bool
== forall thing. NamedThing thing => thing -> RdrName
getRdrName TyCon
unrestrictedFunTyCon
mkRecConstrOrUpdate
:: Bool
-> LHsExpr GhcPs
-> SrcSpan
-> ([Fbind (HsExpr GhcPs)], Maybe SrcSpan)
-> EpAnn [AddEpAnn]
-> PV (HsExpr GhcPs)
mkRecConstrOrUpdate :: Bool
-> LHsExpr GhcPs
-> SrcSpan
-> ([Fbind (HsExpr GhcPs)], Maybe SrcSpan)
-> EpAnn [AddEpAnn]
-> PV (HsExpr GhcPs)
mkRecConstrOrUpdate Bool
_ (L SrcSpanAnnA
_ (HsVar XVar GhcPs
_ (L SrcSpanAnnN
l RdrName
c))) SrcSpan
_lrec ([Fbind (HsExpr GhcPs)]
fbinds,Maybe SrcSpan
dd) EpAnn [AddEpAnn]
anns
| RdrName -> Bool
isRdrDataCon RdrName
c
= do
let ([GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs))
(GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
fs, [GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldLabelStrings GhcPs))
(GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
ps) = forall a b. [Either a b] -> ([a], [b])
partitionEithers [Fbind (HsExpr GhcPs)]
fbinds
case [GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldLabelStrings GhcPs))
(GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
ps of
GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldLabelStrings GhcPs))
(GenLocated SrcSpanAnnA (HsExpr GhcPs)))
p:[GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldLabelStrings GhcPs))
(GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
_ -> forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
getLocA GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldLabelStrings GhcPs))
(GenLocated SrcSpanAnnA (HsExpr GhcPs)))
p) forall a b. (a -> b) -> a -> b
$
PsMessage
PsErrOverloadedRecordDotInvalid
[GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldLabelStrings GhcPs))
(GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return (GenLocated SrcSpanAnnN RdrName
-> HsRecordBinds GhcPs -> EpAnn [AddEpAnn] -> HsExpr GhcPs
mkRdrRecordCon (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
l RdrName
c) (forall (p :: Pass) arg.
[LocatedA (HsRecField (GhcPass p) arg)]
-> Maybe SrcSpan -> HsRecFields (GhcPass p) arg
mk_rec_fields [GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs))
(GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
fs Maybe SrcSpan
dd) EpAnn [AddEpAnn]
anns)
mkRecConstrOrUpdate Bool
overloaded_update LHsExpr GhcPs
exp SrcSpan
_ ([Fbind (HsExpr GhcPs)]
fs,Maybe SrcSpan
dd) EpAnn [AddEpAnn]
anns
| Just SrcSpan
dd_loc <- Maybe SrcSpan
dd = forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
dd_loc forall a b. (a -> b) -> a -> b
$
PsMessage
PsErrDotsInRecordUpdate
| Bool
otherwise = Bool
-> LHsExpr GhcPs
-> [Fbind (HsExpr GhcPs)]
-> EpAnn [AddEpAnn]
-> PV (HsExpr GhcPs)
mkRdrRecordUpd Bool
overloaded_update LHsExpr GhcPs
exp [Fbind (HsExpr GhcPs)]
fs EpAnn [AddEpAnn]
anns
mkRdrRecordUpd :: Bool -> LHsExpr GhcPs -> [Fbind (HsExpr GhcPs)] -> EpAnn [AddEpAnn] -> PV (HsExpr GhcPs)
mkRdrRecordUpd :: Bool
-> LHsExpr GhcPs
-> [Fbind (HsExpr GhcPs)]
-> EpAnn [AddEpAnn]
-> PV (HsExpr GhcPs)
mkRdrRecordUpd Bool
overloaded_on exp :: LHsExpr GhcPs
exp@(L SrcSpanAnnA
loc HsExpr GhcPs
_) [Fbind (HsExpr GhcPs)]
fbinds EpAnn [AddEpAnn]
anns = do
let ([GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs))
(GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
fs, [GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldLabelStrings GhcPs))
(GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
ps) = forall a b. [Either a b] -> ([a], [b])
partitionEithers [Fbind (HsExpr GhcPs)]
fbinds
fs' :: [LHsRecUpdField GhcPs]
fs' :: [LHsRecUpdField GhcPs]
fs' = forall a b. (a -> b) -> [a] -> [b]
map (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap HsRecField GhcPs (LHsExpr GhcPs) -> HsRecUpdField GhcPs
mk_rec_upd_field) [GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs))
(GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
fs
case Bool
overloaded_on of
Bool
False | Bool -> Bool
not forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t a -> Bool
null [GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldLabelStrings GhcPs))
(GenLocated SrcSpanAnnA (HsExpr GhcPs)))]
ps ->
forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
loc) PsMessage
PsErrOverloadedRecordUpdateNotEnabled
Bool
False ->
forall (m :: * -> *) a. Monad m => a -> m a
return RecordUpd {
rupd_ext :: XRecordUpd GhcPs
rupd_ext = EpAnn [AddEpAnn]
anns
, rupd_expr :: LHsExpr GhcPs
rupd_expr = LHsExpr GhcPs
exp
, rupd_flds :: Either [LHsRecUpdField GhcPs] [LHsRecProj GhcPs (LHsExpr GhcPs)]
rupd_flds = forall a b. a -> Either a b
Left [LHsRecUpdField GhcPs]
fs' }
Bool
True -> do
let qualifiedFields :: [GenLocated (SrcAnn NoEpAnns) (AmbiguousFieldOcc GhcPs)]
qualifiedFields =
[ forall l e. l -> e -> GenLocated l e
L SrcAnn NoEpAnns
l AmbiguousFieldOcc GhcPs
lbl | L SrcSpanAnnA
_ (HsFieldBind XHsFieldBind
(GenLocated (SrcAnn NoEpAnns) (AmbiguousFieldOcc GhcPs))
_ (L SrcAnn NoEpAnns
l AmbiguousFieldOcc GhcPs
lbl) GenLocated SrcSpanAnnA (HsExpr GhcPs)
_ Bool
_) <- [LHsRecUpdField GhcPs]
fs'
, RdrName -> Bool
isQual forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: Pass). AmbiguousFieldOcc (GhcPass p) -> RdrName
rdrNameAmbiguousFieldOcc forall a b. (a -> b) -> a -> b
$ AmbiguousFieldOcc GhcPs
lbl
]
case [GenLocated (SrcAnn NoEpAnns) (AmbiguousFieldOcc GhcPs)]
qualifiedFields of
GenLocated (SrcAnn NoEpAnns) (AmbiguousFieldOcc GhcPs)
qf:[GenLocated (SrcAnn NoEpAnns) (AmbiguousFieldOcc GhcPs)]
_ -> forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
getLocA GenLocated (SrcAnn NoEpAnns) (AmbiguousFieldOcc GhcPs)
qf) forall a b. (a -> b) -> a -> b
$
PsMessage
PsErrOverloadedRecordUpdateNoQualifiedFields
[GenLocated (SrcAnn NoEpAnns) (AmbiguousFieldOcc GhcPs)]
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return RecordUpd
{ rupd_ext :: XRecordUpd GhcPs
rupd_ext = EpAnn [AddEpAnn]
anns
, rupd_expr :: LHsExpr GhcPs
rupd_expr = LHsExpr GhcPs
exp
, rupd_flds :: Either [LHsRecUpdField GhcPs] [LHsRecProj GhcPs (LHsExpr GhcPs)]
rupd_flds = forall a b. b -> Either a b
Right ([Fbind (HsExpr GhcPs)] -> [LHsRecProj GhcPs (LHsExpr GhcPs)]
toProjUpdates [Fbind (HsExpr GhcPs)]
fbinds) }
where
toProjUpdates :: [Fbind (HsExpr GhcPs)] -> [LHsRecUpdProj GhcPs]
toProjUpdates :: [Fbind (HsExpr GhcPs)] -> [LHsRecProj GhcPs (LHsExpr GhcPs)]
toProjUpdates = forall a b. (a -> b) -> [a] -> [b]
map (\case { Right GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldLabelStrings GhcPs))
(GenLocated SrcSpanAnnA (HsExpr GhcPs)))
p -> GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldLabelStrings GhcPs))
(GenLocated SrcSpanAnnA (HsExpr GhcPs)))
p; Left GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs))
(GenLocated SrcSpanAnnA (HsExpr GhcPs)))
f -> LHsRecField GhcPs (LHsExpr GhcPs)
-> LHsRecProj GhcPs (LHsExpr GhcPs)
recFieldToProjUpdate GenLocated
SrcSpanAnnA
(HsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs))
(GenLocated SrcSpanAnnA (HsExpr GhcPs)))
f })
recFieldToProjUpdate :: LHsRecField GhcPs (LHsExpr GhcPs) -> LHsRecUpdProj GhcPs
recFieldToProjUpdate :: LHsRecField GhcPs (LHsExpr GhcPs)
-> LHsRecProj GhcPs (LHsExpr GhcPs)
recFieldToProjUpdate (L SrcSpanAnnA
l (HsFieldBind XHsFieldBind (GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs))
anns (L SrcAnn NoEpAnns
_ (FieldOcc XCFieldOcc GhcPs
_ (L SrcSpanAnnN
loc RdrName
rdr))) GenLocated SrcSpanAnnA (HsExpr GhcPs)
arg Bool
pun)) =
let f :: FastString
f = OccName -> FastString
occNameFS forall b c a. (b -> c) -> (a -> b) -> a -> c
. RdrName -> OccName
rdrNameOcc forall a b. (a -> b) -> a -> b
$ RdrName
rdr
fl :: DotFieldOcc GhcPs
fl = forall p.
XCDotFieldOcc p -> XRec p FieldLabelString -> DotFieldOcc p
DotFieldOcc forall a. EpAnn a
noAnn (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
loc (FastString -> FieldLabelString
FieldLabelString FastString
f))
lf :: SrcSpan
lf = forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnN
loc
in SrcSpanAnnA
-> Located [LocatedAn NoEpAnns (DotFieldOcc GhcPs)]
-> LHsExpr GhcPs
-> Bool
-> EpAnn [AddEpAnn]
-> LHsRecProj GhcPs (LHsExpr GhcPs)
mkRdrProjUpdate SrcSpanAnnA
l (forall l e. l -> e -> GenLocated l e
L SrcSpan
lf [forall l e. l -> e -> GenLocated l e
L (forall a ann. SrcSpanAnn' a -> SrcAnn ann
l2l SrcSpanAnnN
loc) DotFieldOcc GhcPs
fl]) (FastString -> LHsExpr GhcPs
punnedVar FastString
f) Bool
pun XHsFieldBind (GenLocated (SrcAnn NoEpAnns) (FieldOcc GhcPs))
anns
where
punnedVar :: FastString -> LHsExpr GhcPs
punnedVar :: FastString -> LHsExpr GhcPs
punnedVar FastString
f = if Bool -> Bool
not Bool
pun then GenLocated SrcSpanAnnA (HsExpr GhcPs)
arg else forall a an. a -> LocatedAn an a
noLocA forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall p. XVar p -> LIdP p -> HsExpr p
HsVar NoExtField
noExtField forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a an. a -> LocatedAn an a
noLocA forall b c a. (b -> c) -> (a -> b) -> a -> c
. OccName -> RdrName
mkRdrUnqual forall b c a. (b -> c) -> (a -> b) -> a -> c
. FastString -> OccName
mkVarOccFS forall a b. (a -> b) -> a -> b
$ FastString
f
mkRdrRecordCon
:: LocatedN RdrName -> HsRecordBinds GhcPs -> EpAnn [AddEpAnn] -> HsExpr GhcPs
mkRdrRecordCon :: GenLocated SrcSpanAnnN RdrName
-> HsRecordBinds GhcPs -> EpAnn [AddEpAnn] -> HsExpr GhcPs
mkRdrRecordCon GenLocated SrcSpanAnnN RdrName
con HsRecordBinds GhcPs
flds EpAnn [AddEpAnn]
anns
= RecordCon { rcon_ext :: XRecordCon GhcPs
rcon_ext = EpAnn [AddEpAnn]
anns, rcon_con :: XRec GhcPs (ConLikeP GhcPs)
rcon_con = GenLocated SrcSpanAnnN RdrName
con, rcon_flds :: HsRecordBinds GhcPs
rcon_flds = HsRecordBinds GhcPs
flds }
mk_rec_fields :: [LocatedA (HsRecField (GhcPass p) arg)] -> Maybe SrcSpan -> HsRecFields (GhcPass p) arg
mk_rec_fields :: forall (p :: Pass) arg.
[LocatedA (HsRecField (GhcPass p) arg)]
-> Maybe SrcSpan -> HsRecFields (GhcPass p) arg
mk_rec_fields [LocatedA (HsRecField (GhcPass p) arg)]
fs Maybe SrcSpan
Nothing = HsRecFields { rec_flds :: [LHsRecField (GhcPass p) arg]
rec_flds = [LocatedA (HsRecField (GhcPass p) arg)]
fs, rec_dotdot :: Maybe (XRec (GhcPass p) RecFieldsDotDot)
rec_dotdot = forall a. Maybe a
Nothing }
mk_rec_fields [LocatedA (HsRecField (GhcPass p) arg)]
fs (Just SrcSpan
s) = HsRecFields { rec_flds :: [LHsRecField (GhcPass p) arg]
rec_flds = [LocatedA (HsRecField (GhcPass p) arg)]
fs
, rec_dotdot :: Maybe (XRec (GhcPass p) RecFieldsDotDot)
rec_dotdot = forall a. a -> Maybe a
Just (forall l e. l -> e -> GenLocated l e
L SrcSpan
s (Int -> RecFieldsDotDot
RecFieldsDotDot forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t a -> Int
length [LocatedA (HsRecField (GhcPass p) arg)]
fs)) }
mk_rec_upd_field :: HsRecField GhcPs (LHsExpr GhcPs) -> HsRecUpdField GhcPs
mk_rec_upd_field :: HsRecField GhcPs (LHsExpr GhcPs) -> HsRecUpdField GhcPs
mk_rec_upd_field (HsFieldBind XHsFieldBind (LFieldOcc GhcPs)
noAnn (L SrcAnn NoEpAnns
loc (FieldOcc XCFieldOcc GhcPs
_ XRec GhcPs RdrName
rdr)) LHsExpr GhcPs
arg Bool
pun)
= forall lhs rhs.
XHsFieldBind lhs -> lhs -> rhs -> Bool -> HsFieldBind lhs rhs
HsFieldBind XHsFieldBind (LFieldOcc GhcPs)
noAnn (forall l e. l -> e -> GenLocated l e
L SrcAnn NoEpAnns
loc (forall pass.
XUnambiguous pass -> XRec pass RdrName -> AmbiguousFieldOcc pass
Unambiguous NoExtField
noExtField XRec GhcPs RdrName
rdr)) LHsExpr GhcPs
arg Bool
pun
mkInlinePragma :: SourceText -> (InlineSpec, RuleMatchInfo) -> Maybe Activation
-> InlinePragma
mkInlinePragma :: SourceText
-> (InlineSpec, RuleMatchInfo) -> Maybe Activation -> InlinePragma
mkInlinePragma SourceText
src (InlineSpec
inl, RuleMatchInfo
match_info) Maybe Activation
mb_act
= InlinePragma { inl_src :: SourceText
inl_src = SourceText
src
, inl_inline :: InlineSpec
inl_inline = InlineSpec
inl
, inl_sat :: Maybe Int
inl_sat = forall a. Maybe a
Nothing
, inl_act :: Activation
inl_act = Activation
act
, inl_rule :: RuleMatchInfo
inl_rule = RuleMatchInfo
match_info }
where
act :: Activation
act = case Maybe Activation
mb_act of
Just Activation
act -> Activation
act
Maybe Activation
Nothing ->
case InlineSpec
inl of
NoInline SourceText
_ -> Activation
NeverActive
Opaque SourceText
_ -> Activation
NeverActive
InlineSpec
_other -> Activation
AlwaysActive
mkOpaquePragma :: SourceText -> InlinePragma
mkOpaquePragma :: SourceText -> InlinePragma
mkOpaquePragma SourceText
src
= InlinePragma { inl_src :: SourceText
inl_src = SourceText
src
, inl_inline :: InlineSpec
inl_inline = SourceText -> InlineSpec
Opaque SourceText
src
, inl_sat :: Maybe Int
inl_sat = forall a. Maybe a
Nothing
, inl_act :: Activation
inl_act = Activation
NeverActive
, inl_rule :: RuleMatchInfo
inl_rule = RuleMatchInfo
FunLike
}
checkNewOrData :: SrcSpan -> RdrName -> Bool -> NewOrData -> [LConDecl GhcPs]
-> P (DataDefnCons (LConDecl GhcPs))
checkNewOrData :: SrcSpan
-> RdrName
-> Bool
-> NewOrData
-> [LConDecl GhcPs]
-> P (DataDefnCons (LConDecl GhcPs))
checkNewOrData SrcSpan
span RdrName
name Bool
is_type_data = forall a b c. ((a, b) -> c) -> a -> b -> c
curry forall a b. (a -> b) -> a -> b
$ \ case
(NewOrData
NewType, [LConDecl GhcPs
a]) -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a. a -> DataDefnCons a
NewTypeCon LConDecl GhcPs
a
(NewOrData
DataType, [LConDecl GhcPs]
as) -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a. Bool -> [a] -> DataDefnCons a
DataTypeCons Bool
is_type_data ([GenLocated SrcSpanAnnA (ConDecl GhcPs)]
-> [GenLocated SrcSpanAnnA (ConDecl GhcPs)]
handle_type_data [LConDecl GhcPs]
as)
(NewOrData
NewType, [LConDecl GhcPs]
as) -> forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
span forall a b. (a -> b) -> a -> b
$ RdrName -> Int -> PsMessage
PsErrMultipleConForNewtype RdrName
name (forall (t :: * -> *) a. Foldable t => t a -> Int
length [LConDecl GhcPs]
as)
where
handle_type_data :: [GenLocated SrcSpanAnnA (ConDecl GhcPs)]
-> [GenLocated SrcSpanAnnA (ConDecl GhcPs)]
handle_type_data
| Bool
is_type_data = forall a b. (a -> b) -> [a] -> [b]
map (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {pass} {f :: * -> *}.
(XRec pass (IdP pass) ~ f RdrName, Functor f) =>
ConDecl pass -> ConDecl pass
promote_constructor)
| Bool
otherwise = forall a. a -> a
id
promote_constructor :: ConDecl pass -> ConDecl pass
promote_constructor (dc :: ConDecl pass
dc@ConDeclGADT { con_names :: forall pass. ConDecl pass -> NonEmpty (LIdP pass)
con_names = NonEmpty (XRec pass (IdP pass))
cons })
= ConDecl pass
dc { con_names :: NonEmpty (XRec pass (IdP pass))
con_names = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap RdrName -> RdrName
promote_name) NonEmpty (XRec pass (IdP pass))
cons }
promote_constructor (dc :: ConDecl pass
dc@ConDeclH98 { con_name :: forall pass. ConDecl pass -> LIdP pass
con_name = XRec pass (IdP pass)
con })
= ConDecl pass
dc { con_name :: XRec pass (IdP pass)
con_name = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap RdrName -> RdrName
promote_name XRec pass (IdP pass)
con }
promote_constructor ConDecl pass
dc = ConDecl pass
dc
promote_name :: RdrName -> RdrName
promote_name RdrName
name = forall a. a -> Maybe a -> a
fromMaybe RdrName
name (RdrName -> Maybe RdrName
promoteRdrName RdrName
name)
mkImport :: Located CCallConv
-> Located Safety
-> (Located StringLiteral, LocatedN RdrName, LHsSigType GhcPs)
-> P (EpAnn [AddEpAnn] -> HsDecl GhcPs)
mkImport :: Located CCallConv
-> Located Safety
-> (Located StringLiteral, GenLocated SrcSpanAnnN RdrName,
LHsSigType GhcPs)
-> P (EpAnn [AddEpAnn] -> HsDecl GhcPs)
mkImport Located CCallConv
cconv Located Safety
safety (L SrcSpan
loc (StringLiteral SourceText
esrc FastString
entity Maybe RealSrcSpan
_), GenLocated SrcSpanAnnN RdrName
v, LHsSigType GhcPs
ty) =
case forall l e. GenLocated l e -> e
unLoc Located CCallConv
cconv of
CCallConv
CCallConv -> ForeignImport GhcPs -> P (EpAnn [AddEpAnn] -> HsDecl GhcPs)
returnSpec forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< P (ForeignImport GhcPs)
mkCImport
CCallConv
CApiConv -> do
ForeignImport GhcPs
imp <- P (ForeignImport GhcPs)
mkCImport
if forall {pass}. ForeignImport pass -> Bool
isCWrapperImport ForeignImport GhcPs
imp
then forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
loc PsMessage
PsErrInvalidCApiImport
else ForeignImport GhcPs -> P (EpAnn [AddEpAnn] -> HsDecl GhcPs)
returnSpec ForeignImport GhcPs
imp
CCallConv
StdCallConv -> ForeignImport GhcPs -> P (EpAnn [AddEpAnn] -> HsDecl GhcPs)
returnSpec forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< P (ForeignImport GhcPs)
mkCImport
CCallConv
PrimCallConv -> P (EpAnn [AddEpAnn] -> HsDecl GhcPs)
mkOtherImport
CCallConv
JavaScriptCallConv -> P (EpAnn [AddEpAnn] -> HsDecl GhcPs)
mkOtherImport
where
mkCImport :: P (ForeignImport GhcPs)
mkCImport = do
let e :: String
e = FastString -> String
unpackFS FastString
entity
case forall (p :: Pass).
Located CCallConv
-> Located Safety
-> FastString
-> String
-> Located SourceText
-> Maybe (ForeignImport (GhcPass p))
parseCImport Located CCallConv
cconv Located Safety
safety (RdrName -> FastString
mkExtName (forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnN RdrName
v)) String
e (forall l e. l -> e -> GenLocated l e
L SrcSpan
loc SourceText
esrc) of
Maybe (ForeignImport GhcPs)
Nothing -> forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
loc forall a b. (a -> b) -> a -> b
$
PsMessage
PsErrMalformedEntityString
Just ForeignImport GhcPs
importSpec -> forall (m :: * -> *) a. Monad m => a -> m a
return ForeignImport GhcPs
importSpec
isCWrapperImport :: ForeignImport pass -> Bool
isCWrapperImport (CImport XCImport pass
_ XRec pass CCallConv
_ XRec pass Safety
_ Maybe Header
_ CImportSpec
CWrapper) = Bool
True
isCWrapperImport ForeignImport pass
_ = Bool
False
mkOtherImport :: P (EpAnn [AddEpAnn] -> HsDecl GhcPs)
mkOtherImport = ForeignImport GhcPs -> P (EpAnn [AddEpAnn] -> HsDecl GhcPs)
returnSpec ForeignImport GhcPs
importSpec
where
entity' :: FastString
entity' = if FastString -> Bool
nullFS FastString
entity
then RdrName -> FastString
mkExtName (forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnN RdrName
v)
else FastString
entity
funcTarget :: CImportSpec
funcTarget = CCallTarget -> CImportSpec
CFunction (SourceText -> FastString -> Maybe Unit -> Bool -> CCallTarget
StaticTarget SourceText
esrc FastString
entity' forall a. Maybe a
Nothing Bool
True)
importSpec :: ForeignImport GhcPs
importSpec = forall pass.
XCImport pass
-> XRec pass CCallConv
-> XRec pass Safety
-> Maybe Header
-> CImportSpec
-> ForeignImport pass
CImport (forall l e. l -> e -> GenLocated l e
L SrcSpan
loc SourceText
esrc) Located CCallConv
cconv Located Safety
safety forall a. Maybe a
Nothing CImportSpec
funcTarget
returnSpec :: ForeignImport GhcPs -> P (EpAnn [AddEpAnn] -> HsDecl GhcPs)
returnSpec ForeignImport GhcPs
spec = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \EpAnn [AddEpAnn]
ann -> forall p. XForD p -> ForeignDecl p -> HsDecl p
ForD NoExtField
noExtField forall a b. (a -> b) -> a -> b
$ ForeignImport
{ fd_i_ext :: XForeignImport GhcPs
fd_i_ext = EpAnn [AddEpAnn]
ann
, fd_name :: XRec GhcPs (IdP GhcPs)
fd_name = GenLocated SrcSpanAnnN RdrName
v
, fd_sig_ty :: LHsSigType GhcPs
fd_sig_ty = LHsSigType GhcPs
ty
, fd_fi :: ForeignImport GhcPs
fd_fi = ForeignImport GhcPs
spec
}
parseCImport :: Located CCallConv -> Located Safety -> FastString -> String
-> Located SourceText
-> Maybe (ForeignImport (GhcPass p))
parseCImport :: forall (p :: Pass).
Located CCallConv
-> Located Safety
-> FastString
-> String
-> Located SourceText
-> Maybe (ForeignImport (GhcPass p))
parseCImport Located CCallConv
cconv Located Safety
safety FastString
nm String
str Located SourceText
sourceText =
forall a. [a] -> Maybe a
listToMaybe forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall a. (a -> Bool) -> [a] -> [a]
filter (forall (t :: * -> *) a. Foldable t => t a -> Bool
nullforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall a b. (a, b) -> b
snd) forall a b. (a -> b) -> a -> b
$
forall a. ReadP a -> ReadS a
readP_to_S ReadP (ForeignImport (GhcPass p))
parse String
str
where
parse :: ReadP (ForeignImport (GhcPass p))
parse = do
ReadP ()
skipSpaces
ForeignImport (GhcPass p)
r <- forall a. [ReadP a] -> ReadP a
choice [
String -> ReadP String
string String
"dynamic" forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Header -> CImportSpec -> ForeignImport (GhcPass p)
mk forall a. Maybe a
Nothing (CCallTarget -> CImportSpec
CFunction CCallTarget
DynamicTarget)),
String -> ReadP String
string String
"wrapper" forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Header -> CImportSpec -> ForeignImport (GhcPass p)
mk forall a. Maybe a
Nothing CImportSpec
CWrapper),
do forall a. ReadP a -> ReadP ()
optional (String -> ReadP ()
token String
"static" forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ReadP ()
skipSpaces)
((Maybe Header -> CImportSpec -> ForeignImport (GhcPass p)
mk forall a. Maybe a
Nothing forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FastString -> ReadP CImportSpec
cimp FastString
nm) forall a. ReadP a -> ReadP a -> ReadP a
+++
(do String
h <- (Char -> Bool) -> ReadP String
munch1 Char -> Bool
hdr_char
ReadP ()
skipSpaces
Maybe Header -> CImportSpec -> ForeignImport (GhcPass p)
mk (forall a. a -> Maybe a
Just (SourceText -> FastString -> Header
Header (String -> SourceText
SourceText String
h) (String -> FastString
mkFastString String
h)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FastString -> ReadP CImportSpec
cimp FastString
nm))
]
ReadP ()
skipSpaces
forall (m :: * -> *) a. Monad m => a -> m a
return ForeignImport (GhcPass p)
r
token :: String -> ReadP ()
token String
str = do String
_ <- String -> ReadP String
string String
str
String
toks <- ReadP String
look
case String
toks of
Char
c : String
_
| Char -> Bool
id_char Char
c -> forall a. ReadP a
pfail
String
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
mk :: Maybe Header -> CImportSpec -> ForeignImport (GhcPass p)
mk Maybe Header
h CImportSpec
n = forall pass.
XCImport pass
-> XRec pass CCallConv
-> XRec pass Safety
-> Maybe Header
-> CImportSpec
-> ForeignImport pass
CImport Located SourceText
sourceText Located CCallConv
cconv Located Safety
safety Maybe Header
h CImportSpec
n
hdr_char :: Char -> Bool
hdr_char Char
c = Bool -> Bool
not (Char -> Bool
isSpace Char
c)
id_first_char :: Char -> Bool
id_first_char Char
c = Char -> Bool
isAlpha Char
c Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
== Char
'_'
id_char :: Char -> Bool
id_char Char
c = Char -> Bool
isAlphaNum Char
c Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
== Char
'_'
cimp :: FastString -> ReadP CImportSpec
cimp FastString
nm = (Char -> ReadP Char
ReadP.char Char
'&' forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ReadP ()
skipSpaces forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> FastString -> CImportSpec
CLabel forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadP FastString
cid)
forall a. ReadP a -> ReadP a -> ReadP a
+++ (do Bool
isFun <- case forall l e. GenLocated l e -> e
unLoc Located CCallConv
cconv of
CCallConv
CApiConv ->
forall a. a -> ReadP a -> ReadP a
option Bool
True
(do String -> ReadP ()
token String
"value"
ReadP ()
skipSpaces
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False)
CCallConv
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
FastString
cid' <- ReadP FastString
cid
forall (m :: * -> *) a. Monad m => a -> m a
return (CCallTarget -> CImportSpec
CFunction (SourceText -> FastString -> Maybe Unit -> Bool -> CCallTarget
StaticTarget SourceText
NoSourceText FastString
cid'
forall a. Maybe a
Nothing Bool
isFun)))
where
cid :: ReadP FastString
cid = forall (m :: * -> *) a. Monad m => a -> m a
return FastString
nm forall a. ReadP a -> ReadP a -> ReadP a
+++
(do Char
c <- (Char -> Bool) -> ReadP Char
satisfy Char -> Bool
id_first_char
String
cs <- forall a. ReadP a -> ReadP [a]
many ((Char -> Bool) -> ReadP Char
satisfy Char -> Bool
id_char)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> FastString
mkFastString (Char
cforall a. a -> [a] -> [a]
:String
cs)))
mkExport :: Located CCallConv
-> (Located StringLiteral, LocatedN RdrName, LHsSigType GhcPs)
-> P (EpAnn [AddEpAnn] -> HsDecl GhcPs)
mkExport :: Located CCallConv
-> (Located StringLiteral, GenLocated SrcSpanAnnN RdrName,
LHsSigType GhcPs)
-> P (EpAnn [AddEpAnn] -> HsDecl GhcPs)
mkExport (L SrcSpan
lc CCallConv
cconv) (L SrcSpan
le (StringLiteral SourceText
esrc FastString
entity Maybe RealSrcSpan
_), GenLocated SrcSpanAnnN RdrName
v, LHsSigType GhcPs
ty)
= forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \EpAnn [AddEpAnn]
ann -> forall p. XForD p -> ForeignDecl p -> HsDecl p
ForD NoExtField
noExtField forall a b. (a -> b) -> a -> b
$
ForeignExport { fd_e_ext :: XForeignExport GhcPs
fd_e_ext = EpAnn [AddEpAnn]
ann, fd_name :: XRec GhcPs (IdP GhcPs)
fd_name = GenLocated SrcSpanAnnN RdrName
v, fd_sig_ty :: LHsSigType GhcPs
fd_sig_ty = LHsSigType GhcPs
ty
, fd_fe :: ForeignExport GhcPs
fd_fe = forall pass.
XCExport pass -> XRec pass CExportSpec -> ForeignExport pass
CExport (forall l e. l -> e -> GenLocated l e
L SrcSpan
le SourceText
esrc) (forall l e. l -> e -> GenLocated l e
L SrcSpan
lc (SourceText -> FastString -> CCallConv -> CExportSpec
CExportStatic SourceText
esrc FastString
entity' CCallConv
cconv)) }
where
entity' :: FastString
entity' | FastString -> Bool
nullFS FastString
entity = RdrName -> FastString
mkExtName (forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnN RdrName
v)
| Bool
otherwise = FastString
entity
mkExtName :: RdrName -> CLabelString
mkExtName :: RdrName -> FastString
mkExtName RdrName
rdrNm = OccName -> FastString
occNameFS (RdrName -> OccName
rdrNameOcc RdrName
rdrNm)
data ImpExpSubSpec = ImpExpAbs
| ImpExpAll
| ImpExpList [LocatedA ImpExpQcSpec]
| ImpExpAllWith [LocatedA ImpExpQcSpec]
data ImpExpQcSpec = ImpExpQcName (LocatedN RdrName)
| ImpExpQcType EpaLocation (LocatedN RdrName)
| ImpExpQcWildcard
mkModuleImpExp :: [AddEpAnn] -> LocatedA ImpExpQcSpec -> ImpExpSubSpec -> P (IE GhcPs)
mkModuleImpExp :: [AddEpAnn]
-> LocatedA ImpExpQcSpec -> ImpExpSubSpec -> P (IE GhcPs)
mkModuleImpExp [AddEpAnn]
anns (L SrcSpanAnnA
l ImpExpQcSpec
specname) ImpExpSubSpec
subs = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l)
let ann :: EpAnn [AddEpAnn]
ann = forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor forall a b. (a -> b) -> a -> b
$ forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) [AddEpAnn]
anns EpAnnComments
cs
case ImpExpSubSpec
subs of
ImpExpSubSpec
ImpExpAbs
| NameSpace -> Bool
isVarNameSpace (RdrName -> NameSpace
rdrNameSpace RdrName
name)
-> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall pass. XIEVar pass -> LIEWrappedName pass -> IE pass
IEVar NoExtField
noExtField (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (ImpExpQcSpec -> IEWrappedName GhcPs
ieNameFromSpec ImpExpQcSpec
specname))
| Bool
otherwise -> forall pass. XIEThingAbs pass -> LIEWrappedName pass -> IE pass
IEThingAbs EpAnn [AddEpAnn]
ann forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> P (IEWrappedName GhcPs)
nameT
ImpExpSubSpec
ImpExpAll -> forall pass. XIEThingAll pass -> LIEWrappedName pass -> IE pass
IEThingAll EpAnn [AddEpAnn]
ann forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> P (IEWrappedName GhcPs)
nameT
ImpExpList [LocatedA ImpExpQcSpec]
xs ->
(\IEWrappedName GhcPs
newName -> forall pass.
XIEThingWith pass
-> LIEWrappedName pass
-> IEWildcard
-> [LIEWrappedName pass]
-> IE pass
IEThingWith EpAnn [AddEpAnn]
ann (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l IEWrappedName GhcPs
newName)
IEWildcard
NoIEWildcard ([LocatedA ImpExpQcSpec]
-> [GenLocated SrcSpanAnnA (IEWrappedName GhcPs)]
wrapped [LocatedA ImpExpQcSpec]
xs)) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> P (IEWrappedName GhcPs)
nameT
ImpExpAllWith [LocatedA ImpExpQcSpec]
xs ->
do Bool
allowed <- forall (m :: * -> *). MonadP m => ExtBits -> m Bool
getBit ExtBits
PatternSynonymsBit
if Bool
allowed
then
let withs :: [ImpExpQcSpec]
withs = forall a b. (a -> b) -> [a] -> [b]
map forall l e. GenLocated l e -> e
unLoc [LocatedA ImpExpQcSpec]
xs
pos :: IEWildcard
pos = forall b a. b -> (a -> b) -> Maybe a -> b
maybe IEWildcard
NoIEWildcard Int -> IEWildcard
IEWildcard
(forall a. (a -> Bool) -> [a] -> Maybe Int
findIndex ImpExpQcSpec -> Bool
isImpExpQcWildcard [ImpExpQcSpec]
withs)
ies :: [LocatedA (IEWrappedName GhcPs)]
ies :: [GenLocated SrcSpanAnnA (IEWrappedName GhcPs)]
ies = [LocatedA ImpExpQcSpec]
-> [GenLocated SrcSpanAnnA (IEWrappedName GhcPs)]
wrapped forall a b. (a -> b) -> a -> b
$ forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. ImpExpQcSpec -> Bool
isImpExpQcWildcard forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l e. GenLocated l e -> e
unLoc) [LocatedA ImpExpQcSpec]
xs
in (\IEWrappedName GhcPs
newName
-> forall pass.
XIEThingWith pass
-> LIEWrappedName pass
-> IEWildcard
-> [LIEWrappedName pass]
-> IE pass
IEThingWith EpAnn [AddEpAnn]
ann (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l IEWrappedName GhcPs
newName) IEWildcard
pos [GenLocated SrcSpanAnnA (IEWrappedName GhcPs)]
ies)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> P (IEWrappedName GhcPs)
nameT
else forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) forall a b. (a -> b) -> a -> b
$
PsMessage
PsErrIllegalPatSynExport
where
name :: RdrName
name = ImpExpQcSpec -> RdrName
ieNameVal ImpExpQcSpec
specname
nameT :: P (IEWrappedName GhcPs)
nameT =
if NameSpace -> Bool
isVarNameSpace (RdrName -> NameSpace
rdrNameSpace RdrName
name)
then forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) forall a b. (a -> b) -> a -> b
$
(RdrName -> PsMessage
PsErrVarForTyCon RdrName
name)
else forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ImpExpQcSpec -> IEWrappedName GhcPs
ieNameFromSpec ImpExpQcSpec
specname
ieNameVal :: ImpExpQcSpec -> RdrName
ieNameVal (ImpExpQcName GenLocated SrcSpanAnnN RdrName
ln) = forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnN RdrName
ln
ieNameVal (ImpExpQcType EpaLocation
_ GenLocated SrcSpanAnnN RdrName
ln) = forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnN RdrName
ln
ieNameVal (ImpExpQcSpec
ImpExpQcWildcard) = forall a. HasCallStack => String -> a
panic String
"ieNameVal got wildcard"
ieNameFromSpec :: ImpExpQcSpec -> IEWrappedName GhcPs
ieNameFromSpec :: ImpExpQcSpec -> IEWrappedName GhcPs
ieNameFromSpec (ImpExpQcName (L SrcSpanAnnN
l RdrName
n)) = forall p. XIEName p -> LIdP p -> IEWrappedName p
IEName NoExtField
noExtField (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
l RdrName
n)
ieNameFromSpec (ImpExpQcType EpaLocation
r (L SrcSpanAnnN
l RdrName
n)) = forall p. XIEType p -> LIdP p -> IEWrappedName p
IEType EpaLocation
r (forall l e. l -> e -> GenLocated l e
L SrcSpanAnnN
l RdrName
n)
ieNameFromSpec (ImpExpQcSpec
ImpExpQcWildcard) = forall a. HasCallStack => String -> a
panic String
"ieName got wildcard"
wrapped :: [LocatedA ImpExpQcSpec]
-> [GenLocated SrcSpanAnnA (IEWrappedName GhcPs)]
wrapped = forall a b. (a -> b) -> [a] -> [b]
map (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ImpExpQcSpec -> IEWrappedName GhcPs
ieNameFromSpec)
mkTypeImpExp :: LocatedN RdrName
-> P (LocatedN RdrName)
mkTypeImpExp :: GenLocated SrcSpanAnnN RdrName
-> P (GenLocated SrcSpanAnnN RdrName)
mkTypeImpExp GenLocated SrcSpanAnnN RdrName
name =
do Bool
allowed <- forall (m :: * -> *). MonadP m => ExtBits -> m Bool
getBit ExtBits
ExplicitNamespacesBit
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
allowed forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
getLocA GenLocated SrcSpanAnnN RdrName
name) forall a b. (a -> b) -> a -> b
$
PsMessage
PsErrIllegalExplicitNamespace
forall (m :: * -> *) a. Monad m => a -> m a
return (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (RdrName -> NameSpace -> RdrName
`setRdrNameSpace` NameSpace
tcClsName) GenLocated SrcSpanAnnN RdrName
name)
checkImportSpec :: LocatedL [LIE GhcPs] -> P (LocatedL [LIE GhcPs])
checkImportSpec :: LocatedL [LIE GhcPs] -> P (LocatedL [LIE GhcPs])
checkImportSpec ie :: LocatedL [LIE GhcPs]
ie@(L SrcSpanAnnL
_ [LIE GhcPs]
specs) =
case [SrcSpanAnnA
l | (L SrcSpanAnnA
l (IEThingWith XIEThingWith GhcPs
_ LIEWrappedName GhcPs
_ (IEWildcard Int
_) [LIEWrappedName GhcPs]
_)) <- [LIE GhcPs]
specs] of
[] -> forall (m :: * -> *) a. Monad m => a -> m a
return LocatedL [LIE GhcPs]
ie
(SrcSpanAnnA
l:[SrcSpanAnnA]
_) -> forall {m :: * -> *} {a}. MonadP m => SrcSpan -> m a
importSpecError (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l)
where
importSpecError :: SrcSpan -> m a
importSpecError SrcSpan
l =
forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
l PsMessage
PsErrIllegalImportBundleForm
mkImpExpSubSpec :: [LocatedA ImpExpQcSpec] -> P ([AddEpAnn], ImpExpSubSpec)
mkImpExpSubSpec :: [LocatedA ImpExpQcSpec] -> P ([AddEpAnn], ImpExpSubSpec)
mkImpExpSubSpec [] = forall (m :: * -> *) a. Monad m => a -> m a
return ([], [LocatedA ImpExpQcSpec] -> ImpExpSubSpec
ImpExpList [])
mkImpExpSubSpec [L SrcSpanAnnA
la ImpExpQcSpec
ImpExpQcWildcard] =
forall (m :: * -> *) a. Monad m => a -> m a
return ([AnnKeywordId -> EpaLocation -> AddEpAnn
AddEpAnn AnnKeywordId
AnnDotdot (forall a. SrcSpanAnn' a -> EpaLocation
la2e SrcSpanAnnA
la)], ImpExpSubSpec
ImpExpAll)
mkImpExpSubSpec [LocatedA ImpExpQcSpec]
xs =
if (forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (ImpExpQcSpec -> Bool
isImpExpQcWildcard forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l e. GenLocated l e -> e
unLoc) [LocatedA ImpExpQcSpec]
xs)
then forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ([], [LocatedA ImpExpQcSpec] -> ImpExpSubSpec
ImpExpAllWith [LocatedA ImpExpQcSpec]
xs)
else forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ([], [LocatedA ImpExpQcSpec] -> ImpExpSubSpec
ImpExpList [LocatedA ImpExpQcSpec]
xs)
isImpExpQcWildcard :: ImpExpQcSpec -> Bool
isImpExpQcWildcard :: ImpExpQcSpec -> Bool
isImpExpQcWildcard ImpExpQcSpec
ImpExpQcWildcard = Bool
True
isImpExpQcWildcard ImpExpQcSpec
_ = Bool
False
warnPrepositiveQualifiedModule :: SrcSpan -> P ()
warnPrepositiveQualifiedModule :: SrcSpan -> P ()
warnPrepositiveQualifiedModule SrcSpan
span =
SrcSpan -> PsMessage -> P ()
addPsMessage SrcSpan
span PsMessage
PsWarnImportPreQualified
failNotEnabledImportQualifiedPost :: SrcSpan -> P ()
failNotEnabledImportQualifiedPost :: SrcSpan -> P ()
failNotEnabledImportQualifiedPost SrcSpan
loc =
forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
loc forall a b. (a -> b) -> a -> b
$ PsMessage
PsErrImportPostQualified
failImportQualifiedTwice :: SrcSpan -> P ()
failImportQualifiedTwice :: SrcSpan -> P ()
failImportQualifiedTwice SrcSpan
loc =
forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
loc forall a b. (a -> b) -> a -> b
$ PsMessage
PsErrImportQualifiedTwice
warnStarIsType :: SrcSpan -> P ()
warnStarIsType :: SrcSpan -> P ()
warnStarIsType SrcSpan
span = SrcSpan -> PsMessage -> P ()
addPsMessage SrcSpan
span PsMessage
PsWarnStarIsType
failOpFewArgs :: MonadP m => LocatedN RdrName -> m a
failOpFewArgs :: forall (m :: * -> *) a.
MonadP m =>
GenLocated SrcSpanAnnN RdrName -> m a
failOpFewArgs (L SrcSpanAnnN
loc RdrName
op) =
do { Bool
star_is_type <- forall (m :: * -> *). MonadP m => ExtBits -> m Bool
getBit ExtBits
StarIsTypeBit
; let is_star_type :: StarIsType
is_star_type = if Bool
star_is_type then StarIsType
StarIsType else StarIsType
StarIsNotType
; forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnN
loc) forall a b. (a -> b) -> a -> b
$
(StarIsType -> RdrName -> PsMessage
PsErrOpFewArgs StarIsType
is_star_type RdrName
op) }
data PV_Context =
PV_Context
{ PV_Context -> ParserOpts
pv_options :: ParserOpts
, PV_Context -> ParseContext
pv_details :: ParseContext
}
data PV_Accum =
PV_Accum
{ PV_Accum -> Messages PsMessage
pv_warnings :: Messages PsMessage
, PV_Accum -> Messages PsMessage
pv_errors :: Messages PsMessage
, :: Strict.Maybe [LEpaComment]
, :: [LEpaComment]
}
data PV_Result a = PV_Ok PV_Accum a | PV_Failed PV_Accum
deriving (forall a. Eq a => a -> PV_Result a -> Bool
forall a. Num a => PV_Result a -> a
forall a. Ord a => PV_Result a -> a
forall m. Monoid m => PV_Result m -> m
forall a. PV_Result a -> Bool
forall a. PV_Result a -> Int
forall a. PV_Result a -> [a]
forall a. (a -> a -> a) -> PV_Result a -> a
forall m a. Monoid m => (a -> m) -> PV_Result a -> m
forall b a. (b -> a -> b) -> b -> PV_Result a -> b
forall a b. (a -> b -> b) -> b -> PV_Result a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => PV_Result a -> a
$cproduct :: forall a. Num a => PV_Result a -> a
sum :: forall a. Num a => PV_Result a -> a
$csum :: forall a. Num a => PV_Result a -> a
minimum :: forall a. Ord a => PV_Result a -> a
$cminimum :: forall a. Ord a => PV_Result a -> a
maximum :: forall a. Ord a => PV_Result a -> a
$cmaximum :: forall a. Ord a => PV_Result a -> a
elem :: forall a. Eq a => a -> PV_Result a -> Bool
$celem :: forall a. Eq a => a -> PV_Result a -> Bool
length :: forall a. PV_Result a -> Int
$clength :: forall a. PV_Result a -> Int
null :: forall a. PV_Result a -> Bool
$cnull :: forall a. PV_Result a -> Bool
toList :: forall a. PV_Result a -> [a]
$ctoList :: forall a. PV_Result a -> [a]
foldl1 :: forall a. (a -> a -> a) -> PV_Result a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> PV_Result a -> a
foldr1 :: forall a. (a -> a -> a) -> PV_Result a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> PV_Result a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> PV_Result a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> PV_Result a -> b
foldl :: forall b a. (b -> a -> b) -> b -> PV_Result a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> PV_Result a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> PV_Result a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> PV_Result a -> b
foldr :: forall a b. (a -> b -> b) -> b -> PV_Result a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> PV_Result a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> PV_Result a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> PV_Result a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> PV_Result a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> PV_Result a -> m
fold :: forall m. Monoid m => PV_Result m -> m
$cfold :: forall m. Monoid m => PV_Result m -> m
Foldable, forall a b. a -> PV_Result b -> PV_Result a
forall a b. (a -> b) -> PV_Result a -> PV_Result b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> PV_Result b -> PV_Result a
$c<$ :: forall a b. a -> PV_Result b -> PV_Result a
fmap :: forall a b. (a -> b) -> PV_Result a -> PV_Result b
$cfmap :: forall a b. (a -> b) -> PV_Result a -> PV_Result b
Functor, Functor PV_Result
Foldable PV_Result
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
PV_Result (m a) -> m (PV_Result a)
forall (f :: * -> *) a.
Applicative f =>
PV_Result (f a) -> f (PV_Result a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> PV_Result a -> m (PV_Result b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PV_Result a -> f (PV_Result b)
sequence :: forall (m :: * -> *) a.
Monad m =>
PV_Result (m a) -> m (PV_Result a)
$csequence :: forall (m :: * -> *) a.
Monad m =>
PV_Result (m a) -> m (PV_Result a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> PV_Result a -> m (PV_Result b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> PV_Result a -> m (PV_Result b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
PV_Result (f a) -> f (PV_Result a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
PV_Result (f a) -> f (PV_Result a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PV_Result a -> f (PV_Result b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PV_Result a -> f (PV_Result b)
Traversable)
newtype PV a = PV { forall a. PV a -> PV_Context -> PV_Accum -> PV_Result a
unPV :: PV_Context -> PV_Accum -> PV_Result a }
deriving (forall a b. a -> PV b -> PV a
forall a b. (a -> b) -> PV a -> PV b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> PV b -> PV a
$c<$ :: forall a b. a -> PV b -> PV a
fmap :: forall a b. (a -> b) -> PV a -> PV b
$cfmap :: forall a b. (a -> b) -> PV a -> PV b
Functor)
instance Applicative PV where
pure :: forall a. a -> PV a
pure a
a = a
a seq :: forall a b. a -> b -> b
`seq` forall a. (PV_Context -> PV_Accum -> PV_Result a) -> PV a
PV (\PV_Context
_ PV_Accum
acc -> forall a. PV_Accum -> a -> PV_Result a
PV_Ok PV_Accum
acc a
a)
<*> :: forall a b. PV (a -> b) -> PV a -> PV b
(<*>) = forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
ap
instance Monad PV where
PV a
m >>= :: forall a b. PV a -> (a -> PV b) -> PV b
>>= a -> PV b
f = forall a. (PV_Context -> PV_Accum -> PV_Result a) -> PV a
PV forall a b. (a -> b) -> a -> b
$ \PV_Context
ctx PV_Accum
acc ->
case forall a. PV a -> PV_Context -> PV_Accum -> PV_Result a
unPV PV a
m PV_Context
ctx PV_Accum
acc of
PV_Ok PV_Accum
acc' a
a -> forall a. PV a -> PV_Context -> PV_Accum -> PV_Result a
unPV (a -> PV b
f a
a) PV_Context
ctx PV_Accum
acc'
PV_Failed PV_Accum
acc' -> forall a. PV_Accum -> PV_Result a
PV_Failed PV_Accum
acc'
runPV :: PV a -> P a
runPV :: forall a. PV a -> P a
runPV = forall a. ParseContext -> PV a -> P a
runPV_details ParseContext
noParseContext
askParseContext :: PV ParseContext
askParseContext :: PV ParseContext
askParseContext = forall a. (PV_Context -> PV_Accum -> PV_Result a) -> PV a
PV forall a b. (a -> b) -> a -> b
$ \(PV_Context ParserOpts
_ ParseContext
details) PV_Accum
acc -> forall a. PV_Accum -> a -> PV_Result a
PV_Ok PV_Accum
acc ParseContext
details
runPV_details :: ParseContext -> PV a -> P a
runPV_details :: forall a. ParseContext -> PV a -> P a
runPV_details ParseContext
details PV a
m =
forall a. (PState -> ParseResult a) -> P a
P forall a b. (a -> b) -> a -> b
$ \PState
s ->
let
pv_ctx :: PV_Context
pv_ctx = PV_Context
{ pv_options :: ParserOpts
pv_options = PState -> ParserOpts
options PState
s
, pv_details :: ParseContext
pv_details = ParseContext
details }
pv_acc :: PV_Accum
pv_acc = PV_Accum
{ pv_warnings :: Messages PsMessage
pv_warnings = PState -> Messages PsMessage
warnings PState
s
, pv_errors :: Messages PsMessage
pv_errors = PState -> Messages PsMessage
errors PState
s
, pv_header_comments :: Maybe [LEpaComment]
pv_header_comments = PState -> Maybe [LEpaComment]
header_comments PState
s
, pv_comment_q :: [LEpaComment]
pv_comment_q = PState -> [LEpaComment]
comment_q PState
s }
mkPState :: PV_Accum -> PState
mkPState PV_Accum
acc' =
PState
s { warnings :: Messages PsMessage
warnings = PV_Accum -> Messages PsMessage
pv_warnings PV_Accum
acc'
, errors :: Messages PsMessage
errors = PV_Accum -> Messages PsMessage
pv_errors PV_Accum
acc'
, comment_q :: [LEpaComment]
comment_q = PV_Accum -> [LEpaComment]
pv_comment_q PV_Accum
acc' }
in
case forall a. PV a -> PV_Context -> PV_Accum -> PV_Result a
unPV PV a
m PV_Context
pv_ctx PV_Accum
pv_acc of
PV_Ok PV_Accum
acc' a
a -> forall a. PState -> a -> ParseResult a
POk (PV_Accum -> PState
mkPState PV_Accum
acc') a
a
PV_Failed PV_Accum
acc' -> forall a. PState -> ParseResult a
PFailed (PV_Accum -> PState
mkPState PV_Accum
acc')
instance MonadP PV where
addError :: MsgEnvelope PsMessage -> PV ()
addError MsgEnvelope PsMessage
err =
forall a. (PV_Context -> PV_Accum -> PV_Result a) -> PV a
PV forall a b. (a -> b) -> a -> b
$ \PV_Context
_ctx PV_Accum
acc -> forall a. PV_Accum -> a -> PV_Result a
PV_Ok PV_Accum
acc{pv_errors :: Messages PsMessage
pv_errors = MsgEnvelope PsMessage
err forall e. MsgEnvelope e -> Messages e -> Messages e
`addMessage` PV_Accum -> Messages PsMessage
pv_errors PV_Accum
acc} ()
addWarning :: MsgEnvelope PsMessage -> PV ()
addWarning MsgEnvelope PsMessage
w =
forall a. (PV_Context -> PV_Accum -> PV_Result a) -> PV a
PV forall a b. (a -> b) -> a -> b
$ \PV_Context
_ctx PV_Accum
acc ->
forall a. PV_Accum -> a -> PV_Result a
PV_Ok PV_Accum
acc{pv_warnings :: Messages PsMessage
pv_warnings= MsgEnvelope PsMessage
w forall e. MsgEnvelope e -> Messages e -> Messages e
`addMessage` PV_Accum -> Messages PsMessage
pv_warnings PV_Accum
acc} ()
addFatalError :: forall a. MsgEnvelope PsMessage -> PV a
addFatalError MsgEnvelope PsMessage
err =
forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError MsgEnvelope PsMessage
err forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. (PV_Context -> PV_Accum -> PV_Result a) -> PV a
PV (forall a b. a -> b -> a
const forall a. PV_Accum -> PV_Result a
PV_Failed)
getBit :: ExtBits -> PV Bool
getBit ExtBits
ext =
forall a. (PV_Context -> PV_Accum -> PV_Result a) -> PV a
PV forall a b. (a -> b) -> a -> b
$ \PV_Context
ctx PV_Accum
acc ->
let b :: Bool
b = ExtBits
ext ExtBits -> ExtsBitmap -> Bool
`xtest` ParserOpts -> ExtsBitmap
pExtsBitmap (PV_Context -> ParserOpts
pv_options PV_Context
ctx) in
forall a. PV_Accum -> a -> PV_Result a
PV_Ok PV_Accum
acc forall a b. (a -> b) -> a -> b
$! Bool
b
allocateCommentsP :: RealSrcSpan -> PV EpAnnComments
allocateCommentsP RealSrcSpan
ss = forall a. (PV_Context -> PV_Accum -> PV_Result a) -> PV a
PV forall a b. (a -> b) -> a -> b
$ \PV_Context
_ PV_Accum
s ->
let ([LEpaComment]
comment_q', [LEpaComment]
newAnns) = RealSrcSpan -> [LEpaComment] -> ([LEpaComment], [LEpaComment])
allocateComments RealSrcSpan
ss (PV_Accum -> [LEpaComment]
pv_comment_q PV_Accum
s) in
forall a. PV_Accum -> a -> PV_Result a
PV_Ok PV_Accum
s {
pv_comment_q :: [LEpaComment]
pv_comment_q = [LEpaComment]
comment_q'
} ([LEpaComment] -> EpAnnComments
EpaComments [LEpaComment]
newAnns)
allocatePriorCommentsP :: RealSrcSpan -> PV EpAnnComments
allocatePriorCommentsP RealSrcSpan
ss = forall a. (PV_Context -> PV_Accum -> PV_Result a) -> PV a
PV forall a b. (a -> b) -> a -> b
$ \PV_Context
_ PV_Accum
s ->
let (Maybe [LEpaComment]
header_comments', [LEpaComment]
comment_q', [LEpaComment]
newAnns)
= RealSrcSpan
-> [LEpaComment]
-> Maybe [LEpaComment]
-> (Maybe [LEpaComment], [LEpaComment], [LEpaComment])
allocatePriorComments RealSrcSpan
ss (PV_Accum -> [LEpaComment]
pv_comment_q PV_Accum
s) (PV_Accum -> Maybe [LEpaComment]
pv_header_comments PV_Accum
s) in
forall a. PV_Accum -> a -> PV_Result a
PV_Ok PV_Accum
s {
pv_header_comments :: Maybe [LEpaComment]
pv_header_comments = Maybe [LEpaComment]
header_comments',
pv_comment_q :: [LEpaComment]
pv_comment_q = [LEpaComment]
comment_q'
} ([LEpaComment] -> EpAnnComments
EpaComments [LEpaComment]
newAnns)
allocateFinalCommentsP :: RealSrcSpan -> PV EpAnnComments
allocateFinalCommentsP RealSrcSpan
ss = forall a. (PV_Context -> PV_Accum -> PV_Result a) -> PV a
PV forall a b. (a -> b) -> a -> b
$ \PV_Context
_ PV_Accum
s ->
let (Maybe [LEpaComment]
header_comments', [LEpaComment]
comment_q', [LEpaComment]
newAnns)
= RealSrcSpan
-> [LEpaComment]
-> Maybe [LEpaComment]
-> (Maybe [LEpaComment], [LEpaComment], [LEpaComment])
allocateFinalComments RealSrcSpan
ss (PV_Accum -> [LEpaComment]
pv_comment_q PV_Accum
s) (PV_Accum -> Maybe [LEpaComment]
pv_header_comments PV_Accum
s) in
forall a. PV_Accum -> a -> PV_Result a
PV_Ok PV_Accum
s {
pv_header_comments :: Maybe [LEpaComment]
pv_header_comments = Maybe [LEpaComment]
header_comments',
pv_comment_q :: [LEpaComment]
pv_comment_q = [LEpaComment]
comment_q'
} ([LEpaComment] -> [LEpaComment] -> EpAnnComments
EpaCommentsBalanced (forall a. a -> Maybe a -> a
Strict.fromMaybe [] Maybe [LEpaComment]
header_comments') [LEpaComment]
newAnns)
hintBangPat :: SrcSpan -> Pat GhcPs -> PV ()
hintBangPat :: SrcSpan -> Pat GhcPs -> PV ()
hintBangPat SrcSpan
span Pat GhcPs
e = do
Bool
bang_on <- forall (m :: * -> *). MonadP m => ExtBits -> m Bool
getBit ExtBits
BangPatBit
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
bang_on forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *). MonadP m => MsgEnvelope PsMessage -> m ()
addError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope SrcSpan
span forall a b. (a -> b) -> a -> b
$ Pat GhcPs -> PsMessage
PsErrIllegalBangPattern Pat GhcPs
e
mkSumOrTupleExpr :: SrcSpanAnnA -> Boxity -> SumOrTuple (HsExpr GhcPs)
-> [AddEpAnn]
-> PV (LHsExpr GhcPs)
mkSumOrTupleExpr :: SrcSpanAnnA
-> Boxity
-> SumOrTuple (HsExpr GhcPs)
-> [AddEpAnn]
-> PV (LHsExpr GhcPs)
mkSumOrTupleExpr SrcSpanAnnA
l Boxity
boxity (Tuple [Either
(EpAnn EpaLocation) (GenLocated SrcSpanAnnA (HsExpr GhcPs))]
es) [AddEpAnn]
anns = do
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (forall p. XExplicitTuple p -> [HsTupArg p] -> Boxity -> HsExpr p
ExplicitTuple (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor forall a b. (a -> b) -> a -> b
$ forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) [AddEpAnn]
anns EpAnnComments
cs) (forall a b. (a -> b) -> [a] -> [b]
map Either (EpAnn EpaLocation) (LHsExpr GhcPs) -> HsTupArg GhcPs
toTupArg [Either
(EpAnn EpaLocation) (GenLocated SrcSpanAnnA (HsExpr GhcPs))]
es) Boxity
boxity)
where
toTupArg :: Either (EpAnn EpaLocation) (LHsExpr GhcPs) -> HsTupArg GhcPs
toTupArg :: Either (EpAnn EpaLocation) (LHsExpr GhcPs) -> HsTupArg GhcPs
toTupArg (Left EpAnn EpaLocation
ann) = EpAnn EpaLocation -> HsTupArg GhcPs
missingTupArg EpAnn EpaLocation
ann
toTupArg (Right LHsExpr GhcPs
a) = forall id. XPresent id -> LHsExpr id -> HsTupArg id
Present forall a. EpAnn a
noAnn LHsExpr GhcPs
a
mkSumOrTupleExpr SrcSpanAnnA
l Boxity
Unboxed (Sum Int
alt Int
arity GenLocated SrcSpanAnnA (HsExpr GhcPs)
e [EpaLocation]
barsp [EpaLocation]
barsa) [AddEpAnn]
anns = do
let an :: AnnExplicitSum
an = case [AddEpAnn]
anns of
[AddEpAnn AnnKeywordId
AnnOpenPH EpaLocation
o, AddEpAnn AnnKeywordId
AnnClosePH EpaLocation
c] ->
EpaLocation
-> [EpaLocation] -> [EpaLocation] -> EpaLocation -> AnnExplicitSum
AnnExplicitSum EpaLocation
o [EpaLocation]
barsp [EpaLocation]
barsa EpaLocation
c
[AddEpAnn]
_ -> forall a. HasCallStack => String -> a
panic String
"mkSumOrTupleExpr"
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (forall p. XExplicitSum p -> Int -> Int -> LHsExpr p -> HsExpr p
ExplicitSum (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor forall a b. (a -> b) -> a -> b
$ forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) AnnExplicitSum
an EpAnnComments
cs) Int
alt Int
arity GenLocated SrcSpanAnnA (HsExpr GhcPs)
e)
mkSumOrTupleExpr SrcSpanAnnA
l Boxity
Boxed a :: SumOrTuple (HsExpr GhcPs)
a@Sum{} [AddEpAnn]
_ =
forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$ forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) forall a b. (a -> b) -> a -> b
$ SumOrTuple (HsExpr GhcPs) -> PsMessage
PsErrUnsupportedBoxedSumExpr SumOrTuple (HsExpr GhcPs)
a
mkSumOrTuplePat
:: SrcSpanAnnA -> Boxity -> SumOrTuple (PatBuilder GhcPs) -> [AddEpAnn]
-> PV (LocatedA (PatBuilder GhcPs))
mkSumOrTuplePat :: SrcSpanAnnA
-> Boxity
-> SumOrTuple (PatBuilder GhcPs)
-> [AddEpAnn]
-> PV (LocatedA (PatBuilder GhcPs))
mkSumOrTuplePat SrcSpanAnnA
l Boxity
boxity (Tuple [Either (EpAnn EpaLocation) (LocatedA (PatBuilder GhcPs))]
ps) [AddEpAnn]
anns = do
[GenLocated SrcSpanAnnA (Pat GhcPs)]
ps' <- forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Either (EpAnn EpaLocation) (LocatedA (PatBuilder GhcPs))
-> PV (LPat GhcPs)
toTupPat [Either (EpAnn EpaLocation) (LocatedA (PatBuilder GhcPs))]
ps
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (forall p. Pat p -> PatBuilder p
PatBuilderPat (forall p. XTuplePat p -> [LPat p] -> Boxity -> Pat p
TuplePat (forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor forall a b. (a -> b) -> a -> b
$ forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) [AddEpAnn]
anns EpAnnComments
cs) [GenLocated SrcSpanAnnA (Pat GhcPs)]
ps' Boxity
boxity))
where
toTupPat :: Either (EpAnn EpaLocation) (LocatedA (PatBuilder GhcPs)) -> PV (LPat GhcPs)
toTupPat :: Either (EpAnn EpaLocation) (LocatedA (PatBuilder GhcPs))
-> PV (LPat GhcPs)
toTupPat Either (EpAnn EpaLocation) (LocatedA (PatBuilder GhcPs))
p = case Either (EpAnn EpaLocation) (LocatedA (PatBuilder GhcPs))
p of
Left EpAnn EpaLocation
_ -> forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$
forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) PsMessage
PsErrTupleSectionInPat
Right LocatedA (PatBuilder GhcPs)
p' -> LocatedA (PatBuilder GhcPs) -> PV (LPat GhcPs)
checkLPat LocatedA (PatBuilder GhcPs)
p'
mkSumOrTuplePat SrcSpanAnnA
l Boxity
Unboxed (Sum Int
alt Int
arity LocatedA (PatBuilder GhcPs)
p [EpaLocation]
barsb [EpaLocation]
barsa) [AddEpAnn]
anns = do
GenLocated SrcSpanAnnA (Pat GhcPs)
p' <- LocatedA (PatBuilder GhcPs) -> PV (LPat GhcPs)
checkLPat LocatedA (PatBuilder GhcPs)
p
EpAnnComments
cs <- forall (m :: * -> *). MonadP m => SrcSpan -> m EpAnnComments
getCommentsFor (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l)
let an :: EpAnn EpAnnSumPat
an = forall ann. Anchor -> ann -> EpAnnComments -> EpAnn ann
EpAnn (SrcSpan -> Anchor
spanAsAnchor forall a b. (a -> b) -> a -> b
$ forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) ([AddEpAnn] -> [EpaLocation] -> [EpaLocation] -> EpAnnSumPat
EpAnnSumPat [AddEpAnn]
anns [EpaLocation]
barsb [EpaLocation]
barsa) EpAnnComments
cs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (forall p. Pat p -> PatBuilder p
PatBuilderPat (forall p. XSumPat p -> LPat p -> Int -> Int -> Pat p
SumPat EpAnn EpAnnSumPat
an GenLocated SrcSpanAnnA (Pat GhcPs)
p' Int
alt Int
arity))
mkSumOrTuplePat SrcSpanAnnA
l Boxity
Boxed a :: SumOrTuple (PatBuilder GhcPs)
a@Sum{} [AddEpAnn]
_ =
forall (m :: * -> *) a. MonadP m => MsgEnvelope PsMessage -> m a
addFatalError forall a b. (a -> b) -> a -> b
$
forall e. Diagnostic e => SrcSpan -> e -> MsgEnvelope e
mkPlainErrorMsgEnvelope (forall a. SrcSpanAnn' a -> SrcSpan
locA SrcSpanAnnA
l) forall a b. (a -> b) -> a -> b
$ SumOrTuple (PatBuilder GhcPs) -> PsMessage
PsErrUnsupportedBoxedSumPat SumOrTuple (PatBuilder GhcPs)
a
mkLHsOpTy :: PromotionFlag -> LHsType GhcPs -> LocatedN RdrName -> LHsType GhcPs -> LHsType GhcPs
mkLHsOpTy :: PromotionFlag
-> LHsType GhcPs
-> GenLocated SrcSpanAnnN RdrName
-> LHsType GhcPs
-> LHsType GhcPs
mkLHsOpTy PromotionFlag
prom LHsType GhcPs
x GenLocated SrcSpanAnnN RdrName
op LHsType GhcPs
y =
let loc :: SrcSpanAnnA
loc = forall l e. GenLocated l e -> l
getLoc LHsType GhcPs
x forall a. Semigroup a => SrcAnn a -> SrcAnn a -> SrcAnn a
`combineSrcSpansA` (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan forall a b. (a -> b) -> a -> b
$ forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
getLocA GenLocated SrcSpanAnnN RdrName
op) forall a. Semigroup a => SrcAnn a -> SrcAnn a -> SrcAnn a
`combineSrcSpansA` forall l e. GenLocated l e -> l
getLoc LHsType GhcPs
y
in forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc (forall (p :: Pass).
(Anno (IdGhcP p) ~ SrcSpanAnnN) =>
PromotionFlag
-> LHsType (GhcPass p)
-> LocatedN (IdP (GhcPass p))
-> LHsType (GhcPass p)
-> HsType (GhcPass p)
mkHsOpTy PromotionFlag
prom LHsType GhcPs
x GenLocated SrcSpanAnnN RdrName
op LHsType GhcPs
y)
mkMultTy :: LHsToken "%" GhcPs -> LHsType GhcPs -> LHsUniToken "->" "→" GhcPs -> HsArrow GhcPs
mkMultTy :: LHsToken "%" GhcPs
-> LHsType GhcPs -> LHsUniToken "->" "\8594" GhcPs -> HsArrow GhcPs
mkMultTy LHsToken "%" GhcPs
pct t :: LHsType GhcPs
t@(L SrcSpanAnnA
_ (HsTyLit XTyLit GhcPs
_ (HsNumTy (SourceText String
"1") Integer
1))) LHsUniToken "->" "\8594" GhcPs
arr
= forall pass. HsLinearArrowTokens pass -> HsArrow pass
HsLinearArrow (forall pass.
LHsToken "%1" pass
-> LHsUniToken "->" "\8594" pass -> HsLinearArrowTokens pass
HsPct1 (forall l e. l -> e -> GenLocated l e
L TokenLocation
locOfPct1 forall (tok :: Symbol). HsToken tok
HsTok) LHsUniToken "->" "\8594" GhcPs
arr)
where
locOfPct1 :: TokenLocation
locOfPct1 :: TokenLocation
locOfPct1 = TokenLocation -> SrcSpan -> TokenLocation
token_location_widenR (forall l e. GenLocated l e -> l
getLoc LHsToken "%" GhcPs
pct) (forall a. SrcSpanAnn' a -> SrcSpan
locA (forall l e. GenLocated l e -> l
getLoc LHsType GhcPs
t))
mkMultTy LHsToken "%" GhcPs
pct LHsType GhcPs
t LHsUniToken "->" "\8594" GhcPs
arr = forall pass.
LHsToken "%" pass
-> LHsType pass -> LHsUniToken "->" "\8594" pass -> HsArrow pass
HsExplicitMult LHsToken "%" GhcPs
pct LHsType GhcPs
t LHsUniToken "->" "\8594" GhcPs
arr
mkTokenLocation :: SrcSpan -> TokenLocation
mkTokenLocation :: SrcSpan -> TokenLocation
mkTokenLocation (UnhelpfulSpan UnhelpfulSpanReason
_) = TokenLocation
NoTokenLoc
mkTokenLocation (RealSrcSpan RealSrcSpan
r Maybe BufSpan
mb) = EpaLocation -> TokenLocation
TokenLoc (RealSrcSpan -> Maybe BufSpan -> EpaLocation
EpaSpan RealSrcSpan
r Maybe BufSpan
mb)
token_location_widenR :: TokenLocation -> SrcSpan -> TokenLocation
token_location_widenR :: TokenLocation -> SrcSpan -> TokenLocation
token_location_widenR TokenLocation
NoTokenLoc SrcSpan
_ = TokenLocation
NoTokenLoc
token_location_widenR TokenLocation
tl (UnhelpfulSpan UnhelpfulSpanReason
_) = TokenLocation
tl
token_location_widenR (TokenLoc (EpaSpan RealSrcSpan
r1 Maybe BufSpan
mb1)) (RealSrcSpan RealSrcSpan
r2 Maybe BufSpan
mb2) =
(EpaLocation -> TokenLocation
TokenLoc (RealSrcSpan -> Maybe BufSpan -> EpaLocation
EpaSpan (RealSrcSpan -> RealSrcSpan -> RealSrcSpan
combineRealSrcSpans RealSrcSpan
r1 RealSrcSpan
r2) (forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 BufSpan -> BufSpan -> BufSpan
combineBufSpans Maybe BufSpan
mb1 Maybe BufSpan
mb2)))
token_location_widenR (TokenLoc (EpaDelta DeltaPos
_ [LEpaComment]
_)) SrcSpan
_ =
forall a. HasCallStack => String -> a
panic String
"token_location_widenR: EpaDelta"
starSym :: Bool -> FastString
starSym :: Bool -> FastString
starSym Bool
True = String -> FastString
fsLit String
"★"
starSym Bool
False = String -> FastString
fsLit String
"*"
mkRdrGetField :: SrcSpanAnnA -> LHsExpr GhcPs -> LocatedAn NoEpAnns (DotFieldOcc GhcPs)
-> EpAnnCO -> LHsExpr GhcPs
mkRdrGetField :: SrcSpanAnnA
-> LHsExpr GhcPs
-> LocatedAn NoEpAnns (DotFieldOcc GhcPs)
-> EpAnnCO
-> LHsExpr GhcPs
mkRdrGetField SrcSpanAnnA
loc LHsExpr GhcPs
arg LocatedAn NoEpAnns (DotFieldOcc GhcPs)
field EpAnnCO
anns =
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc HsGetField {
gf_ext :: XGetField GhcPs
gf_ext = EpAnnCO
anns
, gf_expr :: LHsExpr GhcPs
gf_expr = LHsExpr GhcPs
arg
, gf_field :: XRec GhcPs (DotFieldOcc GhcPs)
gf_field = LocatedAn NoEpAnns (DotFieldOcc GhcPs)
field
}
mkRdrProjection :: NonEmpty (LocatedAn NoEpAnns (DotFieldOcc GhcPs)) -> EpAnn AnnProjection -> HsExpr GhcPs
mkRdrProjection :: NonEmpty (LocatedAn NoEpAnns (DotFieldOcc GhcPs))
-> EpAnn AnnProjection -> HsExpr GhcPs
mkRdrProjection NonEmpty (LocatedAn NoEpAnns (DotFieldOcc GhcPs))
flds EpAnn AnnProjection
anns =
HsProjection {
proj_ext :: XProjection GhcPs
proj_ext = EpAnn AnnProjection
anns
, proj_flds :: NonEmpty (XRec GhcPs (DotFieldOcc GhcPs))
proj_flds = NonEmpty (LocatedAn NoEpAnns (DotFieldOcc GhcPs))
flds
}
mkRdrProjUpdate :: SrcSpanAnnA -> Located [LocatedAn NoEpAnns (DotFieldOcc GhcPs)]
-> LHsExpr GhcPs -> Bool -> EpAnn [AddEpAnn]
-> LHsRecProj GhcPs (LHsExpr GhcPs)
mkRdrProjUpdate :: SrcSpanAnnA
-> Located [LocatedAn NoEpAnns (DotFieldOcc GhcPs)]
-> LHsExpr GhcPs
-> Bool
-> EpAnn [AddEpAnn]
-> LHsRecProj GhcPs (LHsExpr GhcPs)
mkRdrProjUpdate SrcSpanAnnA
_ (L SrcSpan
_ []) LHsExpr GhcPs
_ Bool
_ EpAnn [AddEpAnn]
_ = forall a. HasCallStack => String -> a
panic String
"mkRdrProjUpdate: The impossible has happened!"
mkRdrProjUpdate SrcSpanAnnA
loc (L SrcSpan
l [LocatedAn NoEpAnns (DotFieldOcc GhcPs)]
flds) LHsExpr GhcPs
arg Bool
isPun EpAnn [AddEpAnn]
anns =
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc HsFieldBind {
hfbAnn :: XHsFieldBind
(GenLocated (SrcAnn NoEpAnns) (FieldLabelStrings GhcPs))
hfbAnn = EpAnn [AddEpAnn]
anns
, hfbLHS :: GenLocated (SrcAnn NoEpAnns) (FieldLabelStrings GhcPs)
hfbLHS = forall l e. l -> e -> GenLocated l e
L (forall ann. SrcSpan -> SrcAnn ann
noAnnSrcSpan SrcSpan
l) (forall p. [XRec p (DotFieldOcc p)] -> FieldLabelStrings p
FieldLabelStrings [LocatedAn NoEpAnns (DotFieldOcc GhcPs)]
flds)
, hfbRHS :: GenLocated SrcSpanAnnA (HsExpr GhcPs)
hfbRHS = LHsExpr GhcPs
arg
, hfbPun :: Bool
hfbPun = Bool
isPun
}