diff options
author | David Waern <david.waern@gmail.com> | 2008-10-15 22:15:01 +0000 |
---|---|---|
committer | David Waern <david.waern@gmail.com> | 2008-10-15 22:15:01 +0000 |
commit | 6e68962ae8a03bfa60ae2c1db6051cab2f30613b (patch) | |
tree | 4133ff4b348bc1fd124d4816077290ff3c761fd8 /src | |
parent | 08e2aa223e55207c46df655976e46ed7aac60805 (diff) |
Add subordinates with docs to the declaration map
The only place in the code where we want the subordinates for a declaration is
right after having looked up the declaration in the map.
And since we include subordinates in the map, we might as well take the
opportunity to store those subordinates that belong to a particular declaration
together with that declaration.
We also store the documentation for each subordinate.
Diffstat (limited to 'src')
-rw-r--r-- | src/Haddock/Interface/Create.hs | 22 | ||||
-rw-r--r-- | src/Haddock/Interface/Rename.hs | 2 | ||||
-rw-r--r-- | src/Haddock/Types.hs | 2 |
3 files changed, 14 insertions, 12 deletions
diff --git a/src/Haddock/Interface/Create.hs b/src/Haddock/Interface/Create.hs index 9252b9eb..5932bc64 100644 --- a/src/Haddock/Interface/Create.hs +++ b/src/Haddock/Interface/Create.hs @@ -142,10 +142,13 @@ type DeclWithDoc = (Decl, Maybe Doc) -- documentation declarations. -- Subordinate names are mapped to the parent declaration, but with the doc -- for the subordinate declaration. -mkDeclMap :: [DeclWithDoc] -> Map Name DeclWithDoc -mkDeclMap decls = Map.fromList [ (n, (L loc d, doc)) | (L loc d, doc) <- decls - , (n, doc) <- (declName d, doc) : subordinates d - , not (isDocD d), not (isInstD d) ] +mkDeclMap :: [(Decl, Maybe Doc)] -> Map Name DeclInfo +mkDeclMap decls = Map.fromList . concat $ + [ (declName d, (parent, doc, subs)) : subDecls + | (parent@(L loc d), doc) <- decls + , let subs = subordinates d + , let subDecls = [ (n, (parent, doc', [])) | (n, doc') <- subs ] + , not (isDocD d), not (isInstD d) ] -- | Group type family instances together. Include the family declaration @@ -161,7 +164,6 @@ mkFamMap decls = -} - subordinates (TyClD d) = classDataSubs d subordinates _ = [] @@ -364,7 +366,7 @@ mkExportItems -> Module -- this module -> [Name] -- exported names (orig) -> [(Decl, Maybe Doc)] - -> Map Name DeclWithDoc -- maps local names to declarations + -> Map Name DeclInfo -- maps local names to declarations -> Map Name [Name] -- sub-map for this module -> [DocOption] -> Maybe [IE Name] @@ -409,7 +411,7 @@ mkExportItems modMap this_mod exported_names decls declMap sub_map -- temp hack: we filter out separately declared ATs, since we haven't decided how -- to handle them yet. We should really give an warning message also, and filter the -- name out in mkVisibleNames... - | Just (decl, maybeDoc) <- findDecl t, t `notElem` declATs (unL decl) = + | Just (decl, maybeDoc, _) <- findDecl t, t `notElem` declATs (unL decl) = return [ ExportDecl (restrictTo subs (extractDecl t mdl decl)) maybeDoc [] ] | otherwise = return [] where @@ -429,9 +431,9 @@ mkExportItems modMap this_mod exported_names decls declMap sub_map | otherwise -> return [ ExportModule m ] Nothing -> return [] -- already emitted a warning in visibleNames - findDecl :: Name -> Maybe (Decl, Maybe Doc) + findDecl :: Name -> Maybe DeclInfo findDecl n - | m == this_mod = Map.lookup n declMap + | m == this_mod = Map.lookup n declMap | otherwise = case Map.lookup m modMap of Just iface -> Map.lookup n (ifaceDeclMap iface) Nothing -> Nothing @@ -523,7 +525,7 @@ mkVisibleNames :: Module -> Map Name [Name] -> Maybe [IE Name] -> [DocOption] - -> Map Name (Decl, Maybe Doc) + -> Map Name DeclInfo -> ErrMsgM [Name] mkVisibleNames mdl modMap localNames scope subMap maybeExps opts declMap diff --git a/src/Haddock/Interface/Rename.hs b/src/Haddock/Interface/Rename.hs index 39aeb48a..3efc2526 100644 --- a/src/Haddock/Interface/Rename.hs +++ b/src/Haddock/Interface/Rename.hs @@ -38,7 +38,7 @@ renameInterface renamingEnv warnings mod = let localEnv = foldl fn renamingEnv (ifaceVisibleExports mod) where fn env name = Map.insert name (ifaceMod mod) env - docMap = Map.map snd $ ifaceDeclMap mod + docMap = Map.map (\(_,x,_) -> x) (ifaceDeclMap mod) docs = [ (n, doc) | (n, Just doc) <- Map.toList docMap ] renameMapElem (k,d) = do d' <- renameDoc d; return (k, d') diff --git a/src/Haddock/Types.hs b/src/Haddock/Types.hs index c3f3e8ce..671637c5 100644 --- a/src/Haddock/Types.hs +++ b/src/Haddock/Types.hs @@ -131,7 +131,7 @@ data Interface = Interface { -- | The Haddock options for this module (prune, ignore-exports, etc) ifaceOptions :: ![DocOption], - ifaceDeclMap :: Map Name (LHsDecl Name, Maybe (HsDoc Name)), + ifaceDeclMap :: Map Name DeclInfo, ifaceRnDocMap :: Map Name (HsDoc DocName), ifaceExportItems :: ![ExportItem Name], |