X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2FhsSyn%2FHsTypes.lhs;h=d5b674be34946373b5554b4363c6734547abddc2;hp=04609c63d6a04d2877e513bc86b933d35624ad96;hb=432b9c9322181a3644083e3c19b7e240d90659e7;hpb=35b9d8e8a5d0e69cc756f21b7637a471e41a4fda diff --git a/compiler/hsSyn/HsTypes.lhs b/compiler/hsSyn/HsTypes.lhs index 04609c6..d5b674b 100644 --- a/compiler/hsSyn/HsTypes.lhs +++ b/compiler/hsSyn/HsTypes.lhs @@ -15,6 +15,8 @@ module HsTypes ( LBangType, BangType, HsBang(..), getBangType, getBangStrictness, + + ConDeclField(..), pprConDeclFields, mkExplicitHsForAllTy, mkImplicitHsForAllTy, hsExplicitTvs, hsTyVarName, hsTyVarNames, replaceTyVarName, @@ -118,8 +120,6 @@ data HsType name | HsTyVar name -- Type variable or type constructor - | HsBangTy HsBang (LHsType name) -- Bang-style type annotations - | HsAppTy (LHsType name) (LHsType name) @@ -159,8 +159,19 @@ data HsType name | HsDocTy (LHsType name) (LHsDoc name) -- A documented type + | HsBangTy HsBang (LHsType name) -- Bang-style type annotations + | HsRecTy [ConDeclField name] -- Only in data type declarations + data HsExplicitForAll = Explicit | Implicit + + +data ConDeclField name -- Record fields have Haddoc docs on them + = ConDeclField { cd_fld_name :: Located name, + cd_fld_type :: LBangType name, + cd_fld_doc :: Maybe (LHsDoc name) } + + ----------------------- -- Combine adjacent for-alls. -- The following awkward situation can happen otherwise: @@ -310,6 +321,13 @@ pprHsContext cxt = ppr_hs_context cxt <+> ptext (sLit "=>") ppr_hs_context :: (OutputableBndr name) => HsContext name -> SDoc ppr_hs_context [] = empty ppr_hs_context cxt = parens (interpp'SP cxt) + +pprConDeclFields :: OutputableBndr name => [ConDeclField name] -> SDoc +pprConDeclFields fields = braces (sep (punctuate comma (map ppr_fld fields))) + where + ppr_fld (ConDeclField { cd_fld_name = n, cd_fld_type = ty, + cd_fld_doc = doc }) + = ppr n <+> dcolon <+> ppr ty <+> ppr_mbDoc doc \end{code} \begin{code} @@ -352,6 +370,7 @@ ppr_mono_ty ctxt_prec (HsForAllTy exp tvs ctxt ty) sep [pprHsForAll exp tvs ctxt, ppr_mono_lty pREC_TOP ty] ppr_mono_ty _ (HsBangTy b ty) = ppr b <> ppr ty +ppr_mono_ty _ (HsRecTy flds) = pprConDeclFields flds ppr_mono_ty _ (HsTyVar name) = ppr name ppr_mono_ty ctxt_prec (HsFunTy ty1 ty2) = ppr_fun_ty ctxt_prec ty1 ty2 ppr_mono_ty _ (HsTupleTy con tys) = tupleParens con (interpp'SP tys) @@ -376,8 +395,11 @@ ppr_mono_ty _ (HsParTy ty) -- But we still use the precedence stuff to add parens because -- toHsType doesn't put in any HsParTys, so we may still need them -ppr_mono_ty _ (HsDocTy ty doc) - = ppr ty <+> ppr (unLoc doc) +ppr_mono_ty ctxt_prec (HsDocTy ty doc) + = maybeParen ctxt_prec pREC_OP $ + ppr_mono_lty pREC_OP ty <+> ppr (unLoc doc) + -- we pretty print Haddock comments on types as if they were + -- postfix operators -------------------------- ppr_fun_ty :: (OutputableBndr name) => Int -> LHsType name -> LHsType name -> SDoc