import qualified GHC
-import GHC ( TyThing(..), SrcLoc )
-import DataCon ( dataConResTys )
+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 =
- 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 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")
- 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)
where tyCon = GHC.dataConTyCon dataCon
pprDataConDecl exts gadt_style show_label dataCon
- = error "kevind stub"
-{-
| not gadt_style = ppr_fields tys_w_strs
| otherwise = ppr_bndr dataCon <+> dcolon <+>
sep [ ppr_tvs, GHC.pprThetaArrow theta, pp_tau ]
where
- (tyvars, theta, argTypes, tyCon) = 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
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 dataCon <+>
braces (sep (punctuate comma (ppr_trim maybe_show_label
(zip labels fields))))
--}
+
pprClass exts cls
| null methods =
pprClassHdr exts cls
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