{-# LANGUAGE DataKinds            #-}
{-# LANGUAGE DeriveDataTypeable   #-}
{-# LANGUAGE FlexibleContexts     #-}
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeApplications     #-}
{-# LANGUAGE TypeFamilies         #-}
{-# LANGUAGE UndecidableInstances #-} -- Wrinkle in Note [Trees That Grow]
                                      -- in module Language.Haskell.Syntax.Extension
{-
(c) The University of Glasgow 2006
(c) The GRASP/AQUA Project, Glasgow University, 1992-1998


GHC.Hs.ImpExp: Abstract syntax: imports, exports, interfaces
-}

module GHC.Hs.ImpExp where

import GHC.Prelude

import GHC.Unit.Module        ( ModuleName, IsBootInterface(..) )
import GHC.Hs.Doc             ( HsDocString )
import GHC.Types.SourceText   ( SourceText(..), StringLiteral(..), pprWithSourceText )
import GHC.Types.FieldLabel   ( FieldLabel )

import GHC.Utils.Outputable
import GHC.Utils.Panic
import GHC.Data.FastString
import GHC.Types.SrcLoc
import Language.Haskell.Syntax.Extension
import GHC.Hs.Extension
import GHC.Parser.Annotation
import GHC.Types.Name

import Data.Data
import Data.Maybe

{-
************************************************************************
*                                                                      *
\subsection{Import and export declaration lists}
*                                                                      *
************************************************************************

One per \tr{import} declaration in a module.
-}

-- | Located Import Declaration
type LImportDecl pass = XRec pass (ImportDecl pass)
        -- ^ When in a list this may have
        --
        --  - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnSemi'

        -- For details on above see note [exact print annotations] in GHC.Parser.Annotation
type instance Anno (ImportDecl (GhcPass p)) = SrcSpanAnnA

-- | If/how an import is 'qualified'.
data ImportDeclQualifiedStyle
  = QualifiedPre  -- ^ 'qualified' appears in prepositive position.
  | QualifiedPost -- ^ 'qualified' appears in postpositive position.
  | NotQualified  -- ^ Not qualified.
  deriving (ImportDeclQualifiedStyle -> ImportDeclQualifiedStyle -> Bool
(ImportDeclQualifiedStyle -> ImportDeclQualifiedStyle -> Bool)
-> (ImportDeclQualifiedStyle -> ImportDeclQualifiedStyle -> Bool)
-> Eq ImportDeclQualifiedStyle
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ImportDeclQualifiedStyle -> ImportDeclQualifiedStyle -> Bool
$c/= :: ImportDeclQualifiedStyle -> ImportDeclQualifiedStyle -> Bool
== :: ImportDeclQualifiedStyle -> ImportDeclQualifiedStyle -> Bool
$c== :: ImportDeclQualifiedStyle -> ImportDeclQualifiedStyle -> Bool
Eq, Typeable ImportDeclQualifiedStyle
Typeable ImportDeclQualifiedStyle
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g)
    -> ImportDeclQualifiedStyle
    -> c ImportDeclQualifiedStyle)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ImportDeclQualifiedStyle)
-> (ImportDeclQualifiedStyle -> Constr)
-> (ImportDeclQualifiedStyle -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d))
    -> Maybe (c ImportDeclQualifiedStyle))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c ImportDeclQualifiedStyle))
-> ((forall b. Data b => b -> b)
    -> ImportDeclQualifiedStyle -> ImportDeclQualifiedStyle)
-> (forall r r'.
    (r -> r' -> r)
    -> r
    -> (forall d. Data d => d -> r')
    -> ImportDeclQualifiedStyle
    -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r
    -> (forall d. Data d => d -> r')
    -> ImportDeclQualifiedStyle
    -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> ImportDeclQualifiedStyle -> [u])
-> (forall u.
    Int
    -> (forall d. Data d => d -> u) -> ImportDeclQualifiedStyle -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> ImportDeclQualifiedStyle -> m ImportDeclQualifiedStyle)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> ImportDeclQualifiedStyle -> m ImportDeclQualifiedStyle)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> ImportDeclQualifiedStyle -> m ImportDeclQualifiedStyle)
-> Data ImportDeclQualifiedStyle
ImportDeclQualifiedStyle -> DataType
ImportDeclQualifiedStyle -> Constr
(forall b. Data b => b -> b)
-> ImportDeclQualifiedStyle -> ImportDeclQualifiedStyle
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int
-> (forall d. Data d => d -> u) -> ImportDeclQualifiedStyle -> u
forall u.
(forall d. Data d => d -> u) -> ImportDeclQualifiedStyle -> [u]
forall r r'.
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> ImportDeclQualifiedStyle
-> r
forall r r'.
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> ImportDeclQualifiedStyle
-> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> ImportDeclQualifiedStyle -> m ImportDeclQualifiedStyle
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ImportDeclQualifiedStyle -> m ImportDeclQualifiedStyle
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ImportDeclQualifiedStyle
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> ImportDeclQualifiedStyle
-> c ImportDeclQualifiedStyle
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ImportDeclQualifiedStyle)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ImportDeclQualifiedStyle)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ImportDeclQualifiedStyle -> m ImportDeclQualifiedStyle
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ImportDeclQualifiedStyle -> m ImportDeclQualifiedStyle
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ImportDeclQualifiedStyle -> m ImportDeclQualifiedStyle
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ImportDeclQualifiedStyle -> m ImportDeclQualifiedStyle
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> ImportDeclQualifiedStyle -> m ImportDeclQualifiedStyle
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> ImportDeclQualifiedStyle -> m ImportDeclQualifiedStyle
gmapQi :: forall u.
Int
-> (forall d. Data d => d -> u) -> ImportDeclQualifiedStyle -> u
$cgmapQi :: forall u.
Int
-> (forall d. Data d => d -> u) -> ImportDeclQualifiedStyle -> u
gmapQ :: forall u.
(forall d. Data d => d -> u) -> ImportDeclQualifiedStyle -> [u]
$cgmapQ :: forall u.
(forall d. Data d => d -> u) -> ImportDeclQualifiedStyle -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> ImportDeclQualifiedStyle
-> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> ImportDeclQualifiedStyle
-> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> ImportDeclQualifiedStyle
-> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> ImportDeclQualifiedStyle
-> r
gmapT :: (forall b. Data b => b -> b)
-> ImportDeclQualifiedStyle -> ImportDeclQualifiedStyle
$cgmapT :: (forall b. Data b => b -> b)
-> ImportDeclQualifiedStyle -> ImportDeclQualifiedStyle
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ImportDeclQualifiedStyle)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ImportDeclQualifiedStyle)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ImportDeclQualifiedStyle)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ImportDeclQualifiedStyle)
dataTypeOf :: ImportDeclQualifiedStyle -> DataType
$cdataTypeOf :: ImportDeclQualifiedStyle -> DataType
toConstr :: ImportDeclQualifiedStyle -> Constr
$ctoConstr :: ImportDeclQualifiedStyle -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ImportDeclQualifiedStyle
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ImportDeclQualifiedStyle
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> ImportDeclQualifiedStyle
-> c ImportDeclQualifiedStyle
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> ImportDeclQualifiedStyle
-> c ImportDeclQualifiedStyle
Data)

