{-# 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
-}

-- | 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, anyLConIsGadt,
  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(..), ppDataDefnHeader,
  pp_vanilla_decl_head,

  -- ** 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
  SpliceDecoration(..),
  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, pprUntypedSplice )
        -- 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.Misc (count)
import GHC.Utils.Outputable
import GHC.Utils.Panic
import GHC.Types.SrcLoc
import GHC.Types.SourceText
import GHC.Core.Type
import GHC.Core.TyCon (TyConFlavour(NewtypeFlavour,DataTypeFlavour))
import GHC.Types.ForeignCall

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

{-
************************************************************************
*                                                                      *
\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 _) = DataConCantHappen

-- | 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 = [LHsDecl GhcPs]
-> (LHsBinds GhcPs, [LSig GhcPs], [LFamilyDecl GhcPs],
    [LTyFamInstDecl GhcPs], [LDataFamInstDecl GhcPs], [LDocDecl GhcPs])
[GenLocated SrcSpanAnnA (HsDecl GhcPs)]
-> (Bag (GenLocated SrcSpanAnnA (HsBind GhcPs)),
    [GenLocated SrcSpanAnnA (Sig GhcPs)],
    [GenLocated SrcSpanAnnA (FamilyDecl GhcPs)],
    [GenLocated SrcSpanAnnA (TyFamInstDecl GhcPs)],
    [GenLocated SrcSpanAnnA (DataFamInstDecl GhcPs)],
    [GenLocated SrcSpanAnnA (DocDecl GhcPs)])
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 p)])
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 p)])
go [] = (Bag (GenLocated l (HsBind p))
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 p)]
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 p)])
go [GenLocated l (HsDecl p)]
ds in
      case HsDecl p
decl of
        ValD XValD p
_ HsBind p
b
          -> (l -> HsBind p -> GenLocated l (HsBind p)
forall l e. l -> e -> GenLocated l e
L l
l HsBind p
b GenLocated l (HsBind p)
-> Bag (GenLocated l (HsBind p)) -> Bag (GenLocated l (HsBind p))
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 p)]
docs)
        SigD XSigD p
_ Sig p
s
          -> (Bag (GenLocated l (HsBind p))
bs, l -> Sig p -> GenLocated l (Sig p)
forall l e. l -> e -> GenLocated l e
L l
l Sig p
s GenLocated l (Sig p)
-> [GenLocated l (Sig p)] -> [GenLocated l (Sig p)]
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 p)]
docs)
        TyClD XTyClD p
_ (FamDecl XFamDecl p
_ FamilyDecl p
t)
          -> (Bag (GenLocated l (HsBind p))
bs, [GenLocated l (Sig p)]
ss, l -> FamilyDecl p -> GenLocated l (FamilyDecl p)
forall l e. l -> e -> GenLocated l e
L l
l FamilyDecl p
t GenLocated l (FamilyDecl p)
-> [GenLocated l (FamilyDecl p)] -> [GenLocated l (FamilyDecl p)]
forall a. a -> [a] -> [a]
: [GenLocated l (FamilyDecl p)]
ts, [GenLocated l (TyFamInstDecl p)]
tfis, [GenLocated l (DataFamInstDecl p)]
dfis, [GenLocated l (DocDecl p)]
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, l -> TyFamInstDecl p -> GenLocated l (TyFamInstDecl p)
forall l e. l -> e -> GenLocated l e
L l
l TyFamInstDecl p
tfi GenLocated l (TyFamInstDecl p)
-> [GenLocated l (TyFamInstDecl p)]
-> [GenLocated l (TyFamInstDecl p)]
forall a. a -> [a] -> [a]
: [GenLocated l (TyFamInstDecl p)]
tfis, [GenLocated l (DataFamInstDecl p)]
dfis, [GenLocated l (DocDecl p)]
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, l -> DataFamInstDecl p -> GenLocated l (DataFamInstDecl p)
forall l e. l -> e -> GenLocated l e
L l
l DataFamInstDecl p
dfi GenLocated l (DataFamInstDecl p)
-> [GenLocated l (DataFamInstDecl p)]
-> [GenLocated l (DataFamInstDecl p)]
forall a. a -> [a] -> [a]
: [GenLocated l (DataFamInstDecl p)]
dfis, [GenLocated l (DocDecl p)]
docs)
        DocD XDocD p
_ DocDecl p
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, l -> DocDecl p -> GenLocated l (DocDecl p)
forall l e. l -> e -> GenLocated l e
L l
l DocDecl p
d GenLocated l (DocDecl p)
-> [GenLocated l (DocDecl p)] -> [GenLocated l (DocDecl p)]
forall a. a -> [a] -> [a]
: [GenLocated l (DocDecl p)]
docs)
        HsDecl p
_ -> String
-> SDoc
-> (Bag (GenLocated l (HsBind p)), [GenLocated l (Sig p)],
    [GenLocated l (FamilyDecl p)], [GenLocated l (TyFamInstDecl p)],
    [GenLocated l (DataFamInstDecl p)], [GenLocated l (DocDecl p)])
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"partitionBindsAndSigs" (HsDecl p -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsDecl p
decl)

-- Okay, I need to reconstruct the document comments, but for now:
instance Outputable (DocDecl name) where
  ppr :: DocDecl name -> SDoc
ppr DocDecl name
_ = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"<document comment>"

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


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

emptyGroup :: forall (p :: Pass). HsGroup (GhcPass p)
emptyGroup = HsGroup { hs_ext :: XCHsGroup (GhcPass p)
hs_ext = XCHsGroup (GhcPass p)
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 = String -> HsValBinds (GhcPass p)
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)]
[GenLocated SrcSpanAnnA (FixitySig (GhcPass p))]
fixds [GenLocated SrcSpanAnnA (FixitySig (GhcPass p))]
-> [GenLocated SrcSpanAnnA (FixitySig (GhcPass p))]
-> [GenLocated SrcSpanAnnA (FixitySig (GhcPass p))]
forall a. [a] -> [a] -> [a]
++ [GenLocated SrcSpanAnnA (FixitySig (GhcPass p))]
cls_fixds
  where
    cls_fixds :: [GenLocated SrcSpanAnnA (FixitySig (GhcPass p))]
