summaryrefslogtreecommitdiff
path: root/compiler/GHC/Rename/Doc.hs
blob: b278e02cf3752c72342c76cfb13b51e62100a757 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
module GHC.Rename.Doc ( rnHsDoc, rnLHsDoc, rnLDocDecl, rnDocDecl ) where

import GHC.Prelude

import GHC.Tc.Types
import GHC.Hs
import GHC.Types.Name.Reader
import GHC.Types.Name
import GHC.Types.SrcLoc
import GHC.Tc.Utils.Monad (getGblEnv)
import GHC.Types.Avail
import GHC.Rename.Env

rnLHsDoc :: LHsDoc GhcPs -> RnM (LHsDoc GhcRn)
rnLHsDoc = traverse rnHsDoc

rnLDocDecl :: LDocDecl GhcPs -> RnM (LDocDecl GhcRn)
rnLDocDecl = traverse rnDocDecl

rnDocDecl :: DocDecl GhcPs -> RnM (DocDecl GhcRn)
rnDocDecl (DocCommentNext doc) = do
  doc' <- rnLHsDoc doc
  pure $ (DocCommentNext doc')
rnDocDecl (DocCommentPrev doc) = do
  doc' <- rnLHsDoc doc
  pure $ (DocCommentPrev doc')
rnDocDecl (DocCommentNamed n doc) = do
  doc' <- rnLHsDoc doc
  pure $ (DocCommentNamed n doc')
rnDocDecl (DocGroup i doc) = do
  doc' <- rnLHsDoc doc
  pure $ (DocGroup i doc')

rnHsDoc :: WithHsDocIdentifiers a GhcPs -> RnM (WithHsDocIdentifiers a GhcRn)
rnHsDoc (WithHsDocIdentifiers s ids) = do
  gre <- tcg_rdr_env <$> getGblEnv
  pure (WithHsDocIdentifiers s (rnHsDocIdentifiers gre ids))

rnHsDocIdentifiers :: GlobalRdrEnv
                  -> [Located RdrName]
                  -> [Located Name]
rnHsDocIdentifiers gre ns = concat
  [ map (L l . greNamePrintableName . gre_name) (lookupGRE_RdrName c gre)
  | L l rdr_name <- ns
  , c <- dataTcOccs rdr_name
  ]