-- | Given two possible located 'qualified' tokens, compute a style
-- (in a conforming Haskell program only one of the two can be not
-- 'Nothing'). This is called from "GHC.Parser".
importDeclQualifiedStyle :: Maybe EpaLocation
                         -> Maybe EpaLocation
                         -> (Maybe EpaLocation, ImportDeclQualifiedStyle)
importDeclQualifiedStyle :: Maybe EpaLocation
-> Maybe EpaLocation
-> (Maybe EpaLocation, ImportDeclQualifiedStyle)
importDeclQualifiedStyle Maybe EpaLocation
mPre Maybe EpaLocation
mPost =
  if Maybe EpaLocation -> Bool
forall a. Maybe a -> Bool
isJust Maybe EpaLocation
mPre then (Maybe EpaLocation
mPre, ImportDeclQualifiedStyle
QualifiedPre)
  else if Maybe EpaLocation -> Bool
forall a. Maybe a -> Bool
isJust Maybe EpaLocation
mPost then (Maybe EpaLocation
mPost,ImportDeclQualifiedStyle
QualifiedPost) else (Maybe EpaLocation
forall a. Maybe a
Nothing, ImportDeclQualifiedStyle
NotQualified)

-- | Convenience function to answer the question if an import decl. is
-- qualified.
isImportDeclQualified :: ImportDeclQualifiedStyle -> Bool
isImportDeclQualified :: ImportDeclQualifiedStyle -> Bool
isImportDeclQualified ImportDeclQualifiedStyle
NotQualified = Bool
False
isImportDeclQualified ImportDeclQualifiedStyle
_ = Bool
True

-- | Import Declaration
--
-- A single Haskell @import@ declaration.
data ImportDecl pass
  = ImportDecl {
      forall pass. ImportDecl pass -> XCImportDecl pass
ideclExt       :: XCImportDecl pass,
      forall pass. ImportDecl pass -> SourceText
ideclSourceSrc :: SourceText,
                                 -- Note [Pragma source text] in GHC.Types.SourceText
      forall pass. ImportDecl pass -> XRec pass ModuleName
ideclName      :: XRec pass ModuleName, -- ^ Module name.
      forall pass. ImportDecl pass -> Maybe StringLiteral
ideclPkgQual   :: Maybe StringLiteral,  -- ^ Package qualifier.
      forall pass. ImportDecl pass -> IsBootInterface
ideclSource    :: IsBootInterface,      -- ^ IsBoot <=> {-\# SOURCE \#-} import
      forall pass. ImportDecl pass -> Bool
ideclSafe      :: Bool,          -- ^ True => safe import
      forall pass. ImportDecl pass -> ImportDeclQualifiedStyle
ideclQualified :: ImportDeclQualifiedStyle, -- ^ If/how the import is qualified.
      forall pass. ImportDecl pass -> Bool
ideclImplicit  :: Bool,          -- ^ True => implicit import (of Prelude)
      forall pass. ImportDecl pass -> Maybe (XRec pass ModuleName)
ideclAs        :: Maybe (XRec pass ModuleName),  -- ^ as Module
      forall pass. ImportDecl pass -> Maybe (Bool, XRec pass [LIE pass])
ideclHiding    :: Maybe (Bool, XRec pass [LIE pass])
                                       -- ^ (True => hiding, names)
    }
  | XImportDecl !(XXImportDecl pass)
     -- ^
     --  'GHC.Parser.Annotation.AnnKeywordId's
     --
     --  - 'GHC.Parser.Annotation.AnnImport'
     --
     --  - 'GHC.Parser.Annotation.AnnOpen', 'GHC.Parser.Annotation.AnnClose' for ideclSource
     --
     --  - 'GHC.Parser.Annotation.AnnSafe','GHC.Parser.Annotation.AnnQualified',
     --    'GHC.Parser.Annotation.AnnPackageName','GHC.Parser.Annotation.AnnAs',
     --    'GHC.Parser.Annotation.AnnVal'
     --
     --  - 'GHC.Parser.Annotation.AnnHiding','GHC.Parser.Annotation.AnnOpen',
     --    'GHC.Parser.Annotation.AnnClose' attached
     --     to location in ideclHiding

     -- For details on above see note [exact print annotations] in GHC.Parser.Annotation

type instance XCImportDecl  GhcPs = EpAnn EpAnnImportDecl
type instance XCImportDecl  GhcRn = NoExtField
type instance XCImportDecl  GhcTc = NoExtField

type instance XXImportDecl  (GhcPass _) = NoExtCon

type instance Anno ModuleName = SrcSpan
type instance Anno [LocatedA (IE (GhcPass p))] = SrcSpanAnnL

-- ---------------------------------------------------------------------

-- API Annotations types

data EpAnnImportDecl = EpAnnImportDecl
  { EpAnnImportDecl -> EpaLocation
importDeclAnnImport    :: EpaLocation
  , EpAnnImportDecl -> Maybe (EpaLocation, EpaLocation)
importDeclAnnPragma    :: Maybe (EpaLocation, EpaLocation)
  , EpAnnImportDecl -> Maybe EpaLocation
importDeclAnnSafe      :: Maybe EpaLocation
  , EpAnnImportDecl -> Maybe EpaLocation
importDeclAnnQualified :: Maybe EpaLocation
  , EpAnnImportDecl -> Maybe EpaLocation
importDeclAnnPackage   :: Maybe EpaLocation
  , EpAnnImportDecl -> Maybe EpaLocation
importDeclAnnAs        :: Maybe EpaLocation
  } deriving (Typeable EpAnnImportDecl
Typeable EpAnnImportDecl
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> EpAnnImportDecl -> c EpAnnImportDecl)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c EpAnnImportDecl)
-> (EpAnnImportDecl -> Constr)
-> (EpAnnImportDecl -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c EpAnnImportDecl))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c EpAnnImportDecl))
-> ((forall b. Data b => b -> b)
    -> EpAnnImportDecl -> EpAnnImportDecl)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> EpAnnImportDecl -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> EpAnnImportDecl -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> EpAnnImportDecl -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> EpAnnImportDecl -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> EpAnnImportDecl -> m EpAnnImportDecl)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> EpAnnImportDecl -> m EpAnnImportDecl)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> EpAnnImportDecl -> m EpAnnImportDecl)
