#include "HsVersions.h"
import qualified GHC
-import GHC ( TyThing(..), SrcLoc )
+
+import TyCon ( tyConFamInst_maybe )
+import Type ( pprTypeApp )
+import GHC ( TyThing(..), SrcSpan )
import Outputable
-- -----------------------------------------------------------------------------
pprTyThingLoc :: Bool -> TyThing -> SDoc
pprTyThingLoc exts tyThing
= showWithLoc loc (pprTyThing exts tyThing)
- where loc = GHC.nameSrcLoc (GHC.getName tyThing)
+ where loc = GHC.nameSrcSpan (GHC.getName tyThing)
-- | Pretty-prints a 'TyThing'.
pprTyThing :: Bool -> TyThing -> SDoc
pprTyThingInContextLoc :: Bool -> TyThing -> SDoc
pprTyThingInContextLoc exts tyThing
= showWithLoc loc (pprTyThingInContext exts tyThing)
- where loc = GHC.nameSrcLoc (GHC.getName tyThing)
+ where loc = GHC.nameSrcSpan (GHC.getName tyThing)
-- | Pretty-prints a 'TyThing' in context: that is, if the entity
-- is a data constructor, record selector, or class method, then
pprTyThingHdr exts (ATyCon tyCon) = pprTyConHdr exts tyCon
pprTyThingHdr exts (AClass cls) = pprClassHdr exts cls
-pprTyConHdr exts tyCon =
- ptext keyword <+> ppr_bndr tyCon <+> hsep (map ppr vars)
+pprTyConHdr exts tyCon
+ | Just (fam_tc, tys) <- tyConFamInst_maybe tyCon
+ = ptext keyword <+> ptext SLIT("instance") <+> pprTypeApp tyCon (ppr_bndr tyCon) tys
+ | otherwise
+ = ptext keyword <+> opt_family <+> ppr_bndr tyCon <+> hsep (map ppr vars)
where
vars | GHC.isPrimTyCon tyCon ||
GHC.isFunTyCon tyCon = take (GHC.tyConArity tyCon) GHC.alphaTyVars
| GHC.isNewTyCon tyCon = SLIT("newtype")
| otherwise = SLIT("data")
+ opt_family
+ | GHC.isOpenTyCon tyCon = ptext SLIT("family")
+ | otherwise = empty
+
pprDataConSig exts dataCon =
ppr_bndr dataCon <+> dcolon <+> pprType exts (GHC.dataConType dataCon)
pprTyCon exts tyCon
| GHC.isSynTyCon tyCon
- = let rhs_type = GHC.synTyConRhs tyCon
- in hang (pprTyConHdr exts tyCon <+> equals) 2 (pprType exts rhs_type)
+ = if GHC.isOpenTyCon tyCon
+ then pprTyConHdr exts tyCon <+> dcolon <+>
+ pprType exts (GHC.synTyConResKind tyCon)
+ else
+ let rhs_type = GHC.synTyConType tyCon
+ in hang (pprTyConHdr exts tyCon <+> equals) 2 (pprType exts rhs_type)
| otherwise
= pprAlgTyCon exts tyCon (const True) (const True)
| otherwise = ppr_bndr dataCon <+> dcolon <+>
sep [ ppr_tvs, GHC.pprThetaArrow theta, pp_tau ]
where
- (tyvars, theta, argTypes, tyCon, res_tys) = GHC.dataConSig dataCon
+ (tyvars, theta, argTypes, res_ty) = GHC.dataConSig dataCon
+ tyCon = GHC.dataConTyCon dataCon
labels = GHC.dataConFieldLabels dataCon
qualVars = filter (flip notElem (GHC.tyConTyVars tyCon)) tyvars
stricts = GHC.dataConStrictMarks dataCon
hsep (map ppr qualVars) <> dot
-- printing out the dataCon as a type signature, in GADT style
- pp_tau = foldr add pp_res_ty tys_w_strs
- pp_res_ty = ppr_bndr tyCon <+> hsep (map GHC.pprParendType res_tys)
+ pp_tau = foldr add (ppr res_ty) tys_w_strs
add (str,ty) pp_ty = pprBangTy str ty <+> arrow <+> pp_ty
pprParendBangTy (strict,ty)
ppr_bndr :: GHC.NamedThing a => a -> SDoc
ppr_bndr a = GHC.pprParenSymName a
-showWithLoc :: SrcLoc -> SDoc -> SDoc
+showWithLoc :: SrcSpan -> SDoc -> SDoc
showWithLoc loc doc
= hang doc 2 (char '\t' <> comment <+> GHC.pprDefnLoc loc)
-- The tab tries to make them line up a bit