{-# LANGUAGE CPP #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-} -- Wrinkle in Note [Trees That Grow]
                                      -- in module Language.Haskell.Syntax.Extension

{-# OPTIONS_GHC -Wno-orphans #-} -- Outputable

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


{-# OPTIONS_GHC -Wno-incomplete-record-updates #-}

-- | Abstract syntax of global declarations.
--
-- Definitions for: @SynDecl@ and @ConDecl@, @ClassDecl@,
-- @InstDecl@, @DefaultDecl@ and @ForeignDecl@.
module GHC.Hs.Decls (
  -- * Toplevel declarations
  HsDecl(..), LHsDecl, HsDataDefn(..), HsDeriving, LHsFunDep,
  HsDerivingClause(..), LHsDerivingClause, DerivClauseTys(..), LDerivClauseTys,
  NewOrData(..), newOrDataToFlavour,
  StandaloneKindSig(..), LStandaloneKindSig, standaloneKindSigName,

  -- ** Class or type declarations
  TyClDecl(..), LTyClDecl, DataDeclRn(..),
  TyClGroup(..),
  tyClGroupTyClDecls, tyClGroupInstDecls, tyClGroupRoleDecls,
  tyClGroupKindSigs,
  isClassDecl, isDataDecl, isSynDecl, tcdName,
  isFamilyDecl, isTypeFamilyDecl, isDataFamilyDecl,
  isOpenTypeFamilyInfo, isClosedTypeFamilyInfo,
  tyFamInstDeclName, tyFamInstDeclLName,
  countTyClDecls, pprTyClDeclFlavour,
  tyClDeclLName, tyClDeclTyVars,
  hsDeclHasCusk, famResultKindSignature,
  FamilyDecl(..), LFamilyDecl,
  FunDep(..),

  -- ** Instance declarations
  InstDecl(..), LInstDecl, FamilyInfo(..),
  TyFamInstDecl(..), LTyFamInstDecl, instDeclDataFamInsts,
  TyFamDefltDecl, LTyFamDefltDecl,
  DataFamInstDecl(..), LDataFamInstDecl,
  pprDataFamInstFlavour, pprTyFamInstDecl, pprHsFamInstLHS,
  FamEqn(..), TyFamInstEqn, LTyFamInstEqn, HsTyPats,
  LClsInstDecl, ClsInstDecl(..),

  -- ** Standalone deriving declarations
  DerivDecl(..), LDerivDecl,
  -- ** Deriving strategies
  DerivStrategy(..), LDerivStrategy,
  derivStrategyName, foldDerivStrategy, mapDerivStrategy,
  XViaStrategyPs(..),
  -- ** @RULE@ declarations
  LRuleDecls,RuleDecls(..),RuleDecl(..),LRuleDecl,HsRuleRn(..),
  HsRuleAnn(..),
  RuleBndr(..),LRuleBndr,
  collectRuleBndrSigTys,
  flattenRuleDecls, pprFullRuleName,
  -- ** @default@ declarations
  DefaultDecl(..), LDefaultDecl,
  -- ** Template haskell declaration splice
  SpliceExplicitFlag(..),
  SpliceDecl(..), LSpliceDecl,
  -- ** Foreign function interface declarations
  ForeignDecl(..), LForeignDecl, ForeignImport(..), ForeignExport(..),
  CImportSpec(..),
  -- ** Data-constructor declarations
  ConDecl(..), LConDecl,
  HsConDeclH98Details, HsConDeclGADTDetails(..), hsConDeclTheta,
  getConNames, getRecConArgs_maybe,
  -- ** Document comments
  DocDecl(..), LDocDecl, docDeclDoc,
  -- ** Deprecations
  WarnDecl(..),  LWarnDecl,
  WarnDecls(..), LWarnDecls,
  -- ** Annotations
  AnnDecl(..), LAnnDecl,
  AnnProvenance(..), annProvenanceName_maybe,
  -- ** Role annotations
  RoleAnnotDecl(..), LRoleAnnotDecl, roleAnnotDeclName,
  -- ** Injective type families
  FamilyResultSig(..), LFamilyResultSig, InjectivityAnn(..), LInjectivityAnn,
  resultVariableName, familyDeclLName, familyDeclName,

  -- * Grouping
  HsGroup(..),  emptyRdrGroup, emptyRnGroup, appendGroups, hsGroupInstDecls,
  hsGroupTopLevelFixitySigs,

  partitionBindsAndSigs,
    ) where

-- friends:
import GHC.Prelude

import Language.Haskell.Syntax.Decls

import {-# SOURCE #-} GHC.Hs.Expr ( pprExpr, pprSpliceDecl )
        -- Because Expr imports Decls via HsBracket

import GHC.Hs.Binds
import GHC.Hs.Type
import GHC.Hs.Doc
import GHC.Types.Basic
import GHC.Core.Coercion
import Language.Haskell.Syntax.Extension
import GHC.Hs.Extension
import GHC.Parser.Annotation
import GHC.Types.Name
import GHC.Types.Name.Set
import GHC.Types.Fixity

-- others:
import GHC.Utils.Outputable
import GHC.Utils.Panic
import GHC.Types.SrcLoc
import GHC.Types.SourceText
import GHC.Core.Type
import GHC.Types.ForeignCall

import GHC.Data.Bag
import GHC.Data.Maybe
import Data.Data (Data)

{-
************************************************************************
*                                                                      *
\subsection[HsDecl]{Declarations}
*                                                                      *
************************************************************************
-}

type instance XTyClD      (GhcPass _) = NoExtField
type instance XInstD      (GhcPass _) = NoExtField
type instance XDerivD     (GhcPass _) = NoExtField
type instance XValD       (GhcPass _) = NoExtField
type instance XSigD       (GhcPass _) = NoExtField
type instance XKindSigD   (GhcPass _) = NoExtField
type instance XDefD       (GhcPass _) = NoExtField
type instance XForD       (GhcPass _) = NoExtField
type instance XWarningD   (GhcPass _) = NoExtField
type instance XAnnD       (GhcPass _) = NoExtField
type instance XRuleD      (GhcPass _) = NoExtField
type instance XSpliceD    (GhcPass _) = NoExtField
type instance XDocD       (GhcPass _) = NoExtField
type instance XRoleAnnotD (GhcPass _) = NoExtField
type instance XXHsDecl    (GhcPass _) = NoExtCon

-- | Partition a list of HsDecls into function/pattern bindings, signatures,
-- type family declarations, type family instances, and documentation comments.
--
-- Panics when given a declaration that cannot be put into any of the output
-- groups.
--
-- The primary use of this function is to implement
-- 'GHC.Parser.PostProcess.cvBindsAndSigs'.
partitionBindsAndSigs
  :: [LHsDecl GhcPs]
  -> (LHsBinds GhcPs, [LSig GhcPs], [LFamilyDecl GhcPs],
      [LTyFamInstDecl GhcPs], [LDataFamInstDecl GhcPs], [LDocDecl GhcPs])
partitionBindsAndSigs :: [LHsDecl GhcPs]
-> (LHsBinds GhcPs, [LSig GhcPs], [LFamilyDecl GhcPs],
    [LTyFamInstDecl GhcPs], [LDataFamInstDecl GhcPs], [LDocDecl GhcPs])
partitionBindsAndSigs = forall {p} {l}.
Outputable (HsDecl p) =>
[GenLocated l (HsDecl p)]
-> (Bag (GenLocated l (HsBind p)), [GenLocated l (Sig p)],
    [GenLocated l (FamilyDecl p)], [GenLocated l (TyFamInstDecl p)],
    [GenLocated l (DataFamInstDecl p)], [GenLocated l DocDecl])
go
  where
    go :: [GenLocated l (HsDecl p)]
-> (Bag (GenLocated l (HsBind p)), [GenLocated l (Sig p)],
    [GenLocated l (FamilyDecl p)], [GenLocated l (TyFamInstDecl p)],
    [GenLocated l (DataFamInstDecl p)], [GenLocated l DocDecl])
go [] = (forall a. Bag a
emptyBag, [], [], [], [], [])
    go ((L l
l HsDecl p
decl) : [GenLocated l (HsDecl p)]
ds) =
      let (Bag (GenLocated l (HsBind p))
bs, [GenLocated l (Sig p)]
ss, [GenLocated l (FamilyDecl p)]
ts, [GenLocated l (TyFamInstDecl p)]
tfis, [GenLocated l (DataFamInstDecl p)]
dfis, [GenLocated l DocDecl]
docs) = [GenLocated l (HsDecl p)]
-> (Bag (GenLocated l (HsBind p)), [GenLocated l (Sig p)],
    [GenLocated l (FamilyDecl p)], [GenLocated l (TyFamInstDecl p)],
    [GenLocated l (DataFamInstDecl p)], [GenLocated l DocDecl])
go [GenLocated l (HsDecl p)]
ds in
      case HsDecl p
decl of
        ValD XValD p
_ HsBind p
b
          -> (forall l e. l -> e -> GenLocated l e
L l
l HsBind p
b forall a. a -> Bag a -> Bag a
`consBag` Bag (GenLocated l (HsBind p))
bs, [GenLocated l (Sig p)]
ss, [GenLocated l (FamilyDecl p)]
ts, [GenLocated l (TyFamInstDecl p)]
tfis, [GenLocated l (DataFamInstDecl p)]
dfis, [GenLocated l DocDecl]
docs)
        SigD XSigD p
_ Sig p
s
          -> (Bag (GenLocated l (HsBind p))
bs, forall l e. l -> e -> GenLocated l e
L l
l Sig p
s forall a. a -> [a] -> [a]
: [GenLocated l (Sig p)]
ss, [GenLocated l (FamilyDecl p)]
ts, [GenLocated l (TyFamInstDecl p)]
tfis, [GenLocated l (DataFamInstDecl p)]
dfis, [GenLocated l DocDecl]
docs)
        TyClD XTyClD p
_ (FamDecl XFamDecl p
_ FamilyDecl p
t)
          -> (Bag (GenLocated l (HsBind p))
bs, [GenLocated l (Sig p)]
ss, forall l e. l -> e -> GenLocated l e
L l
l FamilyDecl p
t forall a. a -> [a] -> [a]
: [GenLocated l (FamilyDecl p)]
ts, [GenLocated l (TyFamInstDecl p)]
tfis, [GenLocated l (DataFamInstDecl p)]
dfis, [GenLocated l DocDecl]
docs)
        InstD XInstD p
_ (TyFamInstD { tfid_inst :: forall pass. InstDecl pass -> TyFamInstDecl pass
tfid_inst = TyFamInstDecl p
tfi })
          -> (Bag (GenLocated l (HsBind p))
bs, [GenLocated l (Sig p)]
ss, [GenLocated l (FamilyDecl p)]
ts, forall l e. l -> e -> GenLocated l e
L l
l TyFamInstDecl p
tfi forall a. a -> [a] -> [a]
: [GenLocated l (TyFamInstDecl p)]
tfis, [GenLocated l (DataFamInstDecl p)]
dfis, [GenLocated l DocDecl]
docs)
        InstD XInstD p
_ (DataFamInstD { dfid_inst :: forall pass. InstDecl pass -> DataFamInstDecl pass
dfid_inst = DataFamInstDecl p
dfi })
          -> (Bag (GenLocated l (HsBind p))
bs, [GenLocated l (Sig p)]
ss, [GenLocated l (FamilyDecl p)]
ts, [GenLocated l (TyFamInstDecl p)]
tfis, forall l e. l -> e -> GenLocated l e
L l
l DataFamInstDecl p
dfi forall a. a -> [a] -> [a]
: [GenLocated l (DataFamInstDecl p)]
dfis, [GenLocated l DocDecl]
docs)
        DocD XDocD p
_ DocDecl
d
          -> (Bag (GenLocated l (HsBind p))
bs, [GenLocated l (Sig p)]
ss, [GenLocated l (FamilyDecl p)]
ts, [GenLocated l (TyFamInstDecl p)]
tfis, [GenLocated l (DataFamInstDecl p)]
dfis, forall l e. l -> e -> GenLocated l e
L l
l DocDecl
d forall a. a -> [a] -> [a]
: [GenLocated l DocDecl]
docs)
        HsDecl p
_ -> forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"partitionBindsAndSigs" (forall a. Outputable a => a -> SDoc
ppr HsDecl p
decl)

type instance XCHsGroup (GhcPass _) = NoExtField
type instance XXHsGroup (GhcPass _) = NoExtCon


emptyGroup, emptyRdrGroup, emptyRnGroup :: HsGroup (GhcPass p)
emptyRdrGroup :: forall (p :: Pass). HsGroup (GhcPass p)
emptyRdrGroup = forall (p :: Pass). HsGroup (GhcPass p)
emptyGroup { hs_valds :: HsValBinds (GhcPass p)
hs_valds = forall (a :: Pass) (b :: Pass).
HsValBindsLR (GhcPass a) (GhcPass b)
emptyValBindsIn }
emptyRnGroup :: forall (p :: Pass). HsGroup (GhcPass p)
emptyRnGroup  = forall (p :: Pass). HsGroup (GhcPass p)
emptyGroup { hs_valds :: HsValBinds (GhcPass p)
hs_valds = forall (a :: Pass) (b :: Pass).
HsValBindsLR (GhcPass a) (GhcPass b)
emptyValBindsOut }

emptyGroup :: forall (p :: Pass). HsGroup (GhcPass p)
emptyGroup = HsGroup { hs_ext :: XCHsGroup (GhcPass p)
hs_ext = NoExtField
noExtField,
                       hs_tyclds :: [TyClGroup (GhcPass p)]
hs_tyclds = [],
                       hs_derivds :: [LDerivDecl (GhcPass p)]
hs_derivds = [],
                       hs_fixds :: [LFixitySig (GhcPass p)]
hs_fixds = [], hs_defds :: [LDefaultDecl (GhcPass p)]
hs_defds = [], hs_annds :: [LAnnDecl (GhcPass p)]
hs_annds = [],
                       hs_fords :: [LForeignDecl (GhcPass p)]
hs_fords = [], hs_warnds :: [LWarnDecls (GhcPass p)]
hs_warnds = [], hs_ruleds :: [LRuleDecls (GhcPass p)]
hs_ruleds = [],
                       hs_valds :: HsValBinds (GhcPass p)
hs_valds = forall a. HasCallStack => String -> a
error String
"emptyGroup hs_valds: Can't happen",
                       hs_splcds :: [LSpliceDecl (GhcPass p)]
hs_splcds = [],
                       hs_docs :: [LDocDecl (GhcPass p)]
hs_docs = [] }

-- | The fixity signatures for each top-level declaration and class method
-- in an 'HsGroup'.
-- See Note [Top-level fixity signatures in an HsGroup]
hsGroupTopLevelFixitySigs :: HsGroup (GhcPass p) -> [LFixitySig (GhcPass p)]
hsGroupTopLevelFixitySigs :: forall (p :: Pass). HsGroup (GhcPass p) -> [LFixitySig (GhcPass p)]
hsGroupTopLevelFixitySigs (HsGroup{ hs_fixds :: forall p. HsGroup p -> [LFixitySig p]
hs_fixds = [LFixitySig (GhcPass p)]
fixds, hs_tyclds :: forall p. HsGroup p -> [TyClGroup p]
hs_tyclds = [TyClGroup (GhcPass p)]
tyclds }) =
    [LFixitySig (GhcPass p)]
fixds forall a. [a] -> [a] -> [a]
++ [GenLocated SrcSpanAnnA (FixitySig (GhcPass p))]
cls_fixds
  where
    cls_fixds :: [GenLocated SrcSpanAnnA (FixitySig (GhcPass p))]
cls_fixds = [ forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc FixitySig (GhcPass p)
sig
                | L SrcSpanAnnA
_ ClassDecl{tcdSigs :: forall pass. TyClDecl pass -> [LSig pass]
tcdSigs = [LSig (GhcPass p)]
sigs} <- forall pass. [TyClGroup pass] -> [LTyClDecl pass]
tyClGroupTyClDecls [TyClGroup (GhcPass p)]
tyclds
                , L SrcSpanAnnA
loc (FixSig XFixSig (GhcPass p)
_ FixitySig (GhcPass p)
sig) <- [LSig (GhcPass p)]
sigs
                ]

appendGroups :: HsGroup (GhcPass p) -> HsGroup (GhcPass p)
             -> HsGroup (GhcPass p)
appendGroups :: forall (p :: Pass).
HsGroup (GhcPass p) -> HsGroup (GhcPass p) -> HsGroup (GhcPass p)
appendGroups
    HsGroup {
        hs_valds :: forall p. HsGroup p -> HsValBinds p
hs_valds  = HsValBinds (GhcPass p)
val_groups1,
        hs_splcds :: forall p. HsGroup p -> [LSpliceDecl p]
hs_splcds = [LSpliceDecl (GhcPass p)]
spliceds1,
        hs_tyclds :: forall p. HsGroup p -> [TyClGroup p]
hs_tyclds = [TyClGroup (GhcPass p)]
tyclds1,
        hs_derivds :: forall p. HsGroup p -> [LDerivDecl p]
hs_derivds = [LDerivDecl (GhcPass p)]
derivds1,
        hs_fixds :: forall p. HsGroup p -> [LFixitySig p]
hs_fixds  = [LFixitySig (GhcPass p)]
fixds1,
        hs_defds :: forall p. HsGroup p -> [LDefaultDecl p]
hs_defds  = [LDefaultDecl (GhcPass p)]
defds1,
        hs_annds :: forall p. HsGroup p -> [LAnnDecl p]
hs_annds  = [LAnnDecl (GhcPass p)]
annds1,
        hs_fords :: forall p. HsGroup p -> [LForeignDecl p]
hs_fords  = [LForeignDecl (GhcPass p)]
fords1,
        hs_warnds :: forall p. HsGroup p -> [LWarnDecls p]
hs_warnds = [LWarnDecls (GhcPass p)]
warnds1,
        hs_ruleds :: forall p. HsGroup p -> [LRuleDecls p]
hs_ruleds = [LRuleDecls (GhcPass p)]
rulds1,
        hs_docs :: forall p. HsGroup p -> [LDocDecl p]
hs_docs   = [LDocDecl (GhcPass p)]
docs1 }
    HsGroup {
        hs_valds :: forall p. HsGroup p -> HsValBinds p
hs_valds  = HsValBinds (GhcPass p)
val_groups2,
        hs_splcds :: forall p. HsGroup p -> [LSpliceDecl p]
hs_splcds = [LSpliceDecl (GhcPass p)]
spliceds2,
        hs_tyclds :: forall p. HsGroup p -> [TyClGroup p]
hs_tyclds = [TyClGroup (GhcPass p)]
tyclds2,
        hs_derivds :: forall p. HsGroup p -> [LDerivDecl p]
hs_derivds = [LDerivDecl (GhcPass p)]
derivds2,
        hs_fixds :: forall p. HsGroup p -> [LFixitySig p]
hs_fixds  = [LFixitySig (GhcPass p)]
fixds2,
        hs_defds :: forall p. HsGroup p -> [LDefaultDecl p]
hs_defds  = [LDefaultDecl (GhcPass p)]
defds2,
        hs_annds :: forall p. HsGroup p -> [LAnnDecl p]
hs_annds  = [LAnnDecl (GhcPass p)]
annds2,
        hs_fords :: forall p. HsGroup p -> [LForeignDecl p]
hs_fords  = [LForeignDecl (GhcPass p)]
fords2,
        hs_warnds :: forall p. HsGroup p -> [LWarnDecls p]
hs_warnds = [LWarnDecls (GhcPass p)]
warnds2,
        hs_ruleds :: forall p. HsGroup p -> [LRuleDecls p]
hs_ruleds = [LRuleDecls (GhcPass p)]
rulds2,
        hs_docs :: forall p. HsGroup p -> [LDocDecl p]
hs_docs   = [LDocDecl (GhcPass p)]
docs2 }
  =
    HsGroup {
        hs_ext :: XCHsGroup (GhcPass p)
hs_ext    = NoExtField
noExtField,
        hs_valds :: HsValBinds (GhcPass p)
hs_valds  = HsValBinds (GhcPass p)
val_groups1 forall (a :: Pass).
HsValBinds (GhcPass a)
-> HsValBinds (GhcPass a) -> HsValBinds (GhcPass a)
`plusHsValBinds` HsValBinds (GhcPass p)
val_groups2,
        hs_splcds :: [LSpliceDecl (GhcPass p)]
hs_splcds = [LSpliceDecl (GhcPass p)]
spliceds1 forall a. [a] -> [a] -> [a]
++ [LSpliceDecl (GhcPass p)]
spliceds2,
        hs_tyclds :: [TyClGroup (GhcPass p)]
hs_tyclds = [TyClGroup (GhcPass p)]
tyclds1 forall a. [a] -> [a] -> [a]
++ [TyClGroup (GhcPass p)]
tyclds2,
        hs_derivds :: [LDerivDecl (GhcPass p)]
hs_derivds = [LDerivDecl (GhcPass p)]
derivds1 forall a. [a] -> [a] -> [a]
++ [LDerivDecl (GhcPass p)]
derivds2,
        hs_fixds :: [LFixitySig (GhcPass p)]
hs_fixds  = [LFixitySig (GhcPass p)]
fixds1 forall a. [a] -> [a] -> [a]
++ [LFixitySig (GhcPass p)]
fixds2,
        hs_annds :: [LAnnDecl (GhcPass p)]
hs_annds  = [LAnnDecl (GhcPass p)]
annds1 forall a. [a] -> [a] -> [a]
++ [LAnnDecl (GhcPass p)]
annds2,
        hs_defds :: [LDefaultDecl (GhcPass p)]
hs_defds  = [LDefaultDecl (GhcPass p)]
defds1 forall a. [a] -> [a] -> [a]
++ [LDefaultDecl (GhcPass p)]
defds2,
        hs_fords :: [LForeignDecl (GhcPass p)]
hs_fords  = [LForeignDecl (GhcPass p)]
fords1 forall a. [a] -> [a] -> [a]
++ [LForeignDecl (GhcPass p)]
fords2,
        hs_warnds :: [LWarnDecls (GhcPass p)]
hs_warnds = [LWarnDecls (GhcPass p)]
warnds1 forall a. [a] -> [a] -> [a]
++ [LWarnDecls (GhcPass p)]
warnds2,
        hs_ruleds :: [LRuleDecls (GhcPass p)]
hs_ruleds = [LRuleDecls (GhcPass p)]
rulds1 forall a. [a] -> [a] -> [a]
++ [LRuleDecls (GhcPass p)]
rulds2,
        hs_docs :: [LDocDecl (GhcPass p)]
hs_docs   = [LDocDecl (GhcPass p)]
docs1  forall a. [a] -> [a] -> [a]
++ [LDocDecl (GhcPass p)]
docs2 }

instance (OutputableBndrId p) => Outputable (HsDecl (GhcPass p)) where
    ppr :: HsDecl (GhcPass p) -> SDoc
ppr (TyClD XTyClD (GhcPass p)
_ TyClDecl (GhcPass p)
dcl)             = forall a. Outputable a => a -> SDoc
ppr TyClDecl (GhcPass p)
dcl
    ppr (ValD XValD (GhcPass p)
_ HsBind (GhcPass p)
binds)            = forall a. Outputable a => a -> SDoc
ppr HsBind (GhcPass p)
binds
    ppr (DefD XDefD (GhcPass p)
_ DefaultDecl (GhcPass p)
def)              = forall a. Outputable a => a -> SDoc
ppr DefaultDecl (GhcPass p)
def
    ppr (InstD XInstD (GhcPass p)
_ InstDecl (GhcPass p)
inst)            = forall a. Outputable a => a -> SDoc
ppr InstDecl (GhcPass p)
inst
    ppr (DerivD XDerivD (GhcPass p)
_ DerivDecl (GhcPass p)
deriv)          = forall a. Outputable a => a -> SDoc
ppr DerivDecl (GhcPass p)
deriv
    ppr (ForD XForD (GhcPass p)
_ ForeignDecl (GhcPass p)
fd)               = forall a. Outputable a => a -> SDoc
ppr ForeignDecl (GhcPass p)
fd
    ppr (SigD XSigD (GhcPass p)
_ Sig (GhcPass p)
sd)               = forall a. Outputable a => a -> SDoc
ppr Sig (GhcPass p)
sd
    ppr (KindSigD XKindSigD (GhcPass p)
_ StandaloneKindSig (GhcPass p)
ksd)          = forall a. Outputable a => a -> SDoc
ppr StandaloneKindSig (GhcPass p)
ksd
    ppr (RuleD XRuleD (GhcPass p)
_ RuleDecls (GhcPass p)
rd)              = forall a. Outputable a => a -> SDoc
ppr RuleDecls (GhcPass p)
rd
    ppr (WarningD XWarningD (GhcPass p)
_ WarnDecls (GhcPass p)
wd)           = forall a. Outputable a => a -> SDoc
ppr WarnDecls (GhcPass p)
wd
    ppr (AnnD XAnnD (GhcPass p)
_ AnnDecl (GhcPass p)
ad)               = forall a. Outputable a => a -> SDoc
ppr AnnDecl (GhcPass p)
ad
    ppr (SpliceD XSpliceD (GhcPass p)
_ SpliceDecl (GhcPass p)
dd)            = forall a. Outputable a => a -> SDoc
ppr SpliceDecl (GhcPass p)
dd
    ppr (DocD XDocD (GhcPass p)
_ DocDecl
doc)              = forall a. Outputable a => a -> SDoc
ppr DocDecl
doc
    ppr (RoleAnnotD XRoleAnnotD (GhcPass p)
_ RoleAnnotDecl (GhcPass p)
ra)         = forall a. Outputable a => a -> SDoc
ppr RoleAnnotDecl (GhcPass p)
ra

instance (OutputableBndrId p) => Outputable (HsGroup (GhcPass p)) where
    ppr :: HsGroup (GhcPass p) -> SDoc
ppr (HsGroup { hs_valds :: forall p. HsGroup p -> HsValBinds p
hs_valds  = HsValBinds (GhcPass p)
val_decls,
                   hs_tyclds :: forall p. HsGroup p -> [TyClGroup p]
hs_tyclds = [TyClGroup (GhcPass p)]
tycl_decls,
                   hs_derivds :: forall p. HsGroup p -> [LDerivDecl p]
hs_derivds = [LDerivDecl (GhcPass p)]
deriv_decls,
                   hs_fixds :: forall p. HsGroup p -> [LFixitySig p]
hs_fixds  = [LFixitySig (GhcPass p)]
fix_decls,
                   hs_warnds :: forall p. HsGroup p -> [LWarnDecls p]
hs_warnds = [LWarnDecls (GhcPass p)]
deprec_decls,
                   hs_annds :: forall p. HsGroup p -> [LAnnDecl p]
hs_annds  = [LAnnDecl (GhcPass p)]
ann_decls,
                   hs_fords :: forall p. HsGroup p -> [LForeignDecl p]
hs_fords  = [LForeignDecl (GhcPass p)]
foreign_decls,
                   hs_defds :: forall p. HsGroup p -> [LDefaultDecl p]
hs_defds  = [LDefaultDecl (GhcPass p)]
default_decls,
                   hs_ruleds :: forall p. HsGroup p -> [LRuleDecls p]
hs_ruleds = [LRuleDecls (GhcPass p)]
rule_decls })
        = SDoc -> [Maybe SDoc] -> SDoc
vcat_mb SDoc
empty
            [forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds [LFixitySig (GhcPass p)]
fix_decls, forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds [LDefaultDecl (GhcPass p)]
default_decls,
             forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds [LWarnDecls (GhcPass p)]
deprec_decls, forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds [LAnnDecl (GhcPass p)]
ann_decls,
             forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds [LRuleDecls (GhcPass p)]
rule_decls,
             if forall (a :: Pass) (b :: Pass).
HsValBindsLR (GhcPass a) (GhcPass b) -> Bool
isEmptyValBinds HsValBinds (GhcPass p)
val_decls
                then forall a. Maybe a
Nothing
                else forall a. a -> Maybe a
Just (forall a. Outputable a => a -> SDoc
ppr HsValBinds (GhcPass p)
val_decls),
             forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds (forall pass. [TyClGroup pass] -> [LRoleAnnotDecl pass]
tyClGroupRoleDecls [TyClGroup (GhcPass p)]
tycl_decls),
             forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds (forall pass. [TyClGroup pass] -> [LStandaloneKindSig pass]
tyClGroupKindSigs  [TyClGroup (GhcPass p)]
tycl_decls),
             forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds (forall pass. [TyClGroup pass] -> [LTyClDecl pass]
tyClGroupTyClDecls [TyClGroup (GhcPass p)]
tycl_decls),
             forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds (forall pass. [TyClGroup pass] -> [LInstDecl pass]
tyClGroupInstDecls [TyClGroup (GhcPass p)]
tycl_decls),
             forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds [LDerivDecl (GhcPass p)]
deriv_decls,
             forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds [LForeignDecl (GhcPass p)]
foreign_decls]
        where
          ppr_ds :: Outputable a => [a] -> Maybe SDoc
          ppr_ds :: forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds [] = forall a. Maybe a
Nothing
          ppr_ds [a]
ds = forall a. a -> Maybe a
Just ([SDoc] -> SDoc
vcat (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [a]
ds))

          vcat_mb :: SDoc -> [Maybe SDoc] -> SDoc
          -- Concatenate vertically with white-space between non-blanks
          vcat_mb :: SDoc -> [Maybe SDoc] -> SDoc
vcat_mb SDoc
_    []             = SDoc
empty
          vcat_mb SDoc
gap (Maybe SDoc
Nothing : [Maybe SDoc]
ds) = SDoc -> [Maybe SDoc] -> SDoc
vcat_mb SDoc
gap [Maybe SDoc]
ds
          vcat_mb SDoc
gap (Just SDoc
d  : [Maybe SDoc]
ds) = SDoc
gap SDoc -> SDoc -> SDoc
$$ SDoc
d SDoc -> SDoc -> SDoc
$$ SDoc -> [Maybe SDoc] -> SDoc
vcat_mb SDoc
blankLine [Maybe SDoc]
ds

type instance XSpliceDecl      (GhcPass _) = NoExtField
type instance XXSpliceDecl     (GhcPass _) = NoExtCon

instance OutputableBndrId p
       => Outputable (SpliceDecl (GhcPass p)) where
   ppr :: SpliceDecl (GhcPass p) -> SDoc
ppr (SpliceDecl XSpliceDecl (GhcPass p)
_ (L Anno (HsSplice (GhcPass p))
_ HsSplice (GhcPass p)
e) SpliceExplicitFlag
f) = forall (p :: Pass).
OutputableBndrId p =>
HsSplice (GhcPass p) -> SpliceExplicitFlag -> SDoc
pprSpliceDecl HsSplice (GhcPass p)
e SpliceExplicitFlag
f

{-
************************************************************************
*                                                                      *
            Type and class declarations
*                                                                      *
************************************************************************
-}

type instance XFamDecl      (GhcPass _) = NoExtField

type instance XSynDecl      GhcPs = EpAnn [AddEpAnn]
type instance XSynDecl      GhcRn = NameSet -- FVs
type instance XSynDecl      GhcTc = NameSet -- FVs

type instance XDataDecl     GhcPs = EpAnn [AddEpAnn]
type instance XDataDecl     GhcRn = DataDeclRn
type instance XDataDecl     GhcTc = DataDeclRn

type instance XClassDecl    GhcPs = (EpAnn [AddEpAnn], AnnSortKey, LayoutInfo)  -- See Note [Class LayoutInfo]
  -- TODO:AZ:tidy up AnnSortKey above
type instance XClassDecl    GhcRn = NameSet -- FVs
type instance XClassDecl    GhcTc = NameSet -- FVs

type instance XXTyClDecl    (GhcPass _) = NoExtCon

type instance XCTyFamInstDecl (GhcPass _) = EpAnn [AddEpAnn]
type instance XXTyFamInstDecl (GhcPass _) = NoExtCon

-- Dealing with names

tyFamInstDeclName :: Anno (IdGhcP p) ~ SrcSpanAnnN
                  => TyFamInstDecl (GhcPass p) -> IdP (GhcPass p)
tyFamInstDeclName :: forall (p :: Pass).
(Anno (IdGhcP p) ~ SrcSpanAnnN) =>
TyFamInstDecl (GhcPass p) -> IdP (GhcPass p)
tyFamInstDeclName = forall l e. GenLocated l e -> e
unLoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: Pass).
(Anno (IdGhcP p) ~ SrcSpanAnnN) =>
TyFamInstDecl (GhcPass p) -> LocatedN (IdP (GhcPass p))
tyFamInstDeclLName

tyFamInstDeclLName :: Anno (IdGhcP p) ~ SrcSpanAnnN
                   => TyFamInstDecl (GhcPass p) -> LocatedN (IdP (GhcPass p))
tyFamInstDeclLName :: forall (p :: Pass).
(Anno (IdGhcP p) ~ SrcSpanAnnN) =>
TyFamInstDecl (GhcPass p) -> LocatedN (IdP (GhcPass p))
tyFamInstDeclLName (TyFamInstDecl { tfid_eqn :: forall pass. TyFamInstDecl pass -> TyFamInstEqn pass
tfid_eqn = FamEqn { feqn_tycon :: forall pass rhs. FamEqn pass rhs -> LIdP pass
feqn_tycon = LIdP (GhcPass p)
ln }})
  = LIdP (GhcPass p)
ln

tyClDeclLName :: Anno (IdGhcP p) ~ SrcSpanAnnN
              => TyClDecl (GhcPass p) -> LocatedN (IdP (GhcPass p))
tyClDeclLName :: forall (p :: Pass).
(Anno (IdGhcP p) ~ SrcSpanAnnN) =>
TyClDecl (GhcPass p) -> LocatedN (IdP (GhcPass p))
tyClDeclLName (FamDecl { tcdFam :: forall pass. TyClDecl pass -> FamilyDecl pass
tcdFam = FamilyDecl (GhcPass p)
fd })     = forall (p :: Pass).
FamilyDecl (GhcPass p) -> XRec (GhcPass p) (IdP (GhcPass p))
familyDeclLName FamilyDecl (GhcPass p)
fd
tyClDeclLName (SynDecl { tcdLName :: forall pass. TyClDecl pass -> LIdP pass
tcdLName = LIdP (GhcPass p)
ln })   = LIdP (GhcPass p)
ln
tyClDeclLName (DataDecl { tcdLName :: forall pass. TyClDecl pass -> LIdP pass
tcdLName = LIdP (GhcPass p)
ln })  = LIdP (GhcPass p)
ln
tyClDeclLName (ClassDecl { tcdLName :: forall pass. TyClDecl pass -> LIdP pass
tcdLName = LIdP (GhcPass p)
ln }) = LIdP (GhcPass p)
ln

-- FIXME: tcdName is commonly used by both GHC and third-party tools, so it
-- needs to be polymorphic in the pass
tcdName :: Anno (IdGhcP p) ~ SrcSpanAnnN
        => TyClDecl (GhcPass p) -> IdP (GhcPass p)
tcdName :: forall (p :: Pass).
(Anno (IdGhcP p) ~ SrcSpanAnnN) =>
TyClDecl (GhcPass p) -> IdP (GhcPass p)
tcdName = forall l e. GenLocated l e -> e
unLoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: Pass).
(Anno (IdGhcP p) ~ SrcSpanAnnN) =>
TyClDecl (GhcPass p) -> LocatedN (IdP (GhcPass p))
tyClDeclLName

-- | Does this declaration have a complete, user-supplied kind signature?
-- See Note [CUSKs: complete user-supplied kind signatures]
hsDeclHasCusk :: TyClDecl GhcRn -> Bool
hsDeclHasCusk :: TyClDecl GhcRn -> Bool
hsDeclHasCusk (FamDecl { tcdFam :: forall pass. TyClDecl pass -> FamilyDecl pass
tcdFam =
    FamilyDecl { fdInfo :: forall pass. FamilyDecl pass -> FamilyInfo pass
fdInfo      = FamilyInfo GhcRn
fam_info
               , fdTyVars :: forall pass. FamilyDecl pass -> LHsQTyVars pass
fdTyVars    = LHsQTyVars GhcRn
tyvars
               , fdResultSig :: forall pass. FamilyDecl pass -> LFamilyResultSig pass
fdResultSig = L SrcSpan
_ FamilyResultSig GhcRn
resultSig } }) =
    case FamilyInfo GhcRn
fam_info of
      ClosedTypeFamily {} -> forall (p :: Pass). LHsQTyVars (GhcPass p) -> Bool
hsTvbAllKinded LHsQTyVars GhcRn
tyvars
                          Bool -> Bool -> Bool
&& forall a. Maybe a -> Bool
isJust (forall (p :: Pass).
FamilyResultSig (GhcPass p) -> Maybe (LHsKind (GhcPass p))
famResultKindSignature FamilyResultSig GhcRn
resultSig)
      FamilyInfo GhcRn
_ -> Bool
True -- Un-associated open type/data families have CUSKs
hsDeclHasCusk (SynDecl { tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
tcdTyVars = LHsQTyVars GhcRn
tyvars, tcdRhs :: forall pass. TyClDecl pass -> LHsType pass
tcdRhs = LHsType GhcRn
rhs })
  = forall (p :: Pass). LHsQTyVars (GhcPass p) -> Bool
hsTvbAllKinded LHsQTyVars GhcRn
tyvars Bool -> Bool -> Bool
&& forall a. Maybe a -> Bool
isJust (forall (p :: Pass).
LHsType (GhcPass p) -> Maybe (LHsType (GhcPass p))
hsTyKindSig LHsType GhcRn
rhs)
hsDeclHasCusk (DataDecl { tcdDExt :: forall pass. TyClDecl pass -> XDataDecl pass
tcdDExt = DataDeclRn { tcdDataCusk :: DataDeclRn -> Bool
tcdDataCusk = Bool
cusk }}) = Bool
cusk
hsDeclHasCusk (ClassDecl { tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
tcdTyVars = LHsQTyVars GhcRn
tyvars }) = forall (p :: Pass). LHsQTyVars (GhcPass p) -> Bool
hsTvbAllKinded LHsQTyVars GhcRn
tyvars

-- Pretty-printing TyClDecl
-- ~~~~~~~~~~~~~~~~~~~~~~~~

instance (OutputableBndrId p) => Outputable (TyClDecl (GhcPass p)) where

    ppr :: TyClDecl (GhcPass p) -> SDoc
ppr (FamDecl { tcdFam :: forall pass. TyClDecl pass -> FamilyDecl pass
tcdFam = FamilyDecl (GhcPass p)
decl }) = forall a. Outputable a => a -> SDoc
ppr FamilyDecl (GhcPass p)
decl
    ppr (SynDecl { tcdLName :: forall pass. TyClDecl pass -> LIdP pass
tcdLName = LIdP (GhcPass p)
ltycon, tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
tcdTyVars = LHsQTyVars (GhcPass p)
tyvars, tcdFixity :: forall pass. TyClDecl pass -> LexicalFixity
tcdFixity = LexicalFixity
fixity
                 , tcdRhs :: forall pass. TyClDecl pass -> LHsType pass
tcdRhs = LHsType (GhcPass p)
rhs })
      = SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"type" SDoc -> SDoc -> SDoc
<+>
              forall (p :: Pass).
OutputableBndrId p =>
XRec (GhcPass p) (IdP (GhcPass p))
-> LHsQTyVars (GhcPass p)
-> LexicalFixity
-> Maybe (LHsContext (GhcPass p))
-> SDoc
pp_vanilla_decl_head LIdP (GhcPass p)
ltycon LHsQTyVars (GhcPass p)
tyvars LexicalFixity
fixity forall a. Maybe a
Nothing SDoc -> SDoc -> SDoc
<+> SDoc
equals)
          Int
4 (forall a. Outputable a => a -> SDoc
ppr LHsType (GhcPass p)
rhs)

    ppr (DataDecl { tcdLName :: forall pass. TyClDecl pass -> LIdP pass
tcdLName = LIdP (GhcPass p)
ltycon, tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
tcdTyVars = LHsQTyVars (GhcPass p)
tyvars, tcdFixity :: forall pass. TyClDecl pass -> LexicalFixity
tcdFixity = LexicalFixity
fixity
                  , tcdDataDefn :: forall pass. TyClDecl pass -> HsDataDefn pass
tcdDataDefn = HsDataDefn (GhcPass p)
defn })
      = forall (p :: Pass).
OutputableBndrId p =>
(Maybe (LHsContext (GhcPass p)) -> SDoc)
-> HsDataDefn (GhcPass p) -> SDoc
pp_data_defn (forall (p :: Pass).
OutputableBndrId p =>
XRec (GhcPass p) (IdP (GhcPass p))
-> LHsQTyVars (GhcPass p)
-> LexicalFixity
-> Maybe (LHsContext (GhcPass p))
-> SDoc
pp_vanilla_decl_head LIdP (GhcPass p)
ltycon LHsQTyVars (GhcPass p)
tyvars LexicalFixity
fixity) HsDataDefn (GhcPass p)
defn

    ppr (ClassDecl {tcdCtxt :: forall pass. TyClDecl pass -> Maybe (LHsContext pass)
tcdCtxt = Maybe (LHsContext (GhcPass p))
context, tcdLName :: forall pass. TyClDecl pass -> LIdP pass
tcdLName = LIdP (GhcPass p)
lclas, tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
tcdTyVars = LHsQTyVars (GhcPass p)
tyvars,
                    tcdFixity :: forall pass. TyClDecl pass -> LexicalFixity
tcdFixity = LexicalFixity
fixity,
                    tcdFDs :: forall pass. TyClDecl pass -> [LHsFunDep pass]
tcdFDs  = [LHsFunDep (GhcPass p)]
fds,
                    tcdSigs :: forall pass. TyClDecl pass -> [LSig pass]
tcdSigs = [LSig (GhcPass p)]
sigs, tcdMeths :: forall pass. TyClDecl pass -> LHsBinds pass
tcdMeths = LHsBinds (GhcPass p)
methods,
                    tcdATs :: forall pass. TyClDecl pass -> [LFamilyDecl pass]
tcdATs = [LFamilyDecl (GhcPass p)]
ats, tcdATDefs :: forall pass. TyClDecl pass -> [LTyFamDefltDecl pass]
tcdATDefs = [LTyFamDefltDecl (GhcPass p)]
at_defs})
      | forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LSig (GhcPass p)]