-> Data EpAnnImportDecl
EpAnnImportDecl -> DataType
EpAnnImportDecl -> Constr
(forall b. Data b => b -> b) -> EpAnnImportDecl -> EpAnnImportDecl
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> EpAnnImportDecl -> u
forall u. (forall d. Data d => d -> u) -> EpAnnImportDecl -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> EpAnnImportDecl -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> EpAnnImportDecl -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> EpAnnImportDecl -> m EpAnnImportDecl
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> EpAnnImportDecl -> m EpAnnImportDecl
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c EpAnnImportDecl
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> EpAnnImportDecl -> c EpAnnImportDecl
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c EpAnnImportDecl)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c EpAnnImportDecl)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> EpAnnImportDecl -> m EpAnnImportDecl
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> EpAnnImportDecl -> m EpAnnImportDecl
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> EpAnnImportDecl -> m EpAnnImportDecl
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> EpAnnImportDecl -> m EpAnnImportDecl
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> EpAnnImportDecl -> m EpAnnImportDecl
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> EpAnnImportDecl -> m EpAnnImportDecl
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> EpAnnImportDecl -> u
$cgmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> EpAnnImportDecl -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> EpAnnImportDecl -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> EpAnnImportDecl -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> EpAnnImportDecl -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> EpAnnImportDecl -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> EpAnnImportDecl -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> EpAnnImportDecl -> r
gmapT :: (forall b. Data b => b -> b) -> EpAnnImportDecl -> EpAnnImportDecl
$cgmapT :: (forall b. Data b => b -> b) -> EpAnnImportDecl -> EpAnnImportDecl
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c EpAnnImportDecl)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c EpAnnImportDecl)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c EpAnnImportDecl)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c EpAnnImportDecl)
dataTypeOf :: EpAnnImportDecl -> DataType
$cdataTypeOf :: EpAnnImportDecl -> DataType
toConstr :: EpAnnImportDecl -> Constr
$ctoConstr :: EpAnnImportDecl -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c EpAnnImportDecl
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c EpAnnImportDecl
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> EpAnnImportDecl -> c EpAnnImportDecl
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> EpAnnImportDecl -> c EpAnnImportDecl
Data)

-- ---------------------------------------------------------------------

simpleImportDecl :: ModuleName -> ImportDecl GhcPs
simpleImportDecl :: ModuleName -> ImportDecl GhcPs
simpleImportDecl ModuleName
mn = ImportDecl {
      ideclExt :: XCImportDecl GhcPs
ideclExt       = XCImportDecl GhcPs
forall a. EpAnn a
noAnn,
      ideclSourceSrc :: SourceText
ideclSourceSrc = SourceText
NoSourceText,
      ideclName :: XRec GhcPs ModuleName
ideclName      = ModuleName -> Located ModuleName
forall e. e -> Located e
noLoc ModuleName
mn,
      ideclPkgQual :: Maybe StringLiteral
ideclPkgQual   = Maybe StringLiteral
forall a. Maybe a
Nothing,
      ideclSource :: IsBootInterface
ideclSource    = IsBootInterface
NotBoot,
      ideclSafe :: Bool
ideclSafe      = Bool
False,
      ideclImplicit :: Bool
ideclImplicit  = Bool
False,
      ideclQualified :: ImportDeclQualifiedStyle
ideclQualified = ImportDeclQualifiedStyle
NotQualified,
      ideclAs :: Maybe (XRec GhcPs ModuleName)
ideclAs        = Maybe (XRec GhcPs ModuleName)
forall a. Maybe a
Nothing,
      ideclHiding :: Maybe (Bool, XRec GhcPs [LIE GhcPs])
ideclHiding    = Maybe (Bool, XRec GhcPs [LIE GhcPs])
forall a. Maybe a
Nothing
    }

instance (OutputableBndrId p
         , Outputable (Anno (IE (GhcPass p))))
       => Outputable (ImportDecl (GhcPass p)) where
    ppr :: ImportDecl (GhcPass p) -> SDoc
ppr (ImportDecl { ideclSourceSrc :: forall pass. ImportDecl pass -> SourceText
ideclSourceSrc = SourceText
mSrcText, ideclName :: forall pass. ImportDecl pass -> XRec pass ModuleName
ideclName = XRec (GhcPass p) ModuleName
mod'
                    , ideclPkgQual :: forall pass. ImportDecl pass -> Maybe StringLiteral
ideclPkgQual = Maybe StringLiteral
pkg
                    , ideclSource :: forall pass. ImportDecl pass -> IsBootInterface
ideclSource = IsBootInterface
from, ideclSafe :: forall pass. ImportDecl pass -> Bool
ideclSafe = Bool
safe
                    , ideclQualified :: forall pass. ImportDecl pass -> ImportDeclQualifiedStyle
ideclQualified = ImportDeclQualifiedStyle
qual, ideclImplicit :: forall pass. ImportDecl pass -> Bool
ideclImplicit = Bool
implicit
                    , ideclAs :: forall pass. ImportDecl pass -> Maybe (XRec pass ModuleName)
ideclAs = Maybe (XRec (GhcPass p) ModuleName)
as, ideclHiding :: forall pass. ImportDecl pass -> Maybe (Bool, XRec pass [LIE pass])
ideclHiding = Maybe (Bool, XRec (GhcPass p) [LIE (GhcPass p)])
spec })
      = SDoc -> Int -> SDoc -> SDoc
hang ([SDoc] -> SDoc
hsep [String -> SDoc
text String
"import", IsBootInterface -> SDoc
ppr_imp IsBootInterface
from, Bool -> SDoc
pp_implicit Bool
implicit, Bool -> SDoc
pp_safe Bool
safe,
                    ImportDeclQualifiedStyle -> Bool -> SDoc
pp_qual ImportDeclQualifiedStyle
qual Bool
False, Maybe StringLiteral -> SDoc
pp_pkg Maybe StringLiteral
pkg, Located ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr Located ModuleName
XRec (GhcPass p) ModuleName
mod', ImportDeclQualifiedStyle -> Bool -> SDoc
pp_qual ImportDeclQualifiedStyle
qual Bool
True, Maybe (Located ModuleName) -> SDoc
forall {a}. Outputable a => Maybe a -> SDoc
pp_as Maybe (Located ModuleName)
Maybe (XRec (GhcPass p) ModuleName)
as])
             Int
4 (Maybe
  (Bool,
   GenLocated SrcSpanAnnL [GenLocated SrcSpanAnnA (IE (GhcPass p))])
-> SDoc
forall {a} {l}.
Outputable a =>
Maybe (Bool, GenLocated l [a]) -> SDoc
pp_spec Maybe
  (Bool,
   GenLocated SrcSpanAnnL [GenLocated SrcSpanAnnA (IE (GhcPass p))])
Maybe (Bool, XRec (GhcPass p) [LIE (GhcPass p)])
spec)
      where
        pp_implicit :: Bool -> SDoc
pp_implicit Bool
False = SDoc
empty
        pp_implicit Bool
True = PtrString -> SDoc
ptext (String -> PtrString
sLit (String
"(implicit)"))

        pp_pkg :: Maybe StringLiteral -> SDoc