cls_fixds = [ SrcSpanAnnA
-> FixitySig (GhcPass p)
-> GenLocated SrcSpanAnnA (FixitySig (GhcPass p))
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} <- [TyClGroup (GhcPass p)] -> [LTyClDecl (GhcPass p)]
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)]
[GenLocated SrcSpanAnnA (Sig (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    = XCHsGroup (GhcPass p)
NoExtField
noExtField,
        hs_valds :: HsValBinds (GhcPass p)
hs_valds  = HsValBinds (GhcPass p)
val_groups1 HsValBinds (GhcPass p)
-> HsValBinds (GhcPass p) -> HsValBinds (GhcPass p)
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)]
[GenLocated SrcSpanAnnA (SpliceDecl (GhcPass p))]
spliceds1 [GenLocated SrcSpanAnnA (SpliceDecl (GhcPass p))]
-> [GenLocated SrcSpanAnnA (SpliceDecl (GhcPass p))]
-> [GenLocated SrcSpanAnnA (SpliceDecl (GhcPass p))]
forall a. [a] -> [a] -> [a]
++ [LSpliceDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (SpliceDecl (GhcPass p))]
spliceds2,
        hs_tyclds :: [TyClGroup (GhcPass p)]
hs_tyclds = [TyClGroup (GhcPass p)]
tyclds1 [TyClGroup (GhcPass p)]
-> [TyClGroup (GhcPass p)] -> [TyClGroup (GhcPass p)]
forall a. [a] -> [a] -> [a]
++ [TyClGroup (GhcPass p)]
tyclds2,
        hs_derivds :: [LDerivDecl (GhcPass p)]
hs_derivds = [LDerivDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (DerivDecl (GhcPass p))]
derivds1 [GenLocated SrcSpanAnnA (DerivDecl (GhcPass p))]
-> [GenLocated SrcSpanAnnA (DerivDecl (GhcPass p))]
-> [GenLocated SrcSpanAnnA (DerivDecl (GhcPass p))]
forall a. [a] -> [a] -> [a]
++ [LDerivDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (DerivDecl (GhcPass p))]
derivds2,
        hs_fixds :: [LFixitySig (GhcPass p)]
hs_fixds  = [LFixitySig (GhcPass p)]
[GenLocated SrcSpanAnnA (FixitySig (GhcPass p))]
fixds1 [GenLocated SrcSpanAnnA (FixitySig (GhcPass p))]
-> [GenLocated SrcSpanAnnA (FixitySig (GhcPass p))]
-> [GenLocated SrcSpanAnnA (FixitySig (GhcPass p))]
forall a. [a] -> [a] -> [a]
++ [LFixitySig (GhcPass p)]
[GenLocated SrcSpanAnnA (FixitySig (GhcPass p))]
fixds2,
        hs_annds :: [LAnnDecl (GhcPass p)]
hs_annds  = [LAnnDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (AnnDecl (GhcPass p))]
annds1 [GenLocated SrcSpanAnnA (AnnDecl (GhcPass p))]
-> [GenLocated SrcSpanAnnA (AnnDecl (GhcPass p))]
-> [GenLocated SrcSpanAnnA (AnnDecl (GhcPass p))]
forall a. [a] -> [a] -> [a]
++ [LAnnDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (AnnDecl (GhcPass p))]
annds2,
        hs_defds :: [LDefaultDecl (GhcPass p)]
hs_defds  = [LDefaultDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (DefaultDecl (GhcPass p))]
defds1 [GenLocated SrcSpanAnnA (DefaultDecl (GhcPass p))]
-> [GenLocated SrcSpanAnnA (DefaultDecl (GhcPass p))]
-> [GenLocated SrcSpanAnnA (DefaultDecl (GhcPass p))]
forall a. [a] -> [a] -> [a]
++ [LDefaultDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (DefaultDecl (GhcPass p))]
defds2,
        hs_fords :: [LForeignDecl (GhcPass p)]
hs_fords  = [LForeignDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (ForeignDecl (GhcPass p))]
fords1 [GenLocated SrcSpanAnnA (ForeignDecl (GhcPass p))]
-> [GenLocated SrcSpanAnnA (ForeignDecl (GhcPass p))]
-> [GenLocated SrcSpanAnnA (ForeignDecl (GhcPass p))]
forall a. [a] -> [a] -> [a]
++ [LForeignDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (ForeignDecl (GhcPass p))]
fords2,
        hs_warnds :: [LWarnDecls (GhcPass p)]
hs_warnds = [LWarnDecls (GhcPass p)]
[GenLocated SrcSpanAnnA (WarnDecls (GhcPass p))]
warnds1 [GenLocated SrcSpanAnnA (WarnDecls (GhcPass p))]
-> [GenLocated SrcSpanAnnA (WarnDecls (GhcPass p))]
-> [GenLocated SrcSpanAnnA (WarnDecls (GhcPass p))]
forall a. [a] -> [a] -> [a]
++ [LWarnDecls (GhcPass p)]
[GenLocated SrcSpanAnnA (WarnDecls (GhcPass p))]
warnds2,
        hs_ruleds :: [LRuleDecls (GhcPass p)]
hs_ruleds = [LRuleDecls (GhcPass p)]
[GenLocated SrcSpanAnnA (RuleDecls (GhcPass p))]
rulds1 [GenLocated SrcSpanAnnA (RuleDecls (GhcPass p))]
-> [GenLocated SrcSpanAnnA (RuleDecls (GhcPass p))]
-> [GenLocated SrcSpanAnnA (RuleDecls (GhcPass p))]
forall a. [a] -> [a] -> [a]
++ [LRuleDecls (GhcPass p)]
[GenLocated SrcSpanAnnA (RuleDecls (GhcPass p))]
rulds2,
        hs_docs :: [LDocDecl (GhcPass p)]
hs_docs   = [LDocDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (DocDecl (GhcPass p))]
docs1  [GenLocated SrcSpanAnnA (DocDecl (GhcPass p))]
-> [GenLocated SrcSpanAnnA (DocDecl (GhcPass p))]
-> [GenLocated SrcSpanAnnA (DocDecl (GhcPass p))]
forall a. [a] -> [a] -> [a]
++ [LDocDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (DocDecl (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)             = TyClDecl (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyClDecl (GhcPass p)
dcl
    ppr (ValD XValD (GhcPass p)
_ HsBind (GhcPass p)
binds)            = HsBind (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsBind (GhcPass p)
binds
    ppr (DefD XDefD (GhcPass p)
_ DefaultDecl (GhcPass p)
def)              = DefaultDecl (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr DefaultDecl (GhcPass p)
def
    ppr (InstD XInstD (GhcPass p)
_ InstDecl (GhcPass p)
inst)            = InstDecl (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr InstDecl (GhcPass p)
inst
    ppr (DerivD XDerivD (GhcPass p)
_ DerivDecl (GhcPass p)
deriv)          = DerivDecl (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr DerivDecl (GhcPass p)
deriv
    ppr (ForD XForD (GhcPass p)
_ ForeignDecl (GhcPass p)
fd)               = ForeignDecl (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr ForeignDecl (GhcPass p)
fd
    ppr (SigD XSigD (GhcPass p)
_ Sig (GhcPass p)
sd)               = Sig (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr Sig (GhcPass p)
sd
    ppr (KindSigD XKindSigD (GhcPass p)
_ StandaloneKindSig (GhcPass p)
ksd)          = StandaloneKindSig (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr StandaloneKindSig (GhcPass p)
ksd
    ppr (RuleD XRuleD (GhcPass p)
_ RuleDecls (GhcPass p)
rd)              = RuleDecls (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr RuleDecls (GhcPass p)
rd
    ppr (WarningD XWarningD (GhcPass p)
_ WarnDecls (GhcPass p)
wd)           = WarnDecls (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr WarnDecls (GhcPass p)
wd
    ppr (AnnD XAnnD (GhcPass p)
_ AnnDecl (GhcPass p)
ad)               = AnnDecl (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr AnnDecl (GhcPass p)
ad
    ppr (SpliceD XSpliceD (GhcPass p)
_ SpliceDecl (GhcPass p)
dd)            = SpliceDecl (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr SpliceDecl (GhcPass p)
dd
    ppr (DocD XDocD (GhcPass p)
_ DocDecl (GhcPass p)
doc)              = DocDecl (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr DocDecl (GhcPass p)
doc
    ppr (RoleAnnotD XRoleAnnotD (GhcPass p)
_ RoleAnnotDecl (GhcPass p)
ra)         = RoleAnnotDecl (GhcPass p) -> SDoc
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
forall doc. IsOutput doc => doc
empty
            [[GenLocated SrcSpanAnnA (FixitySig (GhcPass p))] -> Maybe SDoc
forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds [LFixitySig (GhcPass p)]
[GenLocated SrcSpanAnnA (FixitySig (GhcPass p))]
fix_decls, [GenLocated SrcSpanAnnA (DefaultDecl (GhcPass p))] -> Maybe SDoc
forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds [LDefaultDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (DefaultDecl (GhcPass p))]
default_decls,
             [GenLocated SrcSpanAnnA (WarnDecls (GhcPass p))] -> Maybe SDoc
forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds [LWarnDecls (GhcPass p)]
[GenLocated SrcSpanAnnA (WarnDecls (GhcPass p))]
deprec_decls, [GenLocated SrcSpanAnnA (AnnDecl (GhcPass p))] -> Maybe SDoc
forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds [LAnnDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (AnnDecl (GhcPass p))]
ann_decls,
             [GenLocated SrcSpanAnnA (RuleDecls (GhcPass p))] -> Maybe SDoc
forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds [LRuleDecls (GhcPass p)]
[GenLocated SrcSpanAnnA (RuleDecls (GhcPass p))]
rule_decls,
             if HsValBinds (GhcPass p) -> Bool
forall (a :: Pass) (b :: Pass).
HsValBindsLR (GhcPass a) (GhcPass b) -> Bool
isEmptyValBinds HsValBinds (GhcPass p)
val_decls
                then Maybe SDoc
forall a. Maybe a
Nothing
                else SDoc -> Maybe SDoc
forall a. a -> Maybe a
Just (HsValBinds (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsValBinds (GhcPass p)
val_decls),
             [GenLocated SrcSpanAnnA (RoleAnnotDecl (GhcPass p))] -> Maybe SDoc
forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds ([TyClGroup (GhcPass p)] -> [LRoleAnnotDecl (GhcPass p)]
forall pass. [TyClGroup pass] -> [LRoleAnnotDecl pass]
tyClGroupRoleDecls [TyClGroup (GhcPass p)]
tycl_decls),
             [GenLocated SrcSpanAnnA (StandaloneKindSig (GhcPass p))]
-> Maybe SDoc
forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds ([TyClGroup (GhcPass p)] -> [LStandaloneKindSig (GhcPass p)]
forall pass. [TyClGroup pass] -> [LStandaloneKindSig pass]
tyClGroupKindSigs  [TyClGroup (GhcPass p)]
tycl_decls),
             [GenLocated SrcSpanAnnA (TyClDecl (GhcPass p))] -> Maybe SDoc
forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds ([TyClGroup (GhcPass p)] -> [LTyClDecl (GhcPass p)]
forall pass. [TyClGroup pass] -> [LTyClDecl pass]
tyClGroupTyClDecls [TyClGroup (GhcPass p)]
tycl_decls),
             [GenLocated SrcSpanAnnA (InstDecl (GhcPass p))] -> Maybe SDoc
forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds ([TyClGroup (GhcPass p)] -> [LInstDecl (GhcPass p)]
forall pass. [TyClGroup pass] -> [LInstDecl pass]
tyClGroupInstDecls [TyClGroup (GhcPass p)]
tycl_decls),
             [GenLocated SrcSpanAnnA (DerivDecl (GhcPass p))] -> Maybe SDoc
forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds [LDerivDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (DerivDecl (GhcPass p))]
deriv_decls,
             [GenLocated SrcSpanAnnA (ForeignDecl (GhcPass p))] -> Maybe SDoc
forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds [LForeignDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (ForeignDecl (GhcPass p))]
foreign_decls]
        where
          ppr_ds :: Outputable a => [a] -> Maybe SDoc
          ppr_ds :: forall a. Outputable a => [a] -> Maybe SDoc
ppr_ds [] = Maybe SDoc
forall a. Maybe a
Nothing
          ppr_ds [a]
ds = SDoc -> Maybe SDoc
forall a. a -> Maybe a
Just ([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat ((a -> SDoc) -> [a] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map a -> SDoc
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
forall doc. IsOutput doc => doc
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
forall doc. IsDoc doc => doc -> doc -> doc
$$ SDoc
d SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ SDoc -> [Maybe SDoc] -> SDoc
vcat_mb SDoc
blankLine [Maybe SDoc]
ds

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

instance OutputableBndrId p
       => Outputable (SpliceDecl (GhcPass p)) where
  ppr :: SpliceDecl (GhcPass p) -> SDoc
ppr (SpliceDecl XSpliceDecl (GhcPass p)
_ (L Anno (HsUntypedSplice (GhcPass p))
_ HsUntypedSplice (GhcPass p)
e) SpliceDecoration
DollarSplice) = Bool
-> Maybe SplicePointName -> HsUntypedSplice (GhcPass p) -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
Bool
-> Maybe SplicePointName -> HsUntypedSplice (GhcPass p) -> SDoc
pprUntypedSplice Bool
True Maybe SplicePointName
forall a. Maybe a
Nothing HsUntypedSplice (GhcPass p)
e
  ppr (SpliceDecl XSpliceDecl (GhcPass p)
_ (L Anno (HsUntypedSplice (GhcPass p))
_ HsUntypedSplice (GhcPass p)
e) SpliceDecoration
BareSplice)   = Bool
-> Maybe SplicePointName -> HsUntypedSplice (GhcPass p) -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
Bool
-> Maybe SplicePointName -> HsUntypedSplice (GhcPass p) -> SDoc
pprUntypedSplice Bool
False Maybe SplicePointName
forall a. Maybe a
Nothing HsUntypedSplice (GhcPass p)
e

instance Outputable SpliceDecoration where
  ppr :: SpliceDecoration -> SDoc
ppr SpliceDecoration
x = String -> SDoc
forall doc. IsLine doc => String -> doc
text (String -> SDoc) -> String -> SDoc
forall a b. (a -> b) -> a -> b
$ SpliceDecoration -> String
forall a. Show a => a -> String
show SpliceDecoration
x



{-
************************************************************************
*                                                                      *
            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

data DataDeclRn = DataDeclRn
             { DataDeclRn -> Bool
tcdDataCusk :: Bool    -- ^ does this have a CUSK?
                 -- See Note [CUSKs: complete user-supplied kind signatures]
             , DataDeclRn -> NameSet
tcdFVs      :: NameSet }
  deriving Typeable DataDeclRn
Typeable DataDeclRn =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> DataDeclRn -> c DataDeclRn)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c DataDeclRn)
-> (DataDeclRn -> Constr)
-> (DataDeclRn -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c DataDeclRn))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c DataDeclRn))
-> ((forall b. Data b => b -> b) -> DataDeclRn -> DataDeclRn)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> DataDeclRn -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> DataDeclRn -> r)
-> (forall u. (forall d. Data d => d -> u) -> DataDeclRn -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> DataDeclRn -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> DataDeclRn -> m DataDeclRn)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> DataDeclRn -> m DataDeclRn)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> DataDeclRn -> m DataDeclRn)
-> Data DataDeclRn
DataDeclRn -> Constr
DataDeclRn -> DataType
(forall b. Data b => b -> b) -> DataDeclRn -> DataDeclRn
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) -> DataDeclRn -> u
forall u. (forall d. Data d => d -> u) -> DataDeclRn -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DataDeclRn -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DataDeclRn -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> DataDeclRn -> m DataDeclRn
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DataDeclRn -> m DataDeclRn
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DataDeclRn
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DataDeclRn -> c DataDeclRn
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DataDeclRn)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c DataDeclRn)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DataDeclRn -> c DataDeclRn
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DataDeclRn -> c DataDeclRn
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DataDeclRn
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DataDeclRn
$ctoConstr :: DataDeclRn -> Constr
toConstr :: DataDeclRn -> Constr
$cdataTypeOf :: DataDeclRn -> DataType
dataTypeOf :: DataDeclRn -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DataDeclRn)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DataDeclRn)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c DataDeclRn)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c DataDeclRn)
$cgmapT :: (forall b. Data b => b -> b) -> DataDeclRn -> DataDeclRn
gmapT :: (forall b. Data b => b -> b) -> DataDeclRn -> DataDeclRn
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DataDeclRn -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DataDeclRn -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DataDeclRn -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DataDeclRn -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> DataDeclRn -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> DataDeclRn -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> DataDeclRn -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> DataDeclRn -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> DataDeclRn -> m DataDeclRn
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> DataDeclRn -> m DataDeclRn
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DataDeclRn -> m DataDeclRn
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DataDeclRn -> m DataDeclRn
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DataDeclRn -> m DataDeclRn
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DataDeclRn -> m DataDeclRn
Data

type instance XClassDecl    GhcPs = (EpAnn [AddEpAnn], AnnSortKey)

  -- TODO:AZ:tidy up AnnSortKey above
type instance XClassDecl    GhcRn = NameSet -- FVs
type instance XClassDecl    GhcTc = NameSet -- FVs

type instance XXTyClDecl    (GhcPass _) = DataConCantHappen

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

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

pprFlavour :: FamilyInfo pass -> SDoc
pprFlavour :: forall pass. FamilyInfo pass -> SDoc
pprFlavour FamilyInfo pass
DataFamily            = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"data"
pprFlavour FamilyInfo pass
OpenTypeFamily        = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"type"
pprFlavour (ClosedTypeFamily {}) = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"type"

instance Outputable (FamilyInfo pass) where
  ppr :: FamilyInfo pass -> SDoc
ppr FamilyInfo pass
info = FamilyInfo pass -> SDoc
forall pass. FamilyInfo pass -> SDoc
pprFlavour FamilyInfo pass
info SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"family"


-- 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 = GenLocated SrcSpanAnnN (IdGhcP p) -> IdGhcP p
forall l e. GenLocated l e -> e
unLoc (GenLocated SrcSpanAnnN (IdGhcP p) -> IdGhcP p)
-> (TyFamInstDecl (GhcPass p) -> GenLocated SrcSpanAnnN (IdGhcP p))
-> TyFamInstDecl (GhcPass p)
-> IdGhcP p
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TyFamInstDecl (GhcPass p) -> LocatedN (IdP (GhcPass p))
TyFamInstDecl (GhcPass p) -> GenLocated SrcSpanAnnN (IdGhcP p)
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)
GenLocated SrcSpanAnnN (IdP (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 })     = FamilyDecl (GhcPass p) -> XRec (GhcPass p) (IdP (GhcPass p))
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 = XRec (GhcPass p) (IdP (GhcPass p))
ln })   = XRec (GhcPass p) (IdP (GhcPass p))
GenLocated SrcSpanAnnN (IdP (GhcPass p))
ln
tyClDeclLName (DataDecl { tcdLName :: forall pass. TyClDecl pass -> LIdP pass
tcdLName = XRec (GhcPass p) (IdP (GhcPass p))
ln })  = XRec (GhcPass p) (IdP (GhcPass p))
GenLocated SrcSpanAnnN (IdP (GhcPass p))
ln
tyClDeclLName (ClassDecl { tcdLName :: forall pass. TyClDecl pass -> LIdP pass
tcdLName = XRec (GhcPass p) (IdP (GhcPass p))
ln }) = XRec (GhcPass p) (IdP (GhcPass p))
GenLocated SrcSpanAnnN (IdP (GhcPass p))
ln

countTyClDecls :: [TyClDecl pass] -> (Int, Int, Int, Int, Int)
        -- class, synonym decls, data, newtype, family decls
countTyClDecls :: forall pass. [TyClDecl pass] -> (Int, Int, Int, Int, Int)
countTyClDecls [TyClDecl pass]
decls
 = ((TyClDecl pass -> Bool) -> [TyClDecl pass] -> Int
forall a. (a -> Bool) -> [a] -> Int
count TyClDecl pass -> Bool
forall pass. TyClDecl pass -> Bool
isClassDecl    [TyClDecl pass]
decls,
    (TyClDecl pass -> Bool) -> [TyClDecl pass] -> Int
forall a. (a -> Bool) -> [a] -> Int
count TyClDecl pass -> Bool
forall pass. TyClDecl pass -> Bool
isSynDecl      [TyClDecl pass]
decls,  -- excluding...
    (TyClDecl pass -> Bool) -> [TyClDecl pass] -> Int
forall a. (a -> Bool) -> [a] -> Int
count TyClDecl pass -> Bool
forall pass. TyClDecl pass -> Bool
isDataTy       [TyClDecl pass]
decls,  -- ...family...
    (TyClDecl pass -> Bool) -> [TyClDecl pass] -> Int
forall a. (a -> Bool) -> [a] -> Int
count TyClDecl pass -> Bool
forall pass. TyClDecl pass -> Bool
isNewTy        [TyClDecl pass]
decls,  -- ...instances
    (TyClDecl pass -> Bool) -> [TyClDecl pass] -> Int
forall a. (a -> Bool) -> [a] -> Int
count TyClDecl pass -> Bool
forall pass. TyClDecl pass -> Bool
isFamilyDecl   [TyClDecl pass]
decls)
 where
   isDataTy :: TyClDecl pass -> Bool
isDataTy DataDecl{ tcdDataDefn :: forall pass. TyClDecl pass -> HsDataDefn pass
tcdDataDefn = HsDataDefn { dd_cons :: forall pass. HsDataDefn pass -> DataDefnCons (LConDecl pass)
dd_cons = DataTypeCons Bool
_ [LConDecl pass]
_ } } = Bool
True
   isDataTy TyClDecl pass
_                                                       = Bool
False

   isNewTy :: TyClDecl pass -> Bool
isNewTy DataDecl{ tcdDataDefn :: forall pass. TyClDecl pass -> HsDataDefn pass
tcdDataDefn = HsDataDefn { dd_cons :: forall pass. HsDataDefn pass -> DataDefnCons (LConDecl pass)
dd_cons = NewTypeCon LConDecl pass
_ } } = Bool
True
   isNewTy TyClDecl pass
_                                                      = Bool
False

-- 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 = GenLocated SrcSpanAnnN (IdGhcP p) -> IdGhcP p
forall l e. GenLocated l e -> e
unLoc (GenLocated SrcSpanAnnN (IdGhcP p) -> IdGhcP p)
-> (TyClDecl (GhcPass p) -> GenLocated SrcSpanAnnN (IdGhcP p))
-> TyClDecl (GhcPass p)
-> IdGhcP p
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TyClDecl (GhcPass p) -> LocatedN (IdP (GhcPass p))
TyClDecl (GhcPass p) -> GenLocated SrcSpanAnnN (IdGhcP p)
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 SrcAnn NoEpAnns
_ FamilyResultSig GhcRn
resultSig } }) =
    case FamilyInfo GhcRn