sigs Bool -> Bool -> Bool
&& forall a. Bag a -> Bool
isEmptyBag LHsBinds (GhcPass p)
methods Bool -> Bool -> Bool
&& forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LFamilyDecl (GhcPass p)]
ats Bool -> Bool -> Bool
&& forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LTyFamDefltDecl (GhcPass p)]
at_defs -- No "where" part
      = SDoc
top_matter

      | Bool
otherwise       -- Laid out
      = [SDoc] -> SDoc
vcat [ SDoc
top_matter SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"where"
             , Int -> SDoc -> SDoc
nest Int
2 forall a b. (a -> b) -> a -> b
$ [SDoc] -> SDoc
pprDeclList (forall a b. (a -> b) -> [a] -> [b]
map (forall a. Outputable a => a -> SDoc
ppr forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l e. GenLocated l e -> e
unLoc) [LFamilyDecl (GhcPass p)]
ats forall a. [a] -> [a] -> [a]
++
                                     forall a b. (a -> b) -> [a] -> [b]
map (forall (p :: Pass).
OutputableBndrId p =>
TyFamDefltDecl (GhcPass p) -> SDoc
pprTyFamDefltDecl forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l e. GenLocated l e -> e
unLoc) [LTyFamDefltDecl (GhcPass p)]
at_defs forall a. [a] -> [a] -> [a]
++
                                     forall (idL :: Pass) (idR :: Pass) (id2 :: Pass).
(OutputableBndrId idL, OutputableBndrId idR,
 OutputableBndrId id2) =>
LHsBindsLR (GhcPass idL) (GhcPass idR)
-> [LSig (GhcPass id2)] -> [SDoc]
pprLHsBindsForUser LHsBinds (GhcPass p)
methods [LSig (GhcPass p)]
sigs) ]
      where
        top_matter :: SDoc