pp_pkg Maybe StringLiteral
Nothing                    = SDoc
empty
        pp_pkg (Just (StringLiteral SourceText
st FastString
p Maybe RealSrcSpan
_))
          = SourceText -> SDoc -> SDoc
pprWithSourceText SourceText
st (SDoc -> SDoc
doubleQuotes (FastString -> SDoc
ftext FastString
p))

        pp_qual :: ImportDeclQualifiedStyle -> Bool -> SDoc
pp_qual ImportDeclQualifiedStyle
QualifiedPre Bool
False = String -> SDoc
text String
"qualified" -- Prepositive qualifier/prepositive position.
        pp_qual ImportDeclQualifiedStyle
QualifiedPost Bool
True = String -> SDoc
text String
"qualified" -- Postpositive qualifier/postpositive position.
        pp_qual ImportDeclQualifiedStyle
QualifiedPre Bool
True = SDoc
empty -- Prepositive qualifier/postpositive position.
        pp_qual ImportDeclQualifiedStyle
QualifiedPost Bool
False = SDoc
empty -- Postpositive qualifier/prepositive position.
        pp_qual ImportDeclQualifiedStyle
NotQualified Bool
_ = SDoc
empty

        pp_safe :: Bool -> SDoc
pp_safe Bool
False   = SDoc
empty
        pp_safe Bool
True    = String -> SDoc
text String
"safe"

        pp_as :: Maybe a -> SDoc
pp_as Maybe a
Nothing   = SDoc
empty
        pp_as (Just a
a)  = String -> SDoc
text String
"as" SDoc -> SDoc -> SDoc
<+> a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
a

        ppr_imp :: IsBootInterface -> SDoc
ppr_imp IsBootInterface
IsBoot = case SourceText
mSrcText of
                          SourceText
NoSourceText   -> String -> SDoc
text String
"{-# SOURCE #-}"
                          SourceText String
src -> String -> SDoc
text String
src SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"#-}"
        ppr_imp IsBootInterface
NotBoot = SDoc
empty

        pp_spec :: Maybe (Bool, GenLocated l [a]) -> SDoc
pp_spec Maybe (Bool, GenLocated l [a])
Nothing             = SDoc
empty
        pp_spec (Just (Bool
False, (L l
_ [a]
ies))) = [a] -> SDoc
forall {a}. Outputable a => [a] -> SDoc
ppr_ies [a]
ies
        pp_spec (Just (Bool
True, (L l
_ [a]
ies))) = String -> SDoc
text String
"hiding" SDoc -> SDoc -> SDoc
<+> [a] -> SDoc
forall {a}. Outputable a => [a] -> SDoc
ppr_ies [a]
ies

        ppr_ies :: [a] -> SDoc
ppr_ies []  = String -> SDoc
text String
"()"
        ppr_ies [a]
ies = Char -> SDoc
char Char
'(' SDoc -> SDoc -> SDoc
<+> [a] -> SDoc
forall {a}. Outputable a => [a] -> SDoc
interpp'SP [a]
ies SDoc -> SDoc -> SDoc
<+> Char -> SDoc
char Char
')'

{-
************************************************************************
*                                                                      *
\subsection{Imported and exported entities}
*                                                                      *
************************************************************************
-}

-- | A name in an import or export specification which may have
-- adornments. Used primarily for accurate pretty printing of
-- ParsedSource, and API Annotation placement. The
-- 'GHC.Parser.Annotation' is the location of the adornment in
-- the original source.
data IEWrappedName name
  = IEName                (LocatedN name)  -- ^ no extra
  | IEPattern EpaLocation (LocatedN name)  -- ^ pattern X
  | IEType    EpaLocation (LocatedN name)  -- ^ type (:+:)
  deriving (IEWrappedName name -> IEWrappedName name -> Bool
(IEWrappedName name -> IEWrappedName name -> Bool)
-> (IEWrappedName name -> IEWrappedName name -> Bool)
-> Eq (IEWrappedName name)
forall name.
Eq name =>
IEWrappedName name -> IEWrappedName name -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IEWrappedName name -> IEWrappedName name -> Bool
$c/= :: forall name.
Eq name =>
IEWrappedName name -> IEWrappedName name -> Bool
== :: IEWrappedName name -> IEWrappedName name -> Bool
$c== :: forall name.
Eq name =>
IEWrappedName name -> IEWrappedName name -> Bool
Eq,Typeable (IEWrappedName name)
Typeable (IEWrappedName name)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g)
    -> IEWrappedName name
    -> c (IEWrappedName name))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (IEWrappedName name))
-> (IEWrappedName name -> Constr)
-> (IEWrappedName name -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (IEWrappedName name)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (IEWrappedName name)))
-> ((forall b. Data b => b -> b)
    -> IEWrappedName name -> IEWrappedName name)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> IEWrappedName name -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> IEWrappedName name -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> IEWrappedName name -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> IEWrappedName name -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> IEWrappedName name -> m (IEWrappedName name))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> IEWrappedName name -> m (IEWrappedName name))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> IEWrappedName name -> m (IEWrappedName name))
