X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fmain%2FPprTyThing.hs;h=86c6f4c3d9720711c3efca9fc8318a63bd40cdfb;hb=9bbcd77cf9b66940058dbea1827db594e8ff6d7f;hp=ea974957c8be45464149658291bbb0a3ed343707;hpb=2b49cf43578194443e0481b4680c3542c3d31bff;p=ghc-hetmet.git diff --git a/compiler/main/PprTyThing.hs b/compiler/main/PprTyThing.hs index ea97495..86c6f4c 100644 --- a/compiler/main/PprTyThing.hs +++ b/compiler/main/PprTyThing.hs @@ -18,8 +18,9 @@ module PprTyThing ( import qualified GHC -import GHC ( TyThing(..), SrcLoc ) -import DataCon ( dataConResTys ) +import TyCon ( tyConFamInst_maybe ) +import Type ( pprTypeApp ) +import GHC ( TyThing(..), SrcSpan ) import Outputable -- ----------------------------------------------------------------------------- @@ -32,7 +33,7 @@ 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 @@ -45,7 +46,7 @@ pprTyThing exts (AClass cls) = pprClass exts cls 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 @@ -66,8 +67,11 @@ pprTyThingHdr exts (ADataCon dataCon) = pprDataConSig exts dataCon pprTyThingHdr exts (ATyCon tyCon) = pprTyConHdr exts tyCon pprTyThingHdr exts (AClass cls) = pprClassHdr exts cls -pprTyConHdr exts tyCon = - addFamily (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 (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 @@ -77,9 +81,9 @@ pprTyConHdr exts tyCon = | GHC.isNewTyCon tyCon = SLIT("newtype") | otherwise = SLIT("data") - addFamily keytext - | GHC.isOpenTyCon tyCon = keytext <> ptext SLIT(" family") - | otherwise = keytext + opt_family + | GHC.isOpenTyCon tyCon = ptext SLIT("family") + | otherwise = empty pprDataConSig exts dataCon = ppr_bndr dataCon <+> dcolon <+> pprType exts (GHC.dataConType dataCon) @@ -143,10 +147,9 @@ pprDataConDecl exts gadt_style show_label dataCon | otherwise = ppr_bndr dataCon <+> dcolon <+> sep [ ppr_tvs, GHC.pprThetaArrow theta, pp_tau ] where - (tyvars, theta, argTypes) = GHC.dataConSig dataCon + (tyvars, theta, argTypes, res_ty) = GHC.dataConSig dataCon tyCon = GHC.dataConTyCon dataCon labels = GHC.dataConFieldLabels dataCon - res_tys = dataConResTys dataCon qualVars = filter (flip notElem (GHC.tyConTyVars tyCon)) tyvars stricts = GHC.dataConStrictMarks dataCon tys_w_strs = zip stricts argTypes @@ -157,8 +160,7 @@ pprDataConDecl exts gadt_style show_label 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) @@ -226,7 +228,7 @@ add_bars (c:cs) = sep ((equals <+> c) : map (char '|' <+>) cs) 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