top_matter = String -> SDoc
text String
"class"
                    SDoc -> SDoc -> SDoc
<+> forall (p :: Pass).
OutputableBndrId p =>
XRec (GhcPass p) (IdP (GhcPass p))
-> LHsQTyVars (GhcPass p)
-> LexicalFixity
-> Maybe (LHsContext (GhcPass p))
-> SDoc
pp_vanilla_decl_head LIdP (GhcPass p)
lclas LHsQTyVars (GhcPass p)
tyvars LexicalFixity
fixity Maybe (LHsContext (GhcPass p))
context
                    SDoc -> SDoc -> SDoc
<+> forall (p :: Pass).
OutputableBndrId p =>
[FunDep (GhcPass p)] -> SDoc
pprFundeps (forall a b. (a -> b) -> [a] -> [b]
map forall l e. GenLocated l e -> e
unLoc [LHsFunDep (GhcPass p)]
fds)

instance OutputableBndrId p
       => Outputable (TyClGroup (GhcPass p)) where
  ppr :: TyClGroup (GhcPass p) -> SDoc
ppr (TyClGroup { group_tyclds :: forall pass. TyClGroup pass -> [LTyClDecl pass]
group_tyclds = [LTyClDecl (GhcPass p)]
tyclds
                 , group_roles :: forall pass. TyClGroup pass -> [LRoleAnnotDecl pass]
group_roles = [LRoleAnnotDecl (GhcPass p)]
roles
                 , group_kisigs :: forall pass. TyClGroup pass -> [LStandaloneKindSig pass]
group_kisigs = [LStandaloneKindSig (GhcPass p)]
kisigs
                 , group_instds :: forall pass. TyClGroup pass -> [LInstDecl pass]
group_instds = [LInstDecl (GhcPass p)]
instds
                 }
      )
    = SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"TyClGroup") Int
2 forall a b. (a -> b) -> a -> b
$
      forall a. Outputable a => a -> SDoc
ppr [LStandaloneKindSig (GhcPass p)]
kisigs SDoc -> SDoc -> SDoc
$$
      forall a. Outputable a => a -> SDoc
ppr [LTyClDecl (GhcPass p)]
tyclds SDoc -> SDoc -> SDoc
$$
      forall a. Outputable a => a -> SDoc
ppr [LRoleAnnotDecl (GhcPass p)]
roles SDoc -> SDoc -> SDoc
$$
      forall a. Outputable a => a -> SDoc
ppr [LInstDecl (GhcPass p)]
instds

pp_vanilla_decl_head :: (OutputableBndrId p)
   => XRec (GhcPass p) (IdP (GhcPass p))
   -> LHsQTyVars (GhcPass p)
   -> LexicalFixity
   -> Maybe (LHsContext (GhcPass p))
   -> SDoc
pp_vanilla_decl_head :: forall (p :: Pass).
OutputableBndrId p =>
XRec (GhcPass p) (IdP (GhcPass p))
-> LHsQTyVars (GhcPass p)
-> LexicalFixity
-> Maybe (LHsContext (GhcPass p))
-> SDoc
pp_vanilla_decl_head XRec (GhcPass p) (IdP (GhcPass p))
thing (HsQTvs { hsq_explicit :: forall pass. LHsQTyVars pass -> [LHsTyVarBndr () pass]
hsq_explicit = [LHsTyVarBndr () (GhcPass p)]
tyvars }) LexicalFixity
fixity Maybe (LHsContext (GhcPass p))
context
 = [SDoc] -> SDoc
hsep [forall (p :: Pass).
OutputableBndrId p =>
Maybe (LHsContext (GhcPass p)) -> SDoc
pprLHsContext Maybe (LHsContext (GhcPass p))
context, [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))] -> SDoc
pp_tyvars [LHsTyVarBndr () (GhcPass p)]
tyvars]
  where
    pp_tyvars :: [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))] -> SDoc
pp_tyvars (GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
varl:[GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))]
varsr)
      | LexicalFixity