-> Data (IEWrappedName name)
IEWrappedName name -> DataType
IEWrappedName name -> Constr
(forall b. Data b => b -> b)
-> IEWrappedName name -> IEWrappedName name
forall {name}. Data name => Typeable (IEWrappedName name)
forall name. Data name => IEWrappedName name -> DataType
forall name. Data name => IEWrappedName name -> Constr
forall name.
Data name =>
(forall b. Data b => b -> b)
-> IEWrappedName name -> IEWrappedName name
forall name u.
Data name =>
Int -> (forall d. Data d => d -> u) -> IEWrappedName name -> u
forall name u.
Data name =>
(forall d. Data d => d -> u) -> IEWrappedName name -> [u]
forall name r r'.
Data name =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> IEWrappedName name -> r
forall name r r'.
Data name =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> IEWrappedName name -> r
forall name (m :: * -> *).
(Data name, Monad m) =>
(forall d. Data d => d -> m d)
-> IEWrappedName name -> m (IEWrappedName name)
forall name (m :: * -> *).
(Data name, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> IEWrappedName name -> m (IEWrappedName name)
forall name (c :: * -> *).
Data name =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (IEWrappedName name)
forall name (c :: * -> *).
Data name =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> IEWrappedName name
-> c (IEWrappedName name)
forall name (t :: * -> *) (c :: * -> *).
(Data name, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (IEWrappedName name))
forall name (t :: * -> * -> *) (c :: * -> *).
(Data name, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (IEWrappedName name))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> IEWrappedName name -> u
forall u. (forall d. Data d => d -> u) -> IEWrappedName name -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> IEWrappedName name -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> IEWrappedName name -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> IEWrappedName name -> m (IEWrappedName name)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> IEWrappedName name -> m (IEWrappedName name)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (IEWrappedName name)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> IEWrappedName name
-> c (IEWrappedName name)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (IEWrappedName name))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (IEWrappedName name))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> IEWrappedName name -> m (IEWrappedName name)
$cgmapMo :: forall name (m :: * -> *).
(Data name, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> IEWrappedName name -> m (IEWrappedName name)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> IEWrappedName name -> m (IEWrappedName name)
$cgmapMp :: forall name (m :: * -> *).
(Data name, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> IEWrappedName name -> m (IEWrappedName name)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> IEWrappedName name -> m (IEWrappedName name)
$cgmapM :: forall name (m :: * -> *).
(Data name, Monad m) =>
(forall d. Data d => d -> m d)
-> IEWrappedName name -> m (IEWrappedName name)
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> IEWrappedName name -> u
$cgmapQi :: forall name u.
Data name =>
Int -> (forall d. Data d => d -> u) -> IEWrappedName name -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> IEWrappedName name -> [u]
$cgmapQ :: forall name u.
Data name =>
(forall d. Data d => d -> u) -> IEWrappedName name -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> IEWrappedName name -> r
$cgmapQr :: forall name r r'.
Data name =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> IEWrappedName name -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> IEWrappedName name -> r
$cgmapQl :: forall name r r'.
Data name =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> IEWrappedName name -> r
gmapT :: (forall b. Data b => b -> b)
-> IEWrappedName name -> IEWrappedName name
$cgmapT :: forall name.
Data name =>
(forall b. Data b => b -> b)
-> IEWrappedName name -> IEWrappedName name
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (IEWrappedName name))
$cdataCast2 :: forall name (t :: * -> * -> *) (c :: * -> *).
(Data name, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (IEWrappedName name))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (IEWrappedName name))
$cdataCast1 :: forall name (t :: * -> *) (c :: * -> *).
(Data name, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (IEWrappedName name))
dataTypeOf :: IEWrappedName name -> DataType
$cdataTypeOf :: forall name. Data name => IEWrappedName name -> DataType
toConstr :: IEWrappedName name -> Constr
$ctoConstr :: forall name. Data name => IEWrappedName name -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (IEWrappedName name)
$cgunfold :: forall name (c :: * -> *).
Data name =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (IEWrappedName name)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> IEWrappedName name
-> c (IEWrappedName name)
$cgfoldl :: forall name (c :: * -> *).
Data name =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> IEWrappedName name
-> c (IEWrappedName name)
Data)

-- | Located name with possible adornment
-- - 'GHC.Parser.Annotation.AnnKeywordId's : 'GHC.Parser.Annotation.AnnType',
--         'GHC.Parser.Annotation.AnnPattern'
type LIEWrappedName name = LocatedA (IEWrappedName name)
-- For details on above see note [exact print annotations] in GHC.Parser.Annotation


-- | Located Import or Export
type LIE pass = XRec pass (IE pass)
        -- ^ When in a list this may have
        --
        --  - 'GHC.Parser.Annotation.AnnKeywordId' : 'GHC.Parser.Annotation.AnnComma'

        -- For details on above see note [exact print annotations] in GHC.Parser.Annotation
type instance Anno (IE (GhcPass p)) = SrcSpanAnnA

-- | Imported or exported entity.
data IE pass
  = IEVar       (XIEVar pass) (LIEWrappedName (IdP pass))
        -- ^ Imported or Exported Variable

  | IEThingAbs  (XIEThingAbs pass) (LIEWrappedName (IdP pass))
        -- ^ Imported or exported Thing with Absent list
        --
        -- The thing is a Class/Type (can't tell)
        --  - 'GHC.Parser.Annotation.AnnKeywordId's : 'GHC.Parser.Annotation.AnnPattern',
        --             'GHC.Parser.Annotation.AnnType','GHC.Parser.Annotation.AnnVal'

        -- For details on above see note [exact print annotations] in GHC.Parser.Annotation
        -- See Note [Located RdrNames] in GHC.Hs.Expr
  | IEThingAll  (XIEThingAll pass) (LIEWrappedName (IdP pass))
        -- ^ Imported or exported Thing with All imported or exported
        --
        -- The thing is a Class/Type and the All refers to methods/constructors
        --
        -- - 'GHC.Parser.Annotation.AnnKeywordId's : 'GHC.Parser.Annotation.AnnOpen',
        --       'GHC.Parser.Annotation.AnnDotdot','GHC.Parser.Annotation.AnnClose',
        --                                 'GHC.Parser.Annotation.AnnType'

        -- For details on above see note [exact print annotations] in GHC.Parser.Annotation
        -- See Note [Located RdrNames] in GHC.Hs.Expr

  | IEThingWith (XIEThingWith pass)
                (LIEWrappedName (IdP pass))
                IEWildcard
                [LIEWrappedName (IdP pass)]
        -- ^ Imported or exported Thing With given imported or exported
        --
        -- The thing is a Class/Type and the imported or exported things are
        -- methods/constructors and record fields; see Note [IEThingWith]
        -- - 'GHC.Parser.Annotation.AnnKeywordId's : 'GHC.Parser.Annotation.AnnOpen',
        --                                   'GHC.Parser.Annotation.AnnClose',
        --                                   'GHC.Parser.Annotation.AnnComma',
        --                                   'GHC.Parser.Annotation.AnnType'

        -- For details on above see note [exact print annotations] in GHC.Parser.Annotation
  | IEModuleContents  (XIEModuleContents pass) (XRec pass ModuleName)
        -- ^ Imported or exported module contents
        --
        -- (Export Only)
        --
        -- - 'GHC.Parser.Annotation.AnnKeywordId's : 'GHC.Parser.Annotation.AnnModule'

        -- For details on above see note [exact print annotations] in GHC.Parser.Annotation
  | IEGroup             (XIEGroup pass) Int HsDocString -- ^ Doc section heading
  | IEDoc               (XIEDoc pass) HsDocString       -- ^ Some documentation
  | IEDocNamed          (XIEDocNamed pass) String    -- ^ Reference to named doc
  | XIE !(XXIE pass)

type instance XIEVar             GhcPs = NoExtField
type instance XIEVar             GhcRn = NoExtField
type instance XIEVar             GhcTc = NoExtField

type instance XIEThingAbs        (GhcPass _) = EpAnn [AddEpAnn]
type instance XIEThingAll        (GhcPass _) = EpAnn [AddEpAnn]

-- See Note [IEThingWith]
type instance XIEThingWith       (GhcPass 'Parsed)      = EpAnn [AddEpAnn]
type instance XIEThingWith       (GhcPass 'Renamed)     = [Located FieldLabel]
type instance XIEThingWith       (GhcPass 'Typechecked) = NoExtField

type instance XIEModuleContents  GhcPs = EpAnn [AddEpAnn]
type instance XIEModuleContents  GhcRn = NoExtField
type instance XIEModuleContents  GhcTc = NoExtField

type instance XIEGroup           (GhcPass _) = NoExtField
type instance XIEDoc             (GhcPass _) = NoExtField
type instance XIEDocNamed        (GhcPass _) = NoExtField
type instance XXIE               (GhcPass _) = NoExtCon

type instance Anno (LocatedA (IE (GhcPass p))) = SrcSpanAnnA

-- | Imported or Exported Wildcard
data IEWildcard = NoIEWildcard | IEWildcard Int deriving (IEWildcard -> IEWildcard -> Bool
(IEWildcard -> IEWildcard -> Bool)
-> (IEWildcard -> IEWildcard -> Bool) -> Eq IEWildcard
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IEWildcard -> IEWildcard -> Bool
$c/= :: IEWildcard -> IEWildcard -> Bool
== :: IEWildcard -> IEWildcard -> Bool
$c== :: IEWildcard -> IEWildcard -> Bool
Eq, Typeable IEWildcard
Typeable IEWildcard
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> IEWildcard -> c IEWildcard)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c IEWildcard)
-> (IEWildcard -> Constr)
-> (IEWildcard -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c IEWildcard))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c IEWildcard))
-> ((forall b. Data b => b -> b) -> IEWildcard -> IEWildcard)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> IEWildcard -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> IEWildcard -> r)
-> (forall u. (forall d. Data d => d -> u) -> IEWildcard -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> IEWildcard -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> IEWildcard -> m IEWildcard)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> IEWildcard -> m IEWildcard)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> IEWildcard -> m IEWildcard)
-> Data IEWildcard
IEWildcard -> DataType
IEWildcard -> Constr
(forall b. Data b => b -> b) -> IEWildcard -> IEWildcard
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> IEWildcard -> u
forall u. (forall d. Data d => d -> u) -> IEWildcard -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> IEWildcard -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> IEWildcard -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> IEWildcard -> m IEWildcard
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IEWildcard -> m IEWildcard
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IEWildcard
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IEWildcard -> c IEWildcard
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c IEWildcard)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IEWildcard)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IEWildcard -> m IEWildcard
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IEWildcard -> m IEWildcard
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IEWildcard -> m IEWildcard
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> IEWildcard -> m IEWildcard
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> IEWildcard -> m IEWildcard
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> IEWildcard -> m IEWildcard
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> IEWildcard -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> IEWildcard -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> IEWildcard -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> IEWildcard -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> IEWildcard -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> IEWildcard -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> IEWildcard -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> IEWildcard -> r
gmapT :: (forall b. Data b => b -> b) -> IEWildcard -> IEWildcard
$cgmapT :: (forall b. Data b => b -> b) -> IEWildcard -> IEWildcard
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IEWildcard)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IEWildcard)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c IEWildcard)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c IEWildcard)
dataTypeOf :: IEWildcard -> DataType
$cdataTypeOf :: IEWildcard -> DataType
toConstr :: IEWildcard -> Constr
$ctoConstr :: IEWildcard -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IEWildcard
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c IEWildcard
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IEWildcard -> c IEWildcard
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IEWildcard -> c IEWildcard
Data)

