{-# LANGUAGE CPP                       #-}
{-# LANGUAGE ConstraintKinds           #-}
{-# LANGUAGE DataKinds                 #-}
{-# LANGUAGE DeriveDataTypeable        #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts          #-}
{-# LANGUAGE FlexibleInstances         #-}
{-# LANGUAGE LambdaCase                #-}
{-# LANGUAGE MultiParamTypeClasses     #-}
{-# LANGUAGE ScopedTypeVariables       #-}
{-# LANGUAGE StandaloneDeriving        #-}
{-# LANGUAGE TypeApplications          #-}
{-# LANGUAGE TypeFamilyDependencies    #-}
{-# 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 Haskell syntax for expressions.
module GHC.Hs.Expr
  ( module Language.Haskell.Syntax.Expr
  , module GHC.Hs.Expr
  ) where

import Language.Haskell.Syntax.Expr

-- friends:
import GHC.Prelude

import GHC.Hs.Decls() -- import instances
import GHC.Hs.Pat
import GHC.Hs.Lit
import Language.Haskell.Syntax.Extension
import Language.Haskell.Syntax.Basic (FieldLabelString(..))
import GHC.Hs.Extension
import GHC.Hs.Type
import GHC.Hs.Binds
import GHC.Parser.Annotation

-- others:
import GHC.Tc.Types.Evidence
import GHC.Types.Name
import GHC.Types.Name.Reader
import GHC.Types.Name.Set
import GHC.Types.Basic
import GHC.Types.Fixity
import GHC.Types.SourceText
import GHC.Types.SrcLoc
import GHC.Types.Tickish (CoreTickish)
import GHC.Core.ConLike
import GHC.Unit.Module (ModuleName)
import GHC.Utils.Misc
import GHC.Utils.Outputable
import GHC.Utils.Panic
import GHC.Utils.Panic.Plain
import GHC.Data.FastString
import GHC.Core.Type
import GHC.Builtin.Types (mkTupleStr)
import GHC.Tc.Utils.TcType (TcType, TcTyVar)
import {-# SOURCE #-} GHC.Tc.Types (TcLclEnv)

import GHCi.RemoteTypes ( ForeignRef )
import qualified Language.Haskell.TH as TH (Q)

-- libraries:
import Data.Data hiding (Fixity(..))
import qualified Data.Data as Data (Fixity(..))
import qualified Data.Kind
import Data.Maybe (isJust)
import Data.Foldable ( toList )
import Data.List (uncons)
import Data.Bifunctor (first)

{- *********************************************************************
*                                                                      *
                Expressions proper
*                                                                      *
********************************************************************* -}

-- | Post-Type checking Expression
--
-- PostTcExpr is an evidence expression attached to the syntax tree by the
-- type checker (c.f. postTcType).
type PostTcExpr  = HsExpr GhcTc

-- | Post-Type checking Table
--
-- We use a PostTcTable where there are a bunch of pieces of evidence, more
-- than is convenient to keep individually.
type PostTcTable = [(Name, PostTcExpr)]

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

-- Defining SyntaxExpr in two stages allows for better type inference, because
-- we can declare SyntaxExprGhc to be injective (and closed). Without injectivity,
-- noSyntaxExpr would be ambiguous.
type instance SyntaxExpr (GhcPass p) = SyntaxExprGhc p

type family SyntaxExprGhc (p :: Pass) = (r :: Data.Kind.Type) | r -> p where
  SyntaxExprGhc 'Parsed      = NoExtField
  SyntaxExprGhc 'Renamed     = SyntaxExprRn
  SyntaxExprGhc 'Typechecked = SyntaxExprTc

-- | The function to use in rebindable syntax. See Note [NoSyntaxExpr].
data SyntaxExprRn = SyntaxExprRn (HsExpr GhcRn)
    -- Why is the payload not just a Name?
    -- See Note [Monad fail : Rebindable syntax, overloaded strings] in "GHC.Rename.Expr"
                  | NoSyntaxExprRn

-- | An expression with wrappers, used for rebindable syntax
--
-- This should desugar to
--
-- > syn_res_wrap $ syn_expr (syn_arg_wraps[0] arg0)
-- >                         (syn_arg_wraps[1] arg1) ...
--
-- where the actual arguments come from elsewhere in the AST.
data SyntaxExprTc = SyntaxExprTc { SyntaxExprTc -> HsExpr GhcTc
syn_expr      :: HsExpr GhcTc
                                 , SyntaxExprTc -> [HsWrapper]
syn_arg_wraps :: [HsWrapper]
                                 , SyntaxExprTc -> HsWrapper
syn_res_wrap  :: HsWrapper }
                  | NoSyntaxExprTc  -- See Note [NoSyntaxExpr]

-- | This is used for rebindable-syntax pieces that are too polymorphic
-- for tcSyntaxOp (trS_fmap and the mzip in ParStmt)
noExpr :: HsExpr (GhcPass p)
noExpr :: forall (p :: Pass). HsExpr (GhcPass p)
noExpr = forall p. XLitE p -> HsLit p -> HsExpr p
HsLit EpAnnCO
noComments (forall x. XHsString x -> FastString -> HsLit x
HsString (String -> SourceText
SourceText  String
"noExpr") (String -> FastString
fsLit String
"noExpr"))

noSyntaxExpr :: forall p. IsPass p => SyntaxExpr (GhcPass p)
                              -- Before renaming, and sometimes after
                              -- See Note [NoSyntaxExpr]
noSyntaxExpr :: forall (p :: Pass). IsPass p => SyntaxExpr (GhcPass p)
noSyntaxExpr = case forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p of
  GhcPass p
GhcPs -> NoExtField
noExtField
  GhcPass p
GhcRn -> SyntaxExprRn
NoSyntaxExprRn
  GhcPass p
GhcTc -> SyntaxExprTc
NoSyntaxExprTc

-- | Make a 'SyntaxExpr GhcRn' from an expression
-- Used only in getMonadFailOp.
-- See Note [Monad fail : Rebindable syntax, overloaded strings] in "GHC.Rename.Expr"
mkSyntaxExpr :: HsExpr GhcRn -> SyntaxExprRn
mkSyntaxExpr :: HsExpr GhcRn -> SyntaxExprRn
mkSyntaxExpr = HsExpr GhcRn -> SyntaxExprRn
SyntaxExprRn

-- | Make a 'SyntaxExpr' from a 'Name' (the "rn" is because this is used in the
-- renamer).
mkRnSyntaxExpr :: Name -> SyntaxExprRn
mkRnSyntaxExpr :: Name -> SyntaxExprRn
mkRnSyntaxExpr Name
name = HsExpr GhcRn -> SyntaxExprRn
SyntaxExprRn forall a b. (a -> b) -> a -> b
$ forall p. XVar p -> LIdP p -> HsExpr p
HsVar NoExtField
noExtField forall a b. (a -> b) -> a -> b
$ forall a an. a -> LocatedAn an a
noLocA Name
name

instance Outputable SyntaxExprRn where
  ppr :: SyntaxExprRn -> SDoc
ppr (SyntaxExprRn HsExpr GhcRn
expr) = forall a. Outputable a => a -> SDoc
ppr HsExpr GhcRn
expr
  ppr SyntaxExprRn
NoSyntaxExprRn      = forall doc. IsLine doc => String -> doc
text String
"<no syntax expr>"

instance Outputable SyntaxExprTc where
  ppr :: SyntaxExprTc -> SDoc
ppr (SyntaxExprTc { syn_expr :: SyntaxExprTc -> HsExpr GhcTc
syn_expr      = HsExpr GhcTc
expr
                    , syn_arg_wraps :: SyntaxExprTc -> [HsWrapper]
syn_arg_wraps = [HsWrapper]
arg_wraps
                    , syn_res_wrap :: SyntaxExprTc -> HsWrapper
syn_res_wrap  = HsWrapper
res_wrap })
    = forall a. (SDocContext -> a) -> (a -> SDoc) -> SDoc
sdocOption SDocContext -> Bool
sdocPrintExplicitCoercions forall a b. (a -> b) -> a -> b
$ \Bool
print_co ->
      forall doc. IsOutput doc => (Bool -> doc) -> doc
getPprDebug forall a b. (a -> b) -> a -> b
$ \Bool
debug ->
      if Bool
debug Bool -> Bool -> Bool
|| Bool
print_co
      then forall a. Outputable a => a -> SDoc
ppr HsExpr GhcTc
expr forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc -> doc
braces (forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas forall a. Outputable a => a -> SDoc
ppr [HsWrapper]
arg_wraps)
                    forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc -> doc
braces (forall a. Outputable a => a -> SDoc
ppr HsWrapper
res_wrap)
      else forall a. Outputable a => a -> SDoc
ppr HsExpr GhcTc
expr

  ppr SyntaxExprTc
NoSyntaxExprTc = forall doc. IsLine doc => String -> doc
text String
"<no syntax expr>"

-- | HsWrap appears only in typechecker output
data HsWrap hs_syn = HsWrap HsWrapper      -- the wrapper
                            (hs_syn GhcTc) -- the thing that is wrapped

deriving instance (Data (hs_syn GhcTc), Typeable hs_syn) => Data (HsWrap hs_syn)

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

data HsBracketTc = HsBracketTc
  { HsBracketTc -> HsQuote GhcRn
hsb_quote   :: HsQuote GhcRn        -- See Note [The life cycle of a TH quotation]
  , HsBracketTc -> Type
hsb_ty      :: Type
  , HsBracketTc -> Maybe QuoteWrapper
hsb_wrap    :: Maybe QuoteWrapper   -- The wrapper to apply type and dictionary argument to the quote.
  , HsBracketTc -> [PendingTcSplice]
hsb_splices :: [PendingTcSplice]    -- Output of the type checker is the *original*
                                        -- renamed expression, plus
                                        -- _typechecked_ splices to be
                                        -- pasted back in by the desugarer
  }

type instance XTypedBracket GhcPs = EpAnn [AddEpAnn]
type instance XTypedBracket GhcRn = NoExtField
type instance XTypedBracket GhcTc = HsBracketTc
type instance XUntypedBracket GhcPs = EpAnn [AddEpAnn]
type instance XUntypedBracket GhcRn = [PendingRnSplice] -- See Note [Pending Splices]
                                                        -- Output of the renamer is the *original* renamed expression,
                                                        -- plus _renamed_ splices to be type checked
type instance XUntypedBracket GhcTc = HsBracketTc

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

-- API Annotations types

data EpAnnHsCase = EpAnnHsCase
      { EpAnnHsCase -> EpaLocation
hsCaseAnnCase :: EpaLocation
      , EpAnnHsCase -> EpaLocation
hsCaseAnnOf   :: EpaLocation
      , EpAnnHsCase -> [AddEpAnn]
hsCaseAnnsRest :: [AddEpAnn]
      } deriving Typeable EpAnnHsCase
EpAnnHsCase -> DataType
EpAnnHsCase -> Constr
(forall b. Data b => b -> b) -> EpAnnHsCase -> EpAnnHsCase
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) -> EpAnnHsCase -> u
forall u. (forall d. Data d => d -> u) -> EpAnnHsCase -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> EpAnnHsCase -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> EpAnnHsCase -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> EpAnnHsCase -> m EpAnnHsCase
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> EpAnnHsCase -> m EpAnnHsCase
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c EpAnnHsCase
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> EpAnnHsCase -> c EpAnnHsCase
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c EpAnnHsCase)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c EpAnnHsCase)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> EpAnnHsCase -> m EpAnnHsCase
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> EpAnnHsCase -> m EpAnnHsCase
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> EpAnnHsCase -> m EpAnnHsCase
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> EpAnnHsCase -> m EpAnnHsCase
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> EpAnnHsCase -> m EpAnnHsCase
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> EpAnnHsCase -> m EpAnnHsCase
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> EpAnnHsCase -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> EpAnnHsCase -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> EpAnnHsCase -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> EpAnnHsCase -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> EpAnnHsCase -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> EpAnnHsCase -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> EpAnnHsCase -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> EpAnnHsCase -> r
gmapT :: (forall b. Data b => b -> b) -> EpAnnHsCase -> EpAnnHsCase
$cgmapT :: (forall b. Data b => b -> b) -> EpAnnHsCase -> EpAnnHsCase
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c EpAnnHsCase)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c EpAnnHsCase)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c EpAnnHsCase)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c EpAnnHsCase)
dataTypeOf :: EpAnnHsCase -> DataType
$cdataTypeOf :: EpAnnHsCase -> DataType
toConstr :: EpAnnHsCase -> Constr
$ctoConstr :: EpAnnHsCase -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c EpAnnHsCase
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c EpAnnHsCase
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> EpAnnHsCase -> c EpAnnHsCase
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> EpAnnHsCase -> c EpAnnHsCase
Data

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

type instance XVar           (GhcPass _) = NoExtField

-- Record selectors at parse time are HsVar; they convert to HsRecSel
-- on renaming.
type instance XRecSel              GhcPs = DataConCantHappen
type instance XRecSel              GhcRn = NoExtField
type instance XRecSel              GhcTc = NoExtField

type instance XLam           (GhcPass _) = NoExtField

-- OverLabel not present in GhcTc pass; see GHC.Rename.Expr
-- Note [Handling overloaded and rebindable constructs]
type instance XOverLabel     GhcPs = EpAnnCO
type instance XOverLabel     GhcRn = EpAnnCO
type instance XOverLabel     GhcTc = DataConCantHappen

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

type instance XVar           (GhcPass _) = NoExtField

type instance XUnboundVar    GhcPs = EpAnn EpAnnUnboundVar
type instance XUnboundVar    GhcRn = NoExtField
type instance XUnboundVar    GhcTc = HoleExprRef
  -- We really don't need the whole HoleExprRef; just the IORef EvTerm
  -- would be enough. But then deriving a Data instance becomes impossible.
  -- Much, much easier just to define HoleExprRef with a Data instance and
  -- store the whole structure.

type instance XIPVar         GhcPs = EpAnnCO
type instance XIPVar         GhcRn = EpAnnCO
type instance XIPVar         GhcTc = DataConCantHappen
type instance XOverLitE      (GhcPass _) = EpAnnCO
type instance XLitE          (GhcPass _) = EpAnnCO

type instance XLam           (GhcPass _) = NoExtField

type instance XLamCase       (GhcPass _) = EpAnn [AddEpAnn]

type instance XApp           (GhcPass _) = EpAnnCO

type instance XAppTypeE      GhcPs = NoExtField
type instance XAppTypeE      GhcRn = NoExtField
type instance XAppTypeE      GhcTc = Type

-- OpApp not present in GhcTc pass; see GHC.Rename.Expr
-- Note [Handling overloaded and rebindable constructs]
type instance XOpApp         GhcPs = EpAnn [AddEpAnn]
type instance XOpApp         GhcRn = Fixity
type instance XOpApp         GhcTc = DataConCantHappen

-- SectionL, SectionR not present in GhcTc pass; see GHC.Rename.Expr
-- Note [Handling overloaded and rebindable constructs]
type instance XSectionL      GhcPs = EpAnnCO
type instance XSectionR      GhcPs = EpAnnCO
type instance XSectionL      GhcRn = EpAnnCO
type instance XSectionR      GhcRn = EpAnnCO
type instance XSectionL      GhcTc = DataConCantHappen
type instance XSectionR      GhcTc = DataConCantHappen


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

type instance XPar           (GhcPass _) = EpAnnCO

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

type instance XExplicitSum   GhcPs = EpAnn AnnExplicitSum
type instance XExplicitSum   GhcRn = NoExtField
type instance XExplicitSum   GhcTc = [Type]

type instance XCase          GhcPs = EpAnn EpAnnHsCase
type instance XCase          GhcRn = NoExtField
type instance XCase          GhcTc = NoExtField

type instance XIf            GhcPs = EpAnn AnnsIf
type instance XIf            GhcRn = NoExtField
type instance XIf            GhcTc = NoExtField

type instance XMultiIf       GhcPs = EpAnn [AddEpAnn]
type instance XMultiIf       GhcRn = NoExtField
type instance XMultiIf       GhcTc = Type

type instance XLet           GhcPs = EpAnnCO
type instance XLet           GhcRn = NoExtField
type instance XLet           GhcTc = NoExtField

type instance XDo            GhcPs = EpAnn AnnList
type instance XDo            GhcRn = NoExtField
type instance XDo            GhcTc = Type

type instance XExplicitList  GhcPs = EpAnn AnnList
type instance XExplicitList  GhcRn = NoExtField
type instance XExplicitList  GhcTc = Type
-- GhcPs: ExplicitList includes all source-level
--   list literals, including overloaded ones
-- GhcRn and GhcTc: ExplicitList used only for list literals
--   that denote Haskell's built-in lists.  Overloaded lists
--   have been expanded away in the renamer
-- See Note [Handling overloaded and rebindable constructs]
-- in  GHC.Rename.Expr

type instance XRecordCon     GhcPs = EpAnn [AddEpAnn]
type instance XRecordCon     GhcRn = NoExtField
type instance XRecordCon     GhcTc = PostTcExpr   -- Instantiated constructor function

type instance XRecordUpd     GhcPs = EpAnn [AddEpAnn]
type instance XRecordUpd     GhcRn = NoExtField
type instance XRecordUpd     GhcTc = DataConCantHappen
  -- We desugar record updates in the typechecker.
  -- See [Handling overloaded and rebindable constructs],
  -- and [Record Updates] in GHC.Tc.Gen.Expr.

type instance XGetField     GhcPs = EpAnnCO
type instance XGetField     GhcRn = NoExtField
type instance XGetField     GhcTc = DataConCantHappen
-- HsGetField is eliminated by the renamer. See [Handling overloaded
-- and rebindable constructs].

type instance XProjection     GhcPs = EpAnn AnnProjection
type instance XProjection     GhcRn = NoExtField
type instance XProjection     GhcTc = DataConCantHappen
-- HsProjection is eliminated by the renamer. See [Handling overloaded
-- and rebindable constructs].

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

type instance XArithSeq      GhcPs = EpAnn [AddEpAnn]
type instance XArithSeq      GhcRn = NoExtField
type instance XArithSeq      GhcTc = PostTcExpr

type instance XProc          (GhcPass _) = EpAnn [AddEpAnn]

type instance XStatic        GhcPs = EpAnn [AddEpAnn]
type instance XStatic        GhcRn = NameSet
type instance XStatic        GhcTc = (NameSet, Type)
  -- Free variables and type of expression, this is stored for convenience as wiring in
  -- StaticPtr is a bit tricky (see #20150)

type instance XPragE         (GhcPass _) = NoExtField

type instance Anno [LocatedA ((StmtLR (GhcPass pl) (GhcPass pr) (LocatedA (body (GhcPass pr)))))] = SrcSpanAnnL
type instance Anno (StmtLR GhcRn GhcRn (LocatedA (body GhcRn))) = SrcSpanAnnA

data AnnExplicitSum
  = AnnExplicitSum {
      AnnExplicitSum -> EpaLocation
aesOpen       :: EpaLocation,
      AnnExplicitSum -> [EpaLocation]
aesBarsBefore :: [EpaLocation],
      AnnExplicitSum -> [EpaLocation]
aesBarsAfter  :: [EpaLocation],
      AnnExplicitSum -> EpaLocation
aesClose      :: EpaLocation
      } deriving Typeable AnnExplicitSum
AnnExplicitSum -> DataType
AnnExplicitSum -> Constr
(forall b. Data b => b -> b) -> AnnExplicitSum -> AnnExplicitSum
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) -> AnnExplicitSum -> u
forall u. (forall d. Data d => d -> u) -> AnnExplicitSum -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AnnExplicitSum -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AnnExplicitSum -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> AnnExplicitSum -> m AnnExplicitSum
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> AnnExplicitSum -> m AnnExplicitSum
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c AnnExplicitSum
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AnnExplicitSum -> c AnnExplicitSum
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c AnnExplicitSum)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c AnnExplicitSum)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> AnnExplicitSum -> m AnnExplicitSum
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> AnnExplicitSum -> m AnnExplicitSum
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> AnnExplicitSum -> m AnnExplicitSum
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> AnnExplicitSum -> m AnnExplicitSum
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> AnnExplicitSum -> m AnnExplicitSum
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> AnnExplicitSum -> m AnnExplicitSum
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> AnnExplicitSum -> u
$cgmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> AnnExplicitSum -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> AnnExplicitSum -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> AnnExplicitSum -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AnnExplicitSum -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AnnExplicitSum -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AnnExplicitSum -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AnnExplicitSum -> r
gmapT :: (forall b. Data b => b -> b) -> AnnExplicitSum -> AnnExplicitSum
$cgmapT :: (forall b. Data b => b -> b) -> AnnExplicitSum -> AnnExplicitSum
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c AnnExplicitSum)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c AnnExplicitSum)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c AnnExplicitSum)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c AnnExplicitSum)
dataTypeOf :: AnnExplicitSum -> DataType
$cdataTypeOf :: AnnExplicitSum -> DataType
toConstr :: AnnExplicitSum -> Constr
$ctoConstr :: AnnExplicitSum -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c AnnExplicitSum
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c AnnExplicitSum
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AnnExplicitSum -> c AnnExplicitSum
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AnnExplicitSum -> c AnnExplicitSum
Data

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

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

data AnnsIf
  = AnnsIf {
      AnnsIf -> EpaLocation
aiIf       :: EpaLocation,
      AnnsIf -> EpaLocation
aiThen     :: EpaLocation,
      AnnsIf -> EpaLocation
aiElse     :: EpaLocation,
      AnnsIf -> Maybe EpaLocation
aiThenSemi :: Maybe EpaLocation,
      AnnsIf -> Maybe EpaLocation
aiElseSemi :: Maybe EpaLocation
      } deriving Typeable AnnsIf
AnnsIf -> DataType
AnnsIf -> Constr
(forall b. Data b => b -> b) -> AnnsIf -> AnnsIf
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) -> AnnsIf -> u
forall u. (forall d. Data d => d -> u) -> AnnsIf -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> AnnsIf -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> AnnsIf -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> AnnsIf -> m AnnsIf
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AnnsIf -> m AnnsIf
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c AnnsIf
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AnnsIf -> c AnnsIf
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c AnnsIf)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c AnnsIf)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AnnsIf -> m AnnsIf
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AnnsIf -> m AnnsIf
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AnnsIf -> m AnnsIf
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AnnsIf -> m AnnsIf
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> AnnsIf -> m AnnsIf
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> AnnsIf -> m AnnsIf
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> AnnsIf -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> AnnsIf -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> AnnsIf -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> AnnsIf -> [u]
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> AnnsIf -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> AnnsIf -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> AnnsIf -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> AnnsIf -> r
gmapT :: (forall b. Data b => b -> b) -> AnnsIf -> AnnsIf
$cgmapT :: (forall b. Data b => b -> b) -> AnnsIf -> AnnsIf
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c AnnsIf)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c AnnsIf)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c AnnsIf)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c AnnsIf)
dataTypeOf :: AnnsIf -> DataType
$cdataTypeOf :: AnnsIf -> DataType
toConstr :: AnnsIf -> Constr
$ctoConstr :: AnnsIf -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c AnnsIf
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c AnnsIf
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AnnsIf -> c AnnsIf
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AnnsIf -> c AnnsIf
Data

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

type instance XSCC           (GhcPass _) = (EpAnn AnnPragma, SourceText)
type instance XXPragE        (GhcPass _) = DataConCantHappen

type instance XCDotFieldOcc (GhcPass _) = EpAnn AnnFieldLabel
type instance XXDotFieldOcc (GhcPass _) = DataConCantHappen

type instance XPresent         (GhcPass _) = EpAnn [AddEpAnn]

type instance XMissing         GhcPs = EpAnn EpaLocation
type instance XMissing         GhcRn = NoExtField
type instance XMissing         GhcTc = Scaled Type

type instance XXTupArg         (GhcPass _) = DataConCantHappen

tupArgPresent :: HsTupArg (GhcPass p) -> Bool
tupArgPresent :: forall (p :: Pass). HsTupArg (GhcPass p) -> Bool
tupArgPresent (Present {}) = Bool
True
tupArgPresent (Missing {}) = Bool
False


{- *********************************************************************
*                                                                      *
            XXExpr: the extension constructor of HsExpr
*                                                                      *
********************************************************************* -}

type instance XXExpr GhcPs = DataConCantHappen
type instance XXExpr GhcRn = HsExpansion (HsExpr GhcRn) (HsExpr GhcRn)
type instance XXExpr GhcTc = XXExprGhcTc
-- HsExpansion: see Note [Rebindable syntax and HsExpansion] below


data XXExprGhcTc
  = WrapExpr        -- Type and evidence application and abstractions
      {-# UNPACK #-} !(HsWrap HsExpr)

  | ExpansionExpr   -- See Note [Rebindable syntax and HsExpansion] below
      {-# UNPACK #-} !(HsExpansion (HsExpr GhcRn) (HsExpr GhcTc))

  | ConLikeTc      -- Result of typechecking a data-con
                   -- See Note [Typechecking data constructors] in
                   --     GHC.Tc.Gen.Head
                   -- The two arguments describe how to eta-expand
                   -- the data constructor when desugaring
        ConLike [TcTyVar] [Scaled TcType]

  ---------------------------------------
  -- Haskell program coverage (Hpc) Support

  | HsTick
     CoreTickish
     (LHsExpr GhcTc)                    -- sub-expression

  | HsBinTick
     Int                                -- module-local tick number for True
     Int                                -- module-local tick number for False
     (LHsExpr GhcTc)                    -- sub-expression


{- *********************************************************************
*                                                                      *
            Pretty-printing expressions
*                                                                      *
********************************************************************* -}

instance (OutputableBndrId p) => Outputable (HsExpr (GhcPass p)) where
    ppr :: HsExpr (GhcPass p) -> SDoc
ppr HsExpr (GhcPass p)
expr = forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> SDoc
pprExpr HsExpr (GhcPass p)
expr

-----------------------
-- pprExpr, pprLExpr, pprBinds call pprDeeper;
-- the underscore versions do not
pprLExpr :: (OutputableBndrId p) => LHsExpr (GhcPass p) -> SDoc
pprLExpr :: forall (p :: Pass).
OutputableBndrId p =>
LHsExpr (GhcPass p) -> SDoc
pprLExpr (L SrcSpanAnnA
_ HsExpr (GhcPass p)
e) = forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> SDoc
pprExpr HsExpr (GhcPass p)
e

pprExpr :: (OutputableBndrId p) => HsExpr (GhcPass p) -> SDoc
pprExpr :: forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> SDoc
pprExpr HsExpr (GhcPass p)
e | forall (p :: Pass). IsPass p => HsExpr (GhcPass p) -> Bool
isAtomicHsExpr HsExpr (GhcPass p)
e Bool -> Bool -> Bool
|| forall id. HsExpr id -> Bool
isQuietHsExpr HsExpr (GhcPass p)
e =            forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> SDoc
ppr_expr HsExpr (GhcPass p)
e
          | Bool
otherwise                           = SDoc -> SDoc
pprDeeper (forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> SDoc
ppr_expr HsExpr (GhcPass p)
e)

isQuietHsExpr :: HsExpr id -> Bool
-- Parentheses do display something, but it gives little info and
-- if we go deeper when we go inside them then we get ugly things
-- like (...)
isQuietHsExpr :: forall id. HsExpr id -> Bool
isQuietHsExpr (HsPar {})        = Bool
True
-- applications don't display anything themselves
isQuietHsExpr (HsApp {})        = Bool
True
isQuietHsExpr (HsAppType {})    = Bool
True
isQuietHsExpr (OpApp {})        = Bool
True
isQuietHsExpr HsExpr id
_ = Bool
False

pprBinds :: (OutputableBndrId idL, OutputableBndrId idR)
         => HsLocalBindsLR (GhcPass idL) (GhcPass idR) -> SDoc
pprBinds :: forall (idL :: Pass) (idR :: Pass).
(OutputableBndrId idL, OutputableBndrId idR) =>
HsLocalBindsLR (GhcPass idL) (GhcPass idR) -> SDoc
pprBinds HsLocalBindsLR (GhcPass idL) (GhcPass idR)
b = SDoc -> SDoc
pprDeeper (forall a. Outputable a => a -> SDoc
ppr HsLocalBindsLR (GhcPass idL) (GhcPass idR)
b)

-----------------------
ppr_lexpr :: (OutputableBndrId p) => LHsExpr (GhcPass p) -> SDoc
ppr_lexpr :: forall (p :: Pass).
OutputableBndrId p =>
LHsExpr (GhcPass p) -> SDoc
ppr_lexpr LHsExpr (GhcPass p)
e = forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> SDoc
ppr_expr (forall l e. GenLocated l e -> e
unLoc LHsExpr (GhcPass p)
e)

ppr_expr :: forall p. (OutputableBndrId p)
         => HsExpr (GhcPass p) -> SDoc
ppr_expr :: forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> SDoc
ppr_expr (HsVar XVar (GhcPass p)
_ (L Anno (IdGhcP p)
_ IdGhcP p
v))   = forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc IdGhcP p
v
ppr_expr (HsUnboundVar XUnboundVar (GhcPass p)
_ RdrName
uv) = forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc RdrName
uv
ppr_expr (HsRecSel XRecSel (GhcPass p)
_ FieldOcc (GhcPass p)
f)      = forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc FieldOcc (GhcPass p)
f
ppr_expr (HsIPVar XIPVar (GhcPass p)
_ HsIPName
v)       = forall a. Outputable a => a -> SDoc
ppr HsIPName
v
ppr_expr (HsOverLabel XOverLabel (GhcPass p)
_ SourceText
s FastString
l) = forall doc. IsLine doc => Char -> doc
char Char
'#' forall doc. IsLine doc => doc -> doc -> doc
<> case SourceText
s of
                                             SourceText
NoSourceText -> forall a. Outputable a => a -> SDoc
ppr FastString
l
                                             SourceText String
src -> forall doc. IsLine doc => String -> doc
text String
src
ppr_expr (HsLit XLitE (GhcPass p)
_ HsLit (GhcPass p)
lit)       = forall a. Outputable a => a -> SDoc
ppr HsLit (GhcPass p)
lit
ppr_expr (HsOverLit XOverLitE (GhcPass p)
_ HsOverLit (GhcPass p)
lit)   = forall a. Outputable a => a -> SDoc
ppr HsOverLit (GhcPass p)
lit
ppr_expr (HsPar XPar (GhcPass p)
_ LHsToken "(" (GhcPass p)
_ XRec (GhcPass p) (HsExpr (GhcPass p))
e LHsToken ")" (GhcPass p)
_)     = forall doc. IsLine doc => doc -> doc
parens (forall (p :: Pass).
OutputableBndrId p =>
LHsExpr (GhcPass p) -> SDoc
ppr_lexpr XRec (GhcPass p) (HsExpr (GhcPass p))
e)

ppr_expr (HsPragE XPragE (GhcPass p)
_ HsPragE (GhcPass p)
prag XRec (GhcPass p) (HsExpr (GhcPass p))
e) = forall doc. IsLine doc => [doc] -> doc
sep [forall a. Outputable a => a -> SDoc
ppr HsPragE (GhcPass p)
prag, forall (p :: Pass).
OutputableBndrId p =>
LHsExpr (GhcPass p) -> SDoc
ppr_lexpr XRec (GhcPass p) (HsExpr (GhcPass p))
e]

ppr_expr e :: HsExpr (GhcPass p)
e@(HsApp {})        = forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p)
-> [Either (LHsExpr (GhcPass p)) (LHsWcType (NoGhcTc (GhcPass p)))]
-> SDoc
ppr_apps HsExpr (GhcPass p)
e []
ppr_expr e :: HsExpr (GhcPass p)
e@(HsAppType {})    = forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p)
-> [Either (LHsExpr (GhcPass p)) (LHsWcType (NoGhcTc (GhcPass p)))]
-> SDoc
ppr_apps HsExpr (GhcPass p)
e []