fixity forall a. Eq a => a -> a -> Bool
== LexicalFixity
Infix Bool -> Bool -> Bool
&& forall (t :: * -> *) a. Foldable t => t a -> Int
length [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))]
varsr forall a. Ord a => a -> a -> Bool
> Int
1
         = [SDoc] -> SDoc
hsep [Char -> SDoc
char Char
'(',forall a. Outputable a => a -> SDoc
ppr (forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
varl), forall a. OutputableBndr a => a -> SDoc
pprInfixOcc (forall l e. GenLocated l e -> e
unLoc XRec (GhcPass p) (IdP (GhcPass p))
thing)
                , (forall a. Outputable a => a -> SDoc
pprforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall l e. GenLocated l e -> e
unLoc) (forall a. [a] -> a
head [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))]
varsr), Char -> SDoc
char Char
')'
                , [SDoc] -> SDoc
hsep (forall a b. (a -> b) -> [a] -> [b]
map (forall a. Outputable a => a -> SDoc
pprforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall l e. GenLocated l e -> e
unLoc) (forall a. [a] -> [a]
tail [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))]
varsr))]
      | LexicalFixity
fixity forall a. Eq a => a -> a -> Bool
== LexicalFixity
Infix
         = [SDoc] -> SDoc
hsep [forall a. Outputable a => a -> SDoc
ppr (forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
varl), forall a. OutputableBndr a => a -> SDoc
pprInfixOcc (forall l e. GenLocated l e -> e
unLoc XRec (GhcPass p) (IdP (GhcPass p))
thing)
         , [SDoc] -> SDoc
hsep (forall a b. (a -> b) -> [a] -> [b]
map (forall a. Outputable a => a -> SDoc
pprforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall l e. GenLocated l e -> e
unLoc) [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))]
varsr)]
      | Bool
otherwise = [SDoc] -> SDoc
hsep [ forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (forall l e. GenLocated l e -> e
unLoc XRec (GhcPass p) (IdP (GhcPass p))
thing)
                  , [SDoc] -> SDoc
hsep (forall a b. (a -> b) -> [a] -> [b]
map (forall a. Outputable a => a -> SDoc
pprforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall l e. GenLocated l e -> e
unLoc) (GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
varlforall a. a -> [a] -> [a]
:[GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))]
varsr))]
    pp_tyvars [] = forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (forall l e. GenLocated l e -> e
unLoc XRec (GhcPass p) (IdP (GhcPass p))
thing)

pprTyClDeclFlavour :: TyClDecl (GhcPass p) -> SDoc
pprTyClDeclFlavour :: forall (p :: Pass). TyClDecl (GhcPass p) -> SDoc
pprTyClDeclFlavour (ClassDecl {})   = String -> SDoc
text String
"class"
pprTyClDeclFlavour (SynDecl {})     = String -> SDoc
text String
"type"
pprTyClDeclFlavour (FamDecl { tcdFam :: forall pass. TyClDecl pass -> FamilyDecl pass
tcdFam = FamilyDecl { fdInfo :: forall pass. FamilyDecl pass -> FamilyInfo pass
fdInfo = FamilyInfo (GhcPass p)
info }})
  = forall pass. FamilyInfo pass -> SDoc
pprFlavour FamilyInfo (GhcPass p)
info SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"family"
pprTyClDeclFlavour (DataDecl { tcdDataDefn :: forall pass. TyClDecl pass -> HsDataDefn pass
tcdDataDefn = HsDataDefn { dd_ND :: forall pass. HsDataDefn pass -> NewOrData
dd_ND = NewOrData
nd } })
  = forall a. Outputable a => a -> SDoc
ppr NewOrData
nd

instance OutputableBndrId p => Outputable (FunDep (GhcPass p)) where
  ppr :: FunDep (GhcPass p) -> SDoc
ppr = forall (p :: Pass).
OutputableBndrId p =>
FunDep (GhcPass p) -> SDoc
pprFunDep

type instance XCFunDep    (GhcPass _) = EpAnn [AddEpAnn]
type instance XXFunDep    (GhcPass _) = NoExtCon

pprFundeps :: OutputableBndrId p => [FunDep (GhcPass p)] -> SDoc
pprFundeps :: forall (p :: Pass).
OutputableBndrId p =>
[FunDep (GhcPass p)] -> SDoc
pprFundeps []  = SDoc
empty
pprFundeps [FunDep (GhcPass p)]
fds = [SDoc] -> SDoc
hsep (SDoc
vbar forall a. a -> [a] -> [a]
: SDoc -> [SDoc] -> [SDoc]
punctuate SDoc
comma (forall a b. (a -> b) -> [a] -> [b]
map forall (p :: Pass).
OutputableBndrId p =>
FunDep (GhcPass p) -> SDoc
pprFunDep [FunDep (GhcPass p)]
fds))

pprFunDep :: OutputableBndrId p => FunDep (GhcPass p) -> SDoc
pprFunDep :: forall (p :: Pass).
OutputableBndrId p =>
FunDep (GhcPass p) -> SDoc
pprFunDep (FunDep XCFunDep (GhcPass p)
_ [LIdP (GhcPass p)]
us [LIdP (GhcPass p)]
vs) = [SDoc] -> SDoc
hsep [forall a. Outputable a => [a] -> SDoc
interppSP [LIdP (GhcPass p)]
us, SDoc
arrow, forall a. Outputable a => [a] -> SDoc
interppSP [LIdP (GhcPass p)]
vs]

{- *********************************************************************
*                                                                      *
                         TyClGroup
        Strongly connected components of
      type, class, instance, and role declarations
*                                                                      *
********************************************************************* -}

type instance XCTyClGroup (GhcPass _) = NoExtField
type instance XXTyClGroup (GhcPass _) = NoExtCon


{- *********************************************************************
*                                                                      *
               Data and type family declarations
*                                                                      *
********************************************************************* -}

type instance XNoSig            (GhcPass _) = NoExtField
type instance XCKindSig         (GhcPass _) = NoExtField

type instance XTyVarSig         (GhcPass _) = NoExtField
type instance XXFamilyResultSig (GhcPass _) = NoExtCon

type instance XCFamilyDecl    (GhcPass _) = EpAnn [AddEpAnn]
type instance XXFamilyDecl    (GhcPass _) = NoExtCon


------------- Functions over FamilyDecls -----------

familyDeclLName :: FamilyDecl (GhcPass p) -> XRec (GhcPass p) (IdP (GhcPass p))
familyDeclLName :: forall (p :: Pass).
FamilyDecl (GhcPass p) -> XRec (GhcPass p) (IdP (GhcPass p))
familyDeclLName (FamilyDecl { fdLName :: forall pass. FamilyDecl pass -> LIdP pass
fdLName = LIdP (GhcPass p)
n }) = LIdP (GhcPass p)
n

familyDeclName :: FamilyDecl (GhcPass p) -> IdP (GhcPass p)
familyDeclName :: forall (p :: Pass). FamilyDecl (GhcPass p) -> IdP (GhcPass p)
familyDeclName = forall l e. GenLocated l e -> e
unLoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: Pass).
FamilyDecl (GhcPass p) -> XRec (GhcPass p) (IdP (GhcPass p))
familyDeclLName

famResultKindSignature :: FamilyResultSig (GhcPass p) -> Maybe (LHsKind (GhcPass p))
famResultKindSignature :: forall (p :: Pass).
FamilyResultSig (GhcPass p) -> Maybe (LHsKind (GhcPass p))
famResultKindSignature (NoSig XNoSig (GhcPass p)
_) = forall a. Maybe a
Nothing
famResultKindSignature (KindSig XCKindSig (GhcPass p)
_ LHsKind (GhcPass p)
ki) = forall a. a -> Maybe a
Just LHsKind (GhcPass p)
ki
famResultKindSignature (TyVarSig XTyVarSig (GhcPass p)
_ LHsTyVarBndr () (GhcPass p)
bndr) =
  case forall l e. GenLocated l e -> e
unLoc LHsTyVarBndr () (GhcPass p)
bndr of
    UserTyVar XUserTyVar (GhcPass p)
_ ()
_ LIdP (GhcPass p)
_ -> forall a. Maybe a
Nothing
    KindedTyVar XKindedTyVar (GhcPass p)
_ ()
_ LIdP (GhcPass p)
_ LHsKind (GhcPass p)
ki -> forall a. a -> Maybe a
Just LHsKind (GhcPass p)
ki

-- | Maybe return name of the result type variable
resultVariableName :: FamilyResultSig (GhcPass a) -> Maybe (IdP (GhcPass a))
resultVariableName :: forall (a :: Pass).
FamilyResultSig (GhcPass a) -> Maybe (IdP (GhcPass a))
resultVariableName (TyVarSig XTyVarSig (GhcPass a)
_ LHsTyVarBndr () (GhcPass a)
sig) = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall flag (p :: Pass).
LHsTyVarBndr flag (GhcPass p) -> IdP (GhcPass p)
hsLTyVarName LHsTyVarBndr () (GhcPass a)
sig
resultVariableName FamilyResultSig (GhcPass a)
_                = forall a. Maybe a
Nothing

------------- Pretty printing FamilyDecls -----------

type instance XCInjectivityAnn  (GhcPass _) = EpAnn [AddEpAnn]
type instance XXInjectivityAnn  (GhcPass _) = NoExtCon

instance OutputableBndrId p
       => Outputable (FamilyDecl (GhcPass p)) where
  ppr :: FamilyDecl (GhcPass p) -> SDoc
ppr (FamilyDecl { fdInfo :: forall pass. FamilyDecl pass -> FamilyInfo pass
fdInfo = FamilyInfo (GhcPass p)
info, fdLName :: forall pass. FamilyDecl pass -> LIdP pass
fdLName = LIdP (GhcPass p)
ltycon
                  , fdTopLevel :: forall pass. FamilyDecl pass -> TopLevelFlag
fdTopLevel = TopLevelFlag
top_level
                  , fdTyVars :: forall pass. FamilyDecl pass -> LHsQTyVars pass
fdTyVars = LHsQTyVars (GhcPass p)
tyvars
                  , fdFixity :: forall pass. FamilyDecl pass -> LexicalFixity
fdFixity = LexicalFixity
fixity
                  , fdResultSig :: forall pass. FamilyDecl pass -> LFamilyResultSig pass
fdResultSig = L SrcSpan
_ FamilyResultSig (GhcPass p)
result
                  , fdInjectivityAnn :: forall pass. FamilyDecl pass -> Maybe (LInjectivityAnn pass)
fdInjectivityAnn = Maybe (LInjectivityAnn (GhcPass p))
mb_inj })
    = [SDoc] -> SDoc
vcat [ forall pass. FamilyInfo pass -> SDoc
pprFlavour FamilyInfo (GhcPass p)
info SDoc -> SDoc -> SDoc
<+> SDoc
pp_top_level SDoc -> SDoc -> SDoc
<+>
             forall (p :: Pass).
OutputableBndrId p =>
XRec (GhcPass p) (IdP (GhcPass p))
-> LHsQTyVars (GhcPass p)
-> LexicalFixity
-> Maybe (LHsContext (GhcPass p))
-> SDoc
pp_vanilla_decl_head LIdP (GhcPass p)
ltycon LHsQTyVars (GhcPass p)
tyvars LexicalFixity
fixity forall a. Maybe a
Nothing SDoc -> SDoc -> SDoc
<+>
             SDoc
pp_kind SDoc -> SDoc -> SDoc
<+> SDoc
pp_inj SDoc -> SDoc -> SDoc
<+> SDoc
pp_where
           , Int -> SDoc -> SDoc
nest Int
2 forall a b. (a -> b) -> a -> b
$ SDoc
pp_eqns ]
    where
      pp_top_level :: SDoc
pp_top_level = case TopLevelFlag
top_level of
                       TopLevelFlag
TopLevel    -> String -> SDoc
text String
"family"
                       TopLevelFlag
NotTopLevel -> SDoc
empty

      pp_kind :: SDoc
pp_kind = case FamilyResultSig (GhcPass p)
result of
                  NoSig    XNoSig (GhcPass p)
_         -> SDoc
empty
                  KindSig  XCKindSig (GhcPass p)
_ LHsKind (GhcPass p)
kind    -> SDoc
dcolon SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr LHsKind (GhcPass p)
kind
                  TyVarSig XTyVarSig (GhcPass p)
_ LHsTyVarBndr () (GhcPass p)
tv_bndr -> String -> SDoc
text String
"=" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr LHsTyVarBndr () (GhcPass p)
tv_bndr
      pp_inj :: SDoc
pp_inj = case Maybe (LInjectivityAnn (GhcPass p))
mb_inj of
                 Just (L SrcSpan
_ (InjectivityAnn XCInjectivityAnn (GhcPass p)
_ LIdP (GhcPass p)
lhs [LIdP (GhcPass p)]
rhs)) ->
                   [SDoc] -> SDoc
hsep [ SDoc
vbar, forall a. Outputable a => a -> SDoc
ppr LIdP (GhcPass p)
lhs, String -> SDoc
text String
"->", [SDoc] -> SDoc
hsep (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [LIdP (GhcPass p)]
rhs) ]
                 Maybe (LInjectivityAnn (GhcPass p))
Nothing -> SDoc
empty
      (SDoc
pp_where, SDoc
pp_eqns) = case FamilyInfo (GhcPass p)
info of
        ClosedTypeFamily Maybe [LTyFamInstEqn (GhcPass p)]
mb_eqns ->
          ( String -> SDoc
text String
"where"
          , case Maybe [LTyFamInstEqn (GhcPass p)]
mb_eqns of
              Maybe [LTyFamInstEqn (GhcPass p)]
Nothing   -> String -> SDoc
text String
".."
              Just [LTyFamInstEqn (GhcPass p)]
eqns -> [SDoc] -> SDoc
vcat forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (forall (p :: Pass).
OutputableBndrId p =>
TyFamInstEqn (GhcPass p) -> SDoc
ppr_fam_inst_eqn forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l e. GenLocated l e -> e
unLoc) [LTyFamInstEqn (GhcPass p)]
eqns )
        FamilyInfo (GhcPass p)
_ -> (SDoc
empty, SDoc
empty)



{- *********************************************************************
*                                                                      *
               Data types and data constructors
*                                                                      *
********************************************************************* -}

type instance XCHsDataDefn    (GhcPass _) = NoExtField
type instance XXHsDataDefn    (GhcPass _) = NoExtCon

type instance XCHsDerivingClause    (GhcPass _) = EpAnn [AddEpAnn]
type instance XXHsDerivingClause    (GhcPass _) = NoExtCon

instance OutputableBndrId p
       => Outputable (HsDerivingClause (GhcPass p)) where
  ppr :: HsDerivingClause (GhcPass p) -> SDoc
ppr (HsDerivingClause { deriv_clause_strategy :: forall pass. HsDerivingClause pass -> Maybe (LDerivStrategy pass)
deriv_clause_strategy = Maybe (LDerivStrategy (GhcPass p))
dcs
                        , deriv_clause_tys :: forall pass. HsDerivingClause pass -> LDerivClauseTys pass
deriv_clause_tys      = L SrcSpanAnnC
_ DerivClauseTys (GhcPass p)
dct })
    = [SDoc] -> SDoc
hsep [ String -> SDoc
text String
"deriving"
           , SDoc
pp_strat_before
           , forall a. Outputable a => a -> SDoc
ppr DerivClauseTys (GhcPass p)
dct
           , SDoc
pp_strat_after ]
      where
        -- @via@ is unique in that in comes /after/ the class being derived,
        -- so we must special-case it.
        (SDoc
pp_strat_before, SDoc
pp_strat_after) =
          case Maybe (LDerivStrategy (GhcPass p))
dcs of
            Just (L SrcSpan
_ via :: DerivStrategy (GhcPass p)
via@ViaStrategy{}) -> (SDoc
empty, forall a. Outputable a => a -> SDoc
ppr DerivStrategy (GhcPass p)
via)
            Maybe (LDerivStrategy (GhcPass p))
_                            -> (forall (p :: Pass).
OutputableBndrId p =>
Maybe (LDerivStrategy (GhcPass p)) -> SDoc
ppDerivStrategy Maybe (LDerivStrategy (GhcPass p))
dcs, SDoc
empty)

type instance XDctSingle (GhcPass _) = NoExtField
type instance XDctMulti  (GhcPass _) = NoExtField
type instance XXDerivClauseTys (GhcPass _) = NoExtCon