{-
Note [IEThingWith]
~~~~~~~~~~~~~~~~~~
A definition like

    {-# LANGUAGE DuplicateRecordFields #-}
    module M ( T(MkT, x) ) where
      data T = MkT { x :: Int }

gives rise to this in the output of the parser:

    IEThingWith NoExtField T [MkT, x] NoIEWildcard

But in the renamer we need to attach the correct field label,
because the selector Name is mangled (see Note [FieldLabel] in
GHC.Types.FieldLabel).  Hence we change this to:

    IEThingWith [FieldLabel "x" True $sel:x:MkT)] T [MkT] NoIEWildcard

using the TTG extension field to store the list of fields in renamed syntax
only.  (Record fields always appear in this list, regardless of whether
DuplicateRecordFields was in use at the definition site or not.)

See Note [Representing fields in AvailInfo] in GHC.Types.Avail for more details.
-}

ieName :: IE (GhcPass p) -> IdP (GhcPass p)
ieName :: forall (p :: Pass). IE (GhcPass p) -> IdP (GhcPass p)
ieName (IEVar XIEVar (GhcPass p)
_ (L SrcSpanAnnA
_ IEWrappedName (IdP (GhcPass p))
n))            = IEWrappedName (IdGhcP p) -> IdGhcP p
forall name. IEWrappedName name -> name
ieWrappedName IEWrappedName (IdP (GhcPass p))
IEWrappedName (IdGhcP p)
n
ieName (IEThingAbs  XIEThingAbs (GhcPass p)
_ (L SrcSpanAnnA
_ IEWrappedName (IdP (GhcPass p))
n))      = IEWrappedName (IdGhcP p) -> IdGhcP p
forall name. IEWrappedName name -> name
ieWrappedName IEWrappedName (IdP (GhcPass p))
IEWrappedName (IdGhcP p)
n
ieName (IEThingWith XIEThingWith (GhcPass p)
_ (L SrcSpanAnnA
_ IEWrappedName (IdP (GhcPass p))
n) IEWildcard
_ [GenLocated SrcSpanAnnA (IEWrappedName (IdP (GhcPass p)))]
_)  = IEWrappedName (IdGhcP p) -> IdGhcP p
forall name. IEWrappedName name -> name
ieWrappedName IEWrappedName (IdP (GhcPass p))
IEWrappedName (IdGhcP p)
n
ieName (IEThingAll  XIEThingAll (GhcPass p)
_ (L SrcSpanAnnA
_ IEWrappedName (IdP (GhcPass p))
n))      = IEWrappedName (IdGhcP p) -> IdGhcP p
forall name. IEWrappedName name -> name
ieWrappedName IEWrappedName (IdP (GhcPass p))
IEWrappedName (IdGhcP p)
n
ieName IE (GhcPass p)
_ = String -> IdGhcP p
forall a. String -> a
panic String
"ieName failed pattern match!"

ieNames :: IE (GhcPass p) -> [IdP (GhcPass p)]
ieNames :: forall (p :: Pass). IE (GhcPass p) -> [IdP (GhcPass p)]
ieNames (IEVar       XIEVar (GhcPass p)
_ (L SrcSpanAnnA
_ IEWrappedName (IdP (GhcPass p))
n)   )   = [IEWrappedName (IdGhcP p) -> IdGhcP p
forall name. IEWrappedName name -> name
ieWrappedName IEWrappedName (IdP (GhcPass p))
IEWrappedName (IdGhcP p)
n]
ieNames (IEThingAbs  XIEThingAbs (GhcPass p)
_ (L SrcSpanAnnA
_ IEWrappedName (IdP (GhcPass p))
n)   )   = [IEWrappedName (IdGhcP p) -> IdGhcP p
forall name. IEWrappedName name -> name
ieWrappedName IEWrappedName (IdP (GhcPass p))
IEWrappedName (IdGhcP p)
n]
ieNames (IEThingAll  XIEThingAll (GhcPass p)
_ (L SrcSpanAnnA
_ IEWrappedName (IdP (GhcPass p))
n)   )   = [IEWrappedName (IdGhcP p) -> IdGhcP p
forall name. IEWrappedName name -> name
ieWrappedName IEWrappedName (IdP (GhcPass p))
IEWrappedName (IdGhcP p)
n]
ieNames (IEThingWith XIEThingWith (GhcPass p)
_ (L SrcSpanAnnA
_ IEWrappedName (IdP (GhcPass p))
n) IEWildcard
_ [GenLocated SrcSpanAnnA (IEWrappedName (IdP (GhcPass p)))]
ns) = IEWrappedName (IdGhcP p) -> IdGhcP p
forall name. IEWrappedName name -> name
ieWrappedName IEWrappedName (IdP (GhcPass p))
IEWrappedName (IdGhcP p)
n
                                     IdGhcP p -> [IdGhcP p] -> [IdGhcP p]