ppr_expr (OpApp XOpApp (GhcPass p)
_ XRec (GhcPass p) (HsExpr (GhcPass p))
e1 XRec (GhcPass p) (HsExpr (GhcPass p))
op XRec (GhcPass p) (HsExpr (GhcPass p))
e2)
  | Just SDoc
pp_op <- forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> Maybe SDoc
ppr_infix_expr (forall l e. GenLocated l e -> e
unLoc XRec (GhcPass p) (HsExpr (GhcPass p))
op)
  = SDoc -> SDoc
pp_infixly SDoc
pp_op
  | Bool
otherwise
  = SDoc
pp_prefixly

  where
    pp_e1 :: SDoc
pp_e1 = forall (p :: Pass).
OutputableBndrId p =>
PprPrec -> LHsExpr (GhcPass p) -> SDoc
pprDebugParendExpr PprPrec
opPrec XRec (GhcPass p) (HsExpr (GhcPass p))
e1   -- In debug mode, add parens
    pp_e2 :: SDoc
pp_e2 = forall (p :: Pass).
OutputableBndrId p =>
PprPrec -> LHsExpr (GhcPass p) -> SDoc
pprDebugParendExpr PprPrec
opPrec XRec (GhcPass p) (HsExpr (GhcPass p))
e2   -- to make precedence clear

    pp_prefixly :: SDoc
pp_prefixly
      = SDoc -> Int -> SDoc -> SDoc
hang (forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
op) Int
2 (forall doc. IsLine doc => [doc] -> doc
sep [SDoc
pp_e1, SDoc
pp_e2])

    pp_infixly :: SDoc -> SDoc
pp_infixly SDoc
pp_op
      = SDoc -> Int -> SDoc -> SDoc
hang SDoc
pp_e1 Int
2 (forall doc. IsLine doc => [doc] -> doc
sep [SDoc
pp_op, Int -> SDoc -> SDoc
nest Int
2 SDoc
pp_e2])

ppr_expr (NegApp XNegApp (GhcPass p)
_ XRec (GhcPass p) (HsExpr (GhcPass p))
e SyntaxExpr (GhcPass p)
_) = forall doc. IsLine doc => Char -> doc
char Char
'-' forall doc. IsLine doc => doc -> doc -> doc
<+> forall (p :: Pass).
OutputableBndrId p =>
PprPrec -> LHsExpr (GhcPass p) -> SDoc
pprDebugParendExpr PprPrec
appPrec XRec (GhcPass p) (HsExpr (GhcPass p))
e

ppr_expr (SectionL XSectionL (GhcPass p)
_ XRec (GhcPass p) (HsExpr (GhcPass p))
expr XRec (GhcPass p) (HsExpr (GhcPass p))
op)
  | Just SDoc
pp_op <- forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> Maybe SDoc
ppr_infix_expr (forall l e. GenLocated l e -> e
unLoc XRec (GhcPass p) (HsExpr (GhcPass p))
op)
  = SDoc -> SDoc
pp_infixly SDoc
pp_op
  | Bool
otherwise
  = SDoc
pp_prefixly
  where
    pp_expr :: SDoc
pp_expr = forall (p :: Pass).
OutputableBndrId p =>
PprPrec -> LHsExpr (GhcPass p) -> SDoc
pprDebugParendExpr PprPrec
opPrec XRec (GhcPass p) (HsExpr (GhcPass p))
expr

    pp_prefixly :: SDoc
pp_prefixly = SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => [doc] -> doc
hsep [forall doc. IsLine doc => String -> doc
text String
" \\ x_ ->", forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
op])
                       Int
4 (forall doc. IsLine doc => [doc] -> doc
hsep [SDoc
pp_expr, forall doc. IsLine doc => String -> doc
text String
"x_ )"])

    pp_infixly :: SDoc -> SDoc
pp_infixly SDoc
v = (forall doc. IsLine doc => [doc] -> doc
sep [SDoc
pp_expr, SDoc
v])

ppr_expr (SectionR XSectionR (GhcPass p)
_ XRec (GhcPass p) (HsExpr (GhcPass p))
op XRec (GhcPass p) (HsExpr (GhcPass p))
expr)
  | Just SDoc
pp_op <- forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> Maybe SDoc
ppr_infix_expr (forall l e. GenLocated l e -> e
unLoc XRec (GhcPass p) (HsExpr (GhcPass p))
op)
  = SDoc -> SDoc
pp_infixly SDoc
pp_op
  | Bool
otherwise
  = SDoc
pp_prefixly
  where
    pp_expr :: SDoc
pp_expr = forall (p :: Pass).
OutputableBndrId p =>
PprPrec -> LHsExpr (GhcPass p) -> SDoc
pprDebugParendExpr PprPrec
opPrec XRec (GhcPass p) (HsExpr (GhcPass p))
expr

    pp_prefixly :: SDoc
pp_prefixly = SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => [doc] -> doc
hsep [forall doc. IsLine doc => String -> doc
text String
"( \\ x_ ->", forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
op, forall doc. IsLine doc => String -> doc
text String
"x_"])
                       Int
4 (SDoc
pp_expr forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
rparen)

    pp_infixly :: SDoc -> SDoc
pp_infixly SDoc
v = forall doc. IsLine doc => [doc] -> doc
sep [SDoc
v, SDoc
pp_expr]

ppr_expr (ExplicitTuple XExplicitTuple (GhcPass p)
_ [HsTupArg (GhcPass p)]
exprs Boxity
boxity)
    -- Special-case unary boxed tuples so that they are pretty-printed as
    -- `MkSolo x`, not `(x)`
  | [Present XPresent (GhcPass p)
_ XRec (GhcPass p) (HsExpr (GhcPass p))
expr] <- [HsTupArg (GhcPass p)]
exprs
  , Boxity
Boxed <- Boxity
boxity
  = forall doc. IsLine doc => [doc] -> doc
hsep [forall doc. IsLine doc => String -> doc
text (Boxity -> NameSpace -> Int -> String
mkTupleStr Boxity
Boxed NameSpace
dataName Int
1), forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
expr]
  | Bool
otherwise
  = TupleSort -> SDoc -> SDoc
tupleParens (Boxity -> TupleSort
boxityTupleSort Boxity
boxity) ([SDoc] -> SDoc
fcat (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)))) =>
[HsTupArg (GhcPass p)] -> [SDoc]
ppr_tup_args [HsTupArg (GhcPass p)]
exprs))
  where
    ppr_tup_args :: [HsTupArg (GhcPass p)] -> [SDoc]
ppr_tup_args []               = []
    ppr_tup_args (Present XPresent (GhcPass p)
_ LHsExpr (GhcPass p)
e : [HsTupArg (GhcPass p)]
es) = (forall (p :: Pass).
OutputableBndrId p =>
LHsExpr (GhcPass p) -> SDoc
ppr_lexpr LHsExpr (GhcPass p)
e forall doc. IsLine doc => doc -> doc -> doc
<> forall {doc} {id}. IsLine doc => [HsTupArg id] -> doc
punc [HsTupArg (GhcPass p)]
es) forall a. a -> [a] -> [a]
: [HsTupArg (GhcPass p)] -> [SDoc]
ppr_tup_args [HsTupArg (GhcPass p)]
es
    ppr_tup_args (Missing XMissing (GhcPass p)
_   : [HsTupArg (GhcPass p)]
es) = forall {doc} {id}. IsLine doc => [HsTupArg id] -> doc
punc [HsTupArg (GhcPass p)]
es forall a. a -> [a] -> [a]
: [HsTupArg (GhcPass p)] -> [SDoc]
ppr_tup_args [HsTupArg (GhcPass p)]
es

    punc :: [HsTupArg id] -> doc
punc (Present {} : [HsTupArg id]
_) = forall doc. IsLine doc => doc
comma forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
space
    punc (Missing {} : [HsTupArg id]
_) = forall doc. IsLine doc => doc
comma
    punc (XTupArg {} : [HsTupArg id]
_) = forall doc. IsLine doc => doc
comma forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
space
    punc []               = forall doc. IsOutput doc => doc
empty

ppr_expr (ExplicitSum XExplicitSum (GhcPass p)
_ Int
alt Int
arity XRec (GhcPass p) (HsExpr (GhcPass p))
expr)
  = forall doc. IsLine doc => String -> doc
text String
"(#" forall doc. IsLine doc => doc -> doc -> doc
<+> forall {doc}. IsLine doc => Int -> doc
ppr_bars (Int
alt forall a. Num a => a -> a -> a
- Int
1) forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
expr forall doc. IsLine doc => doc -> doc -> doc
<+> forall {doc}. IsLine doc => Int -> doc
ppr_bars (Int
arity forall a. Num a => a -> a -> a
- Int
alt) forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"#)"
  where
    ppr_bars :: Int -> doc
ppr_bars Int
n = forall doc. IsLine doc => [doc] -> doc
hsep (forall a. Int -> a -> [a]
replicate Int
n (forall doc. IsLine doc => Char -> doc
char Char
'|'))

ppr_expr (HsLam XLam (GhcPass p)
_ MatchGroup (GhcPass p) (XRec (GhcPass p) (HsExpr (GhcPass p)))
matches)
  = forall (idR :: Pass) body.
(OutputableBndrId idR, Outputable body) =>
MatchGroup (GhcPass idR) body -> SDoc
pprMatches MatchGroup (GhcPass p) (XRec (GhcPass p) (HsExpr (GhcPass p)))
matches

ppr_expr (HsLamCase XLamCase (GhcPass p)
_ LamCaseVariant
lc_variant MatchGroup (GhcPass p) (XRec (GhcPass p) (HsExpr (GhcPass p)))
matches)
  = forall doc. IsLine doc => [doc] -> doc
sep [ forall doc. IsLine doc => [doc] -> doc
sep [LamCaseVariant -> SDoc
lamCaseKeyword LamCaseVariant
lc_variant],
          Int -> SDoc -> SDoc
nest Int
2 (forall (idR :: Pass) body.
(OutputableBndrId idR, Outputable body) =>
MatchGroup (GhcPass idR) body -> SDoc
pprMatches MatchGroup (GhcPass p) (XRec (GhcPass p) (HsExpr (GhcPass p)))
matches) ]

ppr_expr (HsCase XCase (GhcPass p)
_ XRec (GhcPass p) (HsExpr (GhcPass p))
expr matches :: MatchGroup (GhcPass p) (XRec (GhcPass p) (HsExpr (GhcPass p)))
matches@(MG { mg_alts :: forall p body. MatchGroup p body -> XRec p [LMatch p body]
mg_alts = L SrcSpanAnnL
_ [GenLocated
   SrcSpanAnnA
   (Match (GhcPass p) (GenLocated SrcSpanAnnA (HsExpr (GhcPass p))))]
alts }))
  = forall doc. IsLine doc => [doc] -> doc
sep [ forall doc. IsLine doc => [doc] -> doc
sep [forall doc. IsLine doc => String -> doc
text String
"case", Int -> SDoc -> SDoc
nest Int
4 (forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
expr), forall doc. IsLine doc => String -> doc
text String
"of"],
          SDoc
pp_alts ]
  where
    pp_alts :: SDoc
pp_alts | forall (t :: * -> *) a. Foldable t => t a -> Bool
null [GenLocated
   SrcSpanAnnA
   (Match (GhcPass p) (GenLocated SrcSpanAnnA (HsExpr (GhcPass p))))]
alts = forall doc. IsLine doc => String -> doc
text String
"{}"
            | Bool
otherwise = Int -> SDoc -> SDoc
nest Int
2 (forall (idR :: Pass) body.
(OutputableBndrId idR, Outputable body) =>
MatchGroup (GhcPass idR) body -> SDoc
pprMatches MatchGroup (GhcPass p) (XRec (GhcPass p) (HsExpr (GhcPass p)))
matches)

ppr_expr (HsIf XIf (GhcPass p)
_ XRec (GhcPass p) (HsExpr (GhcPass p))
e1 XRec (GhcPass p) (HsExpr (GhcPass p))
e2 XRec (GhcPass p) (HsExpr (GhcPass p))
e3)
  = forall doc. IsLine doc => [doc] -> doc
sep [forall doc. IsLine doc => [doc] -> doc
hsep [forall doc. IsLine doc => String -> doc
text String
"if", Int -> SDoc -> SDoc
nest Int
2 (forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
e1), forall doc. IsLine doc => String -> doc
text String
"then"],
         Int -> SDoc -> SDoc
nest Int
4 (forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
e2),
         forall doc. IsLine doc => String -> doc
text String
"else",
         Int -> SDoc -> SDoc
nest Int
4 (forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
e3)]

ppr_expr (HsMultiIf XMultiIf (GhcPass p)
_ [LGRHS (GhcPass p) (XRec (GhcPass p) (HsExpr (GhcPass p)))]
alts)
  = SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"if") Int
3  (forall doc. IsDoc doc => [doc] -> doc
vcat (forall a b. (a -> b) -> [a] -> [b]
map forall {a} {p} {l}.
(Outputable a,
 Outputable (XRec p (StmtLR p p (XRec p (HsExpr p)))),
 Outputable (XXGRHS p a)) =>
GenLocated l (GRHS p a) -> SDoc
ppr_alt [LGRHS (GhcPass p) (XRec (GhcPass p) (HsExpr (GhcPass p)))]
alts))
  where ppr_alt :: GenLocated l (GRHS p a) -> SDoc
ppr_alt (L l
_ (GRHS XCGRHS p a
_ [XRec p (StmtLR p p (XRec p (HsExpr p)))]
guards a
expr)) =
          SDoc -> Int -> SDoc -> SDoc
hang forall doc. IsLine doc => doc
vbar Int
2 ([SDoc] -> SDoc
ppr_one [SDoc]
one_alt)
          where
            ppr_one :: [SDoc] -> SDoc
ppr_one [] = forall a. HasCallStack => String -> a
panic String
"ppr_exp HsMultiIf"
            ppr_one (SDoc
h:[SDoc]
t) = SDoc -> Int -> SDoc -> SDoc
hang SDoc
h Int
2 (forall doc. IsLine doc => [doc] -> doc
sep [SDoc]
t)
            one_alt :: [SDoc]
one_alt = [ forall a. Outputable a => [a] -> SDoc
interpp'SP [XRec p (StmtLR p p (XRec p (HsExpr p)))]
guards
                      , forall doc. IsLine doc => String -> doc
text String
"->" forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
pprDeeper (forall a. Outputable a => a -> SDoc
ppr a
expr) ]
        ppr_alt (L l
_ (XGRHS XXGRHS p a
x)) = forall a. Outputable a => a -> SDoc
ppr XXGRHS p a
x

-- special case: let ... in let ...
ppr_expr (HsLet XLet (GhcPass p)
_ LHsToken "let" (GhcPass p)
_ HsLocalBinds (GhcPass p)
binds LHsToken "in" (GhcPass p)
_ expr :: XRec (GhcPass p) (HsExpr (GhcPass p))
expr@(L SrcSpanAnnA
_ (HsLet XLet (GhcPass p)
_ LHsToken "let" (GhcPass p)
_ HsLocalBinds (GhcPass p)
_ LHsToken "in" (GhcPass p)
_ XRec (GhcPass p) (HsExpr (GhcPass p))
_)))
  = forall doc. IsLine doc => [doc] -> doc
sep [SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"let") Int
2 (forall doc. IsLine doc => [doc] -> doc
hsep [forall (idL :: Pass) (idR :: Pass).
(OutputableBndrId idL, OutputableBndrId idR) =>
HsLocalBindsLR (GhcPass idL) (GhcPass idR) -> SDoc
pprBinds HsLocalBinds (GhcPass p)
binds, forall doc. IsLine doc => String -> doc
text String
"in"]),
         forall (p :: Pass).
OutputableBndrId p =>
LHsExpr (GhcPass p) -> SDoc
ppr_lexpr XRec (GhcPass p) (HsExpr (GhcPass p))
expr]

ppr_expr (HsLet XLet (GhcPass p)
_ LHsToken "let" (GhcPass p)
_ HsLocalBinds (GhcPass p)
binds LHsToken "in" (GhcPass p)
_ XRec (GhcPass p) (HsExpr (GhcPass p))
expr)
  = forall doc. IsLine doc => [doc] -> doc
sep [SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"let") Int
2 (forall (idL :: Pass) (idR :: Pass).
(OutputableBndrId idL, OutputableBndrId idR) =>
HsLocalBindsLR (GhcPass idL) (GhcPass idR) -> SDoc
pprBinds HsLocalBinds (GhcPass p)
binds),
         SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"in")  Int
2 (forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
expr)]

ppr_expr (HsDo XDo (GhcPass p)
_ HsDoFlavour
do_or_list_comp (L SrcSpanAnnL
_ [GenLocated
   SrcSpanAnnA
   (StmtLR
      (GhcPass p)
      (GhcPass p)
      (GenLocated SrcSpanAnnA (HsExpr (GhcPass p))))]
stmts)) = forall (p :: Pass) body.
(OutputableBndrId p, Outputable body,
 Anno (StmtLR (GhcPass p) (GhcPass p) body) ~ SrcSpanAnnA) =>
HsDoFlavour -> [LStmt (GhcPass p) body] -> SDoc
pprDo HsDoFlavour
do_or_list_comp [GenLocated
   SrcSpanAnnA
   (StmtLR
      (GhcPass p)
      (GhcPass p)
      (GenLocated SrcSpanAnnA (HsExpr (GhcPass p))))]
stmts

ppr_expr (ExplicitList XExplicitList (GhcPass p)
_ [XRec (GhcPass p) (HsExpr (GhcPass p))]
exprs)
  = forall doc. IsLine doc => doc -> doc
brackets (([SDoc] -> SDoc) -> [SDoc] -> SDoc
pprDeeperList forall doc. IsLine doc => [doc] -> doc
fsep (forall doc. IsLine doc => doc -> [doc] -> [doc]
punctuate forall doc. IsLine doc => doc
comma (forall a b. (a -> b) -> [a] -> [b]
map forall (p :: Pass).
OutputableBndrId p =>
LHsExpr (GhcPass p) -> SDoc
ppr_lexpr [XRec (GhcPass p) (HsExpr (GhcPass p))]
exprs)))

ppr_expr (RecordCon { rcon_con :: forall p. HsExpr p -> XRec p (ConLikeP p)
rcon_con = XRec (GhcPass p) (ConLikeP (GhcPass p))
con, rcon_flds :: forall p. HsExpr p -> HsRecordBinds p
rcon_flds = HsRecordBinds (GhcPass p)
rbinds })
  = SDoc -> Int -> SDoc -> SDoc
hang SDoc
pp_con Int
2 (forall a. Outputable a => a -> SDoc
ppr HsRecordBinds (GhcPass p)
rbinds)
  where
    -- con :: ConLikeP (GhcPass p)
    -- so we need case analysis to know to print it
    pp_con :: SDoc
pp_con = case forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p of
               GhcPass p
GhcPs -> forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (ConLikeP (GhcPass p))
con
               GhcPass p
GhcRn -> forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (ConLikeP (GhcPass p))
con
               GhcPass p
GhcTc -> forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (ConLikeP (GhcPass p))
con

ppr_expr (RecordUpd { rupd_expr :: forall p. HsExpr p -> LHsExpr p
rupd_expr = L SrcSpanAnnA
_ HsExpr (GhcPass p)
aexp, rupd_flds :: forall p. HsExpr p -> Either [LHsRecUpdField p] [LHsRecUpdProj p]
rupd_flds = Either [LHsRecUpdField (GhcPass p)] [LHsRecUpdProj (GhcPass p)]
flds })
  = case Either [LHsRecUpdField (GhcPass p)] [LHsRecUpdProj (GhcPass p)]
flds of
      Left [LHsRecUpdField (GhcPass p)]
rbinds -> SDoc -> Int -> SDoc -> SDoc
hang (forall a. Outputable a => a -> SDoc
ppr HsExpr (GhcPass p)
aexp) Int
2 (forall doc. IsLine doc => doc -> doc
braces (forall doc. IsLine doc => [doc] -> doc
fsep (forall doc. IsLine doc => doc -> [doc] -> [doc]
punctuate forall doc. IsLine doc => doc
comma (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [LHsRecUpdField (GhcPass p)]
rbinds))))
      Right [LHsRecUpdProj (GhcPass p)]
pbinds -> SDoc -> Int -> SDoc -> SDoc
hang (forall a. Outputable a => a -> SDoc
ppr HsExpr (GhcPass p)
aexp) Int
2 (forall doc. IsLine doc => doc -> doc
braces (forall doc. IsLine doc => [doc] -> doc
fsep (forall doc. IsLine doc => doc -> [doc] -> [doc]
punctuate forall doc. IsLine doc => doc
comma (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [LHsRecUpdProj (GhcPass p)]
pbinds))))

ppr_expr (HsGetField { gf_expr :: forall p. HsExpr p -> LHsExpr p
gf_expr = L SrcSpanAnnA
_ HsExpr (GhcPass p)
fexp, gf_field :: forall p. HsExpr p -> XRec p (DotFieldOcc p)
gf_field = XRec (GhcPass p) (DotFieldOcc (GhcPass p))
field })
  = forall a. Outputable a => a -> SDoc
ppr HsExpr (GhcPass p)
fexp forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
dot forall doc. IsLine doc => doc -> doc -> doc
<> forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (DotFieldOcc (GhcPass p))
field

ppr_expr (HsProjection { proj_flds :: forall p. HsExpr p -> NonEmpty (XRec p (DotFieldOcc p))
proj_flds = NonEmpty (XRec (GhcPass p) (DotFieldOcc (GhcPass p)))
flds }) = forall doc. IsLine doc => doc -> doc
parens (forall doc. IsLine doc => [doc] -> doc
hcat (forall doc. IsLine doc => doc
dot forall a. a -> [a] -> [a]
: (forall doc. IsLine doc => doc -> [doc] -> [doc]
punctuate forall doc. IsLine doc => doc
dot (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t a -> [a]
toList NonEmpty (XRec (GhcPass p) (DotFieldOcc (GhcPass p)))
flds))))

ppr_expr (ExprWithTySig XExprWithTySig (GhcPass p)
_ XRec (GhcPass p) (HsExpr (GhcPass p))
expr LHsSigWcType (NoGhcTc (GhcPass p))
sig)
  = SDoc -> Int -> SDoc -> SDoc
hang (Int -> SDoc -> SDoc
nest Int
2 (forall (p :: Pass).
OutputableBndrId p =>
LHsExpr (GhcPass p) -> SDoc
ppr_lexpr XRec (GhcPass p) (HsExpr (GhcPass p))
expr) forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
dcolon)
         Int
4 (forall a. Outputable a => a -> SDoc
ppr LHsSigWcType (NoGhcTc (GhcPass p))
sig)

ppr_expr (ArithSeq XArithSeq (GhcPass p)
_ Maybe (SyntaxExpr (GhcPass p))
_ ArithSeqInfo (GhcPass p)
info) = forall doc. IsLine doc => doc -> doc
brackets (forall a. Outputable a => a -> SDoc
ppr ArithSeqInfo (GhcPass p)
info)

ppr_expr (HsTypedSplice XTypedSplice (GhcPass p)
ext XRec (GhcPass p) (HsExpr (GhcPass p))
e)   =
    case forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p of
      GhcPass p
GhcPs -> forall (p :: Pass).
OutputableBndrId p =>
Maybe Name -> LHsExpr (GhcPass p) -> SDoc
pprTypedSplice forall a. Maybe a
Nothing XRec (GhcPass p) (HsExpr (GhcPass p))
e
      GhcPass p
GhcRn -> forall (p :: Pass).
OutputableBndrId p =>
Maybe Name -> LHsExpr (GhcPass p) -> SDoc
pprTypedSplice (forall a. a -> Maybe a
Just XTypedSplice (GhcPass p)
ext) XRec (GhcPass p) (HsExpr (GhcPass p))
e
      GhcPass p
GhcTc -> forall (p :: Pass).
OutputableBndrId p =>
Maybe Name -> LHsExpr (GhcPass p) -> SDoc
pprTypedSplice forall a. Maybe a
Nothing XRec (GhcPass p) (HsExpr (GhcPass p))
e
ppr_expr (HsUntypedSplice XUntypedSplice (GhcPass p)
ext HsUntypedSplice (GhcPass p)
s) =
    case forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p of
      GhcPass p
GhcPs -> forall (p :: Pass).
OutputableBndrId p =>
Bool -> Maybe Name -> HsUntypedSplice (GhcPass p) -> SDoc
pprUntypedSplice Bool
True forall a. Maybe a
Nothing HsUntypedSplice (GhcPass p)
s
      GhcPass p
GhcRn | HsUntypedSpliceNested Name
n <- XUntypedSplice (GhcPass p)
ext -> forall (p :: Pass).
OutputableBndrId p =>
Bool -> Maybe Name -> HsUntypedSplice (GhcPass p) -> SDoc
pprUntypedSplice Bool
True (forall a. a -> Maybe a
Just Name
n) HsUntypedSplice (GhcPass p)
s
      GhcPass p
GhcRn | HsUntypedSpliceTop ThModFinalizers
_ HsExpr GhcRn
e  <- XUntypedSplice (GhcPass p)
ext -> forall a. Outputable a => a -> SDoc
ppr HsExpr GhcRn
e
      GhcPass p
GhcTc -> forall a. DataConCantHappen -> a
dataConCantHappen XUntypedSplice (GhcPass p)
ext

ppr_expr (HsTypedBracket XTypedBracket (GhcPass p)
b XRec (GhcPass p) (HsExpr (GhcPass p))
e)
  = case forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p of
    GhcPass p