instance OutputableBndrId p => Outputable (DerivClauseTys (GhcPass p)) where
  ppr :: DerivClauseTys (GhcPass p) -> SDoc
ppr (DctSingle XDctSingle (GhcPass p)
_ LHsSigType (GhcPass p)
ty) = forall a. Outputable a => a -> SDoc
ppr LHsSigType (GhcPass p)
ty
  ppr (DctMulti XDctMulti (GhcPass p)
_ [LHsSigType (GhcPass p)]
tys) = SDoc -> SDoc
parens (forall a. Outputable a => [a] -> SDoc
interpp'SP [LHsSigType (GhcPass p)]
tys)

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

type instance XXStandaloneKindSig (GhcPass p) = NoExtCon

standaloneKindSigName :: StandaloneKindSig (GhcPass p) -> IdP (GhcPass p)
standaloneKindSigName :: forall (p :: Pass).
StandaloneKindSig (GhcPass p) -> IdP (GhcPass p)
standaloneKindSigName (StandaloneKindSig XStandaloneKindSig (GhcPass p)
_ LIdP (GhcPass p)
lname LHsSigType (GhcPass p)
_) = forall l e. GenLocated l e -> e
unLoc LIdP (GhcPass p)
lname

type instance XConDeclGADT (GhcPass _) = EpAnn [AddEpAnn]
type instance XConDeclH98  (GhcPass _) = EpAnn [AddEpAnn]

type instance XXConDecl (GhcPass _) = NoExtCon

getConNames :: ConDecl GhcRn -> [LocatedN Name]
getConNames :: ConDecl GhcRn -> [LocatedN Name]
getConNames ConDeclH98  {con_name :: forall pass. ConDecl pass -> LIdP pass
con_name  = LIdP GhcRn
name}  = [LIdP GhcRn
name]
getConNames ConDeclGADT {con_names :: forall pass. ConDecl pass -> [LIdP pass]
con_names = [LIdP GhcRn]
names} = [LIdP GhcRn]
names

-- | Return @'Just' fields@ if a data constructor declaration uses record
-- syntax (i.e., 'RecCon'), where @fields@ are the field selectors.
-- Otherwise, return 'Nothing'.
getRecConArgs_maybe :: ConDecl GhcRn -> Maybe (LocatedL [LConDeclField GhcRn])
getRecConArgs_maybe :: ConDecl GhcRn -> Maybe (LocatedL [LConDeclField GhcRn])
getRecConArgs_maybe (ConDeclH98{con_args :: forall pass. ConDecl pass -> HsConDeclH98Details pass
con_args = HsConDeclH98Details GhcRn
args}) = case HsConDeclH98Details GhcRn
args of
  PrefixCon{} -> forall a. Maybe a
Nothing
  RecCon XRec GhcRn [LConDeclField GhcRn]
flds -> forall a. a -> Maybe a
Just XRec GhcRn [LConDeclField GhcRn]
flds
  InfixCon{}  -> forall a. Maybe a
Nothing
getRecConArgs_maybe (ConDeclGADT{con_g_args :: forall pass. ConDecl pass -> HsConDeclGADTDetails pass
con_g_args = HsConDeclGADTDetails GhcRn
args}) = case HsConDeclGADTDetails GhcRn
args of
  PrefixConGADT{} -> forall a. Maybe a
Nothing
  RecConGADT XRec GhcRn [LConDeclField GhcRn]
flds -> forall a. a -> Maybe a
Just XRec GhcRn [LConDeclField GhcRn]
flds

hsConDeclTheta :: Maybe (LHsContext (GhcPass p)) -> [LHsType (GhcPass p)]
hsConDeclTheta :: forall (p :: Pass).
Maybe (LHsContext (GhcPass p)) -> [LHsType (GhcPass p)]
hsConDeclTheta Maybe (LHsContext (GhcPass p))
Nothing            = []
hsConDeclTheta (Just (L SrcSpanAnnC
_ [GenLocated SrcSpanAnnA (HsType (GhcPass p))]
theta)) = [GenLocated SrcSpanAnnA (HsType (GhcPass p))]
theta

pp_data_defn :: (OutputableBndrId p)
                  => (Maybe (LHsContext (GhcPass p)) -> SDoc)   -- Printing the header
                  -> HsDataDefn (GhcPass p)
                  -> SDoc
pp_data_defn :: forall (p :: Pass).
OutputableBndrId p =>
(Maybe (LHsContext (GhcPass p)) -> SDoc)
-> HsDataDefn (GhcPass p) -> SDoc
pp_data_defn Maybe (LHsContext (GhcPass p)) -> SDoc
pp_hdr (HsDataDefn { dd_ND :: forall pass. HsDataDefn pass -> NewOrData
dd_ND = NewOrData
new_or_data, dd_ctxt :: forall pass. HsDataDefn pass -> Maybe (LHsContext pass)
dd_ctxt = Maybe (LHsContext (GhcPass p))
context
                                , dd_cType :: forall pass. HsDataDefn pass -> Maybe (XRec pass CType)
dd_cType = Maybe (XRec (GhcPass p) CType)
mb_ct
                                , dd_kindSig :: forall pass. HsDataDefn pass -> Maybe (LHsKind pass)
dd_kindSig = Maybe (LHsKind (GhcPass p))
mb_sig
                                , dd_cons :: forall pass. HsDataDefn pass -> [LConDecl pass]
dd_cons = [LConDecl (GhcPass p)]
condecls, dd_derivs :: forall pass. HsDataDefn pass -> HsDeriving pass
dd_derivs = HsDeriving (GhcPass p)
derivings })
  | forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LConDecl (GhcPass p)]
condecls
  = forall a. Outputable a => a -> SDoc
ppr NewOrData
new_or_data SDoc -> SDoc -> SDoc
<+> SDoc
pp_ct SDoc -> SDoc -> SDoc
<+> Maybe (LHsContext (GhcPass p)) -> SDoc
pp_hdr Maybe (LHsContext (GhcPass p))
context SDoc -> SDoc -> SDoc
<+> SDoc
pp_sig
    SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => [a] -> SDoc
pp_derivings HsDeriving (GhcPass p)
derivings

  | Bool
otherwise
  = SDoc -> Int -> SDoc -> SDoc
hang (forall a. Outputable a => a -> SDoc
ppr NewOrData
new_or_data SDoc -> SDoc -> SDoc
<+> SDoc
pp_ct  SDoc -> SDoc -> SDoc
<+> Maybe (LHsContext (GhcPass p)) -> SDoc
pp_hdr Maybe (LHsContext (GhcPass p))
context SDoc -> SDoc -> SDoc
<+> SDoc
pp_sig)
       Int
2 (forall (p :: Pass).
OutputableBndrId p =>
[LConDecl (GhcPass p)] -> SDoc
pp_condecls [LConDecl (GhcPass p)]
condecls SDoc -> SDoc -> SDoc
$$ forall a. Outputable a => [a] -> SDoc
pp_derivings HsDeriving (GhcPass p)
derivings)
  where
    pp_ct :: SDoc
pp_ct = case Maybe (XRec (GhcPass p) CType)
mb_ct of
               Maybe (XRec (GhcPass p) CType)
Nothing   -> SDoc
empty
               Just XRec (GhcPass p) CType
ct -> forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) CType
ct
    pp_sig :: SDoc
pp_sig = case Maybe (LHsKind (GhcPass p))
mb_sig of
               Maybe (LHsKind (GhcPass p))
Nothing   -> SDoc
empty
               Just LHsKind (GhcPass p)
kind -> SDoc
dcolon SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr LHsKind (GhcPass p)
kind
    pp_derivings :: [a] -> SDoc
pp_derivings [a]
ds = [SDoc] -> SDoc
vcat (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [a]
ds)

instance OutputableBndrId p
       => Outputable (HsDataDefn (GhcPass p)) where
   ppr :: HsDataDefn (GhcPass p) -> SDoc
ppr HsDataDefn (GhcPass p)
d = forall (p :: Pass).
OutputableBndrId p =>
(Maybe (LHsContext (GhcPass p)) -> SDoc)
-> HsDataDefn (GhcPass p) -> SDoc
pp_data_defn (\Maybe (LHsContext (GhcPass p))
_ -> String -> SDoc
text String
"Naked HsDataDefn") HsDataDefn (GhcPass p)
d

instance OutputableBndrId p
       => Outputable (StandaloneKindSig (GhcPass p)) where
  ppr :: StandaloneKindSig (GhcPass p) -> SDoc
ppr (StandaloneKindSig XStandaloneKindSig (GhcPass p)
_ LIdP (GhcPass p)
v LHsSigType (GhcPass p)
ki)
    = String -> SDoc
text String
"type" SDoc -> SDoc -> SDoc
<+> forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (forall l e. GenLocated l e -> e
unLoc LIdP (GhcPass p)
v) SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"::" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr LHsSigType (GhcPass p)
ki

pp_condecls :: forall p. OutputableBndrId p => [LConDecl (GhcPass p)] -> SDoc
pp_condecls :: forall (p :: Pass).
OutputableBndrId p =>
[LConDecl (GhcPass p)] -> SDoc
pp_condecls [LConDecl (GhcPass p)]
cs
  | Bool
gadt_syntax                  -- In GADT syntax
  = SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"where") Int
2 ([SDoc] -> SDoc
vcat (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [LConDecl (GhcPass p)]
cs))
  | Bool
otherwise                    -- In H98 syntax
  = SDoc
equals SDoc -> SDoc -> SDoc
<+> [SDoc] -> SDoc
sep (SDoc -> [SDoc] -> [SDoc]
punctuate (String -> SDoc
text String
" |") (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [LConDecl (GhcPass p)]
cs))
  where
    gadt_syntax :: Bool
gadt_syntax = case [LConDecl (GhcPass p)]
cs of
      []                      -> Bool
False
      (L SrcSpanAnnA
_ ConDeclH98{}  : [LConDecl (GhcPass p)]
_) -> Bool
False
      (L SrcSpanAnnA
_ ConDeclGADT{} : [LConDecl (GhcPass p)]
_) -> Bool
True

instance (OutputableBndrId p) => Outputable (ConDecl (GhcPass p)) where
    ppr :: ConDecl (GhcPass p) -> SDoc
ppr = forall (p :: Pass).
OutputableBndrId p =>
ConDecl (GhcPass p) -> SDoc
pprConDecl

pprConDecl :: forall p. OutputableBndrId p => ConDecl (GhcPass p) -> SDoc
pprConDecl :: forall (p :: Pass).
OutputableBndrId p =>
ConDecl (GhcPass p) -> SDoc
pprConDecl (ConDeclH98 { con_name :: forall pass. ConDecl pass -> LIdP pass
con_name = L Anno (IdGhcP p)
_ IdGhcP p
con
                       , con_ex_tvs :: forall pass. ConDecl pass -> [LHsTyVarBndr Specificity pass]
con_ex_tvs = [LHsTyVarBndr Specificity (GhcPass p)]
ex_tvs
                       , con_mb_cxt :: forall pass. ConDecl pass -> Maybe (LHsContext pass)
con_mb_cxt = Maybe (LHsContext (GhcPass p))
mcxt
                       , con_args :: forall pass. ConDecl pass -> HsConDeclH98Details pass
con_args = HsConDeclH98Details (GhcPass p)
args
                       , con_doc :: forall pass. ConDecl pass -> Maybe LHsDocString
con_doc = Maybe LHsDocString
doc })
  = [SDoc] -> SDoc
sep [ Maybe LHsDocString -> SDoc
ppr_mbDoc Maybe LHsDocString
doc
        , forall (p :: Pass).
OutputableBndrId p =>
HsForAllTelescope (GhcPass p)
-> Maybe (LHsContext (GhcPass p)) -> SDoc
pprHsForAll (forall (p :: Pass).
EpAnnForallTy
-> [LHsTyVarBndr Specificity (GhcPass p)]
-> HsForAllTelescope (GhcPass p)
mkHsForAllInvisTele forall a. EpAnn a
noAnn [LHsTyVarBndr Specificity (GhcPass p)]
ex_tvs) Maybe (LHsContext (GhcPass p))
mcxt
        , HsConDetails
  Void
  (HsScaled
     (GhcPass p) (GenLocated SrcSpanAnnA (HsType (GhcPass p))))
  (GenLocated
     SrcSpanAnnL [GenLocated SrcSpanAnnA (ConDeclField (GhcPass p))])
-> SDoc
ppr_details HsConDeclH98Details (GhcPass p)
args ]
  where
    -- In ppr_details: let's not print the multiplicities (they are always 1, by
    -- definition) as they do not appear in an actual declaration.
    ppr_details :: HsConDetails
  Void
  (HsScaled
     (GhcPass p) (GenLocated SrcSpanAnnA (HsType (GhcPass p))))
  (GenLocated
     SrcSpanAnnL [GenLocated SrcSpanAnnA (ConDeclField (GhcPass p))])