fam_info of
      ClosedTypeFamily {} -> LHsQTyVars GhcRn -> Bool
forall (p :: Pass). LHsQTyVars (GhcPass p) -> Bool
hsTvbAllKinded LHsQTyVars GhcRn
tyvars
                          Bool -> Bool -> Bool
&& Maybe (GenLocated SrcSpanAnnA (HsType GhcRn)) -> Bool
forall a. Maybe a -> Bool
isJust (FamilyResultSig GhcRn -> Maybe (LHsKind GhcRn)
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 = LHsKind GhcRn
rhs })
  = LHsQTyVars GhcRn -> Bool
forall (p :: Pass). LHsQTyVars (GhcPass p) -> Bool
hsTvbAllKinded LHsQTyVars GhcRn
tyvars Bool -> Bool -> Bool
&& Maybe (GenLocated SrcSpanAnnA (HsType GhcRn)) -> Bool
forall a. Maybe a -> Bool
isJust (LHsKind GhcRn -> Maybe (LHsKind GhcRn)
forall (p :: Pass).
LHsType (GhcPass p) -> Maybe (LHsType (GhcPass p))
hsTyKindSig LHsKind 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 }) = LHsQTyVars GhcRn -> Bool
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 }) = FamilyDecl (GhcPass p) -> SDoc
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
forall doc. IsLine doc => String -> doc
text String
"type" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
              LIdP (GhcPass p)
-> LHsQTyVars (GhcPass p)
-> LexicalFixity
-> Maybe (LHsContext (GhcPass p))
-> 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 Maybe (LHsContext (GhcPass p))
Maybe
  (GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass p))])
forall a. Maybe a
Nothing SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
forall doc. IsLine doc => doc
equals)
          Int
4 (GenLocated SrcSpanAnnA (HsType (GhcPass p)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LHsType (GhcPass p)
GenLocated SrcSpanAnnA (HsType (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 })
      = (Maybe (LHsContext (GhcPass p)) -> SDoc)
-> HsDataDefn (GhcPass p) -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
(Maybe (LHsContext (GhcPass p)) -> SDoc)
-> HsDataDefn (GhcPass p) -> SDoc
pp_data_defn (LIdP (GhcPass p)
-> LHsQTyVars (GhcPass p)
-> LexicalFixity
-> Maybe (LHsContext (GhcPass p))
-> 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) 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})
      | [GenLocated SrcSpanAnnA (Sig (GhcPass p))] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LSig (GhcPass p)]
[GenLocated SrcSpanAnnA (Sig (GhcPass p))]
sigs Bool -> Bool -> Bool
&& Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))
-> Bool
forall a. Bag a -> Bool
isEmptyBag LHsBinds (GhcPass p)
Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))
methods Bool -> Bool -> Bool
&& [GenLocated SrcSpanAnnA (FamilyDecl (GhcPass p))] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LFamilyDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (FamilyDecl (GhcPass p))]
ats Bool -> Bool -> Bool
&& [GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass p))] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LTyFamDefltDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass p))]
at_defs -- No "where" part
      = SDoc
top_matter

      | Bool
otherwise       -- Laid out
      = [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ SDoc
top_matter SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"where"
             , Int -> SDoc -> SDoc
nest Int
2 (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ [SDoc] -> SDoc
pprDeclList ((GenLocated SrcSpanAnnA (FamilyDecl (GhcPass p)) -> SDoc)
-> [GenLocated SrcSpanAnnA (FamilyDecl (GhcPass p))] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (FamilyDecl (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr (FamilyDecl (GhcPass p) -> SDoc)
-> (GenLocated SrcSpanAnnA (FamilyDecl (GhcPass p))
    -> FamilyDecl (GhcPass p))
-> GenLocated SrcSpanAnnA (FamilyDecl (GhcPass p))
-> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (FamilyDecl (GhcPass p))
-> FamilyDecl (GhcPass p)
forall l e. GenLocated l e -> e
unLoc) [LFamilyDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (FamilyDecl (GhcPass p))]
ats [SDoc] -> [SDoc] -> [SDoc]
forall a. [a] -> [a] -> [a]
++
                                     (GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass p)) -> SDoc)
-> [GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass p))] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (TyFamInstDecl (GhcPass p) -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
TyFamDefltDecl (GhcPass p) -> SDoc
pprTyFamDefltDecl (TyFamInstDecl (GhcPass p) -> SDoc)
-> (GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass p))
    -> TyFamInstDecl (GhcPass p))
-> GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass p))
-> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass p))
-> TyFamInstDecl (GhcPass p)
forall l e. GenLocated l e -> e
unLoc) [LTyFamDefltDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass p))]
at_defs [SDoc] -> [SDoc] -> [SDoc]
forall a. [a] -> [a] -> [a]
++
                                     LHsBinds (GhcPass p) -> [LSig (GhcPass p)] -> [SDoc]
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
forall doc. IsLine doc => String -> doc
text String
"class"
                    SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> LIdP (GhcPass p)