GhcPs -> SDoc -> SDoc
thTyBrackets (forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
e)
    GhcPass p
GhcRn -> SDoc -> SDoc
thTyBrackets (forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
e)
    GhcPass p
GhcTc | HsBracketTc HsQuote GhcRn
_  Type
_ty Maybe QuoteWrapper
_wrap [PendingTcSplice]
ps <- XTypedBracket (GhcPass p)
b ->
      SDoc -> SDoc
thTyBrackets (forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
e) SDoc -> [PendingTcSplice] -> SDoc
`ppr_with_pending_tc_splices` [PendingTcSplice]
ps
ppr_expr (HsUntypedBracket XUntypedBracket (GhcPass p)
b HsQuote (GhcPass p)
q)
  = case forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p of
    GhcPass p
GhcPs -> forall a. Outputable a => a -> SDoc
ppr HsQuote (GhcPass p)
q
    GhcPass p
GhcRn -> case XUntypedBracket (GhcPass p)
b of
      [] -> forall a. Outputable a => a -> SDoc
ppr HsQuote (GhcPass p)
q
      XUntypedBracket (GhcPass p)
ps -> forall a. Outputable a => a -> SDoc
ppr HsQuote (GhcPass p)
q forall doc. IsDoc doc => doc -> doc -> doc
$$ forall doc. IsLine doc => String -> doc
text String
"pending(rn)" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr XUntypedBracket (GhcPass p)
ps
    GhcPass p
GhcTc | HsBracketTc HsQuote GhcRn
rnq  Type
_ty Maybe QuoteWrapper
_wrap [PendingTcSplice]
ps <- XUntypedBracket (GhcPass p)
b ->
      forall a. Outputable a => a -> SDoc
ppr HsQuote GhcRn
rnq SDoc -> [PendingTcSplice] -> SDoc
`ppr_with_pending_tc_splices` [PendingTcSplice]
ps

ppr_expr (HsProc XProc (GhcPass p)
_ LPat (GhcPass p)
pat (L SrcAnn NoEpAnns
_ (HsCmdTop XCmdTop (GhcPass p)
_ LHsCmd (GhcPass p)
cmd)))
  = forall doc. IsLine doc => [doc] -> doc
hsep [forall doc. IsLine doc => String -> doc
text String
"proc", forall a. Outputable a => a -> SDoc
ppr LPat (GhcPass p)
pat, forall doc. IsLine doc => String -> doc
text String
"->", forall a. Outputable a => a -> SDoc
ppr LHsCmd (GhcPass p)
cmd]

ppr_expr (HsStatic XStatic (GhcPass p)
_ XRec (GhcPass p) (HsExpr (GhcPass p))
e)
  = forall doc. IsLine doc => [doc] -> doc
hsep [forall doc. IsLine doc => String -> doc
text String
"static", forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
e]

ppr_expr (XExpr XXExpr (GhcPass p)
x) = case forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p of
#if __GLASGOW_HASKELL__ < 811
  GhcPs -> ppr x
#endif
  GhcPass p
GhcRn -> forall a. Outputable a => a -> SDoc
ppr XXExpr (GhcPass p)
x
  GhcPass p
GhcTc -> forall a. Outputable a => a -> SDoc
ppr XXExpr (GhcPass p)
x

instance Outputable XXExprGhcTc where
  ppr :: XXExprGhcTc -> SDoc
ppr (WrapExpr (HsWrap HsWrapper
co_fn HsExpr GhcTc
e))
    = HsWrapper -> (Bool -> SDoc) -> SDoc
pprHsWrapper HsWrapper
co_fn (\Bool
_parens -> forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> SDoc
pprExpr HsExpr GhcTc
e)

  ppr (ExpansionExpr HsExpansion (HsExpr GhcRn) (HsExpr GhcTc)
e)
    = forall a. Outputable a => a -> SDoc
ppr HsExpansion (HsExpr GhcRn) (HsExpr GhcTc)
e -- e is an HsExpansion, we print the original
            -- expression (LHsExpr GhcPs), not the
            -- desugared one (LHsExpr GhcTc).

  ppr (ConLikeTc ConLike
con [Id]
_ [Scaled Type]
_) = forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc ConLike
con
   -- Used in error messages generated by
   -- the pattern match overlap checker

  ppr (HsTick CoreTickish
tickish LHsExpr GhcTc
exp) =
    SDoc -> SDoc -> SDoc
pprTicks (forall a. Outputable a => a -> SDoc
ppr LHsExpr GhcTc
exp) forall a b. (a -> b) -> a -> b
$
      forall a. Outputable a => a -> SDoc
ppr CoreTickish
tickish forall doc. IsLine doc => doc -> doc -> doc
<+> forall (p :: Pass).
OutputableBndrId p =>
LHsExpr (GhcPass p) -> SDoc
ppr_lexpr LHsExpr GhcTc
exp

  ppr (HsBinTick Int
tickIdTrue Int
tickIdFalse LHsExpr GhcTc
exp) =
    SDoc -> SDoc -> SDoc
pprTicks (forall a. Outputable a => a -> SDoc
ppr LHsExpr GhcTc
exp) forall a b. (a -> b) -> a -> b
$
      forall doc. IsLine doc => [doc] -> doc
hcat [forall doc. IsLine doc => String -> doc
text String
"bintick<",
            forall a. Outputable a => a -> SDoc
ppr Int
tickIdTrue,
            forall doc. IsLine doc => String -> doc
text String
",",
            forall a. Outputable a => a -> SDoc
ppr Int
tickIdFalse,
            forall doc. IsLine doc => String -> doc
text String
">(",
            forall a. Outputable a => a -> SDoc
ppr LHsExpr GhcTc
exp, forall doc. IsLine doc => String -> doc
text String
")"]

ppr_infix_expr :: forall p. (OutputableBndrId p) => HsExpr (GhcPass p) -> Maybe SDoc
ppr_infix_expr :: forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> Maybe SDoc
ppr_infix_expr (HsVar XVar (GhcPass p)
_ (L Anno (IdGhcP p)
_ IdGhcP p
v))    = forall a. a -> Maybe a
Just (forall a. OutputableBndr a => a -> SDoc
pprInfixOcc IdGhcP p
v)
ppr_infix_expr (HsRecSel XRecSel (GhcPass p)
_ FieldOcc (GhcPass p)
f)       = forall a. a -> Maybe a
Just (forall a. OutputableBndr a => a -> SDoc
pprInfixOcc FieldOcc (GhcPass p)
f)
ppr_infix_expr (HsUnboundVar XUnboundVar (GhcPass p)
_ RdrName
occ) = forall a. a -> Maybe a
Just (forall a. OutputableBndr a => a -> SDoc
pprInfixOcc RdrName
occ)
ppr_infix_expr (XExpr XXExpr (GhcPass p)
x)            = case forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p of
#if __GLASGOW_HASKELL__ < 901
                                        GhcPs -> Nothing
#endif
                                        GhcPass p
GhcRn -> HsExpansion (HsExpr GhcRn) (HsExpr GhcRn) -> Maybe SDoc
ppr_infix_expr_rn XXExpr (GhcPass p)
x
                                        GhcPass p
GhcTc -> XXExprGhcTc -> Maybe SDoc
ppr_infix_expr_tc XXExpr (GhcPass p)
x
ppr_infix_expr HsExpr (GhcPass p)
_ = forall a. Maybe a
Nothing

ppr_infix_expr_rn :: HsExpansion (HsExpr GhcRn) (HsExpr GhcRn) -> Maybe SDoc
ppr_infix_expr_rn :: HsExpansion (HsExpr GhcRn) (HsExpr GhcRn) -> Maybe SDoc
ppr_infix_expr_rn (HsExpanded HsExpr GhcRn
a HsExpr GhcRn
_) = forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> Maybe SDoc
ppr_infix_expr HsExpr GhcRn
a

ppr_infix_expr_tc :: XXExprGhcTc -> Maybe SDoc
ppr_infix_expr_tc :: XXExprGhcTc -> Maybe SDoc
ppr_infix_expr_tc (WrapExpr (HsWrap HsWrapper
_ HsExpr GhcTc
e))          = forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> Maybe SDoc
ppr_infix_expr HsExpr GhcTc
e
ppr_infix_expr_tc (ExpansionExpr (HsExpanded HsExpr GhcRn
a HsExpr GhcTc
_)) = forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> Maybe SDoc
ppr_infix_expr HsExpr GhcRn
a
ppr_infix_expr_tc (ConLikeTc {})                   = forall a. Maybe a
Nothing
ppr_infix_expr_tc (HsTick {})                      = forall a. Maybe a
Nothing
ppr_infix_expr_tc (HsBinTick {})                   = forall a. Maybe a
Nothing

ppr_apps :: (OutputableBndrId p)
         => HsExpr (GhcPass p)
         -> [Either (LHsExpr (GhcPass p)) (LHsWcType (NoGhcTc (GhcPass p)))]
         -> SDoc
ppr_apps :: forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p)
-> [Either (LHsExpr (GhcPass p)) (LHsWcType (NoGhcTc (GhcPass p)))]
-> SDoc
ppr_apps (HsApp XApp (GhcPass p)
_ (L SrcSpanAnnA
_ HsExpr (GhcPass p)
fun) LHsExpr (GhcPass p)
arg)        [Either (LHsExpr (GhcPass p)) (LHsWcType (NoGhcTc (GhcPass p)))]
args
  = forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p)
-> [Either (LHsExpr (GhcPass p)) (LHsWcType (NoGhcTc (GhcPass p)))]
-> SDoc
ppr_apps HsExpr (GhcPass p)
fun (forall a b. a -> Either a b
Left LHsExpr (GhcPass p)
arg forall a. a -> [a] -> [a]
: [Either (LHsExpr (GhcPass p)) (LHsWcType (NoGhcTc (GhcPass p)))]
args)
ppr_apps (HsAppType XAppTypeE (GhcPass p)
_ (L SrcSpanAnnA
_ HsExpr (GhcPass p)
fun) LHsToken "@" (GhcPass p)
_ LHsWcType (NoGhcTc (GhcPass p))
arg)  [Either (LHsExpr (GhcPass p)) (LHsWcType (NoGhcTc (GhcPass p)))]
args
  = forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p)
-> [Either (LHsExpr (GhcPass p)) (LHsWcType (NoGhcTc (GhcPass p)))]
-> SDoc
ppr_apps HsExpr (GhcPass p)
fun (forall a b. b -> Either a b
Right LHsWcType (NoGhcTc (GhcPass p))
arg forall a. a -> [a] -> [a]
: [Either (LHsExpr (GhcPass p)) (LHsWcType (NoGhcTc (GhcPass p)))]
args)
ppr_apps HsExpr (GhcPass p)
fun [Either (LHsExpr (GhcPass p)) (LHsWcType (NoGhcTc (GhcPass p)))]
args = SDoc -> Int -> SDoc -> SDoc
hang (forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> SDoc
ppr_expr HsExpr (GhcPass p)
fun) Int
2 (forall doc. IsLine doc => [doc] -> doc
fsep (forall a b. (a -> b) -> [a] -> [b]
map forall {a} {a}. (Outputable a, Outputable a) => Either a a -> SDoc
pp [Either (LHsExpr (GhcPass p)) (LHsWcType (NoGhcTc (GhcPass p)))]
args))
  where
    pp :: Either a a -> SDoc
pp (Left a
arg)                             = forall a. Outputable a => a -> SDoc
ppr a
arg
    -- pp (Right (LHsWcTypeX (HsWC { hswc_body = L _ arg })))
    --   = char '@' <> pprHsType arg
    pp (Right a
arg)
      = forall doc. IsLine doc => String -> doc
text String
"@" forall doc. IsLine doc => doc -> doc -> doc
<> forall a. Outputable a => a -> SDoc
ppr a
arg


pprDebugParendExpr :: (OutputableBndrId p)
                   => PprPrec -> LHsExpr (GhcPass p) -> SDoc
pprDebugParendExpr :: forall (p :: Pass).
OutputableBndrId p =>
PprPrec -> LHsExpr (GhcPass p) -> SDoc
pprDebugParendExpr PprPrec
p LHsExpr (GhcPass p)
expr
  = forall doc. IsOutput doc => (Bool -> doc) -> doc
getPprDebug forall a b. (a -> b) -> a -> b
$ \case
      Bool
True  -> forall (p :: Pass).
OutputableBndrId p =>
PprPrec -> LHsExpr (GhcPass p) -> SDoc
pprParendLExpr PprPrec
p LHsExpr (GhcPass p)
expr
      Bool
False -> forall (p :: Pass).
OutputableBndrId p =>
LHsExpr (GhcPass p) -> SDoc
pprLExpr         LHsExpr (GhcPass p)
expr

pprParendLExpr :: (OutputableBndrId p)
               => PprPrec -> LHsExpr (GhcPass p) -> SDoc
pprParendLExpr :: forall (p :: Pass).
OutputableBndrId p =>
PprPrec -> LHsExpr (GhcPass p) -> SDoc
pprParendLExpr PprPrec
p (L SrcSpanAnnA
_ HsExpr (GhcPass p)
e) = forall (p :: Pass).
OutputableBndrId p =>
PprPrec -> HsExpr (GhcPass p) -> SDoc
pprParendExpr PprPrec
p HsExpr (GhcPass p)
e

pprParendExpr :: (OutputableBndrId p)
              => PprPrec -> HsExpr (GhcPass p) -> SDoc
pprParendExpr :: forall (p :: Pass).
OutputableBndrId p =>
PprPrec -> HsExpr (GhcPass p) -> SDoc
pprParendExpr PprPrec
p HsExpr (GhcPass p)
expr
  | forall (p :: Pass).
IsPass p =>
PprPrec -> HsExpr (GhcPass p) -> Bool
hsExprNeedsParens PprPrec
p HsExpr (GhcPass p)
expr = forall doc. IsLine doc => doc -> doc
parens (forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> SDoc
pprExpr HsExpr (GhcPass p)
expr)
  | Bool
otherwise                = forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> SDoc
pprExpr HsExpr (GhcPass p)
expr
        -- Using pprLExpr makes sure that we go 'deeper'
        -- I think that is usually (always?) right

-- | @'hsExprNeedsParens' p e@ returns 'True' if the expression @e@ needs
-- parentheses under precedence @p@.
hsExprNeedsParens :: forall p. IsPass p => PprPrec -> HsExpr (GhcPass p) -> Bool
hsExprNeedsParens :: forall (p :: Pass).
IsPass p =>
PprPrec -> HsExpr (GhcPass p) -> Bool
hsExprNeedsParens PprPrec
prec = HsExpr (GhcPass p) -> Bool
go
  where
    go :: HsExpr (GhcPass p) -> Bool
    go :: HsExpr (GhcPass p) -> Bool
go (HsVar{})                      = Bool
False
    go (HsUnboundVar{})               = Bool
False
    go (HsIPVar{})                    = Bool
False
    go (HsOverLabel{})                = Bool
False
    go (HsLit XLitE (GhcPass p)
_ HsLit (GhcPass p)
l)                    = forall x. PprPrec -> HsLit x -> Bool
hsLitNeedsParens PprPrec
prec HsLit (GhcPass p)
l
    go (HsOverLit XOverLitE (GhcPass p)
_ HsOverLit (GhcPass p)
ol)               = forall x. PprPrec -> HsOverLit x -> Bool
hsOverLitNeedsParens PprPrec
prec HsOverLit (GhcPass p)
ol
    go (HsPar{})                      = Bool
False
    go (HsApp{})                      = PprPrec
prec forall a. Ord a => a -> a -> Bool
>= PprPrec
appPrec
    go (HsAppType {})                 = PprPrec
prec forall a. Ord a => a -> a -> Bool
>= PprPrec
appPrec
    go (OpApp{})                      = PprPrec
prec forall a. Ord a => a -> a -> Bool
>= PprPrec
opPrec
    go (NegApp{})                     = PprPrec
prec forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec
    go (SectionL{})                   = Bool
True
    go (SectionR{})                   = Bool