-> SDoc
ppr_details (InfixCon HsScaled (GhcPass p) (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
t1 HsScaled (GhcPass p) (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
t2) = [SDoc] -> SDoc
hsep [forall a. Outputable a => a -> SDoc
ppr (forall pass a. HsScaled pass a -> a
hsScaledThing HsScaled (GhcPass p) (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
t1),
                                         forall a. OutputableBndr a => a -> SDoc
pprInfixOcc IdGhcP p
con,
                                         forall a. Outputable a => a -> SDoc
ppr (forall pass a. HsScaled pass a -> a
hsScaledThing HsScaled (GhcPass p) (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
t2)]
    ppr_details (PrefixCon [Void]
_ [HsScaled
   (GhcPass p) (GenLocated SrcSpanAnnA (HsType (GhcPass p)))]
tys) = [SDoc] -> SDoc
hsep (forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc IdGhcP p
con
                                    forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map (forall (p :: Pass).
OutputableBndrId p =>
HsType (GhcPass p) -> SDoc
pprHsType forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l e. GenLocated l e -> e
unLoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall pass a. HsScaled pass a -> a
hsScaledThing) [HsScaled
   (GhcPass p) (GenLocated SrcSpanAnnA (HsType (GhcPass p)))]
tys)
    ppr_details (RecCon GenLocated
  SrcSpanAnnL [GenLocated SrcSpanAnnA (ConDeclField (GhcPass p))]
fields)  = forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc IdGhcP p
con
                                 SDoc -> SDoc -> SDoc
<+> forall (p :: Pass).
OutputableBndrId p =>
[LConDeclField (GhcPass p)] -> SDoc
pprConDeclFields (forall l e. GenLocated l e -> e
unLoc GenLocated
  SrcSpanAnnL [GenLocated SrcSpanAnnA (ConDeclField (GhcPass p))]
fields)

pprConDecl (ConDeclGADT { con_names :: forall pass. ConDecl pass -> [LIdP pass]
con_names = [LIdP (GhcPass p)]
cons, con_bndrs :: forall pass. ConDecl pass -> XRec pass (HsOuterSigTyVarBndrs pass)
con_bndrs = L SrcSpanAnnA
_ HsOuterSigTyVarBndrs (GhcPass p)
outer_bndrs
                        , con_mb_cxt :: forall pass. ConDecl pass -> Maybe (LHsContext pass)
con_mb_cxt = Maybe (LHsContext (GhcPass p))
mcxt, con_g_args :: forall pass. ConDecl pass -> HsConDeclGADTDetails pass
con_g_args = HsConDeclGADTDetails (GhcPass p)
args
                        , con_res_ty :: forall pass. ConDecl pass -> LHsType pass
con_res_ty = LHsType (GhcPass p)
res_ty, con_doc :: forall pass. ConDecl pass -> Maybe LHsDocString
con_doc = Maybe LHsDocString
doc })
  = Maybe LHsDocString -> SDoc
ppr_mbDoc Maybe LHsDocString
doc SDoc -> SDoc -> SDoc
<+> forall a l. OutputableBndr a => [GenLocated l a] -> SDoc
ppr_con_names [LIdP (GhcPass p)]
cons SDoc -> SDoc -> SDoc
<+> SDoc
dcolon
    SDoc -> SDoc -> SDoc
<+> ([SDoc] -> SDoc
sep [forall (p :: Pass).
OutputableBndrId p =>
HsOuterSigTyVarBndrs (GhcPass p) -> SDoc
pprHsOuterSigTyVarBndrs HsOuterSigTyVarBndrs (GhcPass p)
outer_bndrs SDoc -> SDoc -> SDoc
<+> forall (p :: Pass).
OutputableBndrId p =>
Maybe (LHsContext (GhcPass p)) -> SDoc
pprLHsContext Maybe (LHsContext (GhcPass p))
mcxt,
              [SDoc] -> SDoc
ppr_arrow_chain (forall {p :: Pass}.
(OutputableBndr (IdGhcP p),
 OutputableBndr (IdGhcP (NoGhcTcPass p)), IsPass p,
 Outputable (GenLocated (Anno (IdGhcP p)) (IdGhcP p)),
 Outputable
   (GenLocated
      (Anno (IdGhcP (NoGhcTcPass p))) (IdGhcP (NoGhcTcPass p)))) =>
HsConDeclGADTDetails (GhcPass p) -> [SDoc]
get_args HsConDeclGADTDetails (GhcPass p)
args forall a. [a] -> [a] -> [a]
++ [forall a. Outputable a => a -> SDoc
ppr LHsType (GhcPass p)
res_ty]) ])
  where
    get_args :: HsConDeclGADTDetails (GhcPass p) -> [SDoc]
get_args (PrefixConGADT [HsScaled (GhcPass p) (XRec (GhcPass p) (BangType (GhcPass p)))]
args) = forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [HsScaled (GhcPass p) (XRec (GhcPass p) (BangType (GhcPass p)))]
args
    get_args (RecConGADT XRec (GhcPass p) [LConDeclField (GhcPass p)]
fields)  = [forall (p :: Pass).
OutputableBndrId p =>
[LConDeclField (GhcPass p)] -> SDoc
pprConDeclFields (forall l e. GenLocated l e -> e
unLoc XRec (GhcPass p) [LConDeclField (GhcPass p)]
fields)]

    ppr_arrow_chain :: [SDoc] -> SDoc
ppr_arrow_chain (SDoc
a:[SDoc]
as) = [SDoc] -> SDoc
sep (SDoc
a forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map (SDoc
arrow SDoc -> SDoc -> SDoc
<+>) [SDoc]
as)
    ppr_arrow_chain []     = SDoc
empty

ppr_con_names :: (OutputableBndr a) => [GenLocated l a] -> SDoc
ppr_con_names :: forall a l. OutputableBndr a => [GenLocated l a] -> SDoc
ppr_con_names = forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas (forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l e. GenLocated l e -> e
unLoc)

{-
************************************************************************
*                                                                      *
                Instance declarations
*                                                                      *
************************************************************************
-}

type instance XCFamEqn    (GhcPass _) r = EpAnn [AddEpAnn]
type instance XXFamEqn    (GhcPass _) r = NoExtCon

type instance Anno (FamEqn (GhcPass p) _) = SrcSpanAnnA

----------------- Class instances -------------

type instance XCClsInstDecl    GhcPs = (EpAnn [AddEpAnn], AnnSortKey) -- TODO:AZ:tidy up
type instance XCClsInstDecl    GhcRn = NoExtField
type instance XCClsInstDecl    GhcTc = NoExtField

type instance XXClsInstDecl    (GhcPass _) = NoExtCon

----------------- Instances of all kinds -------------

type instance XClsInstD     (GhcPass _) = NoExtField

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

type instance XTyFamInstD   GhcPs = NoExtField
type instance XTyFamInstD   GhcRn = NoExtField
type instance XTyFamInstD   GhcTc = NoExtField

type instance XXInstDecl    (GhcPass _) = NoExtCon

instance OutputableBndrId p
       => Outputable (TyFamInstDecl (GhcPass p)) where
  ppr :: TyFamInstDecl (GhcPass p) -> SDoc
ppr = forall (p :: Pass).
OutputableBndrId p =>
TopLevelFlag -> TyFamInstDecl (GhcPass p) -> SDoc
pprTyFamInstDecl TopLevelFlag
TopLevel

pprTyFamInstDecl :: (OutputableBndrId p)
                 => TopLevelFlag -> TyFamInstDecl (GhcPass p) -> SDoc
pprTyFamInstDecl :: forall (p :: Pass).
OutputableBndrId p =>
TopLevelFlag -> TyFamInstDecl (GhcPass p) -> SDoc
pprTyFamInstDecl TopLevelFlag
top_lvl (TyFamInstDecl { tfid_eqn :: forall pass. TyFamInstDecl pass -> TyFamInstEqn pass
tfid_eqn = TyFamInstEqn (GhcPass p)
eqn })
   = String -> SDoc
text String
"type" SDoc -> SDoc -> SDoc
<+> TopLevelFlag -> SDoc
ppr_instance_keyword TopLevelFlag
top_lvl SDoc -> SDoc -> SDoc
<+> forall (p :: Pass).
OutputableBndrId p =>
TyFamInstEqn (GhcPass p) -> SDoc
ppr_fam_inst_eqn TyFamInstEqn (GhcPass p)
eqn

ppr_instance_keyword :: TopLevelFlag -> SDoc
ppr_instance_keyword :: TopLevelFlag -> SDoc
ppr_instance_keyword TopLevelFlag
TopLevel    = String -> SDoc
text String
"instance"
ppr_instance_keyword TopLevelFlag
NotTopLevel = SDoc
empty

pprTyFamDefltDecl :: (OutputableBndrId p)
                  => TyFamDefltDecl (GhcPass p) -> SDoc
pprTyFamDefltDecl :: forall (p :: Pass).
OutputableBndrId p =>
TyFamDefltDecl (GhcPass p) -> SDoc
pprTyFamDefltDecl = forall (p :: Pass).
OutputableBndrId p =>
TopLevelFlag -> TyFamInstDecl (GhcPass p) -> SDoc
pprTyFamInstDecl TopLevelFlag
NotTopLevel

ppr_fam_inst_eqn :: (OutputableBndrId p)
                 => TyFamInstEqn (GhcPass p) -> SDoc
ppr_fam_inst_eqn :: forall (p :: Pass).
OutputableBndrId p =>
TyFamInstEqn (GhcPass p) -> SDoc
ppr_fam_inst_eqn (FamEqn { feqn_tycon :: forall pass rhs. FamEqn pass rhs -> LIdP pass
feqn_tycon  = L Anno (IdGhcP p)
_ IdGhcP p
tycon
                         , feqn_bndrs :: forall pass rhs. FamEqn pass rhs -> HsOuterFamEqnTyVarBndrs pass
feqn_bndrs  = HsOuterFamEqnTyVarBndrs (GhcPass p)
bndrs
                         , feqn_pats :: forall pass rhs. FamEqn pass rhs -> HsTyPats pass
feqn_pats   = HsTyPats (GhcPass p)
pats
                         , feqn_fixity :: forall pass rhs. FamEqn pass rhs -> LexicalFixity
feqn_fixity = LexicalFixity
fixity
                         , feqn_rhs :: forall pass rhs. FamEqn pass rhs -> rhs
feqn_rhs    = LHsType (GhcPass p)
rhs })
    = forall (p :: Pass).
OutputableBndrId p =>
IdP (GhcPass p)
-> HsOuterFamEqnTyVarBndrs (GhcPass p)
-> HsTyPats (GhcPass p)
-> LexicalFixity
-> Maybe (LHsContext (GhcPass p))
-> SDoc
pprHsFamInstLHS IdGhcP p
tycon HsOuterFamEqnTyVarBndrs (GhcPass p)
bndrs HsTyPats (GhcPass p)
pats LexicalFixity
fixity forall a. Maybe a
Nothing SDoc -> SDoc -> SDoc
<+> SDoc
equals SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr LHsType (GhcPass p)
rhs

instance OutputableBndrId p
       => Outputable (DataFamInstDecl (GhcPass p)) where
  ppr :: DataFamInstDecl (GhcPass p) -> SDoc
ppr = forall (p :: Pass).
OutputableBndrId p =>
TopLevelFlag -> DataFamInstDecl (GhcPass p) -> SDoc
pprDataFamInstDecl TopLevelFlag
TopLevel

pprDataFamInstDecl :: (OutputableBndrId p)
                   => TopLevelFlag -> DataFamInstDecl (GhcPass p) -> SDoc
pprDataFamInstDecl :: forall (p :: Pass).
OutputableBndrId p =>
TopLevelFlag -> DataFamInstDecl (GhcPass p) -> SDoc
pprDataFamInstDecl TopLevelFlag
top_lvl (DataFamInstDecl { dfid_eqn :: forall pass. DataFamInstDecl pass -> FamEqn pass (HsDataDefn pass)
dfid_eqn =
                            (FamEqn { feqn_tycon :: forall pass rhs. FamEqn pass rhs -> LIdP pass
feqn_tycon  = L Anno (IdGhcP p)
_ IdGhcP p
tycon
                                    , feqn_bndrs :: forall pass rhs. FamEqn pass rhs -> HsOuterFamEqnTyVarBndrs pass
feqn_bndrs  = HsOuterFamEqnTyVarBndrs (GhcPass p)
bndrs
                                    , feqn_pats :: forall pass rhs. FamEqn pass rhs -> HsTyPats pass
feqn_pats   = HsTyPats (GhcPass p)
pats
                                    , feqn_fixity :: forall pass rhs. FamEqn pass rhs -> LexicalFixity
feqn_fixity = LexicalFixity
fixity
                                    , feqn_rhs :: forall pass rhs. FamEqn pass rhs -> rhs
feqn_rhs    = HsDataDefn (GhcPass p)
defn })})
  = forall (p :: Pass).
OutputableBndrId p =>
(Maybe (LHsContext (GhcPass p)) -> SDoc)
-> HsDataDefn (GhcPass p) -> SDoc
pp_data_defn Maybe
  (GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass p))])
-> SDoc
pp_hdr HsDataDefn (GhcPass p)
defn
  where
    pp_hdr :: Maybe
  (GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass p))])
-> SDoc
pp_hdr Maybe
  (GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass p))])
mctxt = TopLevelFlag -> SDoc
ppr_instance_keyword TopLevelFlag
top_lvl
              SDoc -> SDoc -> SDoc
<+> forall (p :: Pass).
OutputableBndrId p =>
IdP (GhcPass p)
-> HsOuterFamEqnTyVarBndrs (GhcPass p)
-> HsTyPats (GhcPass p)
-> LexicalFixity
-> Maybe (LHsContext (GhcPass p))
-> SDoc
pprHsFamInstLHS IdGhcP p
tycon HsOuterFamEqnTyVarBndrs (GhcPass p)
bndrs HsTyPats (GhcPass p)
pats LexicalFixity
fixity Maybe
  (GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass p))])
mctxt
                  -- pp_data_defn pretty-prints the kind sig. See #14817.

pprDataFamInstFlavour :: DataFamInstDecl (GhcPass p) -> SDoc
pprDataFamInstFlavour :: forall (p :: Pass). DataFamInstDecl (GhcPass p) -> SDoc
pprDataFamInstFlavour (DataFamInstDecl { dfid_eqn :: forall pass. DataFamInstDecl pass -> FamEqn pass (HsDataDefn pass)
dfid_eqn =
                       (FamEqn { feqn_rhs :: forall pass rhs. FamEqn pass rhs -> rhs
feqn_rhs = HsDataDefn { dd_ND :: forall pass. HsDataDefn pass -> NewOrData
dd_ND = NewOrData
nd }})})
  = forall a. Outputable a => a -> SDoc
ppr NewOrData
nd

pprHsFamInstLHS :: (OutputableBndrId p)
   => IdP (GhcPass p)
   -> HsOuterFamEqnTyVarBndrs (GhcPass p)
   -> HsTyPats (GhcPass p)
   -> LexicalFixity
   -> Maybe (LHsContext (GhcPass p))
   -> SDoc
pprHsFamInstLHS :: forall (p :: Pass).
OutputableBndrId p =>
IdP (GhcPass p)
-> HsOuterFamEqnTyVarBndrs (GhcPass p)
-> HsTyPats (GhcPass p)
-> LexicalFixity
-> Maybe (LHsContext (GhcPass p))
-> SDoc
pprHsFamInstLHS IdP (GhcPass p)
thing HsOuterFamEqnTyVarBndrs (GhcPass p)
bndrs HsTyPats (GhcPass p)
typats LexicalFixity
fixity Maybe (LHsContext (GhcPass p))
mb_ctxt
   = [SDoc] -> SDoc
hsep [ forall (p :: Pass).
OutputableBndrId p =>
HsOuterFamEqnTyVarBndrs (GhcPass p) -> SDoc
pprHsOuterFamEqnTyVarBndrs HsOuterFamEqnTyVarBndrs (GhcPass p)
bndrs
          , forall (p :: Pass).
OutputableBndrId p =>
Maybe (LHsContext (GhcPass p)) -> SDoc
pprLHsContext Maybe (LHsContext (GhcPass p))
mb_ctxt
          , [HsArg
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))]
-> SDoc
pp_pats HsTyPats (GhcPass p)
typats ]
   where
     pp_pats :: [HsArg
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))]
-> SDoc
pp_pats (HsArg
  (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
  (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
patl:HsArg
  (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
  (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
patr:[HsArg
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))]
pats)
       | LexicalFixity
Infix <- LexicalFixity
fixity
       = let pp_op_app :: SDoc
pp_op_app = [SDoc] -> SDoc
hsep [ forall a. Outputable a => a -> SDoc
ppr HsArg
  (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
  (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
patl, forall a. OutputableBndr a => a -> SDoc
pprInfixOcc IdP (GhcPass p)
thing, forall a. Outputable a => a -> SDoc
ppr HsArg
  (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
  (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
patr ] in
         case [HsArg
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))]
pats of
           [] -> SDoc
pp_op_app
           [HsArg
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))]
_  -> [SDoc] -> SDoc
hsep (SDoc -> SDoc
parens SDoc
pp_op_app forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [HsArg
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))]
pats)

     pp_pats [HsArg
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))]
pats = [SDoc] -> SDoc
hsep [ forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc IdP (GhcPass p)
thing
                         , [SDoc] -> SDoc
hsep (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [HsArg
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))]
pats)]

instance OutputableBndrId p
       => Outputable (ClsInstDecl (GhcPass p)) where
    ppr :: ClsInstDecl (GhcPass p) -> SDoc
ppr (ClsInstDecl { cid_poly_ty :: forall pass. ClsInstDecl pass -> LHsSigType pass
cid_poly_ty = LHsSigType (GhcPass p)
inst_ty, cid_binds :: forall pass. ClsInstDecl pass -> LHsBinds pass
cid_binds = LHsBinds (GhcPass p)
binds
                     , cid_sigs :: forall pass. ClsInstDecl pass -> [LSig pass]
cid_sigs = [LSig (GhcPass p)]
sigs, cid_tyfam_insts :: forall pass. ClsInstDecl pass -> [LTyFamInstDecl pass]
cid_tyfam_insts = [LTyFamInstDecl (GhcPass p)]
ats
                     , cid_overlap_mode :: forall pass. ClsInstDecl pass -> Maybe (XRec pass OverlapMode)
cid_overlap_mode = Maybe (XRec (GhcPass p) OverlapMode)
mbOverlap
                     , cid_datafam_insts :: forall pass. ClsInstDecl pass -> [LDataFamInstDecl pass]
cid_datafam_insts = [LDataFamInstDecl (GhcPass p)]
adts })
      | forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LSig (GhcPass p)]
sigs, forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LTyFamInstDecl (GhcPass p)]
ats, forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LDataFamInstDecl (GhcPass p)]
adts, forall a. Bag a -> Bool
isEmptyBag LHsBinds (GhcPass p)
binds  -- No "where" part
      = SDoc
top_matter

      | Bool
otherwise       -- Laid out
      = [SDoc] -> SDoc
