{-
(c) The University of Glasgow 2006
(c) The GRASP/AQUA Project, Glasgow University, 1992-1998


HsImpExp: Abstract syntax: imports, exports, interfaces
-}

{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-} -- Note [Pass sensitive types]
                                      -- in module PlaceHolder

module HsImpExp where

import GhcPrelude

import Module           ( ModuleName )
import HsDoc            ( HsDocString )
import OccName          ( HasOccName(..), isTcOcc, isSymOcc )
import BasicTypes       ( SourceText(..), StringLiteral(..), pprWithSourceText )
import FieldLabel       ( FieldLbl(..) )

import Outputable
import FastString
import SrcLoc
import HsExtension

import Data.Data

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

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

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

        -- For details on above see note [Api annotations] in ApiAnnotation

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

     -- For details on above see note [Api annotations] in ApiAnnotation

type instance XCImportDecl  (GhcPass _) = NoExt
type instance XXImportDecl  (GhcPass _) = NoExt

simpleImportDecl :: ModuleName -> ImportDecl (GhcPass p)
simpleImportDecl :: ModuleName -> ImportDecl (GhcPass p)
simpleImportDecl mn :: ModuleName
mn = ImportDecl :: forall pass.
XCImportDecl pass
-> SourceText
-> Located ModuleName
-> Maybe StringLiteral
-> Bool
-> Bool
-> Bool
-> Bool
-> Maybe (Located ModuleName)
-> Maybe (Bool, Located [LIE pass])
-> ImportDecl pass
ImportDecl {
      ideclExt :: XCImportDecl (GhcPass p)
ideclExt       = XCImportDecl (GhcPass p)
NoExt
noExt,
      ideclSourceSrc :: SourceText
ideclSourceSrc = SourceText
NoSourceText,
      ideclName :: Located ModuleName
ideclName      = SrcSpanLess (Located ModuleName) -> Located ModuleName
forall a. HasSrcSpan a => SrcSpanLess a -> a
noLoc ModuleName
SrcSpanLess (Located ModuleName)
mn,
      ideclPkgQual :: Maybe StringLiteral
ideclPkgQual   = Maybe StringLiteral
forall a. Maybe a
Nothing,
      ideclSource :: Bool
ideclSource    = Bool
False,
      ideclSafe :: Bool
ideclSafe      = Bool
False,
      ideclImplicit :: Bool
ideclImplicit  = Bool
False,
      ideclQualified :: Bool
ideclQualified = Bool
False,
      ideclAs :: Maybe (Located ModuleName)
ideclAs        = Maybe (Located ModuleName)
forall a. Maybe a
Nothing,
      ideclHiding :: Maybe (Bool, Located [LIE (GhcPass p)])
ideclHiding    = Maybe (Bool, Located [LIE (GhcPass p)])
forall a. Maybe a
Nothing
    }

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

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

        pp_qual :: Bool -> SDoc
pp_qual False   = SDoc
empty
        pp_qual True    = String -> SDoc
text "qualified"

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

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

        ppr_imp :: Bool -> SDoc
ppr_imp True  = case SourceText
mSrcText of
                          NoSourceText   -> String -> SDoc
text "{-# SOURCE #-}"
                          SourceText src :: String
src -> String -> SDoc
text String
src SDoc -> SDoc -> SDoc
<+> String -> SDoc
text "#-}"
        ppr_imp False = SDoc
empty

        pp_spec :: Maybe (Bool, GenLocated l [a]) -> SDoc
pp_spec Nothing             = SDoc
empty
        pp_spec (Just (False, (L _ ies :: [a]
ies))) = [a] -> SDoc
forall a. Outputable a => [a] -> SDoc
ppr_ies [a]
ies
        pp_spec (Just (True, (L _ ies :: [a]
ies))) = String -> SDoc
text "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 "()"
        ppr_ies ies :: [a]
ies = Char -> SDoc
char '(' SDoc -> SDoc -> SDoc
<+> [a] -> SDoc
forall a. Outputable a => [a] -> SDoc
interpp'SP [a]
ies SDoc -> SDoc -> SDoc
<+> Char -> SDoc
char ')'
    ppr (XImportDecl x :: XXImportDecl p
x) = NoExt -> SDoc
forall a. Outputable a => a -> SDoc
ppr XXImportDecl p
NoExt
x