-> LHsQTyVars (GhcPass p)
-> LexicalFixity
-> Maybe (LHsContext (GhcPass p))
-> 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 doc. IsLine doc => doc -> doc -> doc
<+> [FunDep (GhcPass p)] -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
[FunDep (GhcPass p)] -> SDoc
pprFundeps ((GenLocated SrcSpanAnnA (FunDep (GhcPass p)) -> FunDep (GhcPass p))
-> [GenLocated SrcSpanAnnA (FunDep (GhcPass p))]
-> [FunDep (GhcPass p)]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated SrcSpanAnnA (FunDep (GhcPass p)) -> FunDep (GhcPass p)
forall l e. GenLocated l e -> e
unLoc [LHsFunDep (GhcPass p)]
[GenLocated SrcSpanAnnA (FunDep (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
forall doc. IsLine doc => String -> doc
text String
"TyClGroup") Int
2 (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$
      [GenLocated SrcSpanAnnA (StandaloneKindSig (GhcPass p))] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [LStandaloneKindSig (GhcPass p)]
[GenLocated SrcSpanAnnA (StandaloneKindSig (GhcPass p))]
kisigs SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$
      [GenLocated SrcSpanAnnA (TyClDecl (GhcPass p))] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [LTyClDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (TyClDecl (GhcPass p))]
tyclds SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$
      [GenLocated SrcSpanAnnA (RoleAnnotDecl (GhcPass p))] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [LRoleAnnotDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (RoleAnnotDecl (GhcPass p))]
roles SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$
      [GenLocated SrcSpanAnnA (InstDecl (GhcPass p))] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [LInstDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (InstDecl (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
forall doc. IsLine doc => [doc] -> doc
hsep [Maybe (LHsContext (GhcPass p)) -> SDoc
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)]
[GenLocated SrcSpanAnnA (HsTyVarBndr () (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 LexicalFixity -> LexicalFixity -> Bool
forall a. Eq a => a -> a -> Bool
== LexicalFixity
Infix, GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
varr:varsr' :: [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))]
varsr'@(GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
_:[GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))]
_) <- [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))]
varsr
         -- If varsr has at least 2 elements, parenthesize.
         = [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep [Char -> SDoc
forall doc. IsLine doc => Char -> doc
char Char
'(',HsTyVarBndr () (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr (GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
-> HsTyVarBndr () (GhcPass p)
forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
varl), IdGhcP p -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprInfixOcc (GenLocated (Anno (IdGhcP p)) (IdGhcP p) -> IdGhcP p
forall l e. GenLocated l e -> e
unLoc XRec (GhcPass p) (IdP (GhcPass p))
GenLocated (Anno (IdGhcP p)) (IdGhcP p)
thing)
                , (HsTyVarBndr () (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr(HsTyVarBndr () (GhcPass p) -> SDoc)
-> (GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
    -> HsTyVarBndr () (GhcPass p))
-> GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
-> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
.GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
-> HsTyVarBndr () (GhcPass p)
forall l e. GenLocated l e -> e
unLoc) GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
varr, Char -> SDoc
forall doc. IsLine doc => Char -> doc
char Char
')'
                , [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep ((GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p)) -> SDoc)
-> [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (HsTyVarBndr () (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr(HsTyVarBndr () (GhcPass p) -> SDoc)
-> (GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
    -> HsTyVarBndr () (GhcPass p))
-> GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
-> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
.GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
-> HsTyVarBndr () (GhcPass p)
forall l e. GenLocated l e -> e
unLoc) [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))]
varsr')]
      | LexicalFixity
fixity LexicalFixity -> LexicalFixity -> Bool
forall a. Eq a => a -> a -> Bool
== LexicalFixity
Infix
         = [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep [HsTyVarBndr () (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr (GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
-> HsTyVarBndr () (GhcPass p)
forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
varl), IdGhcP p -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprInfixOcc (GenLocated (Anno (IdGhcP p)) (IdGhcP p) -> IdGhcP p
forall l e. GenLocated l e -> e
unLoc XRec (GhcPass p) (IdP (GhcPass p))
GenLocated (Anno (IdGhcP p)) (IdGhcP p)
thing)
         , [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep ((GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p)) -> SDoc)
-> [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (HsTyVarBndr () (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr(HsTyVarBndr () (GhcPass p) -> SDoc)
-> (GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
    -> HsTyVarBndr () (GhcPass p))
-> GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
-> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
.GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
-> HsTyVarBndr () (GhcPass p)
forall l e. GenLocated l e -> e
unLoc) [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))]
varsr)]
      | Bool
otherwise = [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep [ IdGhcP p -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (GenLocated (Anno (IdGhcP p)) (IdGhcP p) -> IdGhcP p
forall l e. GenLocated l e -> e
unLoc XRec (GhcPass p) (IdP (GhcPass p))
GenLocated (Anno (IdGhcP p)) (IdGhcP p)
thing)
                  , [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep ((GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p)) -> SDoc)
-> [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (HsTyVarBndr () (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr(HsTyVarBndr () (GhcPass p) -> SDoc)
-> (GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
    -> HsTyVarBndr () (GhcPass p))
-> GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
-> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
.GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
-> HsTyVarBndr () (GhcPass p)
forall l e. GenLocated l e -> e
unLoc) (GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
varlGenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
-> [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))]
-> [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))]
forall a. a -> [a] -> [a]
:[GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))]
varsr))]
    pp_tyvars [] = IdGhcP p -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (GenLocated (Anno (IdGhcP p)) (IdGhcP p) -> IdGhcP p
forall l e. GenLocated l e -> e
unLoc XRec (GhcPass p) (IdP (GhcPass p))
GenLocated (Anno (IdGhcP p)) (IdGhcP p)
thing)

pprTyClDeclFlavour :: TyClDecl (GhcPass p) -> SDoc
pprTyClDeclFlavour :: forall (p :: Pass). TyClDecl (GhcPass p) -> SDoc
pprTyClDeclFlavour (ClassDecl {})   = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"class"
pprTyClDeclFlavour (SynDecl {})     = String -> SDoc
forall doc. IsLine doc => String -> doc
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 }})
  = FamilyInfo (GhcPass p) -> SDoc
forall pass. FamilyInfo pass -> SDoc
pprFlavour FamilyInfo (GhcPass p)
info SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"family"
pprTyClDeclFlavour (DataDecl { tcdDataDefn :: forall pass. TyClDecl pass -> HsDataDefn pass
tcdDataDefn = HsDataDefn { dd_cons :: forall pass. HsDataDefn pass -> DataDefnCons (LConDecl pass)
dd_cons = DataDefnCons (LConDecl (GhcPass p))
nd } })
  = NewOrData -> SDoc
forall a. Outputable a => a -> SDoc
ppr (DataDefnCons (GenLocated SrcSpanAnnA (ConDecl (GhcPass p)))
-> NewOrData
forall a. DataDefnCons a -> NewOrData
dataDefnConsNewOrData DataDefnCons (LConDecl (GhcPass p))
DataDefnCons (GenLocated SrcSpanAnnA (ConDecl (GhcPass p)))
nd)

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

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

pprFundeps :: OutputableBndrId p => [FunDep (GhcPass p)] -> SDoc
pprFundeps :: forall (p :: Pass).
OutputableBndrId p =>
[FunDep (GhcPass p)] -> SDoc
pprFundeps []  = SDoc
forall doc. IsOutput doc => doc
empty
pprFundeps [FunDep (GhcPass p)]
fds = [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep (SDoc
forall doc. IsLine doc => doc
vbar SDoc -> [SDoc] -> [SDoc]
forall a. a -> [a] -> [a]
: SDoc -> [SDoc] -> [SDoc]
forall doc. IsLine doc => doc -> [doc] -> [doc]
punctuate SDoc
forall doc. IsLine doc => doc
comma ((FunDep (GhcPass p) -> SDoc) -> [FunDep (GhcPass p)] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map FunDep (GhcPass p) -> SDoc
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
forall doc. IsLine doc => [doc] -> doc
hsep [[GenLocated (Anno (IdGhcP p)) (IdGhcP p)] -> SDoc
forall a. Outputable a => [a] -> SDoc
interppSP [LIdP (GhcPass p)]
[GenLocated (Anno (IdGhcP p)) (IdGhcP p)]
us, SDoc
arrow, [GenLocated (Anno (IdGhcP p)) (IdGhcP p)] -> SDoc
forall a. Outputable a => [a] -> SDoc
interppSP [LIdP (GhcPass p)]
[GenLocated (Anno (IdGhcP p)) (IdGhcP p)]
vs]

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

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


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

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

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

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


------------- 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 = GenLocated (Anno (IdGhcP p)) (IdGhcP p) -> IdGhcP p
forall l e. GenLocated l e -> e
unLoc (GenLocated (Anno (IdGhcP p)) (IdGhcP p) -> IdGhcP p)
-> (FamilyDecl (GhcPass p)
    -> GenLocated (Anno (IdGhcP p)) (IdGhcP p))
-> FamilyDecl (GhcPass p)
-> IdGhcP p
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FamilyDecl (GhcPass p) -> XRec (GhcPass p) (IdP (GhcPass p))
FamilyDecl (GhcPass p) -> GenLocated (Anno (IdGhcP p)) (IdGhcP p)
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)
_) = Maybe (XRec (GhcPass p) (HsType (GhcPass p)))
Maybe (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
forall a. Maybe a
Nothing
famResultKindSignature (KindSig XCKindSig (GhcPass p)
_ XRec (GhcPass p) (HsType (GhcPass p))
ki) = GenLocated SrcSpanAnnA (HsType (GhcPass p))
-> Maybe (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
forall a. a -> Maybe a
Just XRec (GhcPass p) (HsType (GhcPass p))
GenLocated SrcSpanAnnA (HsType (GhcPass p))
ki
famResultKindSignature (TyVarSig XTyVarSig (GhcPass p)
_ LHsTyVarBndr () (GhcPass p)
bndr) =
  case GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
-> HsTyVarBndr () (GhcPass p)
forall l e. GenLocated l e -> e
unLoc LHsTyVarBndr () (GhcPass p)
GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass p))
bndr of
    UserTyVar XUserTyVar (GhcPass p)
_ ()
_ LIdP (GhcPass p)
_ -> Maybe (XRec (GhcPass p) (HsType (GhcPass p)))
Maybe (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
forall a. Maybe a
Nothing
    KindedTyVar XKindedTyVar (GhcPass p)
_ ()
_ LIdP (GhcPass p)
_ XRec (GhcPass p) (HsType (GhcPass p))
ki -> GenLocated SrcSpanAnnA (HsType (GhcPass p))
-> Maybe (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
forall a. a -> Maybe a
Just XRec (GhcPass p) (HsType (GhcPass p))
GenLocated SrcSpanAnnA (HsType (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) = IdP (GhcPass a) -> Maybe (IdP (GhcPass a))
forall a. a -> Maybe a
Just (IdP (GhcPass a) -> Maybe (IdP (GhcPass a)))
-> IdP (GhcPass a) -> Maybe (IdP (GhcPass a))
forall a b. (a -> b) -> a -> b
$ LHsTyVarBndr () (GhcPass a) -> IdP (GhcPass a)
forall flag (p :: Pass).
LHsTyVarBndr flag (GhcPass p) -> IdP (GhcPass p)
hsLTyVarName LHsTyVarBndr () (GhcPass a)
sig
resultVariableName FamilyResultSig (GhcPass a)
_                = Maybe (IdP (GhcPass a))
Maybe (IdGhcP a)
forall a. Maybe a
Nothing

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

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

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 SrcAnn NoEpAnns
_ FamilyResultSig (GhcPass p)
result
                  , fdInjectivityAnn :: forall pass. FamilyDecl pass -> Maybe (LInjectivityAnn pass)
fdInjectivityAnn = Maybe (LInjectivityAnn (GhcPass p))
mb_inj })
    = [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ FamilyInfo (GhcPass p) -> SDoc
forall pass. FamilyInfo pass -> SDoc
pprFlavour FamilyInfo (GhcPass p)
info SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
pp_top_level SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
             LIdP (GhcPass p)
-> LHsQTyVars (GhcPass p)
-> LexicalFixity
-> Maybe (LHsContext (GhcPass p))
-> 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 Maybe (LHsContext (GhcPass p))
Maybe
  (GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass p))])
forall a. Maybe a
Nothing SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
             SDoc
pp_kind SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
pp_inj SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
pp_where
           , Int -> SDoc -> SDoc
nest Int
2 (SDoc -> SDoc) -> SDoc -> SDoc
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
forall doc. IsLine doc => String -> doc
text String
"family"
                       TopLevelFlag
NotTopLevel -> SDoc
forall doc. IsOutput doc => doc
empty

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



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

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

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

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
forall doc. IsLine doc => [doc] -> doc
hsep [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"deriving"
           , SDoc
pp_strat_before
           , DerivClauseTys (GhcPass p) -> SDoc
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 SrcAnn NoEpAnns
_ via :: DerivStrategy (GhcPass p)
via@ViaStrategy{}) -> (SDoc
forall doc. IsOutput doc => doc
empty, DerivStrategy (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr DerivStrategy (GhcPass p)
via)
            Maybe (LDerivStrategy (GhcPass p))
_                            -> (Maybe (LDerivStrategy (GhcPass p)) -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
Maybe (LDerivStrategy (GhcPass p)) -> SDoc
ppDerivStrategy Maybe (LDerivStrategy (GhcPass p))
dcs, SDoc
forall doc. IsOutput doc => doc
empty)

-- | A short description of a @DerivStrategy'@.
derivStrategyName :: DerivStrategy a -> SDoc
derivStrategyName :: forall a. DerivStrategy a -> SDoc
derivStrategyName = String -> SDoc
forall doc. IsLine doc => String -> doc
text (String -> SDoc)
-> (DerivStrategy a -> String) -> DerivStrategy a -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DerivStrategy a -> String
forall {pass}. DerivStrategy pass -> String
go
  where
    go :: DerivStrategy pass -> String
go StockStrategy    {} = String
"stock"
    go AnyclassStrategy {} = String
"anyclass"
    go NewtypeStrategy  {} = String
"newtype"
    go ViaStrategy      {} = String
"via"

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

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

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

type instance XXStandaloneKindSig (GhcPass p) = DataConCantHappen

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)
_) = GenLocated (Anno (IdGhcP p)) (IdGhcP p) -> IdGhcP p
forall l e. GenLocated l e -> e
unLoc LIdP (GhcPass p)
GenLocated (Anno (IdGhcP p)) (IdGhcP p)
lname

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

type instance XXConDecl (GhcPass _) = DataConCantHappen

-- Codomain could be 'NonEmpty', but at the moment all users need a list.
getConNames :: ConDecl GhcRn -> [LocatedN Name]
getConNames :: ConDecl GhcRn -> [LocatedN SplicePointName]
getConNames ConDeclH98  {con_name :: forall pass. ConDecl pass -> LIdP pass
con_name  = LIdP GhcRn
name}  = [LIdP GhcRn
LocatedN SplicePointName
name]
getConNames ConDeclGADT {con_names :: forall pass. ConDecl pass -> NonEmpty (LIdP pass)
con_names = NonEmpty (LIdP GhcRn)
names} = NonEmpty (LocatedN SplicePointName) -> [LocatedN SplicePointName]
forall a. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList NonEmpty (LIdP GhcRn)
NonEmpty (LocatedN SplicePointName)
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{} -> Maybe (LocatedL [LConDeclField GhcRn])
Maybe (LocatedL [GenLocated SrcSpanAnnA (ConDeclField GhcRn)])
forall a. Maybe a
Nothing
  RecCon XRec GhcRn [LConDeclField GhcRn]
flds -> LocatedL [GenLocated SrcSpanAnnA (ConDeclField GhcRn)]
-> Maybe (LocatedL [GenLocated SrcSpanAnnA (ConDeclField GhcRn)])
forall a. a -> Maybe a
Just XRec GhcRn [LConDeclField GhcRn]
LocatedL [GenLocated SrcSpanAnnA (ConDeclField GhcRn)]
flds
  InfixCon{}  -> Maybe (LocatedL [LConDeclField GhcRn])
Maybe (LocatedL [GenLocated SrcSpanAnnA (ConDeclField GhcRn)])
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{} -> Maybe (LocatedL [LConDeclField GhcRn])
Maybe (LocatedL [GenLocated SrcSpanAnnA (ConDeclField GhcRn)])
forall a. Maybe a
Nothing
  RecConGADT XRec GhcRn [LConDeclField GhcRn]
flds LHsUniToken "->" "\8594" GhcRn
_ -> LocatedL [GenLocated SrcSpanAnnA (ConDeclField GhcRn)]
-> Maybe (LocatedL [GenLocated SrcSpanAnnA (ConDeclField GhcRn)])
forall a. a -> Maybe a
Just XRec GhcRn [LConDeclField GhcRn]
LocatedL [GenLocated SrcSpanAnnA (ConDeclField 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)) = [XRec (GhcPass p) (HsType (GhcPass p))]
[GenLocated SrcSpanAnnA (HsType (GhcPass p))]
theta

ppDataDefnHeader
 :: (OutputableBndrId p)
 => (Maybe (LHsContext (GhcPass p)) -> SDoc)   -- Printing the header
 -> HsDataDefn (GhcPass p)
 -> SDoc
ppDataDefnHeader :: forall (p :: Pass).
OutputableBndrId p =>
(Maybe (LHsContext (GhcPass p)) -> SDoc)
-> HsDataDefn (GhcPass p) -> SDoc
ppDataDefnHeader Maybe (LHsContext (GhcPass p)) -> SDoc
pp_hdr HsDataDefn
  { 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 -> DataDefnCons (LConDecl pass)
dd_cons = DataDefnCons (LConDecl (GhcPass p))
condecls }
  = SDoc
pp_type SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> NewOrData -> SDoc
forall a. Outputable a => a -> SDoc
ppr (DataDefnCons (GenLocated SrcSpanAnnA (ConDecl (GhcPass p)))
-> NewOrData
forall a. DataDefnCons a -> NewOrData
dataDefnConsNewOrData DataDefnCons (LConDecl (GhcPass p))
DataDefnCons (GenLocated SrcSpanAnnA (ConDecl (GhcPass p)))
condecls) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
pp_ct SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Maybe (LHsContext (GhcPass p)) -> SDoc
pp_hdr Maybe (LHsContext (GhcPass p))
context SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
pp_sig
  where
    pp_type :: SDoc
pp_type
      | DataDefnCons (GenLocated SrcSpanAnnA (ConDecl (GhcPass p))) -> Bool
forall a. DataDefnCons a -> Bool
isTypeDataDefnCons DataDefnCons (LConDecl (GhcPass p))
DataDefnCons (GenLocated SrcSpanAnnA (ConDecl (GhcPass p)))
condecls = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"type"
      | Bool
otherwise = SDoc
forall doc. IsOutput doc => doc
empty
    pp_ct :: SDoc
pp_ct = case Maybe (XRec (GhcPass p) CType)
mb_ct of
               Maybe (XRec (GhcPass p) CType)
Nothing   -> SDoc
forall doc. IsOutput doc => doc
empty
               Just XRec (GhcPass p) CType
ct -> GenLocated SrcSpanAnnP CType -> SDoc
forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) CType
GenLocated SrcSpanAnnP CType
ct
    pp_sig :: SDoc
pp_sig = case Maybe (LHsKind (GhcPass p))
mb_sig of
               Maybe (LHsKind (GhcPass p))
Nothing   -> SDoc
forall doc. IsOutput doc => doc
empty
               Just LHsKind (GhcPass p)