True
    -- Special-case unary boxed tuple applications so that they are
    -- parenthesized as `Identity (Solo x)`, not `Identity Solo x` (#18612)
    -- See Note [One-tuples] in GHC.Builtin.Types
    go (ExplicitTuple XExplicitTuple (GhcPass p)
_ [Present{}] Boxity
Boxed)
                                      = PprPrec
prec forall a. Ord a => a -> a -> Bool
>= PprPrec
appPrec
    go (ExplicitTuple{})              = Bool
False
    go (ExplicitSum{})                = Bool
False
    go (HsLam{})                      = PprPrec
prec forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec
    go (HsLamCase{})                  = PprPrec
prec forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec
    go (HsCase{})                     = PprPrec
prec forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec
    go (HsIf{})                       = PprPrec
prec forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec
    go (HsMultiIf{})                  = PprPrec
prec forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec
    go (HsLet{})                      = PprPrec
prec forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec
    go (HsDo XDo (GhcPass p)
_ HsDoFlavour
sc XRec (GhcPass p) [ExprLStmt (GhcPass p)]
_)
      | HsDoFlavour -> Bool
isDoComprehensionContext HsDoFlavour
sc   = Bool
False
      | Bool
otherwise                     = PprPrec
prec forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec
    go (ExplicitList{})               = Bool
False
    go (RecordUpd{})                  = Bool
False
    go (ExprWithTySig{})              = PprPrec
prec forall a. Ord a => a -> a -> Bool
>= PprPrec
sigPrec
    go (ArithSeq{})                   = Bool
False
    go (HsPragE{})                    = PprPrec
prec forall a. Ord a => a -> a -> Bool
>= PprPrec
appPrec
    go (HsTypedSplice{})              = Bool
False
    go (HsUntypedSplice{})            = Bool
False
    go (HsTypedBracket{})             = Bool
False
    go (HsUntypedBracket{})           = Bool
False
    go (HsProc{})                     = PprPrec
prec forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec
    go (HsStatic{})                   = PprPrec
prec forall a. Ord a => a -> a -> Bool
>= PprPrec
appPrec
    go (RecordCon{})                  = Bool
False
    go (HsRecSel{})                   = Bool
False
    go (HsProjection{})               = Bool
True
    go (HsGetField{})                 = Bool
False
    go (XExpr XXExpr (GhcPass p)
x) = case forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p of
                     GhcPass p
GhcTc -> XXExprGhcTc -> Bool
go_x_tc XXExpr (GhcPass p)
x
                     GhcPass p
GhcRn -> HsExpansion (HsExpr GhcRn) (HsExpr GhcRn) -> Bool
go_x_rn XXExpr (GhcPass p)
x
#if __GLASGOW_HASKELL__ <= 900
                     GhcPs -> True
#endif

    go_x_tc :: XXExprGhcTc -> Bool
    go_x_tc :: XXExprGhcTc -> Bool
go_x_tc (WrapExpr (HsWrap HsWrapper
_ HsExpr GhcTc
e))          = forall (p :: Pass).
IsPass p =>
PprPrec -> HsExpr (GhcPass p) -> Bool
hsExprNeedsParens PprPrec
prec HsExpr GhcTc
e
    go_x_tc (ExpansionExpr (HsExpanded HsExpr GhcRn
a HsExpr GhcTc
_)) = forall (p :: Pass).
IsPass p =>
PprPrec -> HsExpr (GhcPass p) -> Bool
hsExprNeedsParens PprPrec
prec HsExpr GhcRn
a
    go_x_tc (ConLikeTc {})                   = Bool
False
    go_x_tc (HsTick CoreTickish
_ (L SrcSpanAnnA
_ HsExpr GhcTc
e))               = forall (p :: Pass).
IsPass p =>
PprPrec -> HsExpr (GhcPass p) -> Bool
hsExprNeedsParens PprPrec
prec HsExpr GhcTc
e
    go_x_tc (HsBinTick Int
_ Int
_ (L SrcSpanAnnA
_ HsExpr GhcTc
e))          = forall (p :: Pass).
IsPass p =>
PprPrec -> HsExpr (GhcPass p) -> Bool
hsExprNeedsParens PprPrec
prec HsExpr GhcTc
e

    go_x_rn :: HsExpansion (HsExpr GhcRn) (HsExpr GhcRn) -> Bool
    go_x_rn :: HsExpansion (HsExpr GhcRn) (HsExpr GhcRn) -> Bool
go_x_rn (HsExpanded HsExpr GhcRn
a HsExpr GhcRn
_) = forall (p :: Pass).
IsPass p =>
PprPrec -> HsExpr (GhcPass p) -> Bool
hsExprNeedsParens PprPrec
prec HsExpr GhcRn
a


-- | Parenthesize an expression without token information
gHsPar :: LHsExpr (GhcPass id) -> HsExpr (GhcPass id)
gHsPar :: forall (id :: Pass). LHsExpr (GhcPass id) -> HsExpr (GhcPass id)
gHsPar LHsExpr (GhcPass id)
e = forall p.
XPar p -> LHsToken "(" p -> LHsExpr p -> LHsToken ")" p -> HsExpr p
HsPar forall a. EpAnn a
noAnn forall (tok :: Symbol). GenLocated TokenLocation (HsToken tok)
noHsTok LHsExpr (GhcPass id)
e forall (tok :: Symbol). GenLocated TokenLocation (HsToken tok)
noHsTok

-- | @'parenthesizeHsExpr' p e@ checks if @'hsExprNeedsParens' p e@ is true,
-- and if so, surrounds @e@ with an 'HsPar'. Otherwise, it simply returns @e@.
parenthesizeHsExpr :: IsPass p => PprPrec -> LHsExpr (GhcPass p) -> LHsExpr (GhcPass p)
parenthesizeHsExpr :: forall (p :: Pass).
IsPass p =>
PprPrec -> LHsExpr (GhcPass p) -> LHsExpr (GhcPass p)
parenthesizeHsExpr PprPrec
p le :: LHsExpr (GhcPass p)
le@(L SrcSpanAnnA
loc HsExpr (GhcPass p)
e)
  | forall (p :: Pass).
IsPass p =>
PprPrec -> HsExpr (GhcPass p) -> Bool
hsExprNeedsParens PprPrec
p HsExpr (GhcPass p)
e = forall l e. l -> e -> GenLocated l e
L SrcSpanAnnA
loc (forall (id :: Pass). LHsExpr (GhcPass id) -> HsExpr (GhcPass id)
gHsPar LHsExpr (GhcPass p)
le)
  | Bool
otherwise             = LHsExpr (GhcPass p)
le

stripParensLHsExpr :: LHsExpr (GhcPass p) -> LHsExpr (GhcPass p)
stripParensLHsExpr :: forall (p :: Pass). LHsExpr (GhcPass p) -> LHsExpr (GhcPass p)
stripParensLHsExpr (L SrcSpanAnnA
_ (HsPar XPar (GhcPass p)
_ LHsToken "(" (GhcPass p)
_ LHsExpr (GhcPass p)
e LHsToken ")" (GhcPass p)
_)) = forall (p :: Pass). LHsExpr (GhcPass p) -> LHsExpr (GhcPass p)
stripParensLHsExpr LHsExpr (GhcPass p)
e
stripParensLHsExpr LHsExpr (GhcPass p)
e = LHsExpr (GhcPass p)
e

stripParensHsExpr :: HsExpr (GhcPass p) -> HsExpr (GhcPass p)
stripParensHsExpr :: forall (p :: Pass). HsExpr (GhcPass p) -> HsExpr (GhcPass p)
stripParensHsExpr (HsPar XPar (GhcPass p)
_ LHsToken "(" (GhcPass p)
_ (L SrcSpanAnnA
_ HsExpr (GhcPass p)
e) LHsToken ")" (GhcPass p)
_) = forall (p :: Pass). HsExpr (GhcPass p) -> HsExpr (GhcPass p)
stripParensHsExpr HsExpr (GhcPass p)
e
stripParensHsExpr HsExpr (GhcPass p)
e = HsExpr (GhcPass p)
e

isAtomicHsExpr :: forall p. IsPass p => HsExpr (GhcPass p) -> Bool
-- True of a single token
isAtomicHsExpr :: forall (p :: Pass). IsPass p => HsExpr (GhcPass p) -> Bool
isAtomicHsExpr (HsVar {})        = Bool
True
isAtomicHsExpr (HsLit {})        = Bool
True
isAtomicHsExpr (HsOverLit {})    = Bool
True
isAtomicHsExpr (HsIPVar {})      = Bool
True
isAtomicHsExpr (HsOverLabel {})  = Bool
True
isAtomicHsExpr (HsUnboundVar {}) = Bool
True
isAtomicHsExpr (HsRecSel{})      = Bool
True
isAtomicHsExpr (XExpr XXExpr (GhcPass p)
x)
  | GhcPass p
GhcTc <- forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p          = XXExprGhcTc -> Bool
go_x_tc XXExpr (GhcPass p)
x
  | GhcPass p
GhcRn <- forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p          = forall {p :: Pass} {expanded}.
IsPass p =>
HsExpansion (HsExpr (GhcPass p)) expanded -> Bool
go_x_rn XXExpr (GhcPass p)
x
  where
    go_x_tc :: XXExprGhcTc -> Bool
go_x_tc (WrapExpr      (HsWrap HsWrapper
_ HsExpr GhcTc
e))     = forall (p :: Pass). IsPass p => HsExpr (GhcPass p) -> Bool
isAtomicHsExpr HsExpr GhcTc
e
    go_x_tc (ExpansionExpr (HsExpanded HsExpr GhcRn
a HsExpr GhcTc
_)) = forall (p :: Pass). IsPass p => HsExpr (GhcPass p) -> Bool
isAtomicHsExpr HsExpr GhcRn
a
    go_x_tc (ConLikeTc {})                   = Bool
True
    go_x_tc (HsTick {}) = Bool
False
    go_x_tc (HsBinTick {}) = Bool
False

    go_x_rn :: HsExpansion (HsExpr (GhcPass p)) expanded -> Bool
go_x_rn (HsExpanded HsExpr (GhcPass p)
a expanded
_) = forall (p :: Pass). IsPass p => HsExpr (GhcPass p) -> Bool
isAtomicHsExpr HsExpr (GhcPass p)
a

isAtomicHsExpr HsExpr (GhcPass p)
_ = Bool
False

instance Outputable (HsPragE (GhcPass p)) where
  ppr :: HsPragE (GhcPass p) -> SDoc
ppr (HsPragSCC (EpAnn AnnPragma
_, SourceText
st) (StringLiteral SourceText
stl FastString
lbl Maybe RealSrcSpan
_)) =
    SourceText -> SDoc -> SDoc
pprWithSourceText SourceText
st (forall doc. IsLine doc => String -> doc
text String
"{-# SCC")
     -- no doublequotes if stl empty, for the case where the SCC was written
     -- without quotes.
    forall doc. IsLine doc => doc -> doc -> doc
<+> SourceText -> SDoc -> SDoc
pprWithSourceText SourceText
stl (forall doc. IsLine doc => FastString -> doc
ftext FastString
lbl) forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"#-}"


{- *********************************************************************
*                                                                      *
             HsExpansion and rebindable syntax
*                                                                      *
********************************************************************* -}

{- Note [Rebindable syntax and HsExpansion]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We implement rebindable syntax (RS) support by performing a desugaring
in the renamer. We transform GhcPs expressions and patterns affected by
RS into the appropriate desugared form, but **annotated with the original
expression/pattern**.

Let us consider a piece of code like:

    {-# LANGUAGE RebindableSyntax #-}
    ifThenElse :: Char -> () -> () -> ()
    ifThenElse _ _ _ = ()
    x = if 'a' then () else True

The parsed AST for the RHS of x would look something like (slightly simplified):

    L locif (HsIf (L loca 'a') (L loctrue ()) (L locfalse True))

Upon seeing such an AST with RS on, we could transform it into a
mere function call, as per the RS rules, equivalent to the
following function application:

    ifThenElse 'a' () True

which doesn't typecheck. But GHC would report an error about
not being able to match the third argument's type (Bool) with the
expected type: (), in the expression _as desugared_, i.e in
the aforementioned function application. But the user never
wrote a function application! This would be pretty bad.

To remedy this, instead of transforming the original HsIf
node into mere applications of 'ifThenElse', we keep the
original 'if' expression around too, using the TTG
XExpr extension point to allow GHC to construct an
'HsExpansion' value that will keep track of the original
expression in its first field, and the desugared one in the
second field. The resulting renamed AST would look like:

    L locif (XExpr
      (HsExpanded
        (HsIf (L loca 'a')
              (L loctrue ())
              (L locfalse True)
        )
        (App (L generatedSrcSpan
                (App (L generatedSrcSpan
                        (App (L generatedSrcSpan (Var ifThenElse))
                             (L loca 'a')
                        )
                     )
                     (L loctrue ())
                )
             )
             (L locfalse True)
        )
      )
    )

When comes the time to typecheck the program, we end up calling
tcMonoExpr on the AST above. If this expression gives rise to
a type error, then it will appear in a context line and GHC
will pretty-print it using the 'Outputable (HsExpansion a b)'
instance defined below, which *only prints the original
expression*. This is the gist of the idea, but is not quite
enough to recover the error messages that we had with the
SyntaxExpr-based, typechecking/desugaring-to-core time
implementation of rebindable syntax. The key idea is to decorate
some elements of the desugared expression so as to be able to
give them a special treatment when typechecking the desugared
expression, to print a different context line or skip one
altogether.

Whenever we 'setSrcSpan' a 'generatedSrcSpan', we update a field in
TcLclEnv called 'tcl_in_gen_code', setting it to True, which indicates that we
entered generated code, i.e code fabricated by the compiler when rebinding some
syntax. If someone tries to push some error context line while that field is set
to True, the pushing won't actually happen and the context line is just dropped.
Once we 'setSrcSpan' a real span (for an expression that was in the original
source code), we set 'tcl_in_gen_code' back to False, indicating that we
"emerged from the generated code tunnel", and that the expressions we will be
processing are relevant to report in context lines again.

You might wonder why TcLclEnv has both
   tcl_loc         :: RealSrcSpan
   tcl_in_gen_code :: Bool
Could we not store a Maybe RealSrcSpan? The problem is that we still
generate constraints when processing generated code, and a CtLoc must
contain a RealSrcSpan -- otherwise, error messages might appear
without source locations. So tcl_loc keeps the RealSrcSpan of the last
location spotted that wasn't generated; it's as good as we're going to
get in generated code. Once we get to sub-trees that are not
generated, then we update the RealSrcSpan appropriately, and set the
tcl_in_gen_code Bool to False.

---

An overview of the constructs that are desugared in this way is laid out in
Note [Handling overloaded and rebindable constructs] in GHC.Rename.Expr.

A general recipe to follow this approach for new constructs could go as follows:

- Remove any GhcRn-time SyntaxExpr extensions to the relevant constructor for your
  construct, in HsExpr or related syntax data types.
- At renaming-time:
    - take your original node of interest (HsIf above)
    - rename its subexpressions/subpatterns (condition and true/false
      branches above)
    - construct the suitable "rebound"-and-renamed result (ifThenElse call
      above), where the 'SrcSpan' attached to any _fabricated node_ (the
      HsVar/HsApp nodes, above) is set to 'generatedSrcSpan'
    - take both the original node and that rebound-and-renamed result and wrap
      them into an expansion construct:
        for expressions, XExpr (HsExpanded <original node> <desugared>)
        for patterns, XPat (HsPatExpanded <original node> <desugared>)
 - At typechecking-time:
    - remove any logic that was previously dealing with your rebindable
      construct, typically involving [tc]SyntaxOp, SyntaxExpr and friends.
    - the XExpr (HsExpanded ... ...) case in tcExpr already makes sure that we
      typecheck the desugared expression while reporting the original one in
      errors
-}

{- Note [Overview of record dot syntax]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is the note that explains all the moving parts for record dot
syntax.

The language extensions @OverloadedRecordDot@ and
@OverloadedRecordUpdate@ (providing "record dot syntax") are
implemented using the techniques of Note [Rebindable syntax and
HsExpansion].

When OverloadedRecordDot is enabled:
- Field selection expressions
  - e.g. foo.bar.baz
  - Have abstract syntax HsGetField
  - After renaming are XExpr (HsExpanded (HsGetField ...) (getField @"..."...)) expressions
- Field selector expressions e.g. (.x.y)
  - Have abstract syntax HsProjection
  - After renaming are XExpr (HsExpanded (HsProjection ...) ((getField @"...") . (getField @"...") . ...) expressions

When OverloadedRecordUpdate is enabled:
- Record update expressions
  - e.g. a{foo.bar=1, quux="corge", baz}
  - Have abstract syntax RecordUpd
    - With rupd_flds containting a Right
    - See Note [RecordDotSyntax field updates] (in Language.Haskell.Syntax.Expr)
  - After renaming are XExpr (HsExpanded (RecordUpd ...) (setField@"..." ...) expressions
    - Note that this is true for all record updates even for those that do not involve '.'

When OverloadedRecordDot is enabled and RebindableSyntax is not
enabled the name 'getField' is resolved to GHC.Records.getField. When
OverloadedRecordDot is enabled and RebindableSyntax is enabled the
name 'getField' is whatever in-scope name that is.

When OverloadedRecordUpd is enabled and RebindableSyntax is not
enabled it is an error for now (temporary while we wait on native
setField support; see
https://gitlab.haskell.org/ghc/ghc/-/issues/16232). When
OverloadedRecordUpd is enabled and RebindableSyntax is enabled the
names 'getField' and 'setField' are whatever in-scope names they are.
-}

-- See Note [Rebindable syntax and HsExpansion] just above.
data HsExpansion orig expanded
  = HsExpanded orig expanded
  deriving HsExpansion orig expanded -> DataType
HsExpansion orig expanded -> Constr
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 {orig} {expanded}.
(Data orig, Data expanded) =>
Typeable (HsExpansion orig expanded)
forall orig expanded.
(Data orig, Data expanded) =>
HsExpansion orig expanded -> DataType
forall orig expanded.
(Data orig, Data expanded) =>
HsExpansion orig expanded -> Constr
forall orig expanded.
(Data orig, Data expanded) =>
(forall b. Data b => b -> b)
-> HsExpansion orig expanded -> HsExpansion orig expanded
forall orig expanded u.
(Data orig, Data expanded) =>
Int
-> (forall d. Data d => d -> u) -> HsExpansion orig expanded -> u
forall orig expanded u.
(Data orig, Data expanded) =>
(forall d. Data d => d -> u) -> HsExpansion orig expanded -> [u]
forall orig expanded r r'.
(Data orig, Data expanded) =>
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> HsExpansion orig expanded
-> r
forall orig expanded r r'.
(Data orig, Data expanded) =>
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> HsExpansion orig expanded
-> r
forall orig expanded (m :: * -> *).
(Data orig, Data expanded, Monad m) =>
(forall d. Data d => d -> m d)
-> HsExpansion orig expanded -> m (HsExpansion orig expanded)
forall orig expanded (m :: * -> *).
(Data orig, Data expanded, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> HsExpansion orig expanded -> m (HsExpansion orig expanded)
forall orig expanded (c :: * -> *).
(Data orig, Data expanded) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (HsExpansion orig expanded)
forall orig expanded (c :: * -> *).
(Data orig, Data expanded) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> HsExpansion orig expanded
-> c (HsExpansion orig expanded)
forall orig expanded (t :: * -> *) (c :: * -> *).
(Data orig, Data expanded, Typeable t) =>
(forall d. Data d => c (t d))
-> Maybe (c (HsExpansion orig expanded))
forall orig expanded (t :: * -> * -> *) (c :: * -> *).
(Data orig, Data expanded, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (HsExpansion orig expanded))
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (HsExpansion orig expanded)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> HsExpansion orig expanded
-> c (HsExpansion orig expanded)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (HsExpansion orig expanded))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> HsExpansion orig expanded -> m (HsExpansion orig expanded)
$cgmapMo :: forall orig expanded (m :: * -> *).
(Data orig, Data expanded, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> HsExpansion orig expanded -> m (HsExpansion orig expanded)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> HsExpansion orig expanded -> m (HsExpansion orig expanded)
$cgmapMp :: forall orig expanded (m :: * -> *).
(Data orig, Data expanded, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> HsExpansion orig expanded -> m (HsExpansion orig expanded)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> HsExpansion orig expanded -> m (HsExpansion orig expanded)
$cgmapM :: forall orig expanded (m :: * -> *).
(Data orig, Data expanded, Monad m) =>
(forall d. Data d => d -> m d)
-> HsExpansion orig expanded -> m (HsExpansion orig expanded)
gmapQi :: forall u.
Int
-> (forall d. Data d => d -> u) -> HsExpansion orig expanded -> u
$cgmapQi :: forall orig expanded u.
(Data orig, Data expanded) =>
Int
-> (forall d. Data d => d -> u) -> HsExpansion orig expanded -> u
gmapQ :: forall u.
(forall d. Data d => d -> u) -> HsExpansion orig expanded -> [u]
$cgmapQ :: forall orig expanded u.
(Data orig, Data expanded) =>
(forall d. Data d => d -> u) -> HsExpansion orig expanded -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> HsExpansion orig expanded
-> r
$cgmapQr :: forall orig expanded r r'.
(Data orig, Data expanded) =>
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> HsExpansion orig expanded
-> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> HsExpansion orig expanded
-> r
$cgmapQl :: forall orig expanded r r'.
(Data orig, Data expanded) =>
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> HsExpansion orig expanded
-> r
gmapT :: (forall b. Data b => b -> b)
-> HsExpansion orig expanded -> HsExpansion orig expanded
$cgmapT :: forall orig expanded.
(Data orig, Data expanded) =>
(forall b. Data b => b -> b)
-> HsExpansion orig expanded -> HsExpansion orig expanded
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (HsExpansion orig expanded))
$cdataCast2 :: forall orig expanded (t :: * -> * -> *) (c :: * -> *).
(Data orig, Data expanded, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (HsExpansion orig expanded))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d))
-> Maybe (c (HsExpansion orig expanded))
$cdataCast1 :: forall orig expanded (t :: * -> *) (c :: * -> *).
(Data orig, Data expanded, Typeable t) =>
(forall d. Data d => c (t d))
-> Maybe (c (HsExpansion orig expanded))
dataTypeOf :: HsExpansion orig expanded -> DataType
$cdataTypeOf :: forall orig expanded.
(Data orig, Data expanded) =>
HsExpansion orig expanded -> DataType
toConstr :: HsExpansion orig expanded -> Constr
$ctoConstr :: forall orig expanded.
(Data orig, Data expanded) =>
HsExpansion orig expanded -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (HsExpansion orig expanded)
$cgunfold :: forall orig expanded (c :: * -> *).
(Data orig, Data expanded) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (HsExpansion orig expanded)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> HsExpansion orig expanded
-> c (HsExpansion orig expanded)
$cgfoldl :: forall orig expanded (c :: * -> *).
(Data orig, Data expanded) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> HsExpansion orig expanded
-> c (HsExpansion orig expanded)
Data

-- | Just print the original expression (the @a@).
instance (Outputable a, Outputable b) => Outputable (HsExpansion a b) where
  ppr :: HsExpansion a b -> SDoc
ppr (HsExpanded a
orig b
expanded)
    = forall doc. IsOutput doc => doc -> doc -> doc
ifPprDebug (forall doc. IsDoc doc => [doc] -> doc
vcat [forall a. Outputable a => a -> SDoc
ppr a
orig, forall doc. IsLine doc => doc -> doc
braces (forall doc. IsLine doc => String -> doc
text String
"Expansion:" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr b
expanded)])
                 (forall a. Outputable a => a -> SDoc
ppr a
orig)


{-
************************************************************************
*                                                                      *
\subsection{Commands (in arrow abstractions)}
*                                                                      *
************************************************************************
-}

type instance XCmdArrApp  GhcPs = EpAnn AddEpAnn
type instance XCmdArrApp  GhcRn = NoExtField
type instance XCmdArrApp  GhcTc = Type

type instance XCmdArrForm GhcPs = EpAnn AnnList
type instance XCmdArrForm GhcRn = NoExtField
type instance XCmdArrForm GhcTc = NoExtField

type instance XCmdApp     (GhcPass _) = EpAnnCO
type instance XCmdLam     (GhcPass _) = NoExtField
type instance XCmdPar     (GhcPass _) = EpAnnCO

type instance XCmdCase    GhcPs = EpAnn EpAnnHsCase
type instance XCmdCase    GhcRn = NoExtField
type instance XCmdCase    GhcTc = NoExtField

type instance XCmdLamCase (GhcPass _) = EpAnn [AddEpAnn]

type instance XCmdIf      GhcPs = EpAnn AnnsIf
type instance XCmdIf      GhcRn = NoExtField
type instance XCmdIf      GhcTc = NoExtField

type instance XCmdLet     GhcPs = EpAnnCO
type instance XCmdLet     GhcRn = NoExtField
type instance XCmdLet     GhcTc = NoExtField

type instance XCmdDo      GhcPs = EpAnn AnnList
type instance XCmdDo      GhcRn = NoExtField
type instance XCmdDo      GhcTc = Type

type instance XCmdWrap    (GhcPass _) = NoExtField

type instance XXCmd       GhcPs = DataConCantHappen
type instance XXCmd       GhcRn = DataConCantHappen
type instance XXCmd       GhcTc = HsWrap HsCmd

type instance Anno [LocatedA (StmtLR (GhcPass pl) (GhcPass pr) (LocatedA (HsCmd (GhcPass pr))))]
  = SrcSpanAnnL

    -- If   cmd :: arg1 --> res
    --      wrap :: arg1 "->" arg2
    -- Then (XCmd (HsWrap wrap cmd)) :: arg2 --> res

-- | Command Syntax Table (for Arrow syntax)
type CmdSyntaxTable p = [(Name, HsExpr p)]
-- See Note [CmdSyntaxTable]

{-
Note [CmdSyntaxTable]
~~~~~~~~~~~~~~~~~~~~~
Used only for arrow-syntax stuff (HsCmdTop), the CmdSyntaxTable keeps
track of the methods needed for a Cmd.

* Before the renamer, this list is an empty list

* After the renamer, it takes the form @[(std_name, HsVar actual_name)]@
  For example, for the 'arr' method
   * normal case:            (GHC.Control.Arrow.arr, HsVar GHC.Control.Arrow.arr)
   * with rebindable syntax: (GHC.Control.Arrow.arr, arr_22)
             where @arr_22@ is whatever 'arr' is in scope

* After the type checker, it takes the form [(std_name, <expression>)]
  where <expression> is the evidence for the method.  This evidence is
  instantiated with the class, but is still polymorphic in everything
  else.  For example, in the case of 'arr', the evidence has type
         forall b c. (b->c) -> a b c
  where 'a' is the ambient type of the arrow.  This polymorphism is
  important because the desugarer uses the same evidence at multiple
  different types.

This is Less Cool than what we normally do for rebindable syntax, which is to
make fully-instantiated piece of evidence at every use site.  The Cmd way
is Less Cool because
  * The renamer has to predict which methods are needed.
    See the tedious GHC.Rename.Expr.methodNamesCmd.

  * The desugarer has to know the polymorphic type of the instantiated
    method. This is checked by Inst.tcSyntaxName, but is less flexible
    than the rest of rebindable syntax, where the type is less
    pre-ordained.  (And this flexibility is useful; for example we can
    typecheck do-notation with (>>=) :: m1 a -> (a -> m2 b) -> m2 b.)
-}

data CmdTopTc
  = CmdTopTc Type    -- Nested tuple of inputs on the command's stack
             Type    -- return type of the command
             (CmdSyntaxTable GhcTc) -- See Note [CmdSyntaxTable]

type instance XCmdTop  GhcPs = NoExtField
type instance XCmdTop  GhcRn = CmdSyntaxTable GhcRn -- See Note [CmdSyntaxTable]
type instance XCmdTop  GhcTc = CmdTopTc


type instance XXCmdTop (GhcPass _) = DataConCantHappen

instance (OutputableBndrId p) => Outputable (HsCmd (GhcPass p)) where
    ppr :: HsCmd (GhcPass p) -> SDoc
ppr HsCmd (GhcPass p)
cmd = forall (p :: Pass). OutputableBndrId p => HsCmd (GhcPass p) -> SDoc
pprCmd HsCmd (GhcPass p)
cmd

-----------------------
-- pprCmd and pprLCmd call pprDeeper;
-- the underscore versions do not
pprLCmd :: (OutputableBndrId p) => LHsCmd (GhcPass p) -> SDoc
pprLCmd :: forall (p :: Pass).
OutputableBndrId p =>
LHsCmd (GhcPass p) -> SDoc
pprLCmd (L SrcSpanAnnA
_ HsCmd (GhcPass p)
c) = forall (p :: Pass). OutputableBndrId p => HsCmd (GhcPass p) -> SDoc
pprCmd HsCmd (GhcPass p)
c

pprCmd :: (OutputableBndrId p) => HsCmd (GhcPass p) -> SDoc
pprCmd :: forall (p :: Pass). OutputableBndrId p => HsCmd (GhcPass p) -> SDoc
pprCmd HsCmd (GhcPass p)
c | forall id. HsCmd id -> Bool
isQuietHsCmd HsCmd (GhcPass p)
c =            forall (p :: Pass). OutputableBndrId p => HsCmd (GhcPass p) -> SDoc
ppr_cmd HsCmd (GhcPass p)
c
         | Bool
otherwise      = SDoc -> SDoc
pprDeeper (forall (p :: Pass). OutputableBndrId p => HsCmd (GhcPass p) -> SDoc
ppr_cmd HsCmd (GhcPass p)
c)

isQuietHsCmd :: HsCmd id -> Bool
-- Parentheses do display something, but it gives little info and
-- if we go deeper when we go inside them then we get ugly things
-- like (...)
isQuietHsCmd :: forall id. HsCmd id -> Bool
isQuietHsCmd (HsCmdPar {}) = Bool
True
-- applications don't display anything themselves
isQuietHsCmd (HsCmdApp {}) = Bool
True
isQuietHsCmd HsCmd id
_ = Bool
False

-----------------------
ppr_lcmd :: (OutputableBndrId p) => LHsCmd (GhcPass p) -> SDoc
ppr_lcmd :: forall (p :: Pass).
OutputableBndrId p =>
LHsCmd (GhcPass p) -> SDoc
ppr_lcmd LHsCmd (GhcPass p)
c = forall (p :: Pass). OutputableBndrId p => HsCmd (GhcPass p) -> SDoc
ppr_cmd (forall l e. GenLocated l e -> e
unLoc LHsCmd (GhcPass p)
c)

ppr_cmd :: forall p. (OutputableBndrId p
                     ) => HsCmd (GhcPass p) -> SDoc
ppr_cmd :: forall (p :: Pass). OutputableBndrId p => HsCmd (GhcPass p) -> SDoc
ppr_cmd (HsCmdPar XCmdPar (GhcPass p)
_ LHsToken "(" (GhcPass p)
_ XRec (GhcPass p) (HsCmd (GhcPass p))
c LHsToken ")" (GhcPass p)
_) = forall doc. IsLine doc => doc -> doc
parens (forall (p :: Pass).
OutputableBndrId p =>
LHsCmd (GhcPass p) -> SDoc
ppr_lcmd XRec (GhcPass p) (HsCmd (GhcPass p))
c)

ppr_cmd (HsCmdApp XCmdApp (GhcPass p)
_ XRec (GhcPass p) (HsCmd (GhcPass p))
c LHsExpr (GhcPass p)
e)
  = let (GenLocated SrcSpanAnnA (HsCmd (GhcPass p))
fun, [LHsExpr (GhcPass p)]
args) = forall {id} {l}.
(XRec id (HsCmd id) ~ GenLocated l (HsCmd id)) =>
GenLocated l (HsCmd id)
-> [XRec id (HsExpr id)]
-> (GenLocated l (HsCmd id), [XRec id (HsExpr id)])
collect_args XRec (GhcPass p) (HsCmd (GhcPass p))
c [LHsExpr (GhcPass p)
e] in
    SDoc -> Int -> SDoc -> SDoc
hang (forall (p :: Pass).
OutputableBndrId p =>
LHsCmd (GhcPass p) -> SDoc
ppr_lcmd GenLocated SrcSpanAnnA (HsCmd (GhcPass p))
fun) Int
2 (forall doc. IsLine doc => [doc] -> doc
sep (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [LHsExpr (GhcPass p)]
args))
  where
    collect_args :: GenLocated l (HsCmd id)
-> [XRec id (HsExpr id)]
-> (GenLocated l (HsCmd id), [XRec id (HsExpr id)])
collect_args (L l
_ (HsCmdApp XCmdApp id
_ XRec id (HsCmd id)
fun XRec id (HsExpr id)
arg)) [XRec id (HsExpr id)]
args = GenLocated l (HsCmd id)
-> [XRec id (HsExpr id)]
-> (GenLocated l (HsCmd id), [XRec id (HsExpr id)])
collect_args XRec id (HsCmd id)
fun (XRec id (HsExpr id)
argforall a. a -> [a] -> [a]
:[XRec id (HsExpr id)]
args)
    collect_args GenLocated l (HsCmd id)
fun [XRec id (HsExpr id)]
args = (GenLocated l (HsCmd id)
fun, [XRec id (HsExpr id)]
args)

ppr_cmd (HsCmdLam XCmdLam (GhcPass p)
_ MatchGroup (GhcPass p) (XRec (GhcPass p) (HsCmd (GhcPass p)))
matches)
  = forall (idR :: Pass) body.
(OutputableBndrId idR, Outputable body) =>
MatchGroup (GhcPass idR) body -> SDoc
pprMatches MatchGroup (GhcPass p) (XRec (GhcPass p) (HsCmd (GhcPass p)))
matches

ppr_cmd (HsCmdCase XCmdCase (GhcPass p)
_ LHsExpr (GhcPass p)
expr MatchGroup (GhcPass p) (XRec (GhcPass p) (HsCmd (GhcPass p)))
matches)
  = forall doc. IsLine doc => [doc] -> doc
sep [ forall doc. IsLine doc => [doc] -> doc
sep [forall doc. IsLine doc => String -> doc
text String
"case", Int -> SDoc -> SDoc
nest Int
4 (forall a. Outputable a => a -> SDoc
ppr LHsExpr (GhcPass p)
expr), forall doc. IsLine doc => String -> doc
text String
"of"],
          Int -> SDoc -> SDoc
nest Int
2 (forall (idR :: Pass) body.
(OutputableBndrId idR, Outputable body) =>
MatchGroup (GhcPass idR) body -> SDoc
pprMatches MatchGroup (GhcPass p) (XRec (GhcPass p) (HsCmd (GhcPass p)))
matches) ]

ppr_cmd (HsCmdLamCase XCmdLamCase (GhcPass p)
_ LamCaseVariant
lc_variant MatchGroup (GhcPass p) (XRec (GhcPass p) (HsCmd (GhcPass p)))
matches)
  = forall doc. IsLine doc => [doc] -> doc
sep [ LamCaseVariant -> SDoc
lamCaseKeyword LamCaseVariant
lc_variant, Int -> SDoc -> SDoc
nest Int
2 (forall (idR :: Pass) body.
(OutputableBndrId idR, Outputable body) =>
MatchGroup (GhcPass idR) body -> SDoc
pprMatches MatchGroup (GhcPass p) (XRec (GhcPass p) (HsCmd (GhcPass p)))
matches) ]

ppr_cmd (HsCmdIf XCmdIf (GhcPass p)
_ SyntaxExpr (GhcPass p)
_ LHsExpr (GhcPass p)
e XRec (GhcPass p) (HsCmd (GhcPass p))
ct XRec (GhcPass p) (HsCmd (GhcPass p))
ce)
  = forall doc. IsLine doc => [doc] -> doc
sep [forall doc. IsLine doc => [doc] -> doc
hsep [forall doc. IsLine doc => String -> doc
text String
"if", Int -> SDoc -> SDoc
nest Int
2 (forall a. Outputable a => a -> SDoc
ppr LHsExpr (GhcPass p)
e), forall doc. IsLine doc => String -> doc
text String
"then"],
         Int -> SDoc -> SDoc
nest Int
4 (forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsCmd (GhcPass p))
ct),
         forall doc. IsLine doc => String -> doc
text String
"else",
         Int -> SDoc -> SDoc
nest Int
4 (forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsCmd (GhcPass p))
ce)]

-- special case: let ... in let ...
ppr_cmd (HsCmdLet XCmdLet (GhcPass p)
_ LHsToken "let" (GhcPass p)
_ HsLocalBinds (GhcPass p)
binds LHsToken "in" (GhcPass p)
_ cmd :: XRec (GhcPass p) (HsCmd (GhcPass p))
cmd@(L SrcSpanAnnA
_ (HsCmdLet {})))
  = forall doc. IsLine doc => [doc] -> doc
sep [SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"let") Int
2 (forall doc. IsLine doc => [doc] -> doc
hsep [forall (idL :: Pass) (idR :: Pass).
(OutputableBndrId idL, OutputableBndrId idR) =>
HsLocalBindsLR (GhcPass idL) (GhcPass idR) -> SDoc
pprBinds HsLocalBinds (GhcPass p)
binds, forall doc. IsLine doc => String -> doc
text String
"in"]),
         forall (p :: Pass).
OutputableBndrId p =>
LHsCmd (GhcPass p) -> SDoc
ppr_lcmd XRec (GhcPass p) (HsCmd (GhcPass p))
cmd]

ppr_cmd (HsCmdLet XCmdLet (GhcPass p)
_ LHsToken "let" (GhcPass p)
_ HsLocalBinds (GhcPass p)
binds LHsToken "in" (GhcPass p)
_ XRec (GhcPass p) (HsCmd (GhcPass p))
cmd)
  = forall doc. IsLine doc => [doc] -> doc
sep [SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"let") Int
2 (forall (idL :: Pass) (idR :: Pass).
(OutputableBndrId idL, OutputableBndrId idR) =>
HsLocalBindsLR (GhcPass idL) (GhcPass idR) -> SDoc
pprBinds HsLocalBinds (GhcPass p)
binds),
         SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"in")  Int
2 (forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsCmd (GhcPass p))
cmd)]

ppr_cmd (HsCmdDo XCmdDo (GhcPass p)
_ (L SrcSpanAnnL
_ [GenLocated
   SrcSpanAnnA
   (StmtLR
      (GhcPass p)
      (GhcPass p)
      (GenLocated SrcSpanAnnA (HsCmd (GhcPass p))))]
stmts))  = forall (p :: Pass) body.
(OutputableBndrId p, Outputable body,
 Anno (StmtLR (GhcPass p) (GhcPass p) body) ~ SrcSpanAnnA) =>
[LStmt (GhcPass p) body] -> SDoc
pprArrowExpr [GenLocated
   SrcSpanAnnA
   (StmtLR
      (GhcPass p)
      (GhcPass p)
      (GenLocated SrcSpanAnnA (HsCmd (GhcPass p))))]
stmts

ppr_cmd (HsCmdArrApp XCmdArrApp (GhcPass p)
_ LHsExpr (GhcPass p)
arrow LHsExpr (GhcPass p)
arg HsArrAppType
HsFirstOrderApp Bool
True)
  = forall doc. IsLine doc => [doc] -> doc
hsep [forall (p :: Pass).
OutputableBndrId p =>
LHsExpr (GhcPass p) -> SDoc
ppr_lexpr LHsExpr (GhcPass p)
arrow, SDoc
larrowt, forall (p :: Pass).
OutputableBndrId p =>
LHsExpr (GhcPass p) -> SDoc
ppr_lexpr LHsExpr (GhcPass p)
arg]
ppr_cmd (HsCmdArrApp XCmdArrApp (GhcPass p)
_ LHsExpr (GhcPass p)
arrow LHsExpr (GhcPass p)
arg HsArrAppType
HsFirstOrderApp Bool
False)
  = forall doc. IsLine doc => [doc] -> doc
hsep [forall (p :: Pass).
OutputableBndrId p =>
LHsExpr (GhcPass p) -> SDoc
ppr_lexpr LHsExpr (GhcPass p)
arg, SDoc
arrowt, forall (p :: Pass).
OutputableBndrId p =>
LHsExpr (GhcPass p) -> SDoc
ppr_lexpr LHsExpr (GhcPass p)
arrow]
ppr_cmd (HsCmdArrApp XCmdArrApp (GhcPass p)
_ LHsExpr (GhcPass p)
arrow LHsExpr (GhcPass p)
arg HsArrAppType
HsHigherOrderApp Bool
True)
  = forall doc. IsLine doc => [doc] -> doc
hsep [forall (p :: Pass).
OutputableBndrId p =>
LHsExpr (GhcPass p) -> SDoc
ppr_lexpr LHsExpr (GhcPass p)
arrow, SDoc
larrowtt, forall (p :: Pass).
OutputableBndrId p =>
LHsExpr (GhcPass p) -> SDoc
ppr_lexpr LHsExpr (GhcPass p)
arg]
ppr_cmd (HsCmdArrApp XCmdArrApp (GhcPass p)
_ LHsExpr (GhcPass p)
arrow LHsExpr (GhcPass p)
arg HsArrAppType
HsHigherOrderApp Bool
False)
  = forall doc. IsLine doc => [doc] -> doc
hsep [forall (p :: Pass).
OutputableBndrId p =>
LHsExpr (GhcPass p) -> SDoc
ppr_lexpr LHsExpr (GhcPass p)
arg, SDoc
arrowtt, forall (p :: Pass).
OutputableBndrId p =>
LHsExpr (GhcPass p) -> SDoc
ppr_lexpr LHsExpr (GhcPass p)
arrow]

