{-# LANGUAGE CPP, ScopedTypeVariables #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
module TcGenDeriv (
BagDerivStuff, DerivStuff(..),
gen_Eq_binds,
gen_Ord_binds,
gen_Enum_binds,
gen_Bounded_binds,
gen_Ix_binds,
gen_Show_binds,
gen_Read_binds,
gen_Data_binds,
gen_Lift_binds,
gen_Newtype_binds,
mkCoerceClassMethEqn,
genAuxBinds,
ordOpTbl, boxConTbl, litConTbl,
mkRdrFunBind, mkRdrFunBindEC, mkRdrFunBindSE, error_Expr
) where
#include "HsVersions.h"
import GhcPrelude
import TcRnMonad
import HsSyn
import RdrName
import BasicTypes
import DataCon
import Name
import Fingerprint
import Encoding
import DynFlags
import PrelInfo
import FamInst
import FamInstEnv
import PrelNames
import THNames
import Module ( moduleName, moduleNameString
, moduleUnitId, unitIdString )
import MkId ( coerceId )
import PrimOp
import SrcLoc
import TyCon
import TcEnv
import TcType
import TcValidity ( checkValidCoAxBranch )
import CoAxiom ( coAxiomSingleBranch )
import TysPrim
import TysWiredIn
import Type
import Class
import VarSet
import VarEnv
import Util
import Var
import Outputable
import Lexeme
import FastString
import Pair
import Bag
import Data.List ( find, partition, intersperse )
type BagDerivStuff = Bag DerivStuff
data AuxBindSpec
= DerivCon2Tag TyCon
| DerivTag2Con TyCon
| DerivMaxTag TyCon
deriving( AuxBindSpec -> AuxBindSpec -> Bool
(AuxBindSpec -> AuxBindSpec -> Bool)
-> (AuxBindSpec -> AuxBindSpec -> Bool) -> Eq AuxBindSpec
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AuxBindSpec -> AuxBindSpec -> Bool
$c/= :: AuxBindSpec -> AuxBindSpec -> Bool
== :: AuxBindSpec -> AuxBindSpec -> Bool
$c== :: AuxBindSpec -> AuxBindSpec -> Bool
Eq )
data DerivStuff
= DerivAuxBind AuxBindSpec
| DerivFamInst FamInst
| DerivHsBind (LHsBind GhcPs, LSig GhcPs)
gen_Eq_binds :: SrcSpan -> TyCon -> TcM (LHsBinds GhcPs, BagDerivStuff)
gen_Eq_binds :: SrcSpan -> TyCon -> TcM (LHsBinds GhcPs, BagDerivStuff)
gen_Eq_binds loc :: SrcSpan
loc tycon :: TyCon
tycon = do
DynFlags
dflags <- IOEnv (Env TcGblEnv TcLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
(LHsBinds GhcPs, BagDerivStuff)
-> TcM (LHsBinds GhcPs, BagDerivStuff)
forall (m :: * -> *) a. Monad m => a -> m a
return (DynFlags -> LHsBinds GhcPs
method_binds DynFlags
dflags, BagDerivStuff
aux_binds)
where
all_cons :: [DataCon]
all_cons = TyCon -> [DataCon]
tyConDataCons TyCon
tycon
(nullary_cons :: [DataCon]
nullary_cons, non_nullary_cons :: [DataCon]
non_nullary_cons) = (DataCon -> Bool) -> [DataCon] -> ([DataCon], [DataCon])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition DataCon -> Bool
isNullarySrcDataCon [DataCon]
all_cons
(tag_match_cons :: [DataCon]
tag_match_cons, pat_match_cons :: [DataCon]
pat_match_cons)
| [DataCon]
nullary_cons [DataCon] -> Int -> Bool
forall a. [a] -> Int -> Bool
`lengthExceeds` 10 = ([DataCon]
nullary_cons, [DataCon]
non_nullary_cons)
| Bool
otherwise = ([], [DataCon]
all_cons)
no_tag_match_cons :: Bool
no_tag_match_cons = [DataCon] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [DataCon]
tag_match_cons
fall_through_eqn :: DynFlags -> [([LPat GhcPs], LHsExpr GhcPs)]
fall_through_eqn dflags :: DynFlags
dflags
| Bool
no_tag_match_cons
= case [DataCon]
pat_match_cons of
[] -> []
[_] -> []
_ ->
[([LPat GhcPs
nlWildPat, LPat GhcPs
nlWildPat], LHsExpr GhcPs
false_Expr)]
| Bool
otherwise
= [([LPat GhcPs
a_Pat, LPat GhcPs
b_Pat],
DynFlags
-> TyCon -> [(RdrName, RdrName)] -> LHsExpr GhcPs -> LHsExpr GhcPs
untag_Expr DynFlags
dflags TyCon
tycon [(RdrName
a_RDR,RdrName
ah_RDR), (RdrName
b_RDR,RdrName
bh_RDR)]
(LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs -> LHsExpr GhcPs
genPrimOpApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
ah_RDR) RdrName
eqInt_RDR (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
bh_RDR)))]
aux_binds :: BagDerivStuff
aux_binds | Bool
no_tag_match_cons = BagDerivStuff
forall a. Bag a
emptyBag
| Bool
otherwise = DerivStuff -> BagDerivStuff
forall a. a -> Bag a
unitBag (DerivStuff -> BagDerivStuff) -> DerivStuff -> BagDerivStuff
forall a b. (a -> b) -> a -> b
$ AuxBindSpec -> DerivStuff
DerivAuxBind (AuxBindSpec -> DerivStuff) -> AuxBindSpec -> DerivStuff
forall a b. (a -> b) -> a -> b
$ TyCon -> AuxBindSpec
DerivCon2Tag TyCon
tycon
method_binds :: DynFlags -> LHsBinds GhcPs
method_binds dflags :: DynFlags
dflags = LHsBind GhcPs -> LHsBinds GhcPs
forall a. a -> Bag a
unitBag (DynFlags -> LHsBind GhcPs
eq_bind DynFlags
dflags)
eq_bind :: DynFlags -> LHsBind GhcPs
eq_bind dflags :: DynFlags
dflags = Int
-> SrcSpan
-> RdrName
-> (LHsExpr GhcPs -> LHsExpr GhcPs)
-> [([LPat GhcPs], LHsExpr GhcPs)]
-> LHsBind GhcPs
mkFunBindEC 2 SrcSpan
loc RdrName
eq_RDR (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall a b. a -> b -> a
const LHsExpr GhcPs
true_Expr)
((DataCon -> ([LPat GhcPs], LHsExpr GhcPs))
-> [DataCon] -> [([LPat GhcPs], LHsExpr GhcPs)]
forall a b. (a -> b) -> [a] -> [b]
map DataCon -> ([LPat GhcPs], LHsExpr GhcPs)
pats_etc [DataCon]
pat_match_cons
[([LPat GhcPs], LHsExpr GhcPs)]
-> [([LPat GhcPs], LHsExpr GhcPs)]
-> [([LPat GhcPs], LHsExpr GhcPs)]
forall a. [a] -> [a] -> [a]
++ DynFlags -> [([LPat GhcPs], LHsExpr GhcPs)]
fall_through_eqn DynFlags
dflags)
pats_etc :: DataCon -> ([LPat GhcPs], LHsExpr GhcPs)
pats_etc data_con :: DataCon
data_con
= let
con1_pat :: LPat GhcPs
con1_pat = LPat GhcPs -> LPat GhcPs
forall (name :: Pass). LPat (GhcPass name) -> LPat (GhcPass name)
nlParPat (LPat GhcPs -> LPat GhcPs) -> LPat GhcPs -> LPat GhcPs
forall a b. (a -> b) -> a -> b
$ RdrName -> [RdrName] -> LPat GhcPs
nlConVarPat RdrName
data_con_RDR [RdrName]
as_needed
con2_pat :: LPat GhcPs
con2_pat = LPat GhcPs -> LPat GhcPs
forall (name :: Pass). LPat (GhcPass name) -> LPat (GhcPass name)
nlParPat (LPat GhcPs -> LPat GhcPs) -> LPat GhcPs -> LPat GhcPs
forall a b. (a -> b) -> a -> b
$ RdrName -> [RdrName] -> LPat GhcPs
nlConVarPat RdrName
data_con_RDR [RdrName]
bs_needed
data_con_RDR :: RdrName
data_con_RDR = DataCon -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName DataCon
data_con
con_arity :: Int
con_arity = [Type] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Type]
tys_needed
as_needed :: [RdrName]
as_needed = Int -> [RdrName] -> [RdrName]
forall a. Int -> [a] -> [a]
take Int
con_arity [RdrName]
as_RDRs
bs_needed :: [RdrName]
bs_needed = Int -> [RdrName] -> [RdrName]
forall a. Int -> [a] -> [a]
take Int
con_arity [RdrName]
bs_RDRs
tys_needed :: [Type]
tys_needed = DataCon -> [Type]
dataConOrigArgTys DataCon
data_con
in
([LPat GhcPs
con1_pat, LPat GhcPs
con2_pat], [Type] -> [RdrName] -> [RdrName] -> LHsExpr GhcPs
nested_eq_expr [Type]
tys_needed [RdrName]
as_needed [RdrName]
bs_needed)
where
nested_eq_expr :: [Type] -> [RdrName] -> [RdrName] -> LHsExpr GhcPs
nested_eq_expr [] [] [] = LHsExpr GhcPs
true_Expr
nested_eq_expr tys :: [Type]
tys as :: [RdrName]
as bs :: [RdrName]
bs
= (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs)
-> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldr1 LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
and_Expr (String
-> (Type -> RdrName -> RdrName -> LHsExpr GhcPs)
-> [Type]
-> [RdrName]
-> [RdrName]
-> [LHsExpr GhcPs]
forall a b c d.
String -> (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
zipWith3Equal "nested_eq" Type -> RdrName -> RdrName -> LHsExpr GhcPs
nested_eq [Type]
tys [RdrName]
as [RdrName]
bs)
where
nested_eq :: Type -> RdrName -> RdrName -> LHsExpr GhcPs
nested_eq ty :: Type
ty a :: RdrName
a b :: RdrName
b = LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass). LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsPar (Type -> LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
eq_Expr Type
ty (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
a) (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
b))
data OrdOp = OrdCompare | OrdLT | OrdLE | OrdGE | OrdGT
ordMethRdr :: OrdOp -> RdrName
ordMethRdr :: OrdOp -> RdrName
ordMethRdr op :: OrdOp
op
= case OrdOp
op of
OrdCompare -> RdrName
compare_RDR
OrdLT -> RdrName
lt_RDR
OrdLE -> RdrName
le_RDR
OrdGE -> RdrName
ge_RDR
OrdGT -> RdrName
gt_RDR
ltResult :: OrdOp -> LHsExpr GhcPs
ltResult :: OrdOp -> LHsExpr GhcPs
ltResult OrdCompare = LHsExpr GhcPs
ltTag_Expr
ltResult OrdLT = LHsExpr GhcPs
true_Expr
ltResult OrdLE = LHsExpr GhcPs
true_Expr
ltResult OrdGE = LHsExpr GhcPs
false_Expr
ltResult OrdGT = LHsExpr GhcPs
false_Expr
eqResult :: OrdOp -> LHsExpr GhcPs
eqResult :: OrdOp -> LHsExpr GhcPs
eqResult OrdCompare = LHsExpr GhcPs
eqTag_Expr
eqResult OrdLT = LHsExpr GhcPs
false_Expr
eqResult OrdLE = LHsExpr GhcPs
true_Expr
eqResult OrdGE = LHsExpr GhcPs
true_Expr
eqResult OrdGT = LHsExpr GhcPs
false_Expr
gtResult :: OrdOp -> LHsExpr GhcPs
gtResult :: OrdOp -> LHsExpr GhcPs
gtResult OrdCompare = LHsExpr GhcPs
gtTag_Expr
gtResult OrdLT = LHsExpr GhcPs
false_Expr
gtResult OrdLE = LHsExpr GhcPs
false_Expr
gtResult OrdGE = LHsExpr GhcPs
true_Expr
gtResult OrdGT = LHsExpr GhcPs
true_Expr
gen_Ord_binds :: SrcSpan -> TyCon -> TcM (LHsBinds GhcPs, BagDerivStuff)
gen_Ord_binds :: SrcSpan -> TyCon -> TcM (LHsBinds GhcPs, BagDerivStuff)
gen_Ord_binds loc :: SrcSpan
loc tycon :: TyCon
tycon = do
DynFlags
dflags <- IOEnv (Env TcGblEnv TcLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
(LHsBinds GhcPs, BagDerivStuff)
-> TcM (LHsBinds GhcPs, BagDerivStuff)
forall (m :: * -> *) a. Monad m => a -> m a
return ((LHsBinds GhcPs, BagDerivStuff)
-> TcM (LHsBinds GhcPs, BagDerivStuff))
-> (LHsBinds GhcPs, BagDerivStuff)
-> TcM (LHsBinds GhcPs, BagDerivStuff)
forall a b. (a -> b) -> a -> b
$ if [DataCon] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [DataCon]
tycon_data_cons
then ( LHsBind GhcPs -> LHsBinds GhcPs
forall a. a -> Bag a
unitBag (LHsBind GhcPs -> LHsBinds GhcPs)
-> LHsBind GhcPs -> LHsBinds GhcPs
forall a b. (a -> b) -> a -> b
$ Int
-> SrcSpan
-> RdrName
-> (LHsExpr GhcPs -> LHsExpr GhcPs)
-> [([LPat GhcPs], LHsExpr GhcPs)]
-> LHsBind GhcPs
mkFunBindEC 2 SrcSpan
loc RdrName
compare_RDR (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall a b. a -> b -> a
const LHsExpr GhcPs
eqTag_Expr) []
, BagDerivStuff
forall a. Bag a
emptyBag)
else ( LHsBind GhcPs -> LHsBinds GhcPs
forall a. a -> Bag a
unitBag (DynFlags -> OrdOp -> LHsBind GhcPs
mkOrdOp DynFlags
dflags OrdOp
OrdCompare) LHsBinds GhcPs -> LHsBinds GhcPs -> LHsBinds GhcPs
forall a. Bag a -> Bag a -> Bag a
`unionBags` DynFlags -> LHsBinds GhcPs
other_ops DynFlags
dflags
, BagDerivStuff
aux_binds)
where
aux_binds :: BagDerivStuff
aux_binds | Bool
single_con_type = BagDerivStuff
forall a. Bag a
emptyBag
| Bool
otherwise = DerivStuff -> BagDerivStuff
forall a. a -> Bag a
unitBag (DerivStuff -> BagDerivStuff) -> DerivStuff -> BagDerivStuff
forall a b. (a -> b) -> a -> b
$ AuxBindSpec -> DerivStuff
DerivAuxBind (AuxBindSpec -> DerivStuff) -> AuxBindSpec -> DerivStuff
forall a b. (a -> b) -> a -> b
$ TyCon -> AuxBindSpec
DerivCon2Tag TyCon
tycon
other_ops :: DynFlags -> LHsBinds GhcPs
other_ops dflags :: DynFlags
dflags
| (Int
last_tag Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
first_tag) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 2
Bool -> Bool -> Bool
|| [DataCon] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [DataCon]
non_nullary_cons
= [LHsBind GhcPs] -> LHsBinds GhcPs
forall a. [a] -> Bag a
listToBag [DynFlags -> OrdOp -> LHsBind GhcPs
mkOrdOp DynFlags
dflags OrdOp
OrdLT, LHsBind GhcPs
lE, LHsBind GhcPs
gT, LHsBind GhcPs
gE]
| Bool
otherwise
= LHsBinds GhcPs
forall a. Bag a
emptyBag
negate_expr :: LHsExpr GhcPs -> LHsExpr GhcPs
negate_expr = LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
not_RDR)
lE :: LHsBind GhcPs
lE = SrcSpan
-> RdrName -> [LPat GhcPs] -> LHsExpr GhcPs -> LHsBind GhcPs
mk_easy_FunBind SrcSpan
loc RdrName
le_RDR [LPat GhcPs
a_Pat, LPat GhcPs
b_Pat] (LHsExpr GhcPs -> LHsBind GhcPs) -> LHsExpr GhcPs -> LHsBind GhcPs
forall a b. (a -> b) -> a -> b
$
LHsExpr GhcPs -> LHsExpr GhcPs
negate_expr (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
lt_RDR) LHsExpr GhcPs
b_Expr) LHsExpr GhcPs
a_Expr)
gT :: LHsBind GhcPs
gT = SrcSpan
-> RdrName -> [LPat GhcPs] -> LHsExpr GhcPs -> LHsBind GhcPs
mk_easy_FunBind SrcSpan
loc RdrName
gt_RDR [LPat GhcPs
a_Pat, LPat GhcPs
b_Pat] (LHsExpr GhcPs -> LHsBind GhcPs) -> LHsExpr GhcPs -> LHsBind GhcPs
forall a b. (a -> b) -> a -> b
$
LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
lt_RDR) LHsExpr GhcPs
b_Expr) LHsExpr GhcPs
a_Expr
gE :: LHsBind GhcPs
gE = SrcSpan
-> RdrName -> [LPat GhcPs] -> LHsExpr GhcPs -> LHsBind GhcPs
mk_easy_FunBind SrcSpan
loc RdrName
ge_RDR [LPat GhcPs
a_Pat, LPat GhcPs
b_Pat] (LHsExpr GhcPs -> LHsBind GhcPs) -> LHsExpr GhcPs -> LHsBind GhcPs
forall a b. (a -> b) -> a -> b
$
LHsExpr GhcPs -> LHsExpr GhcPs
negate_expr (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
lt_RDR) LHsExpr GhcPs
a_Expr) LHsExpr GhcPs
b_Expr)
get_tag :: DataCon -> Int
get_tag con :: DataCon
con = DataCon -> Int
dataConTag DataCon
con Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
fIRST_TAG
tycon_data_cons :: [DataCon]
tycon_data_cons = TyCon -> [DataCon]
tyConDataCons TyCon
tycon
single_con_type :: Bool
single_con_type = [DataCon] -> Bool
forall a. [a] -> Bool
isSingleton [DataCon]
tycon_data_cons
(first_con :: DataCon
first_con : _) = [DataCon]
tycon_data_cons
(last_con :: DataCon
last_con : _) = [DataCon] -> [DataCon]
forall a. [a] -> [a]
reverse [DataCon]
tycon_data_cons
first_tag :: Int
first_tag = DataCon -> Int
get_tag DataCon
first_con
last_tag :: Int
last_tag = DataCon -> Int
get_tag DataCon
last_con
(nullary_cons :: [DataCon]
nullary_cons, non_nullary_cons :: [DataCon]
non_nullary_cons) = (DataCon -> Bool) -> [DataCon] -> ([DataCon], [DataCon])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition DataCon -> Bool
isNullarySrcDataCon [DataCon]
tycon_data_cons
mkOrdOp :: DynFlags -> OrdOp -> LHsBind GhcPs
mkOrdOp :: DynFlags -> OrdOp -> LHsBind GhcPs
mkOrdOp dflags :: DynFlags
dflags op :: OrdOp
op = SrcSpan
-> RdrName -> [LPat GhcPs] -> LHsExpr GhcPs -> LHsBind GhcPs
mk_easy_FunBind SrcSpan
loc (OrdOp -> RdrName
ordMethRdr OrdOp
op) [LPat GhcPs
a_Pat, LPat GhcPs
b_Pat]
(DynFlags -> OrdOp -> LHsExpr GhcPs
mkOrdOpRhs DynFlags
dflags OrdOp
op)
mkOrdOpRhs :: DynFlags -> OrdOp -> LHsExpr GhcPs
mkOrdOpRhs :: DynFlags -> OrdOp -> LHsExpr GhcPs
mkOrdOpRhs dflags :: DynFlags
dflags op :: OrdOp
op
| [DataCon]
nullary_cons [DataCon] -> Int -> Bool
forall a. [a] -> Int -> Bool
`lengthAtMost` 2
= LHsExpr GhcPs -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsExpr GhcPs
nlHsCase (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
a_RDR) ([LMatch GhcPs (LHsExpr GhcPs)] -> LHsExpr GhcPs)
-> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$
(DataCon -> LMatch GhcPs (LHsExpr GhcPs))
-> [DataCon] -> [LMatch GhcPs (LHsExpr GhcPs)]
forall a b. (a -> b) -> [a] -> [b]
map (DynFlags -> OrdOp -> DataCon -> LMatch GhcPs (LHsExpr GhcPs)
mkOrdOpAlt DynFlags
dflags OrdOp
op) [DataCon]
tycon_data_cons
| [DataCon] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [DataCon]
non_nullary_cons
= DynFlags -> OrdOp -> LHsExpr GhcPs
mkTagCmp DynFlags
dflags OrdOp
op
| Bool
otherwise
= LHsExpr GhcPs -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsExpr GhcPs
nlHsCase (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
a_RDR) ([LMatch GhcPs (LHsExpr GhcPs)] -> LHsExpr GhcPs)
-> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$
((DataCon -> LMatch GhcPs (LHsExpr GhcPs))
-> [DataCon] -> [LMatch GhcPs (LHsExpr GhcPs)]
forall a b. (a -> b) -> [a] -> [b]
map (DynFlags -> OrdOp -> DataCon -> LMatch GhcPs (LHsExpr GhcPs)
mkOrdOpAlt DynFlags
dflags OrdOp
op) [DataCon]
non_nullary_cons
[LMatch GhcPs (LHsExpr GhcPs)]
-> [LMatch GhcPs (LHsExpr GhcPs)] -> [LMatch GhcPs (LHsExpr GhcPs)]
forall a. [a] -> [a] -> [a]
++ [LPat GhcPs -> LHsExpr GhcPs -> LMatch GhcPs (LHsExpr GhcPs)
forall (p :: Pass) (body :: * -> *).
LPat (GhcPass p)
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkHsCaseAlt LPat GhcPs
nlWildPat (DynFlags -> OrdOp -> LHsExpr GhcPs
mkTagCmp DynFlags
dflags OrdOp
op)])
mkOrdOpAlt :: DynFlags -> OrdOp -> DataCon
-> LMatch GhcPs (LHsExpr GhcPs)
mkOrdOpAlt :: DynFlags -> OrdOp -> DataCon -> LMatch GhcPs (LHsExpr GhcPs)
mkOrdOpAlt dflags :: DynFlags
dflags op :: OrdOp
op data_con :: DataCon
data_con
= LPat GhcPs -> LHsExpr GhcPs -> LMatch GhcPs (LHsExpr GhcPs)
forall (p :: Pass) (body :: * -> *).
LPat (GhcPass p)
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkHsCaseAlt (RdrName -> [RdrName] -> LPat GhcPs
nlConVarPat RdrName
data_con_RDR [RdrName]
as_needed)
(DynFlags -> OrdOp -> DataCon -> LHsExpr GhcPs
mkInnerRhs DynFlags
dflags OrdOp
op DataCon
data_con)
where
as_needed :: [RdrName]
as_needed = Int -> [RdrName] -> [RdrName]
forall a. Int -> [a] -> [a]
take (DataCon -> Int
dataConSourceArity DataCon
data_con) [RdrName]
as_RDRs
data_con_RDR :: RdrName
data_con_RDR = DataCon -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName DataCon
data_con
mkInnerRhs :: DynFlags -> OrdOp -> DataCon -> LHsExpr GhcPs
mkInnerRhs dflags :: DynFlags
dflags op :: OrdOp
op data_con :: DataCon
data_con
| Bool
single_con_type
= LHsExpr GhcPs -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsExpr GhcPs
nlHsCase (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
b_RDR) [ OrdOp -> DataCon -> LMatch GhcPs (LHsExpr GhcPs)
mkInnerEqAlt OrdOp
op DataCon
data_con ]
| Int
tag Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
first_tag
= LHsExpr GhcPs -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsExpr GhcPs
nlHsCase (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
b_RDR) [ OrdOp -> DataCon -> LMatch GhcPs (LHsExpr GhcPs)
mkInnerEqAlt OrdOp
op DataCon
data_con
, LPat GhcPs -> LHsExpr GhcPs -> LMatch GhcPs (LHsExpr GhcPs)
forall (p :: Pass) (body :: * -> *).
LPat (GhcPass p)
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkHsCaseAlt LPat GhcPs
nlWildPat (OrdOp -> LHsExpr GhcPs
ltResult OrdOp
op) ]
| Int
tag Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
last_tag
= LHsExpr GhcPs -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsExpr GhcPs
nlHsCase (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
b_RDR) [ OrdOp -> DataCon -> LMatch GhcPs (LHsExpr GhcPs)
mkInnerEqAlt OrdOp
op DataCon
data_con
, LPat GhcPs -> LHsExpr GhcPs -> LMatch GhcPs (LHsExpr GhcPs)
forall (p :: Pass) (body :: * -> *).
LPat (GhcPass p)
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkHsCaseAlt LPat GhcPs
nlWildPat (OrdOp -> LHsExpr GhcPs
gtResult OrdOp
op) ]
| Int
tag Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
first_tag Int -> Int -> Int
forall a. Num a => a -> a -> a
+ 1
= LHsExpr GhcPs -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsExpr GhcPs
nlHsCase (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
b_RDR) [ LPat GhcPs -> LHsExpr GhcPs -> LMatch GhcPs (LHsExpr GhcPs)
forall (p :: Pass) (body :: * -> *).
LPat (GhcPass p)
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkHsCaseAlt (DataCon -> LPat GhcPs
nlConWildPat DataCon
first_con)
(OrdOp -> LHsExpr GhcPs
gtResult OrdOp
op)
, OrdOp -> DataCon -> LMatch GhcPs (LHsExpr GhcPs)
mkInnerEqAlt OrdOp
op DataCon
data_con
, LPat GhcPs -> LHsExpr GhcPs -> LMatch GhcPs (LHsExpr GhcPs)
forall (p :: Pass) (body :: * -> *).
LPat (GhcPass p)
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkHsCaseAlt LPat GhcPs
nlWildPat (OrdOp -> LHsExpr GhcPs
ltResult OrdOp
op) ]
| Int
tag Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
last_tag Int -> Int -> Int
forall a. Num a => a -> a -> a
- 1
= LHsExpr GhcPs -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsExpr GhcPs
nlHsCase (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
b_RDR) [ LPat GhcPs -> LHsExpr GhcPs -> LMatch GhcPs (LHsExpr GhcPs)
forall (p :: Pass) (body :: * -> *).
LPat (GhcPass p)
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkHsCaseAlt (DataCon -> LPat GhcPs
nlConWildPat DataCon
last_con)
(OrdOp -> LHsExpr GhcPs
ltResult OrdOp
op)
, OrdOp -> DataCon -> LMatch GhcPs (LHsExpr GhcPs)
mkInnerEqAlt OrdOp
op DataCon
data_con
, LPat GhcPs -> LHsExpr GhcPs -> LMatch GhcPs (LHsExpr GhcPs)
forall (p :: Pass) (body :: * -> *).
LPat (GhcPass p)
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkHsCaseAlt LPat GhcPs
nlWildPat (OrdOp -> LHsExpr GhcPs
gtResult OrdOp
op) ]
| Int
tag Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
last_tag Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` 2
= DynFlags
-> TyCon -> [(RdrName, RdrName)] -> LHsExpr GhcPs -> LHsExpr GhcPs
untag_Expr DynFlags
dflags TyCon
tycon [(RdrName
b_RDR, RdrName
bh_RDR)] (LHsExpr GhcPs -> LHsExpr GhcPs) -> LHsExpr GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$
LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
nlHsIf (LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs -> LHsExpr GhcPs
genPrimOpApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
bh_RDR) RdrName
ltInt_RDR LHsExpr GhcPs
tag_lit)
(OrdOp -> LHsExpr GhcPs
gtResult OrdOp
op) (LHsExpr GhcPs -> LHsExpr GhcPs) -> LHsExpr GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$
LHsExpr GhcPs -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsExpr GhcPs
nlHsCase (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
b_RDR) [ OrdOp -> DataCon -> LMatch GhcPs (LHsExpr GhcPs)
mkInnerEqAlt OrdOp
op DataCon
data_con
, LPat GhcPs -> LHsExpr GhcPs -> LMatch GhcPs (LHsExpr GhcPs)
forall (p :: Pass) (body :: * -> *).
LPat (GhcPass p)
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkHsCaseAlt LPat GhcPs
nlWildPat (OrdOp -> LHsExpr GhcPs
ltResult OrdOp
op) ]
| Bool
otherwise
= DynFlags
-> TyCon -> [(RdrName, RdrName)] -> LHsExpr GhcPs -> LHsExpr GhcPs
untag_Expr DynFlags
dflags TyCon
tycon [(RdrName
b_RDR, RdrName
bh_RDR)] (LHsExpr GhcPs -> LHsExpr GhcPs) -> LHsExpr GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$
LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
nlHsIf (LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs -> LHsExpr GhcPs
genPrimOpApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
bh_RDR) RdrName
gtInt_RDR LHsExpr GhcPs
tag_lit)
(OrdOp -> LHsExpr GhcPs
ltResult OrdOp
op) (LHsExpr GhcPs -> LHsExpr GhcPs) -> LHsExpr GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$
LHsExpr GhcPs -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsExpr GhcPs
nlHsCase (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
b_RDR) [ OrdOp -> DataCon -> LMatch GhcPs (LHsExpr GhcPs)
mkInnerEqAlt OrdOp
op DataCon
data_con
, LPat GhcPs -> LHsExpr GhcPs -> LMatch GhcPs (LHsExpr GhcPs)
forall (p :: Pass) (body :: * -> *).
LPat (GhcPass p)
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkHsCaseAlt LPat GhcPs
nlWildPat (OrdOp -> LHsExpr GhcPs
gtResult OrdOp
op) ]
where
tag :: Int
tag = DataCon -> Int
get_tag DataCon
data_con
tag_lit :: LHsExpr GhcPs
tag_lit = SrcSpanLess (LHsExpr GhcPs) -> LHsExpr GhcPs
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc (XLitE GhcPs -> HsLit GhcPs -> HsExpr GhcPs
forall p. XLitE p -> HsLit p -> HsExpr p
HsLit XLitE GhcPs
NoExt
noExt (XHsIntPrim GhcPs -> Integer -> HsLit GhcPs
forall x. XHsIntPrim x -> Integer -> HsLit x
HsIntPrim SourceText
XHsIntPrim GhcPs
NoSourceText (Int -> Integer
forall a. Integral a => a -> Integer
toInteger Int
tag)))
mkInnerEqAlt :: OrdOp -> DataCon -> LMatch GhcPs (LHsExpr GhcPs)
mkInnerEqAlt :: OrdOp -> DataCon -> LMatch GhcPs (LHsExpr GhcPs)
mkInnerEqAlt op :: OrdOp
op data_con :: DataCon
data_con
= LPat GhcPs -> LHsExpr GhcPs -> LMatch GhcPs (LHsExpr GhcPs)
forall (p :: Pass) (body :: * -> *).
LPat (GhcPass p)
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkHsCaseAlt (RdrName -> [RdrName] -> LPat GhcPs
nlConVarPat RdrName
data_con_RDR [RdrName]
bs_needed) (LHsExpr GhcPs -> LMatch GhcPs (LHsExpr GhcPs))
-> LHsExpr GhcPs -> LMatch GhcPs (LHsExpr GhcPs)
forall a b. (a -> b) -> a -> b
$
OrdOp -> [Type] -> LHsExpr GhcPs
mkCompareFields OrdOp
op (DataCon -> [Type]
dataConOrigArgTys DataCon
data_con)
where
data_con_RDR :: RdrName
data_con_RDR = DataCon -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName DataCon
data_con
bs_needed :: [RdrName]
bs_needed = Int -> [RdrName] -> [RdrName]
forall a. Int -> [a] -> [a]
take (DataCon -> Int
dataConSourceArity DataCon
data_con) [RdrName]
bs_RDRs
mkTagCmp :: DynFlags -> OrdOp -> LHsExpr GhcPs
mkTagCmp :: DynFlags -> OrdOp -> LHsExpr GhcPs
mkTagCmp dflags :: DynFlags
dflags op :: OrdOp
op =
DynFlags
-> TyCon -> [(RdrName, RdrName)] -> LHsExpr GhcPs -> LHsExpr GhcPs
untag_Expr DynFlags
dflags TyCon
tycon[(RdrName
a_RDR, RdrName
ah_RDR),(RdrName
b_RDR, RdrName
bh_RDR)] (LHsExpr GhcPs -> LHsExpr GhcPs) -> LHsExpr GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$
Type -> OrdOp -> RdrName -> RdrName -> LHsExpr GhcPs
unliftedOrdOp Type
intPrimTy OrdOp
op RdrName
ah_RDR RdrName
bh_RDR
mkCompareFields :: OrdOp -> [Type] -> LHsExpr GhcPs
mkCompareFields :: OrdOp -> [Type] -> LHsExpr GhcPs
mkCompareFields op :: OrdOp
op tys :: [Type]
tys
= [Type] -> [RdrName] -> [RdrName] -> LHsExpr GhcPs
go [Type]
tys [RdrName]
as_RDRs [RdrName]
bs_RDRs
where
go :: [Type] -> [RdrName] -> [RdrName] -> LHsExpr GhcPs
go [] _ _ = OrdOp -> LHsExpr GhcPs
eqResult OrdOp
op
go [ty :: Type
ty] (a :: RdrName
a:_) (b :: RdrName
b:_)
| HasDebugCallStack => Type -> Bool
Type -> Bool
isUnliftedType Type
ty = Type -> OrdOp -> RdrName -> RdrName -> LHsExpr GhcPs
unliftedOrdOp Type
ty OrdOp
op RdrName
a RdrName
b
| Bool
otherwise = LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs -> LHsExpr GhcPs
genOpApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
a) (OrdOp -> RdrName
ordMethRdr OrdOp
op) (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
b)
go (ty :: Type
ty:tys :: [Type]
tys) (a :: RdrName
a:as :: [RdrName]
as) (b :: RdrName
b:bs :: [RdrName]
bs) = Type
-> RdrName
-> RdrName
-> LHsExpr GhcPs
-> LHsExpr GhcPs
-> LHsExpr GhcPs
-> LHsExpr GhcPs
mk_compare Type
ty RdrName
a RdrName
b
(OrdOp -> LHsExpr GhcPs
ltResult OrdOp
op)
([Type] -> [RdrName] -> [RdrName] -> LHsExpr GhcPs
go [Type]
tys [RdrName]
as [RdrName]
bs)
(OrdOp -> LHsExpr GhcPs
gtResult OrdOp
op)
go _ _ _ = String -> LHsExpr GhcPs
forall a. String -> a
panic "mkCompareFields"
mk_compare :: Type
-> RdrName
-> RdrName
-> LHsExpr GhcPs
-> LHsExpr GhcPs
-> LHsExpr GhcPs
-> LHsExpr GhcPs
mk_compare ty :: Type
ty a :: RdrName
a b :: RdrName
b lt :: LHsExpr GhcPs
lt eq :: LHsExpr GhcPs
eq gt :: LHsExpr GhcPs
gt
| HasDebugCallStack => Type -> Bool
Type -> Bool
isUnliftedType Type
ty
= RdrName
-> RdrName
-> LHsExpr GhcPs
-> LHsExpr GhcPs
-> LHsExpr GhcPs
-> LHsExpr GhcPs
-> LHsExpr GhcPs
-> LHsExpr GhcPs
unliftedCompare RdrName
lt_op RdrName
eq_op LHsExpr GhcPs
a_expr LHsExpr GhcPs
b_expr LHsExpr GhcPs
lt LHsExpr GhcPs
eq LHsExpr GhcPs
gt
| Bool
otherwise
= LHsExpr GhcPs -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsExpr GhcPs
nlHsCase (LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass). LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsPar (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
compare_RDR) LHsExpr GhcPs
a_expr) LHsExpr GhcPs
b_expr))
[LPat GhcPs -> LHsExpr GhcPs -> LMatch GhcPs (LHsExpr GhcPs)
forall (p :: Pass) (body :: * -> *).
LPat (GhcPass p)
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkHsCaseAlt (IdP GhcPs -> LPat GhcPs
forall (p :: Pass). IdP (GhcPass p) -> LPat (GhcPass p)
nlNullaryConPat RdrName
IdP GhcPs
ltTag_RDR) LHsExpr GhcPs
lt,
LPat GhcPs -> LHsExpr GhcPs -> LMatch GhcPs (LHsExpr GhcPs)
forall (p :: Pass) (body :: * -> *).
LPat (GhcPass p)
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkHsCaseAlt (IdP GhcPs -> LPat GhcPs
forall (p :: Pass). IdP (GhcPass p) -> LPat (GhcPass p)
nlNullaryConPat RdrName
IdP GhcPs
eqTag_RDR) LHsExpr GhcPs
eq,
LPat GhcPs -> LHsExpr GhcPs -> LMatch GhcPs (LHsExpr GhcPs)
forall (p :: Pass) (body :: * -> *).
LPat (GhcPass p)
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkHsCaseAlt (IdP GhcPs -> LPat GhcPs
forall (p :: Pass). IdP (GhcPass p) -> LPat (GhcPass p)
nlNullaryConPat RdrName
IdP GhcPs
gtTag_RDR) LHsExpr GhcPs
gt]
where
a_expr :: LHsExpr GhcPs
a_expr = IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
a
b_expr :: LHsExpr GhcPs
b_expr = IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
b
(lt_op :: RdrName
lt_op, _, eq_op :: RdrName
eq_op, _, _) = String -> Type -> (RdrName, RdrName, RdrName, RdrName, RdrName)
primOrdOps "Ord" Type
ty
unliftedOrdOp :: Type -> OrdOp -> RdrName -> RdrName -> LHsExpr GhcPs
unliftedOrdOp :: Type -> OrdOp -> RdrName -> RdrName -> LHsExpr GhcPs
unliftedOrdOp ty :: Type
ty op :: OrdOp
op a :: RdrName
a b :: RdrName
b
= case OrdOp
op of
OrdCompare -> RdrName
-> RdrName
-> LHsExpr GhcPs
-> LHsExpr GhcPs
-> LHsExpr GhcPs
-> LHsExpr GhcPs
-> LHsExpr GhcPs
-> LHsExpr GhcPs
unliftedCompare RdrName
lt_op RdrName
eq_op LHsExpr GhcPs
a_expr LHsExpr GhcPs
b_expr
LHsExpr GhcPs
ltTag_Expr LHsExpr GhcPs
eqTag_Expr LHsExpr GhcPs
gtTag_Expr
OrdLT -> RdrName -> LHsExpr GhcPs
wrap RdrName
lt_op
OrdLE -> RdrName -> LHsExpr GhcPs
wrap RdrName
le_op
OrdGE -> RdrName -> LHsExpr GhcPs
wrap RdrName
ge_op
OrdGT -> RdrName -> LHsExpr GhcPs
wrap RdrName
gt_op
where
(lt_op :: RdrName
lt_op, le_op :: RdrName
le_op, eq_op :: RdrName
eq_op, ge_op :: RdrName
ge_op, gt_op :: RdrName
gt_op) = String -> Type -> (RdrName, RdrName, RdrName, RdrName, RdrName)
primOrdOps "Ord" Type
ty
wrap :: RdrName -> LHsExpr GhcPs
wrap prim_op :: RdrName
prim_op = LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs -> LHsExpr GhcPs
genPrimOpApp LHsExpr GhcPs
a_expr RdrName
prim_op LHsExpr GhcPs
b_expr
a_expr :: LHsExpr GhcPs
a_expr = IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
a
b_expr :: LHsExpr GhcPs
b_expr = IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
b
unliftedCompare :: RdrName -> RdrName
-> LHsExpr GhcPs -> LHsExpr GhcPs
-> LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
-> LHsExpr GhcPs
unliftedCompare :: RdrName
-> RdrName
-> LHsExpr GhcPs
-> LHsExpr GhcPs
-> LHsExpr GhcPs
-> LHsExpr GhcPs
-> LHsExpr GhcPs
-> LHsExpr GhcPs
unliftedCompare lt_op :: RdrName
lt_op eq_op :: RdrName
eq_op a_expr :: LHsExpr GhcPs
a_expr b_expr :: LHsExpr GhcPs
b_expr lt :: LHsExpr GhcPs
lt eq :: LHsExpr GhcPs
eq gt :: LHsExpr GhcPs
gt
= LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
nlHsIf (LHsExpr GhcPs -> LHsExpr GhcPs
ascribeBool (LHsExpr GhcPs -> LHsExpr GhcPs) -> LHsExpr GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$ LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs -> LHsExpr GhcPs
genPrimOpApp LHsExpr GhcPs
a_expr RdrName
lt_op LHsExpr GhcPs
b_expr) LHsExpr GhcPs
lt (LHsExpr GhcPs -> LHsExpr GhcPs) -> LHsExpr GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$
LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
nlHsIf (LHsExpr GhcPs -> LHsExpr GhcPs
ascribeBool (LHsExpr GhcPs -> LHsExpr GhcPs) -> LHsExpr GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$ LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs -> LHsExpr GhcPs
genPrimOpApp LHsExpr GhcPs
a_expr RdrName
eq_op LHsExpr GhcPs
b_expr) LHsExpr GhcPs
eq LHsExpr GhcPs
gt
where
ascribeBool :: LHsExpr GhcPs -> LHsExpr GhcPs
ascribeBool e :: LHsExpr GhcPs
e = LHsExpr GhcPs -> Type -> LHsExpr GhcPs
nlExprWithTySig LHsExpr GhcPs
e Type
boolTy
nlConWildPat :: DataCon -> LPat GhcPs
nlConWildPat :: DataCon -> LPat GhcPs
nlConWildPat con :: DataCon
con = SrcSpanLess (LPat GhcPs) -> LPat GhcPs
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc (Located (IdP GhcPs) -> HsConPatDetails GhcPs -> LPat GhcPs
forall p. Located (IdP p) -> HsConPatDetails p -> Pat p
ConPatIn (SrcSpanLess (Located RdrName) -> Located RdrName
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc (DataCon -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName DataCon
con))
(HsRecFields GhcPs (LPat GhcPs) -> HsConPatDetails GhcPs
forall arg rec. rec -> HsConDetails arg rec
RecCon (HsRecFields :: forall p arg. [LHsRecField p arg] -> Maybe Int -> HsRecFields p arg
HsRecFields { rec_flds :: [LHsRecField GhcPs (LPat GhcPs)]
rec_flds = []
, rec_dotdot :: Maybe Int
rec_dotdot = Maybe Int
forall a. Maybe a
Nothing })))
gen_Enum_binds :: SrcSpan -> TyCon -> TcM (LHsBinds GhcPs, BagDerivStuff)
gen_Enum_binds :: SrcSpan -> TyCon -> TcM (LHsBinds GhcPs, BagDerivStuff)
gen_Enum_binds loc :: SrcSpan
loc tycon :: TyCon
tycon = do
DynFlags
dflags <- IOEnv (Env TcGblEnv TcLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
(LHsBinds GhcPs, BagDerivStuff)
-> TcM (LHsBinds GhcPs, BagDerivStuff)
forall (m :: * -> *) a. Monad m => a -> m a
return (DynFlags -> LHsBinds GhcPs
method_binds DynFlags
dflags, BagDerivStuff
aux_binds)
where
method_binds :: DynFlags -> LHsBinds GhcPs
method_binds dflags :: DynFlags
dflags = [LHsBind GhcPs] -> LHsBinds GhcPs
forall a. [a] -> Bag a
listToBag
[ DynFlags -> LHsBind GhcPs
succ_enum DynFlags
dflags
, DynFlags -> LHsBind GhcPs
pred_enum DynFlags
dflags
, DynFlags -> LHsBind GhcPs
to_enum DynFlags
dflags
, DynFlags -> LHsBind GhcPs
enum_from DynFlags
dflags
, DynFlags -> LHsBind GhcPs
enum_from_then DynFlags
dflags
, DynFlags -> LHsBind GhcPs
from_enum DynFlags
dflags
]
aux_binds :: BagDerivStuff
aux_binds = [DerivStuff] -> BagDerivStuff
forall a. [a] -> Bag a
listToBag ([DerivStuff] -> BagDerivStuff) -> [DerivStuff] -> BagDerivStuff
forall a b. (a -> b) -> a -> b
$ (AuxBindSpec -> DerivStuff) -> [AuxBindSpec] -> [DerivStuff]
forall a b. (a -> b) -> [a] -> [b]
map AuxBindSpec -> DerivStuff
DerivAuxBind
[TyCon -> AuxBindSpec
DerivCon2Tag TyCon
tycon, TyCon -> AuxBindSpec
DerivTag2Con TyCon
tycon, TyCon -> AuxBindSpec
DerivMaxTag TyCon
tycon]
occ_nm :: String
occ_nm = TyCon -> String
forall a. NamedThing a => a -> String
getOccString TyCon
tycon
succ_enum :: DynFlags -> LHsBind GhcPs
succ_enum dflags :: DynFlags
dflags
= SrcSpan
-> RdrName -> [LPat GhcPs] -> LHsExpr GhcPs -> LHsBind GhcPs
mk_easy_FunBind SrcSpan
loc RdrName
succ_RDR [LPat GhcPs
a_Pat] (LHsExpr GhcPs -> LHsBind GhcPs) -> LHsExpr GhcPs -> LHsBind GhcPs
forall a b. (a -> b) -> a -> b
$
DynFlags
-> TyCon -> [(RdrName, RdrName)] -> LHsExpr GhcPs -> LHsExpr GhcPs
untag_Expr DynFlags
dflags TyCon
tycon [(RdrName
a_RDR, RdrName
ah_RDR)] (LHsExpr GhcPs -> LHsExpr GhcPs) -> LHsExpr GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$
LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
nlHsIf (IdP GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP GhcPs
eq_RDR [IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar (DynFlags -> TyCon -> RdrName
maxtag_RDR DynFlags
dflags TyCon
tycon),
IdP GhcPs -> [IdP GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsVarApps RdrName
IdP GhcPs
intDataCon_RDR [RdrName
IdP GhcPs
ah_RDR]])
(String -> String -> String -> LHsExpr GhcPs
illegal_Expr "succ" String
occ_nm "tried to take `succ' of last tag in enumeration")
(LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar (DynFlags -> TyCon -> RdrName
tag2con_RDR DynFlags
dflags TyCon
tycon))
(IdP GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP GhcPs
plus_RDR [IdP GhcPs -> [IdP GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsVarApps RdrName
IdP GhcPs
intDataCon_RDR [RdrName
IdP GhcPs
ah_RDR],
Integer -> LHsExpr GhcPs
forall (p :: Pass). Integer -> LHsExpr (GhcPass p)
nlHsIntLit 1]))
pred_enum :: DynFlags -> LHsBind GhcPs
pred_enum dflags :: DynFlags
dflags
= SrcSpan
-> RdrName -> [LPat GhcPs] -> LHsExpr GhcPs -> LHsBind GhcPs
mk_easy_FunBind SrcSpan
loc RdrName
pred_RDR [LPat GhcPs
a_Pat] (LHsExpr GhcPs -> LHsBind GhcPs) -> LHsExpr GhcPs -> LHsBind GhcPs
forall a b. (a -> b) -> a -> b
$
DynFlags
-> TyCon -> [(RdrName, RdrName)] -> LHsExpr GhcPs -> LHsExpr GhcPs
untag_Expr DynFlags
dflags TyCon
tycon [(RdrName
a_RDR, RdrName
ah_RDR)] (LHsExpr GhcPs -> LHsExpr GhcPs) -> LHsExpr GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$
LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
nlHsIf (IdP GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP GhcPs
eq_RDR [Integer -> LHsExpr GhcPs
forall (p :: Pass). Integer -> LHsExpr (GhcPass p)
nlHsIntLit 0,
IdP GhcPs -> [IdP GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsVarApps RdrName
IdP GhcPs
intDataCon_RDR [RdrName
IdP GhcPs
ah_RDR]])
(String -> String -> String -> LHsExpr GhcPs
illegal_Expr "pred" String
occ_nm "tried to take `pred' of first tag in enumeration")
(LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar (DynFlags -> TyCon -> RdrName
tag2con_RDR DynFlags
dflags TyCon
tycon))
(IdP GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP GhcPs
plus_RDR
[ IdP GhcPs -> [IdP GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsVarApps RdrName
IdP GhcPs
intDataCon_RDR [RdrName
IdP GhcPs
ah_RDR]
, HsLit GhcPs -> LHsExpr GhcPs
forall (p :: Pass). HsLit (GhcPass p) -> LHsExpr (GhcPass p)
nlHsLit (XHsInt GhcPs -> IntegralLit -> HsLit GhcPs
forall x. XHsInt x -> IntegralLit -> HsLit x
HsInt XHsInt GhcPs
NoExt
noExt
(Int -> IntegralLit
forall a. Integral a => a -> IntegralLit
mkIntegralLit (-1 :: Int)))]))
to_enum :: DynFlags -> LHsBind GhcPs
to_enum dflags :: DynFlags
dflags
= SrcSpan
-> RdrName -> [LPat GhcPs] -> LHsExpr GhcPs -> LHsBind GhcPs
mk_easy_FunBind SrcSpan
loc RdrName
toEnum_RDR [LPat GhcPs
a_Pat] (LHsExpr GhcPs -> LHsBind GhcPs) -> LHsExpr GhcPs -> LHsBind GhcPs
forall a b. (a -> b) -> a -> b
$
LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
nlHsIf (IdP GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP GhcPs
and_RDR
[IdP GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP GhcPs
ge_RDR [IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
a_RDR, Integer -> LHsExpr GhcPs
forall (p :: Pass). Integer -> LHsExpr (GhcPass p)
nlHsIntLit 0],
IdP GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP GhcPs
le_RDR [ IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
a_RDR
, IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar (DynFlags -> TyCon -> RdrName
maxtag_RDR DynFlags
dflags TyCon
tycon)]])
(IdP GhcPs -> [IdP GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsVarApps (DynFlags -> TyCon -> RdrName
tag2con_RDR DynFlags
dflags TyCon
tycon) [RdrName
IdP GhcPs
a_RDR])
(String -> RdrName -> LHsExpr GhcPs
illegal_toEnum_tag String
occ_nm (DynFlags -> TyCon -> RdrName
maxtag_RDR DynFlags
dflags TyCon
tycon))
enum_from :: DynFlags -> LHsBind GhcPs
enum_from dflags :: DynFlags
dflags
= SrcSpan
-> RdrName -> [LPat GhcPs] -> LHsExpr GhcPs -> LHsBind GhcPs
mk_easy_FunBind SrcSpan
loc RdrName
enumFrom_RDR [LPat GhcPs
a_Pat] (LHsExpr GhcPs -> LHsBind GhcPs) -> LHsExpr GhcPs -> LHsBind GhcPs
forall a b. (a -> b) -> a -> b
$
DynFlags
-> TyCon -> [(RdrName, RdrName)] -> LHsExpr GhcPs -> LHsExpr GhcPs
untag_Expr DynFlags
dflags TyCon
tycon [(RdrName
a_RDR, RdrName
ah_RDR)] (LHsExpr GhcPs -> LHsExpr GhcPs) -> LHsExpr GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$
IdP GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP GhcPs
map_RDR
[IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar (DynFlags -> TyCon -> RdrName
tag2con_RDR DynFlags
dflags TyCon
tycon),
LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass). LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsPar (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
enum_from_to_Expr
(IdP GhcPs -> [IdP GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsVarApps RdrName
IdP GhcPs
intDataCon_RDR [RdrName
IdP GhcPs
ah_RDR])
(IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar (DynFlags -> TyCon -> RdrName
maxtag_RDR DynFlags
dflags TyCon
tycon)))]
enum_from_then :: DynFlags -> LHsBind GhcPs
enum_from_then dflags :: DynFlags
dflags
= SrcSpan
-> RdrName -> [LPat GhcPs] -> LHsExpr GhcPs -> LHsBind GhcPs
mk_easy_FunBind SrcSpan
loc RdrName
enumFromThen_RDR [LPat GhcPs
a_Pat, LPat GhcPs
b_Pat] (LHsExpr GhcPs -> LHsBind GhcPs) -> LHsExpr GhcPs -> LHsBind GhcPs
forall a b. (a -> b) -> a -> b
$
DynFlags
-> TyCon -> [(RdrName, RdrName)] -> LHsExpr GhcPs -> LHsExpr GhcPs
untag_Expr DynFlags
dflags TyCon
tycon [(RdrName
a_RDR, RdrName
ah_RDR), (RdrName
b_RDR, RdrName
bh_RDR)] (LHsExpr GhcPs -> LHsExpr GhcPs) -> LHsExpr GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$
LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> [IdP GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsVarApps RdrName
IdP GhcPs
map_RDR [DynFlags -> TyCon -> RdrName
tag2con_RDR DynFlags
dflags TyCon
tycon]) (LHsExpr GhcPs -> LHsExpr GhcPs) -> LHsExpr GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$
LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass). LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsPar (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
enum_from_then_to_Expr
(IdP GhcPs -> [IdP GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsVarApps RdrName
IdP GhcPs
intDataCon_RDR [RdrName
IdP GhcPs
ah_RDR])
(IdP GhcPs -> [IdP GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsVarApps RdrName
IdP GhcPs
intDataCon_RDR [RdrName
IdP GhcPs
bh_RDR])
(LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id)
nlHsIf (IdP GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP GhcPs
gt_RDR [IdP GhcPs -> [IdP GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsVarApps RdrName
IdP GhcPs
intDataCon_RDR [RdrName
IdP GhcPs
ah_RDR],
IdP GhcPs -> [IdP GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsVarApps RdrName
IdP GhcPs
intDataCon_RDR [RdrName
IdP GhcPs
bh_RDR]])
(Integer -> LHsExpr GhcPs
forall (p :: Pass). Integer -> LHsExpr (GhcPass p)
nlHsIntLit 0)
(IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar (DynFlags -> TyCon -> RdrName
maxtag_RDR DynFlags
dflags TyCon
tycon))
))
from_enum :: DynFlags -> LHsBind GhcPs
from_enum dflags :: DynFlags
dflags
= SrcSpan
-> RdrName -> [LPat GhcPs] -> LHsExpr GhcPs -> LHsBind GhcPs
mk_easy_FunBind SrcSpan
loc RdrName
fromEnum_RDR [LPat GhcPs
a_Pat] (LHsExpr GhcPs -> LHsBind GhcPs) -> LHsExpr GhcPs -> LHsBind GhcPs
forall a b. (a -> b) -> a -> b
$
DynFlags
-> TyCon -> [(RdrName, RdrName)] -> LHsExpr GhcPs -> LHsExpr GhcPs
untag_Expr DynFlags
dflags TyCon
tycon [(RdrName
a_RDR, RdrName
ah_RDR)] (LHsExpr GhcPs -> LHsExpr GhcPs) -> LHsExpr GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$
(IdP GhcPs -> [IdP GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsVarApps RdrName
IdP GhcPs
intDataCon_RDR [RdrName
IdP GhcPs
ah_RDR])
gen_Bounded_binds :: SrcSpan -> TyCon -> (LHsBinds GhcPs, BagDerivStuff)
gen_Bounded_binds :: SrcSpan -> TyCon -> (LHsBinds GhcPs, BagDerivStuff)
gen_Bounded_binds loc :: SrcSpan
loc tycon :: TyCon
tycon
| TyCon -> Bool
isEnumerationTyCon TyCon
tycon
= ([LHsBind GhcPs] -> LHsBinds GhcPs
forall a. [a] -> Bag a
listToBag [ LHsBind GhcPs
min_bound_enum, LHsBind GhcPs
max_bound_enum ], BagDerivStuff
forall a. Bag a
emptyBag)
| Bool
otherwise
= ASSERT(isSingleton data_cons)
([LHsBind GhcPs] -> LHsBinds GhcPs
forall a. [a] -> Bag a
listToBag [ LHsBind GhcPs
min_bound_1con, LHsBind GhcPs
max_bound_1con ], BagDerivStuff
forall a. Bag a
emptyBag)
where
data_cons :: [DataCon]
data_cons = TyCon -> [DataCon]
tyConDataCons TyCon
tycon
min_bound_enum :: LHsBind GhcPs
min_bound_enum = SrcSpan -> RdrName -> LHsExpr GhcPs -> LHsBind GhcPs
mkHsVarBind SrcSpan
loc RdrName
minBound_RDR (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
data_con_1_RDR)
max_bound_enum :: LHsBind GhcPs
max_bound_enum = SrcSpan -> RdrName -> LHsExpr GhcPs -> LHsBind GhcPs
mkHsVarBind SrcSpan
loc RdrName
maxBound_RDR (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
data_con_N_RDR)
data_con_1 :: DataCon
data_con_1 = [DataCon] -> DataCon
forall a. [a] -> a
head [DataCon]
data_cons
data_con_N :: DataCon
data_con_N = [DataCon] -> DataCon
forall a. [a] -> a
last [DataCon]
data_cons
data_con_1_RDR :: RdrName
data_con_1_RDR = DataCon -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName DataCon
data_con_1
data_con_N_RDR :: RdrName
data_con_N_RDR = DataCon -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName DataCon
data_con_N
arity :: Int
arity = DataCon -> Int
dataConSourceArity DataCon
data_con_1
min_bound_1con :: LHsBind GhcPs
min_bound_1con = SrcSpan -> RdrName -> LHsExpr GhcPs -> LHsBind GhcPs
mkHsVarBind SrcSpan
loc RdrName
minBound_RDR (LHsExpr GhcPs -> LHsBind GhcPs) -> LHsExpr GhcPs -> LHsBind GhcPs
forall a b. (a -> b) -> a -> b
$
IdP GhcPs -> [IdP GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsVarApps RdrName
IdP GhcPs
data_con_1_RDR (Int -> RdrName -> [RdrName]
forall a. Int -> a -> [a]
nOfThem Int
arity RdrName
minBound_RDR)
max_bound_1con :: LHsBind GhcPs
max_bound_1con = SrcSpan -> RdrName -> LHsExpr GhcPs -> LHsBind GhcPs
mkHsVarBind SrcSpan
loc RdrName
maxBound_RDR (LHsExpr GhcPs -> LHsBind GhcPs) -> LHsExpr GhcPs -> LHsBind GhcPs
forall a b. (a -> b) -> a -> b
$
IdP GhcPs -> [IdP GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsVarApps RdrName
IdP GhcPs
data_con_1_RDR (Int -> RdrName -> [RdrName]
forall a. Int -> a -> [a]
nOfThem Int
arity RdrName
maxBound_RDR)
gen_Ix_binds :: SrcSpan -> TyCon -> TcM (LHsBinds GhcPs, BagDerivStuff)
gen_Ix_binds :: SrcSpan -> TyCon -> TcM (LHsBinds GhcPs, BagDerivStuff)
gen_Ix_binds loc :: SrcSpan
loc tycon :: TyCon
tycon = do
DynFlags
dflags <- IOEnv (Env TcGblEnv TcLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
(LHsBinds GhcPs, BagDerivStuff)
-> TcM (LHsBinds GhcPs, BagDerivStuff)
forall (m :: * -> *) a. Monad m => a -> m a
return ((LHsBinds GhcPs, BagDerivStuff)
-> TcM (LHsBinds GhcPs, BagDerivStuff))
-> (LHsBinds GhcPs, BagDerivStuff)
-> TcM (LHsBinds GhcPs, BagDerivStuff)
forall a b. (a -> b) -> a -> b
$ if TyCon -> Bool
isEnumerationTyCon TyCon
tycon
then (DynFlags -> LHsBinds GhcPs
enum_ixes DynFlags
dflags, [DerivStuff] -> BagDerivStuff
forall a. [a] -> Bag a
listToBag ([DerivStuff] -> BagDerivStuff) -> [DerivStuff] -> BagDerivStuff
forall a b. (a -> b) -> a -> b
$ (AuxBindSpec -> DerivStuff) -> [AuxBindSpec] -> [DerivStuff]
forall a b. (a -> b) -> [a] -> [b]
map AuxBindSpec -> DerivStuff
DerivAuxBind
[TyCon -> AuxBindSpec
DerivCon2Tag TyCon
tycon, TyCon -> AuxBindSpec
DerivTag2Con TyCon
tycon, TyCon -> AuxBindSpec
DerivMaxTag TyCon
tycon])
else (LHsBinds GhcPs
single_con_ixes, DerivStuff -> BagDerivStuff
forall a. a -> Bag a
unitBag (AuxBindSpec -> DerivStuff
DerivAuxBind (TyCon -> AuxBindSpec
DerivCon2Tag TyCon
tycon)))
where
enum_ixes :: DynFlags -> LHsBinds GhcPs
enum_ixes dflags :: DynFlags
dflags = [LHsBind GhcPs] -> LHsBinds GhcPs
forall a. [a] -> Bag a
listToBag
[ DynFlags -> LHsBind GhcPs
enum_range DynFlags
dflags
, DynFlags -> LHsBind GhcPs
enum_index DynFlags
dflags
, DynFlags -> LHsBind GhcPs
enum_inRange DynFlags
dflags
]
enum_range :: DynFlags -> LHsBind GhcPs
enum_range dflags :: DynFlags
dflags
= SrcSpan
-> RdrName -> [LPat GhcPs] -> LHsExpr GhcPs -> LHsBind GhcPs
mk_easy_FunBind SrcSpan
loc RdrName
range_RDR [[LPat GhcPs] -> Boxity -> LPat GhcPs
nlTuplePat [LPat GhcPs
a_Pat, LPat GhcPs
b_Pat] Boxity
Boxed] (LHsExpr GhcPs -> LHsBind GhcPs) -> LHsExpr GhcPs -> LHsBind GhcPs
forall a b. (a -> b) -> a -> b
$
DynFlags
-> TyCon -> [(RdrName, RdrName)] -> LHsExpr GhcPs -> LHsExpr GhcPs
untag_Expr DynFlags
dflags TyCon
tycon [(RdrName
a_RDR, RdrName
ah_RDR)] (LHsExpr GhcPs -> LHsExpr GhcPs) -> LHsExpr GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$
DynFlags
-> TyCon -> [(RdrName, RdrName)] -> LHsExpr GhcPs -> LHsExpr GhcPs
untag_Expr DynFlags
dflags TyCon
tycon [(RdrName
b_RDR, RdrName
bh_RDR)] (LHsExpr GhcPs -> LHsExpr GhcPs) -> LHsExpr GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$
LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> [IdP GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsVarApps RdrName
IdP GhcPs
map_RDR [DynFlags -> TyCon -> RdrName
tag2con_RDR DynFlags
dflags TyCon
tycon]) (LHsExpr GhcPs -> LHsExpr GhcPs) -> LHsExpr GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$
LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass). LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsPar (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
enum_from_to_Expr
(IdP GhcPs -> [IdP GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsVarApps RdrName
IdP GhcPs
intDataCon_RDR [RdrName
IdP GhcPs
ah_RDR])
(IdP GhcPs -> [IdP GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsVarApps RdrName
IdP GhcPs
intDataCon_RDR [RdrName
IdP GhcPs
bh_RDR]))
enum_index :: DynFlags -> LHsBind GhcPs
enum_index dflags :: DynFlags
dflags
= SrcSpan
-> RdrName -> [LPat GhcPs] -> LHsExpr GhcPs -> LHsBind GhcPs
mk_easy_FunBind SrcSpan
loc RdrName
unsafeIndex_RDR
[SrcSpanLess (LPat GhcPs) -> LPat GhcPs
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc (XAsPat GhcPs -> Located (IdP GhcPs) -> LPat GhcPs -> LPat GhcPs
forall p. XAsPat p -> Located (IdP p) -> Pat p -> Pat p
AsPat XAsPat GhcPs
NoExt
noExt (SrcSpanLess (Located RdrName) -> Located RdrName
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc SrcSpanLess (Located RdrName)
RdrName
c_RDR)
([LPat GhcPs] -> Boxity -> LPat GhcPs
nlTuplePat [LPat GhcPs
a_Pat, LPat GhcPs
nlWildPat] Boxity
Boxed)),
LPat GhcPs
d_Pat] (
DynFlags
-> TyCon -> [(RdrName, RdrName)] -> LHsExpr GhcPs -> LHsExpr GhcPs
untag_Expr DynFlags
dflags TyCon
tycon [(RdrName
a_RDR, RdrName
ah_RDR)] (
DynFlags
-> TyCon -> [(RdrName, RdrName)] -> LHsExpr GhcPs -> LHsExpr GhcPs
untag_Expr DynFlags
dflags TyCon
tycon [(RdrName
d_RDR, RdrName
dh_RDR)] (
let
rhs :: LHsExpr GhcPs
rhs = IdP GhcPs -> [IdP GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsVarApps RdrName
IdP GhcPs
intDataCon_RDR [RdrName
IdP GhcPs
c_RDR]
in
LHsExpr GhcPs -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsExpr GhcPs
nlHsCase
(LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs -> LHsExpr GhcPs
genOpApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
dh_RDR) RdrName
minusInt_RDR (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
ah_RDR))
[LPat GhcPs -> LHsExpr GhcPs -> LMatch GhcPs (LHsExpr GhcPs)
forall (p :: Pass) (body :: * -> *).
LPat (GhcPass p)
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkHsCaseAlt (IdP GhcPs -> LPat GhcPs
forall (p :: Pass). IdP (GhcPass p) -> LPat (GhcPass p)
nlVarPat RdrName
IdP GhcPs
c_RDR) LHsExpr GhcPs
rhs]
))
)
enum_inRange :: DynFlags -> LHsBind GhcPs
enum_inRange dflags :: DynFlags
dflags
= SrcSpan
-> RdrName -> [LPat GhcPs] -> LHsExpr GhcPs -> LHsBind GhcPs
mk_easy_FunBind SrcSpan
loc RdrName
inRange_RDR [[LPat GhcPs] -> Boxity -> LPat GhcPs
nlTuplePat [LPat GhcPs
a_Pat, LPat GhcPs
b_Pat] Boxity
Boxed, LPat GhcPs
c_Pat] (LHsExpr GhcPs -> LHsBind GhcPs) -> LHsExpr GhcPs -> LHsBind GhcPs
forall a b. (a -> b) -> a -> b
$
DynFlags
-> TyCon -> [(RdrName, RdrName)] -> LHsExpr GhcPs -> LHsExpr GhcPs
untag_Expr DynFlags
dflags TyCon
tycon [(RdrName
a_RDR, RdrName
ah_RDR)] (
DynFlags
-> TyCon -> [(RdrName, RdrName)] -> LHsExpr GhcPs -> LHsExpr GhcPs
untag_Expr DynFlags
dflags TyCon
tycon [(RdrName
b_RDR, RdrName
bh_RDR)] (
DynFlags
-> TyCon -> [(RdrName, RdrName)] -> LHsExpr GhcPs -> LHsExpr GhcPs
untag_Expr DynFlags
dflags TyCon
tycon [(RdrName
c_RDR, RdrName
ch_RDR)] (
IdP GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP GhcPs
and_RDR
[ LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs -> LHsExpr GhcPs
genPrimOpApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
ch_RDR) RdrName
geInt_RDR (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
ah_RDR)
, LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs -> LHsExpr GhcPs
genPrimOpApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
ch_RDR) RdrName
leInt_RDR (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
bh_RDR)
]
)))
single_con_ixes :: LHsBinds GhcPs
single_con_ixes
= [LHsBind GhcPs] -> LHsBinds GhcPs
forall a. [a] -> Bag a
listToBag [LHsBind GhcPs
single_con_range, LHsBind GhcPs
single_con_index, LHsBind GhcPs
single_con_inRange]
data_con :: DataCon
data_con
= case TyCon -> Maybe DataCon
tyConSingleDataCon_maybe TyCon
tycon of
Nothing -> String -> DataCon
forall a. String -> a
panic "get_Ix_binds"
Just dc :: DataCon
dc -> DataCon
dc
con_arity :: Int
con_arity = DataCon -> Int
dataConSourceArity DataCon
data_con
data_con_RDR :: RdrName
data_con_RDR = DataCon -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName DataCon
data_con
as_needed :: [RdrName]
as_needed = Int -> [RdrName] -> [RdrName]
forall a. Int -> [a] -> [a]
take Int
con_arity [RdrName]
as_RDRs
bs_needed :: [RdrName]
bs_needed = Int -> [RdrName] -> [RdrName]
forall a. Int -> [a] -> [a]
take Int
con_arity [RdrName]
bs_RDRs
cs_needed :: [RdrName]
cs_needed = Int -> [RdrName] -> [RdrName]
forall a. Int -> [a] -> [a]
take Int
con_arity [RdrName]
cs_RDRs
con_pat :: [RdrName] -> LPat GhcPs
con_pat xs :: [RdrName]
xs = RdrName -> [RdrName] -> LPat GhcPs
nlConVarPat RdrName
data_con_RDR [RdrName]
xs
con_expr :: LHsExpr GhcPs
con_expr = IdP GhcPs -> [IdP GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsVarApps RdrName
IdP GhcPs
data_con_RDR [RdrName]
[IdP GhcPs]
cs_needed
single_con_range :: LHsBind GhcPs
single_con_range
= SrcSpan
-> RdrName -> [LPat GhcPs] -> LHsExpr GhcPs -> LHsBind GhcPs
mk_easy_FunBind SrcSpan
loc RdrName
range_RDR
[[LPat GhcPs] -> Boxity -> LPat GhcPs
nlTuplePat [[RdrName] -> LPat GhcPs
con_pat [RdrName]
as_needed, [RdrName] -> LPat GhcPs
con_pat [RdrName]
bs_needed] Boxity
Boxed] (LHsExpr GhcPs -> LHsBind GhcPs) -> LHsExpr GhcPs -> LHsBind GhcPs
forall a b. (a -> b) -> a -> b
$
SrcSpanLess (LHsExpr GhcPs) -> LHsExpr GhcPs
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc (HsStmtContext Name
-> [ExprLStmt GhcPs] -> LHsExpr GhcPs -> HsExpr GhcPs
mkHsComp HsStmtContext Name
forall id. HsStmtContext id
ListComp [ExprLStmt GhcPs]
stmts LHsExpr GhcPs
con_expr)
where
stmts :: [ExprLStmt GhcPs]
stmts = String
-> (RdrName -> RdrName -> RdrName -> ExprLStmt GhcPs)
-> [RdrName]
-> [RdrName]
-> [RdrName]
-> [ExprLStmt GhcPs]
forall a b c d.
String -> (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
zipWith3Equal "single_con_range" RdrName -> RdrName -> RdrName -> ExprLStmt GhcPs
forall a (idL :: Pass) (idR :: Pass).
(HasSrcSpan a,
XBindStmt
(GhcPass idL) (GhcPass idR) (Located (HsExpr (GhcPass idR)))
~ NoExt,
IdP (GhcPass idR) ~ RdrName,
SrcSpanLess a
~ StmtLR
(GhcPass idL) (GhcPass idR) (Located (HsExpr (GhcPass idR)))) =>
RdrName -> RdrName -> IdP (GhcPass idL) -> a
mk_qual [RdrName]
as_needed [RdrName]
bs_needed [RdrName]
cs_needed
mk_qual :: RdrName -> RdrName -> IdP (GhcPass idL) -> a
mk_qual a :: RdrName
a b :: RdrName
b c :: IdP (GhcPass idL)
c = SrcSpanLess a -> a
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc (SrcSpanLess a -> a) -> SrcSpanLess a -> a
forall a b. (a -> b) -> a -> b
$ LPat (GhcPass idL)
-> Located (HsExpr (GhcPass idR))
-> StmtLR
(GhcPass idL) (GhcPass idR) (Located (HsExpr (GhcPass idR)))
forall (idL :: Pass) (idR :: Pass) (bodyR :: * -> *).
(XBindStmt
(GhcPass idL) (GhcPass idR) (Located (bodyR (GhcPass idR)))
~ NoExt) =>
LPat (GhcPass idL)
-> Located (bodyR (GhcPass idR))
-> StmtLR
(GhcPass idL) (GhcPass idR) (Located (bodyR (GhcPass idR)))
mkBindStmt (IdP (GhcPass idL) -> LPat (GhcPass idL)
forall (p :: Pass). IdP (GhcPass p) -> LPat (GhcPass p)
nlVarPat IdP (GhcPass idL)
c)
(Located (HsExpr (GhcPass idR))
-> Located (HsExpr (GhcPass idR)) -> Located (HsExpr (GhcPass idR))
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP (GhcPass idR) -> Located (HsExpr (GhcPass idR))
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP (GhcPass idR)
range_RDR)
([IdP (GhcPass idR)] -> Located (HsExpr (GhcPass idR))
forall (a :: Pass). [IdP (GhcPass a)] -> LHsExpr (GhcPass a)
mkLHsVarTuple [RdrName
IdP (GhcPass idR)
a,RdrName
IdP (GhcPass idR)
b]))
single_con_index :: LHsBind GhcPs
single_con_index
= SrcSpan
-> RdrName -> [LPat GhcPs] -> LHsExpr GhcPs -> LHsBind GhcPs
mk_easy_FunBind SrcSpan
loc RdrName
unsafeIndex_RDR
[[LPat GhcPs] -> Boxity -> LPat GhcPs
nlTuplePat [[RdrName] -> LPat GhcPs
con_pat [RdrName]
as_needed, [RdrName] -> LPat GhcPs
con_pat [RdrName]
bs_needed] Boxity
Boxed,
[RdrName] -> LPat GhcPs
con_pat [RdrName]
cs_needed]
([(RdrName, RdrName, RdrName)] -> LHsExpr GhcPs
mk_index ([(RdrName, RdrName, RdrName)] -> [(RdrName, RdrName, RdrName)]
forall a. [a] -> [a]
reverse ([(RdrName, RdrName, RdrName)] -> [(RdrName, RdrName, RdrName)])
-> [(RdrName, RdrName, RdrName)] -> [(RdrName, RdrName, RdrName)]
forall a b. (a -> b) -> a -> b
$ [RdrName]
-> [RdrName] -> [RdrName] -> [(RdrName, RdrName, RdrName)]
forall a b c. [a] -> [b] -> [c] -> [(a, b, c)]
zip3 [RdrName]
as_needed [RdrName]
bs_needed [RdrName]
cs_needed))
where
mk_index :: [(RdrName, RdrName, RdrName)] -> LHsExpr GhcPs
mk_index [] = Integer -> LHsExpr GhcPs
forall (p :: Pass). Integer -> LHsExpr (GhcPass p)
nlHsIntLit 0
mk_index [(l :: RdrName
l,u :: RdrName
u,i :: RdrName
i)] = RdrName -> RdrName -> RdrName -> LHsExpr GhcPs
forall (id :: Pass).
(IdP (GhcPass id) ~ RdrName) =>
RdrName -> RdrName -> RdrName -> LHsExpr (GhcPass id)
mk_one RdrName
l RdrName
u RdrName
i
mk_index ((l :: RdrName
l,u :: RdrName
u,i :: RdrName
i) : rest :: [(RdrName, RdrName, RdrName)]
rest)
= LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs -> LHsExpr GhcPs
genOpApp (
RdrName -> RdrName -> RdrName -> LHsExpr GhcPs
forall (id :: Pass).
(IdP (GhcPass id) ~ RdrName) =>
RdrName -> RdrName -> RdrName -> LHsExpr (GhcPass id)
mk_one RdrName
l RdrName
u RdrName
i
) RdrName
plus_RDR (
LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs -> LHsExpr GhcPs
genOpApp (
(LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
unsafeRangeSize_RDR)
([IdP GhcPs] -> LHsExpr GhcPs
forall (a :: Pass). [IdP (GhcPass a)] -> LHsExpr (GhcPass a)
mkLHsVarTuple [RdrName
IdP GhcPs
l,RdrName
IdP GhcPs
u]))
) RdrName
times_RDR ([(RdrName, RdrName, RdrName)] -> LHsExpr GhcPs
mk_index [(RdrName, RdrName, RdrName)]
rest)
)
mk_one :: RdrName -> RdrName -> RdrName -> LHsExpr (GhcPass id)
mk_one l :: RdrName
l u :: RdrName
u i :: RdrName
i
= IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP (GhcPass id)
unsafeIndex_RDR [[IdP (GhcPass id)] -> LHsExpr (GhcPass id)
forall (a :: Pass). [IdP (GhcPass a)] -> LHsExpr (GhcPass a)
mkLHsVarTuple [RdrName
IdP (GhcPass id)
l,RdrName
IdP (GhcPass id)
u], IdP (GhcPass id) -> LHsExpr (GhcPass id)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP (GhcPass id)
i]
single_con_inRange :: LHsBind GhcPs
single_con_inRange
= SrcSpan
-> RdrName -> [LPat GhcPs] -> LHsExpr GhcPs -> LHsBind GhcPs
mk_easy_FunBind SrcSpan
loc RdrName
inRange_RDR
[[LPat GhcPs] -> Boxity -> LPat GhcPs
nlTuplePat [[RdrName] -> LPat GhcPs
con_pat [RdrName]
as_needed, [RdrName] -> LPat GhcPs
con_pat [RdrName]
bs_needed] Boxity
Boxed,
[RdrName] -> LPat GhcPs
con_pat [RdrName]
cs_needed] (LHsExpr GhcPs -> LHsBind GhcPs) -> LHsExpr GhcPs -> LHsBind GhcPs
forall a b. (a -> b) -> a -> b
$
if Int
con_arity Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 0
then LHsExpr GhcPs
true_Expr
else (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs)
-> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldl1 LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
and_Expr (String
-> (RdrName -> RdrName -> RdrName -> LHsExpr GhcPs)
-> [RdrName]
-> [RdrName]
-> [RdrName]
-> [LHsExpr GhcPs]
forall a b c d.
String -> (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
zipWith3Equal "single_con_inRange" RdrName -> RdrName -> RdrName -> LHsExpr GhcPs
forall (id :: Pass).
(IdP (GhcPass id) ~ RdrName) =>
RdrName -> RdrName -> RdrName -> LHsExpr (GhcPass id)
in_range
[RdrName]
as_needed [RdrName]
bs_needed [RdrName]
cs_needed)
where
in_range :: RdrName -> RdrName -> RdrName -> LHsExpr (GhcPass id)
in_range a :: RdrName
a b :: RdrName
b c :: RdrName
c = IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP (GhcPass id)
inRange_RDR [[IdP (GhcPass id)] -> LHsExpr (GhcPass id)
forall (a :: Pass). [IdP (GhcPass a)] -> LHsExpr (GhcPass a)
mkLHsVarTuple [RdrName
IdP (GhcPass id)
a,RdrName
IdP (GhcPass id)
b], IdP (GhcPass id) -> LHsExpr (GhcPass id)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP (GhcPass id)
c]
gen_Read_binds :: (Name -> Fixity) -> SrcSpan -> TyCon
-> (LHsBinds GhcPs, BagDerivStuff)
gen_Read_binds :: (Name -> Fixity)
-> SrcSpan -> TyCon -> (LHsBinds GhcPs, BagDerivStuff)
gen_Read_binds get_fixity :: Name -> Fixity
get_fixity loc :: SrcSpan
loc tycon :: TyCon
tycon
= ([LHsBind GhcPs] -> LHsBinds GhcPs
forall a. [a] -> Bag a
listToBag [LHsBind GhcPs
read_prec, LHsBind GhcPs
default_readlist, LHsBind GhcPs
default_readlistprec], BagDerivStuff
forall a. Bag a
emptyBag)
where
default_readlist :: LHsBind GhcPs
default_readlist
= SrcSpan -> RdrName -> LHsExpr GhcPs -> LHsBind GhcPs
mkHsVarBind SrcSpan
loc RdrName
readList_RDR (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
readListDefault_RDR)
default_readlistprec :: LHsBind GhcPs
default_readlistprec
= SrcSpan -> RdrName -> LHsExpr GhcPs -> LHsBind GhcPs
mkHsVarBind SrcSpan
loc RdrName
readListPrec_RDR (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
readListPrecDefault_RDR)
data_cons :: [DataCon]
data_cons = TyCon -> [DataCon]
tyConDataCons TyCon
tycon
(nullary_cons :: [DataCon]
nullary_cons, non_nullary_cons :: [DataCon]
non_nullary_cons) = (DataCon -> Bool) -> [DataCon] -> ([DataCon], [DataCon])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition DataCon -> Bool
isNullarySrcDataCon [DataCon]
data_cons
read_prec :: LHsBind GhcPs
read_prec = SrcSpan -> RdrName -> LHsExpr GhcPs -> LHsBind GhcPs
mkHsVarBind SrcSpan
loc RdrName
readPrec_RDR LHsExpr GhcPs
rhs
where
rhs :: LHsExpr GhcPs
rhs | [DataCon] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [DataCon]
data_cons
= IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
pfail_RDR
| Bool
otherwise
= LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
parens_RDR)
((LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs)
-> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldr1 LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
mk_alt ([LHsExpr GhcPs]
read_nullary_cons [LHsExpr GhcPs] -> [LHsExpr GhcPs] -> [LHsExpr GhcPs]
forall a. [a] -> [a] -> [a]
++
[LHsExpr GhcPs]
read_non_nullary_cons))
read_non_nullary_cons :: [LHsExpr GhcPs]
read_non_nullary_cons = (DataCon -> LHsExpr GhcPs) -> [DataCon] -> [LHsExpr GhcPs]
forall a b. (a -> b) -> [a] -> [b]
map DataCon -> LHsExpr GhcPs
read_non_nullary_con [DataCon]
non_nullary_cons
read_nullary_cons :: [LHsExpr GhcPs]
read_nullary_cons
= case [DataCon]
nullary_cons of
[] -> []
[con :: DataCon
con] -> [HsStmtContext Name -> [ExprLStmt GhcPs] -> LHsExpr GhcPs
nlHsDo HsStmtContext Name
forall id. HsStmtContext id
DoExpr (DataCon -> [ExprLStmt GhcPs]
forall a a (idL :: Pass).
(NamedThing a, HasSrcSpan a,
SrcSpanLess a ~ StmtLR (GhcPass idL) GhcPs (LHsExpr GhcPs)) =>
a -> [a]
match_con DataCon
con [ExprLStmt GhcPs] -> [ExprLStmt GhcPs] -> [ExprLStmt GhcPs]
forall a. [a] -> [a] -> [a]
++ [SrcSpanLess (ExprLStmt GhcPs) -> ExprLStmt GhcPs
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc (SrcSpanLess (ExprLStmt GhcPs) -> ExprLStmt GhcPs)
-> SrcSpanLess (ExprLStmt GhcPs) -> ExprLStmt GhcPs
forall a b. (a -> b) -> a -> b
$ LHsExpr GhcPs -> StmtLR GhcPs GhcPs (LHsExpr GhcPs)
forall (bodyR :: * -> *) (idR :: Pass) (idL :: Pass).
Located (bodyR (GhcPass idR))
-> StmtLR
(GhcPass idL) (GhcPass idR) (Located (bodyR (GhcPass idR)))
mkLastStmt (DataCon -> [IdP GhcPs] -> LHsExpr GhcPs
forall thing (id :: Pass).
(NamedThing thing, IdP (GhcPass id) ~ RdrName) =>
thing -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
result_expr DataCon
con [])])]
_ -> [LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
choose_RDR)
([LHsExpr GhcPs] -> LHsExpr GhcPs
nlList ((DataCon -> LHsExpr GhcPs) -> [DataCon] -> [LHsExpr GhcPs]
forall a b. (a -> b) -> [a] -> [b]
map DataCon -> LHsExpr GhcPs
forall thing (a :: Pass).
(NamedThing thing, IdP (GhcPass a) ~ RdrName) =>
thing -> LHsExpr (GhcPass a)
mk_pair [DataCon]
nullary_cons))]
match_con :: a -> [a]
match_con con :: a
con | String -> Bool
isSym String
con_str = [String -> a
forall a (idL :: Pass).
(HasSrcSpan a,
SrcSpanLess a ~ StmtLR (GhcPass idL) GhcPs (LHsExpr GhcPs)) =>
String -> a
symbol_pat String
con_str]
| Bool
otherwise = String -> [a]
forall a (idL :: Pass).
(HasSrcSpan a,
SrcSpanLess a ~ StmtLR (GhcPass idL) GhcPs (LHsExpr GhcPs)) =>
String -> [a]
ident_h_pat String
con_str
where
con_str :: String
con_str = a -> String
forall a. NamedThing a => a -> String
data_con_str a
con
mk_pair :: thing -> LHsExpr (GhcPass a)
mk_pair con :: thing
con = [LHsExpr (GhcPass a)] -> LHsExpr (GhcPass a)
forall (a :: Pass). [LHsExpr (GhcPass a)] -> LHsExpr (GhcPass a)
mkLHsTupleExpr [HsLit (GhcPass a) -> LHsExpr (GhcPass a)
forall (p :: Pass). HsLit (GhcPass p) -> LHsExpr (GhcPass p)
nlHsLit (String -> HsLit (GhcPass a)
forall (p :: Pass). String -> HsLit (GhcPass p)
mkHsString (thing -> String
forall a. NamedThing a => a -> String
data_con_str thing
con)),
thing -> [IdP (GhcPass a)] -> LHsExpr (GhcPass a)
forall thing (id :: Pass).
(NamedThing thing, IdP (GhcPass id) ~ RdrName) =>
thing -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
result_expr thing
con []]
read_non_nullary_con :: DataCon -> LHsExpr GhcPs
read_non_nullary_con data_con :: DataCon
data_con
| Bool
is_infix = Integer -> [ExprLStmt GhcPs] -> LHsExpr GhcPs -> LHsExpr GhcPs
mk_parser Integer
infix_prec [ExprLStmt GhcPs]
infix_stmts LHsExpr GhcPs
body
| Bool
is_record = Integer -> [ExprLStmt GhcPs] -> LHsExpr GhcPs -> LHsExpr GhcPs
mk_parser Integer
record_prec [ExprLStmt GhcPs]
record_stmts LHsExpr GhcPs
body
| Bool
otherwise = LHsExpr GhcPs
prefix_parser
where
body :: LHsExpr GhcPs
body = DataCon -> [IdP GhcPs] -> LHsExpr GhcPs
forall thing (id :: Pass).
(NamedThing thing, IdP (GhcPass id) ~ RdrName) =>
thing -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
result_expr DataCon
data_con [RdrName]
[IdP GhcPs]
as_needed
con_str :: String
con_str = DataCon -> String
forall a. NamedThing a => a -> String
data_con_str DataCon
data_con
prefix_parser :: LHsExpr GhcPs
prefix_parser = Integer -> [ExprLStmt GhcPs] -> LHsExpr GhcPs -> LHsExpr GhcPs
mk_parser Integer
prefix_prec [ExprLStmt GhcPs]
prefix_stmts LHsExpr GhcPs
body
read_prefix_con :: [ExprLStmt GhcPs]
read_prefix_con
| String -> Bool
isSym String
con_str = [String -> ExprLStmt GhcPs
forall a (idL :: Pass).
(HasSrcSpan a,
SrcSpanLess a ~ StmtLR (GhcPass idL) GhcPs (LHsExpr GhcPs)) =>
String -> a
read_punc "(", String -> ExprLStmt GhcPs
forall a (idL :: Pass).
(HasSrcSpan a,
SrcSpanLess a ~ StmtLR (GhcPass idL) GhcPs (LHsExpr GhcPs)) =>
String -> a
symbol_pat String
con_str, String -> ExprLStmt GhcPs
forall a (idL :: Pass).
(HasSrcSpan a,
SrcSpanLess a ~ StmtLR (GhcPass idL) GhcPs (LHsExpr GhcPs)) =>
String -> a
read_punc ")"]
| Bool
otherwise = String -> [ExprLStmt GhcPs]
forall a (idL :: Pass).
(HasSrcSpan a,
SrcSpanLess a ~ StmtLR (GhcPass idL) GhcPs (LHsExpr GhcPs)) =>
String -> [a]
ident_h_pat String
con_str
read_infix_con :: [ExprLStmt GhcPs]
read_infix_con
| String -> Bool
isSym String
con_str = [String -> ExprLStmt GhcPs
forall a (idL :: Pass).
(HasSrcSpan a,
SrcSpanLess a ~ StmtLR (GhcPass idL) GhcPs (LHsExpr GhcPs)) =>
String -> a
symbol_pat String
con_str]
| Bool
otherwise = [String -> ExprLStmt GhcPs
forall a (idL :: Pass).
(HasSrcSpan a,
SrcSpanLess a ~ StmtLR (GhcPass idL) GhcPs (LHsExpr GhcPs)) =>
String -> a
read_punc "`"] [ExprLStmt GhcPs] -> [ExprLStmt GhcPs] -> [ExprLStmt GhcPs]
forall a. [a] -> [a] -> [a]
++ String -> [ExprLStmt GhcPs]
forall a (idL :: Pass).
(HasSrcSpan a,
SrcSpanLess a ~ StmtLR (GhcPass idL) GhcPs (LHsExpr GhcPs)) =>
String -> [a]
ident_h_pat String
con_str [ExprLStmt GhcPs] -> [ExprLStmt GhcPs] -> [ExprLStmt GhcPs]
forall a. [a] -> [a] -> [a]
++ [String -> ExprLStmt GhcPs
forall a (idL :: Pass).
(HasSrcSpan a,
SrcSpanLess a ~ StmtLR (GhcPass idL) GhcPs (LHsExpr GhcPs)) =>
String -> a
read_punc "`"]
prefix_stmts :: [ExprLStmt GhcPs]
prefix_stmts
= [ExprLStmt GhcPs]
read_prefix_con [ExprLStmt GhcPs] -> [ExprLStmt GhcPs] -> [ExprLStmt GhcPs]
forall a. [a] -> [a] -> [a]
++ [ExprLStmt GhcPs]
read_args
infix_stmts :: [ExprLStmt GhcPs]
infix_stmts
= [ExprLStmt GhcPs
read_a1]
[ExprLStmt GhcPs] -> [ExprLStmt GhcPs] -> [ExprLStmt GhcPs]
forall a. [a] -> [a] -> [a]
++ [ExprLStmt GhcPs]
read_infix_con
[ExprLStmt GhcPs] -> [ExprLStmt GhcPs] -> [ExprLStmt GhcPs]
forall a. [a] -> [a] -> [a]
++ [ExprLStmt GhcPs
read_a2]
record_stmts :: [ExprLStmt GhcPs]
record_stmts
= [ExprLStmt GhcPs]
read_prefix_con
[ExprLStmt GhcPs] -> [ExprLStmt GhcPs] -> [ExprLStmt GhcPs]
forall a. [a] -> [a] -> [a]
++ [String -> ExprLStmt GhcPs
forall a (idL :: Pass).
(HasSrcSpan a,
SrcSpanLess a ~ StmtLR (GhcPass idL) GhcPs (LHsExpr GhcPs)) =>
String -> a
read_punc "{"]
[ExprLStmt GhcPs] -> [ExprLStmt GhcPs] -> [ExprLStmt GhcPs]
forall a. [a] -> [a] -> [a]
++ [[ExprLStmt GhcPs]] -> [ExprLStmt GhcPs]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([ExprLStmt GhcPs] -> [[ExprLStmt GhcPs]] -> [[ExprLStmt GhcPs]]
forall a. a -> [a] -> [a]
intersperse [String -> ExprLStmt GhcPs
forall a (idL :: Pass).
(HasSrcSpan a,
SrcSpanLess a ~ StmtLR (GhcPass idL) GhcPs (LHsExpr GhcPs)) =>
String -> a
read_punc ","] [[ExprLStmt GhcPs]]
field_stmts)
[ExprLStmt GhcPs] -> [ExprLStmt GhcPs] -> [ExprLStmt GhcPs]
forall a. [a] -> [a] -> [a]
++ [String -> ExprLStmt GhcPs
forall a (idL :: Pass).
(HasSrcSpan a,
SrcSpanLess a ~ StmtLR (GhcPass idL) GhcPs (LHsExpr GhcPs)) =>
String -> a
read_punc "}"]
field_stmts :: [[ExprLStmt GhcPs]]
field_stmts = String
-> (FastString -> RdrName -> [ExprLStmt GhcPs])
-> [FastString]
-> [RdrName]
-> [[ExprLStmt GhcPs]]
forall a b c. String -> (a -> b -> c) -> [a] -> [b] -> [c]
zipWithEqual "lbl_stmts" FastString -> RdrName -> [ExprLStmt GhcPs]
forall a (idR :: Pass) (idL :: Pass).
(HasSrcSpan a, IdP (GhcPass idR) ~ RdrName,
XBindStmt
(GhcPass idL) (GhcPass idR) (Located (HsExpr (GhcPass idR)))
~ NoExt,
SrcSpanLess a
~ StmtLR
(GhcPass idL) (GhcPass idR) (Located (HsExpr (GhcPass idR)))) =>
FastString -> IdP (GhcPass idL) -> [a]
read_field [FastString]
labels [RdrName]
as_needed
con_arity :: Int
con_arity = DataCon -> Int
dataConSourceArity DataCon
data_con
labels :: [FastString]
labels = (FieldLbl Name -> FastString) -> [FieldLbl Name] -> [FastString]
forall a b. (a -> b) -> [a] -> [b]
map FieldLbl Name -> FastString
forall a. FieldLbl a -> FastString
flLabel ([FieldLbl Name] -> [FastString])
-> [FieldLbl Name] -> [FastString]
forall a b. (a -> b) -> a -> b
$ DataCon -> [FieldLbl Name]
dataConFieldLabels DataCon
data_con
dc_nm :: Name
dc_nm = DataCon -> Name
forall a. NamedThing a => a -> Name
getName DataCon
data_con
is_infix :: Bool
is_infix = DataCon -> Bool
dataConIsInfix DataCon
data_con
is_record :: Bool
is_record = [FastString]
labels [FastString] -> Int -> Bool
forall a. [a] -> Int -> Bool
`lengthExceeds` 0
as_needed :: [RdrName]
as_needed = Int -> [RdrName] -> [RdrName]
forall a. Int -> [a] -> [a]
take Int
con_arity [RdrName]
as_RDRs
read_args :: [ExprLStmt GhcPs]
read_args = String
-> (RdrName -> Type -> ExprLStmt GhcPs)
-> [RdrName]
-> [Type]
-> [ExprLStmt GhcPs]
forall a b c. String -> (a -> b -> c) -> [a] -> [b] -> [c]
zipWithEqual "gen_Read_binds" RdrName -> Type -> ExprLStmt GhcPs
forall p (idL :: Pass) (idR :: Pass).
(HasSrcSpan p,
XBindStmt
(GhcPass idL) (GhcPass idR) (Located (HsExpr (GhcPass idR)))
~ NoExt,
IdP (GhcPass idR) ~ RdrName,
SrcSpanLess p
~ StmtLR
(GhcPass idL) (GhcPass idR) (Located (HsExpr (GhcPass idR)))) =>
IdP (GhcPass idL) -> Type -> p
read_arg [RdrName]
as_needed (DataCon -> [Type]
dataConOrigArgTys DataCon
data_con)
(read_a1 :: ExprLStmt GhcPs
read_a1:read_a2 :: ExprLStmt GhcPs
read_a2:_) = [ExprLStmt GhcPs]
read_args
prefix_prec :: Integer
prefix_prec = Integer
appPrecedence
infix_prec :: Integer
infix_prec = (Name -> Fixity) -> Name -> Integer
getPrecedence Name -> Fixity
get_fixity Name
dc_nm
record_prec :: Integer
record_prec = Integer
appPrecedence Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ 1
mk_alt :: LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
mk_alt e1 :: LHsExpr GhcPs
e1 e2 :: LHsExpr GhcPs
e2 = LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs -> LHsExpr GhcPs
genOpApp LHsExpr GhcPs
e1 RdrName
alt_RDR LHsExpr GhcPs
e2
mk_parser :: Integer -> [ExprLStmt GhcPs] -> LHsExpr GhcPs -> LHsExpr GhcPs
mk_parser p :: Integer
p ss :: [ExprLStmt GhcPs]
ss b :: LHsExpr GhcPs
b = IdP GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP GhcPs
prec_RDR [Integer -> LHsExpr GhcPs
forall (p :: Pass). Integer -> LHsExpr (GhcPass p)
nlHsIntLit Integer
p
, HsStmtContext Name -> [ExprLStmt GhcPs] -> LHsExpr GhcPs
nlHsDo HsStmtContext Name
forall id. HsStmtContext id
DoExpr ([ExprLStmt GhcPs]
ss [ExprLStmt GhcPs] -> [ExprLStmt GhcPs] -> [ExprLStmt GhcPs]
forall a. [a] -> [a] -> [a]
++ [SrcSpanLess (ExprLStmt GhcPs) -> ExprLStmt GhcPs
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc (SrcSpanLess (ExprLStmt GhcPs) -> ExprLStmt GhcPs)
-> SrcSpanLess (ExprLStmt GhcPs) -> ExprLStmt GhcPs
forall a b. (a -> b) -> a -> b
$ LHsExpr GhcPs -> StmtLR GhcPs GhcPs (LHsExpr GhcPs)
forall (bodyR :: * -> *) (idR :: Pass) (idL :: Pass).
Located (bodyR (GhcPass idR))
-> StmtLR
(GhcPass idL) (GhcPass idR) (Located (bodyR (GhcPass idR)))
mkLastStmt LHsExpr GhcPs
b])]
con_app :: thing -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
con_app con :: thing
con as :: [IdP (GhcPass id)]
as = IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
forall (id :: Pass).
IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsVarApps (thing -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName thing
con) [IdP (GhcPass id)]
as
result_expr :: thing -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
result_expr con :: thing
con as :: [IdP (GhcPass id)]
as = LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP (GhcPass id) -> LHsExpr (GhcPass id)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP (GhcPass id)
returnM_RDR) (thing -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
forall thing (id :: Pass).
(NamedThing thing, IdP (GhcPass id) ~ RdrName) =>
thing -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
con_app thing
con [IdP (GhcPass id)]
as)
ident_h_pat :: String -> [a]
ident_h_pat s :: String
s | Just (ss :: String
ss, '#') <- String -> Maybe (String, Char)
forall a. [a] -> Maybe ([a], a)
snocView String
s = [ String -> a
forall a (idL :: Pass).
(HasSrcSpan a,
SrcSpanLess a ~ StmtLR (GhcPass idL) GhcPs (LHsExpr GhcPs)) =>
String -> a
ident_pat String
ss, String -> a
forall a (idL :: Pass).
(HasSrcSpan a,
SrcSpanLess a ~ StmtLR (GhcPass idL) GhcPs (LHsExpr GhcPs)) =>
String -> a
symbol_pat "#" ]
| Bool
otherwise = [ String -> a
forall a (idL :: Pass).
(HasSrcSpan a,
SrcSpanLess a ~ StmtLR (GhcPass idL) GhcPs (LHsExpr GhcPs)) =>
String -> a
ident_pat String
s ]
bindLex :: LHsExpr GhcPs -> a
bindLex pat :: LHsExpr GhcPs
pat = SrcSpanLess a -> a
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc (LHsExpr GhcPs -> StmtLR (GhcPass idL) GhcPs (LHsExpr GhcPs)
forall (bodyR :: * -> *) (idL :: Pass).
Located (bodyR GhcPs)
-> StmtLR (GhcPass idL) GhcPs (Located (bodyR GhcPs))
mkBodyStmt (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
expectP_RDR) LHsExpr GhcPs
pat))
ident_pat :: String -> a
ident_pat s :: String
s = LHsExpr GhcPs -> a
forall a (idL :: Pass).
(HasSrcSpan a,
SrcSpanLess a ~ StmtLR (GhcPass idL) GhcPs (LHsExpr GhcPs)) =>
LHsExpr GhcPs -> a
bindLex (LHsExpr GhcPs -> a) -> LHsExpr GhcPs -> a
forall a b. (a -> b) -> a -> b
$ IdP GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP GhcPs
ident_RDR [HsLit GhcPs -> LHsExpr GhcPs
forall (p :: Pass). HsLit (GhcPass p) -> LHsExpr (GhcPass p)
nlHsLit (String -> HsLit GhcPs
forall (p :: Pass). String -> HsLit (GhcPass p)
mkHsString String
s)]
symbol_pat :: String -> a
symbol_pat s :: String
s = LHsExpr GhcPs -> a
forall a (idL :: Pass).
(HasSrcSpan a,
SrcSpanLess a ~ StmtLR (GhcPass idL) GhcPs (LHsExpr GhcPs)) =>
LHsExpr GhcPs -> a
bindLex (LHsExpr GhcPs -> a) -> LHsExpr GhcPs -> a
forall a b. (a -> b) -> a -> b
$ IdP GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP GhcPs
symbol_RDR [HsLit GhcPs -> LHsExpr GhcPs
forall (p :: Pass). HsLit (GhcPass p) -> LHsExpr (GhcPass p)
nlHsLit (String -> HsLit GhcPs
forall (p :: Pass). String -> HsLit (GhcPass p)
mkHsString String
s)]
read_punc :: String -> a
read_punc c :: String
c = LHsExpr GhcPs -> a
forall a (idL :: Pass).
(HasSrcSpan a,
SrcSpanLess a ~ StmtLR (GhcPass idL) GhcPs (LHsExpr GhcPs)) =>
LHsExpr GhcPs -> a
bindLex (LHsExpr GhcPs -> a) -> LHsExpr GhcPs -> a
forall a b. (a -> b) -> a -> b
$ IdP GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP GhcPs
punc_RDR [HsLit GhcPs -> LHsExpr GhcPs
forall (p :: Pass). HsLit (GhcPass p) -> LHsExpr (GhcPass p)
nlHsLit (String -> HsLit GhcPs
forall (p :: Pass). String -> HsLit (GhcPass p)
mkHsString String
c)]
data_con_str :: a -> String
data_con_str con :: a
con = OccName -> String
occNameString (a -> OccName
forall a. NamedThing a => a -> OccName
getOccName a
con)
read_arg :: IdP (GhcPass idL) -> Type -> p
read_arg a :: IdP (GhcPass idL)
a ty :: Type
ty = ASSERT( not (isUnliftedType ty) )
SrcSpanLess p -> p
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc (LPat (GhcPass idL)
-> Located (HsExpr (GhcPass idR))
-> StmtLR
(GhcPass idL) (GhcPass idR) (Located (HsExpr (GhcPass idR)))
forall (idL :: Pass) (idR :: Pass) (bodyR :: * -> *).
(XBindStmt
(GhcPass idL) (GhcPass idR) (Located (bodyR (GhcPass idR)))
~ NoExt) =>
LPat (GhcPass idL)
-> Located (bodyR (GhcPass idR))
-> StmtLR
(GhcPass idL) (GhcPass idR) (Located (bodyR (GhcPass idR)))
mkBindStmt (IdP (GhcPass idL) -> LPat (GhcPass idL)
forall (p :: Pass). IdP (GhcPass p) -> LPat (GhcPass p)
nlVarPat IdP (GhcPass idL)
a) (IdP (GhcPass idR)
-> [IdP (GhcPass idR)] -> Located (HsExpr (GhcPass idR))
forall (id :: Pass).
IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsVarApps RdrName
IdP (GhcPass idR)
step_RDR [RdrName
IdP (GhcPass idR)
readPrec_RDR]))
read_field :: FastString -> IdP (GhcPass idL) -> [a]
read_field lbl :: FastString
lbl a :: IdP (GhcPass idL)
a =
[SrcSpanLess a -> a
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc
(LPat (GhcPass idL)
-> Located (HsExpr (GhcPass idR))
-> StmtLR
(GhcPass idL) (GhcPass idR) (Located (HsExpr (GhcPass idR)))
forall (idL :: Pass) (idR :: Pass) (bodyR :: * -> *).
(XBindStmt
(GhcPass idL) (GhcPass idR) (Located (bodyR (GhcPass idR)))
~ NoExt) =>
LPat (GhcPass idL)
-> Located (bodyR (GhcPass idR))
-> StmtLR
(GhcPass idL) (GhcPass idR) (Located (bodyR (GhcPass idR)))
mkBindStmt
(IdP (GhcPass idL) -> LPat (GhcPass idL)
forall (p :: Pass). IdP (GhcPass p) -> LPat (GhcPass p)
nlVarPat IdP (GhcPass idL)
a)
(Located (HsExpr (GhcPass idR))
-> Located (HsExpr (GhcPass idR)) -> Located (HsExpr (GhcPass idR))
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp
Located (HsExpr (GhcPass idR))
read_field
(IdP (GhcPass idR)
-> [IdP (GhcPass idR)] -> Located (HsExpr (GhcPass idR))
forall (id :: Pass).
IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsVarApps RdrName
IdP (GhcPass idR)
reset_RDR [RdrName
IdP (GhcPass idR)
readPrec_RDR])
)
)
]
where
lbl_str :: String
lbl_str = FastString -> String
unpackFS FastString
lbl
mk_read_field :: IdP (GhcPass id) -> String -> LHsExpr (GhcPass id)
mk_read_field read_field_rdr :: IdP (GhcPass id)
read_field_rdr lbl :: String
lbl
= IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps IdP (GhcPass id)
read_field_rdr [HsLit (GhcPass id) -> LHsExpr (GhcPass id)
forall (p :: Pass). HsLit (GhcPass p) -> LHsExpr (GhcPass p)
nlHsLit (String -> HsLit (GhcPass id)
forall (p :: Pass). String -> HsLit (GhcPass p)
mkHsString String
lbl)]
read_field :: Located (HsExpr (GhcPass idR))
read_field
| String -> Bool
isSym String
lbl_str
= IdP (GhcPass idR) -> String -> Located (HsExpr (GhcPass idR))
forall (id :: Pass).
IdP (GhcPass id) -> String -> LHsExpr (GhcPass id)
mk_read_field RdrName
IdP (GhcPass idR)
readSymField_RDR String
lbl_str
| Just (ss :: String
ss, '#') <- String -> Maybe (String, Char)
forall a. [a] -> Maybe ([a], a)
snocView String
lbl_str
= IdP (GhcPass idR) -> String -> Located (HsExpr (GhcPass idR))
forall (id :: Pass).
IdP (GhcPass id) -> String -> LHsExpr (GhcPass id)
mk_read_field RdrName
IdP (GhcPass idR)
readFieldHash_RDR String
ss
| Bool
otherwise
= IdP (GhcPass idR) -> String -> Located (HsExpr (GhcPass idR))
forall (id :: Pass).
IdP (GhcPass id) -> String -> LHsExpr (GhcPass id)
mk_read_field RdrName
IdP (GhcPass idR)
readField_RDR String
lbl_str
gen_Show_binds :: (Name -> Fixity) -> SrcSpan -> TyCon
-> (LHsBinds GhcPs, BagDerivStuff)
gen_Show_binds :: (Name -> Fixity)
-> SrcSpan -> TyCon -> (LHsBinds GhcPs, BagDerivStuff)
gen_Show_binds get_fixity :: Name -> Fixity
get_fixity loc :: SrcSpan
loc tycon :: TyCon
tycon
= (LHsBind GhcPs -> LHsBinds GhcPs
forall a. a -> Bag a
unitBag LHsBind GhcPs
shows_prec, BagDerivStuff
forall a. Bag a
emptyBag)
where
data_cons :: [DataCon]
data_cons = TyCon -> [DataCon]
tyConDataCons TyCon
tycon
shows_prec :: LHsBind GhcPs
shows_prec = Int
-> SrcSpan
-> RdrName
-> (LHsExpr GhcPs -> LHsExpr GhcPs)
-> [([LPat GhcPs], LHsExpr GhcPs)]
-> LHsBind GhcPs
mkFunBindEC 2 SrcSpan
loc RdrName
showsPrec_RDR LHsExpr GhcPs -> LHsExpr GhcPs
forall a. a -> a
id ((DataCon -> ([LPat GhcPs], LHsExpr GhcPs))
-> [DataCon] -> [([LPat GhcPs], LHsExpr GhcPs)]
forall a b. (a -> b) -> [a] -> [b]
map DataCon -> ([LPat GhcPs], LHsExpr GhcPs)
pats_etc [DataCon]
data_cons)
comma_space :: LHsExpr GhcPs
comma_space = IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
showCommaSpace_RDR
pats_etc :: DataCon -> ([LPat GhcPs], LHsExpr GhcPs)
pats_etc data_con :: DataCon
data_con
| Bool
nullary_con =
ASSERT(null bs_needed)
([LPat GhcPs
nlWildPat, LPat GhcPs
con_pat], String -> LHsExpr GhcPs
mk_showString_app String
op_con_str)
| Bool
otherwise =
([LPat GhcPs
a_Pat, LPat GhcPs
con_pat],
LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
showParen_Expr (LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs -> LHsExpr GhcPs
genOpApp LHsExpr GhcPs
a_Expr RdrName
ge_RDR (HsLit GhcPs -> LHsExpr GhcPs
forall (p :: Pass). HsLit (GhcPass p) -> LHsExpr (GhcPass p)
nlHsLit
(XHsInt GhcPs -> IntegralLit -> HsLit GhcPs
forall x. XHsInt x -> IntegralLit -> HsLit x
HsInt XHsInt GhcPs
NoExt
noExt (Integer -> IntegralLit
forall a. Integral a => a -> IntegralLit
mkIntegralLit Integer
con_prec_plus_one))))
(LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass). LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsPar ([LHsExpr GhcPs] -> LHsExpr GhcPs
nested_compose_Expr [LHsExpr GhcPs]
show_thingies)))
where
data_con_RDR :: RdrName
data_con_RDR = DataCon -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName DataCon
data_con
con_arity :: Int
con_arity = DataCon -> Int
dataConSourceArity DataCon
data_con
bs_needed :: [RdrName]
bs_needed = Int -> [RdrName] -> [RdrName]
forall a. Int -> [a] -> [a]
take Int
con_arity [RdrName]
bs_RDRs
arg_tys :: [Type]
arg_tys = DataCon -> [Type]
dataConOrigArgTys DataCon
data_con
con_pat :: LPat GhcPs
con_pat = RdrName -> [RdrName] -> LPat GhcPs
nlConVarPat RdrName
data_con_RDR [RdrName]
bs_needed
nullary_con :: Bool
nullary_con = Int
con_arity Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 0
labels :: [FastString]
labels = (FieldLbl Name -> FastString) -> [FieldLbl Name] -> [FastString]
forall a b. (a -> b) -> [a] -> [b]
map FieldLbl Name -> FastString
forall a. FieldLbl a -> FastString
flLabel ([FieldLbl Name] -> [FastString])
-> [FieldLbl Name] -> [FastString]
forall a b. (a -> b) -> a -> b
$ DataCon -> [FieldLbl Name]
dataConFieldLabels DataCon
data_con
lab_fields :: Int
lab_fields = [FastString] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [FastString]
labels
record_syntax :: Bool
record_syntax = Int
lab_fields Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0
dc_nm :: Name
dc_nm = DataCon -> Name
forall a. NamedThing a => a -> Name
getName DataCon
data_con
dc_occ_nm :: OccName
dc_occ_nm = DataCon -> OccName
forall a. NamedThing a => a -> OccName
getOccName DataCon
data_con
con_str :: String
con_str = OccName -> String
occNameString OccName
dc_occ_nm
op_con_str :: String
op_con_str = String -> String
wrapOpParens String
con_str
backquote_str :: String
backquote_str = String -> String
wrapOpBackquotes String
con_str
show_thingies :: [LHsExpr GhcPs]
show_thingies
| Bool
is_infix = [LHsExpr GhcPs
show_arg1, String -> LHsExpr GhcPs
mk_showString_app (" " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
backquote_str String -> String -> String
forall a. [a] -> [a] -> [a]
++ " "), LHsExpr GhcPs
show_arg2]
| Bool
record_syntax = String -> LHsExpr GhcPs
mk_showString_app (String
op_con_str String -> String -> String
forall a. [a] -> [a] -> [a]
++ " {") LHsExpr GhcPs -> [LHsExpr GhcPs] -> [LHsExpr GhcPs]
forall a. a -> [a] -> [a]
:
[LHsExpr GhcPs]
show_record_args [LHsExpr GhcPs] -> [LHsExpr GhcPs] -> [LHsExpr GhcPs]
forall a. [a] -> [a] -> [a]
++ [String -> LHsExpr GhcPs
mk_showString_app "}"]
| Bool
otherwise = String -> LHsExpr GhcPs
mk_showString_app (String
op_con_str String -> String -> String
forall a. [a] -> [a] -> [a]
++ " ") LHsExpr GhcPs -> [LHsExpr GhcPs] -> [LHsExpr GhcPs]
forall a. a -> [a] -> [a]
: [LHsExpr GhcPs]
show_prefix_args
show_label :: FastString -> LHsExpr GhcPs
show_label l :: FastString
l = String -> LHsExpr GhcPs
mk_showString_app (String
nm String -> String -> String
forall a. [a] -> [a] -> [a]
++ " = ")
where
nm :: String
nm = String -> String
wrapOpParens (FastString -> String
unpackFS FastString
l)
show_args :: [LHsExpr GhcPs]
show_args = (RdrName -> Type -> LHsExpr GhcPs)
-> [RdrName] -> [Type] -> [LHsExpr GhcPs]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith RdrName -> Type -> LHsExpr GhcPs
show_arg [RdrName]
bs_needed [Type]
arg_tys
(show_arg1 :: LHsExpr GhcPs
show_arg1:show_arg2 :: LHsExpr GhcPs
show_arg2:_) = [LHsExpr GhcPs]
show_args
show_prefix_args :: [LHsExpr GhcPs]
show_prefix_args = LHsExpr GhcPs -> [LHsExpr GhcPs] -> [LHsExpr GhcPs]
forall a. a -> [a] -> [a]
intersperse (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
showSpace_RDR) [LHsExpr GhcPs]
show_args
show_record_args :: [LHsExpr GhcPs]
show_record_args = [[LHsExpr GhcPs]] -> [LHsExpr GhcPs]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[LHsExpr GhcPs]] -> [LHsExpr GhcPs])
-> [[LHsExpr GhcPs]] -> [LHsExpr GhcPs]
forall a b. (a -> b) -> a -> b
$
[LHsExpr GhcPs] -> [[LHsExpr GhcPs]] -> [[LHsExpr GhcPs]]
forall a. a -> [a] -> [a]
intersperse [LHsExpr GhcPs
comma_space] ([[LHsExpr GhcPs]] -> [[LHsExpr GhcPs]])
-> [[LHsExpr GhcPs]] -> [[LHsExpr GhcPs]]
forall a b. (a -> b) -> a -> b
$
[ [FastString -> LHsExpr GhcPs
show_label FastString
lbl, LHsExpr GhcPs
arg]
| (lbl :: FastString
lbl,arg :: LHsExpr GhcPs
arg) <- String
-> [FastString] -> [LHsExpr GhcPs] -> [(FastString, LHsExpr GhcPs)]
forall a b. String -> [a] -> [b] -> [(a, b)]
zipEqual "gen_Show_binds"
[FastString]
labels [LHsExpr GhcPs]
show_args ]
show_arg :: RdrName -> Type -> LHsExpr GhcPs
show_arg :: RdrName -> Type -> LHsExpr GhcPs
show_arg b :: RdrName
b arg_ty :: Type
arg_ty
| HasDebugCallStack => Type -> Bool
Type -> Bool
isUnliftedType Type
arg_ty
= LHsExpr GhcPs -> LHsExpr GhcPs
with_conv (LHsExpr GhcPs -> LHsExpr GhcPs) -> LHsExpr GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$
IdP GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP GhcPs
compose_RDR
[LHsExpr GhcPs -> LHsExpr GhcPs
mk_shows_app LHsExpr GhcPs
boxed_arg, String -> LHsExpr GhcPs
mk_showString_app String
postfixMod]
| Bool
otherwise
= Integer -> LHsExpr GhcPs -> LHsExpr GhcPs
mk_showsPrec_app Integer
arg_prec LHsExpr GhcPs
arg
where
arg :: LHsExpr GhcPs
arg = IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
b
boxed_arg :: LHsExpr GhcPs
boxed_arg = String -> LHsExpr GhcPs -> Type -> LHsExpr GhcPs
box "Show" LHsExpr GhcPs
arg Type
arg_ty
postfixMod :: String
postfixMod = String -> [(Type, String)] -> Type -> String
forall a. HasCallStack => String -> [(Type, a)] -> Type -> a
assoc_ty_id "Show" [(Type, String)]
postfixModTbl Type
arg_ty
with_conv :: LHsExpr GhcPs -> LHsExpr GhcPs
with_conv expr :: LHsExpr GhcPs
expr
| (Just conv :: String
conv) <- [(Type, String)] -> Type -> Maybe String
forall a. [(Type, a)] -> Type -> Maybe a
assoc_ty_id_maybe [(Type, String)]
primConvTbl Type
arg_ty =
[LHsExpr GhcPs] -> LHsExpr GhcPs
nested_compose_Expr
[ String -> LHsExpr GhcPs
mk_showString_app ("(" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
conv String -> String -> String
forall a. [a] -> [a] -> [a]
++ " ")
, LHsExpr GhcPs
expr
, String -> LHsExpr GhcPs
mk_showString_app ")"
]
| Bool
otherwise = LHsExpr GhcPs
expr
is_infix :: Bool
is_infix = DataCon -> Bool
dataConIsInfix DataCon
data_con
con_prec_plus_one :: Integer
con_prec_plus_one = 1 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Bool -> (Name -> Fixity) -> Name -> Integer
getPrec Bool
is_infix Name -> Fixity
get_fixity Name
dc_nm
arg_prec :: Integer
arg_prec | Bool
record_syntax = 0
| Bool
otherwise = Integer
con_prec_plus_one
wrapOpParens :: String -> String
wrapOpParens :: String -> String
wrapOpParens s :: String
s | String -> Bool
isSym String
s = '(' Char -> String -> String
forall a. a -> [a] -> [a]
: String
s String -> String -> String
forall a. [a] -> [a] -> [a]
++ ")"
| Bool
otherwise = String
s
wrapOpBackquotes :: String -> String
wrapOpBackquotes :: String -> String
wrapOpBackquotes s :: String
s | String -> Bool
isSym String
s = String
s
| Bool
otherwise = '`' Char -> String -> String
forall a. a -> [a] -> [a]
: String
s String -> String -> String
forall a. [a] -> [a] -> [a]
++ "`"
isSym :: String -> Bool
isSym :: String -> Bool
isSym "" = Bool
False
isSym (c :: Char
c : _) = Char -> Bool
startsVarSym Char
c Bool -> Bool -> Bool
|| Char -> Bool
startsConSym Char
c
mk_showString_app :: String -> LHsExpr GhcPs
mk_showString_app :: String -> LHsExpr GhcPs
mk_showString_app str :: String
str = LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
showString_RDR) (HsLit GhcPs -> LHsExpr GhcPs
forall (p :: Pass). HsLit (GhcPass p) -> LHsExpr (GhcPass p)
nlHsLit (String -> HsLit GhcPs
forall (p :: Pass). String -> HsLit (GhcPass p)
mkHsString String
str))
mk_showsPrec_app :: Integer -> LHsExpr GhcPs -> LHsExpr GhcPs
mk_showsPrec_app :: Integer -> LHsExpr GhcPs -> LHsExpr GhcPs
mk_showsPrec_app p :: Integer
p x :: LHsExpr GhcPs
x
= IdP GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP GhcPs
showsPrec_RDR [HsLit GhcPs -> LHsExpr GhcPs
forall (p :: Pass). HsLit (GhcPass p) -> LHsExpr (GhcPass p)
nlHsLit (XHsInt GhcPs -> IntegralLit -> HsLit GhcPs
forall x. XHsInt x -> IntegralLit -> HsLit x
HsInt XHsInt GhcPs
NoExt
noExt (Integer -> IntegralLit
forall a. Integral a => a -> IntegralLit
mkIntegralLit Integer
p)), LHsExpr GhcPs
x]
mk_shows_app :: LHsExpr GhcPs -> LHsExpr GhcPs
mk_shows_app :: LHsExpr GhcPs -> LHsExpr GhcPs
mk_shows_app x :: LHsExpr GhcPs
x = LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
shows_RDR) LHsExpr GhcPs
x
getPrec :: Bool -> (Name -> Fixity) -> Name -> Integer
getPrec :: Bool -> (Name -> Fixity) -> Name -> Integer
getPrec is_infix :: Bool
is_infix get_fixity :: Name -> Fixity
get_fixity nm :: Name
nm
| Bool -> Bool
not Bool
is_infix = Integer
appPrecedence
| Bool
otherwise = (Name -> Fixity) -> Name -> Integer
getPrecedence Name -> Fixity
get_fixity Name
nm
appPrecedence :: Integer
appPrecedence :: Integer
appPrecedence = Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
maxPrecedence Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ 1
getPrecedence :: (Name -> Fixity) -> Name -> Integer
getPrecedence :: (Name -> Fixity) -> Name -> Integer
getPrecedence get_fixity :: Name -> Fixity
get_fixity nm :: Name
nm
= case Name -> Fixity
get_fixity Name
nm of
Fixity _ x :: Int
x _assoc :: FixityDirection
_assoc -> Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
x
gen_Data_binds :: SrcSpan
-> TyCon
-> TcM (LHsBinds GhcPs,
BagDerivStuff)
gen_Data_binds :: SrcSpan -> TyCon -> TcM (LHsBinds GhcPs, BagDerivStuff)
gen_Data_binds loc :: SrcSpan
loc rep_tc :: TyCon
rep_tc
= do { DynFlags
dflags <- IOEnv (Env TcGblEnv TcLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
; OccName
dt_occ <- (OccSet -> OccName) -> TcM OccName
chooseUniqueOccTc (OccName -> OccSet -> OccName
mkDataTOcc (TyCon -> OccName
forall a. NamedThing a => a -> OccName
getOccName TyCon
rep_tc))
; [OccName]
dc_occs <- (DataCon -> TcM OccName)
-> [DataCon] -> IOEnv (Env TcGblEnv TcLclEnv) [OccName]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ((OccSet -> OccName) -> TcM OccName
chooseUniqueOccTc ((OccSet -> OccName) -> TcM OccName)
-> (DataCon -> OccSet -> OccName) -> DataCon -> TcM OccName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OccName -> OccSet -> OccName
mkDataCOcc (OccName -> OccSet -> OccName)
-> (DataCon -> OccName) -> DataCon -> OccSet -> OccName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataCon -> OccName
forall a. NamedThing a => a -> OccName
getOccName)
(TyCon -> [DataCon]
tyConDataCons TyCon
rep_tc)
; let dt_rdr :: RdrName
dt_rdr = OccName -> RdrName
mkRdrUnqual OccName
dt_occ
dc_rdrs :: [RdrName]
dc_rdrs = (OccName -> RdrName) -> [OccName] -> [RdrName]
forall a b. (a -> b) -> [a] -> [b]
map OccName -> RdrName
mkRdrUnqual [OccName]
dc_occs
; (LHsBinds GhcPs, BagDerivStuff)
-> TcM (LHsBinds GhcPs, BagDerivStuff)
forall (m :: * -> *) a. Monad m => a -> m a
return (DynFlags
-> RdrName
-> [RdrName]
-> SrcSpan
-> TyCon
-> (LHsBinds GhcPs, BagDerivStuff)
gen_data DynFlags
dflags RdrName
dt_rdr [RdrName]
dc_rdrs SrcSpan
loc TyCon
rep_tc) }
gen_data :: DynFlags -> RdrName -> [RdrName]
-> SrcSpan -> TyCon
-> (LHsBinds GhcPs,
BagDerivStuff)
gen_data :: DynFlags
-> RdrName
-> [RdrName]
-> SrcSpan
-> TyCon
-> (LHsBinds GhcPs, BagDerivStuff)
gen_data dflags :: DynFlags
dflags data_type_name :: RdrName
data_type_name constr_names :: [RdrName]
constr_names loc :: SrcSpan
loc rep_tc :: TyCon
rep_tc
= ([LHsBind GhcPs] -> LHsBinds GhcPs
forall a. [a] -> Bag a
listToBag [LHsBind GhcPs
gfoldl_bind, LHsBind GhcPs
gunfold_bind, LHsBind GhcPs
toCon_bind, LHsBind GhcPs
dataTypeOf_bind]
LHsBinds GhcPs -> LHsBinds GhcPs -> LHsBinds GhcPs
forall a. Bag a -> Bag a -> Bag a
`unionBags` LHsBinds GhcPs
gcast_binds,
[DerivStuff] -> BagDerivStuff
forall a. [a] -> Bag a
listToBag ( DerivStuff
genDataTyCon
DerivStuff -> [DerivStuff] -> [DerivStuff]
forall a. a -> [a] -> [a]
: (DataCon -> RdrName -> DerivStuff)
-> [DataCon] -> [RdrName] -> [DerivStuff]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith DataCon -> RdrName -> DerivStuff
genDataDataCon [DataCon]
data_cons [RdrName]
constr_names ) )
where
data_cons :: [DataCon]
data_cons = TyCon -> [DataCon]
tyConDataCons TyCon
rep_tc
n_cons :: Int
n_cons = [DataCon] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [DataCon]
data_cons
one_constr :: Bool
one_constr = Int
n_cons Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 1
genDataTyCon :: DerivStuff
genDataTyCon :: DerivStuff
genDataTyCon
= (LHsBind GhcPs, LSig GhcPs) -> DerivStuff
DerivHsBind (SrcSpan -> RdrName -> LHsExpr GhcPs -> LHsBind GhcPs
mkHsVarBind SrcSpan
loc RdrName
data_type_name LHsExpr GhcPs
rhs,
SrcSpan -> Sig GhcPs -> LSig GhcPs
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc (XTypeSig GhcPs
-> [Located (IdP GhcPs)] -> LHsSigWcType GhcPs -> Sig GhcPs
forall pass.
XTypeSig pass
-> [Located (IdP pass)] -> LHsSigWcType pass -> Sig pass
TypeSig XTypeSig GhcPs
NoExt
noExt [SrcSpan -> RdrName -> Located RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc RdrName
data_type_name] LHsSigWcType GhcPs
sig_ty))
sig_ty :: LHsSigWcType GhcPs
sig_ty = LHsType GhcPs -> LHsSigWcType GhcPs
mkLHsSigWcType (IdP GhcPs -> LHsType GhcPs
forall (p :: Pass). IdP (GhcPass p) -> LHsType (GhcPass p)
nlHsTyVar RdrName
IdP GhcPs
dataType_RDR)
rhs :: LHsExpr GhcPs
rhs = IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
mkDataType_RDR
LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
`nlHsApp` HsLit GhcPs -> LHsExpr GhcPs
forall (p :: Pass). HsLit (GhcPass p) -> LHsExpr (GhcPass p)
nlHsLit (String -> HsLit GhcPs
forall (p :: Pass). String -> HsLit (GhcPass p)
mkHsString (DynFlags -> SDoc -> String
showSDocOneLine DynFlags
dflags (TyCon -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCon
rep_tc)))
LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
`nlHsApp` [LHsExpr GhcPs] -> LHsExpr GhcPs
nlList ((RdrName -> LHsExpr GhcPs) -> [RdrName] -> [LHsExpr GhcPs]
forall a b. (a -> b) -> [a] -> [b]
map RdrName -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar [RdrName]
constr_names)
genDataDataCon :: DataCon -> RdrName -> DerivStuff
genDataDataCon :: DataCon -> RdrName -> DerivStuff
genDataDataCon dc :: DataCon
dc constr_name :: RdrName
constr_name
= (LHsBind GhcPs, LSig GhcPs) -> DerivStuff
DerivHsBind (SrcSpan -> RdrName -> LHsExpr GhcPs -> LHsBind GhcPs
mkHsVarBind SrcSpan
loc RdrName
constr_name LHsExpr GhcPs
rhs,
SrcSpan -> Sig GhcPs -> LSig GhcPs
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc (XTypeSig GhcPs
-> [Located (IdP GhcPs)] -> LHsSigWcType GhcPs -> Sig GhcPs
forall pass.
XTypeSig pass
-> [Located (IdP pass)] -> LHsSigWcType pass -> Sig pass
TypeSig XTypeSig GhcPs
NoExt
noExt [SrcSpan -> RdrName -> Located RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc RdrName
constr_name] LHsSigWcType GhcPs
sig_ty))
where
sig_ty :: LHsSigWcType GhcPs
sig_ty = LHsType GhcPs -> LHsSigWcType GhcPs
mkLHsSigWcType (IdP GhcPs -> LHsType GhcPs
forall (p :: Pass). IdP (GhcPass p) -> LHsType (GhcPass p)
nlHsTyVar RdrName
IdP GhcPs
constr_RDR)
rhs :: LHsExpr GhcPs
rhs = IdP GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP GhcPs
mkConstr_RDR [LHsExpr GhcPs]
constr_args
constr_args :: [LHsExpr GhcPs]
constr_args
= [
IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar (RdrName
IdP GhcPs
data_type_name)
, HsLit GhcPs -> LHsExpr GhcPs
forall (p :: Pass). HsLit (GhcPass p) -> LHsExpr (GhcPass p)
nlHsLit (String -> HsLit GhcPs
forall (p :: Pass). String -> HsLit (GhcPass p)
mkHsString (OccName -> String
occNameString OccName
dc_occ))
, [LHsExpr GhcPs] -> LHsExpr GhcPs
nlList [LHsExpr GhcPs]
labels
, IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
fixity ]
labels :: [LHsExpr GhcPs]
labels = (FieldLbl Name -> LHsExpr GhcPs)
-> [FieldLbl Name] -> [LHsExpr GhcPs]
forall a b. (a -> b) -> [a] -> [b]
map (HsLit GhcPs -> LHsExpr GhcPs
forall (p :: Pass). HsLit (GhcPass p) -> LHsExpr (GhcPass p)
nlHsLit (HsLit GhcPs -> LHsExpr GhcPs)
-> (FieldLbl Name -> HsLit GhcPs) -> FieldLbl Name -> LHsExpr GhcPs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> HsLit GhcPs
forall (p :: Pass). String -> HsLit (GhcPass p)
mkHsString (String -> HsLit GhcPs)
-> (FieldLbl Name -> String) -> FieldLbl Name -> HsLit GhcPs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FastString -> String
unpackFS (FastString -> String)
-> (FieldLbl Name -> FastString) -> FieldLbl Name -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FieldLbl Name -> FastString
forall a. FieldLbl a -> FastString
flLabel)
(DataCon -> [FieldLbl Name]
dataConFieldLabels DataCon
dc)
dc_occ :: OccName
dc_occ = DataCon -> OccName
forall a. NamedThing a => a -> OccName
getOccName DataCon
dc
is_infix :: Bool
is_infix = OccName -> Bool
isDataSymOcc OccName
dc_occ
fixity :: RdrName
fixity | Bool
is_infix = RdrName
infix_RDR
| Bool
otherwise = RdrName
prefix_RDR
gfoldl_bind :: LHsBind GhcPs
gfoldl_bind = Int
-> SrcSpan
-> RdrName
-> (LHsExpr GhcPs -> LHsExpr GhcPs)
-> [([LPat GhcPs], LHsExpr GhcPs)]
-> LHsBind GhcPs
mkFunBindEC 3 SrcSpan
loc RdrName
gfoldl_RDR LHsExpr GhcPs -> LHsExpr GhcPs
forall a. a -> a
id ((DataCon -> ([LPat GhcPs], LHsExpr GhcPs))
-> [DataCon] -> [([LPat GhcPs], LHsExpr GhcPs)]
forall a b. (a -> b) -> [a] -> [b]
map DataCon -> ([LPat GhcPs], LHsExpr GhcPs)
gfoldl_eqn [DataCon]
data_cons)
gfoldl_eqn :: DataCon -> ([LPat GhcPs], LHsExpr GhcPs)
gfoldl_eqn con :: DataCon
con
= ([IdP GhcPs -> LPat GhcPs
forall (p :: Pass). IdP (GhcPass p) -> LPat (GhcPass p)
nlVarPat RdrName
IdP GhcPs
k_RDR, LPat GhcPs
z_Pat, RdrName -> [RdrName] -> LPat GhcPs
nlConVarPat RdrName
con_name [RdrName]
as_needed],
(LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs)
-> LHsExpr GhcPs -> [RdrName] -> LHsExpr GhcPs
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs
mk_k_app (LHsExpr GhcPs
z_Expr LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
`nlHsApp` IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
con_name) [RdrName]
as_needed)
where
con_name :: RdrName
con_name :: RdrName
con_name = DataCon -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName DataCon
con
as_needed :: [RdrName]
as_needed = Int -> [RdrName] -> [RdrName]
forall a. Int -> [a] -> [a]
take (DataCon -> Int
dataConSourceArity DataCon
con) [RdrName]
as_RDRs
mk_k_app :: LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs
mk_k_app e :: LHsExpr GhcPs
e v :: RdrName
v = LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass). LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsPar (LHsExpr GhcPs -> IdP GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
nlHsOpApp LHsExpr GhcPs
e RdrName
IdP GhcPs
k_RDR (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
v))
gunfold_bind :: LHsBind GhcPs
gunfold_bind = SrcSpan
-> RdrName -> [LPat GhcPs] -> LHsExpr GhcPs -> LHsBind GhcPs
mk_easy_FunBind SrcSpan
loc
RdrName
gunfold_RDR
[LPat GhcPs
k_Pat, LPat GhcPs
z_Pat, if Bool
one_constr then LPat GhcPs
nlWildPat else LPat GhcPs
c_Pat]
LHsExpr GhcPs
gunfold_rhs
gunfold_rhs :: LHsExpr GhcPs
gunfold_rhs
| Bool
one_constr = DataCon -> LHsExpr GhcPs
mk_unfold_rhs ([DataCon] -> DataCon
forall a. [a] -> a
head [DataCon]
data_cons)
| Bool
otherwise = LHsExpr GhcPs -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsExpr GhcPs
nlHsCase (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
conIndex_RDR LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
`nlHsApp` LHsExpr GhcPs
c_Expr)
((DataCon -> LMatch GhcPs (LHsExpr GhcPs))
-> [DataCon] -> [LMatch GhcPs (LHsExpr GhcPs)]
forall a b. (a -> b) -> [a] -> [b]
map DataCon -> LMatch GhcPs (LHsExpr GhcPs)
gunfold_alt [DataCon]
data_cons)
gunfold_alt :: DataCon -> LMatch GhcPs (LHsExpr GhcPs)
gunfold_alt dc :: DataCon
dc = LPat GhcPs -> LHsExpr GhcPs -> LMatch GhcPs (LHsExpr GhcPs)
forall (p :: Pass) (body :: * -> *).
LPat (GhcPass p)
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkHsCaseAlt (DataCon -> LPat GhcPs
mk_unfold_pat DataCon
dc) (DataCon -> LHsExpr GhcPs
mk_unfold_rhs DataCon
dc)
mk_unfold_rhs :: DataCon -> LHsExpr GhcPs
mk_unfold_rhs dc :: DataCon
dc = (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs)
-> LHsExpr GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp
(LHsExpr GhcPs
z_Expr LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
`nlHsApp` IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar (DataCon -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName DataCon
dc))
(Int -> LHsExpr GhcPs -> [LHsExpr GhcPs]
forall a. Int -> a -> [a]
replicate (DataCon -> Int
dataConSourceArity DataCon
dc) (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
k_RDR))
mk_unfold_pat :: DataCon -> LPat GhcPs
mk_unfold_pat dc :: DataCon
dc
| Int
tagInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
fIRST_TAG Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n_consInt -> Int -> Int
forall a. Num a => a -> a -> a
-1 = LPat GhcPs
nlWildPat
| Bool
otherwise = RdrName -> [LPat GhcPs] -> LPat GhcPs
nlConPat RdrName
intDataCon_RDR
[HsLit GhcPs -> LPat GhcPs
nlLitPat (XHsIntPrim GhcPs -> Integer -> HsLit GhcPs
forall x. XHsIntPrim x -> Integer -> HsLit x
HsIntPrim SourceText
XHsIntPrim GhcPs
NoSourceText (Int -> Integer
forall a. Integral a => a -> Integer
toInteger Int
tag))]
where
tag :: Int
tag = DataCon -> Int
dataConTag DataCon
dc
toCon_bind :: LHsBind GhcPs
toCon_bind = Int
-> SrcSpan
-> RdrName
-> (LHsExpr GhcPs -> LHsExpr GhcPs)
-> [([LPat GhcPs], LHsExpr GhcPs)]
-> LHsBind GhcPs
mkFunBindEC 1 SrcSpan
loc RdrName
toConstr_RDR LHsExpr GhcPs -> LHsExpr GhcPs
forall a. a -> a
id
((DataCon -> RdrName -> ([LPat GhcPs], LHsExpr GhcPs))
-> [DataCon] -> [RdrName] -> [([LPat GhcPs], LHsExpr GhcPs)]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith DataCon -> RdrName -> ([LPat GhcPs], LHsExpr GhcPs)
forall (id :: Pass).
DataCon -> IdP (GhcPass id) -> ([LPat GhcPs], LHsExpr (GhcPass id))
to_con_eqn [DataCon]
data_cons [RdrName]
constr_names)
to_con_eqn :: DataCon -> IdP (GhcPass id) -> ([LPat GhcPs], LHsExpr (GhcPass id))
to_con_eqn dc :: DataCon
dc con_name :: IdP (GhcPass id)
con_name = ([DataCon -> LPat GhcPs
nlWildConPat DataCon
dc], IdP (GhcPass id) -> LHsExpr (GhcPass id)
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar IdP (GhcPass id)
con_name)
dataTypeOf_bind :: LHsBind GhcPs
dataTypeOf_bind = SrcSpan
-> RdrName -> [LPat GhcPs] -> LHsExpr GhcPs -> LHsBind GhcPs
mk_easy_FunBind
SrcSpan
loc
RdrName
dataTypeOf_RDR
[LPat GhcPs
nlWildPat]
(IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
data_type_name)
tycon_kind :: Type
tycon_kind = case TyCon -> Maybe (TyCon, [Type])
tyConFamInst_maybe TyCon
rep_tc of
Just (fam_tc :: TyCon
fam_tc, _) -> TyCon -> Type
tyConKind TyCon
fam_tc
Nothing -> TyCon -> Type
tyConKind TyCon
rep_tc
gcast_binds :: LHsBinds GhcPs
gcast_binds | Type
tycon_kind HasDebugCallStack => Type -> Type -> Bool
Type -> Type -> Bool
`tcEqKind` Type
kind1 = RdrName -> RdrName -> LHsBinds GhcPs
mk_gcast RdrName
dataCast1_RDR RdrName
gcast1_RDR
| Type
tycon_kind HasDebugCallStack => Type -> Type -> Bool
Type -> Type -> Bool
`tcEqKind` Type
kind2 = RdrName -> RdrName -> LHsBinds GhcPs
mk_gcast RdrName
dataCast2_RDR RdrName
gcast2_RDR
| Bool
otherwise = LHsBinds GhcPs
forall a. Bag a
emptyBag
mk_gcast :: RdrName -> RdrName -> LHsBinds GhcPs
mk_gcast dataCast_RDR :: RdrName
dataCast_RDR gcast_RDR :: RdrName
gcast_RDR
= LHsBind GhcPs -> LHsBinds GhcPs
forall a. a -> Bag a
unitBag (SrcSpan
-> RdrName -> [LPat GhcPs] -> LHsExpr GhcPs -> LHsBind GhcPs
mk_easy_FunBind SrcSpan
loc RdrName
dataCast_RDR [IdP GhcPs -> LPat GhcPs
forall (p :: Pass). IdP (GhcPass p) -> LPat (GhcPass p)
nlVarPat RdrName
IdP GhcPs
f_RDR]
(IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
gcast_RDR LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
`nlHsApp` IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
f_RDR))
kind1, kind2 :: Kind
kind1 :: Type
kind1 = Type
liftedTypeKind Type -> Type -> Type
`mkFunTy` Type
liftedTypeKind
kind2 :: Type
kind2 = Type
liftedTypeKind Type -> Type -> Type
`mkFunTy` Type
kind1
gfoldl_RDR, gunfold_RDR, toConstr_RDR, dataTypeOf_RDR, mkConstr_RDR,
mkDataType_RDR, conIndex_RDR, prefix_RDR, infix_RDR,
dataCast1_RDR, dataCast2_RDR, gcast1_RDR, gcast2_RDR,
constr_RDR, dataType_RDR,
eqChar_RDR , ltChar_RDR , geChar_RDR , gtChar_RDR , leChar_RDR ,
eqInt_RDR , ltInt_RDR , geInt_RDR , gtInt_RDR , leInt_RDR ,
eqInt8_RDR , ltInt8_RDR , geInt8_RDR , gtInt8_RDR , leInt8_RDR ,
eqInt16_RDR , ltInt16_RDR , geInt16_RDR , gtInt16_RDR , leInt16_RDR ,
eqWord_RDR , ltWord_RDR , geWord_RDR , gtWord_RDR , leWord_RDR ,
eqWord8_RDR , ltWord8_RDR , geWord8_RDR , gtWord8_RDR , leWord8_RDR ,
eqWord16_RDR, ltWord16_RDR, geWord16_RDR, gtWord16_RDR, leWord16_RDR,
eqAddr_RDR , ltAddr_RDR , geAddr_RDR , gtAddr_RDR , leAddr_RDR ,
eqFloat_RDR , ltFloat_RDR , geFloat_RDR , gtFloat_RDR , leFloat_RDR ,
eqDouble_RDR, ltDouble_RDR, geDouble_RDR, gtDouble_RDR, leDouble_RDR,
extendWord8_RDR, extendInt8_RDR,
extendWord16_RDR, extendInt16_RDR :: RdrName
gfoldl_RDR :: RdrName
gfoldl_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gENERICS (String -> FastString
fsLit "gfoldl")
gunfold_RDR :: RdrName
gunfold_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gENERICS (String -> FastString
fsLit "gunfold")
toConstr_RDR :: RdrName
toConstr_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gENERICS (String -> FastString
fsLit "toConstr")
dataTypeOf_RDR :: RdrName
dataTypeOf_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gENERICS (String -> FastString
fsLit "dataTypeOf")
dataCast1_RDR :: RdrName
dataCast1_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gENERICS (String -> FastString
fsLit "dataCast1")
dataCast2_RDR :: RdrName
dataCast2_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gENERICS (String -> FastString
fsLit "dataCast2")
gcast1_RDR :: RdrName
gcast1_RDR = Module -> FastString -> RdrName
varQual_RDR Module
tYPEABLE (String -> FastString
fsLit "gcast1")
gcast2_RDR :: RdrName
gcast2_RDR = Module -> FastString -> RdrName
varQual_RDR Module
tYPEABLE (String -> FastString
fsLit "gcast2")
mkConstr_RDR :: RdrName
mkConstr_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gENERICS (String -> FastString
fsLit "mkConstr")
constr_RDR :: RdrName
constr_RDR = Module -> FastString -> RdrName
tcQual_RDR Module
gENERICS (String -> FastString
fsLit "Constr")
mkDataType_RDR :: RdrName
mkDataType_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gENERICS (String -> FastString
fsLit "mkDataType")
dataType_RDR :: RdrName
dataType_RDR = Module -> FastString -> RdrName
tcQual_RDR Module
gENERICS (String -> FastString
fsLit "DataType")
conIndex_RDR :: RdrName
conIndex_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gENERICS (String -> FastString
fsLit "constrIndex")
prefix_RDR :: RdrName
prefix_RDR = Module -> FastString -> RdrName
dataQual_RDR Module
gENERICS (String -> FastString
fsLit "Prefix")
infix_RDR :: RdrName
infix_RDR = Module -> FastString -> RdrName
dataQual_RDR Module
gENERICS (String -> FastString
fsLit "Infix")
eqChar_RDR :: RdrName
eqChar_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "eqChar#")
ltChar_RDR :: RdrName
ltChar_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "ltChar#")
leChar_RDR :: RdrName
leChar_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "leChar#")
gtChar_RDR :: RdrName
gtChar_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "gtChar#")
geChar_RDR :: RdrName
geChar_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "geChar#")
eqInt_RDR :: RdrName
eqInt_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "==#")
ltInt_RDR :: RdrName
ltInt_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "<#" )
leInt_RDR :: RdrName
leInt_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "<=#")
gtInt_RDR :: RdrName
gtInt_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit ">#" )
geInt_RDR :: RdrName
geInt_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit ">=#")
eqInt8_RDR :: RdrName
eqInt8_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "eqInt8#")
ltInt8_RDR :: RdrName
ltInt8_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "ltInt8#" )
leInt8_RDR :: RdrName
leInt8_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "leInt8#")
gtInt8_RDR :: RdrName
gtInt8_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "gtInt8#" )
geInt8_RDR :: RdrName
geInt8_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "geInt8#")
eqInt16_RDR :: RdrName
eqInt16_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "eqInt16#")
ltInt16_RDR :: RdrName
ltInt16_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "ltInt16#" )
leInt16_RDR :: RdrName
leInt16_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "leInt16#")
gtInt16_RDR :: RdrName
gtInt16_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "gtInt16#" )
geInt16_RDR :: RdrName
geInt16_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "geInt16#")
eqWord_RDR :: RdrName
eqWord_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "eqWord#")
ltWord_RDR :: RdrName
ltWord_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "ltWord#")
leWord_RDR :: RdrName
leWord_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "leWord#")
gtWord_RDR :: RdrName
gtWord_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "gtWord#")
geWord_RDR :: RdrName
geWord_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "geWord#")
eqWord8_RDR :: RdrName
eqWord8_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "eqWord8#")
ltWord8_RDR :: RdrName
ltWord8_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "ltWord8#" )
leWord8_RDR :: RdrName
leWord8_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "leWord8#")
gtWord8_RDR :: RdrName
gtWord8_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "gtWord8#" )
geWord8_RDR :: RdrName
geWord8_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "geWord8#")
eqWord16_RDR :: RdrName
eqWord16_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "eqWord16#")
ltWord16_RDR :: RdrName
ltWord16_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "ltWord16#" )
leWord16_RDR :: RdrName
leWord16_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "leWord16#")
gtWord16_RDR :: RdrName
gtWord16_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "gtWord16#" )
geWord16_RDR :: RdrName
geWord16_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "geWord16#")
eqAddr_RDR :: RdrName
eqAddr_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "eqAddr#")
ltAddr_RDR :: RdrName
ltAddr_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "ltAddr#")
leAddr_RDR :: RdrName
leAddr_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "leAddr#")
gtAddr_RDR :: RdrName
gtAddr_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "gtAddr#")
geAddr_RDR :: RdrName
geAddr_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "geAddr#")
eqFloat_RDR :: RdrName
eqFloat_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "eqFloat#")
ltFloat_RDR :: RdrName
ltFloat_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "ltFloat#")
leFloat_RDR :: RdrName
leFloat_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "leFloat#")
gtFloat_RDR :: RdrName
gtFloat_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "gtFloat#")
geFloat_RDR :: RdrName
geFloat_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "geFloat#")
eqDouble_RDR :: RdrName
eqDouble_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "==##")
ltDouble_RDR :: RdrName
ltDouble_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "<##" )
leDouble_RDR :: RdrName
leDouble_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "<=##")
gtDouble_RDR :: RdrName
gtDouble_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit ">##" )
geDouble_RDR :: RdrName
geDouble_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit ">=##")
extendWord8_RDR :: RdrName
extendWord8_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "extendWord8#")
extendInt8_RDR :: RdrName
extendInt8_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "extendInt8#")
extendWord16_RDR :: RdrName
extendWord16_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "extendWord16#")
extendInt16_RDR :: RdrName
extendInt16_RDR = Module -> FastString -> RdrName
varQual_RDR Module
gHC_PRIM (String -> FastString
fsLit "extendInt16#")
gen_Lift_binds :: SrcSpan -> TyCon -> (LHsBinds GhcPs, BagDerivStuff)
gen_Lift_binds :: SrcSpan -> TyCon -> (LHsBinds GhcPs, BagDerivStuff)
gen_Lift_binds loc :: SrcSpan
loc tycon :: TyCon
tycon = (LHsBind GhcPs -> LHsBinds GhcPs
forall a. a -> Bag a
unitBag LHsBind GhcPs
lift_bind, BagDerivStuff
forall a. Bag a
emptyBag)
where
lift_bind :: LHsBind GhcPs
lift_bind = Int
-> SrcSpan
-> RdrName
-> (LHsExpr GhcPs -> LHsExpr GhcPs)
-> [([LPat GhcPs], LHsExpr GhcPs)]
-> LHsBind GhcPs
mkFunBindEC 1 SrcSpan
loc RdrName
lift_RDR (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp LHsExpr GhcPs
pure_Expr)
((DataCon -> ([LPat GhcPs], LHsExpr GhcPs))
-> [DataCon] -> [([LPat GhcPs], LHsExpr GhcPs)]
forall a b. (a -> b) -> [a] -> [b]
map DataCon -> ([LPat GhcPs], LHsExpr GhcPs)
pats_etc [DataCon]
data_cons)
data_cons :: [DataCon]
data_cons = TyCon -> [DataCon]
tyConDataCons TyCon
tycon
pats_etc :: DataCon -> ([LPat GhcPs], LHsExpr GhcPs)
pats_etc data_con :: DataCon
data_con
= ([LPat GhcPs
con_pat], LHsExpr GhcPs
lift_Expr)
where
con_pat :: LPat GhcPs
con_pat = RdrName -> [RdrName] -> LPat GhcPs
nlConVarPat RdrName
data_con_RDR [RdrName]
as_needed
data_con_RDR :: RdrName
data_con_RDR = DataCon -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName DataCon
data_con
con_arity :: Int
con_arity = DataCon -> Int
dataConSourceArity DataCon
data_con
as_needed :: [RdrName]
as_needed = Int -> [RdrName] -> [RdrName]
forall a. Int -> [a] -> [a]
take Int
con_arity [RdrName]
as_RDRs
lifted_as :: [LHsExpr GhcPs]
lifted_as = String
-> (Type -> RdrName -> LHsExpr GhcPs)
-> [Type]
-> [RdrName]
-> [LHsExpr GhcPs]
forall a b c. String -> (a -> b -> c) -> [a] -> [b] -> [c]
zipWithEqual "mk_lift_app" Type -> RdrName -> LHsExpr GhcPs
mk_lift_app
[Type]
tys_needed [RdrName]
as_needed
tycon_name :: Name
tycon_name = TyCon -> Name
tyConName TyCon
tycon
is_infix :: Bool
is_infix = DataCon -> Bool
dataConIsInfix DataCon
data_con
tys_needed :: [Type]
tys_needed = DataCon -> [Type]
dataConOrigArgTys DataCon
data_con
mk_lift_app :: Type -> RdrName -> LHsExpr GhcPs
mk_lift_app ty :: Type
ty a :: RdrName
a
| Bool -> Bool
not (HasDebugCallStack => Type -> Bool
Type -> Bool
isUnliftedType Type
ty) = LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
lift_RDR)
(IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
a)
| Bool
otherwise = LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
litE_RDR)
(LHsExpr GhcPs -> LHsExpr GhcPs
primLitOp (LHsExpr GhcPs -> LHsExpr GhcPs
mkBoxExp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
a)))
where (primLitOp :: LHsExpr GhcPs -> LHsExpr GhcPs
primLitOp, mkBoxExp :: LHsExpr GhcPs -> LHsExpr GhcPs
mkBoxExp) = String
-> Type
-> (LHsExpr GhcPs -> LHsExpr GhcPs, LHsExpr GhcPs -> LHsExpr GhcPs)
primLitOps "Lift" Type
ty
pkg_name :: String
pkg_name = UnitId -> String
unitIdString (UnitId -> String) -> (Name -> UnitId) -> Name -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Module -> UnitId
moduleUnitId
(Module -> UnitId) -> (Name -> Module) -> Name -> UnitId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasDebugCallStack => Name -> Module
Name -> Module
nameModule (Name -> String) -> Name -> String
forall a b. (a -> b) -> a -> b
$ Name
tycon_name
mod_name :: String
mod_name = ModuleName -> String
moduleNameString (ModuleName -> String) -> (Name -> ModuleName) -> Name -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Module -> ModuleName
moduleName (Module -> ModuleName) -> (Name -> Module) -> Name -> ModuleName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HasDebugCallStack => Name -> Module
Name -> Module
nameModule (Name -> String) -> Name -> String
forall a b. (a -> b) -> a -> b
$ Name
tycon_name
con_name :: String
con_name = OccName -> String
occNameString (OccName -> String) -> (DataCon -> OccName) -> DataCon -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> OccName
nameOccName (Name -> OccName) -> (DataCon -> Name) -> DataCon -> OccName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataCon -> Name
dataConName (DataCon -> String) -> DataCon -> String
forall a b. (a -> b) -> a -> b
$ DataCon
data_con
conE_Expr :: LHsExpr GhcPs
conE_Expr = LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
conE_RDR)
(IdP GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP GhcPs
mkNameG_dRDR
((String -> LHsExpr GhcPs) -> [String] -> [LHsExpr GhcPs]
forall a b. (a -> b) -> [a] -> [b]
map (HsLit GhcPs -> LHsExpr GhcPs
forall (p :: Pass). HsLit (GhcPass p) -> LHsExpr (GhcPass p)
nlHsLit (HsLit GhcPs -> LHsExpr GhcPs)
-> (String -> HsLit GhcPs) -> String -> LHsExpr GhcPs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> HsLit GhcPs
forall (p :: Pass). String -> HsLit (GhcPass p)
mkHsString)
[String
pkg_name, String
mod_name, String
con_name]))
lift_Expr :: LHsExpr GhcPs
lift_Expr
| Bool
is_infix = IdP GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP GhcPs
infixApp_RDR [LHsExpr GhcPs
a1, LHsExpr GhcPs
conE_Expr, LHsExpr GhcPs
a2]
| Bool
otherwise = (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs)
-> LHsExpr GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
mk_appE_app LHsExpr GhcPs
conE_Expr [LHsExpr GhcPs]
lifted_as
(a1 :: LHsExpr GhcPs
a1:a2 :: LHsExpr GhcPs
a2:_) = [LHsExpr GhcPs]
lifted_as
mk_appE_app :: LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
mk_appE_app :: LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
mk_appE_app a :: LHsExpr GhcPs
a b :: LHsExpr GhcPs
b = IdP GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsApps RdrName
IdP GhcPs
appE_RDR [LHsExpr GhcPs
a, LHsExpr GhcPs
b]
gen_Newtype_binds :: SrcSpan
-> Class
-> [TyVar]
-> [Type]
-> Type
-> TcM (LHsBinds GhcPs, BagDerivStuff)
gen_Newtype_binds :: SrcSpan
-> Class
-> [TyVar]
-> [Type]
-> Type
-> TcM (LHsBinds GhcPs, BagDerivStuff)
gen_Newtype_binds loc :: SrcSpan
loc cls :: Class
cls inst_tvs :: [TyVar]
inst_tvs inst_tys :: [Type]
inst_tys rhs_ty :: Type
rhs_ty
= do let ats :: [TyCon]
ats = Class -> [TyCon]
classATs Class
cls
[FamInst]
atf_insts <- ASSERT( all (not . isDataFamilyTyCon) ats )
(TyCon -> IOEnv (Env TcGblEnv TcLclEnv) FamInst)
-> [TyCon] -> IOEnv (Env TcGblEnv TcLclEnv) [FamInst]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM TyCon -> IOEnv (Env TcGblEnv TcLclEnv) FamInst
mk_atf_inst [TyCon]
ats
(LHsBinds GhcPs, BagDerivStuff)
-> TcM (LHsBinds GhcPs, BagDerivStuff)
forall (m :: * -> *) a. Monad m => a -> m a
return ( [LHsBind GhcPs] -> LHsBinds GhcPs
forall a. [a] -> Bag a
listToBag ([LHsBind GhcPs] -> LHsBinds GhcPs)
-> [LHsBind GhcPs] -> LHsBinds GhcPs
forall a b. (a -> b) -> a -> b
$ (TyVar -> LHsBind GhcPs) -> [TyVar] -> [LHsBind GhcPs]
forall a b. (a -> b) -> [a] -> [b]
map TyVar -> LHsBind GhcPs
mk_bind (Class -> [TyVar]
classMethods Class
cls)
, [DerivStuff] -> BagDerivStuff
forall a. [a] -> Bag a
listToBag ([DerivStuff] -> BagDerivStuff) -> [DerivStuff] -> BagDerivStuff
forall a b. (a -> b) -> a -> b
$ (FamInst -> DerivStuff) -> [FamInst] -> [DerivStuff]
forall a b. (a -> b) -> [a] -> [b]
map FamInst -> DerivStuff
DerivFamInst [FamInst]
atf_insts )
where
mk_bind :: Id -> LHsBind GhcPs
mk_bind :: TyVar -> LHsBind GhcPs
mk_bind meth_id :: TyVar
meth_id
= Located RdrName -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsBind GhcPs
mkRdrFunBind (SrcSpan -> RdrName -> Located RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc RdrName
meth_RDR) [HsMatchContext (NameOrRdrName (IdP GhcPs))
-> [LPat GhcPs] -> LHsExpr GhcPs -> LMatch GhcPs (LHsExpr GhcPs)
forall (p :: Pass) (body :: * -> *).
HsMatchContext (NameOrRdrName (IdP (GhcPass p)))
-> [LPat (GhcPass p)]
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkSimpleMatch
(Located RdrName -> HsMatchContext RdrName
forall id. Located id -> HsMatchContext id
mkPrefixFunRhs (SrcSpan -> RdrName -> Located RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc RdrName
meth_RDR))
[] LHsExpr GhcPs
rhs_expr]
where
Pair from_ty :: Type
from_ty to_ty :: Type
to_ty = Class -> [TyVar] -> [Type] -> Type -> TyVar -> Pair Type
mkCoerceClassMethEqn Class
cls [TyVar]
inst_tvs [Type]
inst_tys Type
rhs_ty TyVar
meth_id
(_, _, from_tau :: Type
from_tau) = Type -> ([TyVar], [Type], Type)
tcSplitSigmaTy Type
from_ty
(_, _, to_tau :: Type
to_tau) = Type -> ([TyVar], [Type], Type)
tcSplitSigmaTy Type
to_ty
meth_RDR :: RdrName
meth_RDR = TyVar -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName TyVar
meth_id
rhs_expr :: LHsExpr GhcPs
rhs_expr = IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar (TyVar -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName TyVar
coerceId)
LHsExpr GhcPs -> Type -> LHsExpr GhcPs
`nlHsAppType` Type
from_tau
LHsExpr GhcPs -> Type -> LHsExpr GhcPs
`nlHsAppType` Type
to_tau
LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
`nlHsApp` LHsExpr GhcPs
meth_app
LHsExpr GhcPs -> Type -> LHsExpr GhcPs
`nlExprWithTySig` Type
to_ty
meth_app :: LHsExpr GhcPs
meth_app = (LHsExpr GhcPs -> Type -> LHsExpr GhcPs)
-> LHsExpr GhcPs -> [Type] -> LHsExpr GhcPs
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' LHsExpr GhcPs -> Type -> LHsExpr GhcPs
nlHsAppType (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
meth_RDR) ([Type] -> LHsExpr GhcPs) -> [Type] -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$
TyCon -> [Type] -> [Type]
filterOutInferredTypes (Class -> TyCon
classTyCon Class
cls) [Type]
underlying_inst_tys
mk_atf_inst :: TyCon -> TcM FamInst
mk_atf_inst :: TyCon -> IOEnv (Env TcGblEnv TcLclEnv) FamInst
mk_atf_inst fam_tc :: TyCon
fam_tc = do
Name
rep_tc_name <- Located Name -> [Type] -> TcM Name
newFamInstTyConName (SrcSpan -> Name -> Located Name
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc (TyCon -> Name
tyConName TyCon
fam_tc))
[Type]
rep_lhs_tys
let axiom :: CoAxiom Unbranched
axiom = Role
-> Name
-> [TyVar]
-> [TyVar]
-> [TyVar]
-> TyCon
-> [Type]
-> Type
-> CoAxiom Unbranched
mkSingleCoAxiom Role
Nominal Name
rep_tc_name [TyVar]
rep_tvs' [] [TyVar]
rep_cvs'
TyCon
fam_tc [Type]
rep_lhs_tys Type
rep_rhs_ty
TyCon -> CoAxBranch -> TcM ()
checkValidCoAxBranch TyCon
fam_tc (CoAxiom Unbranched -> CoAxBranch
coAxiomSingleBranch CoAxiom Unbranched
axiom)
FamFlavor
-> CoAxiom Unbranched -> IOEnv (Env TcGblEnv TcLclEnv) FamInst
newFamInst FamFlavor
SynFamilyInst CoAxiom Unbranched
axiom
where
cls_tvs :: [TyVar]
cls_tvs = Class -> [TyVar]
classTyVars Class
cls
in_scope :: InScopeSet
in_scope = VarSet -> InScopeSet
mkInScopeSet (VarSet -> InScopeSet) -> VarSet -> InScopeSet
forall a b. (a -> b) -> a -> b
$ [TyVar] -> VarSet
mkVarSet [TyVar]
inst_tvs
lhs_env :: TvSubstEnv
lhs_env = [TyVar] -> [Type] -> TvSubstEnv
HasDebugCallStack => [TyVar] -> [Type] -> TvSubstEnv
zipTyEnv [TyVar]
cls_tvs [Type]
inst_tys
lhs_subst :: TCvSubst
lhs_subst = InScopeSet -> TvSubstEnv -> TCvSubst
mkTvSubst InScopeSet
in_scope TvSubstEnv
lhs_env
rhs_env :: TvSubstEnv
rhs_env = [TyVar] -> [Type] -> TvSubstEnv
HasDebugCallStack => [TyVar] -> [Type] -> TvSubstEnv
zipTyEnv [TyVar]
cls_tvs [Type]
underlying_inst_tys
rhs_subst :: TCvSubst
rhs_subst = InScopeSet -> TvSubstEnv -> TCvSubst
mkTvSubst InScopeSet
in_scope TvSubstEnv
rhs_env
fam_tvs :: [TyVar]
fam_tvs = TyCon -> [TyVar]
tyConTyVars TyCon
fam_tc
rep_lhs_tys :: [Type]
rep_lhs_tys = TCvSubst -> [TyVar] -> [Type]
substTyVars TCvSubst
lhs_subst [TyVar]
fam_tvs
rep_rhs_tys :: [Type]
rep_rhs_tys = TCvSubst -> [TyVar] -> [Type]
substTyVars TCvSubst
rhs_subst [TyVar]
fam_tvs
rep_rhs_ty :: Type
rep_rhs_ty = TyCon -> [Type] -> Type
mkTyConApp TyCon
fam_tc [Type]
rep_rhs_tys
rep_tcvs :: [TyVar]
rep_tcvs = [Type] -> [TyVar]
tyCoVarsOfTypesList [Type]
rep_lhs_tys
(rep_tvs :: [TyVar]
rep_tvs, rep_cvs :: [TyVar]
rep_cvs) = (TyVar -> Bool) -> [TyVar] -> ([TyVar], [TyVar])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition TyVar -> Bool
isTyVar [TyVar]
rep_tcvs
rep_tvs' :: [TyVar]
rep_tvs' = [TyVar] -> [TyVar]
scopedSort [TyVar]
rep_tvs
rep_cvs' :: [TyVar]
rep_cvs' = [TyVar] -> [TyVar]
scopedSort [TyVar]
rep_cvs
underlying_inst_tys :: [Type]
underlying_inst_tys :: [Type]
underlying_inst_tys = [Type] -> Type -> [Type]
forall a. [a] -> a -> [a]
changeLast [Type]
inst_tys Type
rhs_ty
nlHsAppType :: LHsExpr GhcPs -> Type -> LHsExpr GhcPs
nlHsAppType :: LHsExpr GhcPs -> Type -> LHsExpr GhcPs
nlHsAppType e :: LHsExpr GhcPs
e s :: Type
s = SrcSpanLess (LHsExpr GhcPs) -> LHsExpr GhcPs
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc (XAppTypeE GhcPs
-> LHsExpr GhcPs -> LHsWcType (NoGhcTc GhcPs) -> HsExpr GhcPs
forall p.
XAppTypeE p -> LHsExpr p -> LHsWcType (NoGhcTc p) -> HsExpr p
HsAppType XAppTypeE GhcPs
NoExt
noExt LHsExpr GhcPs
e LHsWcType (NoGhcTc GhcPs)
HsWildCardBndrs GhcPs (LHsType GhcPs)
hs_ty)
where
hs_ty :: HsWildCardBndrs GhcPs (LHsType GhcPs)
hs_ty = LHsType GhcPs -> HsWildCardBndrs GhcPs (LHsType GhcPs)
forall thing. thing -> HsWildCardBndrs GhcPs thing
mkHsWildCardBndrs (LHsType GhcPs -> HsWildCardBndrs GhcPs (LHsType GhcPs))
-> LHsType GhcPs -> HsWildCardBndrs GhcPs (LHsType GhcPs)
forall a b. (a -> b) -> a -> b
$ PprPrec -> LHsType GhcPs -> LHsType GhcPs
forall (p :: Pass).
PprPrec -> LHsType (GhcPass p) -> LHsType (GhcPass p)
parenthesizeHsType PprPrec
appPrec (Type -> LHsType GhcPs
typeToLHsType Type
s)
nlExprWithTySig :: LHsExpr GhcPs -> Type -> LHsExpr GhcPs
nlExprWithTySig :: LHsExpr GhcPs -> Type -> LHsExpr GhcPs
nlExprWithTySig e :: LHsExpr GhcPs
e s :: Type
s = SrcSpanLess (LHsExpr GhcPs) -> LHsExpr GhcPs
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc (SrcSpanLess (LHsExpr GhcPs) -> LHsExpr GhcPs)
-> SrcSpanLess (LHsExpr GhcPs) -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$ XExprWithTySig GhcPs
-> LHsExpr GhcPs -> LHsSigWcType (NoGhcTc GhcPs) -> HsExpr GhcPs
forall p.
XExprWithTySig p
-> LHsExpr p -> LHsSigWcType (NoGhcTc p) -> HsExpr p
ExprWithTySig XExprWithTySig GhcPs
NoExt
noExt (PprPrec -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (p :: Pass).
PprPrec -> LHsExpr (GhcPass p) -> LHsExpr (GhcPass p)
parenthesizeHsExpr PprPrec
sigPrec LHsExpr GhcPs
e) LHsSigWcType (NoGhcTc GhcPs)
LHsSigWcType GhcPs
hs_ty
where
hs_ty :: LHsSigWcType GhcPs
hs_ty = LHsType GhcPs -> LHsSigWcType GhcPs
mkLHsSigWcType (Type -> LHsType GhcPs
typeToLHsType Type
s)
mkCoerceClassMethEqn :: Class
-> [TyVar]
-> [Type]
-> Type
-> Id
-> Pair Type
mkCoerceClassMethEqn :: Class -> [TyVar] -> [Type] -> Type -> TyVar -> Pair Type
mkCoerceClassMethEqn cls :: Class
cls inst_tvs :: [TyVar]
inst_tvs inst_tys :: [Type]
inst_tys rhs_ty :: Type
rhs_ty id :: TyVar
id
= Type -> Type -> Pair Type
forall a. a -> a -> Pair a
Pair (HasCallStack => TCvSubst -> Type -> Type
TCvSubst -> Type -> Type
substTy TCvSubst
rhs_subst Type
user_meth_ty)
(HasCallStack => TCvSubst -> Type -> Type
TCvSubst -> Type -> Type
substTy TCvSubst
lhs_subst Type
user_meth_ty)
where
cls_tvs :: [TyVar]
cls_tvs = Class -> [TyVar]
classTyVars Class
cls
in_scope :: InScopeSet
in_scope = VarSet -> InScopeSet
mkInScopeSet (VarSet -> InScopeSet) -> VarSet -> InScopeSet
forall a b. (a -> b) -> a -> b
$ [TyVar] -> VarSet
mkVarSet [TyVar]
inst_tvs
lhs_subst :: TCvSubst
lhs_subst = InScopeSet -> TvSubstEnv -> TCvSubst
mkTvSubst InScopeSet
in_scope ([TyVar] -> [Type] -> TvSubstEnv
HasDebugCallStack => [TyVar] -> [Type] -> TvSubstEnv
zipTyEnv [TyVar]
cls_tvs [Type]
inst_tys)
rhs_subst :: TCvSubst
rhs_subst = InScopeSet -> TvSubstEnv -> TCvSubst
mkTvSubst InScopeSet
in_scope ([TyVar] -> [Type] -> TvSubstEnv
HasDebugCallStack => [TyVar] -> [Type] -> TvSubstEnv
zipTyEnv [TyVar]
cls_tvs ([Type] -> Type -> [Type]
forall a. [a] -> a -> [a]
changeLast [Type]
inst_tys Type
rhs_ty))
(_class_tvs :: [TyVar]
_class_tvs, _class_constraint :: Type
_class_constraint, user_meth_ty :: Type
user_meth_ty)
= Type -> ([TyVar], Type, Type)
tcSplitMethodTy (TyVar -> Type
varType TyVar
id)
genAuxBindSpec :: DynFlags -> SrcSpan -> AuxBindSpec
-> (LHsBind GhcPs, LSig GhcPs)
genAuxBindSpec :: DynFlags -> SrcSpan -> AuxBindSpec -> (LHsBind GhcPs, LSig GhcPs)
genAuxBindSpec dflags :: DynFlags
dflags loc :: SrcSpan
loc (DerivCon2Tag tycon :: TyCon
tycon)
= (Int
-> SrcSpan
-> RdrName
-> [([LPat GhcPs], LHsExpr GhcPs)]
-> LHsBind GhcPs
mkFunBindSE 0 SrcSpan
loc RdrName
rdr_name [([LPat GhcPs], LHsExpr GhcPs)]
eqns,
SrcSpan -> Sig GhcPs -> LSig GhcPs
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc (XTypeSig GhcPs
-> [Located (IdP GhcPs)] -> LHsSigWcType GhcPs -> Sig GhcPs
forall pass.
XTypeSig pass
-> [Located (IdP pass)] -> LHsSigWcType pass -> Sig pass
TypeSig XTypeSig GhcPs
NoExt
noExt [SrcSpan -> RdrName -> Located RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc RdrName
rdr_name] LHsSigWcType GhcPs
sig_ty))
where
rdr_name :: RdrName
rdr_name = DynFlags -> TyCon -> RdrName
con2tag_RDR DynFlags
dflags TyCon
tycon
sig_ty :: LHsSigWcType GhcPs
sig_ty = LHsType GhcPs -> LHsSigWcType GhcPs
mkLHsSigWcType (LHsType GhcPs -> LHsSigWcType GhcPs)
-> LHsType GhcPs -> LHsSigWcType GhcPs
forall a b. (a -> b) -> a -> b
$ SrcSpan -> HsType GhcPs -> LHsType GhcPs
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc (HsType GhcPs -> LHsType GhcPs) -> HsType GhcPs -> LHsType GhcPs
forall a b. (a -> b) -> a -> b
$ XXType GhcPs -> HsType GhcPs
forall pass. XXType pass -> HsType pass
XHsType (XXType GhcPs -> HsType GhcPs) -> XXType GhcPs -> HsType GhcPs
forall a b. (a -> b) -> a -> b
$ Type -> XXType GhcPs
Type -> NewHsTypeX
NHsCoreTy (Type -> XXType GhcPs) -> Type -> XXType GhcPs
forall a b. (a -> b) -> a -> b
$
[TyVar] -> [Type] -> Type -> Type
mkSpecSigmaTy (TyCon -> [TyVar]
tyConTyVars TyCon
tycon) (TyCon -> [Type]
tyConStupidTheta TyCon
tycon) (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
TyCon -> Type
mkParentType TyCon
tycon Type -> Type -> Type
`mkFunTy` Type
intPrimTy
lots_of_constructors :: Bool
lots_of_constructors = TyCon -> Int
tyConFamilySize TyCon
tycon Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 8
eqns :: [([LPat GhcPs], LHsExpr GhcPs)]
eqns | Bool
lots_of_constructors = [([LPat GhcPs], LHsExpr GhcPs)
get_tag_eqn]
| Bool
otherwise = (DataCon -> ([LPat GhcPs], LHsExpr GhcPs))
-> [DataCon] -> [([LPat GhcPs], LHsExpr GhcPs)]
forall a b. (a -> b) -> [a] -> [b]
map DataCon -> ([LPat GhcPs], LHsExpr GhcPs)
mk_eqn (TyCon -> [DataCon]
tyConDataCons TyCon
tycon)
get_tag_eqn :: ([LPat GhcPs], LHsExpr GhcPs)
get_tag_eqn = ([IdP GhcPs -> LPat GhcPs
forall (p :: Pass). IdP (GhcPass p) -> LPat (GhcPass p)
nlVarPat RdrName
IdP GhcPs
a_RDR], LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
getTag_RDR) LHsExpr GhcPs
a_Expr)
mk_eqn :: DataCon -> ([LPat GhcPs], LHsExpr GhcPs)
mk_eqn :: DataCon -> ([LPat GhcPs], LHsExpr GhcPs)
mk_eqn con :: DataCon
con = ([DataCon -> LPat GhcPs
nlWildConPat DataCon
con],
HsLit GhcPs -> LHsExpr GhcPs
forall (p :: Pass). HsLit (GhcPass p) -> LHsExpr (GhcPass p)
nlHsLit (XHsIntPrim GhcPs -> Integer -> HsLit GhcPs
forall x. XHsIntPrim x -> Integer -> HsLit x
HsIntPrim SourceText
XHsIntPrim GhcPs
NoSourceText
(Int -> Integer
forall a. Integral a => a -> Integer
toInteger ((DataCon -> Int
dataConTag DataCon
con) Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
fIRST_TAG))))
genAuxBindSpec dflags :: DynFlags
dflags loc :: SrcSpan
loc (DerivTag2Con tycon :: TyCon
tycon)
= (Int
-> SrcSpan
-> RdrName
-> [([LPat GhcPs], LHsExpr GhcPs)]
-> LHsBind GhcPs
mkFunBindSE 0 SrcSpan
loc RdrName
rdr_name
[([RdrName -> [RdrName] -> LPat GhcPs
nlConVarPat RdrName
intDataCon_RDR [RdrName
a_RDR]],
LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
tagToEnum_RDR) LHsExpr GhcPs
a_Expr)],
SrcSpan -> Sig GhcPs -> LSig GhcPs
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc (XTypeSig GhcPs
-> [Located (IdP GhcPs)] -> LHsSigWcType GhcPs -> Sig GhcPs
forall pass.
XTypeSig pass
-> [Located (IdP pass)] -> LHsSigWcType pass -> Sig pass
TypeSig XTypeSig GhcPs
NoExt
noExt [SrcSpan -> RdrName -> Located RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc RdrName
rdr_name] LHsSigWcType GhcPs
sig_ty))
where
sig_ty :: LHsSigWcType GhcPs
sig_ty = LHsType GhcPs -> LHsSigWcType GhcPs
mkLHsSigWcType (LHsType GhcPs -> LHsSigWcType GhcPs)
-> LHsType GhcPs -> LHsSigWcType GhcPs
forall a b. (a -> b) -> a -> b
$ SrcSpan -> HsType GhcPs -> LHsType GhcPs
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc (HsType GhcPs -> LHsType GhcPs) -> HsType GhcPs -> LHsType GhcPs
forall a b. (a -> b) -> a -> b
$
XXType GhcPs -> HsType GhcPs
forall pass. XXType pass -> HsType pass
XHsType (XXType GhcPs -> HsType GhcPs) -> XXType GhcPs -> HsType GhcPs
forall a b. (a -> b) -> a -> b
$ Type -> XXType GhcPs
Type -> NewHsTypeX
NHsCoreTy (Type -> XXType GhcPs) -> Type -> XXType GhcPs
forall a b. (a -> b) -> a -> b
$ [TyVar] -> Type -> Type
mkSpecForAllTys (TyCon -> [TyVar]
tyConTyVars TyCon
tycon) (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
Type
intTy Type -> Type -> Type
`mkFunTy` TyCon -> Type
mkParentType TyCon
tycon
rdr_name :: RdrName
rdr_name = DynFlags -> TyCon -> RdrName
tag2con_RDR DynFlags
dflags TyCon
tycon
genAuxBindSpec dflags :: DynFlags
dflags loc :: SrcSpan
loc (DerivMaxTag tycon :: TyCon
tycon)
= (SrcSpan -> RdrName -> LHsExpr GhcPs -> LHsBind GhcPs
mkHsVarBind SrcSpan
loc RdrName
rdr_name LHsExpr GhcPs
rhs,
SrcSpan -> Sig GhcPs -> LSig GhcPs
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc (XTypeSig GhcPs
-> [Located (IdP GhcPs)] -> LHsSigWcType GhcPs -> Sig GhcPs
forall pass.
XTypeSig pass
-> [Located (IdP pass)] -> LHsSigWcType pass -> Sig pass
TypeSig XTypeSig GhcPs
NoExt
noExt [SrcSpan -> RdrName -> Located RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc RdrName
rdr_name] LHsSigWcType GhcPs
sig_ty))
where
rdr_name :: RdrName
rdr_name = DynFlags -> TyCon -> RdrName
maxtag_RDR DynFlags
dflags TyCon
tycon
sig_ty :: LHsSigWcType GhcPs
sig_ty = LHsType GhcPs -> LHsSigWcType GhcPs
mkLHsSigWcType (SrcSpan -> HsType GhcPs -> LHsType GhcPs
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc (XXType GhcPs -> HsType GhcPs
forall pass. XXType pass -> HsType pass
XHsType (Type -> NewHsTypeX
NHsCoreTy Type
intTy)))
rhs :: LHsExpr GhcPs
rhs = LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
intDataCon_RDR)
(HsLit GhcPs -> LHsExpr GhcPs
forall (p :: Pass). HsLit (GhcPass p) -> LHsExpr (GhcPass p)
nlHsLit (XHsIntPrim GhcPs -> Integer -> HsLit GhcPs
forall x. XHsIntPrim x -> Integer -> HsLit x
HsIntPrim SourceText
XHsIntPrim GhcPs
NoSourceText Integer
max_tag))
max_tag :: Integer
max_tag = case (TyCon -> [DataCon]
tyConDataCons TyCon
tycon) of
data_cons :: [DataCon]
data_cons -> Int -> Integer
forall a. Integral a => a -> Integer
toInteger (([DataCon] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [DataCon]
data_cons) Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
fIRST_TAG)
type SeparateBagsDerivStuff =
( Bag (LHsBind GhcPs, LSig GhcPs)
, Bag (FamInst) )
genAuxBinds :: DynFlags -> SrcSpan -> BagDerivStuff -> SeparateBagsDerivStuff
genAuxBinds :: DynFlags -> SrcSpan -> BagDerivStuff -> SeparateBagsDerivStuff
genAuxBinds dflags :: DynFlags
dflags loc :: SrcSpan
loc b :: BagDerivStuff
b = BagDerivStuff -> SeparateBagsDerivStuff
genAuxBinds' BagDerivStuff
b2 where
(b1 :: Bag AuxBindSpec
b1,b2 :: BagDerivStuff
b2) = (DerivStuff -> Either AuxBindSpec DerivStuff)
-> BagDerivStuff -> (Bag AuxBindSpec, BagDerivStuff)
forall a b c. (a -> Either b c) -> Bag a -> (Bag b, Bag c)
partitionBagWith DerivStuff -> Either AuxBindSpec DerivStuff
splitDerivAuxBind BagDerivStuff
b
splitDerivAuxBind :: DerivStuff -> Either AuxBindSpec DerivStuff
splitDerivAuxBind (DerivAuxBind x :: AuxBindSpec
x) = AuxBindSpec -> Either AuxBindSpec DerivStuff
forall a b. a -> Either a b
Left AuxBindSpec
x
splitDerivAuxBind x :: DerivStuff
x = DerivStuff -> Either AuxBindSpec DerivStuff
forall a b. b -> Either a b
Right DerivStuff
x
rm_dups :: Bag AuxBindSpec -> Bag AuxBindSpec
rm_dups = (AuxBindSpec -> Bag AuxBindSpec -> Bag AuxBindSpec)
-> Bag AuxBindSpec -> Bag AuxBindSpec -> Bag AuxBindSpec
forall a r. (a -> r -> r) -> r -> Bag a -> r
foldrBag AuxBindSpec -> Bag AuxBindSpec -> Bag AuxBindSpec
forall a. Eq a => a -> Bag a -> Bag a
dup_check Bag AuxBindSpec
forall a. Bag a
emptyBag
dup_check :: a -> Bag a -> Bag a
dup_check a :: a
a b :: Bag a
b = if (a -> Bool) -> Bag a -> Bool
forall a. (a -> Bool) -> Bag a -> Bool
anyBag (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
a) Bag a
b then Bag a
b else a -> Bag a -> Bag a
forall a. a -> Bag a -> Bag a
consBag a
a Bag a
b
genAuxBinds' :: BagDerivStuff -> SeparateBagsDerivStuff
genAuxBinds' :: BagDerivStuff -> SeparateBagsDerivStuff
genAuxBinds' = (DerivStuff -> SeparateBagsDerivStuff -> SeparateBagsDerivStuff)
-> SeparateBagsDerivStuff
-> BagDerivStuff
-> SeparateBagsDerivStuff
forall a r. (a -> r -> r) -> r -> Bag a -> r
foldrBag DerivStuff -> SeparateBagsDerivStuff -> SeparateBagsDerivStuff
f ( (AuxBindSpec -> (LHsBind GhcPs, LSig GhcPs))
-> Bag AuxBindSpec -> Bag (LHsBind GhcPs, LSig GhcPs)
forall a b. (a -> b) -> Bag a -> Bag b
mapBag (DynFlags -> SrcSpan -> AuxBindSpec -> (LHsBind GhcPs, LSig GhcPs)
genAuxBindSpec DynFlags
dflags SrcSpan
loc) (Bag AuxBindSpec -> Bag AuxBindSpec
rm_dups Bag AuxBindSpec
b1)
, Bag FamInst
forall a. Bag a
emptyBag )
f :: DerivStuff -> SeparateBagsDerivStuff -> SeparateBagsDerivStuff
f :: DerivStuff -> SeparateBagsDerivStuff -> SeparateBagsDerivStuff
f (DerivAuxBind _) = String -> SeparateBagsDerivStuff -> SeparateBagsDerivStuff
forall a. String -> a
panic "genAuxBinds'"
f (DerivHsBind b :: (LHsBind GhcPs, LSig GhcPs)
b) = (LHsBind GhcPs, LSig GhcPs)
-> SeparateBagsDerivStuff -> SeparateBagsDerivStuff
forall a b. a -> (Bag a, b) -> (Bag a, b)
add1 (LHsBind GhcPs, LSig GhcPs)
b
f (DerivFamInst t :: FamInst
t) = FamInst -> SeparateBagsDerivStuff -> SeparateBagsDerivStuff
forall a a. a -> (a, Bag a) -> (a, Bag a)
add2 FamInst
t
add1 :: a -> (Bag a, b) -> (Bag a, b)
add1 x :: a
x (a :: Bag a
a,b :: b
b) = (a
x a -> Bag a -> Bag a
forall a. a -> Bag a -> Bag a
`consBag` Bag a
a,b
b)
add2 :: a -> (a, Bag a) -> (a, Bag a)
add2 x :: a
x (a :: a
a,b :: Bag a
b) = (a
a,a
x a -> Bag a -> Bag a
forall a. a -> Bag a -> Bag a
`consBag` Bag a
b)
mkParentType :: TyCon -> Type
mkParentType :: TyCon -> Type
mkParentType tc :: TyCon
tc
= case TyCon -> Maybe (TyCon, [Type])
tyConFamInst_maybe TyCon
tc of
Nothing -> TyCon -> [Type] -> Type
mkTyConApp TyCon
tc ([TyVar] -> [Type]
mkTyVarTys (TyCon -> [TyVar]
tyConTyVars TyCon
tc))
Just (fam_tc :: TyCon
fam_tc,tys :: [Type]
tys) -> TyCon -> [Type] -> Type
mkTyConApp TyCon
fam_tc [Type]
tys
mkFunBindSE :: Arity -> SrcSpan -> RdrName
-> [([LPat GhcPs], LHsExpr GhcPs)]
-> LHsBind GhcPs
mkFunBindSE :: Int
-> SrcSpan
-> RdrName
-> [([LPat GhcPs], LHsExpr GhcPs)]
-> LHsBind GhcPs
mkFunBindSE arity :: Int
arity loc :: SrcSpan
loc fun :: RdrName
fun pats_and_exprs :: [([LPat GhcPs], LHsExpr GhcPs)]
pats_and_exprs
= Int
-> Located RdrName
-> [LMatch GhcPs (LHsExpr GhcPs)]
-> LHsBind GhcPs
mkRdrFunBindSE Int
arity (SrcSpan -> RdrName -> Located RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc RdrName
fun) [LMatch GhcPs (LHsExpr GhcPs)]
matches
where
matches :: [LMatch GhcPs (LHsExpr GhcPs)]
matches = [HsMatchContext (NameOrRdrName (IdP GhcPs))
-> [LPat GhcPs]
-> LHsExpr GhcPs
-> Located (HsLocalBinds GhcPs)
-> LMatch GhcPs (LHsExpr GhcPs)
forall (p :: Pass).
HsMatchContext (NameOrRdrName (IdP (GhcPass p)))
-> [LPat (GhcPass p)]
-> LHsExpr (GhcPass p)
-> Located (HsLocalBinds (GhcPass p))
-> LMatch (GhcPass p) (LHsExpr (GhcPass p))
mkMatch (Located RdrName -> HsMatchContext RdrName
forall id. Located id -> HsMatchContext id
mkPrefixFunRhs (SrcSpan -> RdrName -> Located RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc RdrName
fun))
((LPat GhcPs -> LPat GhcPs) -> [LPat GhcPs] -> [LPat GhcPs]
forall a b. (a -> b) -> [a] -> [b]
map (PprPrec -> LPat GhcPs -> LPat GhcPs
forall (p :: Pass). PprPrec -> LPat (GhcPass p) -> LPat (GhcPass p)
parenthesizePat PprPrec
appPrec) [LPat GhcPs]
p) LHsExpr GhcPs
e
(SrcSpanLess (Located (HsLocalBinds GhcPs))
-> Located (HsLocalBinds GhcPs)
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc SrcSpanLess (Located (HsLocalBinds GhcPs))
forall (a :: Pass) (b :: Pass).
HsLocalBindsLR (GhcPass a) (GhcPass b)
emptyLocalBinds)
| (p :: [LPat GhcPs]
p,e :: LHsExpr GhcPs
e) <-[([LPat GhcPs], LHsExpr GhcPs)]
pats_and_exprs]
mkRdrFunBind :: Located RdrName -> [LMatch GhcPs (LHsExpr GhcPs)]
-> LHsBind GhcPs
mkRdrFunBind :: Located RdrName -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsBind GhcPs
mkRdrFunBind fun :: Located RdrName
fun@(L loc :: SrcSpan
loc _fun_rdr :: RdrName
_fun_rdr) matches :: [LMatch GhcPs (LHsExpr GhcPs)]
matches
= SrcSpan -> HsBind GhcPs -> LHsBind GhcPs
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc (Located RdrName -> [LMatch GhcPs (LHsExpr GhcPs)] -> HsBind GhcPs
mkFunBind Located RdrName
fun [LMatch GhcPs (LHsExpr GhcPs)]
matches)
mkFunBindEC :: Arity -> SrcSpan -> RdrName
-> (LHsExpr GhcPs -> LHsExpr GhcPs)
-> [([LPat GhcPs], LHsExpr GhcPs)]
-> LHsBind GhcPs
mkFunBindEC :: Int
-> SrcSpan
-> RdrName
-> (LHsExpr GhcPs -> LHsExpr GhcPs)
-> [([LPat GhcPs], LHsExpr GhcPs)]
-> LHsBind GhcPs
mkFunBindEC arity :: Int
arity loc :: SrcSpan
loc fun :: RdrName
fun catch_all :: LHsExpr GhcPs -> LHsExpr GhcPs
catch_all pats_and_exprs :: [([LPat GhcPs], LHsExpr GhcPs)]
pats_and_exprs
= Int
-> (LHsExpr GhcPs -> LHsExpr GhcPs)
-> Located RdrName
-> [LMatch GhcPs (LHsExpr GhcPs)]
-> LHsBind GhcPs
mkRdrFunBindEC Int
arity LHsExpr GhcPs -> LHsExpr GhcPs
catch_all (SrcSpan -> RdrName -> Located RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc RdrName
fun) [LMatch GhcPs (LHsExpr GhcPs)]
matches
where
matches :: [LMatch GhcPs (LHsExpr GhcPs)]
matches = [ HsMatchContext (NameOrRdrName (IdP GhcPs))
-> [LPat GhcPs]
-> LHsExpr GhcPs
-> Located (HsLocalBinds GhcPs)
-> LMatch GhcPs (LHsExpr GhcPs)
forall (p :: Pass).
HsMatchContext (NameOrRdrName (IdP (GhcPass p)))
-> [LPat (GhcPass p)]
-> LHsExpr (GhcPass p)
-> Located (HsLocalBinds (GhcPass p))
-> LMatch (GhcPass p) (LHsExpr (GhcPass p))
mkMatch (Located RdrName -> HsMatchContext RdrName
forall id. Located id -> HsMatchContext id
mkPrefixFunRhs (SrcSpan -> RdrName -> Located RdrName
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc RdrName
fun))
((LPat GhcPs -> LPat GhcPs) -> [LPat GhcPs] -> [LPat GhcPs]
forall a b. (a -> b) -> [a] -> [b]
map (PprPrec -> LPat GhcPs -> LPat GhcPs
forall (p :: Pass). PprPrec -> LPat (GhcPass p) -> LPat (GhcPass p)
parenthesizePat PprPrec
appPrec) [LPat GhcPs]
p) LHsExpr GhcPs
e
(SrcSpanLess (Located (HsLocalBinds GhcPs))
-> Located (HsLocalBinds GhcPs)
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc SrcSpanLess (Located (HsLocalBinds GhcPs))
forall (a :: Pass) (b :: Pass).
HsLocalBindsLR (GhcPass a) (GhcPass b)
emptyLocalBinds)
| (p :: [LPat GhcPs]
p,e :: LHsExpr GhcPs
e) <- [([LPat GhcPs], LHsExpr GhcPs)]
pats_and_exprs ]
mkRdrFunBindEC :: Arity
-> (LHsExpr GhcPs -> LHsExpr GhcPs)
-> Located RdrName
-> [LMatch GhcPs (LHsExpr GhcPs)]
-> LHsBind GhcPs
mkRdrFunBindEC :: Int
-> (LHsExpr GhcPs -> LHsExpr GhcPs)
-> Located RdrName
-> [LMatch GhcPs (LHsExpr GhcPs)]
-> LHsBind GhcPs
mkRdrFunBindEC arity :: Int
arity catch_all :: LHsExpr GhcPs -> LHsExpr GhcPs
catch_all
fun :: Located RdrName
fun@(L loc :: SrcSpan
loc _fun_rdr :: RdrName
_fun_rdr) matches :: [LMatch GhcPs (LHsExpr GhcPs)]
matches = SrcSpan -> HsBind GhcPs -> LHsBind GhcPs
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc (Located RdrName -> [LMatch GhcPs (LHsExpr GhcPs)] -> HsBind GhcPs
mkFunBind Located RdrName
fun [LMatch GhcPs (LHsExpr GhcPs)]
matches')
where
matches' :: [LMatch GhcPs (LHsExpr GhcPs)]
matches' = if [LMatch GhcPs (LHsExpr GhcPs)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LMatch GhcPs (LHsExpr GhcPs)]
matches
then [HsMatchContext (NameOrRdrName (IdP GhcPs))
-> [LPat GhcPs]
-> LHsExpr GhcPs
-> Located (HsLocalBinds GhcPs)
-> LMatch GhcPs (LHsExpr GhcPs)
forall (p :: Pass).
HsMatchContext (NameOrRdrName (IdP (GhcPass p)))
-> [LPat (GhcPass p)]
-> LHsExpr (GhcPass p)
-> Located (HsLocalBinds (GhcPass p))
-> LMatch (GhcPass p) (LHsExpr (GhcPass p))
mkMatch (Located RdrName -> HsMatchContext RdrName
forall id. Located id -> HsMatchContext id
mkPrefixFunRhs Located RdrName
fun)
(Int -> LPat GhcPs -> [LPat GhcPs]
forall a. Int -> a -> [a]
replicate (Int
arity Int -> Int -> Int
forall a. Num a => a -> a -> a
- 1) LPat GhcPs
nlWildPat [LPat GhcPs] -> [LPat GhcPs] -> [LPat GhcPs]
forall a. [a] -> [a] -> [a]
++ [LPat GhcPs
z_Pat])
(LHsExpr GhcPs -> LHsExpr GhcPs
catch_all (LHsExpr GhcPs -> LHsExpr GhcPs) -> LHsExpr GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$ LHsExpr GhcPs -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsExpr GhcPs
nlHsCase LHsExpr GhcPs
z_Expr [])
(SrcSpanLess (Located (HsLocalBinds GhcPs))
-> Located (HsLocalBinds GhcPs)
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc SrcSpanLess (Located (HsLocalBinds GhcPs))
forall (a :: Pass) (b :: Pass).
HsLocalBindsLR (GhcPass a) (GhcPass b)
emptyLocalBinds)]
else [LMatch GhcPs (LHsExpr GhcPs)]
matches
mkRdrFunBindSE :: Arity -> Located RdrName ->
[LMatch GhcPs (LHsExpr GhcPs)] -> LHsBind GhcPs
mkRdrFunBindSE :: Int
-> Located RdrName
-> [LMatch GhcPs (LHsExpr GhcPs)]
-> LHsBind GhcPs
mkRdrFunBindSE arity :: Int
arity
fun :: Located RdrName
fun@(L loc :: SrcSpan
loc fun_rdr :: RdrName
fun_rdr) matches :: [LMatch GhcPs (LHsExpr GhcPs)]
matches = SrcSpan -> HsBind GhcPs -> LHsBind GhcPs
forall l e. l -> e -> GenLocated l e
L SrcSpan
loc (Located RdrName -> [LMatch GhcPs (LHsExpr GhcPs)] -> HsBind GhcPs
mkFunBind Located RdrName
fun [LMatch GhcPs (LHsExpr GhcPs)]
matches')
where
matches' :: [LMatch GhcPs (LHsExpr GhcPs)]
matches' = if [LMatch GhcPs (LHsExpr GhcPs)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LMatch GhcPs (LHsExpr GhcPs)]
matches
then [HsMatchContext (NameOrRdrName (IdP GhcPs))
-> [LPat GhcPs]
-> LHsExpr GhcPs
-> Located (HsLocalBinds GhcPs)
-> LMatch GhcPs (LHsExpr GhcPs)
forall (p :: Pass).
HsMatchContext (NameOrRdrName (IdP (GhcPass p)))
-> [LPat (GhcPass p)]
-> LHsExpr (GhcPass p)
-> Located (HsLocalBinds (GhcPass p))
-> LMatch (GhcPass p) (LHsExpr (GhcPass p))
mkMatch (Located RdrName -> HsMatchContext RdrName
forall id. Located id -> HsMatchContext id
mkPrefixFunRhs Located RdrName
fun)
(Int -> LPat GhcPs -> [LPat GhcPs]
forall a. Int -> a -> [a]
replicate Int
arity LPat GhcPs
nlWildPat)
(String -> LHsExpr GhcPs
error_Expr String
str) (SrcSpanLess (Located (HsLocalBinds GhcPs))
-> Located (HsLocalBinds GhcPs)
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc SrcSpanLess (Located (HsLocalBinds GhcPs))
forall (a :: Pass) (b :: Pass).
HsLocalBindsLR (GhcPass a) (GhcPass b)
emptyLocalBinds)]
else [LMatch GhcPs (LHsExpr GhcPs)]
matches
str :: String
str = "Void " String -> String -> String
forall a. [a] -> [a] -> [a]
++ OccName -> String
occNameString (RdrName -> OccName
rdrNameOcc RdrName
fun_rdr)
box :: String
-> LHsExpr GhcPs
-> Type
-> LHsExpr GhcPs
box :: String -> LHsExpr GhcPs -> Type -> LHsExpr GhcPs
box cls_str :: String
cls_str arg :: LHsExpr GhcPs
arg arg_ty :: Type
arg_ty = String
-> [(Type, LHsExpr GhcPs -> LHsExpr GhcPs)]
-> Type
-> LHsExpr GhcPs
-> LHsExpr GhcPs
forall a. HasCallStack => String -> [(Type, a)] -> Type -> a
assoc_ty_id String
cls_str [(Type, LHsExpr GhcPs -> LHsExpr GhcPs)]
boxConTbl Type
arg_ty LHsExpr GhcPs
arg
primOrdOps :: String
-> Type
-> (RdrName, RdrName, RdrName, RdrName, RdrName)
primOrdOps :: String -> Type -> (RdrName, RdrName, RdrName, RdrName, RdrName)
primOrdOps str :: String
str ty :: Type
ty = String
-> [(Type, (RdrName, RdrName, RdrName, RdrName, RdrName))]
-> Type
-> (RdrName, RdrName, RdrName, RdrName, RdrName)
forall a. HasCallStack => String -> [(Type, a)] -> Type -> a
assoc_ty_id String
str [(Type, (RdrName, RdrName, RdrName, RdrName, RdrName))]
ordOpTbl Type
ty
primLitOps :: String
-> Type
-> ( LHsExpr GhcPs -> LHsExpr GhcPs
, LHsExpr GhcPs -> LHsExpr GhcPs
)
primLitOps :: String
-> Type
-> (LHsExpr GhcPs -> LHsExpr GhcPs, LHsExpr GhcPs -> LHsExpr GhcPs)
primLitOps str :: String
str ty :: Type
ty = (String
-> [(Type, LHsExpr GhcPs -> LHsExpr GhcPs)]
-> Type
-> LHsExpr GhcPs
-> LHsExpr GhcPs
forall a. HasCallStack => String -> [(Type, a)] -> Type -> a
assoc_ty_id String
str [(Type, LHsExpr GhcPs -> LHsExpr GhcPs)]
litConTbl Type
ty, \v :: LHsExpr GhcPs
v -> LHsExpr GhcPs -> LHsExpr GhcPs
boxed LHsExpr GhcPs
v)
where
boxed :: LHsExpr GhcPs -> LHsExpr GhcPs
boxed v :: LHsExpr GhcPs
v
| Type
ty Type -> Type -> Bool
`eqType` Type
addrPrimTy = IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
unpackCString_RDR LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
`nlHsApp` LHsExpr GhcPs
v
| Bool
otherwise = String
-> [(Type, LHsExpr GhcPs -> LHsExpr GhcPs)]
-> Type
-> LHsExpr GhcPs
-> LHsExpr GhcPs
forall a. HasCallStack => String -> [(Type, a)] -> Type -> a
assoc_ty_id String
str [(Type, LHsExpr GhcPs -> LHsExpr GhcPs)]
boxConTbl Type
ty LHsExpr GhcPs
v
ordOpTbl :: [(Type, (RdrName, RdrName, RdrName, RdrName, RdrName))]
ordOpTbl :: [(Type, (RdrName, RdrName, RdrName, RdrName, RdrName))]
ordOpTbl
= [(Type
charPrimTy , (RdrName
ltChar_RDR , RdrName
leChar_RDR
, RdrName
eqChar_RDR , RdrName
geChar_RDR , RdrName
gtChar_RDR ))
,(Type
intPrimTy , (RdrName
ltInt_RDR , RdrName
leInt_RDR
, RdrName
eqInt_RDR , RdrName
geInt_RDR , RdrName
gtInt_RDR ))
,(Type
int8PrimTy , (RdrName
ltInt8_RDR , RdrName
leInt8_RDR
, RdrName
eqInt8_RDR , RdrName
geInt8_RDR , RdrName
gtInt8_RDR ))
,(Type
int16PrimTy , (RdrName
ltInt16_RDR , RdrName
leInt16_RDR
, RdrName
eqInt16_RDR , RdrName
geInt16_RDR , RdrName
gtInt16_RDR ))
,(Type
wordPrimTy , (RdrName
ltWord_RDR , RdrName
leWord_RDR
, RdrName
eqWord_RDR , RdrName
geWord_RDR , RdrName
gtWord_RDR ))
,(Type
word8PrimTy , (RdrName
ltWord8_RDR , RdrName
leWord8_RDR
, RdrName
eqWord8_RDR , RdrName
geWord8_RDR , RdrName
gtWord8_RDR ))
,(Type
word16PrimTy, (RdrName
ltWord16_RDR, RdrName
leWord16_RDR
, RdrName
eqWord16_RDR, RdrName
geWord16_RDR, RdrName
gtWord16_RDR ))
,(Type
addrPrimTy , (RdrName
ltAddr_RDR , RdrName
leAddr_RDR
, RdrName
eqAddr_RDR , RdrName
geAddr_RDR , RdrName
gtAddr_RDR ))
,(Type
floatPrimTy , (RdrName
ltFloat_RDR , RdrName
leFloat_RDR
, RdrName
eqFloat_RDR , RdrName
geFloat_RDR , RdrName
gtFloat_RDR ))
,(Type
doublePrimTy, (RdrName
ltDouble_RDR, RdrName
leDouble_RDR
, RdrName
eqDouble_RDR, RdrName
geDouble_RDR, RdrName
gtDouble_RDR)) ]
boxConTbl :: [(Type, LHsExpr GhcPs -> LHsExpr GhcPs)]
boxConTbl :: [(Type, LHsExpr GhcPs -> LHsExpr GhcPs)]
boxConTbl =
[ (Type
charPrimTy , LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar (IdP GhcPs -> LHsExpr GhcPs) -> IdP GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$ DataCon -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName DataCon
charDataCon))
, (Type
intPrimTy , LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar (IdP GhcPs -> LHsExpr GhcPs) -> IdP GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$ DataCon -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName DataCon
intDataCon))
, (Type
wordPrimTy , LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar (IdP GhcPs -> LHsExpr GhcPs) -> IdP GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$ DataCon -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName DataCon
wordDataCon ))
, (Type
floatPrimTy , LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar (IdP GhcPs -> LHsExpr GhcPs) -> IdP GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$ DataCon -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName DataCon
floatDataCon ))
, (Type
doublePrimTy, LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar (IdP GhcPs -> LHsExpr GhcPs) -> IdP GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$ DataCon -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName DataCon
doubleDataCon))
, (Type
int8PrimTy,
LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar (IdP GhcPs -> LHsExpr GhcPs) -> IdP GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$ DataCon -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName DataCon
intDataCon)
(LHsExpr GhcPs -> LHsExpr GhcPs)
-> (LHsExpr GhcPs -> LHsExpr GhcPs)
-> LHsExpr GhcPs
-> LHsExpr GhcPs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
extendInt8_RDR))
, (Type
word8PrimTy,
LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar (IdP GhcPs -> LHsExpr GhcPs) -> IdP GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$ DataCon -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName DataCon
wordDataCon)
(LHsExpr GhcPs -> LHsExpr GhcPs)
-> (LHsExpr GhcPs -> LHsExpr GhcPs)
-> LHsExpr GhcPs
-> LHsExpr GhcPs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
extendWord8_RDR))
, (Type
int16PrimTy,
LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar (IdP GhcPs -> LHsExpr GhcPs) -> IdP GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$ DataCon -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName DataCon
intDataCon)
(LHsExpr GhcPs -> LHsExpr GhcPs)
-> (LHsExpr GhcPs -> LHsExpr GhcPs)
-> LHsExpr GhcPs
-> LHsExpr GhcPs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
extendInt16_RDR))
, (Type
word16PrimTy,
LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar (IdP GhcPs -> LHsExpr GhcPs) -> IdP GhcPs -> LHsExpr GhcPs
forall a b. (a -> b) -> a -> b
$ DataCon -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName DataCon
wordDataCon)
(LHsExpr GhcPs -> LHsExpr GhcPs)
-> (LHsExpr GhcPs -> LHsExpr GhcPs)
-> LHsExpr GhcPs
-> LHsExpr GhcPs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
extendWord16_RDR))
]
postfixModTbl :: [(Type, String)]
postfixModTbl :: [(Type, String)]
postfixModTbl
= [(Type
charPrimTy , "#" )
,(Type
intPrimTy , "#" )
,(Type
wordPrimTy , "##")
,(Type
floatPrimTy , "#" )
,(Type
doublePrimTy, "##")
,(Type
int8PrimTy, "#")
,(Type
word8PrimTy, "##")
,(Type
int16PrimTy, "#")
,(Type
word16PrimTy, "##")
]
primConvTbl :: [(Type, String)]
primConvTbl :: [(Type, String)]
primConvTbl =
[ (Type
int8PrimTy, "narrowInt8#")
, (Type
word8PrimTy, "narrowWord8#")
, (Type
int16PrimTy, "narrowInt16#")
, (Type
word16PrimTy, "narrowWord16#")
]
litConTbl :: [(Type, LHsExpr GhcPs -> LHsExpr GhcPs)]
litConTbl :: [(Type, LHsExpr GhcPs -> LHsExpr GhcPs)]
litConTbl
= [(Type
charPrimTy , LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
charPrimL_RDR))
,(Type
intPrimTy , LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
intPrimL_RDR)
(LHsExpr GhcPs -> LHsExpr GhcPs)
-> (LHsExpr GhcPs -> LHsExpr GhcPs)
-> LHsExpr GhcPs
-> LHsExpr GhcPs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
toInteger_RDR))
,(Type
wordPrimTy , LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
wordPrimL_RDR)
(LHsExpr GhcPs -> LHsExpr GhcPs)
-> (LHsExpr GhcPs -> LHsExpr GhcPs)
-> LHsExpr GhcPs
-> LHsExpr GhcPs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
toInteger_RDR))
,(Type
addrPrimTy , LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
stringPrimL_RDR)
(LHsExpr GhcPs -> LHsExpr GhcPs)
-> (LHsExpr GhcPs -> LHsExpr GhcPs)
-> LHsExpr GhcPs
-> LHsExpr GhcPs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp
(IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
map_RDR)
(RdrName
IdP GhcPs
compose_RDR IdP GhcPs -> [LHsExpr GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [LHsExpr (GhcPass id)] -> LHsExpr (GhcPass id)
`nlHsApps`
[ IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
fromIntegral_RDR
, IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
fromEnum_RDR
])))
,(Type
floatPrimTy , LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
floatPrimL_RDR)
(LHsExpr GhcPs -> LHsExpr GhcPs)
-> (LHsExpr GhcPs -> LHsExpr GhcPs)
-> LHsExpr GhcPs
-> LHsExpr GhcPs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
toRational_RDR))
,(Type
doublePrimTy, LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
doublePrimL_RDR)
(LHsExpr GhcPs -> LHsExpr GhcPs)
-> (LHsExpr GhcPs -> LHsExpr GhcPs)
-> LHsExpr GhcPs
-> LHsExpr GhcPs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
toRational_RDR))
]
assoc_ty_id :: HasCallStack => String
-> [(Type,a)]
-> Type
-> a
assoc_ty_id :: String -> [(Type, a)] -> Type -> a
assoc_ty_id cls_str :: String
cls_str tbl :: [(Type, a)]
tbl ty :: Type
ty
| Just a :: a
a <- [(Type, a)] -> Type -> Maybe a
forall a. [(Type, a)] -> Type -> Maybe a
assoc_ty_id_maybe [(Type, a)]
tbl Type
ty = a
a
| Bool
otherwise =
String -> SDoc -> a
forall a. HasCallStack => String -> SDoc -> a
pprPanic "Error in deriving:"
(String -> SDoc
text "Can't derive" SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
cls_str SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text "for primitive type" SDoc -> SDoc -> SDoc
<+> Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr Type
ty)
assoc_ty_id_maybe :: [(Type, a)] -> Type -> Maybe a
assoc_ty_id_maybe :: [(Type, a)] -> Type -> Maybe a
assoc_ty_id_maybe tbl :: [(Type, a)]
tbl ty :: Type
ty = (Type, a) -> a
forall a b. (a, b) -> b
snd ((Type, a) -> a) -> Maybe (Type, a) -> Maybe a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Type, a) -> Bool) -> [(Type, a)] -> Maybe (Type, a)
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find (\(t :: Type
t, _) -> Type
t Type -> Type -> Bool
`eqType` Type
ty) [(Type, a)]
tbl
and_Expr :: LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
and_Expr :: LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
and_Expr a :: LHsExpr GhcPs
a b :: LHsExpr GhcPs
b = LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs -> LHsExpr GhcPs
genOpApp LHsExpr GhcPs
a RdrName
and_RDR LHsExpr GhcPs
b
eq_Expr :: Type -> LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
eq_Expr :: Type -> LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
eq_Expr ty :: Type
ty a :: LHsExpr GhcPs
a b :: LHsExpr GhcPs
b
| Bool -> Bool
not (HasDebugCallStack => Type -> Bool
Type -> Bool
isUnliftedType Type
ty) = LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs -> LHsExpr GhcPs
genOpApp LHsExpr GhcPs
a RdrName
eq_RDR LHsExpr GhcPs
b
| Bool
otherwise = LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs -> LHsExpr GhcPs
genPrimOpApp LHsExpr GhcPs
a RdrName
prim_eq LHsExpr GhcPs
b
where
(_, _, prim_eq :: RdrName
prim_eq, _, _) = String -> Type -> (RdrName, RdrName, RdrName, RdrName, RdrName)
primOrdOps "Eq" Type
ty
untag_Expr :: DynFlags -> TyCon -> [( RdrName, RdrName)]
-> LHsExpr GhcPs -> LHsExpr GhcPs
untag_Expr :: DynFlags
-> TyCon -> [(RdrName, RdrName)] -> LHsExpr GhcPs -> LHsExpr GhcPs
untag_Expr _ _ [] expr :: LHsExpr GhcPs
expr = LHsExpr GhcPs
expr
untag_Expr dflags :: DynFlags
dflags tycon :: TyCon
tycon ((untag_this :: RdrName
untag_this, put_tag_here :: RdrName
put_tag_here) : more :: [(RdrName, RdrName)]
more) expr :: LHsExpr GhcPs
expr
= LHsExpr GhcPs -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsExpr GhcPs
nlHsCase (LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass). LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsPar (IdP GhcPs -> [IdP GhcPs] -> LHsExpr GhcPs
forall (id :: Pass).
IdP (GhcPass id) -> [IdP (GhcPass id)] -> LHsExpr (GhcPass id)
nlHsVarApps (DynFlags -> TyCon -> RdrName
con2tag_RDR DynFlags
dflags TyCon
tycon)
[RdrName
IdP GhcPs
untag_this]))
[LPat GhcPs -> LHsExpr GhcPs -> LMatch GhcPs (LHsExpr GhcPs)
forall (p :: Pass) (body :: * -> *).
LPat (GhcPass p)
-> Located (body (GhcPass p))
-> LMatch (GhcPass p) (Located (body (GhcPass p)))
mkHsCaseAlt (IdP GhcPs -> LPat GhcPs
forall (p :: Pass). IdP (GhcPass p) -> LPat (GhcPass p)
nlVarPat RdrName
IdP GhcPs
put_tag_here) (DynFlags
-> TyCon -> [(RdrName, RdrName)] -> LHsExpr GhcPs -> LHsExpr GhcPs
untag_Expr DynFlags
dflags TyCon
tycon [(RdrName, RdrName)]
more LHsExpr GhcPs
expr)]
enum_from_to_Expr
:: LHsExpr GhcPs -> LHsExpr GhcPs
-> LHsExpr GhcPs
enum_from_then_to_Expr
:: LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
-> LHsExpr GhcPs
enum_from_to_Expr :: LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
enum_from_to_Expr f :: LHsExpr GhcPs
f t2 :: LHsExpr GhcPs
t2 = LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
enumFromTo_RDR) LHsExpr GhcPs
f) LHsExpr GhcPs
t2
enum_from_then_to_Expr :: LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
enum_from_then_to_Expr f :: LHsExpr GhcPs
f t :: LHsExpr GhcPs
t t2 :: LHsExpr GhcPs
t2 = LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
enumFromThenTo_RDR) LHsExpr GhcPs
f) LHsExpr GhcPs
t) LHsExpr GhcPs
t2
showParen_Expr
:: LHsExpr GhcPs -> LHsExpr GhcPs
-> LHsExpr GhcPs
showParen_Expr :: LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
showParen_Expr e1 :: LHsExpr GhcPs
e1 e2 :: LHsExpr GhcPs
e2 = LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
showParen_RDR) LHsExpr GhcPs
e1) LHsExpr GhcPs
e2
nested_compose_Expr :: [LHsExpr GhcPs] -> LHsExpr GhcPs
nested_compose_Expr :: [LHsExpr GhcPs] -> LHsExpr GhcPs
nested_compose_Expr [] = String -> LHsExpr GhcPs
forall a. String -> a
panic "nested_compose_expr"
nested_compose_Expr [e :: LHsExpr GhcPs
e] = LHsExpr GhcPs -> LHsExpr GhcPs
parenify LHsExpr GhcPs
e
nested_compose_Expr (e :: LHsExpr GhcPs
e:es :: [LHsExpr GhcPs]
es)
= LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
compose_RDR) (LHsExpr GhcPs -> LHsExpr GhcPs
parenify LHsExpr GhcPs
e)) ([LHsExpr GhcPs] -> LHsExpr GhcPs
nested_compose_Expr [LHsExpr GhcPs]
es)
error_Expr :: String -> LHsExpr GhcPs
error_Expr :: String -> LHsExpr GhcPs
error_Expr string :: String
string = LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
error_RDR) (HsLit GhcPs -> LHsExpr GhcPs
forall (p :: Pass). HsLit (GhcPass p) -> LHsExpr (GhcPass p)
nlHsLit (String -> HsLit GhcPs
forall (p :: Pass). String -> HsLit (GhcPass p)
mkHsString String
string))
illegal_Expr :: String -> String -> String -> LHsExpr GhcPs
illegal_Expr :: String -> String -> String -> LHsExpr GhcPs
illegal_Expr meth :: String
meth tp :: String
tp msg :: String
msg =
LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
error_RDR) (HsLit GhcPs -> LHsExpr GhcPs
forall (p :: Pass). HsLit (GhcPass p) -> LHsExpr (GhcPass p)
nlHsLit (String -> HsLit GhcPs
forall (p :: Pass). String -> HsLit (GhcPass p)
mkHsString (String
meth String -> String -> String
forall a. [a] -> [a] -> [a]
++ '{'Char -> String -> String
forall a. a -> [a] -> [a]
:String
tp String -> String -> String
forall a. [a] -> [a] -> [a]
++ "}: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
msg)))
illegal_toEnum_tag :: String -> RdrName -> LHsExpr GhcPs
illegal_toEnum_tag :: String -> RdrName -> LHsExpr GhcPs
illegal_toEnum_tag tp :: String
tp maxtag :: RdrName
maxtag =
LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
error_RDR)
(LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
append_RDR)
(HsLit GhcPs -> LHsExpr GhcPs
forall (p :: Pass). HsLit (GhcPass p) -> LHsExpr (GhcPass p)
nlHsLit (String -> HsLit GhcPs
forall (p :: Pass). String -> HsLit (GhcPass p)
mkHsString ("toEnum{" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
tp String -> String -> String
forall a. [a] -> [a] -> [a]
++ "}: tag ("))))
(LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp
(IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
showsPrec_RDR)
(Integer -> LHsExpr GhcPs
forall (p :: Pass). Integer -> LHsExpr (GhcPass p)
nlHsIntLit 0))
(IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
a_RDR))
(LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp
(IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
append_RDR)
(HsLit GhcPs -> LHsExpr GhcPs
forall (p :: Pass). HsLit (GhcPass p) -> LHsExpr (GhcPass p)
nlHsLit (String -> HsLit GhcPs
forall (p :: Pass). String -> HsLit (GhcPass p)
mkHsString ") is outside of enumeration's range (0,")))
(LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp
(IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
showsPrec_RDR)
(Integer -> LHsExpr GhcPs
forall (p :: Pass). Integer -> LHsExpr (GhcPass p)
nlHsIntLit 0))
(IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
maxtag))
(HsLit GhcPs -> LHsExpr GhcPs
forall (p :: Pass). HsLit (GhcPass p) -> LHsExpr (GhcPass p)
nlHsLit (String -> HsLit GhcPs
forall (p :: Pass). String -> HsLit (GhcPass p)
mkHsString ")"))))))
parenify :: LHsExpr GhcPs -> LHsExpr GhcPs
parenify :: LHsExpr GhcPs -> LHsExpr GhcPs
parenify e :: LHsExpr GhcPs
e@(L _ (HsVar _ _)) = LHsExpr GhcPs
e
parenify e :: LHsExpr GhcPs
e = LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass). LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
mkHsPar LHsExpr GhcPs
e
genOpApp :: LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs -> LHsExpr GhcPs
genOpApp :: LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs -> LHsExpr GhcPs
genOpApp e1 :: LHsExpr GhcPs
e1 op :: RdrName
op e2 :: LHsExpr GhcPs
e2 = LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass). LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsPar (LHsExpr GhcPs -> IdP GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
nlHsOpApp LHsExpr GhcPs
e1 RdrName
IdP GhcPs
op LHsExpr GhcPs
e2)
genPrimOpApp :: LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs -> LHsExpr GhcPs
genPrimOpApp :: LHsExpr GhcPs -> RdrName -> LHsExpr GhcPs -> LHsExpr GhcPs
genPrimOpApp e1 :: LHsExpr GhcPs
e1 op :: RdrName
op e2 :: LHsExpr GhcPs
e2 = LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass). LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsPar (LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
forall (id :: Pass).
LHsExpr (GhcPass id)
-> LHsExpr (GhcPass id) -> LHsExpr (GhcPass id)
nlHsApp (IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
tagToEnum_RDR) (LHsExpr GhcPs -> IdP GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
nlHsOpApp LHsExpr GhcPs
e1 RdrName
IdP GhcPs
op LHsExpr GhcPs
e2))
a_RDR, b_RDR, c_RDR, d_RDR, f_RDR, k_RDR, z_RDR, ah_RDR, bh_RDR, ch_RDR, dh_RDR
:: RdrName
a_RDR :: RdrName
a_RDR = FastString -> RdrName
mkVarUnqual (String -> FastString
fsLit "a")
b_RDR :: RdrName
b_RDR = FastString -> RdrName
mkVarUnqual (String -> FastString
fsLit "b")
c_RDR :: RdrName
c_RDR = FastString -> RdrName
mkVarUnqual (String -> FastString
fsLit "c")
d_RDR :: RdrName
d_RDR = FastString -> RdrName
mkVarUnqual (String -> FastString
fsLit "d")
f_RDR :: RdrName
f_RDR = FastString -> RdrName
mkVarUnqual (String -> FastString
fsLit "f")
k_RDR :: RdrName
k_RDR = FastString -> RdrName
mkVarUnqual (String -> FastString
fsLit "k")
z_RDR :: RdrName
z_RDR = FastString -> RdrName
mkVarUnqual (String -> FastString
fsLit "z")
ah_RDR :: RdrName
ah_RDR = FastString -> RdrName
mkVarUnqual (String -> FastString
fsLit "a#")
bh_RDR :: RdrName
bh_RDR = FastString -> RdrName
mkVarUnqual (String -> FastString
fsLit "b#")
ch_RDR :: RdrName
ch_RDR = FastString -> RdrName
mkVarUnqual (String -> FastString
fsLit "c#")
dh_RDR :: RdrName
dh_RDR = FastString -> RdrName
mkVarUnqual (String -> FastString
fsLit "d#")
as_RDRs, bs_RDRs, cs_RDRs :: [RdrName]
as_RDRs :: [RdrName]
as_RDRs = [ FastString -> RdrName
mkVarUnqual (String -> FastString
mkFastString ("a"String -> String -> String
forall a. [a] -> [a] -> [a]
++Int -> String
forall a. Show a => a -> String
show Int
i)) | Int
i <- [(1::Int) .. ] ]
bs_RDRs :: [RdrName]
bs_RDRs = [ FastString -> RdrName
mkVarUnqual (String -> FastString
mkFastString ("b"String -> String -> String
forall a. [a] -> [a] -> [a]
++Int -> String
forall a. Show a => a -> String
show Int
i)) | Int
i <- [(1::Int) .. ] ]
cs_RDRs :: [RdrName]
cs_RDRs = [ FastString -> RdrName
mkVarUnqual (String -> FastString
mkFastString ("c"String -> String -> String
forall a. [a] -> [a] -> [a]
++Int -> String
forall a. Show a => a -> String
show Int
i)) | Int
i <- [(1::Int) .. ] ]
a_Expr, b_Expr, c_Expr, z_Expr, ltTag_Expr, eqTag_Expr, gtTag_Expr, false_Expr,
true_Expr, pure_Expr :: LHsExpr GhcPs
a_Expr :: LHsExpr GhcPs
a_Expr = IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
a_RDR
b_Expr :: LHsExpr GhcPs
b_Expr = IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
b_RDR
c_Expr :: LHsExpr GhcPs
c_Expr = IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
c_RDR
z_Expr :: LHsExpr GhcPs
z_Expr = IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
z_RDR
ltTag_Expr :: LHsExpr GhcPs
ltTag_Expr = IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
ltTag_RDR
eqTag_Expr :: LHsExpr GhcPs
eqTag_Expr = IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
eqTag_RDR
gtTag_Expr :: LHsExpr GhcPs
gtTag_Expr = IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
gtTag_RDR
false_Expr :: LHsExpr GhcPs
false_Expr = IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
false_RDR
true_Expr :: LHsExpr GhcPs
true_Expr = IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
true_RDR
pure_Expr :: LHsExpr GhcPs
pure_Expr = IdP GhcPs -> LHsExpr GhcPs
forall (id :: Pass). IdP (GhcPass id) -> LHsExpr (GhcPass id)
nlHsVar RdrName
IdP GhcPs
pure_RDR
a_Pat, b_Pat, c_Pat, d_Pat, k_Pat, z_Pat :: LPat GhcPs
a_Pat :: LPat GhcPs
a_Pat = IdP GhcPs -> LPat GhcPs
forall (p :: Pass). IdP (GhcPass p) -> LPat (GhcPass p)
nlVarPat RdrName
IdP GhcPs
a_RDR
b_Pat :: LPat GhcPs
b_Pat = IdP GhcPs -> LPat GhcPs
forall (p :: Pass). IdP (GhcPass p) -> LPat (GhcPass p)
nlVarPat RdrName
IdP GhcPs
b_RDR
c_Pat :: LPat GhcPs
c_Pat = IdP GhcPs -> LPat GhcPs
forall (p :: Pass). IdP (GhcPass p) -> LPat (GhcPass p)
nlVarPat RdrName
IdP GhcPs
c_RDR
d_Pat :: LPat GhcPs
d_Pat = IdP GhcPs -> LPat GhcPs
forall (p :: Pass). IdP (GhcPass p) -> LPat (GhcPass p)
nlVarPat RdrName
IdP GhcPs
d_RDR
k_Pat :: LPat GhcPs
k_Pat = IdP GhcPs -> LPat GhcPs
forall (p :: Pass). IdP (GhcPass p) -> LPat (GhcPass p)
nlVarPat RdrName
IdP GhcPs
k_RDR
z_Pat :: LPat GhcPs
z_Pat = IdP GhcPs -> LPat GhcPs
forall (p :: Pass). IdP (GhcPass p) -> LPat (GhcPass p)
nlVarPat RdrName
IdP GhcPs
z_RDR
minusInt_RDR, tagToEnum_RDR :: RdrName
minusInt_RDR :: RdrName
minusInt_RDR = TyVar -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName (PrimOp -> TyVar
primOpId PrimOp
IntSubOp )
tagToEnum_RDR :: RdrName
tagToEnum_RDR = TyVar -> RdrName
forall thing. NamedThing thing => thing -> RdrName
getRdrName (PrimOp -> TyVar
primOpId PrimOp
TagToEnumOp)
con2tag_RDR, tag2con_RDR, maxtag_RDR :: DynFlags -> TyCon -> RdrName
con2tag_RDR :: DynFlags -> TyCon -> RdrName
con2tag_RDR dflags :: DynFlags
dflags tycon :: TyCon
tycon = DynFlags -> TyCon -> (OccName -> OccName) -> RdrName
mk_tc_deriv_name DynFlags
dflags TyCon
tycon OccName -> OccName
mkCon2TagOcc
tag2con_RDR :: DynFlags -> TyCon -> RdrName
tag2con_RDR dflags :: DynFlags
dflags tycon :: TyCon
tycon = DynFlags -> TyCon -> (OccName -> OccName) -> RdrName
mk_tc_deriv_name DynFlags
dflags TyCon
tycon OccName -> OccName
mkTag2ConOcc
maxtag_RDR :: DynFlags -> TyCon -> RdrName
maxtag_RDR dflags :: DynFlags
dflags tycon :: TyCon
tycon = DynFlags -> TyCon -> (OccName -> OccName) -> RdrName
mk_tc_deriv_name DynFlags
dflags TyCon
tycon OccName -> OccName
mkMaxTagOcc
mk_tc_deriv_name :: DynFlags -> TyCon -> (OccName -> OccName) -> RdrName
mk_tc_deriv_name :: DynFlags -> TyCon -> (OccName -> OccName) -> RdrName
mk_tc_deriv_name dflags :: DynFlags
dflags tycon :: TyCon
tycon occ_fun :: OccName -> OccName
occ_fun =
DynFlags -> Name -> (OccName -> OccName) -> RdrName
mkAuxBinderName DynFlags
dflags (TyCon -> Name
tyConName TyCon
tycon) OccName -> OccName
occ_fun
mkAuxBinderName :: DynFlags -> Name -> (OccName -> OccName) -> RdrName
mkAuxBinderName :: DynFlags -> Name -> (OccName -> OccName) -> RdrName
mkAuxBinderName dflags :: DynFlags
dflags parent :: Name
parent occ_fun :: OccName -> OccName
occ_fun
= OccName -> RdrName
mkRdrUnqual (OccName -> OccName
occ_fun OccName
stable_parent_occ)
where
stable_parent_occ :: OccName
stable_parent_occ = NameSpace -> String -> OccName
mkOccName (OccName -> NameSpace
occNameSpace OccName
parent_occ) String
stable_string
stable_string :: String
stable_string
| DynFlags -> Bool
hasPprDebug DynFlags
dflags = String
parent_stable
| Bool
otherwise = String
parent_stable_hash
parent_stable :: String
parent_stable = Name -> String
nameStableString Name
parent
parent_stable_hash :: String
parent_stable_hash =
let Fingerprint high :: Word64
high low :: Word64
low = String -> Fingerprint
fingerprintString String
parent_stable
in Word64 -> String
toBase62 Word64
high String -> String -> String
forall a. [a] -> [a] -> [a]
++ Word64 -> String
toBase62Padded Word64
low
parent_occ :: OccName
parent_occ = Name -> OccName
nameOccName Name
parent