From 6fd172c2692723ab67fcc1a998feed320a8ab144 Mon Sep 17 00:00:00 2001 From: Max Bolingbroke Date: Mon, 22 Aug 2011 20:25:27 +0100 Subject: Adapt Haddock for the ConstraintKind extension changes --- src/Haddock/Backends/Xhtml/Decl.hs | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'src/Haddock/Backends/Xhtml/Decl.hs') diff --git a/src/Haddock/Backends/Xhtml/Decl.hs b/src/Haddock/Backends/Xhtml/Decl.hs index add926ab..eb1219f4 100644 --- a/src/Haddock/Backends/Xhtml/Decl.hs +++ b/src/Haddock/Backends/Xhtml/Decl.hs @@ -32,9 +32,9 @@ import qualified Data.Map as Map import Data.Maybe import Text.XHtml hiding ( name, title, p, quote ) -import BasicTypes ( IPName(..), Boxity(..) ) import GHC import Name +import BasicTypes ( ipNameName ) import Outputable ( ppr, showSDoc, Outputable ) @@ -301,7 +301,7 @@ ppContextNoArrow [] _ _ = noHtml ppContextNoArrow cxt unicode qual = pp_hs_context (map unLoc cxt) unicode qual -ppContextNoLocs :: [HsPred DocName] -> Bool -> Qualification -> Html +ppContextNoLocs :: [HsType DocName] -> Bool -> Qualification -> Html ppContextNoLocs [] _ _ = noHtml ppContextNoLocs cxt unicode qual = pp_hs_context cxt unicode qual <+> darrow unicode @@ -311,18 +311,10 @@ ppContext :: HsContext DocName -> Bool -> Qualification -> Html ppContext cxt unicode qual = ppContextNoLocs (map unLoc cxt) unicode qual -pp_hs_context :: [HsPred DocName] -> Bool -> Qualification-> Html +pp_hs_context :: [HsType DocName] -> Bool -> Qualification-> Html pp_hs_context [] _ _ = noHtml -pp_hs_context [p] unicode qual = ppPred unicode qual p -pp_hs_context cxt unicode qual = parenList (map (ppPred unicode qual) cxt) - - -ppPred :: Bool -> Qualification -> HsPred DocName -> Html -ppPred unicode qual (HsClassP n ts) = ppAppNameTypes n (map unLoc ts) unicode qual -ppPred unicode qual (HsEqualP t1 t2) = ppLType unicode qual t1 <+> toHtml "~" - <+> ppLType unicode qual t2 -ppPred unicode qual (HsIParam (IPName n) t) - = toHtml "?" +++ ppDocName qual n <+> dcolon unicode <+> ppLType unicode qual t +pp_hs_context [p] unicode qual = ppType unicode qual p +pp_hs_context cxt unicode qual = parenList (map (ppType unicode qual) cxt) ------------------------------------------------------------------------------- @@ -330,7 +322,7 @@ ppPred unicode qual (HsIParam (IPName n) t) ------------------------------------------------------------------------------- -ppClassHdr :: Bool -> Located [LHsPred DocName] -> DocName +ppClassHdr :: Bool -> Located [LHsType DocName] -> DocName -> [Located (HsTyVarBndr DocName)] -> [Located ([DocName], [DocName])] -> Bool -> Qualification -> Html ppClassHdr summ lctxt n tvs fds unicode qual = @@ -653,9 +645,9 @@ ppBang _ = toHtml "!" -- Unpacked args is an implementation detail, -- so we just show the strictness annotation -tupleParens :: Boxity -> [Html] -> Html -tupleParens Boxed = parenList -tupleParens Unboxed = ubxParenList +tupleParens :: HsTupleSort -> [Html] -> Html +tupleParens (HsBoxyTuple _) = parenList +tupleParens HsUnboxedTuple = ubxParenList -------------------------------------------------------------------------------- @@ -724,7 +716,7 @@ ppr_mono_ty _ (HsKindSig ty kind) u q = parens (ppr_mono_lty pREC_TOP ty u q <+> dcolon u <+> ppKind kind) ppr_mono_ty _ (HsListTy ty) u q = brackets (ppr_mono_lty pREC_TOP ty u q) ppr_mono_ty _ (HsPArrTy ty) u q = pabrackets (ppr_mono_lty pREC_TOP ty u q) -ppr_mono_ty _ (HsPredTy p) u q = parens (ppPred u q p) +ppr_mono_ty _ (HsIParamTy n ty) u q = brackets (ppDocName q (ipNameName n) <+> dcolon u <+> ppr_mono_lty pREC_TOP ty u q) ppr_mono_ty _ (HsSpliceTy {}) _ _ = error "ppr_mono_ty HsSpliceTy" #if __GLASGOW_HASKELL__ == 612 ppr_mono_ty _ (HsSpliceTyOut {}) _ _ = error "ppr_mono_ty HsQuasiQuoteTy" @@ -734,6 +726,10 @@ ppr_mono_ty _ (HsQuasiQuoteTy {}) _ _ = error "ppr_mono_ty HsQuasiQuoteT ppr_mono_ty _ (HsRecTy {}) _ _ = error "ppr_mono_ty HsRecTy" ppr_mono_ty _ (HsCoreTy {}) _ _ = error "ppr_mono_ty HsCoreTy" +ppr_mono_ty ctxt_prec (HsEqTy ty1 ty2) unicode qual + = maybeParen ctxt_prec pREC_OP $ + ppr_mono_lty pREC_OP ty1 unicode qual <+> char '~' <+> ppr_mono_lty pREC_OP ty2 unicode qual + ppr_mono_ty ctxt_prec (HsAppTy fun_ty arg_ty) unicode qual = maybeParen ctxt_prec pREC_CON $ hsep [ppr_mono_lty pREC_FUN fun_ty unicode qual, ppr_mono_lty pREC_CON arg_ty unicode qual] -- cgit v1.2.3 From 0f21c474382af69bb7dac214d6c225218240e033 Mon Sep 17 00:00:00 2001 From: Max Bolingbroke Date: Tue, 6 Sep 2011 09:13:59 +0100 Subject: Ignore associated type defaults (just as we ignore default methods) --- src/Haddock/Backends/LaTeX.hs | 6 +++--- src/Haddock/Backends/Xhtml/Decl.hs | 4 ++-- src/Haddock/Convert.hs | 13 ++++++++++--- src/Haddock/Interface/Rename.hs | 5 +++-- 4 files changed, 18 insertions(+), 10 deletions(-) (limited to 'src/Haddock/Backends/Xhtml/Decl.hs') diff --git a/src/Haddock/Backends/LaTeX.hs b/src/Haddock/Backends/LaTeX.hs index 27f6bd5e..a6e1bcdc 100644 --- a/src/Haddock/Backends/LaTeX.hs +++ b/src/Haddock/Backends/LaTeX.hs @@ -473,7 +473,7 @@ ppClassDecl :: [DocInstance DocName] -> SrcSpan -> Maybe (Doc DocName) -> [(DocName, DocForDecl DocName)] -> TyClDecl DocName -> Bool -> LaTeX ppClassDecl instances loc mbDoc subdocs - (ClassDecl lctxt lname ltyvars lfds lsigs _ ats _) unicode + (ClassDecl lctxt lname ltyvars lfds lsigs _ ats at_defs _) unicode = declWithDoc classheader (if null body then Nothing else Just (vcat body)) $$ instancesBit where @@ -486,8 +486,8 @@ ppClassDecl instances loc mbDoc subdocs body = catMaybes [fmap docToLaTeX mbDoc, body_] body_ - | null lsigs, null ats = Nothing - | null ats = Just methodTable + | null lsigs, null ats, null at_defs = Nothing + | null ats, null at_defs = Just methodTable --- | otherwise = atTable $$ methodTable | otherwise = error "LaTeX.ppClassDecl" diff --git a/src/Haddock/Backends/Xhtml/Decl.hs b/src/Haddock/Backends/Xhtml/Decl.hs index add926ab..16e32b7e 100644 --- a/src/Haddock/Backends/Xhtml/Decl.hs +++ b/src/Haddock/Backends/Xhtml/Decl.hs @@ -352,7 +352,7 @@ ppFds fds unicode qual = ppShortClassDecl :: Bool -> LinksInfo -> TyClDecl DocName -> SrcSpan -> [(DocName, DocForDecl DocName)] -> Bool -> Qualification -> Html -ppShortClassDecl summary links (ClassDecl lctxt lname tvs fds sigs _ ats _) loc +ppShortClassDecl summary links (ClassDecl lctxt lname tvs fds sigs _ ats _ _) loc subdocs unicode qual = if null sigs && null ats then (if summary then id else topDeclElem links loc [nm]) hdr @@ -381,7 +381,7 @@ ppClassDecl :: Bool -> LinksInfo -> [DocInstance DocName] -> SrcSpan -> Maybe (Doc DocName) -> [(DocName, DocForDecl DocName)] -> TyClDecl DocName -> Bool -> Qualification -> Html ppClassDecl summary links instances loc mbDoc subdocs - decl@(ClassDecl lctxt lname ltyvars lfds lsigs _ ats _) unicode qual + decl@(ClassDecl lctxt lname ltyvars lfds lsigs _ ats _ _) unicode qual | summary = ppShortClassDecl summary links decl loc subdocs unicode qual | otherwise = classheader +++ maybeDocSection qual mbDoc +++ atBit +++ methodBit +++ instancesBit diff --git a/src/Haddock/Convert.hs b/src/Haddock/Convert.hs index 34de6775..81435a6e 100644 --- a/src/Haddock/Convert.hs +++ b/src/Haddock/Convert.hs @@ -68,14 +68,21 @@ tyThingToLHsDecl t = noLoc $ case t of (map (noLoc . synifyIdSig DeleteTopLevelQuantification) (classMethods cl)) emptyBag --ignore default method definitions, they don't affect signature - (map synifyClassAT (classATs cl)) + ats + (concat at_defss) [] --we don't have any docs at this point + where (ats, at_defss) = unzip $ map synifyClassAT (classATItems cl) -- class associated-types are a subset of TyCon -- (mainly only type/data-families) -synifyClassAT :: TyCon -> LTyClDecl Name -synifyClassAT = noLoc . synifyTyCon +synifyClassAT :: ClassATItem -> (LTyClDecl Name, [LTyClDecl Name]) +synifyClassAT (tc, _mb_defs) = (noLoc (synifyTyCon tc), []) + -- ignore the mb_defs since we ignore default methods + +synifyATDefault :: TyCon -> LTyClDecl Name +synifyATDefault tc = noLoc (synifyAxiom ax) + where Just ax = tyConFamilyCoercion_maybe tc synifyAxiom :: CoAxiom -> TyClDecl Name synifyAxiom (CoAxiom { co_ax_tvs = tvs, co_ax_lhs = lhs, co_ax_rhs = rhs }) diff --git a/src/Haddock/Interface/Rename.hs b/src/Haddock/Interface/Rename.hs index 2d5c899a..70520028 100644 --- a/src/Haddock/Interface/Rename.hs +++ b/src/Haddock/Interface/Rename.hs @@ -351,15 +351,16 @@ renameTyClD d = case d of typats' <- mapM (mapM renameLType) typats return (TySynonym lname' ltyvars' typats' ltype') - ClassDecl lcontext lname ltyvars lfundeps lsigs _ ats _ -> do + ClassDecl lcontext lname ltyvars lfundeps lsigs _ ats at_defs _ -> do lcontext' <- renameLContext lcontext lname' <- renameL lname ltyvars' <- mapM renameLTyVarBndr ltyvars lfundeps' <- mapM renameLFunDep lfundeps lsigs' <- mapM renameLSig lsigs ats' <- mapM renameLTyClD ats + at_defs' <- mapM renameLTyClD at_defs -- we don't need the default methods or the already collected doc entities - return (ClassDecl lcontext' lname' ltyvars' lfundeps' lsigs' emptyBag ats' []) + return (ClassDecl lcontext' lname' ltyvars' lfundeps' lsigs' emptyBag ats' at_defs' []) where renameLCon (L loc con) = return . L loc =<< renameCon con -- cgit v1.2.3 From 8b2ee333020aeb9e639cd1772e1dca3b4b4ef3d2 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Sat, 1 Oct 2011 01:34:06 +0100 Subject: Follow changes to ForeignImport/ForeignExport in GHC --- src/Haddock/Backends/Hoogle.hs | 4 ++-- src/Haddock/Backends/Xhtml/Decl.hs | 2 +- src/Haddock/GhcUtils.hs | 4 ++-- src/Haddock/Interface/Create.hs | 2 +- src/Haddock/Interface/ExtractFnArgDocs.hs | 2 +- src/Haddock/Interface/Rename.hs | 8 ++++---- 6 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/Haddock/Backends/Xhtml/Decl.hs') diff --git a/src/Haddock/Backends/Hoogle.hs b/src/Haddock/Backends/Hoogle.hs index adf95636..45399963 100644 --- a/src/Haddock/Backends/Hoogle.hs +++ b/src/Haddock/Backends/Hoogle.hs @@ -114,8 +114,8 @@ ppExport (ExportDecl decl dc subdocs _) = doc (fst dc) ++ f (unL decl) f (TyClD d@TyData{}) = ppData d subdocs f (TyClD d@ClassDecl{}) = ppClass d f (TyClD d@TySynonym{}) = ppSynonym d - f (ForD (ForeignImport name typ _)) = ppSig $ TypeSig [name] typ - f (ForD (ForeignExport name typ _)) = ppSig $ TypeSig [name] typ + f (ForD (ForeignImport name typ _ _)) = ppSig $ TypeSig [name] typ + f (ForD (ForeignExport name typ _ _)) = ppSig $ TypeSig [name] typ f (SigD sig) = ppSig sig f _ = [] ppExport _ = [] diff --git a/src/Haddock/Backends/Xhtml/Decl.hs b/src/Haddock/Backends/Xhtml/Decl.hs index 28132046..c1f3a89a 100644 --- a/src/Haddock/Backends/Xhtml/Decl.hs +++ b/src/Haddock/Backends/Xhtml/Decl.hs @@ -114,7 +114,7 @@ tyvarNames = map (getName . hsTyVarName . unLoc) ppFor :: Bool -> LinksInfo -> SrcSpan -> DocForDecl DocName -> ForeignDecl DocName -> Bool -> Qualification -> Html -ppFor summary links loc doc (ForeignImport (L _ name) (L _ typ) _) unicode qual +ppFor summary links loc doc (ForeignImport (L _ name) (L _ typ) _ _) unicode qual = ppFunSig summary links loc doc [name] typ unicode qual ppFor _ _ _ _ _ _ _ = error "ppFor" diff --git a/src/Haddock/GhcUtils.hs b/src/Haddock/GhcUtils.hs index f79acd94..33ae1b6d 100644 --- a/src/Haddock/GhcUtils.hs +++ b/src/Haddock/GhcUtils.hs @@ -96,8 +96,8 @@ getMainDeclBinder (ValD d) = #endif getMainDeclBinder (SigD d) = sigNameNoLoc d -getMainDeclBinder (ForD (ForeignImport name _ _)) = [unLoc name] -getMainDeclBinder (ForD (ForeignExport _ _ _)) = [] +getMainDeclBinder (ForD (ForeignImport name _ _ _)) = [unLoc name] +getMainDeclBinder (ForD (ForeignExport _ _ _ _)) = [] getMainDeclBinder _ = [] -- Useful when there is a signature with multiple names, e.g. diff --git a/src/Haddock/Interface/Create.hs b/src/Haddock/Interface/Create.hs index 860a0044..057fceb7 100644 --- a/src/Haddock/Interface/Create.hs +++ b/src/Haddock/Interface/Create.hs @@ -263,7 +263,7 @@ declsFromClass class_ = docs ++ defs ++ sigs ++ ats declNames :: HsDecl a -> [a] declNames (TyClD d) = [tcdName d] -declNames (ForD (ForeignImport n _ _)) = [unLoc n] +declNames (ForD (ForeignImport n _ _ _)) = [unLoc n] -- we have normal sigs only (since they are taken from ValBindsOut) declNames (SigD sig) = sigNameNoLoc sig declNames _ = error "unexpected argument to declNames" diff --git a/src/Haddock/Interface/ExtractFnArgDocs.hs b/src/Haddock/Interface/ExtractFnArgDocs.hs index 8889c3ab..a9f8a807 100644 --- a/src/Haddock/Interface/ExtractFnArgDocs.hs +++ b/src/Haddock/Interface/ExtractFnArgDocs.hs @@ -24,7 +24,7 @@ import GHC getDeclFnArgDocs :: HsDecl Name -> Map Int HsDocString getDeclFnArgDocs (SigD (TypeSig _ ty)) = getTypeFnArgDocs ty -getDeclFnArgDocs (ForD (ForeignImport _ ty _)) = getTypeFnArgDocs ty +getDeclFnArgDocs (ForD (ForeignImport _ ty _ _)) = getTypeFnArgDocs ty getDeclFnArgDocs (TyClD (TySynonym {tcdSynRhs = ty})) = getTypeFnArgDocs ty getDeclFnArgDocs _ = Map.empty diff --git a/src/Haddock/Interface/Rename.hs b/src/Haddock/Interface/Rename.hs index 4ea22a2e..546ba62b 100644 --- a/src/Haddock/Interface/Rename.hs +++ b/src/Haddock/Interface/Rename.hs @@ -392,14 +392,14 @@ renameSig sig = case sig of renameForD :: ForeignDecl Name -> RnM (ForeignDecl DocName) -renameForD (ForeignImport lname ltype x) = do +renameForD (ForeignImport lname ltype co x) = do lname' <- renameL lname ltype' <- renameLType ltype - return (ForeignImport lname' ltype' x) -renameForD (ForeignExport lname ltype x) = do + return (ForeignImport lname' ltype' co x) +renameForD (ForeignExport lname ltype co x) = do lname' <- renameL lname ltype' <- renameLType ltype - return (ForeignExport lname' ltype' x) + return (ForeignExport lname' ltype' co x) renameInstD :: InstDecl Name -> RnM (InstDecl DocName) -- cgit v1.2.3