ppr_cmd (HsCmdArrForm XCmdArrForm (GhcPass p)
_ (L SrcSpanAnnA
_ HsExpr (GhcPass p)
op) LexicalFixity
ps_fix Maybe Fixity
rn_fix [LHsCmdTop (GhcPass p)]
args)
  | HsVar XVar (GhcPass p)
_ (L Anno (IdGhcP p)
_ IdGhcP p
v) <- HsExpr (GhcPass p)
op
  = forall a. OutputableBndr a => a -> SDoc
ppr_cmd_infix IdGhcP p
v
  | GhcPass p
GhcTc <- forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p
  , XExpr (ConLikeTc ConLike
c [Id]
_ [Scaled Type]
_) <- HsExpr (GhcPass p)
op
  = forall a. OutputableBndr a => a -> SDoc
ppr_cmd_infix (ConLike -> Name
conLikeName ConLike
c)
  | Bool
otherwise
  = SDoc
fall_through
  where
    fall_through :: SDoc
fall_through = SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"(|" forall doc. IsLine doc => doc -> doc -> doc
<+> forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> SDoc
ppr_expr HsExpr (GhcPass p)
op)
                      Int
4 (forall doc. IsLine doc => [doc] -> doc
sep (forall a b. (a -> b) -> [a] -> [b]
map (forall (p :: Pass).
OutputableBndrId p =>
HsCmdTop (GhcPass p) -> SDoc
pprCmdArgforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall l e. GenLocated l e -> e
unLoc) [LHsCmdTop (GhcPass p)]
args) forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"|)")

    ppr_cmd_infix :: OutputableBndr v => v -> SDoc
    ppr_cmd_infix :: forall a. OutputableBndr a => a -> SDoc
ppr_cmd_infix v
v
      | [LHsCmdTop (GhcPass p)
arg1, LHsCmdTop (GhcPass p)
arg2] <- [LHsCmdTop (GhcPass p)]
args
      , forall a. Maybe a -> Bool
isJust Maybe Fixity
rn_fix Bool -> Bool -> Bool
|| LexicalFixity
ps_fix forall a. Eq a => a -> a -> Bool
== LexicalFixity
Infix
      = SDoc -> Int -> SDoc -> SDoc
hang (forall (p :: Pass).
OutputableBndrId p =>
HsCmdTop (GhcPass p) -> SDoc
pprCmdArg (forall l e. GenLocated l e -> e
unLoc LHsCmdTop (GhcPass p)
arg1))
           Int
4 (forall doc. IsLine doc => [doc] -> doc
sep [ forall a. OutputableBndr a => a -> SDoc
pprInfixOcc v
v, forall (p :: Pass).
OutputableBndrId p =>
HsCmdTop (GhcPass p) -> SDoc
pprCmdArg (forall l e. GenLocated l e -> e
unLoc LHsCmdTop (GhcPass p)
arg2)])
      | Bool
otherwise
      = SDoc
fall_through

ppr_cmd (XCmd XXCmd (GhcPass p)
x) = case forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p of
#if __GLASGOW_HASKELL__ < 811
  GhcPs -> ppr x
  GhcRn -> ppr x
#endif
  GhcPass p
GhcTc -> case XXCmd (GhcPass p)
x of
    HsWrap HsWrapper
w HsCmd GhcTc
cmd -> HsWrapper -> (Bool -> SDoc) -> SDoc
pprHsWrapper HsWrapper
w (\Bool
_ -> forall doc. IsLine doc => doc -> doc
parens (forall (p :: Pass). OutputableBndrId p => HsCmd (GhcPass p) -> SDoc
ppr_cmd HsCmd GhcTc
cmd))

pprCmdArg :: (OutputableBndrId p) => HsCmdTop (GhcPass p) -> SDoc
pprCmdArg :: forall (p :: Pass).
OutputableBndrId p =>
HsCmdTop (GhcPass p) -> SDoc
pprCmdArg (HsCmdTop XCmdTop (GhcPass p)
_ LHsCmd (GhcPass p)
cmd)
  = forall (p :: Pass).
OutputableBndrId p =>
LHsCmd (GhcPass p) -> SDoc
ppr_lcmd LHsCmd (GhcPass p)
cmd

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

{-
************************************************************************
*                                                                      *
\subsection{@Match@, @GRHSs@, and @GRHS@ datatypes}
*                                                                      *
************************************************************************
-}

type instance XMG         GhcPs b = Origin
type instance XMG         GhcRn b = Origin
type instance XMG         GhcTc b = MatchGroupTc

data MatchGroupTc
  = MatchGroupTc
       { MatchGroupTc -> [Scaled Type]
mg_arg_tys :: [Scaled Type]  -- Types of the arguments, t1..tn
       , MatchGroupTc -> Type
mg_res_ty  :: Type    -- Type of the result, tr
       , MatchGroupTc -> Origin
mg_origin  :: Origin  -- Origin (Generated vs FromSource)
       } deriving Typeable MatchGroupTc
MatchGroupTc -> DataType
MatchGroupTc -> Constr
(forall b. Data b => b -> b) -> MatchGroupTc -> MatchGroupTc
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) -> MatchGroupTc -> u
forall u. (forall d. Data d => d -> u) -> MatchGroupTc -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> MatchGroupTc -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> MatchGroupTc -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> MatchGroupTc -> m MatchGroupTc
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> MatchGroupTc -> m MatchGroupTc
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c MatchGroupTc
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> MatchGroupTc -> c MatchGroupTc
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c MatchGroupTc)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c MatchGroupTc)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> MatchGroupTc -> m MatchGroupTc
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> MatchGroupTc -> m MatchGroupTc
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> MatchGroupTc -> m MatchGroupTc
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> MatchGroupTc -> m MatchGroupTc
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> MatchGroupTc -> m MatchGroupTc
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> MatchGroupTc -> m MatchGroupTc
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> MatchGroupTc -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> MatchGroupTc -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> MatchGroupTc -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> MatchGroupTc -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> MatchGroupTc -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> MatchGroupTc -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> MatchGroupTc -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> MatchGroupTc -> r
gmapT :: (forall b. Data b => b -> b) -> MatchGroupTc -> MatchGroupTc
$cgmapT :: (forall b. Data b => b -> b) -> MatchGroupTc -> MatchGroupTc
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c MatchGroupTc)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c MatchGroupTc)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c MatchGroupTc)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c MatchGroupTc)
dataTypeOf :: MatchGroupTc -> DataType
$cdataTypeOf :: MatchGroupTc -> DataType
toConstr :: MatchGroupTc -> Constr
$ctoConstr :: MatchGroupTc -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c MatchGroupTc
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c MatchGroupTc
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> MatchGroupTc -> c MatchGroupTc
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> MatchGroupTc -> c MatchGroupTc
Data

type instance XXMatchGroup (GhcPass _) b = DataConCantHappen

type instance XCMatch (GhcPass _) b = EpAnn [AddEpAnn]
type instance XXMatch (GhcPass _) b = DataConCantHappen

instance (OutputableBndrId pr, Outputable body)
            => Outputable (Match (GhcPass pr) body) where
  ppr :: Match (GhcPass pr) body -> SDoc
ppr = forall (pr :: Pass) body.
(OutputableBndrId pr, Outputable body) =>
Match (GhcPass pr) body -> SDoc
pprMatch

isEmptyMatchGroup :: MatchGroup (GhcPass p) body -> Bool
isEmptyMatchGroup :: forall (p :: Pass) body. MatchGroup (GhcPass p) body -> Bool
isEmptyMatchGroup (MG { mg_alts :: forall p body. MatchGroup p body -> XRec p [LMatch p body]
mg_alts = XRec (GhcPass p) [LMatch (GhcPass p) body]
ms }) = forall (t :: * -> *) a. Foldable t => t a -> Bool
null forall a b. (a -> b) -> a -> b
$ forall l e. GenLocated l e -> e
unLoc XRec (GhcPass p) [LMatch (GhcPass p) body]
ms

-- | Is there only one RHS in this list of matches?
isSingletonMatchGroup :: [LMatch (GhcPass p) body] -> Bool
isSingletonMatchGroup :: forall (p :: Pass) body. [LMatch (GhcPass p) body] -> Bool
isSingletonMatchGroup [LMatch (GhcPass p) body]
matches
  | [L Anno (Match (GhcPass p) body)
_ Match (GhcPass p) body
match] <- [LMatch (GhcPass p) body]
matches
  , Match { m_grhss :: forall p body. Match p body -> GRHSs p body
m_grhss = GRHSs { grhssGRHSs :: forall p body. GRHSs p body -> [LGRHS p body]
grhssGRHSs = [LGRHS (GhcPass p) body
_] } } <- Match (GhcPass p) body
match
  = Bool
True
  | Bool
otherwise
  = Bool
False

matchGroupArity :: MatchGroup (GhcPass id) body -> Arity
-- Precondition: MatchGroup is non-empty
-- This is called before type checking, when mg_arg_tys is not set
matchGroupArity :: forall (id :: Pass) body. MatchGroup (GhcPass id) body -> Int
matchGroupArity (MG { mg_alts :: forall p body. MatchGroup p body -> XRec p [LMatch p body]
mg_alts = XRec (GhcPass id) [LMatch (GhcPass id) body]
alts })
  | L Anno
  [GenLocated
     (Anno (Match (GhcPass id) body)) (Match (GhcPass id) body)]
_ (GenLocated
  (Anno (Match (GhcPass id) body)) (Match (GhcPass id) body)
alt1:[GenLocated
   (Anno (Match (GhcPass id) body)) (Match (GhcPass id) body)]
_) <- XRec (GhcPass id) [LMatch (GhcPass id) body]
alts = forall (t :: * -> *) a. Foldable t => t a -> Int
length (forall (id :: Pass) body.
LMatch (GhcPass id) body -> [LPat (GhcPass id)]
hsLMatchPats GenLocated
  (Anno (Match (GhcPass id) body)) (Match (GhcPass id) body)
alt1)
  | Bool
otherwise        = forall a. HasCallStack => String -> a
panic String
"matchGroupArity"

hsLMatchPats :: LMatch (GhcPass id) body -> [LPat (GhcPass id)]
hsLMatchPats :: forall (id :: Pass) body.
LMatch (GhcPass id) body -> [LPat (GhcPass id)]
hsLMatchPats (L Anno (Match (GhcPass id) body)
_ (Match { m_pats :: forall p body. Match p body -> [LPat p]
m_pats = [LPat (GhcPass id)]
pats })) = [LPat (GhcPass id)]
pats

-- We keep the type checker happy by providing EpAnnComments.  They
-- can only be used if they follow a `where` keyword with no binds,
-- but in that case the comment is attached to the following parsed
-- item. So this can never be used in practice.
type instance XCGRHSs (GhcPass _) _ = EpAnnComments

type instance XXGRHSs (GhcPass _) _ = DataConCantHappen

data GrhsAnn
  = GrhsAnn {
      GrhsAnn -> Maybe EpaLocation
ga_vbar :: Maybe EpaLocation, -- TODO:AZ do we need this?
      GrhsAnn -> AddEpAnn
ga_sep  :: AddEpAnn -- ^ Match separator location
      } deriving (Typeable GrhsAnn
GrhsAnn -> DataType
GrhsAnn -> Constr
(forall b. Data b => b -> b) -> GrhsAnn -> GrhsAnn
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) -> GrhsAnn -> u
forall u. (forall d. Data d => d -> u) -> GrhsAnn -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> GrhsAnn -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> GrhsAnn -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> GrhsAnn -> m GrhsAnn
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> GrhsAnn -> m GrhsAnn
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c GrhsAnn
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> GrhsAnn -> c GrhsAnn
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c GrhsAnn)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c GrhsAnn)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> GrhsAnn -> m GrhsAnn
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> GrhsAnn -> m GrhsAnn
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> GrhsAnn -> m GrhsAnn
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> GrhsAnn -> m GrhsAnn
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> GrhsAnn -> m GrhsAnn
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> GrhsAnn -> m GrhsAnn
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> GrhsAnn -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> GrhsAnn -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> GrhsAnn -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> GrhsAnn -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> GrhsAnn -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> GrhsAnn -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> GrhsAnn -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> GrhsAnn -> r
gmapT :: (forall b. Data b => b -> b) -> GrhsAnn -> GrhsAnn
$cgmapT :: (forall b. Data b => b -> b) -> GrhsAnn -> GrhsAnn
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c GrhsAnn)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c GrhsAnn)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c GrhsAnn)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c GrhsAnn)
dataTypeOf :: GrhsAnn -> DataType
$cdataTypeOf :: GrhsAnn -> DataType
toConstr :: GrhsAnn -> Constr
$ctoConstr :: GrhsAnn -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c GrhsAnn
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c GrhsAnn
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> GrhsAnn -> c GrhsAnn
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> GrhsAnn -> c GrhsAnn
Data)

type instance XCGRHS (GhcPass _) _ = EpAnn GrhsAnn
                                   -- Location of matchSeparator
                                   -- TODO:AZ does this belong on the GRHS, or GRHSs?

type instance XXGRHS (GhcPass _) b = DataConCantHappen

pprMatches :: (OutputableBndrId idR, Outputable body)
           => MatchGroup (GhcPass idR) body -> SDoc
pprMatches :: forall (idR :: Pass) body.
(OutputableBndrId idR, Outputable body) =>
MatchGroup (GhcPass idR) body -> SDoc
pprMatches MG { mg_alts :: forall p body. MatchGroup p body -> XRec p [LMatch p body]
mg_alts = XRec (GhcPass idR) [LMatch (GhcPass idR) body]
matches }
    = forall doc. IsDoc doc => [doc] -> doc
vcat (forall a b. (a -> b) -> [a] -> [b]
map forall (pr :: Pass) body.
(OutputableBndrId pr, Outputable body) =>
Match (GhcPass pr) body -> SDoc
pprMatch (forall a b. (a -> b) -> [a] -> [b]
map forall l e. GenLocated l e -> e
unLoc (forall l e. GenLocated l e -> e
unLoc XRec (GhcPass idR) [LMatch (GhcPass idR) body]
matches)))
      -- Don't print the type; it's only a place-holder before typechecking

-- Exported to GHC.Hs.Binds, which can't see the defn of HsMatchContext
pprFunBind :: (OutputableBndrId idR)
           => MatchGroup (GhcPass idR) (LHsExpr (GhcPass idR)) -> SDoc
pprFunBind :: forall (idR :: Pass).
OutputableBndrId idR =>
MatchGroup (GhcPass idR) (LHsExpr (GhcPass idR)) -> SDoc
pprFunBind MatchGroup (GhcPass idR) (LHsExpr (GhcPass idR))
matches = forall (idR :: Pass) body.
(OutputableBndrId idR, Outputable body) =>
MatchGroup (GhcPass idR) body -> SDoc
pprMatches MatchGroup (GhcPass idR) (LHsExpr (GhcPass idR))
matches

-- Exported to GHC.Hs.Binds, which can't see the defn of HsMatchContext
pprPatBind :: forall bndr p . (OutputableBndrId bndr,
                               OutputableBndrId p)
           => LPat (GhcPass bndr) -> GRHSs (GhcPass p) (LHsExpr (GhcPass p)) -> SDoc
pprPatBind :: forall (bndr :: Pass) (p :: Pass).
(OutputableBndrId bndr, OutputableBndrId p) =>
LPat (GhcPass bndr)
-> GRHSs (GhcPass p) (LHsExpr (GhcPass p)) -> SDoc
pprPatBind LPat (GhcPass bndr)
pat GRHSs (GhcPass p) (LHsExpr (GhcPass p))
grhss
 = forall doc. IsLine doc => [doc] -> doc
sep [forall a. Outputable a => a -> SDoc
ppr LPat (GhcPass bndr)
pat,
       Int -> SDoc -> SDoc
nest Int
2 (forall (idR :: Pass) body passL.
(OutputableBndrId idR, Outputable body) =>
HsMatchContext passL -> GRHSs (GhcPass idR) body -> SDoc
pprGRHSs (forall p. HsMatchContext p
PatBindRhs :: HsMatchContext (GhcPass p)) GRHSs (GhcPass p) (LHsExpr (GhcPass p))
grhss)]

pprMatch :: (OutputableBndrId idR, Outputable body)
         => Match (GhcPass idR) body -> SDoc
pprMatch :: forall (pr :: Pass) body.
(OutputableBndrId pr, Outputable body) =>
Match (GhcPass pr) body -> SDoc
pprMatch (Match { m_pats :: forall p body. Match p body -> [LPat p]
m_pats = [LPat (GhcPass idR)]
pats, m_ctxt :: forall p body. Match p body -> HsMatchContext p
m_ctxt = HsMatchContext (GhcPass idR)
ctxt, m_grhss :: forall p body. Match p body -> GRHSs p body
m_grhss = GRHSs (GhcPass idR) body
grhss })
  = forall doc. IsLine doc => [doc] -> doc
sep [ forall doc. IsLine doc => [doc] -> doc
sep (SDoc
herald forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map (Int -> SDoc -> SDoc
nest Int
2 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: Pass).
OutputableBndrId p =>
PprPrec -> LPat (GhcPass p) -> SDoc
pprParendLPat PprPrec
appPrec) [GenLocated SrcSpanAnnA (Pat (GhcPass idR))]
other_pats)
        , Int -> SDoc -> SDoc
nest Int
2 (forall (idR :: Pass) body passL.
(OutputableBndrId idR, Outputable body) =>
HsMatchContext passL -> GRHSs (GhcPass idR) body -> SDoc
pprGRHSs HsMatchContext (GhcPass idR)
ctxt GRHSs (GhcPass idR) body
grhss) ]
  where
    (SDoc
herald, [GenLocated SrcSpanAnnA (Pat (GhcPass idR))]
other_pats)
        = case HsMatchContext (GhcPass idR)
ctxt of
            FunRhs {mc_fun :: forall p. HsMatchContext p -> LIdP (NoGhcTc p)
mc_fun=L Anno (IdGhcP (NoGhcTcPass idR))
_ IdGhcP (NoGhcTcPass idR)
fun, mc_fixity :: forall p. HsMatchContext p -> LexicalFixity
mc_fixity=LexicalFixity
fixity, mc_strictness :: forall p. HsMatchContext p -> SrcStrictness
mc_strictness=SrcStrictness
strictness}
                | SrcStrictness
SrcStrict <- SrcStrictness
strictness
                -> forall a. HasCallStack => Bool -> a -> a
assert (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LPat (GhcPass idR)]
pats)     -- A strict variable binding
                   (forall doc. IsLine doc => Char -> doc
char Char
'!'forall doc. IsLine doc => doc -> doc -> doc
<>forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc IdGhcP (NoGhcTcPass idR)
fun, [LPat (GhcPass idR)]
pats)

                | LexicalFixity
Prefix <- LexicalFixity
fixity
                -> (forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc IdGhcP (NoGhcTcPass idR)
fun, [LPat (GhcPass idR)]
pats) -- f x y z = e
                                            -- Not pprBndr; the AbsBinds will
                                            -- have printed the signature
                | Bool
otherwise
                -> case [LPat (GhcPass idR)]
pats of
                     (LPat (GhcPass idR)
p1:LPat (GhcPass idR)
p2:[LPat (GhcPass idR)]
rest)
                        | forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LPat (GhcPass idR)]
rest -> (SDoc
pp_infix, [])           -- x &&& y = e
                        | Bool
otherwise -> (forall doc. IsLine doc => doc -> doc
parens SDoc
pp_infix, [LPat (GhcPass idR)]
rest)  -- (x &&& y) z = e
                        where
                          pp_infix :: SDoc
pp_infix = forall (p :: Pass).
OutputableBndrId p =>
PprPrec -> LPat (GhcPass p) -> SDoc
pprParendLPat PprPrec
opPrec LPat (GhcPass idR)
p1
                                     forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. OutputableBndr a => a -> SDoc
pprInfixOcc IdGhcP (NoGhcTcPass idR)
fun
                                     forall doc. IsLine doc => doc -> doc -> doc
<+> forall (p :: Pass).
OutputableBndrId p =>
PprPrec -> LPat (GhcPass p) -> SDoc
pprParendLPat PprPrec
opPrec LPat (GhcPass idR)
p2
                     [LPat (GhcPass idR)]
_ -> forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"pprMatch" (forall a. Outputable a => a -> SDoc
ppr HsMatchContext (GhcPass idR)
ctxt forall doc. IsDoc doc => doc -> doc -> doc
$$ forall a. Outputable a => a -> SDoc
ppr [LPat (GhcPass idR)]
pats)

            HsMatchContext (GhcPass idR)
LambdaExpr -> (forall doc. IsLine doc => Char -> doc
char Char
'\\', [LPat (GhcPass idR)]
pats)

            -- We don't simply return (empty, pats) to avoid introducing an
            -- additional `nest 2` via the empty herald
            LamCaseAlt LamCaseVariant
LamCases ->
              forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall doc. IsOutput doc => doc
empty, []) (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first forall a b. (a -> b) -> a -> b
$ forall (p :: Pass).
OutputableBndrId p =>
PprPrec -> LPat (GhcPass p) -> SDoc
pprParendLPat PprPrec
appPrec) (forall a. [a] -> Maybe (a, [a])
uncons [LPat (GhcPass idR)]
pats)

            ArrowMatchCtxt (ArrowLamCaseAlt LamCaseVariant
LamCases) ->
              forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall doc. IsOutput doc => doc
empty, []) (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first forall a b. (a -> b) -> a -> b
$ forall (p :: Pass).
OutputableBndrId p =>
PprPrec -> LPat (GhcPass p) -> SDoc
pprParendLPat PprPrec
appPrec) (forall a. [a] -> Maybe (a, [a])
uncons [LPat (GhcPass idR)]
pats)

            ArrowMatchCtxt HsArrowMatchContext
KappaExpr -> (forall doc. IsLine doc => Char -> doc
char Char
'\\', [LPat (GhcPass idR)]
pats)

            ArrowMatchCtxt HsArrowMatchContext
ProcExpr -> (forall doc. IsLine doc => String -> doc
text String
"proc", [LPat (GhcPass idR)]
pats)

            HsMatchContext (GhcPass idR)
_ -> case [LPat (GhcPass idR)]
pats of
                   []    -> (forall doc. IsOutput doc => doc
empty, [])
                   [LPat (GhcPass idR)
pat] -> (forall a. Outputable a => a -> SDoc
ppr LPat (GhcPass idR)
pat, [])  -- No parens around the single pat in a case
                   [LPat (GhcPass idR)]
_     -> forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"pprMatch" (forall a. Outputable a => a -> SDoc
ppr HsMatchContext (GhcPass idR)
ctxt forall doc. IsDoc doc => doc -> doc -> doc
$$ forall a. Outputable a => a -> SDoc
ppr [LPat (GhcPass idR)]
pats)

pprGRHSs :: (OutputableBndrId idR, Outputable body)
         => HsMatchContext passL -> GRHSs (GhcPass idR) body -> SDoc
pprGRHSs :: forall (idR :: Pass) body passL.
(OutputableBndrId idR, Outputable body) =>
HsMatchContext passL -> GRHSs (GhcPass idR) body -> SDoc
pprGRHSs HsMatchContext passL
ctxt (GRHSs XCGRHSs (GhcPass idR) body
_ [LGRHS (GhcPass idR) body]
grhss HsLocalBinds (GhcPass idR)
binds)
  = forall doc. IsDoc doc => [doc] -> doc
vcat (forall a b. (a -> b) -> [a] -> [b]
map (forall (idR :: Pass) body passL.
(OutputableBndrId idR, Outputable body) =>
HsMatchContext passL -> GRHS (GhcPass idR) body -> SDoc
pprGRHS HsMatchContext passL
ctxt forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l e. GenLocated l e -> e
unLoc) [LGRHS (GhcPass idR) body]
grhss)
  -- Print the "where" even if the contents of the binds is empty. Only
  -- EmptyLocalBinds means no "where" keyword
 forall doc. IsDoc doc => doc -> doc -> doc
$$ forall doc. IsOutput doc => Bool -> doc -> doc
ppUnless (forall a b. HsLocalBindsLR a b -> Bool
eqEmptyLocalBinds HsLocalBinds (GhcPass idR)
binds)
      (forall doc. IsLine doc => String -> doc
text String
"where" forall doc. IsDoc doc => doc -> doc -> doc
$$ Int -> SDoc -> SDoc
nest Int
4 (forall (idL :: Pass) (idR :: Pass).
(OutputableBndrId idL, OutputableBndrId idR) =>
HsLocalBindsLR (GhcPass idL) (GhcPass idR) -> SDoc
pprBinds HsLocalBinds (GhcPass idR)
binds))

pprGRHS :: (OutputableBndrId idR, Outputable body)
        => HsMatchContext passL -> GRHS (GhcPass idR) body -> SDoc
pprGRHS :: forall (idR :: Pass) body passL.
(OutputableBndrId idR, Outputable body) =>
HsMatchContext passL -> GRHS (GhcPass idR) body -> SDoc
pprGRHS HsMatchContext passL
ctxt (GRHS XCGRHS (GhcPass idR) body
_ [] body
body)
 =  forall body passL.
Outputable body =>
HsMatchContext passL -> body -> SDoc
pp_rhs HsMatchContext passL
ctxt body
body

pprGRHS HsMatchContext passL
ctxt (GRHS XCGRHS (GhcPass idR) body
_ [GuardLStmt (GhcPass idR)]
guards body
body)
 = forall doc. IsLine doc => [doc] -> doc
sep [forall doc. IsLine doc => doc
vbar forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => [a] -> SDoc
interpp'SP [GuardLStmt (GhcPass idR)]
guards, forall body passL.
Outputable body =>
HsMatchContext passL -> body -> SDoc
pp_rhs HsMatchContext passL
ctxt body
body]

pp_rhs :: Outputable body => HsMatchContext passL -> body -> SDoc
pp_rhs :: forall body passL.
Outputable body =>
HsMatchContext passL -> body -> SDoc
pp_rhs HsMatchContext passL
ctxt body
rhs = forall p. HsMatchContext p -> SDoc
matchSeparator HsMatchContext passL
ctxt forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
pprDeeper (forall a. Outputable a => a -> SDoc
ppr body
rhs)

instance Outputable GrhsAnn where
  ppr :: GrhsAnn -> SDoc
ppr (GrhsAnn Maybe EpaLocation
v AddEpAnn
s) = forall doc. IsLine doc => String -> doc
text String
"GrhsAnn" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr Maybe EpaLocation
v forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr AddEpAnn
s

{-
************************************************************************
*                                                                      *
\subsection{Do stmts and list comprehensions}
*                                                                      *
************************************************************************
-}

-- Extra fields available post typechecking for RecStmt.
data RecStmtTc =
  RecStmtTc
     { RecStmtTc -> Type
recS_bind_ty :: Type       -- S in (>>=) :: Q -> (R -> S) -> T
     , RecStmtTc -> [HsExpr GhcTc]
recS_later_rets :: [PostTcExpr] -- (only used in the arrow version)
     , RecStmtTc -> [HsExpr GhcTc]
recS_rec_rets :: [PostTcExpr] -- These expressions correspond 1-to-1
                                  -- with recS_later_ids and recS_rec_ids,
                                  -- and are the expressions that should be
                                  -- returned by the recursion.
                                  -- They may not quite be the Ids themselves,
                                  -- because the Id may be *polymorphic*, but
                                  -- the returned thing has to be *monomorphic*,
                                  -- so they may be type applications

      , RecStmtTc -> Type
recS_ret_ty :: Type        -- The type of
                                   -- do { stmts; return (a,b,c) }
                                   -- With rebindable syntax the type might not
                                   -- be quite as simple as (m (tya, tyb, tyc)).
      }


type instance XLastStmt        (GhcPass _) (GhcPass _) b = NoExtField

type instance XBindStmt        (GhcPass _) GhcPs b = EpAnn [AddEpAnn]
type instance XBindStmt        (GhcPass _) GhcRn b = XBindStmtRn
type instance XBindStmt        (GhcPass _) GhcTc b = XBindStmtTc

data XBindStmtRn = XBindStmtRn
  { XBindStmtRn -> SyntaxExpr GhcRn
xbsrn_bindOp :: SyntaxExpr GhcRn
  , XBindStmtRn -> FailOperator GhcRn
xbsrn_failOp :: FailOperator GhcRn
  }

data XBindStmtTc = XBindStmtTc
  { XBindStmtTc -> SyntaxExpr GhcTc
xbstc_bindOp :: SyntaxExpr GhcTc
  , XBindStmtTc -> Type
xbstc_boundResultType :: Type -- If (>>=) :: Q -> (R -> S) -> T, this is S
  , XBindStmtTc -> Type
xbstc_boundResultMult :: Mult -- If (>>=) :: Q -> (R -> S) -> T, this is S
  , XBindStmtTc -> FailOperator GhcTc
xbstc_failOp :: FailOperator GhcTc
  }