kind -> SDoc
dcolon SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> GenLocated SrcSpanAnnA (HsType (GhcPass p)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LHsKind (GhcPass p)
GenLocated SrcSpanAnnA (HsType (GhcPass p))
kind

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 defn :: HsDataDefn (GhcPass p)
defn@HsDataDefn
  { dd_cons :: forall pass. HsDataDefn pass -> DataDefnCons (LConDecl pass)
dd_cons = DataDefnCons (LConDecl (GhcPass p))
condecls
  , dd_derivs :: forall pass. HsDataDefn pass -> HsDeriving pass
dd_derivs = HsDeriving (GhcPass p)
derivings }
  | DataDefnCons (GenLocated SrcSpanAnnA (ConDecl (GhcPass p))) -> Bool
forall a. DataDefnCons a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null DataDefnCons (LConDecl (GhcPass p))
DataDefnCons (GenLocated SrcSpanAnnA (ConDecl (GhcPass p)))
condecls
  = (Maybe (LHsContext (GhcPass p)) -> SDoc)
-> HsDataDefn (GhcPass p) -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
(Maybe (LHsContext (GhcPass p)) -> SDoc)
-> HsDataDefn (GhcPass p) -> SDoc
ppDataDefnHeader Maybe (LHsContext (GhcPass p)) -> SDoc
pp_hdr HsDataDefn (GhcPass p)
defn SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [GenLocated (SrcAnn NoEpAnns) (HsDerivingClause (GhcPass p))]
-> SDoc
forall a. Outputable a => [a] -> SDoc
pp_derivings HsDeriving (GhcPass p)
[GenLocated (SrcAnn NoEpAnns) (HsDerivingClause (GhcPass p))]
derivings

  | Bool
otherwise
  = SDoc -> Int -> SDoc -> SDoc
hang ((Maybe (LHsContext (GhcPass p)) -> SDoc)
-> HsDataDefn (GhcPass p) -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
(Maybe (LHsContext (GhcPass p)) -> SDoc)
-> HsDataDefn (GhcPass p) -> SDoc
ppDataDefnHeader Maybe (LHsContext (GhcPass p)) -> SDoc
pp_hdr HsDataDefn (GhcPass p)
defn) Int
2 ([LConDecl (GhcPass p)] -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
[LConDecl (GhcPass p)] -> SDoc
pp_condecls (DataDefnCons (GenLocated SrcSpanAnnA (ConDecl (GhcPass p)))
-> [GenLocated SrcSpanAnnA (ConDecl (GhcPass p))]
forall a. DataDefnCons a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList DataDefnCons (LConDecl (GhcPass p))
DataDefnCons (GenLocated SrcSpanAnnA (ConDecl (GhcPass p)))
condecls) SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ [GenLocated (SrcAnn NoEpAnns) (HsDerivingClause (GhcPass p))]
-> SDoc
forall a. Outputable a => [a] -> SDoc
pp_derivings HsDeriving (GhcPass p)
[GenLocated (SrcAnn NoEpAnns) (HsDerivingClause (GhcPass p))]
derivings)
  where
    pp_derivings :: [a] -> SDoc
pp_derivings [a]
ds = [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat ((a -> SDoc) -> [a] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map a -> SDoc
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 = (Maybe (LHsContext (GhcPass p)) -> SDoc)
-> HsDataDefn (GhcPass p) -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
(Maybe (LHsContext (GhcPass p)) -> SDoc)
-> HsDataDefn (GhcPass p) -> SDoc
pp_data_defn (\Maybe (LHsContext (GhcPass p))
_ -> String -> SDoc
forall doc. IsLine doc => String -> doc
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
forall doc. IsLine doc => String -> doc
text String
"type" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> IdGhcP p -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (GenLocated (Anno (IdGhcP p)) (IdGhcP p) -> IdGhcP p
forall l e. GenLocated l e -> e
unLoc LIdP (GhcPass p)
GenLocated (Anno (IdGhcP p)) (IdGhcP p)
v) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"::" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> GenLocated SrcSpanAnnA (HsSigType (GhcPass p)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LHsSigType (GhcPass p)
GenLocated SrcSpanAnnA (HsSigType (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
  | [GenLocated SrcSpanAnnA (ConDecl (GhcPass p))] -> Bool
forall (f :: * -> *) l pass.
Foldable f =>
f (GenLocated l (ConDecl pass)) -> Bool
anyLConIsGadt [LConDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (ConDecl (GhcPass p))]
cs             -- In GADT syntax
  = SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"where") Int
2 ([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat ((GenLocated SrcSpanAnnA (ConDecl (GhcPass p)) -> SDoc)
-> [GenLocated SrcSpanAnnA (ConDecl (GhcPass p))] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated SrcSpanAnnA (ConDecl (GhcPass p)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr [LConDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (ConDecl (GhcPass p))]
cs))
  | Bool
otherwise                    -- In H98 syntax
  = SDoc
forall doc. IsLine doc => doc
equals SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
sep (SDoc -> [SDoc] -> [SDoc]
forall doc. IsLine doc => doc -> [doc] -> [doc]
punctuate (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
" |") ((GenLocated SrcSpanAnnA (ConDecl (GhcPass p)) -> SDoc)
-> [GenLocated SrcSpanAnnA (ConDecl (GhcPass p))] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated SrcSpanAnnA (ConDecl (GhcPass p)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr [LConDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (ConDecl (GhcPass p))]
cs))

instance (OutputableBndrId p) => Outputable (ConDecl (GhcPass p)) where
    ppr :: ConDecl (GhcPass p) -> SDoc
ppr = ConDecl (GhcPass p) -> SDoc
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 (LHsDoc pass)
con_doc = Maybe (LHsDoc (GhcPass p))
doc })
  = Maybe (LHsDoc (GhcPass p)) -> SDoc -> SDoc
forall name. Maybe (LHsDoc name) -> SDoc -> SDoc
pprMaybeWithDoc Maybe (LHsDoc (GhcPass p))
doc (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$
    [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
sep [ HsForAllTelescope (GhcPass p)
-> Maybe (LHsContext (GhcPass p)) -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
HsForAllTelescope (GhcPass p)
-> Maybe (LHsContext (GhcPass p)) -> SDoc
pprHsForAll (EpAnnForallTy
-> [LHsTyVarBndr Specificity (GhcPass p)]
-> HsForAllTelescope (GhcPass p)
forall (p :: Pass).
EpAnnForallTy
-> [LHsTyVarBndr Specificity (GhcPass p)]
-> HsForAllTelescope (GhcPass p)
mkHsForAllInvisTele EpAnnForallTy
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)
HsConDetails
  Void
  (HsScaled
     (GhcPass p) (GenLocated SrcSpanAnnA (HsType (GhcPass p))))
  (GenLocated
     SrcSpanAnnL [GenLocated SrcSpanAnnA (ConDeclField (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
forall doc. IsLine doc => [doc] -> doc
hsep [GenLocated SrcSpanAnnA (HsType (GhcPass p)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr (HsScaled (GhcPass p) (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
-> GenLocated SrcSpanAnnA (HsType (GhcPass p))
forall pass a. HsScaled pass a -> a
hsScaledThing HsScaled (GhcPass p) (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
t1),
                                         IdGhcP p -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprInfixOcc IdGhcP p
con,
                                         GenLocated SrcSpanAnnA (HsType (GhcPass p)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr (HsScaled (GhcPass p) (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
-> GenLocated SrcSpanAnnA (HsType (GhcPass p))
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
forall doc. IsLine doc => [doc] -> doc
hsep (IdGhcP p -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc IdGhcP p
con
                                    SDoc -> [SDoc] -> [SDoc]
forall a. a -> [a] -> [a]
: (HsScaled (GhcPass p) (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
 -> SDoc)
-> [HsScaled
      (GhcPass p) (GenLocated SrcSpanAnnA (HsType (GhcPass p)))]
-> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (HsType (GhcPass p) -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
HsType (GhcPass p) -> SDoc
pprHsType (HsType (GhcPass p) -> SDoc)
-> (HsScaled
      (GhcPass p) (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
    -> HsType (GhcPass p))
-> HsScaled
     (GhcPass p) (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
-> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (HsType (GhcPass p)) -> HsType (GhcPass p)
forall l e. GenLocated l e -> e
unLoc (GenLocated SrcSpanAnnA (HsType (GhcPass p)) -> HsType (GhcPass p))
-> (HsScaled
      (GhcPass p) (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
    -> GenLocated SrcSpanAnnA (HsType (GhcPass p)))
-> HsScaled
     (GhcPass p) (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
-> HsType (GhcPass p)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsScaled (GhcPass p) (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
-> GenLocated SrcSpanAnnA (HsType (GhcPass p))
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)  = IdGhcP p -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc IdGhcP p
con
                                 SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [LConDeclField (GhcPass p)] -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
[LConDeclField (GhcPass p)] -> SDoc
pprConDeclFields (GenLocated
  SrcSpanAnnL [GenLocated SrcSpanAnnA (ConDeclField (GhcPass p))]
-> [GenLocated SrcSpanAnnA (ConDeclField (GhcPass p))]
forall l e. GenLocated l e -> e
unLoc GenLocated
  SrcSpanAnnL [GenLocated SrcSpanAnnA (ConDeclField (GhcPass p))]
fields)

pprConDecl (ConDeclGADT { con_names :: forall pass. ConDecl pass -> NonEmpty (LIdP pass)
con_names = NonEmpty (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 (LHsDoc pass)
con_doc = Maybe (LHsDoc (GhcPass p))
doc })
  = Maybe (LHsDoc (GhcPass p)) -> SDoc -> SDoc
forall name. Maybe (LHsDoc name) -> SDoc -> SDoc
pprMaybeWithDoc Maybe (LHsDoc (GhcPass p))
doc (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ [GenLocated (Anno (IdGhcP p)) (IdGhcP p)] -> SDoc
forall a l. OutputableBndr a => [GenLocated l a] -> SDoc
ppr_con_names (NonEmpty (GenLocated (Anno (IdGhcP p)) (IdGhcP p))
-> [GenLocated (Anno (IdGhcP p)) (IdGhcP p)]
forall a. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList NonEmpty (LIdP (GhcPass p))
NonEmpty (GenLocated (Anno (IdGhcP p)) (IdGhcP p))
cons) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
dcolon
    SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ([SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
sep [HsOuterSigTyVarBndrs (GhcPass p) -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
HsOuterSigTyVarBndrs (GhcPass p) -> SDoc
pprHsOuterSigTyVarBndrs HsOuterSigTyVarBndrs (GhcPass p)
outer_bndrs SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Maybe (LHsContext (GhcPass p)) -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
Maybe (LHsContext (GhcPass p)) -> SDoc
pprLHsContext Maybe (LHsContext (GhcPass p))
mcxt,
              [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
sep (HsConDeclGADTDetails (GhcPass p) -> [SDoc]
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]
ppr_args HsConDeclGADTDetails (GhcPass p)
args [SDoc] -> [SDoc] -> [SDoc]
forall a. [a] -> [a] -> [a]
++ [GenLocated SrcSpanAnnA (HsType (GhcPass p)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LHsType (GhcPass p)
GenLocated SrcSpanAnnA (HsType (GhcPass p))
res_ty]) ])
  where
    ppr_args :: HsConDeclGADTDetails (GhcPass p) -> [SDoc]
ppr_args (PrefixConGADT [HsScaled (GhcPass p) (LBangType (GhcPass p))]
args) = (HsScaled (GhcPass p) (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
 -> SDoc)
-> [HsScaled
      (GhcPass p) (GenLocated SrcSpanAnnA (HsType (GhcPass p)))]
-> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (\(HsScaled HsArrow (GhcPass p)
arr GenLocated SrcSpanAnnA (HsType (GhcPass p))
t) -> GenLocated SrcSpanAnnA (HsType (GhcPass p)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr GenLocated SrcSpanAnnA (HsType (GhcPass p))
t SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> HsArrow (GhcPass p) -> SDoc
forall {pass :: Pass}.
(OutputableBndr (IdGhcP pass),
 OutputableBndr (IdGhcP (NoGhcTcPass pass)), IsPass pass,
 Outputable (GenLocated (Anno (IdGhcP pass)) (IdGhcP pass)),
 Outputable
   (GenLocated
      (Anno (IdGhcP (NoGhcTcPass pass))) (IdGhcP (NoGhcTcPass pass)))) =>
HsArrow (GhcPass pass) -> SDoc
ppr_arr HsArrow (GhcPass p)
arr) [HsScaled (GhcPass p) (LBangType (GhcPass p))]
[HsScaled
   (GhcPass p) (GenLocated SrcSpanAnnA (HsType (GhcPass p)))]
args
    ppr_args (RecConGADT XRec (GhcPass p) [LConDeclField (GhcPass p)]
fields LHsUniToken "->" "\8594" (GhcPass p)
_) = [[LConDeclField (GhcPass p)] -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
[LConDeclField (GhcPass p)] -> SDoc
pprConDeclFields (GenLocated
  SrcSpanAnnL [GenLocated SrcSpanAnnA (ConDeclField (GhcPass p))]
-> [GenLocated SrcSpanAnnA (ConDeclField (GhcPass p))]
forall l e. GenLocated l e -> e
unLoc XRec (GhcPass p) [LConDeclField (GhcPass p)]
GenLocated
  SrcSpanAnnL [GenLocated SrcSpanAnnA (ConDeclField (GhcPass p))]
fields) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
arrow]

    -- Display linear arrows as unrestricted with -XNoLinearTypes
    -- (cf. dataConDisplayType in Note [Displaying linear fields] in GHC.Core.DataCon)
    ppr_arr :: HsArrow (GhcPass pass) -> SDoc
ppr_arr (HsLinearArrow HsLinearArrowTokens (GhcPass pass)
_) = (SDocContext -> Bool) -> (Bool -> SDoc) -> SDoc
forall a. (SDocContext -> a) -> (a -> SDoc) -> SDoc
sdocOption SDocContext -> Bool
sdocLinearTypes ((Bool -> SDoc) -> SDoc) -> (Bool -> SDoc) -> SDoc
forall a b. (a -> b) -> a -> b
$ \Bool
show_linear_types ->
                                  if Bool
show_linear_types then SDoc
lollipop else SDoc
arrow
    ppr_arr HsArrow (GhcPass pass)
arr = HsArrow (GhcPass pass) -> SDoc
forall (pass :: Pass).
OutputableBndrId pass =>
HsArrow (GhcPass pass) -> SDoc
pprHsArrow HsArrow (GhcPass pass)
arr

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

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

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

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 _) = DataConCantHappen

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

type instance XClsInstD     (GhcPass _) = NoExtField

type instance XDataFamInstD (GhcPass _) = NoExtField

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

type instance XXInstDecl    (GhcPass _) = DataConCantHappen

instance OutputableBndrId p
       => Outputable (TyFamInstDecl (GhcPass p)) where
  ppr :: TyFamInstDecl (GhcPass p) -> SDoc
ppr = TopLevelFlag -> TyFamInstDecl (GhcPass p) -> SDoc
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
forall doc. IsLine doc => String -> doc
text String
"type" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> TopLevelFlag -> SDoc
ppr_instance_keyword TopLevelFlag
top_lvl SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> TyFamInstEqn (GhcPass p) -> 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
forall doc. IsLine doc => String -> doc
text String
"instance"
ppr_instance_keyword TopLevelFlag
NotTopLevel = SDoc
forall doc. IsOutput doc => doc
empty

pprTyFamDefltDecl :: (OutputableBndrId p)
                  => TyFamDefltDecl (GhcPass p) -> SDoc
pprTyFamDefltDecl :: forall (p :: Pass).
OutputableBndrId p =>
TyFamDefltDecl (GhcPass p) -> SDoc
pprTyFamDefltDecl = TopLevelFlag -> TyFamInstDecl (GhcPass p) -> SDoc
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 })
    = IdP (GhcPass p)
-> HsOuterFamEqnTyVarBndrs (GhcPass p)
-> HsTyPats (GhcPass p)
-> LexicalFixity
-> Maybe (LHsContext (GhcPass p))
-> SDoc
forall (p :: Pass).
OutputableBndrId p =>
IdP (GhcPass p)
-> HsOuterFamEqnTyVarBndrs (GhcPass p)
-> HsTyPats (GhcPass p)
-> LexicalFixity
-> Maybe (LHsContext (GhcPass p))
-> SDoc
pprHsFamInstLHS IdP (GhcPass p)
IdGhcP p
tycon HsOuterFamEqnTyVarBndrs (GhcPass p)
bndrs HsTyPats (GhcPass p)
pats LexicalFixity
fixity Maybe (LHsContext (GhcPass p))
Maybe
  (GenLocated
     SrcSpanAnnC [GenLocated SrcSpanAnnA (HsType (GhcPass p))])
forall a. Maybe a
Nothing SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
forall doc. IsLine doc => doc
equals SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> GenLocated SrcSpanAnnA (HsType (GhcPass p)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LHsType (GhcPass p)
GenLocated SrcSpanAnnA (HsType (GhcPass p))
rhs

instance OutputableBndrId p
       => Outputable (DataFamInstDecl (GhcPass p)) where
  ppr :: DataFamInstDecl (GhcPass p) -> SDoc
ppr = TopLevelFlag -> DataFamInstDecl (GhcPass p) -> SDoc
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 })})
  = (Maybe (LHsContext (GhcPass p)) -> SDoc)
-> HsDataDefn (GhcPass p) -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
(Maybe (LHsContext (GhcPass p)) -> SDoc)
-> HsDataDefn (GhcPass p) -> SDoc
pp_data_defn Maybe (LHsContext (GhcPass p)) -> SDoc
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 doc. IsLine doc => doc -> doc -> doc
<+> IdP (GhcPass p)
-> HsOuterFamEqnTyVarBndrs (GhcPass p)
-> HsTyPats (GhcPass p)
-> LexicalFixity
-> Maybe (LHsContext (GhcPass p))
-> SDoc
forall (p :: Pass).
OutputableBndrId p =>
IdP (GhcPass p)
-> HsOuterFamEqnTyVarBndrs (GhcPass p)
-> HsTyPats (GhcPass p)
-> LexicalFixity
-> Maybe (LHsContext (GhcPass p))
-> SDoc
pprHsFamInstLHS IdP (GhcPass p)
IdGhcP p
tycon HsOuterFamEqnTyVarBndrs (GhcPass p)
bndrs HsTyPats (GhcPass p)
pats LexicalFixity
fixity Maybe (LHsContext (GhcPass p))
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_cons :: forall pass. HsDataDefn pass -> DataDefnCons (LConDecl pass)
dd_cons = DataDefnCons (LConDecl (GhcPass p))
cons }}}
  = NewOrData -> SDoc
forall a. Outputable a => a -> SDoc
ppr (DataDefnCons (GenLocated SrcSpanAnnA (ConDecl (GhcPass p)))
-> NewOrData
forall a. DataDefnCons a -> NewOrData
dataDefnConsNewOrData DataDefnCons (LConDecl (GhcPass p))
DataDefnCons (GenLocated SrcSpanAnnA (ConDecl (GhcPass p)))
cons)

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
forall doc. IsLine doc => [doc] -> doc
hsep [ HsOuterFamEqnTyVarBndrs (GhcPass p) -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
HsOuterFamEqnTyVarBndrs (GhcPass p) -> SDoc
pprHsOuterFamEqnTyVarBndrs HsOuterFamEqnTyVarBndrs (GhcPass p)
bndrs
          , Maybe (LHsContext (GhcPass p)) -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
Maybe (LHsContext (GhcPass p)) -> SDoc
pprLHsContext Maybe (LHsContext (GhcPass p))
mb_ctxt
          , IdGhcP p
-> LexicalFixity
-> [HsArg
      (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
      (GenLocated SrcSpanAnnA (HsType (GhcPass p)))]
-> SDoc
forall id tm ty.
(OutputableBndr id, Outputable tm, Outputable ty) =>
id -> LexicalFixity -> [HsArg tm ty] -> SDoc
pprHsArgsApp IdP (GhcPass p)
IdGhcP p
thing LexicalFixity
fixity HsTyPats (GhcPass p)
[HsArg
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))
   (GenLocated SrcSpanAnnA (HsType (GhcPass p)))]
typats ]

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 })
      | [GenLocated SrcSpanAnnA (Sig (GhcPass p))] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LSig (GhcPass p)]
[GenLocated SrcSpanAnnA (Sig (GhcPass p))]
sigs, [GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass p))] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LTyFamInstDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass p))]
ats, [GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass p))] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LDataFamInstDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass p))]
adts, Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))
-> Bool
forall a. Bag a -> Bool
isEmptyBag LHsBinds (GhcPass p)
Bag (GenLocated SrcSpanAnnA (HsBindLR (GhcPass p) (GhcPass p)))
binds  -- No "where" part
      = SDoc
top_matter

      | Bool
otherwise       -- Laid out
      = [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ SDoc
top_matter SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"where"
             , Int -> SDoc -> SDoc
nest Int
2 (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ [SDoc] -> SDoc
pprDeclList ([SDoc] -> SDoc) -> [SDoc] -> SDoc
forall a b. (a -> b) -> a -> b
$
               (GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass p)) -> SDoc)
-> [GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass p))] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (TopLevelFlag -> TyFamInstDecl (GhcPass p) -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
TopLevelFlag -> TyFamInstDecl (GhcPass p) -> SDoc
pprTyFamInstDecl TopLevelFlag
NotTopLevel (TyFamInstDecl (GhcPass p) -> SDoc)
-> (GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass p))
    -> TyFamInstDecl (GhcPass p))
-> GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass p))
-> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass p))
-> TyFamInstDecl (GhcPass p)
forall l e. GenLocated l e -> e
unLoc)   [LTyFamInstDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (TyFamInstDecl (GhcPass p))]
ats [SDoc] -> [SDoc] -> [SDoc]
forall a. [a] -> [a] -> [a]
++
               (GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass p)) -> SDoc)