{-
************************************************************************
*                                                                      *
\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.
data IEWrappedName name
  = IEName    (Located name)  -- ^ no extra
  | IEPattern (Located name)  -- ^ pattern X
  | IEType    (Located 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)
DataType
Constr
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 d. Data d => c (t d)) -> Maybe (c (IEWrappedName name))
(forall b. Data b => b -> b)
-> IEWrappedName name -> IEWrappedName name
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> IEWrappedName name
-> c (IEWrappedName name)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (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))
$cIEType :: Constr
$cIEPattern :: Constr
$cIEName :: Constr
$tIEWrappedName :: DataType
gmapMo :: (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 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 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 :: 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 d. Data d => d -> u) -> IEWrappedName name -> [u]
$cgmapQ :: forall name u.
Data name =>
(forall d. Data d => d -> u) -> IEWrappedName name -> [u]
gmapQr :: (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 :: (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 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 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 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 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)
$cp1Data :: forall name. Data name => Typeable (IEWrappedName name)
Data)

-- | Located name with possible adornment
-- - 'ApiAnnotation.AnnKeywordId's : 'ApiAnnotation.AnnType',
--         'ApiAnnotation.AnnPattern'
type LIEWrappedName name = Located (IEWrappedName name)
-- For details on above see note [Api annotations] in ApiAnnotation


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

        -- For details on above see note [Api annotations] in ApiAnnotation