vcat [ SDoc
top_matter SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"where"
             , Int -> SDoc -> SDoc
nest Int
2 forall a b. (a -> b) -> a -> b
$ [SDoc] -> SDoc
pprDeclList forall a b. (a -> b) -> a -> b
$
               forall a b. (a -> b) -> [a] -> [b]
map (forall (p :: Pass).
OutputableBndrId p =>
TopLevelFlag -> TyFamInstDecl (GhcPass p) -> SDoc
pprTyFamInstDecl TopLevelFlag
NotTopLevel forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l e. GenLocated l e -> e
unLoc)   [LTyFamInstDecl (GhcPass p)]
ats forall a. [a] -> [a] -> [a]
++
               forall a b. (a -> b) -> [a] -> [b]
map (forall (p :: Pass).
OutputableBndrId p =>
TopLevelFlag -> DataFamInstDecl (GhcPass p) -> SDoc
pprDataFamInstDecl TopLevelFlag
NotTopLevel forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l e. GenLocated l e -> e
unLoc) [LDataFamInstDecl (GhcPass p)]
adts forall a. [a] -> [a] -> [a]
++
               forall (idL :: Pass) (idR :: Pass) (id2 :: Pass).
(OutputableBndrId idL, OutputableBndrId idR,
 OutputableBndrId id2) =>
LHsBindsLR (GhcPass idL) (GhcPass idR)
-> [LSig (GhcPass id2)] -> [SDoc]
pprLHsBindsForUser LHsBinds (GhcPass p)
binds [LSig (GhcPass p)]
sigs ]
      where
        top_matter :: SDoc
top_matter = String -> SDoc
text String
"instance" SDoc -> SDoc -> SDoc
<+> Maybe (LocatedP OverlapMode) -> SDoc
ppOverlapPragma Maybe (XRec (GhcPass p) OverlapMode)
mbOverlap
                                             SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr LHsSigType (GhcPass p)
inst_ty

ppDerivStrategy :: OutputableBndrId p
                => Maybe (LDerivStrategy (GhcPass p)) -> SDoc
ppDerivStrategy :: forall (p :: Pass).
OutputableBndrId p =>
Maybe (LDerivStrategy (GhcPass p)) -> SDoc
ppDerivStrategy Maybe (LDerivStrategy (GhcPass p))
mb =
  case Maybe (LDerivStrategy (GhcPass p))
mb of
    Maybe (LDerivStrategy (GhcPass p))
Nothing       -> SDoc
empty
    Just (L SrcSpan
_ DerivStrategy (GhcPass p)
ds) -> forall a. Outputable a => a -> SDoc
ppr DerivStrategy (GhcPass p)
ds

ppOverlapPragma :: Maybe (LocatedP OverlapMode) -> SDoc
ppOverlapPragma :: Maybe (LocatedP OverlapMode) -> SDoc
ppOverlapPragma Maybe (LocatedP OverlapMode)
mb =
  case Maybe (LocatedP OverlapMode)
mb of
    Maybe (LocatedP OverlapMode)
Nothing           -> SDoc
empty
    Just (L SrcSpanAnnP
_ (NoOverlap SourceText
s))    -> SourceText -> String -> SDoc
maybe_stext SourceText
s String
"{-# NO_OVERLAP #-}"
    Just (L SrcSpanAnnP
_ (Overlappable SourceText
s)) -> SourceText -> String -> SDoc
maybe_stext SourceText
s String
"{-# OVERLAPPABLE #-}"
    Just (L SrcSpanAnnP
_ (Overlapping SourceText
s))  -> SourceText -> String -> SDoc
maybe_stext SourceText
s String
"{-# OVERLAPPING #-}"
    Just (L SrcSpanAnnP
_ (Overlaps SourceText
s))     -> SourceText -> String -> SDoc
maybe_stext SourceText
s String
"{-# OVERLAPS #-}"
    Just (L SrcSpanAnnP
_ (Incoherent SourceText
s))   -> SourceText -> String -> SDoc
maybe_stext SourceText
s String
"{-# INCOHERENT #-}"
  where
    maybe_stext :: SourceText -> String -> SDoc
maybe_stext SourceText
NoSourceText     String
alt = String -> SDoc
text String
alt
    maybe_stext (SourceText String
src) String
_   = String -> SDoc
text String
src SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"#-}"


instance (OutputableBndrId p) => Outputable (InstDecl (GhcPass p)) where
    ppr :: InstDecl (GhcPass p) -> SDoc
ppr (ClsInstD     { cid_inst :: forall pass. InstDecl pass -> ClsInstDecl pass
cid_inst  = ClsInstDecl (GhcPass p)
decl }) = forall a. Outputable a => a -> SDoc
ppr ClsInstDecl (GhcPass p)
decl
    ppr (TyFamInstD   { tfid_inst :: forall pass. InstDecl pass -> TyFamInstDecl pass
tfid_inst = TyFamInstDecl (GhcPass p)
decl }) = forall a. Outputable a => a -> SDoc
ppr TyFamInstDecl (GhcPass p)
decl
    ppr (DataFamInstD { dfid_inst :: forall pass. InstDecl pass -> DataFamInstDecl pass
dfid_inst = DataFamInstDecl (GhcPass p)
decl }) = forall a. Outputable a => a -> SDoc
ppr DataFamInstDecl (GhcPass p)
decl

-- Extract the declarations of associated data types from an instance

instDeclDataFamInsts :: [LInstDecl (GhcPass p)] -> [DataFamInstDecl (GhcPass p)]
instDeclDataFamInsts :: forall (p :: Pass).
[LInstDecl (GhcPass p)] -> [DataFamInstDecl (GhcPass p)]
instDeclDataFamInsts [LInstDecl (GhcPass p)]
inst_decls
  = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap forall (p :: Pass).
LInstDecl (GhcPass p) -> [DataFamInstDecl (GhcPass p)]
do_one [LInstDecl (GhcPass p)]
inst_decls
  where
    do_one :: LInstDecl (GhcPass p) -> [DataFamInstDecl (GhcPass p)]
    do_one :: forall (p :: Pass).
LInstDecl (GhcPass p) -> [DataFamInstDecl (GhcPass p)]
do_one (L SrcSpanAnnA
_ (ClsInstD { cid_inst :: forall pass. InstDecl pass -> ClsInstDecl pass
cid_inst = ClsInstDecl { cid_datafam_insts :: forall pass. ClsInstDecl pass -> [LDataFamInstDecl pass]
cid_datafam_insts = [LDataFamInstDecl (GhcPass p)]
fam_insts } }))
      = forall a b. (a -> b) -> [a] -> [b]
map forall l e. GenLocated l e -> e
unLoc [LDataFamInstDecl (GhcPass p)]
fam_insts
    do_one (L SrcSpanAnnA
_ (DataFamInstD { dfid_inst :: forall pass. InstDecl pass -> DataFamInstDecl pass
dfid_inst = DataFamInstDecl (GhcPass p)
fam_inst }))      = [DataFamInstDecl (GhcPass p)
fam_inst]
    do_one (L SrcSpanAnnA
_ (TyFamInstD {}))                              = []

{-
************************************************************************
*                                                                      *
\subsection[DerivDecl]{A stand-alone instance deriving declaration}
*                                                                      *
************************************************************************
-}

type instance XCDerivDecl    (GhcPass _) = EpAnn [AddEpAnn]
type instance XXDerivDecl    (GhcPass _) = NoExtCon

type instance Anno OverlapMode = SrcSpanAnnP

instance OutputableBndrId p
       => Outputable (DerivDecl (GhcPass p)) where
    ppr :: DerivDecl (GhcPass p) -> SDoc
ppr (DerivDecl { deriv_type :: forall pass. DerivDecl pass -> LHsSigWcType pass
deriv_type = LHsSigWcType (GhcPass p)
ty
                   , deriv_strategy :: forall pass. DerivDecl pass -> Maybe (LDerivStrategy pass)
deriv_strategy = Maybe (LDerivStrategy (GhcPass p))
ds
                   , deriv_overlap_mode :: forall pass. DerivDecl pass -> Maybe (XRec pass OverlapMode)
deriv_overlap_mode = Maybe (XRec (GhcPass p) OverlapMode)
o })
        = [SDoc] -> SDoc
hsep [ String -> SDoc
text String
"deriving"
               , forall (p :: Pass).
OutputableBndrId p =>
Maybe (LDerivStrategy (GhcPass p)) -> SDoc
ppDerivStrategy Maybe (LDerivStrategy (GhcPass p))
ds
               , String -> SDoc
text String
"instance"
               , Maybe (LocatedP OverlapMode) -> SDoc
ppOverlapPragma Maybe (XRec (GhcPass p) OverlapMode)
o
               , forall a. Outputable a => a -> SDoc
ppr LHsSigWcType (GhcPass p)
ty ]

{-
************************************************************************
*                                                                      *
                Deriving strategies
*                                                                      *
************************************************************************
-}

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

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

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

type instance XViaStrategy GhcPs = XViaStrategyPs
type instance XViaStrategy GhcRn = LHsSigType GhcRn
type instance XViaStrategy GhcTc = Type

data XViaStrategyPs = XViaStrategyPs (EpAnn [AddEpAnn]) (LHsSigType GhcPs)

instance OutputableBndrId p
        => Outputable (DerivStrategy (GhcPass p)) where
    ppr :: DerivStrategy (GhcPass p) -> SDoc
ppr (StockStrategy    XStockStrategy (GhcPass p)
_) = String -> SDoc
text String
"stock"
    ppr (AnyclassStrategy XAnyClassStrategy (GhcPass p)
_) = String -> SDoc
text String
"anyclass"
    ppr (NewtypeStrategy  XNewtypeStrategy (GhcPass p)
_) = String -> SDoc
text String
"newtype"
    ppr (ViaStrategy XViaStrategy (GhcPass p)
ty)     = String -> SDoc
text String
"via" SDoc -> SDoc -> SDoc
<+> case forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p of
                                                GhcPass p
GhcPs -> forall a. Outputable a => a -> SDoc
ppr XViaStrategy (GhcPass p)
ty
                                                GhcPass p
GhcRn -> forall a. Outputable a => a -> SDoc
ppr XViaStrategy (GhcPass p)
ty
                                                GhcPass p
GhcTc -> forall a. Outputable a => a -> SDoc
ppr XViaStrategy (GhcPass p)
ty

instance Outputable XViaStrategyPs where
    ppr :: XViaStrategyPs -> SDoc
ppr (XViaStrategyPs EpAnn [AddEpAnn]
_ LHsSigType GhcPs
t) = forall a. Outputable a => a -> SDoc
ppr LHsSigType GhcPs
t


-- | Eliminate a 'DerivStrategy'.
foldDerivStrategy :: (p ~ GhcPass pass)
                  => r -> (XViaStrategy p -> r) -> DerivStrategy p -> r
foldDerivStrategy :: forall p (pass :: Pass) r.
(p ~ GhcPass pass) =>
r -> (XViaStrategy p -> r) -> DerivStrategy p -> r
foldDerivStrategy r
other XViaStrategy p -> r
_   (StockStrategy    XStockStrategy p
_) = r
other
foldDerivStrategy r
other XViaStrategy p -> r
_   (AnyclassStrategy XAnyClassStrategy p
_) = r
other
foldDerivStrategy r
other XViaStrategy p -> r
_   (NewtypeStrategy  XNewtypeStrategy p
_) = r
other
foldDerivStrategy r
_     XViaStrategy p -> r
via (ViaStrategy XViaStrategy p
t)  = XViaStrategy p -> r
via XViaStrategy p
t

-- | Map over the @via@ type if dealing with 'ViaStrategy'. Otherwise,
-- return the 'DerivStrategy' unchanged.
mapDerivStrategy :: (p ~ GhcPass pass)
                 => (XViaStrategy p -> XViaStrategy p)
                 -> DerivStrategy p -> DerivStrategy p
mapDerivStrategy :: forall p (pass :: Pass).
(p ~ GhcPass pass) =>
(XViaStrategy p -> XViaStrategy p)
-> DerivStrategy p -> DerivStrategy p
mapDerivStrategy XViaStrategy p -> XViaStrategy p
f DerivStrategy p
ds = forall p (pass :: Pass) r.
(p ~ GhcPass pass) =>
r -> (XViaStrategy p -> r) -> DerivStrategy p -> r
foldDerivStrategy DerivStrategy p
ds (forall pass. XViaStrategy pass -> DerivStrategy pass
ViaStrategy forall b c a. (b -> c) -> (a -> b) -> a -> c
. XViaStrategy p -> XViaStrategy p
f) DerivStrategy p
ds

{-
************************************************************************
*                                                                      *
\subsection[DefaultDecl]{A @default@ declaration}
*                                                                      *
************************************************************************
-}

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

type instance XXDefaultDecl    (GhcPass _) = NoExtCon

instance OutputableBndrId p
       => Outputable (DefaultDecl (GhcPass p)) where
    ppr :: DefaultDecl (GhcPass p) -> SDoc
ppr (DefaultDecl XCDefaultDecl (GhcPass p)
_ [LHsType (GhcPass p)]
tys)
      = String -> SDoc
text String
"default" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
parens (forall a. Outputable a => [a] -> SDoc
interpp'SP [LHsType (GhcPass p)]
tys)

{-
************************************************************************
*                                                                      *
\subsection{Foreign function interface declaration}
*                                                                      *
************************************************************************
-}

type instance XForeignImport   GhcPs = EpAnn [AddEpAnn]
type instance XForeignImport   GhcRn = NoExtField
type instance XForeignImport   GhcTc = Coercion

type instance XForeignExport   GhcPs = EpAnn [AddEpAnn]
type instance XForeignExport   GhcRn = NoExtField
type instance XForeignExport   GhcTc = Coercion

type instance XXForeignDecl    (GhcPass _) = NoExtCon

instance OutputableBndrId p
       => Outputable (ForeignDecl (GhcPass p)) where
  ppr :: ForeignDecl (GhcPass p) -> SDoc
ppr (ForeignImport { fd_name :: forall pass. ForeignDecl pass -> LIdP pass
fd_name = LIdP (GhcPass p)
n, fd_sig_ty :: forall pass. ForeignDecl pass -> LHsSigType pass
fd_sig_ty = LHsSigType (GhcPass p)
ty, fd_fi :: forall pass. ForeignDecl pass -> ForeignImport
fd_fi = ForeignImport
fimport })
    = SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"foreign import" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr ForeignImport
fimport SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr LIdP (GhcPass p)
n)
         Int
2 (SDoc
dcolon SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr LHsSigType (GhcPass p)
ty)
  ppr (ForeignExport { fd_name :: forall pass. ForeignDecl pass -> LIdP pass
fd_name = LIdP (GhcPass p)
n, fd_sig_ty :: forall pass. ForeignDecl pass -> LHsSigType pass
fd_sig_ty = LHsSigType (GhcPass p)
ty, fd_fe :: forall pass. ForeignDecl pass -> ForeignExport
fd_fe = ForeignExport
fexport }) =
    SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"foreign export" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr ForeignExport
fexport SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr LIdP (GhcPass p)
n)
       Int
2 (SDoc
dcolon SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr LHsSigType (GhcPass p)
ty)

{-
************************************************************************
*                                                                      *
\subsection{Rewrite rules}
*                                                                      *
************************************************************************
-}

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

type instance XXRuleDecls    (GhcPass _) = NoExtCon

type instance XHsRule       GhcPs = EpAnn HsRuleAnn
type instance XHsRule       GhcRn = HsRuleRn
type instance XHsRule       GhcTc = HsRuleRn

type instance XXRuleDecl    (GhcPass _) = NoExtCon

type instance Anno (SourceText, RuleName) = SrcSpan