-> [GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass p))] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (TopLevelFlag -> DataFamInstDecl (GhcPass p) -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
TopLevelFlag -> DataFamInstDecl (GhcPass p) -> SDoc
pprDataFamInstDecl TopLevelFlag
NotTopLevel (DataFamInstDecl (GhcPass p) -> SDoc)
-> (GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass p))
    -> DataFamInstDecl (GhcPass p))
-> GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass p))
-> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass p))
-> DataFamInstDecl (GhcPass p)
forall l e. GenLocated l e -> e
unLoc) [LDataFamInstDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass p))]
adts [SDoc] -> [SDoc] -> [SDoc]
forall a. [a] -> [a] -> [a]
++
               LHsBinds (GhcPass p) -> [LSig (GhcPass p)] -> [SDoc]
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
forall doc. IsLine doc => String -> doc
text String
"instance" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Maybe (LocatedP OverlapMode) -> SDoc
ppOverlapPragma Maybe (XRec (GhcPass p) OverlapMode)
Maybe (LocatedP OverlapMode)
mbOverlap
                                             SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> GenLocated SrcSpanAnnA (HsSigType (GhcPass p)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LHsSigType (GhcPass p)
GenLocated SrcSpanAnnA (HsSigType (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
forall doc. IsOutput doc => doc
empty
    Just (L SrcAnn NoEpAnns
_ DerivStrategy (GhcPass p)
ds) -> DerivStrategy (GhcPass p) -> SDoc
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
forall doc. IsOutput doc => doc
empty
    Just (L SrcSpanAnnP
_ (NoOverlap SourceText
s))    -> SourceText -> String -> SDoc
forall {doc}. IsLine doc => SourceText -> String -> doc
maybe_stext SourceText
s String
"{-# NO_OVERLAP #-}"
    Just (L SrcSpanAnnP
_ (Overlappable SourceText
s)) -> SourceText -> String -> SDoc
forall {doc}. IsLine doc => SourceText -> String -> doc
maybe_stext SourceText
s String
"{-# OVERLAPPABLE #-}"
    Just (L SrcSpanAnnP
_ (Overlapping SourceText
s))  -> SourceText -> String -> SDoc
forall {doc}. IsLine doc => SourceText -> String -> doc
maybe_stext SourceText
s String
"{-# OVERLAPPING #-}"
    Just (L SrcSpanAnnP
_ (Overlaps SourceText
s))     -> SourceText -> String -> SDoc
forall {doc}. IsLine doc => SourceText -> String -> doc
maybe_stext SourceText
s String
"{-# OVERLAPS #-}"
    Just (L SrcSpanAnnP
_ (Incoherent SourceText
s))   -> SourceText -> String -> SDoc
forall {doc}. IsLine doc => SourceText -> String -> doc
maybe_stext SourceText
s String
"{-# INCOHERENT #-}"
  where
    maybe_stext :: SourceText -> String -> doc
maybe_stext SourceText
NoSourceText     String
alt = String -> doc
forall doc. IsLine doc => String -> doc
text String
alt
    maybe_stext (SourceText String
src) String
_   = String -> doc
forall doc. IsLine doc => String -> doc
text String
src doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> doc
forall doc. IsLine doc => String -> doc
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 }) = ClsInstDecl (GhcPass p) -> SDoc
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 }) = TyFamInstDecl (GhcPass p) -> SDoc
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 }) = DataFamInstDecl (GhcPass p) -> SDoc
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
  = (GenLocated SrcSpanAnnA (InstDecl (GhcPass p))
 -> [DataFamInstDecl (GhcPass p)])
-> [GenLocated SrcSpanAnnA (InstDecl (GhcPass p))]
-> [DataFamInstDecl (GhcPass p)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap LInstDecl (GhcPass p) -> [DataFamInstDecl (GhcPass p)]
GenLocated SrcSpanAnnA (InstDecl (GhcPass p))
-> [DataFamInstDecl (GhcPass p)]
forall (p :: Pass).
LInstDecl (GhcPass p) -> [DataFamInstDecl (GhcPass p)]
do_one [LInstDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (InstDecl (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 } }))
      = (GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass p))
 -> DataFamInstDecl (GhcPass p))