-- | 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)
        --  - 'ApiAnnotation.AnnKeywordId's : 'ApiAnnotation.AnnPattern',
        --             'ApiAnnotation.AnnType','ApiAnnotation.AnnVal'

        -- For details on above see note [Api annotations] in ApiAnnotation
        -- See Note [Located RdrNames] in HsExpr
  | 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
        --
        -- - 'ApiAnnotation.AnnKeywordId's : 'ApiAnnotation.AnnOpen',
        --       'ApiAnnotation.AnnDotdot','ApiAnnotation.AnnClose',
        --                                 'ApiAnnotation.AnnType'

        -- For details on above see note [Api annotations] in ApiAnnotation
        -- See Note [Located RdrNames] in HsExpr

  | IEThingWith (XIEThingWith pass)
                (LIEWrappedName (IdP pass))
                IEWildcard
                [LIEWrappedName (IdP pass)]
                [Located (FieldLbl (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]
        -- - 'ApiAnnotation.AnnKeywordId's : 'ApiAnnotation.AnnOpen',
        --                                   'ApiAnnotation.AnnClose',
        --                                   'ApiAnnotation.AnnComma',
        --                                   'ApiAnnotation.AnnType'

        -- For details on above see note [Api annotations] in ApiAnnotation
  | IEModuleContents  (XIEModuleContents pass) (Located ModuleName)
        -- ^ Imported or exported module contents
        --
        -- (Export Only)
        --
        -- - 'ApiAnnotation.AnnKeywordId's : 'ApiAnnotation.AnnModule'

        -- For details on above see note [Api annotations] in ApiAnnotation
  | 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             (GhcPass _) = NoExt
type instance XIEThingAbs        (GhcPass _) = NoExt
type instance XIEThingAll        (GhcPass _) = NoExt
type instance XIEThingWith       (GhcPass _) = NoExt
type instance XIEModuleContents  (GhcPass _) = NoExt
type instance XIEGroup           (GhcPass _) = NoExt
type instance XIEDoc             (GhcPass _) = NoExt
type instance XIEDocNamed        (GhcPass _) = NoExt
type instance XXIE               (GhcPass _) = NoExt

-- | 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
DataType
Constr
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 d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> IEWildcard -> c IEWildcard
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c 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)
$cIEWildcard :: Constr
$cNoIEWildcard :: Constr
$tIEWildcard :: DataType
gmapMo :: (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 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 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 :: Int -> (forall d. Data d => d -> u) -> IEWildcard -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> IEWildcard -> u
gmapQ :: (forall d. Data d => d -> u) -> IEWildcard -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> IEWildcard -> [u]
gmapQr :: (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 :: (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 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 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 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 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
$cp1Data :: Typeable IEWildcard
Data)

{-
Note [IEThingWith]
~~~~~~~~~~~~~~~~~~

A definition like

    module M ( T(MkT, x) ) where
      data T = MkT { x :: Int }

gives rise to

    IEThingWith T [MkT] [FieldLabel "x" False x)]           (without DuplicateRecordFields)
    IEThingWith T [MkT] [FieldLabel "x" True $sel:x:MkT)]   (with    DuplicateRecordFields)

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

ieName :: IE pass -> IdP pass
ieName :: IE pass -> IdP pass
ieName (IEVar _ (L _ n :: IEWrappedName (IdP pass)
n))              = IEWrappedName (IdP pass) -> IdP pass
forall name. IEWrappedName name -> name
ieWrappedName IEWrappedName (IdP pass)
n
ieName (IEThingAbs  _ (L _ n :: IEWrappedName (IdP pass)
n))        = IEWrappedName (IdP pass) -> IdP pass
forall name. IEWrappedName name -> name
ieWrappedName IEWrappedName (IdP pass)
n
ieName (IEThingWith _ (L _ n :: IEWrappedName (IdP pass)
n) _ _ _)  = IEWrappedName (IdP pass) -> IdP pass
forall name. IEWrappedName name -> name
ieWrappedName IEWrappedName (IdP pass)
n
ieName (IEThingAll  _ (L _ n :: IEWrappedName (IdP pass)
n))        = IEWrappedName (IdP pass) -> IdP pass
forall name. IEWrappedName name -> name
ieWrappedName IEWrappedName (IdP pass)
n
ieName _ = String -> IdP pass
forall a. String -> a
panic "ieName failed pattern match!"

ieNames :: IE pass -> [IdP pass]
ieNames :: IE pass -> [IdP pass]
ieNames (IEVar       _ (L _ n :: IEWrappedName (IdP pass)
n)   )     = [IEWrappedName (IdP pass) -> IdP pass
forall name. IEWrappedName name -> name
ieWrappedName IEWrappedName (IdP pass)
n]
ieNames (IEThingAbs  _ (L _ n :: IEWrappedName (IdP pass)
n)   )     = [IEWrappedName (IdP pass) -> IdP pass
forall name. IEWrappedName name -> name
ieWrappedName IEWrappedName (IdP pass)
n]
ieNames (IEThingAll  _ (L _ n :: IEWrappedName (IdP pass)
n)   )     = [IEWrappedName (IdP pass) -> IdP pass
forall name. IEWrappedName name -> name
ieWrappedName IEWrappedName (IdP pass)
n]
ieNames (IEThingWith _ (L _ n :: IEWrappedName (IdP pass)
n) _ ns :: [GenLocated SrcSpan (IEWrappedName (IdP pass))]
ns _) = IEWrappedName (IdP pass) -> IdP pass
forall name. IEWrappedName name -> name
ieWrappedName IEWrappedName (IdP pass)
n
                                       IdP pass -> [IdP pass] -> [IdP pass]
forall a. a -> [a] -> [a]
: (GenLocated SrcSpan (IEWrappedName (IdP pass)) -> IdP pass)
-> [GenLocated SrcSpan (IEWrappedName (IdP pass))] -> [IdP pass]
forall a b. (a -> b) -> [a] -> [b]
map (IEWrappedName (IdP pass) -> IdP pass
forall name. IEWrappedName name -> name
ieWrappedName (IEWrappedName (IdP pass) -> IdP pass)
-> (GenLocated SrcSpan (IEWrappedName (IdP pass))
    -> IEWrappedName (IdP pass))
-> GenLocated SrcSpan (IEWrappedName (IdP pass))
-> IdP pass
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpan (IEWrappedName (IdP pass))
-> IEWrappedName (IdP pass)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc) [GenLocated SrcSpan (IEWrappedName (IdP pass))]
ns
ieNames (IEModuleContents {})     = []
ieNames (IEGroup          {})     = []
ieNames (IEDoc            {})     = []
ieNames (IEDocNamed       {})     = []
ieNames (XIE {}) = String -> [IdP pass]
forall a. String -> a
panic "ieNames"

ieWrappedName :: IEWrappedName name -> name
ieWrappedName :: IEWrappedName name -> name
ieWrappedName (IEName    (L _ n :: name
n)) = name
n
ieWrappedName (IEPattern (L _ n :: name
n)) = name
n
ieWrappedName (IEType    (L _ n :: name
n)) = name
n

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

ieLWrappedName :: LIEWrappedName name -> Located name
ieLWrappedName :: LIEWrappedName name -> Located name
ieLWrappedName (L l :: SrcSpan
l n :: IEWrappedName name
n) = SrcSpan -> name -> Located name
forall l e. l -> e -> GenLocated l e
L SrcSpan
l (IEWrappedName name -> name
forall name. IEWrappedName name -> name
ieWrappedName IEWrappedName name
n)

replaceWrappedName :: IEWrappedName name1 -> name2 -> IEWrappedName name2
replaceWrappedName :: IEWrappedName name1 -> name2 -> IEWrappedName name2
replaceWrappedName (IEName    (L l :: SrcSpan
l _)) n :: name2
n = Located name2 -> IEWrappedName name2
forall name. Located name -> IEWrappedName name
IEName    (SrcSpan -> name2 -> Located name2
forall l e. l -> e -> GenLocated l e
L SrcSpan
l name2
n)
replaceWrappedName (IEPattern (L l :: SrcSpan
l _)) n :: name2
n = Located name2 -> IEWrappedName name2
forall name. Located name -> IEWrappedName name
IEPattern (SrcSpan -> name2 -> Located name2
forall l e. l -> e -> GenLocated l e
L SrcSpan
l name2
n)
replaceWrappedName (IEType    (L l :: SrcSpan
l _)) n :: name2
n = Located name2 -> IEWrappedName name2
forall name. Located name -> IEWrappedName name
IEType    (SrcSpan -> name2 -> Located name2
forall l e. l -> e -> GenLocated l e
L SrcSpan
l name2
n)

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

instance (p ~ GhcPass pass,OutputableBndrId p) => Outputable (IE p) where
    ppr :: IE p -> SDoc
ppr (IEVar       _     var :: LIEWrappedName (IdP p)
var) = IEWrappedName (IdP (GhcPass pass)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr (LIEWrappedName (IdP (GhcPass pass))
-> SrcSpanLess (LIEWrappedName (IdP (GhcPass pass)))
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LIEWrappedName (IdP p)
LIEWrappedName (IdP (GhcPass pass))
var)
    ppr (IEThingAbs  _   thing :: LIEWrappedName (IdP p)
thing) = IEWrappedName (IdP (GhcPass pass)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr (LIEWrappedName (IdP (GhcPass pass))
-> SrcSpanLess (LIEWrappedName (IdP (GhcPass pass)))
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LIEWrappedName (IdP p)
LIEWrappedName (IdP (GhcPass pass))
thing)
    ppr (IEThingAll  _   thing :: LIEWrappedName (IdP p)
thing) = [SDoc] -> SDoc
hcat [IEWrappedName (IdP (GhcPass pass)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr (LIEWrappedName (IdP (GhcPass pass))
-> SrcSpanLess (LIEWrappedName (IdP (GhcPass pass)))
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LIEWrappedName (IdP p)
LIEWrappedName (IdP (GhcPass pass))
thing), String -> SDoc
text "(..)"]
    ppr (IEThingWith _ thing :: LIEWrappedName (IdP p)
thing wc :: IEWildcard
wc withs :: [LIEWrappedName (IdP p)]
withs flds :: [Located (FieldLbl (IdP p))]
flds)
        = IEWrappedName (IdP (GhcPass pass)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr (LIEWrappedName (IdP (GhcPass pass))
-> SrcSpanLess (LIEWrappedName (IdP (GhcPass pass)))
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LIEWrappedName (IdP p)
LIEWrappedName (IdP (GhcPass pass))
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]
++
                                              (Located (FieldLbl (IdP (GhcPass pass))) -> SDoc)
-> [Located (FieldLbl (IdP (GhcPass pass)))] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (FastString -> SDoc
forall a. Outputable a => a -> SDoc
ppr (FastString -> SDoc)
-> (Located (FieldLbl (IdP (GhcPass pass))) -> FastString)
-> Located (FieldLbl (IdP (GhcPass pass)))
-> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FieldLbl (IdP (GhcPass pass)) -> FastString
forall a. FieldLbl a -> FastString
flLabel (FieldLbl (IdP (GhcPass pass)) -> FastString)
-> (Located (FieldLbl (IdP (GhcPass pass)))
    -> FieldLbl (IdP (GhcPass pass)))
-> Located (FieldLbl (IdP (GhcPass pass)))
-> FastString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Located (FieldLbl (IdP (GhcPass pass)))
-> FieldLbl (IdP (GhcPass pass))
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc) [Located (FieldLbl (IdP p))]
[Located (FieldLbl (IdP (GhcPass pass)))]
flds)))
      where
        ppWiths :: [SDoc]
ppWiths =
          case IEWildcard
wc of
              NoIEWildcard ->
                (LIEWrappedName (IdP (GhcPass pass)) -> SDoc)
-> [LIEWrappedName (IdP (GhcPass pass))] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (IEWrappedName (IdP (GhcPass pass)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr (IEWrappedName (IdP (GhcPass pass)) -> SDoc)
-> (LIEWrappedName (IdP (GhcPass pass))
    -> IEWrappedName (IdP (GhcPass pass)))
-> LIEWrappedName (IdP (GhcPass pass))
-> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LIEWrappedName (IdP (GhcPass pass))
-> IEWrappedName (IdP (GhcPass pass))
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc) [LIEWrappedName (IdP p)]
[LIEWrappedName (IdP (GhcPass pass))]
withs
              IEWildcard pos :: Int
pos ->
                let (bs :: [SDoc]
bs, as :: [SDoc]
as) = Int -> [SDoc] -> ([SDoc], [SDoc])
forall a. Int -> [a] -> ([a], [a])
splitAt Int
pos ((LIEWrappedName (IdP (GhcPass pass)) -> SDoc)
-> [LIEWrappedName (IdP (GhcPass pass))] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (IEWrappedName (IdP (GhcPass pass)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr (IEWrappedName (IdP (GhcPass pass)) -> SDoc)
-> (LIEWrappedName (IdP (GhcPass pass))
    -> IEWrappedName (IdP (GhcPass pass)))
-> LIEWrappedName (IdP (GhcPass pass))
-> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LIEWrappedName (IdP (GhcPass pass))
-> IEWrappedName (IdP (GhcPass pass))
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc) [LIEWrappedName (IdP p)]
[LIEWrappedName (IdP (GhcPass pass))]
withs)
                in [SDoc]
bs [SDoc] -> [SDoc] -> [SDoc]
forall a. [a] -> [a] -> [a]
++ [String -> SDoc
text ".."] [SDoc] -> [SDoc] -> [SDoc]
forall a. [a] -> [a] -> [a]
++ [SDoc]
as
    ppr (IEModuleContents _ mod' :: Located ModuleName
mod')
        = String -> SDoc
text "module" SDoc -> SDoc -> SDoc
<+> Located ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr Located ModuleName
mod'
    ppr (IEGroup _ n :: Int
n _)           = String -> SDoc
text ("<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]
++ ">")
    ppr (IEDoc _ doc :: HsDocString
doc)             = HsDocString -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsDocString
doc
    ppr (IEDocNamed _ string :: String
string)     = String -> SDoc
text ("<IEDocNamed: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
string String -> String -> String
forall a. [a] -> [a] -> [a]
++ ">")
    ppr (XIE x :: XXIE p
x) = NoExt -> SDoc
forall a. Outputable a => a -> SDoc
ppr XXIE p
NoExt
x

instance (HasOccName name) => HasOccName (IEWrappedName name) where
  occName :: IEWrappedName name -> OccName
occName w :: 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 bs :: BindingSite
bs   w :: 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 w :: 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  w :: 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    n :: Located name
n) = name -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (Located name -> SrcSpanLess (Located name)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Located name
n)
  ppr (IEPattern n :: Located name
n) = String -> SDoc
text "pattern" SDoc -> SDoc -> SDoc
<+> name -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (Located name -> SrcSpanLess (Located name)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Located name
n)
  ppr (IEType    n :: Located name
n) = String -> SDoc
text "type"    SDoc -> SDoc -> SDoc
<+> name -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (Located name -> SrcSpanLess (Located name)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc Located name
n)

pprImpExp :: (HasOccName name, OutputableBndr name) => name -> SDoc
pprImpExp :: name -> SDoc
pprImpExp name :: 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 "type"
              | Bool
otherwise                   = SDoc
empty