forall a. a -> [a] -> [a]
: (GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p)) -> IdGhcP p)
-> [GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p))]
-> [IdGhcP p]
forall a b. (a -> b) -> [a] -> [b]
map (IEWrappedName (IdGhcP p) -> IdGhcP p
forall name. IEWrappedName name -> name
ieWrappedName (IEWrappedName (IdGhcP p) -> IdGhcP p)
-> (GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p))
    -> IEWrappedName (IdGhcP p))
-> GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p))
-> IdGhcP p
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p))
-> IEWrappedName (IdGhcP p)
forall l e. GenLocated l e -> e
unLoc) [GenLocated SrcSpanAnnA (IEWrappedName (IdP (GhcPass p)))]
[GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p))]
ns
-- NB the above case does not include names of field selectors
ieNames (IEModuleContents {})     = []
ieNames (IEGroup          {})     = []
ieNames (IEDoc            {})     = []
ieNames (IEDocNamed       {})     = []

ieWrappedLName :: IEWrappedName name -> LocatedN name
ieWrappedLName :: forall name. IEWrappedName name -> LocatedN name
ieWrappedLName (IEName      LocatedN name
ln) = LocatedN name
ln
ieWrappedLName (IEPattern EpaLocation
_ LocatedN name
ln) = LocatedN name
ln
ieWrappedLName (IEType    EpaLocation
_ LocatedN name
ln) = LocatedN name
ln

ieWrappedName :: IEWrappedName name -> name
ieWrappedName :: forall name. IEWrappedName name -> name
ieWrappedName = GenLocated (SrcSpanAnn' (EpAnn NameAnn)) name -> name
forall l e. GenLocated l e -> e
unLoc (GenLocated (SrcSpanAnn' (EpAnn NameAnn)) name -> name)
-> (IEWrappedName name
    -> GenLocated (SrcSpanAnn' (EpAnn NameAnn)) name)
-> IEWrappedName name
-> name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IEWrappedName name -> GenLocated (SrcSpanAnn' (EpAnn NameAnn)) name
forall name. IEWrappedName name -> LocatedN name
ieWrappedLName


lieWrappedName :: LIEWrappedName name -> name
lieWrappedName :: forall name. LIEWrappedName name -> name
lieWrappedName (L SrcSpanAnnA
_ IEWrappedName name
n) = IEWrappedName name -> name
forall name. IEWrappedName name -> name
ieWrappedName IEWrappedName name
n

ieLWrappedName :: LIEWrappedName name -> LocatedN name
ieLWrappedName :: forall name. LIEWrappedName name -> LocatedN name
ieLWrappedName (L SrcSpanAnnA
_ IEWrappedName name
n) = IEWrappedName name -> LocatedN name
forall name. IEWrappedName name -> LocatedN name
ieWrappedLName IEWrappedName name
n

replaceWrappedName :: IEWrappedName name1 -> name2 -> IEWrappedName name2
replaceWrappedName :: forall name1 name2.
IEWrappedName name1 -> name2 -> IEWrappedName name2
replaceWrappedName (IEName      (L SrcSpanAnn' (EpAnn NameAnn)
l name1
_)) name2
n = LocatedN name2 -> IEWrappedName name2
forall name. LocatedN name -> IEWrappedName name
IEName      (SrcSpanAnn' (EpAnn NameAnn) -> name2 -> LocatedN name2
forall l e. l -> e -> GenLocated l e
L SrcSpanAnn' (EpAnn NameAnn)
l name2
n)
replaceWrappedName (IEPattern EpaLocation
r (L SrcSpanAnn' (EpAnn NameAnn)
l name1
_)) name2
n = EpaLocation -> LocatedN name2 -> IEWrappedName name2
forall name. EpaLocation -> LocatedN name -> IEWrappedName name
IEPattern EpaLocation
r (SrcSpanAnn' (EpAnn NameAnn) -> name2 -> LocatedN name2
forall l e. l -> e -> GenLocated l e
L SrcSpanAnn' (EpAnn NameAnn)
l name2
n)
replaceWrappedName (IEType    EpaLocation
r (L SrcSpanAnn' (EpAnn NameAnn)
l name1
_)) name2
n = EpaLocation -> LocatedN name2 -> IEWrappedName name2
forall name. EpaLocation -> LocatedN name -> IEWrappedName name
IEType    EpaLocation
r (SrcSpanAnn' (EpAnn NameAnn) -> name2 -> LocatedN name2
forall l e. l -> e -> GenLocated l e
L SrcSpanAnn' (EpAnn NameAnn)
l name2
n)

replaceLWrappedName :: LIEWrappedName name1 -> name2 -> LIEWrappedName name2
replaceLWrappedName :: forall name1 name2.
LIEWrappedName name1 -> name2 -> LIEWrappedName name2
replaceLWrappedName (L SrcSpanAnnA
l IEWrappedName name1
n) name2
n' = SrcSpanAnnA
-> IEWrappedName name2
-> GenLocated SrcSpanAnnA (IEWrappedName name2)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
l (IEWrappedName name1 -> name2 -> IEWrappedName name2
forall name1 name2.
IEWrappedName name1 -> name2 -> IEWrappedName name2
replaceWrappedName IEWrappedName name1
n name2
n')

instance OutputableBndrId p => Outputable (IE (GhcPass p)) where
    ppr :: IE (GhcPass p) -> SDoc
ppr (IEVar       XIEVar (GhcPass p)
_     LIEWrappedName (IdP (GhcPass p))
var) = IEWrappedName (IdGhcP p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr (GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p))
-> IEWrappedName (IdGhcP p)
forall l e. GenLocated l e -> e
unLoc LIEWrappedName (IdP (GhcPass p))
GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p))
var)
    ppr (IEThingAbs  XIEThingAbs (GhcPass p)
_   LIEWrappedName (IdP (GhcPass p))
thing) = IEWrappedName (IdGhcP p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr (GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p))
-> IEWrappedName (IdGhcP p)
forall l e. GenLocated l e -> e
unLoc LIEWrappedName (IdP (GhcPass p))
GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p))
thing)
    ppr (IEThingAll  XIEThingAll (GhcPass p)
_   LIEWrappedName (IdP (GhcPass p))
thing) = [SDoc] -> SDoc
hcat [IEWrappedName (IdGhcP p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr (GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p))
-> IEWrappedName (IdGhcP p)
forall l e. GenLocated l e -> e
unLoc LIEWrappedName (IdP (GhcPass p))
GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p))
thing), String -> SDoc
text String
"(..)"]
    ppr (IEThingWith XIEThingWith (GhcPass p)
flds LIEWrappedName (IdP (GhcPass p))
thing IEWildcard
wc [LIEWrappedName (IdP (GhcPass p))]
withs)
        = IEWrappedName (IdGhcP p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr (GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p))