type instance XApplicativeStmt (GhcPass _) GhcPs b = NoExtField
type instance XApplicativeStmt (GhcPass _) GhcRn b = NoExtField
type instance XApplicativeStmt (GhcPass _) GhcTc b = Type

type instance XBodyStmt        (GhcPass _) GhcPs b = NoExtField
type instance XBodyStmt        (GhcPass _) GhcRn b = NoExtField
type instance XBodyStmt        (GhcPass _) GhcTc b = Type

type instance XLetStmt         (GhcPass _) (GhcPass _) b = EpAnn [AddEpAnn]

type instance XParStmt         (GhcPass _) GhcPs b = NoExtField
type instance XParStmt         (GhcPass _) GhcRn b = NoExtField
type instance XParStmt         (GhcPass _) GhcTc b = Type

type instance XTransStmt       (GhcPass _) GhcPs b = EpAnn [AddEpAnn]
type instance XTransStmt       (GhcPass _) GhcRn b = NoExtField
type instance XTransStmt       (GhcPass _) GhcTc b = Type

type instance XRecStmt         (GhcPass _) GhcPs b = EpAnn AnnList
type instance XRecStmt         (GhcPass _) GhcRn b = NoExtField
type instance XRecStmt         (GhcPass _) GhcTc b = RecStmtTc

type instance XXStmtLR         (GhcPass _) (GhcPass _) b = DataConCantHappen

type instance XParStmtBlock  (GhcPass pL) (GhcPass pR) = NoExtField
type instance XXParStmtBlock (GhcPass pL) (GhcPass pR) = DataConCantHappen

type instance XApplicativeArgOne GhcPs = NoExtField
type instance XApplicativeArgOne GhcRn = FailOperator GhcRn
type instance XApplicativeArgOne GhcTc = FailOperator GhcTc

type instance XApplicativeArgMany (GhcPass _) = NoExtField
type instance XXApplicativeArg    (GhcPass _) = DataConCantHappen

instance (Outputable (StmtLR (GhcPass idL) (GhcPass idL) (LHsExpr (GhcPass idL))),
          Outputable (XXParStmtBlock (GhcPass idL) (GhcPass idR)))
        => Outputable (ParStmtBlock (GhcPass idL) (GhcPass idR)) where
  ppr :: ParStmtBlock (GhcPass idL) (GhcPass idR) -> SDoc
ppr (ParStmtBlock XParStmtBlock (GhcPass idL) (GhcPass idR)
_ [ExprLStmt (GhcPass idL)]
stmts [IdP (GhcPass idR)]
_ SyntaxExpr (GhcPass idR)
_) = forall a. Outputable a => [a] -> SDoc
interpp'SP [ExprLStmt (GhcPass idL)]
stmts

instance (OutputableBndrId pl, OutputableBndrId pr,
                 Anno (StmtLR (GhcPass pl) (GhcPass pr) body) ~ SrcSpanAnnA,
          Outputable body)
         => Outputable (StmtLR (GhcPass pl) (GhcPass pr) body) where
    ppr :: StmtLR (GhcPass pl) (GhcPass pr) body -> SDoc
ppr StmtLR (GhcPass pl) (GhcPass pr) body
stmt = forall (pl :: Pass) (pr :: Pass) body.
(OutputableBndrId pl, OutputableBndrId pr,
 Anno (StmtLR (GhcPass pl) (GhcPass pr) body) ~ SrcSpanAnnA,
 Outputable body) =>
StmtLR (GhcPass pl) (GhcPass pr) body -> SDoc
pprStmt StmtLR (GhcPass pl) (GhcPass pr) body
stmt

pprStmt :: forall idL idR body . (OutputableBndrId idL,
                                  OutputableBndrId idR,
                 Anno (StmtLR (GhcPass idL) (GhcPass idR) body) ~ SrcSpanAnnA,
                                  Outputable body)
        => (StmtLR (GhcPass idL) (GhcPass idR) body) -> SDoc
pprStmt :: forall (pl :: Pass) (pr :: Pass) body.
(OutputableBndrId pl, OutputableBndrId pr,
 Anno (StmtLR (GhcPass pl) (GhcPass pr) body) ~ SrcSpanAnnA,
 Outputable body) =>
StmtLR (GhcPass pl) (GhcPass pr) body -> SDoc
pprStmt (LastStmt XLastStmt (GhcPass idL) (GhcPass idR) body
_ body
expr Maybe Bool
m_dollar_stripped SyntaxExpr (GhcPass idR)
_)
  = forall doc. IsOutput doc => doc -> doc
whenPprDebug (forall doc. IsLine doc => String -> doc
text String
"[last]") forall doc. IsLine doc => doc -> doc -> doc
<+>
      (case Maybe Bool
m_dollar_stripped of
        Just Bool
True -> forall doc. IsLine doc => String -> doc
text String
"return $"
        Just Bool
False -> forall doc. IsLine doc => String -> doc
text String
"return"
        Maybe Bool
Nothing -> forall doc. IsOutput doc => doc
empty) forall doc. IsLine doc => doc -> doc -> doc
<+>
      forall a. Outputable a => a -> SDoc
ppr body
expr
pprStmt (BindStmt XBindStmt (GhcPass idL) (GhcPass idR) body
_ LPat (GhcPass idL)
pat body
expr)  = forall pat expr.
(Outputable pat, Outputable expr) =>
pat -> expr -> SDoc
pprBindStmt LPat (GhcPass idL)
pat body
expr
pprStmt (LetStmt XLetStmt (GhcPass idL) (GhcPass idR) body
_ HsLocalBindsLR (GhcPass idL) (GhcPass idR)
binds)      = forall doc. IsLine doc => [doc] -> doc
hsep [forall doc. IsLine doc => String -> doc
text String
"let", forall (idL :: Pass) (idR :: Pass).
(OutputableBndrId idL, OutputableBndrId idR) =>
HsLocalBindsLR (GhcPass idL) (GhcPass idR) -> SDoc
pprBinds HsLocalBindsLR (GhcPass idL) (GhcPass idR)
binds]
pprStmt (BodyStmt XBodyStmt (GhcPass idL) (GhcPass idR) body
_ body
expr SyntaxExpr (GhcPass idR)
_ SyntaxExpr (GhcPass idR)
_)  = forall a. Outputable a => a -> SDoc
ppr body
expr
pprStmt (ParStmt XParStmt (GhcPass idL) (GhcPass idR) body
_ [ParStmtBlock (GhcPass idL) (GhcPass idR)]
stmtss HsExpr (GhcPass idR)
_ SyntaxExpr (GhcPass idR)
_) = forall doc. IsLine doc => [doc] -> doc
sep (forall doc. IsLine doc => doc -> [doc] -> [doc]
punctuate (forall doc. IsLine doc => String -> doc
text String
" | ") (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [ParStmtBlock (GhcPass idL) (GhcPass idR)]
stmtss))

pprStmt (TransStmt { trS_stmts :: forall idL idR body. StmtLR idL idR body -> [ExprLStmt idL]
trS_stmts = [ExprLStmt (GhcPass idL)]
stmts, trS_by :: forall idL idR body. StmtLR idL idR body -> Maybe (LHsExpr idR)
trS_by = Maybe (LHsExpr (GhcPass idR))
by
                   , trS_using :: forall idL idR body. StmtLR idL idR body -> LHsExpr idR
trS_using = LHsExpr (GhcPass idR)
using, trS_form :: forall idL idR body. StmtLR idL idR body -> TransForm
trS_form = TransForm
form })
  = forall doc. IsLine doc => [doc] -> doc
sep forall a b. (a -> b) -> a -> b
$ forall doc. IsLine doc => doc -> [doc] -> [doc]
punctuate forall doc. IsLine doc => doc
comma (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [ExprLStmt (GhcPass idL)]
stmts forall a. [a] -> [a] -> [a]
++ [forall body.
Outputable body =>
Maybe body -> body -> TransForm -> SDoc
pprTransStmt Maybe (LHsExpr (GhcPass idR))
by LHsExpr (GhcPass idR)
using TransForm
form])

pprStmt (RecStmt { recS_stmts :: forall idL idR body.
StmtLR idL idR body -> XRec idR [LStmtLR idL idR body]
recS_stmts = XRec (GhcPass idR) [LStmtLR (GhcPass idL) (GhcPass idR) body]
segment, recS_rec_ids :: forall idL idR body. StmtLR idL idR body -> [IdP idR]
recS_rec_ids = [IdP (GhcPass idR)]
rec_ids
                 , recS_later_ids :: forall idL idR body. StmtLR idL idR body -> [IdP idR]
recS_later_ids = [IdP (GhcPass idR)]
later_ids })
  = forall doc. IsLine doc => String -> doc
text String
"rec" forall doc. IsLine doc => doc -> doc -> doc
<+>
    forall doc. IsDoc doc => [doc] -> doc
vcat [ forall (idL :: Pass) (idR :: Pass) body.
(OutputableBndrId idL, OutputableBndrId idR,
 Anno (StmtLR (GhcPass idL) (GhcPass idR) body) ~ SrcSpanAnnA,
 Outputable body) =>
[LStmtLR (GhcPass idL) (GhcPass idR) body] -> SDoc
ppr_do_stmts (forall l e. GenLocated l e -> e
unLoc XRec (GhcPass idR) [LStmtLR (GhcPass idL) (GhcPass idR) body]
segment)
         , forall doc. IsOutput doc => doc -> doc
whenPprDebug (forall doc. IsDoc doc => [doc] -> doc
vcat [ forall doc. IsLine doc => String -> doc
text String
"rec_ids=" forall doc. IsLine doc => doc -> doc -> doc
<> forall a. Outputable a => a -> SDoc
ppr [IdP (GhcPass idR)]
rec_ids
                            , forall doc. IsLine doc => String -> doc
text String
"later_ids=" forall doc. IsLine doc => doc -> doc -> doc
<> forall a. Outputable a => a -> SDoc
ppr [IdP (GhcPass idR)]
later_ids])]

pprStmt (ApplicativeStmt XApplicativeStmt (GhcPass idL) (GhcPass idR) body
_ [(SyntaxExpr (GhcPass idR), ApplicativeArg (GhcPass idL))]
args Maybe (SyntaxExpr (GhcPass idR))
mb_join)
  = (PprStyle -> SDoc) -> SDoc
getPprStyle forall a b. (a -> b) -> a -> b
$ \PprStyle
style ->
      if PprStyle -> Bool
userStyle PprStyle
style
         then SDoc
pp_for_user
         else SDoc
pp_debug
  where
  -- make all the Applicative stuff invisible in error messages by
  -- flattening the whole ApplicativeStmt nest back to a sequence
  -- of statements.
   pp_for_user :: SDoc
pp_for_user = forall doc. IsDoc doc => [doc] -> doc
vcat forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap forall a. (a, ApplicativeArg (GhcPass idL)) -> [SDoc]
flattenArg [(SyntaxExpr (GhcPass idR), ApplicativeArg (GhcPass idL))]
args

   -- ppr directly rather than transforming here, because we need to
   -- inject a "return" which is hard when we're polymorphic in the id
   -- type.
   flattenStmt :: ExprLStmt (GhcPass idL) -> [SDoc]
   flattenStmt :: ExprLStmt (GhcPass idL) -> [SDoc]
flattenStmt (L SrcSpanAnnA
_ (ApplicativeStmt XApplicativeStmt
  (GhcPass idL)
  (GhcPass idL)
  (GenLocated SrcSpanAnnA (HsExpr (GhcPass idL)))
_ [(SyntaxExpr (GhcPass idL), ApplicativeArg (GhcPass idL))]
args Maybe (SyntaxExpr (GhcPass idL))
_)) = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap forall a. (a, ApplicativeArg (GhcPass idL)) -> [SDoc]
flattenArg [(SyntaxExpr (GhcPass idL), ApplicativeArg (GhcPass idL))]
args
   flattenStmt ExprLStmt (GhcPass idL)
stmt = [forall a. Outputable a => a -> SDoc
ppr ExprLStmt (GhcPass idL)
stmt]

   flattenArg :: forall a . (a, ApplicativeArg (GhcPass idL)) -> [SDoc]
   flattenArg :: forall a. (a, ApplicativeArg (GhcPass idL)) -> [SDoc]
flattenArg (a
_, ApplicativeArgOne XApplicativeArgOne (GhcPass idL)
_ LPat (GhcPass idL)
pat LHsExpr (GhcPass idL)
expr Bool
isBody)
     | Bool
isBody =  [forall a. Outputable a => a -> SDoc
ppr LHsExpr (GhcPass idL)
expr] -- See Note [Applicative BodyStmt]
     | Bool
otherwise = [forall pat expr.
(Outputable pat, Outputable expr) =>
pat -> expr -> SDoc
pprBindStmt LPat (GhcPass idL)
pat LHsExpr (GhcPass idL)
expr]
   flattenArg (a
_, ApplicativeArgMany XApplicativeArgMany (GhcPass idL)
_ [ExprLStmt (GhcPass idL)]
stmts HsExpr (GhcPass idL)
_ LPat (GhcPass idL)
_ HsDoFlavour
_) =
     forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ExprLStmt (GhcPass idL) -> [SDoc]
flattenStmt [ExprLStmt (GhcPass idL)]
stmts

   pp_debug :: SDoc
pp_debug =
     let
         ap_expr :: SDoc
ap_expr = forall doc. IsLine doc => [doc] -> doc
sep (forall doc. IsLine doc => doc -> [doc] -> [doc]
punctuate (forall doc. IsLine doc => String -> doc
text String
" |") (forall a b. (a -> b) -> [a] -> [b]
map forall a. (a, ApplicativeArg (GhcPass idL)) -> SDoc
pp_arg [(SyntaxExpr (GhcPass idR), ApplicativeArg (GhcPass idL))]
args))
     in
       forall doc. IsOutput doc => doc -> doc
whenPprDebug (if forall a. Maybe a -> Bool
isJust Maybe (SyntaxExpr (GhcPass idR))
mb_join then forall doc. IsLine doc => String -> doc
text String
"[join]" else forall doc. IsOutput doc => doc
empty) forall doc. IsLine doc => doc -> doc -> doc
<+>
       (if forall a. [a] -> Int -> Bool
lengthAtLeast [(SyntaxExpr (GhcPass idR), ApplicativeArg (GhcPass idL))]
args Int
2 then forall doc. IsLine doc => doc -> doc
parens else forall a. a -> a
id) SDoc
ap_expr

   pp_arg :: (a, ApplicativeArg (GhcPass idL)) -> SDoc
   pp_arg :: forall a. (a, ApplicativeArg (GhcPass idL)) -> SDoc
pp_arg (a
_, ApplicativeArg (GhcPass idL)
applicativeArg) = forall a. Outputable a => a -> SDoc
ppr ApplicativeArg (GhcPass idL)
applicativeArg

pprBindStmt :: (Outputable pat, Outputable expr) => pat -> expr -> SDoc
pprBindStmt :: forall pat expr.
(Outputable pat, Outputable expr) =>
pat -> expr -> SDoc
pprBindStmt pat
pat expr
expr = forall doc. IsLine doc => [doc] -> doc
hsep [forall a. Outputable a => a -> SDoc
ppr pat
pat, SDoc
larrow, forall a. Outputable a => a -> SDoc
ppr expr
expr]

instance (OutputableBndrId idL)
      => Outputable (ApplicativeArg (GhcPass idL)) where
  ppr :: ApplicativeArg (GhcPass idL) -> SDoc
ppr = forall (idL :: Pass).
OutputableBndrId idL =>
ApplicativeArg (GhcPass idL) -> SDoc
pprArg

pprArg :: forall idL . (OutputableBndrId idL) => ApplicativeArg (GhcPass idL) -> SDoc
pprArg :: forall (idL :: Pass).
OutputableBndrId idL =>
ApplicativeArg (GhcPass idL) -> SDoc
pprArg (ApplicativeArgOne XApplicativeArgOne (GhcPass idL)
_ LPat (GhcPass idL)
pat LHsExpr (GhcPass idL)
expr Bool
isBody)
  | Bool
isBody = forall a. Outputable a => a -> SDoc
ppr LHsExpr (GhcPass idL)
expr -- See Note [Applicative BodyStmt]
  | Bool
otherwise = forall pat expr.
(Outputable pat, Outputable expr) =>
pat -> expr -> SDoc
pprBindStmt LPat (GhcPass idL)
pat LHsExpr (GhcPass idL)
expr
pprArg (ApplicativeArgMany XApplicativeArgMany (GhcPass idL)
_ [ExprLStmt (GhcPass idL)]
stmts HsExpr (GhcPass idL)
return LPat (GhcPass idL)
pat HsDoFlavour
ctxt) =
     forall a. Outputable a => a -> SDoc
ppr LPat (GhcPass idL)
pat forall doc. IsLine doc => doc -> doc -> doc
<+>
     forall doc. IsLine doc => String -> doc
text String
"<-" forall doc. IsLine doc => doc -> doc -> doc
<+>
     forall (p :: Pass) body.
(OutputableBndrId p, Outputable body,
 Anno (StmtLR (GhcPass p) (GhcPass p) body) ~ SrcSpanAnnA) =>
HsDoFlavour -> [LStmt (GhcPass p) body] -> SDoc
pprDo HsDoFlavour
ctxt ([ExprLStmt (GhcPass idL)]
stmts forall a. [a] -> [a] -> [a]
++
                   [forall a an. a -> LocatedAn an a
noLocA (forall idL idR body.
XLastStmt idL idR body
-> body -> Maybe Bool -> SyntaxExpr idR -> StmtLR idL idR body
LastStmt NoExtField
noExtField (forall a an. a -> LocatedAn an a
noLocA HsExpr (GhcPass idL)
return) forall a. Maybe a
Nothing forall (p :: Pass). IsPass p => SyntaxExpr (GhcPass p)
noSyntaxExpr)])

pprTransformStmt :: (OutputableBndrId p)
                 => [IdP (GhcPass p)] -> LHsExpr (GhcPass p)
                 -> Maybe (LHsExpr (GhcPass p)) -> SDoc
pprTransformStmt :: forall (p :: Pass).
OutputableBndrId p =>
[IdP (GhcPass p)]
-> LHsExpr (GhcPass p) -> Maybe (LHsExpr (GhcPass p)) -> SDoc
pprTransformStmt [IdP (GhcPass p)]
bndrs LHsExpr (GhcPass p)
using Maybe (LHsExpr (GhcPass p))
by
  = forall doc. IsLine doc => [doc] -> doc
sep [ forall doc. IsLine doc => String -> doc
text String
"then" forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsOutput doc => doc -> doc
whenPprDebug (forall doc. IsLine doc => doc -> doc
braces (forall a. Outputable a => a -> SDoc
ppr [IdP (GhcPass p)]
bndrs))
        , Int -> SDoc -> SDoc
nest Int
2 (forall a. Outputable a => a -> SDoc
ppr LHsExpr (GhcPass p)
using)
        , Int -> SDoc -> SDoc
nest Int
2 (forall body. Outputable body => Maybe body -> SDoc
pprBy Maybe (LHsExpr (GhcPass p))
by)]

pprTransStmt :: Outputable body => Maybe body -> body -> TransForm -> SDoc
pprTransStmt :: forall body.
Outputable body =>
Maybe body -> body -> TransForm -> SDoc
pprTransStmt Maybe body
by body
using TransForm
ThenForm
  = forall doc. IsLine doc => [doc] -> doc
sep [ forall doc. IsLine doc => String -> doc
text String
"then", Int -> SDoc -> SDoc
nest Int
2 (forall a. Outputable a => a -> SDoc
ppr body
using), Int -> SDoc -> SDoc
nest Int
2 (forall body. Outputable body => Maybe body -> SDoc
pprBy Maybe body
by)]
pprTransStmt Maybe body
by body
using TransForm
GroupForm
  = forall doc. IsLine doc => [doc] -> doc
sep [ forall doc. IsLine doc => String -> doc
text String
"then group", Int -> SDoc -> SDoc
nest Int
2 (forall body. Outputable body => Maybe body -> SDoc
pprBy Maybe body
by), Int -> SDoc -> SDoc
nest Int
2 (forall doc. IsLine doc => String -> doc
text String
"using" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr body
using)]

pprBy :: Outputable body => Maybe body -> SDoc
pprBy :: forall body. Outputable body => Maybe body -> SDoc
pprBy Maybe body
Nothing  = forall doc. IsOutput doc => doc
empty
pprBy (Just body
e) = forall doc. IsLine doc => String -> doc
text String
"by" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr body
e

pprDo :: (OutputableBndrId p, Outputable body,
                 Anno (StmtLR (GhcPass p) (GhcPass p) body) ~ SrcSpanAnnA
         )
      => HsDoFlavour -> [LStmt (GhcPass p) body] -> SDoc
pprDo :: forall (p :: Pass) body.
(OutputableBndrId p, Outputable body,
 Anno (StmtLR (GhcPass p) (GhcPass p) body) ~ SrcSpanAnnA) =>
HsDoFlavour -> [LStmt (GhcPass p) body] -> SDoc
pprDo (DoExpr Maybe ModuleName
m)    [LStmt (GhcPass p) body]
stmts =
  Maybe ModuleName -> SDoc
ppr_module_name_prefix Maybe ModuleName
m forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => String -> doc
text String
"do"  forall doc. IsLine doc => doc -> doc -> doc
<+> forall (idL :: Pass) (idR :: Pass) body.
(OutputableBndrId idL, OutputableBndrId idR,
 Anno (StmtLR (GhcPass idL) (GhcPass idR) body) ~ SrcSpanAnnA,
 Outputable body) =>
[LStmtLR (GhcPass idL) (GhcPass idR) body] -> SDoc
ppr_do_stmts [LStmt (GhcPass p) body]
stmts
pprDo HsDoFlavour
GhciStmtCtxt  [LStmt (GhcPass p) body]
stmts = forall doc. IsLine doc => String -> doc
text String
"do"  forall doc. IsLine doc => doc -> doc -> doc
<+> forall (idL :: Pass) (idR :: Pass) body.
(OutputableBndrId idL, OutputableBndrId idR,
 Anno (StmtLR (GhcPass idL) (GhcPass idR) body) ~ SrcSpanAnnA,
 Outputable body) =>
[LStmtLR (GhcPass idL) (GhcPass idR) body] -> SDoc
ppr_do_stmts [LStmt (GhcPass p) body]
stmts
pprDo (MDoExpr Maybe ModuleName
m)   [LStmt (GhcPass p) body]
stmts =
  Maybe ModuleName -> SDoc
ppr_module_name_prefix Maybe ModuleName
m forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => String -> doc
text String
"mdo"  forall doc. IsLine doc => doc -> doc -> doc
<+> forall (idL :: Pass) (idR :: Pass) body.
(OutputableBndrId idL, OutputableBndrId idR,
 Anno (StmtLR (GhcPass idL) (GhcPass idR) body) ~ SrcSpanAnnA,
 Outputable body) =>
[LStmtLR (GhcPass idL) (GhcPass idR) body] -> SDoc
ppr_do_stmts [LStmt (GhcPass p) body]
stmts
pprDo HsDoFlavour
ListComp      [LStmt (GhcPass p) body]
stmts = forall doc. IsLine doc => doc -> doc
brackets    forall a b. (a -> b) -> a -> b
$ forall (p :: Pass) body.
(OutputableBndrId p, Outputable body,
 Anno (StmtLR (GhcPass p) (GhcPass p) body) ~ SrcSpanAnnA) =>
[LStmt (GhcPass p) body] -> SDoc
pprComp [LStmt (GhcPass p) body]
stmts
pprDo HsDoFlavour
MonadComp     [LStmt (GhcPass p) body]
stmts = forall doc. IsLine doc => doc -> doc
brackets    forall a b. (a -> b) -> a -> b
$ forall (p :: Pass) body.
(OutputableBndrId p, Outputable body,
 Anno (StmtLR (GhcPass p) (GhcPass p) body) ~ SrcSpanAnnA) =>
[LStmt (GhcPass p) body] -> SDoc
pprComp [LStmt (GhcPass p) body]
stmts

pprArrowExpr :: (OutputableBndrId p, Outputable body,
                 Anno (StmtLR (GhcPass p) (GhcPass p) body) ~ SrcSpanAnnA
         )
      => [LStmt (GhcPass p) body] -> SDoc
pprArrowExpr :: forall (p :: Pass) body.
(OutputableBndrId p, Outputable body,
 Anno (StmtLR (GhcPass p) (GhcPass p) body) ~ SrcSpanAnnA) =>
[LStmt (GhcPass p) body] -> SDoc
pprArrowExpr [LStmt (GhcPass p) body]
stmts = forall doc. IsLine doc => String -> doc
text String
"do"  forall doc. IsLine doc => doc -> doc -> doc
<+> forall (idL :: Pass) (idR :: Pass) body.
(OutputableBndrId idL, OutputableBndrId idR,
 Anno (StmtLR (GhcPass idL) (GhcPass idR) body) ~ SrcSpanAnnA,
 Outputable body) =>
[LStmtLR (GhcPass idL) (GhcPass idR) body] -> SDoc
ppr_do_stmts [LStmt (GhcPass p) body]
stmts

ppr_module_name_prefix :: Maybe ModuleName -> SDoc
ppr_module_name_prefix :: Maybe ModuleName -> SDoc
ppr_module_name_prefix = \case
  Maybe ModuleName
Nothing -> forall doc. IsOutput doc => doc
empty
  Just ModuleName
module_name -> forall a. Outputable a => a -> SDoc
ppr ModuleName
module_name forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => Char -> doc
char Char
'.'

ppr_do_stmts :: (OutputableBndrId idL, OutputableBndrId idR,
                 Anno (StmtLR (GhcPass idL) (GhcPass idR) body) ~ SrcSpanAnnA,
                 Outputable body)
             => [LStmtLR (GhcPass idL) (GhcPass idR) body] -> SDoc
-- Print a bunch of do stmts
ppr_do_stmts :: forall (idL :: Pass) (idR :: Pass) body.
(OutputableBndrId idL, OutputableBndrId idR,
 Anno (StmtLR (GhcPass idL) (GhcPass idR) body) ~ SrcSpanAnnA,
 Outputable body) =>
[LStmtLR (GhcPass idL) (GhcPass idR) body] -> SDoc
ppr_do_stmts [LStmtLR (GhcPass idL) (GhcPass idR) body]
stmts = ([SDoc] -> SDoc) -> [SDoc] -> SDoc
pprDeeperList forall doc. IsDoc doc => [doc] -> doc
vcat (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [LStmtLR (GhcPass idL) (GhcPass idR) body]
stmts)

pprComp :: (OutputableBndrId p, Outputable body,
                 Anno (StmtLR (GhcPass p) (GhcPass p) body) ~ SrcSpanAnnA)
        => [LStmt (GhcPass p) body] -> SDoc
pprComp :: forall (p :: Pass) body.
(OutputableBndrId p, Outputable body,
 Anno (StmtLR (GhcPass p) (GhcPass p) body) ~ SrcSpanAnnA) =>
[LStmt (GhcPass p) body] -> SDoc
pprComp [LStmt (GhcPass p) body]
quals     -- Prints:  body | qual1, ..., qualn
  | Just ([GenLocated SrcSpanAnnA (StmtLR (GhcPass p) (GhcPass p) body)]
initStmts, L SrcSpanAnnA
_ (LastStmt XLastStmt (GhcPass p) (GhcPass p) body
_ body
body Maybe Bool
_ SyntaxExpr (GhcPass p)
_)) <- forall a. [a] -> Maybe ([a], a)
snocView [LStmt (GhcPass p) body]
quals
  = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [GenLocated SrcSpanAnnA (StmtLR (GhcPass p) (GhcPass p) body)]