-> [GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass p))]
-> [DataFamInstDecl (GhcPass p)]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated SrcSpanAnnA (DataFamInstDecl (GhcPass p))
-> DataFamInstDecl (GhcPass p)
forall l e. GenLocated l e -> e
unLoc [LDataFamInstDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (DataFamInstDecl (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 {}))                              = []

-- | Convert a 'NewOrData' to a 'TyConFlavour'
newOrDataToFlavour :: NewOrData -> TyConFlavour
newOrDataToFlavour :: NewOrData -> TyConFlavour
newOrDataToFlavour NewOrData
NewType  = TyConFlavour
NewtypeFlavour
newOrDataToFlavour NewOrData
DataType = TyConFlavour
DataTypeFlavour

instance Outputable NewOrData where
  ppr :: NewOrData -> SDoc
ppr NewOrData
NewType  = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"newtype"
  ppr NewOrData
DataType = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"data"

-- At the moment we only call this with @f = '[]'@ and @f = 'DataDefnCons'@.
anyLConIsGadt :: Foldable f => f (GenLocated l (ConDecl pass)) -> Bool
anyLConIsGadt :: forall (f :: * -> *) l pass.
Foldable f =>
f (GenLocated l (ConDecl pass)) -> Bool
anyLConIsGadt f (GenLocated l (ConDecl pass))
xs = case f (GenLocated l (ConDecl pass)) -> [GenLocated l (ConDecl pass)]
forall a. f a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList f (GenLocated l (ConDecl pass))
xs of
    L l
_ ConDeclGADT {} : [GenLocated l (ConDecl pass)]
_ -> Bool
True
    [GenLocated l (ConDecl pass)]
_ -> Bool
False
{-# SPECIALIZE anyLConIsGadt :: [GenLocated l (ConDecl pass)] -> Bool #-}
{-# SPECIALIZE anyLConIsGadt :: DataDefnCons (GenLocated l (ConDecl pass)) -> Bool #-}

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

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

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
forall doc. IsLine doc => [doc] -> doc
hsep [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"deriving"
               , Maybe (LDerivStrategy (GhcPass p)) -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
Maybe (LDerivStrategy (GhcPass p)) -> SDoc
ppDerivStrategy Maybe (LDerivStrategy (GhcPass p))
ds
               , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"instance"
               , Maybe (LocatedP OverlapMode) -> SDoc
ppOverlapPragma Maybe (XRec (GhcPass p) OverlapMode)
Maybe (LocatedP OverlapMode)
o
               , HsWildCardBndrs
  (GhcPass p) (GenLocated SrcSpanAnnA (HsSigType (GhcPass p)))
-> SDoc
forall a. Outputable a => a -> SDoc
ppr LHsSigWcType (GhcPass p)
HsWildCardBndrs
  (GhcPass p) (GenLocated SrcSpanAnnA (HsSigType (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
forall doc. IsLine doc => String -> doc
text String
"stock"
    ppr (AnyclassStrategy XAnyClassStrategy (GhcPass p)
_) = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"anyclass"
    ppr (NewtypeStrategy  XNewtypeStrategy (GhcPass p)
_) = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"newtype"
    ppr (ViaStrategy XViaStrategy (GhcPass p)
ty)     = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"via" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> case forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p of
                                                GhcPass p
GhcPs -> XViaStrategyPs -> SDoc
forall a. Outputable a => a -> SDoc
ppr XViaStrategy (GhcPass p)
XViaStrategyPs
ty
                                                GhcPass p
GhcRn -> GenLocated SrcSpanAnnA (HsSigType GhcRn) -> SDoc
forall a. Outputable a => a -> SDoc
ppr XViaStrategy (GhcPass p)
GenLocated SrcSpanAnnA (HsSigType GhcRn)
ty
                                                GhcPass p
GhcTc -> Type -> SDoc
forall a. Outputable a => a -> SDoc
ppr XViaStrategy (GhcPass p)
Type
ty

instance Outputable XViaStrategyPs where
    ppr :: XViaStrategyPs -> SDoc
ppr (XViaStrategyPs EpAnn [AddEpAnn]
_ LHsSigType GhcPs
t) = GenLocated SrcSpanAnnA (HsSigType GhcPs) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LHsSigType GhcPs
GenLocated SrcSpanAnnA (HsSigType 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 = DerivStrategy p
-> (XViaStrategy p -> DerivStrategy p)
-> DerivStrategy p
-> DerivStrategy p
forall p (pass :: Pass) r.
(p ~ GhcPass pass) =>
r -> (XViaStrategy p -> r) -> DerivStrategy p -> r
foldDerivStrategy DerivStrategy p
ds (XViaStrategy p -> DerivStrategy p
XViaStrategy (GhcPass pass) -> DerivStrategy p
forall pass. XViaStrategy pass -> DerivStrategy pass
ViaStrategy (XViaStrategy (GhcPass pass) -> DerivStrategy p)
-> (XViaStrategy (GhcPass pass) -> XViaStrategy (GhcPass pass))
-> XViaStrategy (GhcPass pass)
-> DerivStrategy p
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XViaStrategy p -> XViaStrategy p
XViaStrategy (GhcPass pass) -> XViaStrategy (GhcPass pass)
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 _) = DataConCantHappen

instance OutputableBndrId p
       => Outputable (DefaultDecl (GhcPass p)) where
    ppr :: DefaultDecl (GhcPass p) -> SDoc
ppr (DefaultDecl XCDefaultDecl (GhcPass p)
_ [LHsType (GhcPass p)]
tys)
      = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"default" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens ([GenLocated SrcSpanAnnA (HsType (GhcPass p))] -> SDoc
forall a. Outputable a => [a] -> SDoc
interpp'SP [LHsType (GhcPass p)]
[GenLocated SrcSpanAnnA (HsType (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 _) = DataConCantHappen

type instance XCImport (GhcPass _) = Located SourceText -- original source text for the C entity
type instance XXForeignImport  (GhcPass _) = DataConCantHappen

type instance XCExport (GhcPass _) = Located SourceText -- original source text for the C entity
type instance XXForeignExport  (GhcPass _) = DataConCantHappen

-- pretty printing of foreign declarations

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 pass
fd_fi = ForeignImport (GhcPass p)
fimport })
    = SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"foreign import" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ForeignImport (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr ForeignImport (GhcPass p)
fimport SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> GenLocated (Anno (IdGhcP p)) (IdGhcP p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LIdP (GhcPass p)
GenLocated (Anno (IdGhcP p)) (IdGhcP p)
n)
         Int
2 (SDoc
dcolon SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> GenLocated SrcSpanAnnA (HsSigType (GhcPass p)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LHsSigType (GhcPass p)
GenLocated SrcSpanAnnA (HsSigType (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 pass
fd_fe = ForeignExport (GhcPass p)
fexport }) =
    SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"foreign export" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ForeignExport (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr ForeignExport (GhcPass p)
fexport SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> GenLocated (Anno (IdGhcP p)) (IdGhcP p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LIdP (GhcPass p)
GenLocated (Anno (IdGhcP p)) (IdGhcP p)
n)
       Int
2 (SDoc
dcolon SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> GenLocated SrcSpanAnnA (HsSigType (GhcPass p)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LHsSigType (GhcPass p)
GenLocated SrcSpanAnnA (HsSigType (GhcPass p))
ty)

instance OutputableBndrId p
       => Outputable (ForeignImport (GhcPass p)) where
  ppr :: ForeignImport (GhcPass p) -> SDoc
ppr (CImport (L SrcSpan
_ SourceText
srcText) XRec (GhcPass p) CCallConv
cconv XRec (GhcPass p) Safety
safety Maybe Header
mHeader CImportSpec
spec) =
    GenLocated SrcSpan CCallConv -> SDoc
forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) CCallConv
GenLocated SrcSpan CCallConv
cconv SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> GenLocated SrcSpan Safety -> SDoc
forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) Safety
GenLocated SrcSpan Safety
safety
      SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SourceText -> SDoc -> SDoc
pprWithSourceText SourceText
srcText (CImportSpec -> String -> SDoc
pprCEntity CImportSpec
spec String
"")
    where
      pp_hdr :: SDoc
pp_hdr = case Maybe Header
mHeader of
               Maybe Header
Nothing -> SDoc
forall doc. IsOutput doc => doc
empty
               Just (Header SourceText
_ CLabelString
header) -> CLabelString -> SDoc
forall doc. IsLine doc => CLabelString -> doc
ftext CLabelString
header

      pprCEntity :: CImportSpec -> String -> SDoc
pprCEntity (CLabel CLabelString
lbl) String
_ =
        SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
doubleQuotes (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"static" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
pp_hdr SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Char -> SDoc
forall doc. IsLine doc => Char -> doc
char Char
'&' SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> CLabelString -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabelString
lbl
      pprCEntity (CFunction (StaticTarget SourceText
st CLabelString
_lbl Maybe Unit
_ Bool
isFun)) String
src =
        if Bool
dqNeeded then SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
doubleQuotes SDoc
ce else SDoc
forall doc. IsOutput doc => doc
empty
          where
            dqNeeded :: Bool
dqNeeded = (Int -> String -> String
forall a. Int -> [a] -> [a]
take Int
6 String
src String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"static")
                    Bool -> Bool -> Bool
|| Maybe Header -> Bool
forall a. Maybe a -> Bool
isJust Maybe Header
mHeader
                    Bool -> Bool -> Bool
|| Bool -> Bool
not Bool
isFun
                    Bool -> Bool -> Bool
|| SourceText
st SourceText -> SourceText -> Bool
forall a. Eq a => a -> a -> Bool
/= SourceText
NoSourceText
            ce :: SDoc
ce =
                  -- We may need to drop leading spaces first
                  (if Int -> String -> String
forall a. Int -> [a] -> [a]
take Int
6 String
src String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"static" then String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"static" else SDoc
forall doc. IsOutput doc => doc
empty)
              SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
pp_hdr
              SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> (if Bool
isFun then SDoc
forall doc. IsOutput doc => doc
empty else String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"value")
              SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> (SourceText -> SDoc -> SDoc
pprWithSourceText SourceText
st SDoc
forall doc. IsOutput doc => doc
empty)
      pprCEntity (CFunction CCallTarget
DynamicTarget) String
_ =
        SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
doubleQuotes (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"dynamic"
      pprCEntity CImportSpec
CWrapper String
_ = SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
doubleQuotes (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"wrapper"

instance OutputableBndrId p
       => Outputable (ForeignExport (GhcPass p)) where
  ppr :: ForeignExport (GhcPass p) -> SDoc
ppr (CExport XCExport (GhcPass p)
_ (L SrcSpan
_ (CExportStatic SourceText
_ CLabelString
lbl CCallConv
cconv))) =
    CCallConv -> SDoc
forall a. Outputable a => a -> SDoc
ppr CCallConv
cconv SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Char -> SDoc
forall doc. IsLine doc => Char -> doc
char Char
'"' SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> CLabelString -> SDoc
forall a. Outputable a => a -> SDoc
ppr CLabelString
lbl SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> Char -> SDoc
forall doc. IsLine doc => Char -> doc
char Char
'"'

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

type instance XCRuleDecls    GhcPs = (EpAnn [AddEpAnn], SourceText)
type instance XCRuleDecls    GhcRn = SourceText
type instance XCRuleDecls    GhcTc = SourceText

type instance XXRuleDecls    (GhcPass _) = DataConCantHappen

type instance XHsRule       GhcPs = (EpAnn HsRuleAnn, SourceText)
type instance XHsRule       GhcRn = (HsRuleRn, SourceText)
type instance XHsRule       GhcTc = (HsRuleRn, SourceText)

data HsRuleRn = HsRuleRn NameSet NameSet -- Free-vars from the LHS and RHS
  deriving Typeable HsRuleRn
Typeable HsRuleRn =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> HsRuleRn -> c HsRuleRn)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c HsRuleRn)
-> (HsRuleRn -> Constr)
-> (HsRuleRn -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c HsRuleRn))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c HsRuleRn))
-> ((forall b. Data b => b -> b) -> HsRuleRn -> HsRuleRn)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> HsRuleRn -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> HsRuleRn -> r)
-> (forall u. (forall d. Data d => d -> u) -> HsRuleRn -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> HsRuleRn -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> HsRuleRn -> m HsRuleRn)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> HsRuleRn -> m HsRuleRn)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> HsRuleRn -> m HsRuleRn)
-> Data HsRuleRn
HsRuleRn -> Constr
HsRuleRn -> DataType
(forall b. Data b => b -> b) -> HsRuleRn -> HsRuleRn
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) -> HsRuleRn -> u
forall u. (forall d. Data d => d -> u) -> HsRuleRn -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> HsRuleRn -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> HsRuleRn -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> HsRuleRn -> m HsRuleRn
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HsRuleRn -> m HsRuleRn
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c HsRuleRn
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> HsRuleRn -> c HsRuleRn
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c HsRuleRn)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c HsRuleRn)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> HsRuleRn -> c HsRuleRn
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> HsRuleRn -> c HsRuleRn
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c HsRuleRn
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c HsRuleRn
$ctoConstr :: HsRuleRn -> Constr
toConstr :: HsRuleRn -> Constr
$cdataTypeOf :: HsRuleRn -> DataType
dataTypeOf :: HsRuleRn -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c HsRuleRn)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c HsRuleRn)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c HsRuleRn)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c HsRuleRn)
$cgmapT :: (forall b. Data b => b -> b) -> HsRuleRn -> HsRuleRn
gmapT :: (forall b. Data b => b -> b) -> HsRuleRn -> HsRuleRn
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> HsRuleRn -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> HsRuleRn -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> HsRuleRn -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> HsRuleRn -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> HsRuleRn -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> HsRuleRn -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> HsRuleRn -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> HsRuleRn -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> HsRuleRn -> m HsRuleRn
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> HsRuleRn -> m HsRuleRn
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HsRuleRn -> m HsRuleRn
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HsRuleRn -> m HsRuleRn
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HsRuleRn -> m HsRuleRn
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HsRuleRn -> m HsRuleRn
Data

type instance XXRuleDecl    (GhcPass _) = DataConCantHappen

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
Typeable HsRuleAnn =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> HsRuleAnn -> c HsRuleAnn)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c HsRuleAnn)
-> (HsRuleAnn -> Constr)
-> (HsRuleAnn -> DataType)
-> (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))
-> ((forall b. Data b => b -> b) -> HsRuleAnn -> HsRuleAnn)
-> (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 u. (forall d. Data d => d -> u) -> HsRuleAnn -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> HsRuleAnn -> u)
-> (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 (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> HsRuleAnn -> m HsRuleAnn)
-> Data HsRuleAnn
HsRuleAnn -> Constr
HsRuleAnn -> DataType
(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)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> HsRuleAnn -> c HsRuleAnn
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> HsRuleAnn -> c HsRuleAnn
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c HsRuleAnn
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c HsRuleAnn
$ctoConstr :: HsRuleAnn -> Constr
toConstr :: HsRuleAnn -> Constr
$cdataTypeOf :: HsRuleAnn -> DataType
dataTypeOf :: HsRuleAnn -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c HsRuleAnn)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c HsRuleAnn)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c HsRuleAnn)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c HsRuleAnn)
$cgmapT :: (forall b. Data b => b -> b) -> HsRuleAnn -> HsRuleAnn
gmapT :: (forall b. Data b => b -> b) -> HsRuleAnn -> HsRuleAnn
$cgmapQl :: 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
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> HsRuleAnn -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> HsRuleAnn -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> HsRuleAnn -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> HsRuleAnn -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> HsRuleAnn -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> HsRuleAnn -> u
$cgmapM :: forall (m :: * -> *).
Monad 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
$cgmapMp :: 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
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HsRuleAnn -> m HsRuleAnn
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> HsRuleAnn -> m HsRuleAnn
Data, HsRuleAnn -> HsRuleAnn -> Bool
(HsRuleAnn -> HsRuleAnn -> Bool)
-> (HsRuleAnn -> HsRuleAnn -> Bool) -> Eq HsRuleAnn
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HsRuleAnn -> HsRuleAnn -> Bool
== :: HsRuleAnn -> HsRuleAnn -> Bool
$c/= :: HsRuleAnn -> HsRuleAnn -> Bool
/= :: 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 = (GenLocated SrcSpanAnnA (RuleDecls (GhcPass p))
 -> [GenLocated SrcSpanAnnA (RuleDecl (GhcPass p))])
