{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ViewPatterns #-}
module ExtractDocs (extractDocs) where
import GhcPrelude
import Bag
import HsBinds
import HsDoc
import HsDecls
import HsExtension
import HsTypes
import HsUtils
import Name
import NameSet
import SrcLoc
import TcRnTypes
import Control.Applicative
import Data.List
import Data.Map (Map)
import qualified Data.Map as M
import Data.Maybe
import Data.Semigroup
extractDocs :: TcGblEnv
-> (Maybe HsDocString, DeclDocMap, ArgDocMap)
TcGblEnv { tcg_semantic_mod :: TcGblEnv -> Module
tcg_semantic_mod = Module
mod
, tcg_rn_decls :: TcGblEnv -> Maybe (HsGroup GhcRn)
tcg_rn_decls = Maybe (HsGroup GhcRn)
mb_rn_decls
, tcg_insts :: TcGblEnv -> [ClsInst]
tcg_insts = [ClsInst]
insts
, tcg_fam_insts :: TcGblEnv -> [FamInst]
tcg_fam_insts = [FamInst]
fam_insts
, tcg_doc_hdr :: TcGblEnv -> Maybe LHsDocString
tcg_doc_hdr = Maybe LHsDocString
mb_doc_hdr
} =
(LHsDocString -> HsDocString
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (LHsDocString -> HsDocString)
-> Maybe LHsDocString -> Maybe HsDocString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe LHsDocString
mb_doc_hdr, Map Name HsDocString -> DeclDocMap
DeclDocMap Map Name HsDocString
doc_map, Map Name (Map Int HsDocString) -> ArgDocMap
ArgDocMap Map Name (Map Int HsDocString)
arg_map)
where
(doc_map :: Map Name HsDocString
doc_map, arg_map :: Map Name (Map Int HsDocString)
arg_map) = (Map Name HsDocString, Map Name (Map Int HsDocString))
-> ([(LHsDecl GhcRn, [HsDocString])]
-> (Map Name HsDocString, Map Name (Map Int HsDocString)))
-> Maybe [(LHsDecl GhcRn, [HsDocString])]
-> (Map Name HsDocString, Map Name (Map Int HsDocString))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Map Name HsDocString
forall k a. Map k a
M.empty, Map Name (Map Int HsDocString)
forall k a. Map k a
M.empty)
([Name]
-> [(LHsDecl GhcRn, [HsDocString])]
-> (Map Name HsDocString, Map Name (Map Int HsDocString))
mkMaps [Name]
local_insts)
Maybe [(LHsDecl GhcRn, [HsDocString])]
mb_decls_with_docs
mb_decls_with_docs :: Maybe [(LHsDecl GhcRn, [HsDocString])]
mb_decls_with_docs = HsGroup GhcRn -> [(LHsDecl GhcRn, [HsDocString])]
topDecls (HsGroup GhcRn -> [(LHsDecl GhcRn, [HsDocString])])
-> Maybe (HsGroup GhcRn) -> Maybe [(LHsDecl GhcRn, [HsDocString])]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (HsGroup GhcRn)
mb_rn_decls
local_insts :: [Name]
local_insts = (Name -> Bool) -> [Name] -> [Name]
forall a. (a -> Bool) -> [a] -> [a]
filter (Module -> Name -> Bool
nameIsLocalOrFrom Module
mod)
([Name] -> [Name]) -> [Name] -> [Name]
forall a b. (a -> b) -> a -> b
$ (ClsInst -> Name) -> [ClsInst] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map ClsInst -> Name
forall a. NamedThing a => a -> Name
getName [ClsInst]
insts [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ (FamInst -> Name) -> [FamInst] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map FamInst -> Name
forall a. NamedThing a => a -> Name
getName [FamInst]
fam_insts
mkMaps :: [Name]
-> [(LHsDecl GhcRn, [HsDocString])]
-> (Map Name (HsDocString), Map Name (Map Int (HsDocString)))
mkMaps :: [Name]
-> [(LHsDecl GhcRn, [HsDocString])]
-> (Map Name HsDocString, Map Name (Map Int HsDocString))
mkMaps instances :: [Name]
instances decls :: [(LHsDecl GhcRn, [HsDocString])]
decls =
( [[(Name, HsDocString)]] -> Map Name HsDocString
forall a. Ord a => [[(a, HsDocString)]] -> Map a HsDocString
f' (([(Name, HsDocString)] -> [(Name, HsDocString)])
-> [[(Name, HsDocString)]] -> [[(Name, HsDocString)]]
forall a b. (a -> b) -> [a] -> [b]
map (((Name, HsDocString) -> Name)
-> [(Name, HsDocString)] -> [(Name, HsDocString)]
forall a. (a -> Name) -> [a] -> [a]
nubByName (Name, HsDocString) -> Name
forall a b. (a, b) -> a
fst) [[(Name, HsDocString)]]
decls')
, [[(Name, Map Int HsDocString)]] -> Map Name (Map Int HsDocString)
forall a b. (Ord a, Semigroup b) => [[(a, b)]] -> Map a b
f ((Map Int HsDocString -> Bool)
-> [[(Name, Map Int HsDocString)]]
-> [[(Name, Map Int HsDocString)]]
forall b a. (b -> Bool) -> [[(a, b)]] -> [[(a, b)]]
filterMapping (Bool -> Bool
not (Bool -> Bool)
-> (Map Int HsDocString -> Bool) -> Map Int HsDocString -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map Int HsDocString -> Bool
forall k a. Map k a -> Bool
M.null) [[(Name, Map Int HsDocString)]]
args)
)
where
(decls' :: [[(Name, HsDocString)]]
decls', args :: [[(Name, Map Int HsDocString)]]
args) = [([(Name, HsDocString)], [(Name, Map Int HsDocString)])]
-> ([[(Name, HsDocString)]], [[(Name, Map Int HsDocString)]])
forall a b. [(a, b)] -> ([a], [b])
unzip (((LHsDecl GhcRn, [HsDocString])
-> ([(Name, HsDocString)], [(Name, Map Int HsDocString)]))
-> [(LHsDecl GhcRn, [HsDocString])]
-> [([(Name, HsDocString)], [(Name, Map Int HsDocString)])]
forall a b. (a -> b) -> [a] -> [b]
map (LHsDecl GhcRn, [HsDocString])
-> ([(Name, HsDocString)], [(Name, Map Int HsDocString)])
mappings [(LHsDecl GhcRn, [HsDocString])]
decls)
f :: (Ord a, Semigroup b) => [[(a, b)]] -> Map a b
f :: [[(a, b)]] -> Map a b
f = (b -> b -> b) -> [(a, b)] -> Map a b
forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
M.fromListWith b -> b -> b
forall a. Semigroup a => a -> a -> a
(<>) ([(a, b)] -> Map a b)
-> ([[(a, b)]] -> [(a, b)]) -> [[(a, b)]] -> Map a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[(a, b)]] -> [(a, b)]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
f' :: Ord a => [[(a, HsDocString)]] -> Map a HsDocString
f' :: [[(a, HsDocString)]] -> Map a HsDocString
f' = (HsDocString -> HsDocString -> HsDocString)
-> [(a, HsDocString)] -> Map a HsDocString
forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
M.fromListWith HsDocString -> HsDocString -> HsDocString
appendDocs ([(a, HsDocString)] -> Map a HsDocString)
-> ([[(a, HsDocString)]] -> [(a, HsDocString)])
-> [[(a, HsDocString)]]
-> Map a HsDocString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[(a, HsDocString)]] -> [(a, HsDocString)]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
filterMapping :: (b -> Bool) -> [[(a, b)]] -> [[(a, b)]]
filterMapping :: (b -> Bool) -> [[(a, b)]] -> [[(a, b)]]
filterMapping p :: b -> Bool
p = ([(a, b)] -> [(a, b)]) -> [[(a, b)]] -> [[(a, b)]]
forall a b. (a -> b) -> [a] -> [b]
map (((a, b) -> Bool) -> [(a, b)] -> [(a, b)]
forall a. (a -> Bool) -> [a] -> [a]
filter (b -> Bool
p (b -> Bool) -> ((a, b) -> b) -> (a, b) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, b) -> b
forall a b. (a, b) -> b
snd))
mappings :: (LHsDecl GhcRn, [HsDocString])
-> ( [(Name, HsDocString)]
, [(Name, Map Int (HsDocString))]
)
mappings :: (LHsDecl GhcRn, [HsDocString])
-> ([(Name, HsDocString)], [(Name, Map Int HsDocString)])
mappings (L l :: SrcSpan
l decl :: HsDecl GhcRn
decl, docStrs :: [HsDocString]
docStrs) =
([(Name, HsDocString)]
dm, [(Name, Map Int HsDocString)]
am)
where
doc :: Maybe HsDocString
doc = [HsDocString] -> Maybe HsDocString
concatDocs [HsDocString]
docStrs
args :: Map Int HsDocString
args = HsDecl GhcRn -> Map Int HsDocString
declTypeDocs HsDecl GhcRn
decl
subs :: [(Name, [(HsDocString)], Map Int (HsDocString))]
subs :: [(Name, [HsDocString], Map Int HsDocString)]
subs = Map SrcSpan Name
-> HsDecl GhcRn -> [(Name, [HsDocString], Map Int HsDocString)]
subordinates Map SrcSpan Name
instanceMap HsDecl GhcRn
decl
(subDocs :: [Maybe HsDocString]
subDocs, subArgs :: [Map Int HsDocString]
subArgs) =
[(Maybe HsDocString, Map Int HsDocString)]
-> ([Maybe HsDocString], [Map Int HsDocString])
forall a b. [(a, b)] -> ([a], [b])
unzip (((Name, [HsDocString], Map Int HsDocString)
-> (Maybe HsDocString, Map Int HsDocString))
-> [(Name, [HsDocString], Map Int HsDocString)]
-> [(Maybe HsDocString, Map Int HsDocString)]
forall a b. (a -> b) -> [a] -> [b]
map (\(_, strs :: [HsDocString]
strs, m :: Map Int HsDocString
m) -> ([HsDocString] -> Maybe HsDocString
concatDocs [HsDocString]
strs, Map Int HsDocString
m)) [(Name, [HsDocString], Map Int HsDocString)]
subs)
ns :: [Name]
ns = SrcSpan -> HsDecl GhcRn -> [Name]
names SrcSpan
l HsDecl GhcRn
decl
subNs :: [Name]
subNs = [ Name
n | (n :: Name
n, _, _) <- [(Name, [HsDocString], Map Int HsDocString)]
subs ]
dm :: [(Name, HsDocString)]
dm = [(Name
n, HsDocString
d) | (n :: Name
n, Just d :: HsDocString
d) <- [Name] -> [Maybe HsDocString] -> [(Name, Maybe HsDocString)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Name]
ns (Maybe HsDocString -> [Maybe HsDocString]
forall a. a -> [a]
repeat Maybe HsDocString
doc) [(Name, Maybe HsDocString)]
-> [(Name, Maybe HsDocString)] -> [(Name, Maybe HsDocString)]
forall a. [a] -> [a] -> [a]
++ [Name] -> [Maybe HsDocString] -> [(Name, Maybe HsDocString)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Name]
subNs [Maybe HsDocString]
subDocs]
am :: [(Name, Map Int HsDocString)]
am = [(Name
n, Map Int HsDocString
args) | Name
n <- [Name]
ns] [(Name, Map Int HsDocString)]
-> [(Name, Map Int HsDocString)] -> [(Name, Map Int HsDocString)]
forall a. [a] -> [a] -> [a]
++ [Name] -> [Map Int HsDocString] -> [(Name, Map Int HsDocString)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Name]
subNs [Map Int HsDocString]
subArgs
instanceMap :: Map SrcSpan Name
instanceMap :: Map SrcSpan Name
instanceMap = [(SrcSpan, Name)] -> Map SrcSpan Name
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(Name -> SrcSpan
forall a. NamedThing a => a -> SrcSpan
getSrcSpan Name
n, Name
n) | Name
n <- [Name]
instances]
names :: SrcSpan -> HsDecl GhcRn -> [Name]
names :: SrcSpan -> HsDecl GhcRn -> [Name]
names l :: SrcSpan
l (InstD _ d :: InstDecl GhcRn
d) = Maybe Name -> [Name]
forall a. Maybe a -> [a]
maybeToList (SrcSpan -> Map SrcSpan Name -> Maybe Name
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup SrcSpan
loc Map SrcSpan Name
instanceMap)
where loc :: SrcSpan
loc = case InstDecl GhcRn
d of
TyFamInstD _ _ -> SrcSpan
l
_ -> InstDecl GhcRn -> SrcSpan
forall name. InstDecl name -> SrcSpan
getInstLoc InstDecl GhcRn
d
names l :: SrcSpan
l (DerivD {}) = Maybe Name -> [Name]
forall a. Maybe a -> [a]
maybeToList (SrcSpan -> Map SrcSpan Name -> Maybe Name
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup SrcSpan
l Map SrcSpan Name
instanceMap)
names _ decl :: HsDecl GhcRn
decl = HsDecl GhcRn -> [IdP GhcRn]
forall (p :: Pass). HsDecl (GhcPass p) -> [IdP (GhcPass p)]
getMainDeclBinder HsDecl GhcRn
decl
getMainDeclBinder :: HsDecl (GhcPass p) -> [IdP (GhcPass p)]
getMainDeclBinder :: HsDecl (GhcPass p) -> [IdP (GhcPass p)]
getMainDeclBinder (TyClD _ d :: TyClDecl (GhcPass p)
d) = [TyClDecl (GhcPass p) -> IdP (GhcPass p)
forall pass. TyClDecl pass -> IdP pass
tcdName TyClDecl (GhcPass p)
d]
getMainDeclBinder (ValD _ d :: HsBind (GhcPass p)
d) =
case HsBind (GhcPass p) -> [IdP (GhcPass p)]
forall p idR.
(SrcSpanLess (LPat p) ~ LPat p, HasSrcSpan (LPat p)) =>
HsBindLR p idR -> [IdP p]
collectHsBindBinders HsBind (GhcPass p)
d of
[] -> []
(name :: IdP (GhcPass p)
name:_) -> [IdP (GhcPass p)
name]
getMainDeclBinder (SigD _ d :: Sig (GhcPass p)
d) = Sig (GhcPass p) -> [IdP (GhcPass p)]
forall pass. Sig pass -> [IdP pass]
sigNameNoLoc Sig (GhcPass p)
d
getMainDeclBinder (ForD _ (ForeignImport _ name :: Located (IdP (GhcPass p))
name _ _)) = [Located (IdP (GhcPass p))
-> SrcSpanLess (Located (IdP (GhcPass p)))
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Located (IdP (GhcPass p))
name]
getMainDeclBinder (ForD _ (ForeignExport _ _ _ _)) = []
getMainDeclBinder _ = []
sigNameNoLoc :: Sig pass -> [IdP pass]
sigNameNoLoc :: Sig pass -> [IdP pass]
sigNameNoLoc (TypeSig _ ns :: [Located (IdP pass)]
ns _) = (Located (IdP pass) -> IdP pass)
-> [Located (IdP pass)] -> [IdP pass]
forall a b. (a -> b) -> [a] -> [b]
map Located (IdP pass) -> IdP pass
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc [Located (IdP pass)]
ns
sigNameNoLoc (ClassOpSig _ _ ns :: [Located (IdP pass)]
ns _) = (Located (IdP pass) -> IdP pass)
-> [Located (IdP pass)] -> [IdP pass]
forall a b. (a -> b) -> [a] -> [b]
map Located (IdP pass) -> IdP pass
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc [Located (IdP pass)]
ns
sigNameNoLoc (PatSynSig _ ns :: [Located (IdP pass)]
ns _) = (Located (IdP pass) -> IdP pass)
-> [Located (IdP pass)] -> [IdP pass]
forall a b. (a -> b) -> [a] -> [b]
map Located (IdP pass) -> IdP pass
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc [Located (IdP pass)]
ns
sigNameNoLoc (SpecSig _ n :: Located (IdP pass)
n _ _) = [Located (IdP pass) -> SrcSpanLess (Located (IdP pass))
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Located (IdP pass)
n]
sigNameNoLoc (InlineSig _ n :: Located (IdP pass)
n _) = [Located (IdP pass) -> SrcSpanLess (Located (IdP pass))
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Located (IdP pass)
n]
sigNameNoLoc (FixSig _ (FixitySig _ ns :: [Located (IdP pass)]
ns _)) = (Located (IdP pass) -> IdP pass)
-> [Located (IdP pass)] -> [IdP pass]
forall a b. (a -> b) -> [a] -> [b]
map Located (IdP pass) -> IdP pass
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc [Located (IdP pass)]
ns
sigNameNoLoc _ = []
getInstLoc :: InstDecl name -> SrcSpan
getInstLoc :: InstDecl name -> SrcSpan
getInstLoc = \case
ClsInstD _ (ClsInstDecl { cid_poly_ty :: forall pass. ClsInstDecl pass -> LHsSigType pass
cid_poly_ty = LHsSigType name
ty }) -> LHsType name -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc (LHsSigType name -> LHsType name
forall pass. LHsSigType pass -> LHsType pass
hsSigType LHsSigType name
ty)
DataFamInstD _ (DataFamInstDecl
{ dfid_eqn :: forall pass.
DataFamInstDecl pass -> FamInstEqn pass (HsDataDefn pass)
dfid_eqn = HsIB { hsib_body :: forall pass thing. HsImplicitBndrs pass thing -> thing
hsib_body = FamEqn { feqn_tycon :: forall pass pats rhs. FamEqn pass pats rhs -> Located (IdP pass)
feqn_tycon = (Located (IdP name) -> Located (SrcSpanLess (Located (IdP name)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L l :: SrcSpan
l _) }}}) -> SrcSpan
l
TyFamInstD _ (TyFamInstDecl
{ tfid_eqn :: forall pass. TyFamInstDecl pass -> TyFamInstEqn pass
tfid_eqn = HsIB { hsib_body :: forall pass thing. HsImplicitBndrs pass thing -> thing
hsib_body = FamEqn { feqn_rhs :: forall pass pats rhs. FamEqn pass pats rhs -> rhs
feqn_rhs = (LHsType name -> Located (SrcSpanLess (LHsType name))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L l :: SrcSpan
l _) }}}) -> SrcSpan
l
ClsInstD _ (XClsInstDecl _) -> [Char] -> SrcSpan
forall a. HasCallStack => [Char] -> a
error "getInstLoc"
DataFamInstD _ (DataFamInstDecl (HsIB _ (XFamEqn _))) -> [Char] -> SrcSpan
forall a. HasCallStack => [Char] -> a
error "getInstLoc"
TyFamInstD _ (TyFamInstDecl (HsIB _ (XFamEqn _))) -> [Char] -> SrcSpan
forall a. HasCallStack => [Char] -> a
error "getInstLoc"
XInstDecl _ -> [Char] -> SrcSpan
forall a. HasCallStack => [Char] -> a
error "getInstLoc"
DataFamInstD _ (DataFamInstDecl (XHsImplicitBndrs _)) -> [Char] -> SrcSpan
forall a. HasCallStack => [Char] -> a
error "getInstLoc"
TyFamInstD _ (TyFamInstDecl (XHsImplicitBndrs _)) -> [Char] -> SrcSpan
forall a. HasCallStack => [Char] -> a
error "getInstLoc"
subordinates :: Map SrcSpan Name
-> HsDecl GhcRn
-> [(Name, [(HsDocString)], Map Int (HsDocString))]
subordinates :: Map SrcSpan Name
-> HsDecl GhcRn -> [(Name, [HsDocString], Map Int HsDocString)]
subordinates instMap :: Map SrcSpan Name
instMap decl :: HsDecl GhcRn
decl = case HsDecl GhcRn
decl of
InstD _ (ClsInstD _ d :: ClsInstDecl GhcRn
d) -> do
DataFamInstDecl { dfid_eqn :: forall pass.
DataFamInstDecl pass -> FamInstEqn pass (HsDataDefn pass)
dfid_eqn = HsIB { hsib_body :: forall pass thing. HsImplicitBndrs pass thing -> thing
hsib_body =
FamEqn { feqn_tycon :: forall pass pats rhs. FamEqn pass pats rhs -> Located (IdP pass)
feqn_tycon = (Located (IdP GhcRn) -> Located (SrcSpanLess (Located Name))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L l :: SrcSpan
l _)
, feqn_rhs :: forall pass pats rhs. FamEqn pass pats rhs -> rhs
feqn_rhs = HsDataDefn GhcRn
defn }}} <- LDataFamInstDecl GhcRn -> DataFamInstDecl GhcRn
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (LDataFamInstDecl GhcRn -> DataFamInstDecl GhcRn)
-> [LDataFamInstDecl GhcRn] -> [DataFamInstDecl GhcRn]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ClsInstDecl GhcRn -> [LDataFamInstDecl GhcRn]
forall pass. ClsInstDecl pass -> [LDataFamInstDecl pass]
cid_datafam_insts ClsInstDecl GhcRn
d
[ (Name
n, [], Map Int HsDocString
forall k a. Map k a
M.empty) | Just n :: Name
n <- [SrcSpan -> Map SrcSpan Name -> Maybe Name
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup SrcSpan
l Map SrcSpan Name
instMap] ] [(Name, [HsDocString], Map Int HsDocString)]
-> [(Name, [HsDocString], Map Int HsDocString)]
-> [(Name, [HsDocString], Map Int HsDocString)]
forall a. [a] -> [a] -> [a]
++ HsDataDefn GhcRn -> [(Name, [HsDocString], Map Int HsDocString)]
dataSubs HsDataDefn GhcRn
defn
InstD _ (DataFamInstD _ (DataFamInstDecl (HsIB { hsib_body :: forall pass thing. HsImplicitBndrs pass thing -> thing
hsib_body = FamEqn GhcRn (HsTyPats GhcRn) (HsDataDefn GhcRn)
d })))
-> HsDataDefn GhcRn -> [(Name, [HsDocString], Map Int HsDocString)]
dataSubs (FamEqn GhcRn (HsTyPats GhcRn) (HsDataDefn GhcRn)
-> HsDataDefn GhcRn
forall pass pats rhs. FamEqn pass pats rhs -> rhs
feqn_rhs FamEqn GhcRn (HsTyPats GhcRn) (HsDataDefn GhcRn)
d)
TyClD _ d :: TyClDecl GhcRn
d | TyClDecl GhcRn -> Bool
forall pass. TyClDecl pass -> Bool
isClassDecl TyClDecl GhcRn
d -> TyClDecl GhcRn -> [(Name, [HsDocString], Map Int HsDocString)]
classSubs TyClDecl GhcRn
d
| TyClDecl GhcRn -> Bool
forall pass. TyClDecl pass -> Bool
isDataDecl TyClDecl GhcRn
d -> HsDataDefn GhcRn -> [(Name, [HsDocString], Map Int HsDocString)]
dataSubs (TyClDecl GhcRn -> HsDataDefn GhcRn
forall pass. TyClDecl pass -> HsDataDefn pass
tcdDataDefn TyClDecl GhcRn
d)
_ -> []
where
classSubs :: TyClDecl GhcRn -> [(Name, [HsDocString], Map Int HsDocString)]
classSubs dd :: TyClDecl GhcRn
dd = [ (Name
name, [HsDocString]
doc, HsDecl GhcRn -> Map Int HsDocString
declTypeDocs SrcSpanLess (LHsDecl GhcRn)
HsDecl GhcRn
d)
| (LHsDecl GhcRn -> Located (SrcSpanLess (LHsDecl GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ d :: SrcSpanLess (LHsDecl GhcRn)
d, doc :: [HsDocString]
doc) <- TyClDecl GhcRn -> [(LHsDecl GhcRn, [HsDocString])]
classDecls TyClDecl GhcRn
dd
, Name
name <- HsDecl GhcRn -> [IdP GhcRn]
forall (p :: Pass). HsDecl (GhcPass p) -> [IdP (GhcPass p)]
getMainDeclBinder SrcSpanLess (LHsDecl GhcRn)
HsDecl GhcRn
d, Bool -> Bool
not (HsDecl GhcRn -> Bool
forall a. HsDecl a -> Bool
isValD SrcSpanLess (LHsDecl GhcRn)
HsDecl GhcRn
d)
]
dataSubs :: HsDataDefn GhcRn
-> [(Name, [HsDocString], Map Int (HsDocString))]
dataSubs :: HsDataDefn GhcRn -> [(Name, [HsDocString], Map Int HsDocString)]
dataSubs dd :: HsDataDefn GhcRn
dd = [(Name, [HsDocString], Map Int HsDocString)]
constrs [(Name, [HsDocString], Map Int HsDocString)]
-> [(Name, [HsDocString], Map Int HsDocString)]
-> [(Name, [HsDocString], Map Int HsDocString)]
forall a. [a] -> [a] -> [a]
++ [(Name, [HsDocString], Map Int HsDocString)]
fields [(Name, [HsDocString], Map Int HsDocString)]
-> [(Name, [HsDocString], Map Int HsDocString)]
-> [(Name, [HsDocString], Map Int HsDocString)]
forall a. [a] -> [a] -> [a]
++ [(Name, [HsDocString], Map Int HsDocString)]
derivs
where
cons :: [ConDecl GhcRn]
cons = (LConDecl GhcRn -> ConDecl GhcRn)
-> [LConDecl GhcRn] -> [ConDecl GhcRn]
forall a b. (a -> b) -> [a] -> [b]
map LConDecl GhcRn -> ConDecl GhcRn
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc ([LConDecl GhcRn] -> [ConDecl GhcRn])
-> [LConDecl GhcRn] -> [ConDecl GhcRn]
forall a b. (a -> b) -> a -> b
$ (HsDataDefn GhcRn -> [LConDecl GhcRn]
forall pass. HsDataDefn pass -> [LConDecl pass]
dd_cons HsDataDefn GhcRn
dd)
constrs :: [(Name, [HsDocString], Map Int HsDocString)]
constrs = [ ( Located Name -> SrcSpanLess (Located Name)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Located Name
cname
, Maybe HsDocString -> [HsDocString]
forall a. Maybe a -> [a]
maybeToList (Maybe HsDocString -> [HsDocString])
-> Maybe HsDocString -> [HsDocString]
forall a b. (a -> b) -> a -> b
$ (LHsDocString -> HsDocString)
-> Maybe LHsDocString -> Maybe HsDocString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap LHsDocString -> HsDocString
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (Maybe LHsDocString -> Maybe HsDocString)
-> Maybe LHsDocString -> Maybe HsDocString
forall a b. (a -> b) -> a -> b
$ ConDecl GhcRn -> Maybe LHsDocString
forall pass. ConDecl pass -> Maybe LHsDocString
con_doc ConDecl GhcRn
c
, ConDecl GhcRn -> Map Int HsDocString
conArgDocs ConDecl GhcRn
c)
| ConDecl GhcRn
c <- [ConDecl GhcRn]
cons, Located Name
cname <- ConDecl GhcRn -> [Located (IdP GhcRn)]
forall pass. ConDecl pass -> [Located (IdP pass)]
getConNames ConDecl GhcRn
c ]
fields :: [(Name, [HsDocString], Map Int HsDocString)]
fields = [ (FieldOcc GhcRn -> XCFieldOcc GhcRn
forall pass. FieldOcc pass -> XCFieldOcc pass
extFieldOcc SrcSpanLess (LFieldOcc GhcRn)
FieldOcc GhcRn
n, Maybe HsDocString -> [HsDocString]
forall a. Maybe a -> [a]
maybeToList (Maybe HsDocString -> [HsDocString])
-> Maybe HsDocString -> [HsDocString]
forall a b. (a -> b) -> a -> b
$ (LHsDocString -> HsDocString)
-> Maybe LHsDocString -> Maybe HsDocString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap LHsDocString -> HsDocString
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Maybe LHsDocString
doc, Map Int HsDocString
forall k a. Map k a
M.empty)
| RecCon flds :: Located [LConDeclField GhcRn]
flds <- (ConDecl GhcRn
-> HsConDetails (LBangType GhcRn) (Located [LConDeclField GhcRn]))
-> [ConDecl GhcRn]
-> [HsConDetails (LBangType GhcRn) (Located [LConDeclField GhcRn])]
forall a b. (a -> b) -> [a] -> [b]
map ConDecl GhcRn
-> HsConDetails (LBangType GhcRn) (Located [LConDeclField GhcRn])
forall pass. ConDecl pass -> HsConDeclDetails pass
getConArgs [ConDecl GhcRn]
cons
, (LConDeclField GhcRn -> Located (SrcSpanLess (LConDeclField GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (ConDeclField _ ns _ doc)) <- (Located [LConDeclField GhcRn]
-> SrcSpanLess (Located [LConDeclField GhcRn])
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Located [LConDeclField GhcRn]
flds)
, (LFieldOcc GhcRn -> Located (SrcSpanLess (LFieldOcc GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ n :: SrcSpanLess (LFieldOcc GhcRn)
n) <- [LFieldOcc GhcRn]
ns ]
derivs :: [(Name, [HsDocString], Map Int HsDocString)]
derivs = [ (Name
instName, [LHsDocString -> SrcSpanLess LHsDocString
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LHsDocString
doc], Map Int HsDocString
forall k a. Map k a
M.empty)
| HsIB { hsib_body :: forall pass thing. HsImplicitBndrs pass thing -> thing
hsib_body = (LBangType GhcRn -> Located (SrcSpanLess (LBangType GhcRn))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L l :: SrcSpan
l (HsDocTy _ _ doc)) }
<- (LHsDerivingClause GhcRn
-> [HsImplicitBndrs GhcRn (LBangType GhcRn)])
-> [LHsDerivingClause GhcRn]
-> [HsImplicitBndrs GhcRn (LBangType GhcRn)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Located [HsImplicitBndrs GhcRn (LBangType GhcRn)]
-> [HsImplicitBndrs GhcRn (LBangType GhcRn)]
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (Located [HsImplicitBndrs GhcRn (LBangType GhcRn)]
-> [HsImplicitBndrs GhcRn (LBangType GhcRn)])
-> (LHsDerivingClause GhcRn
-> Located [HsImplicitBndrs GhcRn (LBangType GhcRn)])
-> LHsDerivingClause GhcRn
-> [HsImplicitBndrs GhcRn (LBangType GhcRn)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsDerivingClause GhcRn
-> Located [HsImplicitBndrs GhcRn (LBangType GhcRn)]
forall pass. HsDerivingClause pass -> Located [LHsSigType pass]
deriv_clause_tys (HsDerivingClause GhcRn
-> Located [HsImplicitBndrs GhcRn (LBangType GhcRn)])
-> (LHsDerivingClause GhcRn -> HsDerivingClause GhcRn)
-> LHsDerivingClause GhcRn
-> Located [HsImplicitBndrs GhcRn (LBangType GhcRn)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LHsDerivingClause GhcRn -> HsDerivingClause GhcRn
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc) ([LHsDerivingClause GhcRn]
-> [HsImplicitBndrs GhcRn (LBangType GhcRn)])
-> [LHsDerivingClause GhcRn]
-> [HsImplicitBndrs GhcRn (LBangType GhcRn)]
forall a b. (a -> b) -> a -> b
$
HsDeriving GhcRn -> [LHsDerivingClause GhcRn]
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (HsDeriving GhcRn -> [LHsDerivingClause GhcRn])
-> HsDeriving GhcRn -> [LHsDerivingClause GhcRn]
forall a b. (a -> b) -> a -> b
$ HsDataDefn GhcRn -> HsDeriving GhcRn
forall pass. HsDataDefn pass -> HsDeriving pass
dd_derivs HsDataDefn GhcRn
dd
, Just instName :: Name
instName <- [SrcSpan -> Map SrcSpan Name -> Maybe Name
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup SrcSpan
l Map SrcSpan Name
instMap] ]
conArgDocs :: ConDecl GhcRn -> Map Int (HsDocString)
conArgDocs :: ConDecl GhcRn -> Map Int HsDocString
conArgDocs con :: ConDecl GhcRn
con = case ConDecl GhcRn
-> HsConDetails (LBangType GhcRn) (Located [LConDeclField GhcRn])
forall pass. ConDecl pass -> HsConDeclDetails pass
getConArgs ConDecl GhcRn
con of
PrefixCon args :: [LBangType GhcRn]
args -> Int -> [HsType GhcRn] -> Map Int HsDocString
forall a pass.
(Ord a, Num a) =>
a -> [HsType pass] -> Map a HsDocString
go 0 ((LBangType GhcRn -> HsType GhcRn)
-> [LBangType GhcRn] -> [HsType GhcRn]
forall a b. (a -> b) -> [a] -> [b]
map LBangType GhcRn -> HsType GhcRn
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc [LBangType GhcRn]
args [HsType GhcRn] -> [HsType GhcRn] -> [HsType GhcRn]
forall a. [a] -> [a] -> [a]
++ [HsType GhcRn]
ret)
InfixCon arg1 :: LBangType GhcRn
arg1 arg2 :: LBangType GhcRn
arg2 -> Int -> [HsType GhcRn] -> Map Int HsDocString
forall a pass.
(Ord a, Num a) =>
a -> [HsType pass] -> Map a HsDocString
go 0 ([LBangType GhcRn -> SrcSpanLess (LBangType GhcRn)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LBangType GhcRn
arg1, LBangType GhcRn -> SrcSpanLess (LBangType GhcRn)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LBangType GhcRn
arg2] [HsType GhcRn] -> [HsType GhcRn] -> [HsType GhcRn]
forall a. [a] -> [a] -> [a]
++ [HsType GhcRn]
ret)
RecCon _ -> Int -> [HsType GhcRn] -> Map Int HsDocString
forall a pass.
(Ord a, Num a) =>
a -> [HsType pass] -> Map a HsDocString
go 1 [HsType GhcRn]
ret
where
go :: a -> [HsType pass] -> Map a HsDocString
go n :: a
n (HsDocTy _ _ (LHsDocString -> Located (SrcSpanLess LHsDocString)
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ ds :: SrcSpanLess LHsDocString
ds) : tys :: [HsType pass]
tys) = a -> HsDocString -> Map a HsDocString -> Map a HsDocString
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert a
n SrcSpanLess LHsDocString
HsDocString
ds (Map a HsDocString -> Map a HsDocString)
-> Map a HsDocString -> Map a HsDocString
forall a b. (a -> b) -> a -> b
$ a -> [HsType pass] -> Map a HsDocString
go (a
na -> a -> a
forall a. Num a => a -> a -> a
+1) [HsType pass]
tys
go n :: a
n (_ : tys :: [HsType pass]
tys) = a -> [HsType pass] -> Map a HsDocString
go (a
na -> a -> a
forall a. Num a => a -> a -> a
+1) [HsType pass]
tys
go _ [] = Map a HsDocString
forall k a. Map k a
M.empty
ret :: [HsType GhcRn]
ret = case ConDecl GhcRn
con of
ConDeclGADT { con_res_ty :: forall pass. ConDecl pass -> LHsType pass
con_res_ty = LBangType GhcRn
res_ty } -> [ LBangType GhcRn -> SrcSpanLess (LBangType GhcRn)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LBangType GhcRn
res_ty ]
_ -> []
isValD :: HsDecl a -> Bool
isValD :: HsDecl a -> Bool
isValD (ValD _ _) = Bool
True
isValD _ = Bool
False
classDecls :: TyClDecl GhcRn -> [(LHsDecl GhcRn, [HsDocString])]
classDecls :: TyClDecl GhcRn -> [(LHsDecl GhcRn, [HsDocString])]
classDecls class_ :: TyClDecl GhcRn
class_ = [(LHsDecl GhcRn, [HsDocString])]
-> [(LHsDecl GhcRn, [HsDocString])]
forall a doc. [(LHsDecl a, doc)] -> [(LHsDecl a, doc)]
filterDecls ([(LHsDecl GhcRn, [HsDocString])]
-> [(LHsDecl GhcRn, [HsDocString])])
-> ([LHsDecl GhcRn] -> [(LHsDecl GhcRn, [HsDocString])])
-> [LHsDecl GhcRn]
-> [(LHsDecl GhcRn, [HsDocString])]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [LHsDecl GhcRn] -> [(LHsDecl GhcRn, [HsDocString])]
forall pass. [LHsDecl pass] -> [(LHsDecl pass, [HsDocString])]
collectDocs ([LHsDecl GhcRn] -> [(LHsDecl GhcRn, [HsDocString])])
-> ([LHsDecl GhcRn] -> [LHsDecl GhcRn])
-> [LHsDecl GhcRn]
-> [(LHsDecl GhcRn, [HsDocString])]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [LHsDecl GhcRn] -> [LHsDecl GhcRn]
forall a. [Located a] -> [Located a]
sortByLoc ([LHsDecl GhcRn] -> [(LHsDecl GhcRn, [HsDocString])])
-> [LHsDecl GhcRn] -> [(LHsDecl GhcRn, [HsDocString])]
forall a b. (a -> b) -> a -> b
$ [LHsDecl GhcRn]
decls
where
decls :: [LHsDecl GhcRn]
decls = [LHsDecl GhcRn]
docs [LHsDecl GhcRn] -> [LHsDecl GhcRn] -> [LHsDecl GhcRn]
forall a. [a] -> [a] -> [a]
++ [LHsDecl GhcRn]
defs [LHsDecl GhcRn] -> [LHsDecl GhcRn] -> [LHsDecl GhcRn]
forall a. [a] -> [a] -> [a]
++ [LHsDecl GhcRn]
sigs [LHsDecl GhcRn] -> [LHsDecl GhcRn] -> [LHsDecl GhcRn]
forall a. [a] -> [a] -> [a]
++ [LHsDecl GhcRn]
ats
docs :: [LHsDecl GhcRn]
docs = (TyClDecl GhcRn -> [Located DocDecl])
-> (DocDecl -> HsDecl GhcRn) -> TyClDecl GhcRn -> [LHsDecl GhcRn]
forall a b c. (a -> [Located b]) -> (b -> c) -> a -> [Located c]
mkDecls TyClDecl GhcRn -> [Located DocDecl]
forall pass. TyClDecl pass -> [Located DocDecl]
tcdDocs (XDocD GhcRn -> DocDecl -> HsDecl GhcRn
forall p. XDocD p -> DocDecl -> HsDecl p
DocD XDocD GhcRn
NoExt
noExt) TyClDecl GhcRn
class_
defs :: [LHsDecl GhcRn]
defs = (TyClDecl GhcRn -> [Located (HsBindLR GhcRn GhcRn)])
-> (HsBindLR GhcRn GhcRn -> HsDecl GhcRn)
-> TyClDecl GhcRn
-> [LHsDecl GhcRn]
forall a b c. (a -> [Located b]) -> (b -> c) -> a -> [Located c]
mkDecls (Bag (Located (HsBindLR GhcRn GhcRn))
-> [Located (HsBindLR GhcRn GhcRn)]
forall a. Bag a -> [a]
bagToList (Bag (Located (HsBindLR GhcRn GhcRn))
-> [Located (HsBindLR GhcRn GhcRn)])
-> (TyClDecl GhcRn -> Bag (Located (HsBindLR GhcRn GhcRn)))
-> TyClDecl GhcRn
-> [Located (HsBindLR GhcRn GhcRn)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TyClDecl GhcRn -> Bag (Located (HsBindLR GhcRn GhcRn))
forall pass. TyClDecl pass -> LHsBinds pass
tcdMeths) (XValD GhcRn -> HsBindLR GhcRn GhcRn -> HsDecl GhcRn
forall p. XValD p -> HsBind p -> HsDecl p
ValD XValD GhcRn
NoExt
noExt) TyClDecl GhcRn
class_
sigs :: [LHsDecl GhcRn]
sigs = (TyClDecl GhcRn -> [Located (Sig GhcRn)])
-> (Sig GhcRn -> HsDecl GhcRn) -> TyClDecl GhcRn -> [LHsDecl GhcRn]
forall a b c. (a -> [Located b]) -> (b -> c) -> a -> [Located c]
mkDecls TyClDecl GhcRn -> [Located (Sig GhcRn)]
forall pass. TyClDecl pass -> [LSig pass]
tcdSigs (XSigD GhcRn -> Sig GhcRn -> HsDecl GhcRn
forall p. XSigD p -> Sig p -> HsDecl p
SigD XSigD GhcRn
NoExt
noExt) TyClDecl GhcRn
class_
ats :: [LHsDecl GhcRn]
ats = (TyClDecl GhcRn -> [Located (FamilyDecl GhcRn)])
-> (FamilyDecl GhcRn -> HsDecl GhcRn)
-> TyClDecl GhcRn
-> [LHsDecl GhcRn]
forall a b c. (a -> [Located b]) -> (b -> c) -> a -> [Located c]
mkDecls TyClDecl GhcRn -> [Located (FamilyDecl GhcRn)]
forall pass. TyClDecl pass -> [LFamilyDecl pass]
tcdATs (XTyClD GhcRn -> TyClDecl GhcRn -> HsDecl GhcRn
forall p. XTyClD p -> TyClDecl p -> HsDecl p
TyClD XTyClD GhcRn
NoExt
noExt (TyClDecl GhcRn -> HsDecl GhcRn)
-> (FamilyDecl GhcRn -> TyClDecl GhcRn)
-> FamilyDecl GhcRn
-> HsDecl GhcRn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XFamDecl GhcRn -> FamilyDecl GhcRn -> TyClDecl GhcRn
forall pass. XFamDecl pass -> FamilyDecl pass -> TyClDecl pass
FamDecl XFamDecl GhcRn
NoExt
noExt) TyClDecl GhcRn
class_
declTypeDocs :: HsDecl GhcRn -> Map Int (HsDocString)
declTypeDocs :: HsDecl GhcRn -> Map Int HsDocString
declTypeDocs = \case
SigD _ (TypeSig _ _ ty :: LHsSigWcType GhcRn
ty) -> HsType GhcRn -> Map Int HsDocString
typeDocs (LBangType GhcRn -> SrcSpanLess (LBangType GhcRn)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (LHsSigWcType GhcRn -> LBangType GhcRn
forall pass. LHsSigWcType pass -> LHsType pass
hsSigWcType LHsSigWcType GhcRn
ty))
SigD _ (ClassOpSig _ _ _ ty :: HsImplicitBndrs GhcRn (LBangType GhcRn)
ty) -> HsType GhcRn -> Map Int HsDocString
typeDocs (LBangType GhcRn -> SrcSpanLess (LBangType GhcRn)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (HsImplicitBndrs GhcRn (LBangType GhcRn) -> LBangType GhcRn
forall pass. LHsSigType pass -> LHsType pass
hsSigType HsImplicitBndrs GhcRn (LBangType GhcRn)
ty))
SigD _ (PatSynSig _ _ ty :: HsImplicitBndrs GhcRn (LBangType GhcRn)
ty) -> HsType GhcRn -> Map Int HsDocString
typeDocs (LBangType GhcRn -> SrcSpanLess (LBangType GhcRn)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (HsImplicitBndrs GhcRn (LBangType GhcRn) -> LBangType GhcRn
forall pass. LHsSigType pass -> LHsType pass
hsSigType HsImplicitBndrs GhcRn (LBangType GhcRn)
ty))
ForD _ (ForeignImport _ _ ty :: HsImplicitBndrs GhcRn (LBangType GhcRn)
ty _) -> HsType GhcRn -> Map Int HsDocString
typeDocs (LBangType GhcRn -> SrcSpanLess (LBangType GhcRn)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (HsImplicitBndrs GhcRn (LBangType GhcRn) -> LBangType GhcRn
forall pass. LHsSigType pass -> LHsType pass
hsSigType HsImplicitBndrs GhcRn (LBangType GhcRn)
ty))
TyClD _ (SynDecl { tcdRhs :: forall pass. TyClDecl pass -> LHsType pass
tcdRhs = LBangType GhcRn
ty }) -> HsType GhcRn -> Map Int HsDocString
typeDocs (LBangType GhcRn -> SrcSpanLess (LBangType GhcRn)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LBangType GhcRn
ty)
_ -> Map Int HsDocString
forall k a. Map k a
M.empty
nubByName :: (a -> Name) -> [a] -> [a]
nubByName :: (a -> Name) -> [a] -> [a]
nubByName f :: a -> Name
f ns :: [a]
ns = NameSet -> [a] -> [a]
go NameSet
emptyNameSet [a]
ns
where
go :: NameSet -> [a] -> [a]
go _ [] = []
go s :: NameSet
s (x :: a
x:xs :: [a]
xs)
| Name
y Name -> NameSet -> Bool
`elemNameSet` NameSet
s = NameSet -> [a] -> [a]
go NameSet
s [a]
xs
| Bool
otherwise = let s' :: NameSet
s' = NameSet -> Name -> NameSet
extendNameSet NameSet
s Name
y
in a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: NameSet -> [a] -> [a]
go NameSet
s' [a]
xs
where
y :: Name
y = a -> Name
f a
x
typeDocs :: HsType GhcRn -> Map Int (HsDocString)
typeDocs :: HsType GhcRn -> Map Int HsDocString
typeDocs = Int -> HsType GhcRn -> Map Int HsDocString
forall k pass.
(Ord k, Num k) =>
k -> HsType pass -> Map k HsDocString
go 0
where
go :: k -> HsType pass -> Map k HsDocString
go n :: k
n (HsForAllTy { hst_body :: forall pass. HsType pass -> LHsType pass
hst_body = LHsType pass
ty }) = k -> HsType pass -> Map k HsDocString
go k
n (LHsType pass -> SrcSpanLess (LHsType pass)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LHsType pass
ty)
go n :: k
n (HsQualTy { hst_body :: forall pass. HsType pass -> LHsType pass
hst_body = LHsType pass
ty }) = k -> HsType pass -> Map k HsDocString
go k
n (LHsType pass -> SrcSpanLess (LHsType pass)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LHsType pass
ty)
go n :: k
n (HsFunTy _ (LHsType pass -> Located (SrcSpanLess (LHsType pass))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _
(HsDocTy _ _ (dL->L _ x))) (LHsType pass -> Located (SrcSpanLess (LHsType pass))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ ty :: SrcSpanLess (LHsType pass)
ty)) =
k -> HsDocString -> Map k HsDocString -> Map k HsDocString
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert k
n SrcSpanLess LHsDocString
HsDocString
x (Map k HsDocString -> Map k HsDocString)
-> Map k HsDocString -> Map k HsDocString
forall a b. (a -> b) -> a -> b
$ k -> HsType pass -> Map k HsDocString
go (k
nk -> k -> k
forall a. Num a => a -> a -> a
+1) SrcSpanLess (LHsType pass)
HsType pass
ty
go n :: k
n (HsFunTy _ _ ty :: LHsType pass
ty) = k -> HsType pass -> Map k HsDocString
go (k
nk -> k -> k
forall a. Num a => a -> a -> a
+1) (LHsType pass -> SrcSpanLess (LHsType pass)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LHsType pass
ty)
go n :: k
n (HsDocTy _ _ (LHsDocString -> Located (SrcSpanLess LHsDocString)
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ doc :: SrcSpanLess LHsDocString
doc)) = k -> HsDocString -> Map k HsDocString
forall k a. k -> a -> Map k a
M.singleton k
n SrcSpanLess LHsDocString
HsDocString
doc
go _ _ = Map k HsDocString
forall k a. Map k a
M.empty
topDecls :: HsGroup GhcRn -> [(LHsDecl GhcRn, [HsDocString])]
topDecls :: HsGroup GhcRn -> [(LHsDecl GhcRn, [HsDocString])]
topDecls = [(LHsDecl GhcRn, [HsDocString])]
-> [(LHsDecl GhcRn, [HsDocString])]
forall a doc. [(LHsDecl a, doc)] -> [(LHsDecl a, doc)]
filterClasses ([(LHsDecl GhcRn, [HsDocString])]
-> [(LHsDecl GhcRn, [HsDocString])])
-> (HsGroup GhcRn -> [(LHsDecl GhcRn, [HsDocString])])
-> HsGroup GhcRn
-> [(LHsDecl GhcRn, [HsDocString])]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(LHsDecl GhcRn, [HsDocString])]
-> [(LHsDecl GhcRn, [HsDocString])]
forall a doc. [(LHsDecl a, doc)] -> [(LHsDecl a, doc)]
filterDecls ([(LHsDecl GhcRn, [HsDocString])]
-> [(LHsDecl GhcRn, [HsDocString])])
-> (HsGroup GhcRn -> [(LHsDecl GhcRn, [HsDocString])])
-> HsGroup GhcRn
-> [(LHsDecl GhcRn, [HsDocString])]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [LHsDecl GhcRn] -> [(LHsDecl GhcRn, [HsDocString])]
forall pass. [LHsDecl pass] -> [(LHsDecl pass, [HsDocString])]
collectDocs ([LHsDecl GhcRn] -> [(LHsDecl GhcRn, [HsDocString])])
-> (HsGroup GhcRn -> [LHsDecl GhcRn])
-> HsGroup GhcRn
-> [(LHsDecl GhcRn, [HsDocString])]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [LHsDecl GhcRn] -> [LHsDecl GhcRn]
forall a. [Located a] -> [Located a]
sortByLoc ([LHsDecl GhcRn] -> [LHsDecl GhcRn])
-> (HsGroup GhcRn -> [LHsDecl GhcRn])
-> HsGroup GhcRn
-> [LHsDecl GhcRn]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsGroup GhcRn -> [LHsDecl GhcRn]
ungroup
ungroup :: HsGroup GhcRn -> [LHsDecl GhcRn]
ungroup :: HsGroup GhcRn -> [LHsDecl GhcRn]
ungroup group_ :: HsGroup GhcRn
group_ =
(HsGroup GhcRn -> [Located (TyClDecl GhcRn)])
-> (TyClDecl GhcRn -> HsDecl GhcRn)
-> HsGroup GhcRn
-> [LHsDecl GhcRn]
forall a b c. (a -> [Located b]) -> (b -> c) -> a -> [Located c]
mkDecls ([TyClGroup GhcRn] -> [Located (TyClDecl GhcRn)]
forall pass. [TyClGroup pass] -> [LTyClDecl pass]
tyClGroupTyClDecls ([TyClGroup GhcRn] -> [Located (TyClDecl GhcRn)])
-> (HsGroup GhcRn -> [TyClGroup GhcRn])
-> HsGroup GhcRn
-> [Located (TyClDecl GhcRn)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsGroup GhcRn -> [TyClGroup GhcRn]
forall p. HsGroup p -> [TyClGroup p]
hs_tyclds) (XTyClD GhcRn -> TyClDecl GhcRn -> HsDecl GhcRn
forall p. XTyClD p -> TyClDecl p -> HsDecl p
TyClD XTyClD GhcRn
NoExt
noExt) HsGroup GhcRn
group_ [LHsDecl GhcRn] -> [LHsDecl GhcRn] -> [LHsDecl GhcRn]
forall a. [a] -> [a] -> [a]
++
(HsGroup GhcRn -> [Located (DerivDecl GhcRn)])
-> (DerivDecl GhcRn -> HsDecl GhcRn)
-> HsGroup GhcRn
-> [LHsDecl GhcRn]
forall a b c. (a -> [Located b]) -> (b -> c) -> a -> [Located c]
mkDecls HsGroup GhcRn -> [Located (DerivDecl GhcRn)]
forall p. HsGroup p -> [LDerivDecl p]
hs_derivds (XDerivD GhcRn -> DerivDecl GhcRn -> HsDecl GhcRn
forall p. XDerivD p -> DerivDecl p -> HsDecl p
DerivD XDerivD GhcRn
NoExt
noExt) HsGroup GhcRn
group_ [LHsDecl GhcRn] -> [LHsDecl GhcRn] -> [LHsDecl GhcRn]
forall a. [a] -> [a] -> [a]
++
(HsGroup GhcRn -> [Located (DefaultDecl GhcRn)])
-> (DefaultDecl GhcRn -> HsDecl GhcRn)
-> HsGroup GhcRn
-> [LHsDecl GhcRn]
forall a b c. (a -> [Located b]) -> (b -> c) -> a -> [Located c]
mkDecls HsGroup GhcRn -> [Located (DefaultDecl GhcRn)]
forall p. HsGroup p -> [LDefaultDecl p]
hs_defds (XDefD GhcRn -> DefaultDecl GhcRn -> HsDecl GhcRn
forall p. XDefD p -> DefaultDecl p -> HsDecl p
DefD XDefD GhcRn
NoExt
noExt) HsGroup GhcRn
group_ [LHsDecl GhcRn] -> [LHsDecl GhcRn] -> [LHsDecl GhcRn]
forall a. [a] -> [a] -> [a]
++
(HsGroup GhcRn -> [Located (ForeignDecl GhcRn)])
-> (ForeignDecl GhcRn -> HsDecl GhcRn)
-> HsGroup GhcRn
-> [LHsDecl GhcRn]
forall a b c. (a -> [Located b]) -> (b -> c) -> a -> [Located c]
mkDecls HsGroup GhcRn -> [Located (ForeignDecl GhcRn)]
forall p. HsGroup p -> [LForeignDecl p]
hs_fords (XForD GhcRn -> ForeignDecl GhcRn -> HsDecl GhcRn
forall p. XForD p -> ForeignDecl p -> HsDecl p
ForD XForD GhcRn
NoExt
noExt) HsGroup GhcRn
group_ [LHsDecl GhcRn] -> [LHsDecl GhcRn] -> [LHsDecl GhcRn]
forall a. [a] -> [a] -> [a]
++
(HsGroup GhcRn -> [Located DocDecl])
-> (DocDecl -> HsDecl GhcRn) -> HsGroup GhcRn -> [LHsDecl GhcRn]
forall a b c. (a -> [Located b]) -> (b -> c) -> a -> [Located c]
mkDecls HsGroup GhcRn -> [Located DocDecl]
forall p. HsGroup p -> [Located DocDecl]
hs_docs (XDocD GhcRn -> DocDecl -> HsDecl GhcRn
forall p. XDocD p -> DocDecl -> HsDecl p
DocD XDocD GhcRn
NoExt
noExt) HsGroup GhcRn
group_ [LHsDecl GhcRn] -> [LHsDecl GhcRn] -> [LHsDecl GhcRn]
forall a. [a] -> [a] -> [a]
++
(HsGroup GhcRn -> [Located (InstDecl GhcRn)])
-> (InstDecl GhcRn -> HsDecl GhcRn)
-> HsGroup GhcRn
-> [LHsDecl GhcRn]
forall a b c. (a -> [Located b]) -> (b -> c) -> a -> [Located c]
mkDecls ([TyClGroup GhcRn] -> [Located (InstDecl GhcRn)]
forall pass. [TyClGroup pass] -> [LInstDecl pass]
tyClGroupInstDecls ([TyClGroup GhcRn] -> [Located (InstDecl GhcRn)])
-> (HsGroup GhcRn -> [TyClGroup GhcRn])
-> HsGroup GhcRn
-> [Located (InstDecl GhcRn)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsGroup GhcRn -> [TyClGroup GhcRn]
forall p. HsGroup p -> [TyClGroup p]
hs_tyclds) (XInstD GhcRn -> InstDecl GhcRn -> HsDecl GhcRn
forall p. XInstD p -> InstDecl p -> HsDecl p
InstD XInstD GhcRn
NoExt
noExt) HsGroup GhcRn
group_ [LHsDecl GhcRn] -> [LHsDecl GhcRn] -> [LHsDecl GhcRn]
forall a. [a] -> [a] -> [a]
++
(HsGroup GhcRn -> [Located (Sig GhcRn)])
-> (Sig GhcRn -> HsDecl GhcRn) -> HsGroup GhcRn -> [LHsDecl GhcRn]
forall a b c. (a -> [Located b]) -> (b -> c) -> a -> [Located c]
mkDecls (HsValBindsLR GhcRn GhcRn -> [Located (Sig GhcRn)]
forall idL idR idL.
(XXValBindsLR idL idR ~ NHsValBindsLR idL) =>
HsValBindsLR idL idR -> [Located (Sig GhcRn)]
typesigs (HsValBindsLR GhcRn GhcRn -> [Located (Sig GhcRn)])
-> (HsGroup GhcRn -> HsValBindsLR GhcRn GhcRn)
-> HsGroup GhcRn
-> [Located (Sig GhcRn)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsGroup GhcRn -> HsValBindsLR GhcRn GhcRn
forall p. HsGroup p -> HsValBinds p
hs_valds) (XSigD GhcRn -> Sig GhcRn -> HsDecl GhcRn
forall p. XSigD p -> Sig p -> HsDecl p
SigD XSigD GhcRn
NoExt
noExt) HsGroup GhcRn
group_ [LHsDecl GhcRn] -> [LHsDecl GhcRn] -> [LHsDecl GhcRn]
forall a. [a] -> [a] -> [a]
++
(HsGroup GhcRn -> [Located (HsBindLR GhcRn GhcRn)])
-> (HsBindLR GhcRn GhcRn -> HsDecl GhcRn)
-> HsGroup GhcRn
-> [LHsDecl GhcRn]
forall a b c. (a -> [Located b]) -> (b -> c) -> a -> [Located c]
mkDecls (HsValBindsLR GhcRn GhcRn -> [Located (HsBindLR GhcRn GhcRn)]
forall idL idR idL.
(XXValBindsLR idL idR ~ NHsValBindsLR idL) =>
HsValBindsLR idL idR -> [LHsBindLR idL idL]
valbinds (HsValBindsLR GhcRn GhcRn -> [Located (HsBindLR GhcRn GhcRn)])
-> (HsGroup GhcRn -> HsValBindsLR GhcRn GhcRn)
-> HsGroup GhcRn
-> [Located (HsBindLR GhcRn GhcRn)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsGroup GhcRn -> HsValBindsLR GhcRn GhcRn
forall p. HsGroup p -> HsValBinds p
hs_valds) (XValD GhcRn -> HsBindLR GhcRn GhcRn -> HsDecl GhcRn
forall p. XValD p -> HsBind p -> HsDecl p
ValD XValD GhcRn
NoExt
noExt) HsGroup GhcRn
group_
where
typesigs :: HsValBindsLR idL idR -> [Located (Sig GhcRn)]
typesigs (XValBindsLR (NValBinds _ sigs)) = (Located (Sig GhcRn) -> Bool)
-> [Located (Sig GhcRn)] -> [Located (Sig GhcRn)]
forall a. (a -> Bool) -> [a] -> [a]
filter (Sig GhcRn -> Bool
forall name. Sig name -> Bool
isUserSig (Sig GhcRn -> Bool)
-> (Located (Sig GhcRn) -> Sig GhcRn)
-> Located (Sig GhcRn)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Located (Sig GhcRn) -> Sig GhcRn
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc) [Located (Sig GhcRn)]
sigs
typesigs _ = [Char] -> [Located (Sig GhcRn)]
forall a. HasCallStack => [Char] -> a
error "expected ValBindsOut"
valbinds :: HsValBindsLR idL idR -> [LHsBindLR idL idL]
valbinds (XValBindsLR (NValBinds binds _)) =
(Bag (LHsBindLR idL idL) -> [LHsBindLR idL idL])
-> [Bag (LHsBindLR idL idL)] -> [LHsBindLR idL idL]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Bag (LHsBindLR idL idL) -> [LHsBindLR idL idL]
forall a. Bag a -> [a]
bagToList ([Bag (LHsBindLR idL idL)] -> [LHsBindLR idL idL])
-> ([(RecFlag, Bag (LHsBindLR idL idL))]
-> [Bag (LHsBindLR idL idL)])
-> [(RecFlag, Bag (LHsBindLR idL idL))]
-> [LHsBindLR idL idL]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([RecFlag], [Bag (LHsBindLR idL idL)]) -> [Bag (LHsBindLR idL idL)]
forall a b. (a, b) -> b
snd (([RecFlag], [Bag (LHsBindLR idL idL)])
-> [Bag (LHsBindLR idL idL)])
-> ([(RecFlag, Bag (LHsBindLR idL idL))]
-> ([RecFlag], [Bag (LHsBindLR idL idL)]))
-> [(RecFlag, Bag (LHsBindLR idL idL))]
-> [Bag (LHsBindLR idL idL)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(RecFlag, Bag (LHsBindLR idL idL))]
-> ([RecFlag], [Bag (LHsBindLR idL idL)])
forall a b. [(a, b)] -> ([a], [b])
unzip ([(RecFlag, Bag (LHsBindLR idL idL))] -> [LHsBindLR idL idL])
-> [(RecFlag, Bag (LHsBindLR idL idL))] -> [LHsBindLR idL idL]
forall a b. (a -> b) -> a -> b
$ [(RecFlag, Bag (LHsBindLR idL idL))]
binds
valbinds _ = [Char] -> [LHsBindLR idL idL]
forall a. HasCallStack => [Char] -> a
error "expected ValBindsOut"
sortByLoc :: [Located a] -> [Located a]
sortByLoc :: [Located a] -> [Located a]
sortByLoc = (Located a -> SrcSpan) -> [Located a] -> [Located a]
forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn Located a -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc
collectDocs :: [LHsDecl pass] -> [(LHsDecl pass, [HsDocString])]
collectDocs :: [LHsDecl pass] -> [(LHsDecl pass, [HsDocString])]
collectDocs = Maybe (LHsDecl pass)
-> [HsDocString]
-> [LHsDecl pass]
-> [(LHsDecl pass, [HsDocString])]
forall a p.
(HasSrcSpan a, SrcSpanLess a ~ HsDecl p) =>
Maybe a -> [HsDocString] -> [a] -> [(a, [HsDocString])]
go Maybe (LHsDecl pass)
forall a. Maybe a
Nothing []
where
go :: Maybe a -> [HsDocString] -> [a] -> [(a, [HsDocString])]
go Nothing _ [] = []
go (Just prev :: a
prev) docs :: [HsDocString]
docs [] = a -> [HsDocString] -> [(a, [HsDocString])] -> [(a, [HsDocString])]
forall a a. a -> [a] -> [(a, [a])] -> [(a, [a])]
finished a
prev [HsDocString]
docs []
go prev :: Maybe a
prev docs :: [HsDocString]
docs ((a -> Located (SrcSpanLess a)
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (DocD _ (DocCommentNext str))) : ds :: [a]
ds)
| Maybe a
Nothing <- Maybe a
prev = Maybe a -> [HsDocString] -> [a] -> [(a, [HsDocString])]
go Maybe a
forall a. Maybe a
Nothing (HsDocString
strHsDocString -> [HsDocString] -> [HsDocString]
forall a. a -> [a] -> [a]
:[HsDocString]
docs) [a]
ds
| Just decl :: a
decl <- Maybe a
prev = a -> [HsDocString] -> [(a, [HsDocString])] -> [(a, [HsDocString])]
forall a a. a -> [a] -> [(a, [a])] -> [(a, [a])]
finished a
decl [HsDocString]
docs (Maybe a -> [HsDocString] -> [a] -> [(a, [HsDocString])]
go Maybe a
forall a. Maybe a
Nothing [HsDocString
str] [a]
ds)
go prev :: Maybe a
prev docs :: [HsDocString]
docs ((a -> Located (SrcSpanLess a)
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (DocD _ (DocCommentPrev str))) : ds :: [a]
ds) =
Maybe a -> [HsDocString] -> [a] -> [(a, [HsDocString])]
go Maybe a
prev (HsDocString
strHsDocString -> [HsDocString] -> [HsDocString]
forall a. a -> [a] -> [a]
:[HsDocString]
docs) [a]
ds
go Nothing docs :: [HsDocString]
docs (d :: a
d:ds :: [a]
ds) = Maybe a -> [HsDocString] -> [a] -> [(a, [HsDocString])]
go (a -> Maybe a
forall a. a -> Maybe a
Just a
d) [HsDocString]
docs [a]
ds
go (Just prev :: a
prev) docs :: [HsDocString]
docs (d :: a
d:ds :: [a]
ds) = a -> [HsDocString] -> [(a, [HsDocString])] -> [(a, [HsDocString])]
forall a a. a -> [a] -> [(a, [a])] -> [(a, [a])]
finished a
prev [HsDocString]
docs (Maybe a -> [HsDocString] -> [a] -> [(a, [HsDocString])]
go (a -> Maybe a
forall a. a -> Maybe a
Just a
d) [] [a]
ds)
finished :: a -> [a] -> [(a, [a])] -> [(a, [a])]
finished decl :: a
decl docs :: [a]
docs rest :: [(a, [a])]
rest = (a
decl, [a] -> [a]
forall a. [a] -> [a]
reverse [a]
docs) (a, [a]) -> [(a, [a])] -> [(a, [a])]
forall a. a -> [a] -> [a]
: [(a, [a])]
rest
filterDecls :: [(LHsDecl a, doc)] -> [(LHsDecl a, doc)]
filterDecls :: [(LHsDecl a, doc)] -> [(LHsDecl a, doc)]
filterDecls = ((LHsDecl a, doc) -> Bool)
-> [(LHsDecl a, doc)] -> [(LHsDecl a, doc)]
forall a. (a -> Bool) -> [a] -> [a]
filter (HsDecl a -> Bool
forall a. HsDecl a -> Bool
isHandled (HsDecl a -> Bool)
-> ((LHsDecl a, doc) -> HsDecl a) -> (LHsDecl a, doc) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LHsDecl a -> HsDecl a
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (LHsDecl a -> HsDecl a)
-> ((LHsDecl a, doc) -> LHsDecl a) -> (LHsDecl a, doc) -> HsDecl a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LHsDecl a, doc) -> LHsDecl a
forall a b. (a, b) -> a
fst)
where
isHandled :: HsDecl name -> Bool
isHandled (ForD _ (ForeignImport {})) = Bool
True
isHandled (TyClD {}) = Bool
True
isHandled (InstD {}) = Bool
True
isHandled (DerivD {}) = Bool
True
isHandled (SigD _ d :: Sig name
d) = Sig name -> Bool
forall name. Sig name -> Bool
isUserSig Sig name
d
isHandled (ValD {}) = Bool
True
isHandled (DocD {}) = Bool
True
isHandled _ = Bool
False
filterClasses :: [(LHsDecl a, doc)] -> [(LHsDecl a, doc)]
filterClasses :: [(LHsDecl a, doc)] -> [(LHsDecl a, doc)]
filterClasses decls :: [(LHsDecl a, doc)]
decls = [ if HsDecl a -> Bool
forall a. HsDecl a -> Bool
isClassD SrcSpanLess (LHsDecl a)
HsDecl a
d then (SrcSpan -> SrcSpanLess (LHsDecl a) -> LHsDecl a
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (HsDecl a -> HsDecl a
forall name. HsDecl name -> HsDecl name
filterClass SrcSpanLess (LHsDecl a)
HsDecl a
d), doc
doc) else (LHsDecl a, doc)
x
| x :: (LHsDecl a, doc)
x@(LHsDecl a -> Located (SrcSpanLess (LHsDecl a))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc d :: SrcSpanLess (LHsDecl a)
d, doc :: doc
doc) <- [(LHsDecl a, doc)]
decls ]
where
filterClass :: HsDecl name -> HsDecl name
filterClass (TyClD x :: XTyClD name
x c :: TyClDecl name
c) =
XTyClD name -> TyClDecl name -> HsDecl name
forall p. XTyClD p -> TyClDecl p -> HsDecl p
TyClD XTyClD name
x (TyClDecl name -> HsDecl name) -> TyClDecl name -> HsDecl name
forall a b. (a -> b) -> a -> b
$ TyClDecl name
c { tcdSigs :: [LSig name]
tcdSigs =
(LSig name -> Bool) -> [LSig name] -> [LSig name]
forall a. (a -> Bool) -> [a] -> [a]
filter ((Bool -> Bool -> Bool)
-> (LSig name -> Bool) -> (LSig name -> Bool) -> LSig name -> Bool
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Bool -> Bool -> Bool
(||) (Sig name -> Bool
forall name. Sig name -> Bool
isUserSig (Sig name -> Bool) -> (LSig name -> Sig name) -> LSig name -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LSig name -> Sig name
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc) LSig name -> Bool
forall name. LSig name -> Bool
isMinimalLSig) (TyClDecl name -> [LSig name]
forall pass. TyClDecl pass -> [LSig pass]
tcdSigs TyClDecl name
c) }
filterClass _ = [Char] -> HsDecl name
forall a. HasCallStack => [Char] -> a
error "expected TyClD"
isUserSig :: Sig name -> Bool
isUserSig :: Sig name -> Bool
isUserSig TypeSig {} = Bool
True
isUserSig ClassOpSig {} = Bool
True
isUserSig PatSynSig {} = Bool
True
isUserSig _ = Bool
False
isClassD :: HsDecl a -> Bool
isClassD :: HsDecl a -> Bool
isClassD (TyClD _ d :: TyClDecl a
d) = TyClDecl a -> Bool
forall pass. TyClDecl pass -> Bool
isClassDecl TyClDecl a
d
isClassD _ = Bool
False
mkDecls :: (a -> [Located b]) -> (b -> c) -> a -> [Located c]
mkDecls :: (a -> [Located b]) -> (b -> c) -> a -> [Located c]
mkDecls field :: a -> [Located b]
field con :: b -> c
con struct :: a
struct = [ SrcSpan -> SrcSpanLess (Located c) -> Located c
forall a. HasSrcSpan a => SrcSpan -> SrcSpanLess a -> a
cL SrcSpan
loc (b -> c
con b
SrcSpanLess (Located b)
decl)
| (Located b -> Located (SrcSpanLess (Located b))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L loc :: SrcSpan
loc decl :: SrcSpanLess (Located b)
decl) <- a -> [Located b]
field a
struct ]