-> IEWrappedName (IdGhcP p)
forall l e. GenLocated l e -> e
unLoc LIEWrappedName (IdP (GhcPass p))
GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p))
thing) SDoc -> SDoc -> SDoc
<> SDoc -> SDoc
parens ([SDoc] -> SDoc
fsep (SDoc -> [SDoc] -> [SDoc]
punctuate SDoc
comma
                                              ([SDoc]
ppWiths [SDoc] -> [SDoc] -> [SDoc]
forall a. [a] -> [a] -> [a]
++ [SDoc]
ppFields) ))
      where
        ppWiths :: [SDoc]
ppWiths =
          case IEWildcard
wc of
              IEWildcard
NoIEWildcard ->
                (GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p)) -> SDoc)
-> [GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p))] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (IEWrappedName (IdGhcP p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr (IEWrappedName (IdGhcP p) -> SDoc)
-> (GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p))
    -> IEWrappedName (IdGhcP p))
-> GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p))
-> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p))
-> IEWrappedName (IdGhcP p)
forall l e. GenLocated l e -> e
unLoc) [LIEWrappedName (IdP (GhcPass p))]
[GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p))]
withs
              IEWildcard Int
pos ->
                let ([SDoc]
bs, [SDoc]
as) = Int -> [SDoc] -> ([SDoc], [SDoc])
forall a. Int -> [a] -> ([a], [a])
splitAt Int
pos ((GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p)) -> SDoc)
-> [GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p))] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (IEWrappedName (IdGhcP p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr (IEWrappedName (IdGhcP p) -> SDoc)
-> (GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p))
    -> IEWrappedName (IdGhcP p))
-> GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p))
-> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p))
-> IEWrappedName (IdGhcP p)
forall l e. GenLocated l e -> e
unLoc) [LIEWrappedName (IdP (GhcPass p))]
[GenLocated SrcSpanAnnA (IEWrappedName (IdGhcP p))]
withs)
                in [SDoc]
bs [SDoc] -> [SDoc] -> [SDoc]
forall a. [a] -> [a] -> [a]
++ [String -> SDoc
text String
".."] [SDoc] -> [SDoc] -> [SDoc]
forall a. [a] -> [a] -> [a]
++ [SDoc]
as
        ppFields :: [SDoc]
ppFields =
          case forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p of
            GhcPass p
GhcRn -> (Located FieldLabel -> SDoc) -> [Located FieldLabel] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map Located FieldLabel -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Located FieldLabel]
XIEThingWith (GhcPass p)
flds
            GhcPass p
_     -> []
    ppr (IEModuleContents XIEModuleContents (GhcPass p)
_ XRec (GhcPass p) ModuleName
mod')
        = String -> SDoc
text String
"module" SDoc -> SDoc -> SDoc
<+> Located ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr Located ModuleName
XRec (GhcPass p) ModuleName
mod'
    ppr (IEGroup XIEGroup (GhcPass p)
_ Int
n HsDocString
_)           = String -> SDoc
text (String
"<IEGroup: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
n String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
">")
    ppr (IEDoc XIEDoc (GhcPass p)
_ HsDocString
doc)             = HsDocString -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsDocString
doc
    ppr (IEDocNamed XIEDocNamed (GhcPass p)
_ String
string)     = String -> SDoc
text (String
"<IEDocNamed: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
string String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
">")

instance (HasOccName name) => HasOccName (IEWrappedName name) where
  occName :: IEWrappedName name -> OccName
occName IEWrappedName name
w = name -> OccName
forall name. HasOccName name => name -> OccName
occName (IEWrappedName name -> name
forall name. IEWrappedName name -> name
ieWrappedName IEWrappedName name
w)

instance (OutputableBndr name) => OutputableBndr (IEWrappedName name) where
  pprBndr :: BindingSite -> IEWrappedName name -> SDoc
pprBndr BindingSite
bs   IEWrappedName name
w = BindingSite -> name -> SDoc
forall a. OutputableBndr a => BindingSite -> a -> SDoc
pprBndr BindingSite
bs   (IEWrappedName name -> name
forall name. IEWrappedName name -> name
ieWrappedName IEWrappedName name
w)
  pprPrefixOcc :: IEWrappedName name -> SDoc
pprPrefixOcc IEWrappedName name
w = name -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (IEWrappedName name -> name
forall name. IEWrappedName name -> name
ieWrappedName IEWrappedName name
w)
  pprInfixOcc :: IEWrappedName name -> SDoc
pprInfixOcc  IEWrappedName name
w = name -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprInfixOcc  (IEWrappedName name -> name
forall name. IEWrappedName name -> name
ieWrappedName IEWrappedName name
w)

instance (OutputableBndr name) => Outputable (IEWrappedName name) where
  ppr :: IEWrappedName name -> SDoc
ppr (IEName      LocatedN name
n) = name -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (LocatedN name -> name
forall l e. GenLocated l e -> e
unLoc LocatedN name
n)
  ppr (IEPattern EpaLocation
_ LocatedN name
n) = String -> SDoc
text String
"pattern" SDoc -> SDoc -> SDoc
<+> name -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (LocatedN name -> name
forall l e. GenLocated l e -> e
unLoc LocatedN name
n)
  ppr (IEType    EpaLocation
_ LocatedN name
n) = String -> SDoc
text String
"type"    SDoc -> SDoc -> SDoc
<+> name -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (LocatedN name -> name
forall l e. GenLocated l e -> e
unLoc LocatedN name
n)

pprImpExp :: (HasOccName name, OutputableBndr name) => name -> SDoc
pprImpExp :: forall name. (HasOccName name, OutputableBndr name) => name -> SDoc
pprImpExp name
name = SDoc
type_pref SDoc -> SDoc -> SDoc
<+> name -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc name
name
    where
    occ :: OccName
occ = name -> OccName
forall name. HasOccName name => name -> OccName
occName name
name
    type_pref :: SDoc
type_pref | OccName -> Bool
isTcOcc OccName
occ Bool -> Bool -> Bool
&& OccName -> Bool
isSymOcc OccName
occ = String -> SDoc
text String
"type"
              | Bool
otherwise                   = SDoc
empty