-> [GenLocated SrcSpanAnnA (RuleDecls (GhcPass p))]
-> [GenLocated SrcSpanAnnA (RuleDecl (GhcPass p))]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (RuleDecls (GhcPass p) -> [XRec (GhcPass p) (RuleDecl (GhcPass p))]
RuleDecls (GhcPass p)
-> [GenLocated SrcSpanAnnA (RuleDecl (GhcPass p))]
forall pass. RuleDecls pass -> [LRuleDecl pass]
rds_rules (RuleDecls (GhcPass p)
 -> [GenLocated SrcSpanAnnA (RuleDecl (GhcPass p))])
-> (GenLocated SrcSpanAnnA (RuleDecls (GhcPass p))
    -> RuleDecls (GhcPass p))
-> GenLocated SrcSpanAnnA (RuleDecls (GhcPass p))
-> [GenLocated SrcSpanAnnA (RuleDecl (GhcPass p))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpanAnnA (RuleDecls (GhcPass p))
-> RuleDecls (GhcPass p)
forall l e. GenLocated l e -> e
unLoc) [LRuleDecls (GhcPass p)]
[GenLocated SrcSpanAnnA (RuleDecls (GhcPass p))]
decls

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

instance (OutputableBndrId p) => Outputable (RuleDecls (GhcPass p)) where
  ppr :: RuleDecls (GhcPass p) -> SDoc
ppr (HsRules { rds_ext :: forall pass. RuleDecls pass -> XCRuleDecls pass
rds_ext = XCRuleDecls (GhcPass p)
ext
               , rds_rules :: forall pass. RuleDecls pass -> [LRuleDecl pass]
rds_rules = [LRuleDecl (GhcPass p)]
rules })
    = SourceText -> SDoc -> SDoc
pprWithSourceText SourceText
st (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"{-# RULES")
          SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat (SDoc -> [SDoc] -> [SDoc]
forall doc. IsLine doc => doc -> [doc] -> [doc]
punctuate SDoc
forall doc. IsLine doc => doc
semi ((GenLocated SrcSpanAnnA (RuleDecl (GhcPass p)) -> SDoc)
-> [GenLocated SrcSpanAnnA (RuleDecl (GhcPass p))] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated SrcSpanAnnA (RuleDecl (GhcPass p)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr [LRuleDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (RuleDecl (GhcPass p))]
rules)) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"#-}"
              where st :: SourceText
st = case forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p of
                           GhcPass p
GhcPs | (EpAnn [AddEpAnn]
_, SourceText
st) <- XCRuleDecls (GhcPass p)
ext -> SourceText
st
                           GhcPass p
GhcRn -> XCRuleDecls (GhcPass p)
SourceText
ext
                           GhcPass p
GhcTc -> XCRuleDecls (GhcPass p)
SourceText
ext

instance (OutputableBndrId p) => Outputable (RuleDecl (GhcPass p)) where
  ppr :: RuleDecl (GhcPass p) -> SDoc
ppr (HsRule { rd_ext :: forall pass. RuleDecl pass -> XHsRule pass
rd_ext  = XHsRule (GhcPass p)
ext
              , rd_name :: forall pass. RuleDecl pass -> XRec pass CLabelString
rd_name = XRec (GhcPass p) CLabelString
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
forall doc. IsLine doc => [doc] -> doc
sep [SourceText -> GenLocated (Anno CLabelString) CLabelString -> SDoc
forall a. SourceText -> GenLocated a CLabelString -> SDoc
pprFullRuleName SourceText
st XRec (GhcPass p) CLabelString
GenLocated (Anno CLabelString) CLabelString
name SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Activation -> SDoc
forall a. Outputable a => a -> SDoc
ppr Activation
act,
               Int -> SDoc -> SDoc
nest Int
4 (Maybe
  [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass (NoGhcTcPass p)))]
-> SDoc
forall {a}. Outputable a => Maybe [a] -> SDoc
pp_forall_ty Maybe [LHsTyVarBndr () (NoGhcTc (GhcPass p))]
Maybe
  [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass (NoGhcTcPass p)))]
tys SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Maybe
  [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass (NoGhcTcPass p)))]
-> SDoc
pp_forall_tm Maybe [LHsTyVarBndr () (NoGhcTc (GhcPass p))]
Maybe
  [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass (NoGhcTcPass p)))]
tys
                                        SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> HsExpr (GhcPass p) -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> SDoc
pprExpr (GenLocated (Anno (HsExpr (GhcPass p))) (HsExpr (GhcPass p))
-> HsExpr (GhcPass p)
forall l e. GenLocated l e -> e
unLoc XRec (GhcPass p) (HsExpr (GhcPass p))
GenLocated (Anno (HsExpr (GhcPass p))) (HsExpr (GhcPass p))
lhs)),
               Int -> SDoc -> SDoc
nest Int
6 (SDoc
forall doc. IsLine doc => doc
equals SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> HsExpr (GhcPass p) -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> SDoc
pprExpr (GenLocated (Anno (HsExpr (GhcPass p))) (HsExpr (GhcPass p))
-> HsExpr (GhcPass p)
forall l e. GenLocated l e -> e
unLoc XRec (GhcPass p) (HsExpr (GhcPass p))
GenLocated (Anno (HsExpr (GhcPass p))) (HsExpr (GhcPass p))
rhs)) ]
        where
          pp_forall_ty :: Maybe [a] -> SDoc
pp_forall_ty Maybe [a]
Nothing     = SDoc
forall doc. IsOutput doc => doc
empty
          pp_forall_ty (Just [a]
qtvs) = SDoc
forAllLit SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
fsep ((a -> SDoc) -> [a] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map a -> SDoc
forall a. Outputable a => a -> SDoc
ppr [a]
qtvs) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
dot
          pp_forall_tm :: Maybe
  [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass (NoGhcTcPass p)))]
-> SDoc
pp_forall_tm Maybe
  [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass (NoGhcTcPass p)))]
Nothing | [GenLocated (SrcAnn NoEpAnns) (RuleBndr (GhcPass p))] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LRuleBndr (GhcPass p)]
[GenLocated (SrcAnn NoEpAnns) (RuleBndr (GhcPass p))]
tms = SDoc
forall doc. IsOutput doc => doc
empty
          pp_forall_tm Maybe
  [GenLocated SrcSpanAnnA (HsTyVarBndr () (GhcPass (NoGhcTcPass p)))]
_ = SDoc
forAllLit SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
fsep ((GenLocated (SrcAnn NoEpAnns) (RuleBndr (GhcPass p)) -> SDoc)
-> [GenLocated (SrcAnn NoEpAnns) (RuleBndr (GhcPass p))] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated (SrcAnn NoEpAnns) (RuleBndr (GhcPass p)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr [LRuleBndr (GhcPass p)]
[GenLocated (SrcAnn NoEpAnns) (RuleBndr (GhcPass p))]
tms) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
dot
          st :: SourceText
st = case forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p of
                 GhcPass p
GhcPs | (EpAnn HsRuleAnn
_, SourceText
st) <- XHsRule (GhcPass p)
ext -> SourceText
st
                 GhcPass p
GhcRn | (HsRuleRn
_, SourceText
st) <- XHsRule (GhcPass p)
ext -> SourceText
st
                 GhcPass p
GhcTc | (HsRuleRn
_, SourceText
st) <- XHsRule (GhcPass p)
ext -> SourceText
st

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

pprFullRuleName :: SourceText -> GenLocated a (RuleName) -> SDoc
pprFullRuleName :: forall a. SourceText -> GenLocated a CLabelString -> SDoc
pprFullRuleName SourceText
st (L a
_ CLabelString
n) = SourceText -> SDoc -> SDoc
pprWithSourceText SourceText
st (SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
doubleQuotes (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ CLabelString -> SDoc
forall doc. IsLine doc => CLabelString -> doc
ftext CLabelString
n)


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

type instance XWarnings      GhcPs = (EpAnn [AddEpAnn], SourceText)
type instance XWarnings      GhcRn = SourceText
type instance XWarnings      GhcTc = SourceText

type instance XXWarnDecls    (GhcPass _) = DataConCantHappen

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


instance OutputableBndrId p
        => Outputable (WarnDecls (GhcPass p)) where
    ppr :: WarnDecls (GhcPass p) -> SDoc
ppr (Warnings XWarnings (GhcPass p)
ext [LWarnDecl (GhcPass p)]
decls)
      = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
src SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat (SDoc -> [SDoc] -> [SDoc]
forall doc. IsLine doc => doc -> [doc] -> [doc]
punctuate SDoc
forall doc. IsLine doc => doc
comma ((GenLocated SrcSpanAnnA (WarnDecl (GhcPass p)) -> SDoc)
-> [GenLocated SrcSpanAnnA (WarnDecl (GhcPass p))] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated SrcSpanAnnA (WarnDecl (GhcPass p)) -> SDoc
forall a. Outputable a => a -> SDoc
ppr [LWarnDecl (GhcPass p)]
[GenLocated SrcSpanAnnA (WarnDecl (GhcPass p))]
decls)) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"#-}"
      where src :: String
src = case forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p of
              GhcPass p
GhcPs | (EpAnn [AddEpAnn]
_, SourceText String
src) <- XWarnings (GhcPass p)
ext -> String
src
              GhcPass p
GhcRn | SourceText String
src <- XWarnings (GhcPass p)
ext -> String
src
              GhcPass p
GhcTc | SourceText String
src <- XWarnings (GhcPass p)
ext -> String
src
              GhcPass p
_ -> String -> String
forall a. HasCallStack => 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 (GhcPass p)
txt)
      = [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep ( SDoc -> [SDoc] -> [SDoc]
forall doc. IsLine doc => doc -> [doc] -> [doc]
punctuate SDoc
forall doc. IsLine doc => doc
comma ((GenLocated (Anno (IdGhcP p)) (IdGhcP p) -> SDoc)
-> [GenLocated (Anno (IdGhcP p)) (IdGhcP p)] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated (Anno (IdGhcP p)) (IdGhcP p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr [LIdP (GhcPass p)]
[GenLocated (Anno (IdGhcP p)) (IdGhcP p)]
thing))
              SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> WarningTxt (GhcPass p) -> SDoc
forall a. Outputable a => a -> SDoc
ppr WarningTxt (GhcPass p)
txt

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

type instance XHsAnnotation (GhcPass _) = (EpAnn AnnPragma, SourceText)
type instance XXAnnDecl     (GhcPass _) = DataConCantHappen

instance (OutputableBndrId p) => Outputable (AnnDecl (GhcPass p)) where
    ppr :: AnnDecl (GhcPass p) -> SDoc
ppr (HsAnnotation XHsAnnotation (GhcPass p)
_ AnnProvenance (GhcPass p)
provenance XRec (GhcPass p) (HsExpr (GhcPass p))
expr)
      = [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep [String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"{-#", AnnProvenance (GhcPass p) -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
AnnProvenance (GhcPass p) -> SDoc
pprAnnProvenance AnnProvenance (GhcPass p)
provenance, HsExpr (GhcPass p) -> SDoc
forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> SDoc
pprExpr (GenLocated (Anno (HsExpr (GhcPass p))) (HsExpr (GhcPass p))
-> HsExpr (GhcPass p)
forall l e. GenLocated l e -> e
unLoc XRec (GhcPass p) (HsExpr (GhcPass p))
GenLocated (Anno (HsExpr (GhcPass p))) (HsExpr (GhcPass p))
expr), String -> SDoc
forall doc. IsLine doc => String -> doc
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
forall doc. IsLine doc => String -> doc
text String
"ANN module"
pprAnnProvenance (ValueAnnProvenance (L Anno (IdGhcP p)
_ IdGhcP p
name))
  = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"ANN" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> IdGhcP p -> SDoc
forall a. Outputable a => a -> SDoc
ppr IdGhcP p
name
pprAnnProvenance (TypeAnnProvenance (L Anno (IdGhcP p)
_ IdGhcP p
name))
  = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"ANN type" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> IdGhcP p -> 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 _) = DataConCantHappen

type instance Anno (Maybe Role) = SrcAnn NoEpAnns

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
forall doc. IsLine doc => String -> doc
text String
"type role" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> IdGhcP p -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (GenLocated (Anno (IdGhcP p)) (IdGhcP p) -> IdGhcP p
forall l e. GenLocated l e -> e
unLoc LIdP (GhcPass p)
GenLocated (Anno (IdGhcP p)) (IdGhcP p)
ltycon) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
      [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep ((GenLocated (SrcAnn NoEpAnns) (Maybe Role) -> SDoc)
-> [GenLocated (SrcAnn NoEpAnns) (Maybe Role)] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (Maybe Role -> SDoc
forall {a}. Outputable a => Maybe a -> SDoc
pp_role (Maybe Role -> SDoc)
-> (GenLocated (SrcAnn NoEpAnns) (Maybe Role) -> Maybe Role)
-> GenLocated (SrcAnn NoEpAnns) (Maybe Role)
-> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated (SrcAnn NoEpAnns) (Maybe Role) -> Maybe Role
forall l e. GenLocated l e -> e
unLoc) [XRec (GhcPass p) (Maybe Role)]
[GenLocated (SrcAnn NoEpAnns) (Maybe Role)]
roles)
    where
      pp_role :: Maybe a -> SDoc
pp_role Maybe a
Nothing  = SDoc
forall doc. IsLine doc => doc
underscore
      pp_role (Just a
r) = a -> SDoc
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)]
_) = IdP (GhcPass p)
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)) = SrcAnn NoEpAnns
type instance Anno (FamilyDecl (GhcPass p)) = SrcSpanAnnA
type instance Anno (InjectivityAnn (GhcPass p)) = SrcAnn NoEpAnns
type instance Anno CType = SrcSpanAnnP
type instance Anno (HsDerivingClause (GhcPass p)) = SrcAnn NoEpAnns
type instance Anno (DerivClauseTys (GhcPass _)) = SrcSpanAnnC
type instance Anno (StandaloneKindSig (GhcPass p)) = SrcSpanAnnA
type instance Anno (ConDecl (GhcPass p)) = SrcSpanAnnA
type instance Anno Bool = SrcAnn NoEpAnns
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 (GhcPass p)) = SrcSpanAnnA
type instance Anno (DerivDecl (GhcPass p)) = SrcSpanAnnA
type instance Anno OverlapMode = SrcSpanAnnP
type instance Anno (DerivStrategy (GhcPass p)) = SrcAnn NoEpAnns
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) = SrcAnn NoEpAnns
type instance Anno (RuleBndr (GhcPass p)) = SrcAnn NoEpAnns
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) = SrcAnn NoEpAnns
type instance Anno CCallConv   = SrcSpan
type instance Anno Safety      = SrcSpan
type instance Anno CExportSpec = SrcSpan