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 :: LHsDoc GhcPs -> RnM (LHsDoc GhcRn)
rnLHsDoc = forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall a.
WithHsDocIdentifiers a GhcPs -> RnM (WithHsDocIdentifiers a GhcRn)
rnHsDoc

rnLDocDecl :: LDocDecl GhcPs -> RnM (LDocDecl GhcRn)
rnLDocDecl :: LDocDecl GhcPs -> RnM (LDocDecl GhcRn)
rnLDocDecl = forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse DocDecl GhcPs -> RnM (DocDecl GhcRn)
rnDocDecl

rnDocDecl :: DocDecl GhcPs -> RnM (DocDecl GhcRn)
rnDocDecl :: DocDecl GhcPs -> RnM (DocDecl GhcRn)
rnDocDecl (DocCommentNext LHsDoc GhcPs
doc) = do
  LHsDoc GhcRn
doc' <- LHsDoc GhcPs -> RnM (LHsDoc GhcRn)
rnLHsDoc LHsDoc GhcPs
doc
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ (forall pass. LHsDoc pass -> DocDecl pass
DocCommentNext LHsDoc GhcRn
doc')
rnDocDecl (DocCommentPrev LHsDoc GhcPs
doc) = do
  LHsDoc GhcRn
doc' <- LHsDoc GhcPs -> RnM (LHsDoc GhcRn)
rnLHsDoc LHsDoc GhcPs
doc
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ (forall pass. LHsDoc pass -> DocDecl pass
DocCommentPrev LHsDoc GhcRn
doc')
rnDocDecl (DocCommentNamed String
n LHsDoc GhcPs
doc) = do
  LHsDoc GhcRn
doc' <- LHsDoc GhcPs -> RnM (LHsDoc GhcRn)
rnLHsDoc LHsDoc GhcPs
doc
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ (forall pass. String -> LHsDoc pass -> DocDecl pass
DocCommentNamed String
n LHsDoc GhcRn
doc')
rnDocDecl (DocGroup Int
i LHsDoc GhcPs
doc) = do
  LHsDoc GhcRn
doc' <- LHsDoc GhcPs -> RnM (LHsDoc GhcRn)
rnLHsDoc LHsDoc GhcPs
doc
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ (forall pass. Int -> LHsDoc pass -> DocDecl pass
DocGroup Int
i LHsDoc GhcRn
doc')

rnHsDoc :: WithHsDocIdentifiers a GhcPs -> RnM (WithHsDocIdentifiers a GhcRn)
rnHsDoc :: forall a.
WithHsDocIdentifiers a GhcPs -> RnM (WithHsDocIdentifiers a GhcRn)
rnHsDoc (WithHsDocIdentifiers a
s [Located (IdP GhcPs)]
ids) = do
  GlobalRdrEnv
gre <- TcGblEnv -> GlobalRdrEnv
tcg_rdr_env forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall gbl lcl. TcRnIf gbl lcl gbl
getGblEnv
  forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall a pass.
a -> [Located (IdP pass)] -> WithHsDocIdentifiers a pass
WithHsDocIdentifiers a
s (GlobalRdrEnv -> [Located RdrName] -> [Located Name]
rnHsDocIdentifiers GlobalRdrEnv
gre [Located (IdP GhcPs)]
ids))

rnHsDocIdentifiers :: GlobalRdrEnv
                  -> [Located RdrName]
                  -> [Located Name]
rnHsDocIdentifiers :: GlobalRdrEnv -> [Located RdrName] -> [Located Name]
rnHsDocIdentifiers GlobalRdrEnv
gre [Located RdrName]
ns = forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
  [ forall a b. (a -> b) -> [a] -> [b]
map (forall l e. l -> e -> GenLocated l e
L SrcSpan
l forall b c a. (b -> c) -> (a -> b) -> a -> c
. GreName -> Name
greNamePrintableName forall b c a. (b -> c) -> (a -> b) -> a -> c
. GlobalRdrElt -> GreName
gre_name) (RdrName -> GlobalRdrEnv -> [GlobalRdrElt]
lookupGRE_RdrName RdrName
c GlobalRdrEnv
gre)
  | L SrcSpan
l RdrName
rdr_name <- [Located RdrName]
ns
  , RdrName
c <- RdrName -> [RdrName]
dataTcOccs RdrName
rdr_name
  ]