X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fmain%2FPprTyThing.hs;h=d87ffa1bf5f4e7a2a2ad3b2684738f0f1c8d79e0;hb=b84ba676034763b3082bbd9405794a4fde499d14;hp=16f5181af8b5cc6b2d8c7aed715563208f690a09;hpb=f12d4af480bc8fea6a44777199c9a32f60f444b9;p=ghc-hetmet.git diff --git a/compiler/main/PprTyThing.hs b/compiler/main/PprTyThing.hs index 16f5181..d87ffa1 100644 --- a/compiler/main/PprTyThing.hs +++ b/compiler/main/PprTyThing.hs @@ -16,18 +16,15 @@ module PprTyThing ( pprTypeForUser ) where -#include "HsVersions.h" - import qualified GHC import GHC ( TyThing(..) ) import TyCon -import Type ( TyThing(..), tidyTopType, pprTypeApp ) import TcType import Var import Name import Outputable -import Pretty ( Doc ) +import FastString -- ----------------------------------------------------------------------------- -- Pretty-printing entities that we get from the GHC API @@ -75,10 +72,10 @@ pprTyThingHdr pefas (ADataCon dataCon) = pprDataConSig pefas dataCon pprTyThingHdr pefas (ATyCon tyCon) = pprTyConHdr pefas tyCon pprTyThingHdr pefas (AClass cls) = pprClassHdr pefas cls -pprTyConHdr :: PrintExplicitForalls -> TyCon -> PprStyle -> Doc +pprTyConHdr :: PrintExplicitForalls -> TyCon -> SDoc pprTyConHdr _ tyCon | Just (_fam_tc, tys) <- tyConFamInst_maybe tyCon - = ptext keyword <+> ptext SLIT("instance") <+> pprTypeApp tyCon (ppr_bndr tyCon) tys + = ptext keyword <+> ptext (sLit "instance") <+> pprTypeApp tyCon tys | otherwise = ptext keyword <+> opt_family <+> opt_stupid <+> ppr_bndr tyCon <+> hsep (map ppr vars) where @@ -86,38 +83,38 @@ pprTyConHdr _ tyCon GHC.isFunTyCon tyCon = take (GHC.tyConArity tyCon) GHC.alphaTyVars | otherwise = GHC.tyConTyVars tyCon - keyword | GHC.isSynTyCon tyCon = SLIT("type") - | GHC.isNewTyCon tyCon = SLIT("newtype") - | otherwise = SLIT("data") + keyword | GHC.isSynTyCon tyCon = sLit "type" + | GHC.isNewTyCon tyCon = sLit "newtype" + | otherwise = sLit "data" opt_family - | GHC.isOpenTyCon tyCon = ptext SLIT("family") + | GHC.isOpenTyCon tyCon = ptext (sLit "family") | otherwise = empty opt_stupid -- The "stupid theta" part of the declaration | isAlgTyCon tyCon = GHC.pprThetaArrow (tyConStupidTheta tyCon) | otherwise = empty -- Returns 'empty' if null theta -pprDataConSig :: PrintExplicitForalls -> GHC.DataCon -> PprStyle -> Doc +pprDataConSig :: PrintExplicitForalls -> GHC.DataCon -> SDoc pprDataConSig pefas dataCon = ppr_bndr dataCon <+> dcolon <+> pprTypeForUser pefas (GHC.dataConType dataCon) -pprClassHdr :: PrintExplicitForalls -> GHC.Class -> PprStyle -> Doc +pprClassHdr :: PrintExplicitForalls -> GHC.Class -> SDoc pprClassHdr _ cls = let (tyVars, funDeps) = GHC.classTvsFds cls - in ptext SLIT("class") <+> + in ptext (sLit "class") <+> GHC.pprThetaArrow (GHC.classSCTheta cls) <+> ppr_bndr cls <+> hsep (map ppr tyVars) <+> GHC.pprFundeps funDeps -pprIdInContext :: PrintExplicitForalls -> Var -> PprStyle -> Doc +pprIdInContext :: PrintExplicitForalls -> Var -> SDoc pprIdInContext pefas id | GHC.isRecordSelector id = pprRecordSelector pefas id | Just cls <- GHC.isClassOpId_maybe id = pprClassOneMethod pefas cls id | otherwise = pprId pefas id -pprRecordSelector :: PrintExplicitForalls -> Id -> PprStyle -> Doc +pprRecordSelector :: PrintExplicitForalls -> Id -> SDoc pprRecordSelector pefas id = pprAlgTyCon pefas tyCon show_con show_label where @@ -146,7 +143,7 @@ pprTypeForUser print_foralls ty tidy_ty = tidyTopType ty (ctxt, ty') = tcMultiSplitSigmaTy tidy_ty -pprTyCon :: PrintExplicitForalls -> TyCon -> PprStyle -> Doc +pprTyCon :: PrintExplicitForalls -> TyCon -> SDoc pprTyCon pefas tyCon | GHC.isSynTyCon tyCon = if GHC.isOpenTyCon tyCon @@ -159,10 +156,9 @@ pprTyCon pefas tyCon = pprAlgTyCon pefas tyCon (const True) (const True) pprAlgTyCon :: PrintExplicitForalls -> TyCon -> (GHC.DataCon -> Bool) - -> (FieldLabel -> Bool) -> PprStyle - -> Doc + -> (FieldLabel -> Bool) -> SDoc pprAlgTyCon pefas tyCon ok_con ok_label - | gadt = pprTyConHdr pefas tyCon <+> ptext SLIT("where") $$ + | gadt = pprTyConHdr pefas tyCon <+> ptext (sLit "where") $$ nest 2 (vcat (ppr_trim show_con datacons)) | otherwise = hang (pprTyConHdr pefas tyCon) 2 (add_bars (ppr_trim show_con datacons)) @@ -174,13 +170,12 @@ pprAlgTyCon pefas tyCon ok_con ok_label | ok_con dataCon = Just (pprDataConDecl pefas gadt ok_label dataCon) | otherwise = Nothing -pprDataCon :: PrintExplicitForalls -> GHC.DataCon -> PprStyle -> Doc +pprDataCon :: PrintExplicitForalls -> GHC.DataCon -> SDoc pprDataCon pefas dataCon = pprAlgTyCon pefas tyCon (== dataCon) (const True) where tyCon = GHC.dataConTyCon dataCon pprDataConDecl :: PrintExplicitForalls -> Bool -> (FieldLabel -> Bool) - -> GHC.DataCon -> PprStyle - -> Doc + -> GHC.DataCon -> SDoc pprDataConDecl _ gadt_style show_label dataCon | not gadt_style = ppr_fields tys_w_strs | otherwise = ppr_bndr dataCon <+> dcolon <+> @@ -195,7 +190,7 @@ pprDataConDecl _ gadt_style show_label dataCon ppr_tvs | null qualVars = empty - | otherwise = ptext SLIT("forall") <+> + | otherwise = ptext (sLit "forall") <+> hsep (map ppr qualVars) <> dot -- printing out the dataCon as a type signature, in GADT style @@ -216,7 +211,7 @@ pprDataConDecl _ gadt_style show_label dataCon ppr_fields [ty1, ty2] | GHC.dataConIsInfix dataCon && null labels - = sep [pprParendBangTy ty1, ppr dataCon, pprParendBangTy ty2] + = sep [pprParendBangTy ty1, pprInfixName dataCon, pprParendBangTy ty2] ppr_fields fields | null labels = ppr_bndr dataCon <+> sep (map pprParendBangTy fields) @@ -225,26 +220,26 @@ pprDataConDecl _ gadt_style show_label dataCon braces (sep (punctuate comma (ppr_trim maybe_show_label (zip labels fields)))) -pprClass :: PrintExplicitForalls -> GHC.Class -> PprStyle -> Doc +pprClass :: PrintExplicitForalls -> GHC.Class -> SDoc pprClass pefas cls | null methods = pprClassHdr pefas cls | otherwise = - hang (pprClassHdr pefas cls <+> ptext SLIT("where")) + hang (pprClassHdr pefas cls <+> ptext (sLit "where")) 2 (vcat (map (pprClassMethod pefas) methods)) where methods = GHC.classMethods cls -pprClassOneMethod :: PrintExplicitForalls -> GHC.Class -> Id -> PprStyle -> Doc +pprClassOneMethod :: PrintExplicitForalls -> GHC.Class -> Id -> SDoc pprClassOneMethod pefas cls this_one - = hang (pprClassHdr pefas cls <+> ptext SLIT("where")) + = hang (pprClassHdr pefas cls <+> ptext (sLit "where")) 2 (vcat (ppr_trim show_meth methods)) where methods = GHC.classMethods cls show_meth id | id == this_one = Just (pprClassMethod pefas id) | otherwise = Nothing -pprClassMethod :: PrintExplicitForalls -> Id -> PprStyle -> Doc +pprClassMethod :: PrintExplicitForalls -> Id -> SDoc pprClassMethod pefas id = hang (ppr_bndr id <+> dcolon) 2 (pprTypeForUser pefas op_ty) where @@ -270,9 +265,9 @@ ppr_trim show xs go x (eliding, so_far) | Just doc <- show x = (False, doc : so_far) | otherwise = if eliding then (True, so_far) - else (True, ptext SLIT("...") : so_far) + else (True, ptext (sLit "...") : so_far) -add_bars :: [SDoc] -> PprStyle -> Doc +add_bars :: [SDoc] -> SDoc add_bars [] = empty add_bars [c] = equals <+> c add_bars (c:cs) = sep ((equals <+> c) : map (char '|' <+>) cs) @@ -286,5 +281,5 @@ showWithLoc loc doc = hang doc 2 (char '\t' <> comment <+> loc) -- The tab tries to make them line up a bit where - comment = ptext SLIT("--") + comment = ptext (sLit "--")