data HsRuleAnn
  = HsRuleAnn
       { HsRuleAnn -> Maybe (AddEpAnn, AddEpAnn)
ra_tyanns :: Maybe (AddEpAnn, AddEpAnn)
                 -- ^ The locations of 'forall' and '.' for forall'd type vars
                 -- Using AddEpAnn to capture possible unicode variants
       , HsRuleAnn -> Maybe (AddEpAnn, AddEpAnn)
ra_tmanns :: Maybe (AddEpAnn, AddEpAnn)
                 -- ^ The locations of 'forall' and '.' for forall'd term vars
                 -- Using AddEpAnn to capture possible unicode variants
       , HsRuleAnn -> [AddEpAnn]
ra_rest :: [AddEpAnn]
       } deriving (Typeable HsRuleAnn
HsRuleAnn -> DataType
HsRuleAnn -> Constr
(forall b. Data b => b -> b) -> HsRuleAnn -> HsRuleAnn
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) -> HsRuleAnn -> u
forall u. (forall d. Data d => d -> u) -> HsRuleAnn -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> HsRuleAnn -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> HsRuleAnn -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> HsRuleAnn -> m HsRuleAnn
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HsRuleAnn -> m HsRuleAnn
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c HsRuleAnn
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> HsRuleAnn -> c HsRuleAnn
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c HsRuleAnn)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c HsRuleAnn)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HsRuleAnn -> m HsRuleAnn
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HsRuleAnn -> m HsRuleAnn
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HsRuleAnn -> m HsRuleAnn
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HsRuleAnn -> m HsRuleAnn
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> HsRuleAnn -> m HsRuleAnn
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> HsRuleAnn -> m HsRuleAnn
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> HsRuleAnn -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> HsRuleAnn -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> HsRuleAnn -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> HsRuleAnn -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> HsRuleAnn -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> HsRuleAnn -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> HsRuleAnn -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> HsRuleAnn -> r
gmapT :: (forall b. Data b => b -> b) -> HsRuleAnn -> HsRuleAnn
$cgmapT :: (forall b. Data b => b -> b) -> HsRuleAnn -> HsRuleAnn
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c HsRuleAnn)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c HsRuleAnn)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c HsRuleAnn)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c HsRuleAnn)
dataTypeOf :: HsRuleAnn -> DataType
$cdataTypeOf :: HsRuleAnn -> DataType
toConstr :: HsRuleAnn -> Constr
$ctoConstr :: HsRuleAnn -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c HsRuleAnn
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c HsRuleAnn
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> HsRuleAnn -> c HsRuleAnn
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> HsRuleAnn -> c HsRuleAnn
Data, HsRuleAnn -> HsRuleAnn -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HsRuleAnn -> HsRuleAnn -> Bool
$c/= :: HsRuleAnn -> HsRuleAnn -> Bool
== :: HsRuleAnn -> HsRuleAnn -> Bool
$c== :: HsRuleAnn -> HsRuleAnn -> Bool
Eq)

flattenRuleDecls :: [LRuleDecls (GhcPass p)] -> [LRuleDecl (GhcPass p)]
flattenRuleDecls :: forall (p :: Pass).
[LRuleDecls (GhcPass p)] -> [LRuleDecl (GhcPass p)]
flattenRuleDecls [LRuleDecls (GhcPass p)]
decls = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (forall pass. RuleDecls pass -> [LRuleDecl pass]
rds_rules forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l e. GenLocated l e -> e
unLoc) [LRuleDecls (GhcPass p)]
decls

type instance XCRuleBndr    (GhcPass _) = EpAnn [AddEpAnn]
type instance XRuleBndrSig  (GhcPass _) = EpAnn [AddEpAnn]
type instance XXRuleBndr    (GhcPass _) = NoExtCon

instance (OutputableBndrId p) => Outputable (RuleDecls (GhcPass p)) where
  ppr :: RuleDecls (GhcPass p) -> SDoc
ppr (HsRules { rds_src :: forall pass. RuleDecls pass -> SourceText
rds_src = SourceText
st
               , rds_rules :: forall pass. RuleDecls pass -> [LRuleDecl pass]
rds_rules = [LRuleDecl (GhcPass p)]
rules })
    = SourceText -> SDoc -> SDoc
pprWithSourceText SourceText
st (String -> SDoc
text String
"{-# RULES")
          SDoc -> SDoc -> SDoc
<+> [SDoc] -> SDoc
vcat (SDoc -> [SDoc] -> [SDoc]
punctuate SDoc
semi (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [LRuleDecl (GhcPass p)]
rules)) SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"#-}"

instance (OutputableBndrId p) => Outputable (RuleDecl (GhcPass p)) where
  ppr :: RuleDecl (GhcPass p) -> SDoc
ppr (HsRule { rd_name :: forall pass. RuleDecl pass -> XRec pass (SourceText, RuleName)
rd_name = XRec (GhcPass p) (SourceText, RuleName)
name
              , rd_act :: forall pass. RuleDecl pass -> Activation
rd_act  = Activation
act
              , rd_tyvs :: forall pass.
RuleDecl pass -> Maybe [LHsTyVarBndr () (NoGhcTc pass)]
rd_tyvs = Maybe [LHsTyVarBndr () (NoGhcTc (GhcPass p))]
tys
              , rd_tmvs :: forall pass. RuleDecl pass -> [LRuleBndr pass]
rd_tmvs = [LRuleBndr (GhcPass p)]
tms
              , rd_lhs :: forall pass. RuleDecl pass -> XRec pass (HsExpr pass)
rd_lhs  = XRec (GhcPass p) (HsExpr (GhcPass p))
lhs
              , rd_rhs :: forall pass. RuleDecl pass -> XRec pass (HsExpr pass)
rd_rhs  = XRec (GhcPass p) (HsExpr (GhcPass p))
rhs })
        = [SDoc] -> SDoc
sep [Located (SourceText, RuleName) -> SDoc
pprFullRuleName XRec (GhcPass p) (SourceText, RuleName)
name SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr Activation
act,
               Int -> SDoc -> SDoc
nest Int
4 (forall {a}. Outputable a => Maybe [a] -> SDoc
pp_forall_ty Maybe [LHsTyVarBndr () (NoGhcTc (GhcPass p))]
tys SDoc -> SDoc -> SDoc
<+> Maybe
  [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass (NoGhcTcPass p)))]
-> SDoc
pp_forall_tm Maybe [LHsTyVarBndr () (NoGhcTc (GhcPass p))]
tys
                                        SDoc -> SDoc -> SDoc
<+> forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> SDoc
pprExpr (forall l e. GenLocated l e -> e
unLoc XRec (GhcPass p) (HsExpr (GhcPass p))
lhs)),
               Int -> SDoc -> SDoc
nest Int
6 (SDoc
equals SDoc -> SDoc -> SDoc
<+> forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> SDoc
pprExpr (forall l e. GenLocated l e -> e
unLoc XRec (GhcPass p) (HsExpr (GhcPass p))
rhs)) ]
        where
          pp_forall_ty :: Maybe [a] -> SDoc
pp_forall_ty Maybe [a]
Nothing     = SDoc
empty
          pp_forall_ty (Just [a]
qtvs) = SDoc
forAllLit SDoc -> SDoc -> SDoc
<+> [SDoc] -> SDoc
fsep (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [a]
qtvs) SDoc -> SDoc -> SDoc
<> SDoc
dot
          pp_forall_tm :: Maybe
  [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass (NoGhcTcPass p)))]
-> SDoc
pp_forall_tm Maybe
  [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass (NoGhcTcPass p)))]
Nothing | forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LRuleBndr (GhcPass p)]
tms = SDoc
empty
          pp_forall_tm Maybe
  [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass (NoGhcTcPass p)))]
_ = SDoc
forAllLit SDoc -> SDoc -> SDoc
<+> [SDoc] -> SDoc
fsep (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [LRuleBndr (GhcPass p)]
tms) SDoc -> SDoc -> SDoc
<> SDoc
dot

instance (OutputableBndrId p) => Outputable (RuleBndr (GhcPass p)) where
   ppr :: RuleBndr (GhcPass p) -> SDoc
ppr (RuleBndr XCRuleBndr (GhcPass p)
_ LIdP (GhcPass p)
name) = forall a. Outputable a => a -> SDoc
ppr LIdP (GhcPass p)
name
   ppr (RuleBndrSig XRuleBndrSig (GhcPass p)
_ LIdP (GhcPass p)
name HsPatSigType (GhcPass p)
ty) = SDoc -> SDoc
parens (forall a. Outputable a => a -> SDoc
ppr LIdP (GhcPass p)
name SDoc -> SDoc -> SDoc
<> SDoc
dcolon SDoc -> SDoc -> SDoc
<> forall a. Outputable a => a -> SDoc
ppr HsPatSigType (GhcPass p)
ty)

{-
************************************************************************
*                                                                      *
\subsection[DeprecDecl]{Deprecations}
*                                                                      *
************************************************************************
-}

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

type instance XXWarnDecls    (GhcPass _) = NoExtCon

type instance XWarning      (GhcPass _) = EpAnn [AddEpAnn]
type instance XXWarnDecl    (GhcPass _) = NoExtCon


instance OutputableBndrId p
        => Outputable (WarnDecls (GhcPass p)) where
    ppr :: WarnDecls (GhcPass p) -> SDoc
ppr (Warnings XWarnings (GhcPass p)
_ (SourceText String
src) [LWarnDecl (GhcPass p)]
decls)
      = String -> SDoc
text String
src SDoc -> SDoc -> SDoc
<+> [SDoc] -> SDoc
vcat (SDoc -> [SDoc] -> [SDoc]
punctuate SDoc
comma (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [LWarnDecl (GhcPass p)]
decls)) SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"#-}"
    ppr (Warnings XWarnings (GhcPass p)
_ SourceText
NoSourceText [LWarnDecl (GhcPass p)]
_decls) = forall a. String -> a
panic String
"WarnDecls"

instance OutputableBndrId p
       => Outputable (WarnDecl (GhcPass p)) where
    ppr :: WarnDecl (GhcPass p) -> SDoc
ppr (Warning XWarning (GhcPass p)
_ [LIdP (GhcPass p)]
thing WarningTxt
txt)
      = [SDoc] -> SDoc
hsep ( SDoc -> [SDoc] -> [SDoc]
punctuate SDoc
comma (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [LIdP (GhcPass p)]
thing))
              SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr WarningTxt
txt

{-
************************************************************************
*                                                                      *
\subsection[AnnDecl]{Annotations}
*                                                                      *
************************************************************************
-}

type instance XHsAnnotation (GhcPass _) = EpAnn AnnPragma
type instance XXAnnDecl     (GhcPass _) = NoExtCon

instance (OutputableBndrId p) => Outputable (AnnDecl (GhcPass p)) where
    ppr :: AnnDecl (GhcPass p) -> SDoc
ppr (HsAnnotation XHsAnnotation (GhcPass p)
_ SourceText
_ AnnProvenance (GhcPass p)
provenance XRec (GhcPass p) (HsExpr (GhcPass p))
expr)
      = [SDoc] -> SDoc
hsep [String -> SDoc
text String
"{-#", forall (p :: Pass).
OutputableBndrId p =>
AnnProvenance (GhcPass p) -> SDoc
pprAnnProvenance AnnProvenance (GhcPass p)
provenance, forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> SDoc
pprExpr (forall l e. GenLocated l e -> e
unLoc XRec (GhcPass p) (HsExpr (GhcPass p))
expr), String -> SDoc
text String
"#-}"]

pprAnnProvenance :: OutputableBndrId p => AnnProvenance (GhcPass p) -> SDoc
pprAnnProvenance :: forall (p :: Pass).
OutputableBndrId p =>
AnnProvenance (GhcPass p) -> SDoc
pprAnnProvenance AnnProvenance (GhcPass p)
ModuleAnnProvenance       = String -> SDoc
text String
"ANN module"
pprAnnProvenance (ValueAnnProvenance (L Anno (IdGhcP p)
_ IdGhcP p
name))
  = String -> SDoc
text String
"ANN" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr IdGhcP p
name
pprAnnProvenance (TypeAnnProvenance (L Anno (IdGhcP p)
_ IdGhcP p
name))
  = String -> SDoc
text String
"ANN type" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr IdGhcP p
name

{-
************************************************************************
*                                                                      *
\subsection[RoleAnnot]{Role annotations}
*                                                                      *
************************************************************************
-}

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

type instance XXRoleAnnotDecl (GhcPass _) = NoExtCon

type instance Anno (Maybe Role) = SrcSpan

instance OutputableBndr (IdP (GhcPass p))
       => Outputable (RoleAnnotDecl (GhcPass p)) where
  ppr :: RoleAnnotDecl (GhcPass p) -> SDoc
ppr (RoleAnnotDecl XCRoleAnnotDecl (GhcPass p)
_ LIdP (GhcPass p)
ltycon [XRec (GhcPass p) (Maybe Role)]
roles)
    = String -> SDoc
text String
"type role" SDoc -> SDoc -> SDoc
<+> forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (forall l e. GenLocated l e -> e
unLoc LIdP (GhcPass p)
ltycon) SDoc -> SDoc -> SDoc
<+>
      [SDoc] -> SDoc
hsep (forall a b. (a -> b) -> [a] -> [b]
map (forall {a}. Outputable a => Maybe a -> SDoc
pp_role forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l e. GenLocated l e -> e
unLoc) [XRec (GhcPass p) (Maybe Role)]
roles)
    where
      pp_role :: Maybe a -> SDoc
pp_role Maybe a
Nothing  = SDoc
underscore
      pp_role (Just a
r) = forall a. Outputable a => a -> SDoc
ppr a
r

roleAnnotDeclName :: RoleAnnotDecl (GhcPass p) -> IdP (GhcPass p)
roleAnnotDeclName :: forall (p :: Pass). RoleAnnotDecl (GhcPass p) -> IdP (GhcPass p)
roleAnnotDeclName (RoleAnnotDecl XCRoleAnnotDecl (GhcPass p)
_ (L Anno (IdGhcP p)
_ IdGhcP p
name) [XRec (GhcPass p) (Maybe Role)]
_) = IdGhcP p
name

{-
************************************************************************
*                                                                      *
\subsection{Anno instances}
*                                                                      *
************************************************************************
-}

type instance Anno (HsDecl (GhcPass _)) = SrcSpanAnnA
type instance Anno (SpliceDecl (GhcPass p)) = SrcSpanAnnA
type instance Anno (TyClDecl (GhcPass p)) = SrcSpanAnnA
type instance Anno (FunDep (GhcPass p)) = SrcSpanAnnA
type instance Anno (FamilyResultSig (GhcPass p)) = SrcSpan
type instance Anno (FamilyDecl (GhcPass p)) = SrcSpanAnnA
type instance Anno (InjectivityAnn (GhcPass p)) = SrcSpan
type instance Anno CType = SrcSpanAnnP
type instance Anno (HsDerivingClause (GhcPass p)) = SrcSpan
type instance Anno (DerivClauseTys (GhcPass _)) = SrcSpanAnnC
type instance Anno (StandaloneKindSig (GhcPass p)) = SrcSpanAnnA
type instance Anno (ConDecl (GhcPass p)) = SrcSpanAnnA
type instance Anno Bool = SrcSpan
type instance Anno [LocatedA (ConDeclField (GhcPass _))] = SrcSpanAnnL
type instance Anno (FamEqn p (LocatedA (HsType p))) = SrcSpanAnnA
type instance Anno (TyFamInstDecl (GhcPass p)) = SrcSpanAnnA
type instance Anno (DataFamInstDecl (GhcPass p)) = SrcSpanAnnA
type instance Anno (FamEqn (GhcPass p) _) = SrcSpanAnnA
type instance Anno (ClsInstDecl (GhcPass p)) = SrcSpanAnnA
type instance Anno (InstDecl (GhcPass p)) = SrcSpanAnnA
type instance Anno DocDecl = SrcSpanAnnA
type instance Anno (DerivDecl (GhcPass p)) = SrcSpanAnnA
type instance Anno OverlapMode = SrcSpanAnnP
type instance Anno (DerivStrategy (GhcPass p)) = SrcSpan
type instance Anno (DefaultDecl (GhcPass p)) = SrcSpanAnnA
type instance Anno (ForeignDecl (GhcPass p)) = SrcSpanAnnA
type instance Anno (RuleDecls (GhcPass p)) = SrcSpanAnnA
type instance Anno (RuleDecl (GhcPass p)) = SrcSpanAnnA
type instance Anno (SourceText, RuleName) = SrcSpan
type instance Anno (RuleBndr (GhcPass p)) = SrcSpan
type instance Anno (WarnDecls (GhcPass p)) = SrcSpanAnnA
type instance Anno (WarnDecl (GhcPass p)) = SrcSpanAnnA
type instance Anno (AnnDecl (GhcPass p)) = SrcSpanAnnA
type instance Anno (RoleAnnotDecl (GhcPass p)) = SrcSpanAnnA
type instance Anno (Maybe Role) = SrcSpan