initStmts
       -- If there are no statements in a list comprehension besides the last
       -- one, we simply treat it like a normal list. This does arise
       -- occasionally in code that GHC generates, e.g., in implementations of
       -- 'range' for derived 'Ix' instances for product datatypes with exactly
       -- one constructor (e.g., see #12583).
       then forall a. Outputable a => a -> SDoc
ppr body
body
       else SDoc -> Int -> SDoc -> SDoc
hang (forall a. Outputable a => a -> SDoc
ppr body
body forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => doc
vbar) Int
2 (forall (p :: Pass) body.
(OutputableBndrId p, Outputable body,
 Anno (StmtLR (GhcPass p) (GhcPass p) body) ~ SrcSpanAnnA) =>
[LStmt (GhcPass p) body] -> SDoc
pprQuals [GenLocated SrcSpanAnnA (StmtLR (GhcPass p) (GhcPass p) body)]
initStmts)
  | Bool
otherwise
  = forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"pprComp" (forall (p :: Pass) body.
(OutputableBndrId p, Outputable body,
 Anno (StmtLR (GhcPass p) (GhcPass p) body) ~ SrcSpanAnnA) =>
[LStmt (GhcPass p) body] -> SDoc
pprQuals [LStmt (GhcPass p) body]
quals)

pprQuals :: (OutputableBndrId p, Outputable body,
                 Anno (StmtLR (GhcPass p) (GhcPass p) body) ~ SrcSpanAnnA)
         => [LStmt (GhcPass p) body] -> SDoc
-- Show list comprehension qualifiers separated by commas
pprQuals :: forall (p :: Pass) body.
(OutputableBndrId p, Outputable body,
 Anno (StmtLR (GhcPass p) (GhcPass p) body) ~ SrcSpanAnnA) =>
[LStmt (GhcPass p) body] -> SDoc
pprQuals [LStmt (GhcPass p) body]
quals = forall a. Outputable a => [a] -> SDoc
interpp'SP [LStmt (GhcPass p) body]
quals

{-
************************************************************************
*                                                                      *
                Template Haskell quotation brackets
*                                                                      *
************************************************************************
-}

-- | Finalizers produced by a splice with
-- 'Language.Haskell.TH.Syntax.addModFinalizer'
--
-- See Note [Delaying modFinalizers in untyped splices] in GHC.Rename.Splice. For how
-- this is used.
--
newtype ThModFinalizers = ThModFinalizers [ForeignRef (TH.Q ())]

-- A Data instance which ignores the argument of 'ThModFinalizers'.
instance Data ThModFinalizers where
  gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ThModFinalizers
gunfold forall b r. Data b => c (b -> r) -> c r
_ forall r. r -> c r
z Constr
_ = forall r. r -> c r
z forall a b. (a -> b) -> a -> b
$ [ForeignRef (Q ())] -> ThModFinalizers
ThModFinalizers []
  toConstr :: ThModFinalizers -> Constr
toConstr  ThModFinalizers
a   = DataType -> String -> [String] -> Fixity -> Constr
mkConstr (forall a. Data a => a -> DataType
dataTypeOf ThModFinalizers
a) String
"ThModFinalizers" [] Fixity
Data.Prefix
  dataTypeOf :: ThModFinalizers -> DataType
dataTypeOf ThModFinalizers
a  = String -> [Constr] -> DataType
mkDataType String
"HsExpr.ThModFinalizers" [forall a. Data a => a -> Constr
toConstr ThModFinalizers
a]

-- See Note [Delaying modFinalizers in untyped splices] in GHC.Rename.Splice.
-- This is the result of splicing a splice. It is produced by
-- the renamer and consumed by the typechecker. It lives only between the two.
data HsUntypedSpliceResult thing  -- 'thing' can be HsExpr or HsType
  = HsUntypedSpliceTop
      { forall thing. HsUntypedSpliceResult thing -> ThModFinalizers
utsplice_result_finalizers :: ThModFinalizers -- ^ TH finalizers produced by the splice.
      , forall thing. HsUntypedSpliceResult thing -> thing
utsplice_result            :: thing           -- ^ The result of splicing; See Note [Lifecycle of a splice]
      }
  | HsUntypedSpliceNested SplicePointName -- A unique name to identify this splice point

type instance XTypedSplice   GhcPs = (EpAnnCO, EpAnn [AddEpAnn])
type instance XTypedSplice   GhcRn = SplicePointName
type instance XTypedSplice   GhcTc = DelayedSplice

type instance XUntypedSplice GhcPs = EpAnnCO
type instance XUntypedSplice GhcRn = HsUntypedSpliceResult (HsExpr GhcRn)
type instance XUntypedSplice GhcTc = DataConCantHappen

-- HsUntypedSplice
type instance XUntypedSpliceExpr GhcPs = EpAnn [AddEpAnn]
type instance XUntypedSpliceExpr GhcRn = EpAnn [AddEpAnn]
type instance XUntypedSpliceExpr GhcTc = DataConCantHappen

type instance XQuasiQuote        p = NoExtField

type instance XXUntypedSplice    p = DataConCantHappen

-- See Note [Running typed splices in the zonker]
-- These are the arguments that are passed to `GHC.Tc.Gen.Splice.runTopSplice`
data DelayedSplice =
  DelayedSplice
    TcLclEnv          -- The local environment to run the splice in
    (LHsExpr GhcRn)   -- The original renamed expression
    TcType            -- The result type of running the splice, unzonked
    (LHsExpr GhcTc)   -- The typechecked expression to run and splice in the result

-- A Data instance which ignores the argument of 'DelayedSplice'.
instance Data DelayedSplice where
  gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DelayedSplice
gunfold forall b r. Data b => c (b -> r) -> c r
_ forall r. r -> c r
_ Constr
_ = forall a. HasCallStack => String -> a
panic String
"DelayedSplice"
  toConstr :: DelayedSplice -> Constr
toConstr  DelayedSplice
a   = DataType -> String -> [String] -> Fixity -> Constr
mkConstr (forall a. Data a => a -> DataType
dataTypeOf DelayedSplice
a) String
"DelayedSplice" [] Fixity
Data.Prefix
  dataTypeOf :: DelayedSplice -> DataType
dataTypeOf DelayedSplice
a  = String -> [Constr] -> DataType
mkDataType String
"HsExpr.DelayedSplice" [forall a. Data a => a -> Constr
toConstr DelayedSplice
a]

-- See Note [Pending Splices]
type SplicePointName = Name

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

-- | Pending Renamer Splice
data PendingRnSplice
  = PendingRnSplice UntypedSpliceFlavour SplicePointName (LHsExpr GhcRn)

-- | Pending Type-checker Splice
data PendingTcSplice
  = PendingTcSplice SplicePointName (LHsExpr GhcTc)


pprPendingSplice :: (OutputableBndrId p)
                 => SplicePointName -> LHsExpr (GhcPass p) -> SDoc
pprPendingSplice :: forall (p :: Pass).
OutputableBndrId p =>
Name -> LHsExpr (GhcPass p) -> SDoc
pprPendingSplice Name
n LHsExpr (GhcPass p)
e = forall doc. IsLine doc => doc -> doc
angleBrackets (forall a. Outputable a => a -> SDoc
ppr Name
n forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
comma forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr (forall (p :: Pass). LHsExpr (GhcPass p) -> LHsExpr (GhcPass p)
stripParensLHsExpr LHsExpr (GhcPass p)
e))

pprTypedSplice :: (OutputableBndrId p) => Maybe SplicePointName -> LHsExpr (GhcPass p) -> SDoc
pprTypedSplice :: forall (p :: Pass).
OutputableBndrId p =>
Maybe Name -> LHsExpr (GhcPass p) -> SDoc
pprTypedSplice Maybe Name
n LHsExpr (GhcPass p)
e = forall (p :: Pass).
OutputableBndrId p =>
SDoc -> Maybe Name -> LHsExpr (GhcPass p) -> SDoc
ppr_splice (forall doc. IsLine doc => String -> doc
text String
"$$") Maybe Name
n LHsExpr (GhcPass p)
e

pprUntypedSplice :: forall p. (OutputableBndrId p)
                 => Bool -- Whether to precede the splice with "$"
                 -> Maybe SplicePointName -- Used for pretty printing when exists
                 -> HsUntypedSplice (GhcPass p)
                 -> SDoc
pprUntypedSplice :: forall (p :: Pass).
OutputableBndrId p =>
Bool -> Maybe Name -> HsUntypedSplice (GhcPass p) -> SDoc
pprUntypedSplice Bool
True  Maybe Name
n (HsUntypedSpliceExpr XUntypedSpliceExpr (GhcPass p)
_ LHsExpr (GhcPass p)
e) = forall (p :: Pass).
OutputableBndrId p =>
SDoc -> Maybe Name -> LHsExpr (GhcPass p) -> SDoc
ppr_splice (forall doc. IsLine doc => String -> doc
text String
"$") Maybe Name
n LHsExpr (GhcPass p)
e
pprUntypedSplice Bool
False Maybe Name
n (HsUntypedSpliceExpr XUntypedSpliceExpr (GhcPass p)
_ LHsExpr (GhcPass p)
e) = forall (p :: Pass).
OutputableBndrId p =>
SDoc -> Maybe Name -> LHsExpr (GhcPass p) -> SDoc
ppr_splice forall doc. IsOutput doc => doc
empty Maybe Name
n LHsExpr (GhcPass p)
e
pprUntypedSplice Bool
_     Maybe Name
_ (HsQuasiQuote XQuasiQuote (GhcPass p)
_ IdP (GhcPass p)
q XRec (GhcPass p) FastString
s)      = forall p. OutputableBndr p => p -> FastString -> SDoc
ppr_quasi IdP (GhcPass p)
q (forall l e. GenLocated l e -> e
unLoc XRec (GhcPass p) FastString
s)

ppr_quasi :: OutputableBndr p => p -> FastString -> SDoc
ppr_quasi :: forall p. OutputableBndr p => p -> FastString -> SDoc
ppr_quasi p
quoter FastString
quote = forall doc. IsLine doc => Char -> doc
char Char
'[' forall doc. IsLine doc => doc -> doc -> doc
<> forall a. Outputable a => a -> SDoc
ppr p
quoter forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
vbar forall doc. IsLine doc => doc -> doc -> doc
<>
                           forall a. Outputable a => a -> SDoc
ppr FastString
quote forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => String -> doc
text String
"|]"

ppr_splice :: (OutputableBndrId p)
           => SDoc
           -> Maybe SplicePointName
           -> LHsExpr (GhcPass p)
           -> SDoc
ppr_splice :: forall (p :: Pass).
OutputableBndrId p =>
SDoc -> Maybe Name -> LHsExpr (GhcPass p) -> SDoc
ppr_splice SDoc
herald Maybe Name
mn LHsExpr (GhcPass p)
e
    = SDoc
herald
    forall doc. IsLine doc => doc -> doc -> doc
<> (case Maybe Name
mn of
         Maybe Name
Nothing -> forall doc. IsOutput doc => doc
empty
         Just Name
splice_name -> forall doc. IsOutput doc => doc -> doc
whenPprDebug (forall doc. IsLine doc => doc -> doc
brackets (forall a. Outputable a => a -> SDoc
ppr Name
splice_name)))
    forall doc. IsLine doc => doc -> doc -> doc
<> forall a. Outputable a => a -> SDoc
ppr LHsExpr (GhcPass p)
e


type instance XExpBr  GhcPs       = NoExtField
type instance XPatBr  GhcPs       = NoExtField
type instance XDecBrL GhcPs       = NoExtField
type instance XDecBrG GhcPs       = NoExtField
type instance XTypBr  GhcPs       = NoExtField
type instance XVarBr  GhcPs       = NoExtField
type instance XXQuote GhcPs       = DataConCantHappen

type instance XExpBr  GhcRn       = NoExtField
type instance XPatBr  GhcRn       = NoExtField
type instance XDecBrL GhcRn       = NoExtField
type instance XDecBrG GhcRn       = NoExtField
type instance XTypBr  GhcRn       = NoExtField
type instance XVarBr  GhcRn       = NoExtField
type instance XXQuote GhcRn       = DataConCantHappen

-- See Note [The life cycle of a TH quotation]
type instance XExpBr  GhcTc       = DataConCantHappen
type instance XPatBr  GhcTc       = DataConCantHappen
type instance XDecBrL GhcTc       = DataConCantHappen
type instance XDecBrG GhcTc       = DataConCantHappen
type instance XTypBr  GhcTc       = DataConCantHappen
type instance XVarBr  GhcTc       = DataConCantHappen
type instance XXQuote GhcTc       = NoExtField

instance OutputableBndrId p
          => Outputable (HsQuote (GhcPass p)) where
  ppr :: HsQuote (GhcPass p) -> SDoc
ppr = forall (p :: Pass).
OutputableBndrId p =>
HsQuote (GhcPass p) -> SDoc
pprHsQuote
    where
      pprHsQuote :: forall p. (OutputableBndrId p)
                   => HsQuote (GhcPass p) -> SDoc
      pprHsQuote :: forall (p :: Pass).
OutputableBndrId p =>
HsQuote (GhcPass p) -> SDoc
pprHsQuote (ExpBr XExpBr (GhcPass p)
_ LHsExpr (GhcPass p)
e)   = SDoc -> SDoc -> SDoc
thBrackets forall doc. IsOutput doc => doc
empty (forall a. Outputable a => a -> SDoc
ppr LHsExpr (GhcPass p)
e)
      pprHsQuote (PatBr XPatBr (GhcPass p)
_ LPat (GhcPass p)
p)   = SDoc -> SDoc -> SDoc
thBrackets (forall doc. IsLine doc => Char -> doc
char Char
'p') (forall a. Outputable a => a -> SDoc
ppr LPat (GhcPass p)
p)
      pprHsQuote (DecBrG XDecBrG (GhcPass p)
_ HsGroup (GhcPass p)
gp) = SDoc -> SDoc -> SDoc
thBrackets (forall doc. IsLine doc => Char -> doc
char Char
'd') (forall a. Outputable a => a -> SDoc
ppr HsGroup (GhcPass p)
gp)
      pprHsQuote (DecBrL XDecBrL (GhcPass p)
_ [LHsDecl (GhcPass p)]
ds) = SDoc -> SDoc -> SDoc
thBrackets (forall doc. IsLine doc => Char -> doc
char Char
'd') (forall doc. IsDoc doc => [doc] -> doc
vcat (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [LHsDecl (GhcPass p)]
ds))
      pprHsQuote (TypBr XTypBr (GhcPass p)
_ LHsType (GhcPass p)
t)   = SDoc -> SDoc -> SDoc
thBrackets (forall doc. IsLine doc => Char -> doc
char Char
't') (forall a. Outputable a => a -> SDoc
ppr LHsType (GhcPass p)
t)
      pprHsQuote (VarBr XVarBr (GhcPass p)
_ Bool
True LIdP (GhcPass p)
n)
        = forall doc. IsLine doc => Char -> doc
char Char
'\'' forall doc. IsLine doc => doc -> doc -> doc
<> forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (forall l e. GenLocated l e -> e
unLoc LIdP (GhcPass p)
n)
      pprHsQuote (VarBr XVarBr (GhcPass p)
_ Bool
False LIdP (GhcPass p)
n)
        = forall doc. IsLine doc => String -> doc
text String
"''" forall doc. IsLine doc => doc -> doc -> doc
<> forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (forall l e. GenLocated l e -> e
unLoc LIdP (GhcPass p)
n)
      pprHsQuote (XQuote XXQuote (GhcPass p)
b)  = case forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p of
#if __GLASGOW_HASKELL__ <= 900
          GhcPs -> dataConCantHappen b
          GhcRn -> dataConCantHappen b
#endif
          GhcPass p
GhcTc -> forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"pprHsQuote: `HsQuote GhcTc` shouldn't exist" (forall a. Outputable a => a -> SDoc
ppr XXQuote (GhcPass p)
b)
                   -- See Note [The life cycle of a TH quotation]

thBrackets :: SDoc -> SDoc -> SDoc
thBrackets :: SDoc -> SDoc -> SDoc
thBrackets SDoc
pp_kind SDoc
pp_body = forall doc. IsLine doc => Char -> doc
char Char
'[' forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
pp_kind forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
vbar forall doc. IsLine doc => doc -> doc -> doc
<+>
                             SDoc
pp_body forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"|]"

thTyBrackets :: SDoc -> SDoc
thTyBrackets :: SDoc -> SDoc
thTyBrackets SDoc
pp_body = forall doc. IsLine doc => String -> doc
text String
"[||" forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
pp_body forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"||]"

instance Outputable PendingRnSplice where
  ppr :: PendingRnSplice -> SDoc
ppr (PendingRnSplice UntypedSpliceFlavour
_ Name
n LHsExpr GhcRn
e) = forall (p :: Pass).
OutputableBndrId p =>
Name -> LHsExpr (GhcPass p) -> SDoc
pprPendingSplice Name
n LHsExpr GhcRn
e

instance Outputable PendingTcSplice where
  ppr :: PendingTcSplice -> SDoc
ppr (PendingTcSplice Name
n LHsExpr GhcTc
e) = forall (p :: Pass).
OutputableBndrId p =>
Name -> LHsExpr (GhcPass p) -> SDoc
pprPendingSplice Name
n LHsExpr GhcTc
e

ppr_with_pending_tc_splices :: SDoc -> [PendingTcSplice] -> SDoc
ppr_with_pending_tc_splices :: SDoc -> [PendingTcSplice] -> SDoc
ppr_with_pending_tc_splices SDoc
x [] = SDoc
x
ppr_with_pending_tc_splices SDoc
x [PendingTcSplice]
ps = SDoc
x forall doc. IsDoc doc => doc -> doc -> doc
$$ forall doc. IsLine doc => String -> doc
text String
"pending(tc)" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr [PendingTcSplice]
ps

{-
************************************************************************
*                                                                      *
\subsection{Enumerations and list comprehensions}
*                                                                      *
************************************************************************
-}

instance OutputableBndrId p
         => Outputable (ArithSeqInfo (GhcPass p)) where
    ppr :: ArithSeqInfo (GhcPass p) -> SDoc
ppr (From LHsExpr (GhcPass p)
e1)             = forall doc. IsLine doc => [doc] -> doc
hcat [forall a. Outputable a => a -> SDoc
ppr LHsExpr (GhcPass p)
e1, SDoc
pp_dotdot]
    ppr (FromThen LHsExpr (GhcPass p)
e1 LHsExpr (GhcPass p)
e2)      = forall doc. IsLine doc => [doc] -> doc
hcat [forall a. Outputable a => a -> SDoc
ppr LHsExpr (GhcPass p)
e1, forall doc. IsLine doc => doc
comma, forall doc. IsLine doc => doc
space, forall a. Outputable a => a -> SDoc
ppr LHsExpr (GhcPass p)
e2, SDoc
pp_dotdot]
    ppr (FromTo LHsExpr (GhcPass p)
e1 LHsExpr (GhcPass p)
e3)        = forall doc. IsLine doc => [doc] -> doc
hcat [forall a. Outputable a => a -> SDoc
ppr LHsExpr (GhcPass p)
e1, SDoc
pp_dotdot, forall a. Outputable a => a -> SDoc
ppr LHsExpr (GhcPass p)
e3]
    ppr (FromThenTo LHsExpr (GhcPass p)
e1 LHsExpr (GhcPass p)
e2 LHsExpr (GhcPass p)
e3)
      = forall doc. IsLine doc => [doc] -> doc
hcat [forall a. Outputable a => a -> SDoc
ppr LHsExpr (GhcPass p)
e1, forall doc. IsLine doc => doc
comma, forall doc. IsLine doc => doc
space, forall a. Outputable a => a -> SDoc
ppr LHsExpr (GhcPass p)
e2, SDoc
pp_dotdot, forall a. Outputable a => a -> SDoc
ppr LHsExpr (GhcPass p)
e3]

pp_dotdot :: SDoc
pp_dotdot :: SDoc
pp_dotdot = forall doc. IsLine doc => String -> doc
text String
" .. "

{-
************************************************************************
*                                                                      *
\subsection{HsMatchCtxt}
*                                                                      *
************************************************************************
-}

instance OutputableBndrId p => Outputable (HsMatchContext (GhcPass p)) where
  ppr :: HsMatchContext (GhcPass p) -> SDoc
ppr m :: HsMatchContext (GhcPass p)
m@(FunRhs{})            = forall doc. IsLine doc => String -> doc
text String
"FunRhs" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr (forall p. HsMatchContext p -> LIdP (NoGhcTc p)
mc_fun HsMatchContext (GhcPass p)
m) forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr (forall p. HsMatchContext p -> LexicalFixity
mc_fixity HsMatchContext (GhcPass p)
m)
  ppr HsMatchContext (GhcPass p)
LambdaExpr              = forall doc. IsLine doc => String -> doc
text String
"LambdaExpr"
  ppr HsMatchContext (GhcPass p)
CaseAlt                 = forall doc. IsLine doc => String -> doc
text String
"CaseAlt"
  ppr (LamCaseAlt LamCaseVariant
lc_variant) = forall doc. IsLine doc => String -> doc
text String
"LamCaseAlt" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr LamCaseVariant
lc_variant
  ppr HsMatchContext (GhcPass p)
IfAlt                   = forall doc. IsLine doc => String -> doc
text String
"IfAlt"
  ppr (ArrowMatchCtxt HsArrowMatchContext
c)      = forall doc. IsLine doc => String -> doc
text String
"ArrowMatchCtxt" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr HsArrowMatchContext
c
  ppr HsMatchContext (GhcPass p)
PatBindRhs              = forall doc. IsLine doc => String -> doc
text String
"PatBindRhs"
  ppr HsMatchContext (GhcPass p)
PatBindGuards           = forall doc. IsLine doc => String -> doc
text String
"PatBindGuards"
  ppr HsMatchContext (GhcPass p)
RecUpd                  = forall doc. IsLine doc => String -> doc
text String
"RecUpd"
  ppr (StmtCtxt HsStmtContext (GhcPass p)
_)            = forall doc. IsLine doc => String -> doc
text String
"StmtCtxt _"
  ppr HsMatchContext (GhcPass p)
ThPatSplice             = forall doc. IsLine doc => String -> doc
text String
"ThPatSplice"
  ppr HsMatchContext (GhcPass p)
ThPatQuote              = forall doc. IsLine doc => String -> doc
text String
"ThPatQuote"
  ppr HsMatchContext (GhcPass p)
PatSyn                  = forall doc. IsLine doc => String -> doc
text String
"PatSyn"

instance Outputable LamCaseVariant where
  ppr :: LamCaseVariant -> SDoc
ppr = forall doc. IsLine doc => String -> doc
text forall b c a. (b -> c) -> (a -> b) -> a -> c
. \case
    LamCaseVariant
LamCase  -> String
"LamCase"
    LamCaseVariant
LamCases -> String
"LamCases"

lamCaseKeyword :: LamCaseVariant -> SDoc
lamCaseKeyword :: LamCaseVariant -> SDoc
lamCaseKeyword LamCaseVariant
LamCase  = forall doc. IsLine doc => String -> doc
text String
"\\case"
lamCaseKeyword LamCaseVariant
LamCases = forall doc. IsLine doc => String -> doc
text String
"\\cases"

pprExternalSrcLoc :: (StringLiteral,(Int,Int),(Int,Int)) -> SDoc
pprExternalSrcLoc :: (StringLiteral, (Int, Int), (Int, Int)) -> SDoc
pprExternalSrcLoc (StringLiteral SourceText
_ FastString
src Maybe RealSrcSpan
_,(Int
n1,Int
n2),(Int
n3,Int
n4))
  = forall a. Outputable a => a -> SDoc
ppr (FastString
src,(Int
n1,Int
n2),(Int
n3,Int
n4))

instance Outputable HsArrowMatchContext where
  ppr :: HsArrowMatchContext -> SDoc
ppr HsArrowMatchContext
ProcExpr                     = forall doc. IsLine doc => String -> doc
text String
"ProcExpr"
  ppr HsArrowMatchContext
ArrowCaseAlt                 = forall doc. IsLine doc => String -> doc
text String
"ArrowCaseAlt"
  ppr (ArrowLamCaseAlt LamCaseVariant
lc_variant) = forall doc. IsLine doc => doc -> doc
parens forall a b. (a -> b) -> a -> b
$ forall doc. IsLine doc => String -> doc
text String
"ArrowLamCaseAlt" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr LamCaseVariant
lc_variant
  ppr HsArrowMatchContext
KappaExpr                    = forall doc. IsLine doc => String -> doc
text String
"KappaExpr"

pprHsArrType :: HsArrAppType -> SDoc
pprHsArrType :: HsArrAppType -> SDoc
pprHsArrType HsArrAppType
HsHigherOrderApp = forall doc. IsLine doc => String -> doc
text String
"higher order arrow application"
pprHsArrType HsArrAppType
HsFirstOrderApp  = forall doc. IsLine doc => String -> doc
text String
"first order arrow application"

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

instance OutputableBndrId p
      => Outputable (HsStmtContext (GhcPass p)) where
    ppr :: HsStmtContext (GhcPass p) -> SDoc
ppr = forall p.
(Outputable (IdP (NoGhcTc p)), UnXRec (NoGhcTc p)) =>
HsStmtContext p -> SDoc
pprStmtContext

-- Used to generate the string for a *runtime* error message
matchContextErrString :: OutputableBndrId p
                      => HsMatchContext (GhcPass p) -> SDoc
matchContextErrString :: forall (p :: Pass).
OutputableBndrId p =>
HsMatchContext (GhcPass p) -> SDoc
matchContextErrString (FunRhs{mc_fun :: forall p. HsMatchContext p -> LIdP (NoGhcTc p)
mc_fun=L Anno (IdGhcP (NoGhcTcPass p))
_ IdGhcP (NoGhcTcPass p)
fun})      = forall doc. IsLine doc => String -> doc
text String
"function" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr IdGhcP (NoGhcTcPass p)
fun
matchContextErrString HsMatchContext (GhcPass p)
CaseAlt                       = forall doc. IsLine doc => String -> doc
text String
"case"
matchContextErrString (LamCaseAlt LamCaseVariant
lc_variant)       = LamCaseVariant -> SDoc
lamCaseKeyword LamCaseVariant
lc_variant
matchContextErrString HsMatchContext (GhcPass p)
IfAlt                         = forall doc. IsLine doc => String -> doc
text String
"multi-way if"
matchContextErrString HsMatchContext (GhcPass p)
PatBindRhs                    = forall doc. IsLine doc => String -> doc
text String
"pattern binding"
matchContextErrString HsMatchContext (GhcPass p)
PatBindGuards                 = forall doc. IsLine doc => String -> doc
text String
"pattern binding guards"
matchContextErrString HsMatchContext (GhcPass p)
RecUpd                        = forall doc. IsLine doc => String -> doc
text String
"record update"
matchContextErrString HsMatchContext (GhcPass p)
LambdaExpr                    = forall doc. IsLine doc => String -> doc
text String
"lambda"
matchContextErrString (ArrowMatchCtxt HsArrowMatchContext
c)            = HsArrowMatchContext -> SDoc
matchArrowContextErrString HsArrowMatchContext
c
matchContextErrString HsMatchContext (GhcPass p)
ThPatSplice                   = forall a. HasCallStack => String -> a
panic String
"matchContextErrString"  -- Not used at runtime
matchContextErrString HsMatchContext (GhcPass p)
ThPatQuote                    = forall a. HasCallStack => String -> a
panic String
"matchContextErrString"  -- Not used at runtime
matchContextErrString HsMatchContext (GhcPass p)
PatSyn                        = forall a. HasCallStack => String -> a
panic String
"matchContextErrString"  -- Not used at runtime
matchContextErrString (StmtCtxt (ParStmtCtxt HsStmtContext (GhcPass p)
c))    = forall (p :: Pass).
OutputableBndrId p =>
HsMatchContext (GhcPass p) -> SDoc
matchContextErrString (forall p. HsStmtContext p -> HsMatchContext p
StmtCtxt HsStmtContext (GhcPass p)
c)
matchContextErrString (StmtCtxt (TransStmtCtxt HsStmtContext (GhcPass p)
c))  = forall (p :: Pass).
OutputableBndrId p =>
HsMatchContext (GhcPass p) -> SDoc
matchContextErrString (forall p. HsStmtContext p -> HsMatchContext p
StmtCtxt HsStmtContext (GhcPass p)
c)
matchContextErrString (StmtCtxt (PatGuard HsMatchContext (GhcPass p)
_))       = forall doc. IsLine doc => String -> doc
text String
"pattern guard"
matchContextErrString (StmtCtxt (HsStmtContext (GhcPass p)
ArrowExpr))        = forall doc. IsLine doc => String -> doc
text String
"'do' block"
matchContextErrString (StmtCtxt (HsDoStmt HsDoFlavour
flavour)) = HsDoFlavour -> SDoc
matchDoContextErrString HsDoFlavour
flavour

matchArrowContextErrString :: HsArrowMatchContext -> SDoc
matchArrowContextErrString :: HsArrowMatchContext -> SDoc
matchArrowContextErrString HsArrowMatchContext
ProcExpr                     = forall doc. IsLine doc => String -> doc
text String
"proc"
matchArrowContextErrString HsArrowMatchContext
ArrowCaseAlt                 = forall doc. IsLine doc => String -> doc
text String
"case"
matchArrowContextErrString (ArrowLamCaseAlt LamCaseVariant
lc_variant) = LamCaseVariant -> SDoc
lamCaseKeyword LamCaseVariant
lc_variant
matchArrowContextErrString HsArrowMatchContext
KappaExpr                    = forall doc. IsLine doc => String -> doc
text String
"kappa"

matchDoContextErrString :: HsDoFlavour -> SDoc
matchDoContextErrString :: HsDoFlavour -> SDoc
matchDoContextErrString HsDoFlavour
GhciStmtCtxt = forall doc. IsLine doc => String -> doc
text String
"interactive GHCi command"
matchDoContextErrString (DoExpr Maybe ModuleName
m)   = Maybe ModuleName -> SDoc -> SDoc
prependQualified Maybe ModuleName
m (forall doc. IsLine doc => String -> doc
text String
"'do' block")
matchDoContextErrString (MDoExpr Maybe ModuleName
m)  = Maybe ModuleName -> SDoc -> SDoc
prependQualified Maybe ModuleName
m (forall doc. IsLine doc => String -> doc
text String
"'mdo' block")
matchDoContextErrString HsDoFlavour
ListComp     = forall doc. IsLine doc => String -> doc
text String
"list comprehension"
matchDoContextErrString HsDoFlavour
MonadComp    = forall doc. IsLine doc => String -> doc
text String
"monad comprehension"

pprMatchInCtxt :: (OutputableBndrId idR, Outputable body)
               => Match (GhcPass idR) body -> SDoc
pprMatchInCtxt :: forall (pr :: Pass) body.
(OutputableBndrId pr, Outputable body) =>
Match (GhcPass pr) body -> SDoc
pprMatchInCtxt Match (GhcPass idR) body
match  = SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"In" forall doc. IsLine doc => doc -> doc -> doc
<+> forall p.
(Outputable (IdP (NoGhcTc p)), UnXRec (NoGhcTc p)) =>
HsMatchContext p -> SDoc
pprMatchContext (forall p body. Match p body -> HsMatchContext p
m_ctxt Match (GhcPass idR) body
match)
                                        forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
colon)
                             Int
4 (forall (pr :: Pass) body.
(OutputableBndrId pr, Outputable body) =>
Match (GhcPass pr) body -> SDoc
pprMatch Match (GhcPass idR) body
match)

pprStmtInCtxt :: (OutputableBndrId idL,
                  OutputableBndrId idR,
                  OutputableBndrId ctx,
                  Outputable body,
                 Anno (StmtLR (GhcPass idL) (GhcPass idR) body) ~ SrcSpanAnnA)
              => HsStmtContext (GhcPass ctx)
              -> StmtLR (GhcPass idL) (GhcPass idR) body
              -> SDoc
pprStmtInCtxt :: forall (idL :: Pass) (idR :: Pass) (ctx :: Pass) body.
(OutputableBndrId idL, OutputableBndrId idR, OutputableBndrId ctx,
 Outputable body,
 Anno (StmtLR (GhcPass idL) (GhcPass idR) body) ~ SrcSpanAnnA) =>
HsStmtContext (GhcPass ctx)
-> StmtLR (GhcPass idL) (GhcPass idR) body -> SDoc
pprStmtInCtxt HsStmtContext (GhcPass ctx)
ctxt (LastStmt XLastStmt (GhcPass idL) (GhcPass idR) body
_ body
e Maybe Bool
_ SyntaxExpr (GhcPass idR)
_)
  | forall id. HsStmtContext id -> Bool
isComprehensionContext HsStmtContext (GhcPass ctx)
ctxt      -- For [ e | .. ], do not mutter about "stmts"
  = SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"In the expression:") Int
2 (forall a. Outputable a => a -> SDoc
ppr body
e)

pprStmtInCtxt HsStmtContext (GhcPass ctx)
ctxt StmtLR (GhcPass idL) (GhcPass idR) body
stmt
  = SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"In a stmt of" forall doc. IsLine doc => doc -> doc -> doc
<+> forall p.
(Outputable (IdP (NoGhcTc p)), UnXRec (NoGhcTc p)) =>
HsStmtContext p -> SDoc
pprAStmtContext HsStmtContext (GhcPass ctx)
ctxt forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
colon)
       Int
2 (forall {idL :: Pass} {idR :: Pass} {body}.
(Anno (StmtLR (GhcPass idL) (GhcPass idR) body) ~ SrcSpanAnnA,
 OutputableBndr (IdGhcP idR), OutputableBndr (IdGhcP idL),
 OutputableBndr (IdGhcP (NoGhcTcPass idR)),
 OutputableBndr (IdGhcP (NoGhcTcPass idL)), IsPass idR, IsPass idL,
 Outputable body,
 Outputable (GenLocated (Anno (IdGhcP idR)) (IdGhcP idR)),
 Outputable (GenLocated (Anno (IdGhcP idL)) (IdGhcP idL)),
 Outputable
   (GenLocated
      (Anno (IdGhcP (NoGhcTcPass idR))) (IdGhcP (NoGhcTcPass idR))),
 Outputable
   (GenLocated
      (Anno (IdGhcP (NoGhcTcPass idL))) (IdGhcP (NoGhcTcPass idL)))) =>
StmtLR (GhcPass idL) (GhcPass idR) body -> SDoc
ppr_stmt StmtLR (GhcPass idL) (GhcPass idR) body
stmt)
  where
    -- For Group and Transform Stmts, don't print the nested stmts!
    ppr_stmt :: StmtLR (GhcPass idL) (GhcPass idR) body -> SDoc
ppr_stmt (TransStmt { trS_by :: forall idL idR body. StmtLR idL idR body -> Maybe (LHsExpr idR)
trS_by = Maybe (LHsExpr (GhcPass idR))
by, trS_using :: forall idL idR body. StmtLR idL idR body -> LHsExpr idR
trS_using = LHsExpr (GhcPass idR)
using
                        , trS_form :: forall idL idR body. StmtLR idL idR body -> TransForm
trS_form = TransForm
form }) = forall body.
Outputable body =>
Maybe body -> body -> TransForm -> SDoc
pprTransStmt Maybe (LHsExpr (GhcPass idR))
by LHsExpr (GhcPass idR)
using TransForm
form
    ppr_stmt StmtLR (GhcPass idL) (GhcPass idR) body
stmt = forall (pl :: Pass) (pr :: Pass) body.
(OutputableBndrId pl, OutputableBndrId pr,
 Anno (StmtLR (GhcPass pl) (GhcPass pr) body) ~ SrcSpanAnnA,
 Outputable body) =>
StmtLR (GhcPass pl) (GhcPass pr) body -> SDoc
pprStmt StmtLR (GhcPass idL) (GhcPass idR) body
stmt

matchSeparator :: HsMatchContext p -> SDoc
matchSeparator :: forall p. HsMatchContext p -> SDoc
matchSeparator FunRhs{}         = forall doc. IsLine doc => String -> doc
text String
"="
matchSeparator HsMatchContext p
CaseAlt          = forall doc. IsLine doc => String -> doc
text String
"->"
matchSeparator LamCaseAlt{}     = forall doc. IsLine doc => String -> doc
text String
"->"
matchSeparator HsMatchContext p
IfAlt            = forall doc. IsLine doc => String -> doc
text String
"->"
matchSeparator HsMatchContext p
LambdaExpr       = forall doc. IsLine doc => String -> doc
text String
"->"
matchSeparator ArrowMatchCtxt{} = forall doc. IsLine doc => String -> doc
text String
"->"
matchSeparator HsMatchContext p
PatBindRhs       = forall doc. IsLine doc => String -> doc
text String
"="
matchSeparator HsMatchContext p
PatBindGuards    = forall doc. IsLine doc => String -> doc
text String
"="
matchSeparator StmtCtxt{}       = forall doc. IsLine doc => String -> doc
text String
"<-"
matchSeparator HsMatchContext p
RecUpd           = forall doc. IsLine doc => String -> doc
text String
"=" -- This can be printed by the pattern
                                       -- match checker trace
matchSeparator HsMatchContext p
ThPatSplice  = forall a. HasCallStack => String -> a
panic String
"unused"
matchSeparator HsMatchContext p
ThPatQuote   = forall a. HasCallStack => String -> a
panic String
"unused"
matchSeparator HsMatchContext p
PatSyn       = forall a. HasCallStack => String -> a
panic String
"unused"

pprMatchContext :: (Outputable (IdP (NoGhcTc p)), UnXRec (NoGhcTc p))
                => HsMatchContext p -> SDoc
pprMatchContext :: forall p.
(Outputable (IdP (NoGhcTc p)), UnXRec (NoGhcTc p)) =>
HsMatchContext p -> SDoc
pprMatchContext HsMatchContext p
ctxt
  | forall {p}. HsMatchContext p -> Bool
want_an HsMatchContext p
ctxt = forall doc. IsLine doc => String -> doc
text String
"an" forall doc. IsLine doc => doc -> doc -> doc
<+> forall p.
(Outputable (IdP (NoGhcTc p)), UnXRec (NoGhcTc p)) =>
HsMatchContext p -> SDoc
pprMatchContextNoun HsMatchContext p
ctxt
  | Bool
otherwise    = forall doc. IsLine doc => String -> doc
text String
"a"  forall doc. IsLine doc => doc -> doc -> doc
<+> forall p.
(Outputable (IdP (NoGhcTc p)), UnXRec (NoGhcTc p)) =>
HsMatchContext p -> SDoc
pprMatchContextNoun HsMatchContext p
ctxt
  where
    want_an :: HsMatchContext p -> Bool
want_an (FunRhs {})                = Bool
True  -- Use "an" in front
    want_an (ArrowMatchCtxt HsArrowMatchContext
ProcExpr)  = Bool
True
    want_an (ArrowMatchCtxt HsArrowMatchContext
KappaExpr) = Bool
True
    want_an HsMatchContext p
_                          = Bool
False

pprMatchContextNoun :: forall p. (Outputable (IdP (NoGhcTc p)), UnXRec (NoGhcTc p))
                    => HsMatchContext p -> SDoc
pprMatchContextNoun :: forall p.
(Outputable (IdP (NoGhcTc p)), UnXRec (NoGhcTc p)) =>
HsMatchContext p -> SDoc
pprMatchContextNoun (FunRhs {mc_fun :: forall p. HsMatchContext p -> LIdP (NoGhcTc p)
mc_fun=LIdP (NoGhcTc p)
fun})   = forall doc. IsLine doc => String -> doc
text String
"equation for"
                                                forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr (forall p a. UnXRec p => XRec p a -> a
unXRec @(NoGhcTc p) LIdP (NoGhcTc p)
fun))
pprMatchContextNoun HsMatchContext p
CaseAlt                 = forall doc. IsLine doc => String -> doc
text String
"case alternative"
pprMatchContextNoun (LamCaseAlt LamCaseVariant
lc_variant) = LamCaseVariant -> SDoc
lamCaseKeyword LamCaseVariant
lc_variant
                                              forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"alternative"
pprMatchContextNoun HsMatchContext p
IfAlt                   = forall doc. IsLine doc => String -> doc
text String
"multi-way if alternative"
pprMatchContextNoun HsMatchContext p
RecUpd                  = forall doc. IsLine doc => String -> doc
text String
"record-update construct"
pprMatchContextNoun HsMatchContext p
ThPatSplice             = forall doc. IsLine doc => String -> doc
text String
"Template Haskell pattern splice"
pprMatchContextNoun HsMatchContext p
ThPatQuote              = forall doc. IsLine doc => String -> doc
text String
"Template Haskell pattern quotation"
pprMatchContextNoun HsMatchContext p
PatBindRhs              = forall doc. IsLine doc => String -> doc
text String
"pattern binding"
pprMatchContextNoun HsMatchContext p
PatBindGuards           = forall doc. IsLine doc => String -> doc
text String
"pattern binding guards"
pprMatchContextNoun HsMatchContext p
LambdaExpr              = forall doc. IsLine doc => String -> doc
text String
"lambda abstraction"
pprMatchContextNoun (ArrowMatchCtxt HsArrowMatchContext
c)      = HsArrowMatchContext -> SDoc
pprArrowMatchContextNoun HsArrowMatchContext
c
pprMatchContextNoun (StmtCtxt HsStmtContext p
ctxt)         = forall doc. IsLine doc => String -> doc
text String
"pattern binding in"
                                              forall doc. IsDoc doc => doc -> doc -> doc
$$ forall p.
(Outputable (IdP (NoGhcTc p)), UnXRec (NoGhcTc p)) =>
HsStmtContext p -> SDoc
pprAStmtContext HsStmtContext p
ctxt
pprMatchContextNoun HsMatchContext p
PatSyn                  = forall doc. IsLine doc => String -> doc
text String
"pattern synonym declaration"

pprMatchContextNouns :: forall p. (Outputable (IdP (NoGhcTc p)), UnXRec (NoGhcTc p))
                     => HsMatchContext p -> SDoc
pprMatchContextNouns :: forall p.
(Outputable (IdP (NoGhcTc p)), UnXRec (NoGhcTc p)) =>
HsMatchContext p -> SDoc
pprMatchContextNouns (FunRhs {mc_fun :: forall p. HsMatchContext p -> LIdP (NoGhcTc p)
mc_fun=LIdP (NoGhcTc p)
fun})   = forall doc. IsLine doc => String -> doc
text String
"equations for"
                                               forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr (forall p a. UnXRec p => XRec p a -> a
unXRec @(NoGhcTc p) LIdP (NoGhcTc p)
fun))
pprMatchContextNouns HsMatchContext p
PatBindGuards           = forall doc. IsLine doc => String -> doc
text String
"pattern binding guards"
pprMatchContextNouns (ArrowMatchCtxt HsArrowMatchContext
c)      = HsArrowMatchContext -> SDoc
pprArrowMatchContextNouns HsArrowMatchContext
c
pprMatchContextNouns (StmtCtxt HsStmtContext p
ctxt)         = forall doc. IsLine doc => String -> doc
text String
"pattern bindings in"
                                               forall doc. IsDoc doc => doc -> doc -> doc
$$ forall p.
(Outputable (IdP (NoGhcTc p)), UnXRec (NoGhcTc p)) =>
HsStmtContext p -> SDoc
pprAStmtContext HsStmtContext p
ctxt
pprMatchContextNouns HsMatchContext p
ctxt                    = forall p.
(Outputable (IdP (NoGhcTc p)), UnXRec (NoGhcTc p)) =>
HsMatchContext p -> SDoc
pprMatchContextNoun HsMatchContext p
ctxt forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => Char -> doc
char Char
's'

pprArrowMatchContextNoun :: HsArrowMatchContext -> SDoc
pprArrowMatchContextNoun :: HsArrowMatchContext -> SDoc
pprArrowMatchContextNoun HsArrowMatchContext
ProcExpr                     = forall doc. IsLine doc => String -> doc
text String
"arrow proc pattern"
pprArrowMatchContextNoun HsArrowMatchContext
ArrowCaseAlt                 = forall doc. IsLine doc => String -> doc
text String
"case alternative within arrow notation"
pprArrowMatchContextNoun (ArrowLamCaseAlt LamCaseVariant
lc_variant) = LamCaseVariant -> SDoc
lamCaseKeyword LamCaseVariant
lc_variant
                                                        forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"alternative within arrow notation"
pprArrowMatchContextNoun HsArrowMatchContext
KappaExpr                    = forall doc. IsLine doc => String -> doc
text String
"arrow kappa abstraction"

pprArrowMatchContextNouns :: HsArrowMatchContext -> SDoc
pprArrowMatchContextNouns :: HsArrowMatchContext -> SDoc
pprArrowMatchContextNouns HsArrowMatchContext
ArrowCaseAlt                 = forall doc. IsLine doc => String -> doc
text String
"case alternatives within arrow notation"
pprArrowMatchContextNouns (ArrowLamCaseAlt LamCaseVariant
lc_variant) = LamCaseVariant -> SDoc
lamCaseKeyword LamCaseVariant
lc_variant
                                                         forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"alternatives within arrow notation"
pprArrowMatchContextNouns HsArrowMatchContext
ctxt                         = HsArrowMatchContext -> SDoc
pprArrowMatchContextNoun HsArrowMatchContext
ctxt forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => Char -> doc
char Char
's'

-----------------
pprAStmtContext, pprStmtContext :: (Outputable (IdP (NoGhcTc p)), UnXRec (NoGhcTc p))
                                => HsStmtContext p -> SDoc
pprAStmtContext :: forall p.
(Outputable (IdP (NoGhcTc p)), UnXRec (NoGhcTc p)) =>
HsStmtContext p -> SDoc
pprAStmtContext (HsDoStmt HsDoFlavour
flavour) = HsDoFlavour -> SDoc
pprAHsDoFlavour HsDoFlavour
flavour
pprAStmtContext HsStmtContext p
ctxt = forall doc. IsLine doc => String -> doc
text String
"a" forall doc. IsLine doc => doc -> doc -> doc
<+> forall p.
(Outputable (IdP (NoGhcTc p)), UnXRec (NoGhcTc p)) =>
HsStmtContext p -> SDoc
pprStmtContext HsStmtContext p
ctxt

-----------------
pprStmtContext :: forall p.
(Outputable (IdP (NoGhcTc p)), UnXRec (NoGhcTc p)) =>
HsStmtContext p -> SDoc
pprStmtContext (HsDoStmt HsDoFlavour
flavour) = HsDoFlavour -> SDoc
pprHsDoFlavour HsDoFlavour
flavour
pprStmtContext (PatGuard HsMatchContext p
ctxt) = forall doc. IsLine doc => String -> doc
text String
"pattern guard for" forall doc. IsDoc doc => doc -> doc -> doc
$$ forall p.
(Outputable (IdP (NoGhcTc p)), UnXRec (NoGhcTc p)) =>
HsMatchContext p -> SDoc
pprMatchContext HsMatchContext p
ctxt
pprStmtContext HsStmtContext p
ArrowExpr       = forall doc. IsLine doc => String -> doc
text String
"'do' block in an arrow command"

-- Drop the inner contexts when reporting errors, else we get
--     Unexpected transform statement
--     in a transformed branch of
--          transformed branch of
--          transformed branch of monad comprehension
pprStmtContext (ParStmtCtxt HsStmtContext p
c) =
  forall doc. IsOutput doc => doc -> doc -> doc
ifPprDebug (forall doc. IsLine doc => [doc] -> doc
sep [forall doc. IsLine doc => String -> doc
text String
"parallel branch of", forall p.
(Outputable (IdP (NoGhcTc p)), UnXRec (NoGhcTc p)) =>
HsStmtContext p -> SDoc
pprAStmtContext HsStmtContext p
c])
             (forall p.
(Outputable (IdP (NoGhcTc p)), UnXRec (NoGhcTc p)) =>
HsStmtContext p -> SDoc
pprStmtContext HsStmtContext p
c)
pprStmtContext (TransStmtCtxt HsStmtContext p
c) =
  forall doc. IsOutput doc => doc -> doc -> doc
ifPprDebug (forall doc. IsLine doc => [doc] -> doc
sep [forall doc. IsLine doc => String -> doc
text String
"transformed branch of", forall p.
(Outputable (IdP (NoGhcTc p)), UnXRec (NoGhcTc p)) =>
HsStmtContext p -> SDoc
pprAStmtContext HsStmtContext p
c])
             (forall p.
(Outputable (IdP (NoGhcTc p)), UnXRec (NoGhcTc p)) =>
HsStmtContext p -> SDoc
pprStmtContext HsStmtContext p
c)

pprStmtCat :: Stmt (GhcPass p) body -> SDoc
pprStmtCat :: forall (p :: Pass) body. Stmt (GhcPass p) body -> SDoc
pprStmtCat (TransStmt {})       = forall doc. IsLine doc => String -> doc
text String
"transform"
pprStmtCat (LastStmt {})        = forall doc. IsLine doc => String -> doc
text String
"return expression"
pprStmtCat (BodyStmt {})        = forall doc. IsLine doc => String -> doc
text String
"body"
pprStmtCat (BindStmt {})        = forall doc. IsLine doc => String -> doc
text String
"binding"
pprStmtCat (LetStmt {})         = forall doc. IsLine doc => String -> doc
text String
"let"
pprStmtCat (RecStmt {})         = forall doc. IsLine doc => String -> doc
text String
"rec"
pprStmtCat (ParStmt {})         = forall doc. IsLine doc => String -> doc
text String
"parallel"
pprStmtCat (ApplicativeStmt {}) = forall doc. IsLine doc => String -> doc
text String
"applicative"

pprAHsDoFlavour, pprHsDoFlavour :: HsDoFlavour -> SDoc
pprAHsDoFlavour :: HsDoFlavour -> SDoc
pprAHsDoFlavour HsDoFlavour
flavour = SDoc
article forall doc. IsLine doc => doc -> doc -> doc
<+> HsDoFlavour -> SDoc
pprHsDoFlavour HsDoFlavour
flavour
  where
    pp_an :: SDoc
pp_an = forall doc. IsLine doc => String -> doc
text String
"an"
    pp_a :: SDoc
pp_a  = forall doc. IsLine doc => String -> doc
text String
"a"
    article :: SDoc
article = case HsDoFlavour
flavour of
                  MDoExpr Maybe ModuleName
Nothing -> SDoc
pp_an
                  HsDoFlavour
GhciStmtCtxt  -> SDoc
pp_an
                  HsDoFlavour
_             -> SDoc
pp_a
pprHsDoFlavour :: HsDoFlavour -> SDoc
pprHsDoFlavour (DoExpr Maybe ModuleName
m)      = Maybe ModuleName -> SDoc -> SDoc
prependQualified Maybe ModuleName
m (forall doc. IsLine doc => String -> doc
text String
"'do' block")
pprHsDoFlavour (MDoExpr Maybe ModuleName
m)     = Maybe ModuleName -> SDoc -> SDoc
prependQualified Maybe ModuleName
m (forall doc. IsLine doc => String -> doc
text String
"'mdo' block")
pprHsDoFlavour HsDoFlavour
ListComp        = forall doc. IsLine doc => String -> doc
text String
"list comprehension"
pprHsDoFlavour HsDoFlavour
MonadComp       = forall doc. IsLine doc => String -> doc
text String
"monad comprehension"
pprHsDoFlavour HsDoFlavour
GhciStmtCtxt    = forall doc. IsLine doc => String -> doc
text String
"interactive GHCi command"

prependQualified :: Maybe ModuleName -> SDoc -> SDoc
prependQualified :: Maybe ModuleName -> SDoc -> SDoc
prependQualified Maybe ModuleName
Nothing  SDoc
t = SDoc
t
prependQualified (Just ModuleName
_) SDoc
t = forall doc. IsLine doc => String -> doc
text String
"qualified" forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
t

{-
************************************************************************
*                                                                      *
FieldLabelStrings
*                                                                      *
************************************************************************
-}

instance (UnXRec p, Outputable (XRec p FieldLabelString)) => Outputable (FieldLabelStrings p) where
  ppr :: FieldLabelStrings p -> SDoc
ppr (FieldLabelStrings [XRec p (DotFieldOcc p)]
flds) =
    forall doc. IsLine doc => [doc] -> doc
hcat (forall doc. IsLine doc => doc -> [doc] -> [doc]
punctuate forall doc. IsLine doc => doc
dot (forall a b. (a -> b) -> [a] -> [b]
map (forall a. Outputable a => a -> SDoc
ppr forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall p a. UnXRec p => XRec p a -> a
unXRec @p) [XRec p (DotFieldOcc p)]
flds))

instance (UnXRec p, Outputable (XRec p FieldLabelString)) => OutputableBndr (FieldLabelStrings p) where
  pprInfixOcc :: FieldLabelStrings p -> SDoc
pprInfixOcc = forall p.
(UnXRec p, Outputable (XRec p FieldLabelString)) =>
FieldLabelStrings p -> SDoc
pprFieldLabelStrings
  pprPrefixOcc :: FieldLabelStrings p -> SDoc
pprPrefixOcc = forall p.
(UnXRec p, Outputable (XRec p FieldLabelString)) =>
FieldLabelStrings p -> SDoc
pprFieldLabelStrings

instance (UnXRec p,  Outputable (XRec p FieldLabelString)) => OutputableBndr (Located (FieldLabelStrings p)) where
  pprInfixOcc :: Located (FieldLabelStrings p) -> SDoc
pprInfixOcc = forall a. OutputableBndr a => a -> SDoc
pprInfixOcc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l e. GenLocated l e -> e
unLoc
  pprPrefixOcc :: Located (FieldLabelStrings p) -> SDoc
pprPrefixOcc = forall a. OutputableBndr a => a -> SDoc
pprInfixOcc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l e. GenLocated l e -> e
unLoc

pprFieldLabelStrings :: forall p. (UnXRec p, Outputable (XRec p FieldLabelString)) => FieldLabelStrings p -> SDoc
pprFieldLabelStrings :: forall p.
(UnXRec p, Outputable (XRec p FieldLabelString)) =>
FieldLabelStrings p -> SDoc
pprFieldLabelStrings (FieldLabelStrings [XRec p (DotFieldOcc p)]
flds) =
    forall doc. IsLine doc => [doc] -> doc
hcat (forall doc. IsLine doc => doc -> [doc] -> [doc]
punctuate forall doc. IsLine doc => doc
dot (forall a b. (a -> b) -> [a] -> [b]
map (forall a. Outputable a => a -> SDoc
ppr forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall p a. UnXRec p => XRec p a -> a
unXRec @p) [XRec p (DotFieldOcc p)]
flds))

pprPrefixFastString :: FastString -> SDoc
pprPrefixFastString :: FastString -> SDoc
pprPrefixFastString FastString
fs = forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (FastString -> RdrName
mkVarUnqual FastString
fs)

instance UnXRec p => Outputable (DotFieldOcc p) where
  ppr :: DotFieldOcc p -> SDoc
ppr (DotFieldOcc XCDotFieldOcc p
_ XRec p FieldLabelString
s) = (FastString -> SDoc
pprPrefixFastString forall b c a. (b -> c) -> (a -> b) -> a -> c
. FieldLabelString -> FastString
field_label forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall p a. UnXRec p => XRec p a -> a
unXRec @p) XRec p FieldLabelString
s
  ppr XDotFieldOcc{} = forall doc. IsLine doc => String -> doc
text String
"XDotFieldOcc"

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

type instance Anno (HsExpr (GhcPass p)) = SrcSpanAnnA
type instance Anno [LocatedA ((StmtLR (GhcPass pl) (GhcPass pr) (LocatedA (HsExpr (GhcPass pr)))))] = SrcSpanAnnL
type instance Anno [LocatedA ((StmtLR (GhcPass pl) (GhcPass pr) (LocatedA (HsCmd (GhcPass pr)))))] = SrcSpanAnnL

type instance Anno (HsCmd (GhcPass p)) = SrcSpanAnnA

type instance Anno [LocatedA (StmtLR (GhcPass pl) (GhcPass pr) (LocatedA (HsCmd (GhcPass pr))))]
  = SrcSpanAnnL
type instance Anno (HsCmdTop (GhcPass p)) = SrcAnn NoEpAnns
type instance Anno [LocatedA (Match (GhcPass p) (LocatedA (HsExpr (GhcPass p))))] = SrcSpanAnnL
type instance Anno [LocatedA (Match (GhcPass p) (LocatedA (HsCmd  (GhcPass p))))] = SrcSpanAnnL
type instance Anno (Match (GhcPass p) (LocatedA (HsExpr (GhcPass p)))) = SrcSpanAnnA
type instance Anno (Match (GhcPass p) (LocatedA (HsCmd  (GhcPass p)))) = SrcSpanAnnA
type instance Anno (GRHS (GhcPass p) (LocatedA (HsExpr (GhcPass p)))) = SrcAnn NoEpAnns
type instance Anno (GRHS (GhcPass p) (LocatedA (HsCmd  (GhcPass p)))) = SrcAnn NoEpAnns
type instance Anno (StmtLR (GhcPass pl) (GhcPass pr) (LocatedA (body (GhcPass pr)))) = SrcSpanAnnA

type instance Anno (HsUntypedSplice (GhcPass p)) = SrcSpanAnnA

type instance Anno [LocatedA (StmtLR (GhcPass pl) (GhcPass pr) (LocatedA (body (GhcPass pr))))] = SrcSpanAnnL

type instance Anno (FieldLabelStrings (GhcPass p)) = SrcAnn NoEpAnns
type instance Anno FieldLabelString                = SrcSpanAnnN

type instance Anno FastString                      = SrcAnn NoEpAnns
  -- Used in HsQuasiQuote and perhaps elsewhere

type instance Anno (DotFieldOcc (GhcPass p))       = SrcAnn NoEpAnns

instance (Anno a ~ SrcSpanAnn' (EpAnn an))
   => WrapXRec (GhcPass p) a where
  wrapXRec :: a -> XRec (GhcPass p) a
wrapXRec = forall a an. a -> LocatedAn an a
noLocA