{-# 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-incomplete-uni-patterns #-}
{-# 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

#include "GhclibHsVersions.h"

import Language.Haskell.Syntax.Expr

-- friends:
import GHC.Prelude

import GHC.Hs.Decls
import GHC.Hs.Pat
import GHC.Hs.Lit
import Language.Haskell.Syntax.Extension
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.Set
import GHC.Types.Basic
import GHC.Types.Fixity
import GHC.Types.SourceText
import GHC.Types.SrcLoc
import GHC.Core.ConLike
import GHC.Unit.Module (ModuleName)
import GHC.Utils.Misc
import GHC.Utils.Outputable
import GHC.Utils.Panic
import GHC.Data.FastString
import GHC.Core.Type
import GHC.Builtin.Types (mkTupleStr)
import GHC.Tc.Utils.TcType (TcType)
import {-# SOURCE #-} GHC.Tc.Types (TcLclEnv)

-- libraries:
import Data.Data hiding (Fixity(..))
import qualified Data.Data as Data (Fixity(..))
import qualified Data.Kind
import Data.Maybe (isJust)
import Data.Void  ( Void )
import Data.Foldable ( toList )

{- *********************************************************************
*                                                                      *
                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      = String -> SDoc
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 ->
      (Bool -> SDoc) -> SDoc
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 SDoc -> SDoc -> SDoc
<> SDoc -> SDoc
braces (forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas forall a. Outputable a => a -> SDoc
ppr [HsWrapper]
arg_wraps)
                    SDoc -> SDoc -> SDoc
<> SDoc -> SDoc
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 = String -> SDoc
text String
"<no syntax expr>"

-- | Extra data fields for a 'RecordUpd', added by the type checker
data RecordUpdTc = RecordUpdTc
      { RecordUpdTc -> [ConLike]
rupd_cons :: [ConLike]
                -- Filled in by the type checker to the
                -- _non-empty_ list of DataCons that have
                -- all the upd'd fields

      , RecordUpdTc -> [Type]
rupd_in_tys  :: [Type]  -- Argument types of *input* record type
      , RecordUpdTc -> [Type]
rupd_out_tys :: [Type]  --             and  *output* record type
                -- For a data family, these are the type args of the
                -- /representation/ type constructor

      , RecordUpdTc -> HsWrapper
rupd_wrap :: HsWrapper  -- See note [Record Update HsWrapper]
      }

-- | HsWrap appears only in typechecker output
-- Invariant: The contained Expr is *NOT* itself an HsWrap.
-- See Note [Detecting forced eta expansion] in "GHC.HsToCore.Expr".
-- This invariant is maintained by 'GHC.Hs.Utils.mkHsWrap'.
-- hs_syn is something like HsExpr or HsCmd
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)

type instance HsDoRn (GhcPass _) = GhcRn
type instance HsBracketRn (GhcPass _) = GhcRn
type instance PendingRnSplice' (GhcPass _) = PendingRnSplice
type instance PendingTcSplice' (GhcPass _) = PendingTcSplice

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

{- Note [Constructor cannot occur]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Some data constructors can't occur in certain phases; e.g. the output
of the type checker never has OverLabel. We signal this by setting
the extension field to Void. For example:
   type instance XOverLabel GhcTc = Void
   dsExpr (HsOverLabel x _) = absurd x

It would be better to omit the pattern match altogether, but we
could only do that if the extension field was strict (#18764)
-}

-- 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
type instance XConLikeOut    (GhcPass _) = NoExtField
type instance XRecFld        (GhcPass _) = 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 = Void  -- See Note [Constructor cannot occur]

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

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 XConLikeOut    (GhcPass _) = NoExtField
type instance XRecFld        (GhcPass _) = NoExtField
type instance XIPVar         (GhcPass _) = EpAnnCO
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 = SrcSpan -- Where the `@` lives
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 = Void  -- See Note [Constructor cannot occur]

-- 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 = Void  -- See Note [Constructor cannot occur]
type instance XSectionR      GhcTc = Void  -- See Note [Constructor cannot occur]


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

type instance XPar           (GhcPass _) = EpAnn AnnParen

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 = EpAnn AnnsLet
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 = RecordUpdTc

type instance XGetField     GhcPs = EpAnnCO
type instance XGetField     GhcRn = NoExtField
type instance XGetField     GhcTc = Void
-- 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 = Void
-- 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 XBracket       (GhcPass _) = EpAnn [AddEpAnn]

type instance XRnBracketOut  (GhcPass _) = NoExtField
type instance XTcBracketOut  (GhcPass _) = NoExtField

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

type instance XStatic        GhcPs = EpAnn [AddEpAnn]
type instance XStatic        GhcRn = NameSet
type instance XStatic        GhcTc = NameSet

type instance XTick          (GhcPass _) = NoExtField
type instance XBinTick       (GhcPass _) = NoExtField

type instance XPragE         (GhcPass _) = NoExtField

type instance XXExpr         GhcPs       = NoExtCon

-- See Note [Rebindable syntax and HsExpansion] below
type instance XXExpr         GhcRn       = HsExpansion (HsExpr GhcRn)
                                                       (HsExpr GhcRn)
type instance XXExpr         GhcTc       = XXExprGhcTc


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 XXExprGhcTc
  = WrapExpr {-# UNPACK #-} !(HsWrap HsExpr)
  | ExpansionExpr {-# UNPACK #-} !(HsExpansion (HsExpr GhcRn) (HsExpr GhcTc))

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

type instance XCHsFieldLabel (GhcPass _) = EpAnn AnnFieldLabel
type instance XXHsFieldLabel (GhcPass _) = NoExtCon

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

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

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)
_ OccName
uv) = forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc OccName
uv
ppr_expr (HsConLikeOut XConLikeOut (GhcPass p)
_ ConLike
c)  = forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc ConLike
c
ppr_expr (HsRecFld XRecFld (GhcPass p)
_ AmbiguousFieldOcc (GhcPass p)
f)      = forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc AmbiguousFieldOcc (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)
_ FastString
l)   = Char -> SDoc
char Char
'#' SDoc -> SDoc -> SDoc
<> forall a. Outputable a => a -> SDoc
ppr FastString
l
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)
_ XRec (GhcPass p) (HsExpr (GhcPass p))
e)         = SDoc -> SDoc
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) = [SDoc] -> SDoc
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 ([SDoc] -> SDoc
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 ([SDoc] -> SDoc
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)
_) = Char -> SDoc
char Char
'-' SDoc -> SDoc -> SDoc
<+> 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 ([SDoc] -> SDoc
hsep [String -> SDoc
text String
" \\ x_ ->", forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
op])
                       Int
4 ([SDoc] -> SDoc
hsep [SDoc
pp_expr, String -> SDoc
text String
"x_ )"])

    pp_infixly :: SDoc -> SDoc
pp_infixly SDoc
v = ([SDoc] -> SDoc
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 ([SDoc] -> SDoc
hsep [String -> SDoc
text String
"( \\ x_ ->", forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
op, String -> SDoc
text String
"x_"])
                       Int
4 (SDoc
pp_expr SDoc -> SDoc -> SDoc
<> SDoc
rparen)

    pp_infixly :: SDoc -> SDoc
pp_infixly SDoc
v = [SDoc] -> SDoc
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
    -- `Solo x`, not `(x)`
  | [Present XPresent (GhcPass p)
_ XRec (GhcPass p) (HsExpr (GhcPass p))
expr] <- [HsTupArg (GhcPass p)]
exprs
  , Boxity
Boxed <- Boxity
boxity
  = [SDoc] -> SDoc
hsep [String -> SDoc
text (Boxity -> Int -> String
mkTupleStr Boxity
Boxed 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 SDoc -> SDoc -> SDoc
<> forall {id}. [HsTupArg id] -> SDoc
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 {id}. [HsTupArg id] -> SDoc
punc [HsTupArg (GhcPass p)]
es forall a. a -> [a] -> [a]
: [HsTupArg (GhcPass p)] -> [SDoc]
ppr_tup_args [HsTupArg (GhcPass p)]
es

    punc :: [HsTupArg id] -> SDoc
punc (Present {} : [HsTupArg id]
_) = SDoc
comma SDoc -> SDoc -> SDoc
<> SDoc
space
    punc (Missing {} : [HsTupArg id]
_) = SDoc
comma
    punc (XTupArg {} : [HsTupArg id]
_) = SDoc
comma SDoc -> SDoc -> SDoc
<> SDoc
space
    punc []               = SDoc
empty

ppr_expr (ExplicitSum XExplicitSum (GhcPass p)
_ Int
alt Int
arity XRec (GhcPass p) (HsExpr (GhcPass p))
expr)
  = String -> SDoc
text String
"(#" SDoc -> SDoc -> SDoc
<+> Int -> SDoc
ppr_bars (Int
alt forall a. Num a => a -> a -> a
- Int
1) SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
expr SDoc -> SDoc -> SDoc
<+> Int -> SDoc
ppr_bars (Int
arity forall a. Num a => a -> a -> a
- Int
alt) SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"#)"
  where
    ppr_bars :: Int -> SDoc
ppr_bars Int
n = [SDoc] -> SDoc
hsep (forall a. Int -> a -> [a]
replicate Int
n (Char -> SDoc
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)
_ MatchGroup (GhcPass p) (XRec (GhcPass p) (HsExpr (GhcPass p)))
matches)
  = [SDoc] -> SDoc
sep [ [SDoc] -> SDoc
sep [String -> SDoc
text String
"\\case"],
          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 }))
  = [SDoc] -> SDoc
sep [ [SDoc] -> SDoc
sep [String -> SDoc
text String
"case", Int -> SDoc -> SDoc
nest Int
4 (forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
expr), PtrString -> SDoc
ptext (String -> PtrString
sLit 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 = String -> SDoc
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)
  = [SDoc] -> SDoc
sep [[SDoc] -> SDoc
hsep [String -> SDoc
text String
"if", Int -> SDoc -> SDoc
nest Int
2 (forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
e1), PtrString -> SDoc
ptext (String -> PtrString
sLit String
"then")],
         Int -> SDoc -> SDoc
nest Int
4 (forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
e2),
         String -> SDoc
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 (String -> SDoc
text String
"if") Int
3  ([SDoc] -> SDoc
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 SDoc
vbar Int
2 ([SDoc] -> SDoc
ppr_one [SDoc]
one_alt)
          where
            ppr_one :: [SDoc] -> SDoc
ppr_one [] = forall a. String -> a
panic String
"ppr_exp HsMultiIf"
            ppr_one (SDoc
h:[SDoc]
t) = SDoc -> Int -> SDoc -> SDoc
hang SDoc
h Int
2 ([SDoc] -> SDoc
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
                      , String -> SDoc
text String
"->" SDoc -> SDoc -> SDoc
<+> 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)
_ HsLocalBinds (GhcPass p)
binds expr :: XRec (GhcPass p) (HsExpr (GhcPass p))
expr@(L SrcSpanAnnA
_ (HsLet XLet (GhcPass p)
_ HsLocalBinds (GhcPass p)
_ XRec (GhcPass p) (HsExpr (GhcPass p))
_)))
  = [SDoc] -> SDoc
sep [SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"let") Int
2 ([SDoc] -> SDoc
hsep [forall (idL :: Pass) (idR :: Pass).
(OutputableBndrId idL, OutputableBndrId idR) =>
HsLocalBindsLR (GhcPass idL) (GhcPass idR) -> SDoc
pprBinds HsLocalBinds (GhcPass p)
binds, PtrString -> SDoc
ptext (String -> PtrString
sLit 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)
_ HsLocalBinds (GhcPass p)
binds XRec (GhcPass p) (HsExpr (GhcPass p))
expr)
  = [SDoc] -> SDoc
sep [SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
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 (String -> SDoc
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)
_ HsStmtContext (HsDoRn (GhcPass p))
do_or_list_comp (L SrcSpanAnnL
_ [GenLocated
   SrcSpanAnnA
   (StmtLR
      (GhcPass p)
      (GhcPass p)
      (GenLocated SrcSpanAnnA (HsExpr (GhcPass p))))]
stmts)) = forall (p :: Pass) body any.
(OutputableBndrId p, Outputable body,
 Anno (StmtLR (GhcPass p) (GhcPass p) body) ~ SrcSpanAnnA) =>
HsStmtContext any -> [LStmt (GhcPass p) body] -> SDoc
pprDo HsStmtContext (HsDoRn (GhcPass p))
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)
  = SDoc -> SDoc
brackets (([SDoc] -> SDoc) -> [SDoc] -> SDoc
pprDeeperList [SDoc] -> SDoc
fsep (SDoc -> [SDoc] -> [SDoc]
punctuate SDoc
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 (SDoc -> SDoc
braces ([SDoc] -> SDoc
fsep (SDoc -> [SDoc] -> [SDoc]
punctuate SDoc
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 (SDoc -> SDoc
braces ([SDoc] -> SDoc
fsep (SDoc -> [SDoc] -> [SDoc]
punctuate SDoc
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 -> Located (HsFieldLabel p)
gf_field = Located (HsFieldLabel (GhcPass p))
field })
  = forall a. Outputable a => a -> SDoc
ppr HsExpr (GhcPass p)
fexp SDoc -> SDoc -> SDoc
<> SDoc
dot SDoc -> SDoc -> SDoc
<> forall a. Outputable a => a -> SDoc
ppr Located (HsFieldLabel (GhcPass p))
field

ppr_expr (HsProjection { proj_flds :: forall p. HsExpr p -> NonEmpty (Located (HsFieldLabel p))
proj_flds = NonEmpty (Located (HsFieldLabel (GhcPass p)))
flds }) = SDoc -> SDoc
parens ([SDoc] -> SDoc
hcat (SDoc
dot forall a. a -> [a] -> [a]
: (SDoc -> [SDoc] -> [SDoc]
punctuate SDoc
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 (Located (HsFieldLabel (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) SDoc -> SDoc -> SDoc
<+> 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) = SDoc -> SDoc
brackets (forall a. Outputable a => a -> SDoc
ppr ArithSeqInfo (GhcPass p)
info)

ppr_expr (HsSpliceE XSpliceE (GhcPass p)
_ HsSplice (GhcPass p)
s)         = forall (p :: Pass).
OutputableBndrId p =>
HsSplice (GhcPass p) -> SDoc
pprSplice HsSplice (GhcPass p)
s
ppr_expr (HsBracket XBracket (GhcPass p)
_ HsBracket (GhcPass p)
b)         = forall (p :: Pass).
OutputableBndrId p =>
HsBracket (GhcPass p) -> SDoc
pprHsBracket HsBracket (GhcPass p)
b
ppr_expr (HsRnBracketOut XRnBracketOut (GhcPass p)
_ HsBracket (HsBracketRn (GhcPass p))
e []) = forall a. Outputable a => a -> SDoc
ppr HsBracket (HsBracketRn (GhcPass p))
e
ppr_expr (HsRnBracketOut XRnBracketOut (GhcPass p)
_ HsBracket (HsBracketRn (GhcPass p))
e [PendingRnSplice' (GhcPass p)]
ps) = forall a. Outputable a => a -> SDoc
ppr HsBracket (HsBracketRn (GhcPass p))
e SDoc -> SDoc -> SDoc
$$ String -> SDoc
text String
"pending(rn)" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr [PendingRnSplice' (GhcPass p)]
ps
ppr_expr (HsTcBracketOut XTcBracketOut (GhcPass p)
_ Maybe QuoteWrapper
_wrap HsBracket (HsBracketRn (GhcPass p))
e []) = forall a. Outputable a => a -> SDoc
ppr HsBracket (HsBracketRn (GhcPass p))
e
ppr_expr (HsTcBracketOut XTcBracketOut (GhcPass p)
_ Maybe QuoteWrapper
_wrap HsBracket (HsBracketRn (GhcPass p))
e [PendingTcSplice' (GhcPass p)]
ps) = forall a. Outputable a => a -> SDoc
ppr HsBracket (HsBracketRn (GhcPass p))
e SDoc -> SDoc -> SDoc
$$ String -> SDoc
text String
"pending(tc)" SDoc -> SDoc -> SDoc
<+> forall (p :: Pass).
IsPass p =>
((p ~ 'Typechecked) => SDoc) -> SDoc
pprIfTc @p (forall a. Outputable a => a -> SDoc
ppr [PendingTcSplice' (GhcPass p)]
ps)

ppr_expr (HsProc XProc (GhcPass p)
_ LPat (GhcPass p)
pat (L SrcSpan
_ (HsCmdTop XCmdTop (GhcPass p)
_ LHsCmd (GhcPass p)
cmd)))
  = [SDoc] -> SDoc
hsep [String -> SDoc
text String
"proc", forall a. Outputable a => a -> SDoc
ppr LPat (GhcPass p)
pat, PtrString -> SDoc
ptext (String -> PtrString
sLit 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)
  = [SDoc] -> SDoc
hsep [String -> SDoc
text String
"static", forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
e]

ppr_expr (HsTick XTick (GhcPass p)
_ CoreTickish
tickish XRec (GhcPass p) (HsExpr (GhcPass p))
exp)
  = SDoc -> SDoc -> SDoc
pprTicks (forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
exp) forall a b. (a -> b) -> a -> b
$
    forall a. Outputable a => a -> SDoc
ppr CoreTickish
tickish SDoc -> SDoc -> SDoc
<+> forall (p :: Pass).
OutputableBndrId p =>
LHsExpr (GhcPass p) -> SDoc
ppr_lexpr XRec (GhcPass p) (HsExpr (GhcPass p))
exp
ppr_expr (HsBinTick XBinTick (GhcPass p)
_ Int
tickIdTrue Int
tickIdFalse XRec (GhcPass p) (HsExpr (GhcPass p))
exp)
  = SDoc -> SDoc -> SDoc
pprTicks (forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
exp) forall a b. (a -> b) -> a -> b
$
    [SDoc] -> SDoc
hcat [String -> SDoc
text String
"bintick<",
          forall a. Outputable a => a -> SDoc
ppr Int
tickIdTrue,
          String -> SDoc
text String
",",
          forall a. Outputable a => a -> SDoc
ppr Int
tickIdFalse,
          String -> SDoc
text String
">(",
          forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsExpr (GhcPass p))
exp, String -> SDoc
text String
")"]

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 -> case XXExpr (GhcPass p)
x of
    WrapExpr (HsWrap HsWrapper
co_fn HsExpr GhcTc
e) -> HsWrapper -> (Bool -> SDoc) -> SDoc
pprHsWrapper HsWrapper
co_fn
      (\Bool
parens -> if Bool
parens then forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> SDoc
pprExpr HsExpr GhcTc
e else forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> SDoc
pprExpr HsExpr GhcTc
e)
    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 GhcT).

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 (HsConLikeOut XConLikeOut (GhcPass p)
_ ConLike
c)   = forall a. a -> Maybe a
Just (forall a. OutputableBndr a => a -> SDoc
pprInfixOcc (ConLike -> Name
conLikeName ConLike
c))
ppr_infix_expr (HsRecFld XRecFld (GhcPass p)
_ AmbiguousFieldOcc (GhcPass p)
f)       = forall a. a -> Maybe a
Just (forall a. OutputableBndr a => a -> SDoc
pprInfixOcc AmbiguousFieldOcc (GhcPass p)
f)
ppr_infix_expr (HsUnboundVar XUnboundVar (GhcPass p)
_ OccName
occ) = forall a. a -> Maybe a
Just (forall a. OutputableBndr a => a -> SDoc
pprInfixOcc OccName
occ)
ppr_infix_expr (XExpr XXExpr (GhcPass p)
x)            = case (forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p, XXExpr (GhcPass p)
x) of
#if __GLASGOW_HASKELL__ < 901
  (GhcPs, _)                              -> Nothing
#endif
  (GhcPass p
GhcRn, HsExpanded HsExpr GhcRn
a HsExpr GhcRn
_)                 -> forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> Maybe SDoc
ppr_infix_expr HsExpr GhcRn
a
  (GhcPass p
GhcTc, WrapExpr (HsWrap HsWrapper
_ HsExpr GhcTc
e))          -> forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> Maybe SDoc
ppr_infix_expr HsExpr GhcTc
e
  (GhcPass p
GhcTc, 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 HsExpr (GhcPass p)
_ = 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) 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 ([SDoc] -> SDoc
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)
      = String -> SDoc
text String
"@" SDoc -> SDoc -> SDoc
<> 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
  = (Bool -> SDoc) -> SDoc
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 = SDoc -> SDoc
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
p = HsExpr (GhcPass p) -> Bool
go
  where
    go :: HsExpr (GhcPass p) -> Bool
go (HsVar{})                      = Bool
False
    go (HsUnboundVar{})               = Bool
False
    go (HsConLikeOut{})               = 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
p HsLit (GhcPass p)
l
    go (HsOverLit XOverLitE (GhcPass p)
_ HsOverLit (GhcPass p)
ol)               = forall x. PprPrec -> HsOverLit x -> Bool
hsOverLitNeedsParens PprPrec
p HsOverLit (GhcPass p)
ol
    go (HsPar{})                      = Bool
False
    go (HsApp{})                      = PprPrec
p forall a. Ord a => a -> a -> Bool
>= PprPrec
appPrec
    go (HsAppType {})                 = PprPrec
p forall a. Ord a => a -> a -> Bool
>= PprPrec
appPrec
    go (OpApp{})                      = PprPrec
p forall a. Ord a => a -> a -> Bool
>= PprPrec
opPrec
    go (NegApp{})                     = PprPrec
p 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
p forall a. Ord a => a -> a -> Bool
>= PprPrec
appPrec
    go (ExplicitTuple{})              = Bool
False
    go (ExplicitSum{})                = Bool
False
    go (HsLam{})                      = PprPrec
p forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec
    go (HsLamCase{})                  = PprPrec
p forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec
    go (HsCase{})                     = PprPrec
p forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec
    go (HsIf{})                       = PprPrec
p forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec
    go (HsMultiIf{})                  = PprPrec
p forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec
    go (HsLet{})                      = PprPrec
p forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec
    go (HsDo XDo (GhcPass p)
_ HsStmtContext (HsDoRn (GhcPass p))
sc XRec (GhcPass p) [ExprLStmt (GhcPass p)]
_)
      | forall id. HsStmtContext id -> Bool
isComprehensionContext HsStmtContext (HsDoRn (GhcPass p))
sc     = Bool
False
      | Bool
otherwise                     = PprPrec
p forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec
    go (ExplicitList{})               = Bool
False
    go (RecordUpd{})                  = Bool
False
    go (ExprWithTySig{})              = PprPrec
p forall a. Ord a => a -> a -> Bool
>= PprPrec
sigPrec
    go (ArithSeq{})                   = Bool
False
    go (HsPragE{})                    = PprPrec
p forall a. Ord a => a -> a -> Bool
>= PprPrec
appPrec
    go (HsSpliceE{})                  = Bool
False
    go (HsBracket{})                  = Bool
False
    go (HsRnBracketOut{})             = Bool
False
    go (HsTcBracketOut{})             = Bool
False
    go (HsProc{})                     = PprPrec
p forall a. Ord a => a -> a -> Bool
> PprPrec
topPrec
    go (HsStatic{})                   = PprPrec
p forall a. Ord a => a -> a -> Bool
>= PprPrec
appPrec
    go (HsTick XTick (GhcPass p)
_ CoreTickish
_ (L SrcSpanAnnA
_ HsExpr (GhcPass p)
e))           = HsExpr (GhcPass p) -> Bool
go HsExpr (GhcPass p)
e
    go (HsBinTick XBinTick (GhcPass p)
_ Int
_ Int
_ (L SrcSpanAnnA
_ HsExpr (GhcPass p)
e))      = HsExpr (GhcPass p) -> Bool
go HsExpr (GhcPass p)
e
    go (RecordCon{})                  = Bool
False
    go (HsRecFld{})                   = Bool
False
    go (HsProjection{})               = Bool
True
    go (HsGetField{})                 = Bool
False
    go (XExpr XXExpr (GhcPass p)
x)
      | GhcPass p
GhcTc <- forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p
      = case XXExpr (GhcPass p)
x of
          WrapExpr      (HsWrap HsWrapper
_ HsExpr GhcTc
e)     -> HsExpr (GhcPass p) -> Bool
go HsExpr GhcTc
e
          ExpansionExpr (HsExpanded HsExpr GhcRn
a HsExpr GhcTc
_) -> forall (p :: Pass).
IsPass p =>
PprPrec -> HsExpr (GhcPass p) -> Bool
hsExprNeedsParens PprPrec
p HsExpr GhcRn
a
      | GhcPass p
GhcRn <- forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p
      = case XXExpr (GhcPass p)
x of HsExpanded HsExpr GhcRn
a HsExpr GhcRn
_ -> forall (p :: Pass).
IsPass p =>
PprPrec -> HsExpr (GhcPass p) -> Bool
hsExprNeedsParens PprPrec
p HsExpr GhcRn
a
#if __GLASGOW_HASKELL__ <= 900
      | otherwise
      = True
#endif


-- | @'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 p. XPar p -> LHsExpr p -> HsExpr p
HsPar forall a. EpAnn a
noAnn 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)
_ LHsExpr (GhcPass p)
e)) = 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)
_ (L SrcSpanAnnA
_ HsExpr (GhcPass p)
e)) = 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 (HsConLikeOut {}) = Bool
True
isAtomicHsExpr (HsLit {})        = Bool
True
isAtomicHsExpr (HsOverLit {})    = Bool
True
isAtomicHsExpr (HsIPVar {})      = Bool
True
isAtomicHsExpr (HsOverLabel {})  = Bool
True
isAtomicHsExpr (HsUnboundVar {}) = Bool
True
isAtomicHsExpr (HsRecFld{})      = Bool
True
isAtomicHsExpr (XExpr XXExpr (GhcPass p)
x)
  | GhcPass p
GhcTc <- forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p          = case XXExpr (GhcPass p)
x of
      WrapExpr      (HsWrap HsWrapper
_ HsExpr GhcTc
e)     -> forall (p :: Pass). IsPass p => HsExpr (GhcPass p) -> Bool
isAtomicHsExpr HsExpr GhcTc
e
      ExpansionExpr (HsExpanded HsExpr GhcRn
a HsExpr GhcTc
_) -> forall (p :: Pass). IsPass p => HsExpr (GhcPass p) -> Bool
isAtomicHsExpr HsExpr GhcRn
a
  | GhcPass p
GhcRn <- forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p          = case XXExpr (GhcPass p)
x of
      HsExpanded HsExpr GhcRn
a HsExpr GhcRn
_         -> forall (p :: Pass). IsPass p => HsExpr (GhcPass p) -> Bool
isAtomicHsExpr HsExpr GhcRn
a
isAtomicHsExpr HsExpr (GhcPass p)
_                 = Bool
False

instance Outputable (HsPragE (GhcPass p)) where
  ppr :: HsPragE (GhcPass p) -> SDoc
ppr (HsPragSCC XSCC (GhcPass p)
_ SourceText
st (StringLiteral SourceText
stl FastString
lbl Maybe RealSrcSpan
_)) =
    SourceText -> SDoc -> SDoc
pprWithSourceText SourceText
st (String -> SDoc
text String
"{-# SCC")
     -- no doublequotes if stl empty, for the case where the SCC was written
     -- without quotes.
    SDoc -> SDoc -> SDoc
<+> SourceText -> SDoc -> SDoc
pprWithSourceText SourceText
stl (FastString -> SDoc
ftext FastString
lbl) SDoc -> SDoc -> SDoc
<+> String -> SDoc
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 affected by RS into the
appropriate desugared form, but **annotated with the original expression**.

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.

---

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 (condition, true branch, false branch 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 in an XExpr: XExpr (HsExpanded <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 a b
  = HsExpanded a b
  deriving HsExpansion a b -> DataType
HsExpansion a b -> 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 {a} {b}. (Data a, Data b) => Typeable (HsExpansion a b)
forall a b. (Data a, Data b) => HsExpansion a b -> DataType
forall a b. (Data a, Data b) => HsExpansion a b -> Constr
forall a b.
(Data a, Data b) =>
(forall b. Data b => b -> b) -> HsExpansion a b -> HsExpansion a b
forall a b u.
(Data a, Data b) =>
Int -> (forall d. Data d => d -> u) -> HsExpansion a b -> u
forall a b u.
(Data a, Data b) =>
(forall d. Data d => d -> u) -> HsExpansion a b -> [u]
forall a b r r'.
(Data a, Data b) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> HsExpansion a b -> r
forall a b r r'.
(Data a, Data b) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> HsExpansion a b -> r
forall a b (m :: * -> *).
(Data a, Data b, Monad m) =>
(forall d. Data d => d -> m d)
-> HsExpansion a b -> m (HsExpansion a b)
forall a b (m :: * -> *).
(Data a, Data b, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> HsExpansion a b -> m (HsExpansion a b)
forall a b (c :: * -> *).
(Data a, Data b) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (HsExpansion a b)
forall a b (c :: * -> *).
(Data a, Data b) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> HsExpansion a b -> c (HsExpansion a b)
forall a b (t :: * -> *) (c :: * -> *).
(Data a, Data b, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (HsExpansion a b))
forall a b (t :: * -> * -> *) (c :: * -> *).
(Data a, Data b, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (HsExpansion a b))
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (HsExpansion a b)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> HsExpansion a b -> c (HsExpansion a b)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (HsExpansion a b))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> HsExpansion a b -> m (HsExpansion a b)
$cgmapMo :: forall a b (m :: * -> *).
(Data a, Data b, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> HsExpansion a b -> m (HsExpansion a b)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> HsExpansion a b -> m (HsExpansion a b)
$cgmapMp :: forall a b (m :: * -> *).
(Data a, Data b, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> HsExpansion a b -> m (HsExpansion a b)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> HsExpansion a b -> m (HsExpansion a b)
$cgmapM :: forall a b (m :: * -> *).
(Data a, Data b, Monad m) =>
(forall d. Data d => d -> m d)
-> HsExpansion a b -> m (HsExpansion a b)
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> HsExpansion a b -> u
$cgmapQi :: forall a b u.
(Data a, Data b) =>
Int -> (forall d. Data d => d -> u) -> HsExpansion a b -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> HsExpansion a b -> [u]
$cgmapQ :: forall a b u.
(Data a, Data b) =>
(forall d. Data d => d -> u) -> HsExpansion a b -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> HsExpansion a b -> r
$cgmapQr :: forall a b r r'.
(Data a, Data b) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> HsExpansion a b -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> HsExpansion a b -> r
$cgmapQl :: forall a b r r'.
(Data a, Data b) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> HsExpansion a b -> r
gmapT :: (forall b. Data b => b -> b) -> HsExpansion a b -> HsExpansion a b
$cgmapT :: forall a b.
(Data a, Data b) =>
(forall b. Data b => b -> b) -> HsExpansion a b -> HsExpansion a b
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (HsExpansion a b))
$cdataCast2 :: forall a b (t :: * -> * -> *) (c :: * -> *).
(Data a, Data b, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (HsExpansion a b))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (HsExpansion a b))
$cdataCast1 :: forall a b (t :: * -> *) (c :: * -> *).
(Data a, Data b, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (HsExpansion a b))
dataTypeOf :: HsExpansion a b -> DataType
$cdataTypeOf :: forall a b. (Data a, Data b) => HsExpansion a b -> DataType
toConstr :: HsExpansion a b -> Constr
$ctoConstr :: forall a b. (Data a, Data b) => HsExpansion a b -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (HsExpansion a b)
$cgunfold :: forall a b (c :: * -> *).
(Data a, Data b) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (HsExpansion a b)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> HsExpansion a b -> c (HsExpansion a b)
$cgfoldl :: forall a b (c :: * -> *).
(Data a, Data b) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> HsExpansion a b -> c (HsExpansion a b)
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
a b
b) = SDoc -> SDoc -> SDoc
ifPprDebug ([SDoc] -> SDoc
vcat [forall a. Outputable a => a -> SDoc
ppr a
a, forall a. Outputable a => a -> SDoc
ppr b
b]) (forall a. Outputable a => a -> SDoc
ppr a
a)


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

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 = EpAnn AnnsLet
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 = NoExtCon
type instance XXCmd       GhcRn = NoExtCon
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

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

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)
_ XRec (GhcPass p) (HsCmd (GhcPass p))
c) = SDoc -> SDoc
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 ([SDoc] -> SDoc
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)
  = [SDoc] -> SDoc
sep [ [SDoc] -> SDoc
sep [String -> SDoc
text String
"case", Int -> SDoc -> SDoc
nest Int
4 (forall a. Outputable a => a -> SDoc
ppr LHsExpr (GhcPass p)
expr), PtrString -> SDoc
ptext (String -> PtrString
sLit 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)
_ MatchGroup (GhcPass p) (XRec (GhcPass p) (HsCmd (GhcPass p)))
matches)
  = [SDoc] -> SDoc
sep [ String -> SDoc
text String
"\\case", 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)
  = [SDoc] -> SDoc
sep [[SDoc] -> SDoc
hsep [String -> SDoc
text String
"if", Int -> SDoc -> SDoc
nest Int
2 (forall a. Outputable a => a -> SDoc
ppr LHsExpr (GhcPass p)
e), PtrString -> SDoc
ptext (String -> PtrString
sLit String
"then")],
         Int -> SDoc -> SDoc
nest Int
4 (forall a. Outputable a => a -> SDoc
ppr XRec (GhcPass p) (HsCmd (GhcPass p))
ct),
         String -> SDoc
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)
_ HsLocalBinds (GhcPass p)
binds cmd :: XRec (GhcPass p) (HsCmd (GhcPass p))
cmd@(L SrcSpanAnnA
_ (HsCmdLet {})))
  = [SDoc] -> SDoc
sep [SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"let") Int
2 ([SDoc] -> SDoc
hsep [forall (idL :: Pass) (idR :: Pass).
(OutputableBndrId idL, OutputableBndrId idR) =>
HsLocalBindsLR (GhcPass idL) (GhcPass idR) -> SDoc
pprBinds HsLocalBinds (GhcPass p)
binds, PtrString -> SDoc
ptext (String -> PtrString
sLit 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)
_ HsLocalBinds (GhcPass p)
binds XRec (GhcPass p) (HsCmd (GhcPass p))
cmd)
  = [SDoc] -> SDoc
sep [SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
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 (String -> SDoc
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 any.
(OutputableBndrId p, Outputable body,
 Anno (StmtLR (GhcPass p) (GhcPass p) body) ~ SrcSpanAnnA) =>
HsStmtContext any -> [LStmt (GhcPass p) body] -> SDoc
pprDo forall p. HsStmtContext p
ArrowExpr [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)
  = [SDoc] -> SDoc
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)
  = [SDoc] -> SDoc
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)
  = [SDoc] -> SDoc
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)
  = [SDoc] -> SDoc
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
_ (HsVar XVar (GhcPass p)
_ (L Anno (IdGhcP p)
_ IdGhcP p
v))) LexicalFixity
_ (Just Fixity
_) [LHsCmdTop (GhcPass p)
arg1, LHsCmdTop (GhcPass p)
arg2])
  = 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 ([SDoc] -> SDoc
sep [ forall a. OutputableBndr a => a -> SDoc
pprInfixOcc IdGhcP p
v
                                         , forall (p :: Pass).
OutputableBndrId p =>
HsCmdTop (GhcPass p) -> SDoc
pprCmdArg (forall l e. GenLocated l e -> e
unLoc LHsCmdTop (GhcPass p)
arg2)])
ppr_cmd (HsCmdArrForm XCmdArrForm (GhcPass p)
_ (L SrcSpanAnnA
_ (HsVar XVar (GhcPass p)
_ (L Anno (IdGhcP p)
_ IdGhcP p
v))) LexicalFixity
Infix Maybe Fixity
_    [LHsCmdTop (GhcPass p)
arg1, LHsCmdTop (GhcPass p)
arg2])
  = 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 ([SDoc] -> SDoc
sep [ forall a. OutputableBndr a => a -> SDoc
pprInfixOcc IdGhcP p
v
                                         , forall (p :: Pass).
OutputableBndrId p =>
HsCmdTop (GhcPass p) -> SDoc
pprCmdArg (forall l e. GenLocated l e -> e
unLoc LHsCmdTop (GhcPass p)
arg2)])
ppr_cmd (HsCmdArrForm XCmdArrForm (GhcPass p)
_ (L SrcSpanAnnA
_ (HsConLikeOut XConLikeOut (GhcPass p)
_ ConLike
c)) LexicalFixity
_ (Just Fixity
_) [LHsCmdTop (GhcPass p)
arg1, LHsCmdTop (GhcPass p)
arg2])
  = 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 ([SDoc] -> SDoc
sep [ forall a. OutputableBndr a => a -> SDoc
pprInfixOcc (ConLike -> Name
conLikeName ConLike
c)
                                         , forall (p :: Pass).
OutputableBndrId p =>
HsCmdTop (GhcPass p) -> SDoc
pprCmdArg (forall l e. GenLocated l e -> e
unLoc LHsCmdTop (GhcPass p)
arg2)])
ppr_cmd (HsCmdArrForm XCmdArrForm (GhcPass p)
_ (L SrcSpanAnnA
_ (HsConLikeOut XConLikeOut (GhcPass p)
_ ConLike
c)) LexicalFixity
Infix Maybe Fixity
_    [LHsCmdTop (GhcPass p)
arg1, LHsCmdTop (GhcPass p)
arg2])
  = 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 ([SDoc] -> SDoc
sep [ forall a. OutputableBndr a => a -> SDoc
pprInfixOcc (ConLike -> Name
conLikeName ConLike
c)
                                         , forall (p :: Pass).
OutputableBndrId p =>
HsCmdTop (GhcPass p) -> SDoc
pprCmdArg (forall l e. GenLocated l e -> e
unLoc LHsCmdTop (GhcPass p)
arg2)])
ppr_cmd (HsCmdArrForm XCmdArrForm (GhcPass p)
_ LHsExpr (GhcPass p)
op LexicalFixity
_ Maybe Fixity
_ [LHsCmdTop (GhcPass p)]
args)
  = SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"(|" SDoc -> SDoc -> SDoc
<+> forall (p :: Pass).
OutputableBndrId p =>
LHsExpr (GhcPass p) -> SDoc
ppr_lexpr LHsExpr (GhcPass p)
op)
         Int
4 ([SDoc] -> SDoc
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) SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"|)")
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
_ -> SDoc -> SDoc
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 = NoExtField
type instance XMG         GhcRn b = NoExtField
type instance XMG         GhcTc b = MatchGroupTc

type instance XXMatchGroup (GhcPass _) b = NoExtCon

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

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. 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 _) _ = NoExtCon

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 = NoExtCon

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 }
    = [SDoc] -> SDoc
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
 = [SDoc] -> SDoc
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 (NoGhcTc p)
m_ctxt = HsMatchContext (NoGhcTc (GhcPass idR))
ctxt, m_grhss :: forall p body. Match p body -> GRHSs p body
m_grhss = GRHSs (GhcPass idR) body
grhss })
  = [SDoc] -> SDoc
sep [ [SDoc] -> SDoc
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 (NoGhcTc (GhcPass idR))
ctxt GRHSs (GhcPass idR) body
grhss) ]
  where
    (SDoc
herald, [GenLocated SrcSpanAnnA (Pat (GhcPass idR))]
other_pats)
        = case HsMatchContext (NoGhcTc (GhcPass idR))
ctxt of
            FunRhs {mc_fun :: forall p. HsMatchContext p -> LIdP 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
                -> ASSERT(null pats)     -- A strict variable binding
                   (Char -> SDoc
char Char
'!'SDoc -> SDoc -> SDoc
<>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 -> (SDoc -> SDoc
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
                                     SDoc -> SDoc -> SDoc
<+> forall a. OutputableBndr a => a -> SDoc
pprInfixOcc IdGhcP (NoGhcTcPass idR)
fun
                                     SDoc -> SDoc -> SDoc
<+> 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 (NoGhcTc (GhcPass idR))
ctxt SDoc -> SDoc -> SDoc
$$ forall a. Outputable a => a -> SDoc
ppr [LPat (GhcPass idR)]
pats)

            HsMatchContext (NoGhcTc (GhcPass idR))
LambdaExpr -> (Char -> SDoc
char Char
'\\', [LPat (GhcPass idR)]
pats)

            HsMatchContext (NoGhcTc (GhcPass idR))
_ -> case [LPat (GhcPass idR)]
pats of
                   []    -> (SDoc
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 (NoGhcTc (GhcPass idR))
ctxt SDoc -> SDoc -> SDoc
$$ 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)
  = [SDoc] -> SDoc
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
 SDoc -> SDoc -> SDoc
$$ Bool -> SDoc -> SDoc
ppUnless (forall a b. HsLocalBindsLR a b -> Bool
eqEmptyLocalBinds HsLocalBinds (GhcPass idR)
binds)
      (String -> SDoc
text String
"where" SDoc -> SDoc -> SDoc
$$ 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)
 = [SDoc] -> SDoc
sep [SDoc
vbar SDoc -> SDoc -> SDoc
<+> 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 SDoc -> SDoc -> SDoc
<+> 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) = String -> SDoc
text String
"GrhsAnn" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr Maybe EpaLocation
v SDoc -> SDoc -> SDoc
<+> 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 = NoExtCon

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

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

type instance ApplicativeArgStmCtxPass _ = GhcRn

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)
_)
  = SDoc -> SDoc
whenPprDebug (String -> SDoc
text String
"[last]") SDoc -> SDoc -> SDoc
<+>
      (case Maybe Bool
m_dollar_stripped of
        Just Bool
True -> String -> SDoc
text String
"return $"
        Just Bool
False -> String -> SDoc
text String
"return"
        Maybe Bool
Nothing -> SDoc
empty) SDoc -> SDoc -> SDoc
<+>
      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)      = [SDoc] -> SDoc
hsep [String -> SDoc
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)
_) = [SDoc] -> SDoc
sep (SDoc -> [SDoc] -> [SDoc]
punctuate (String -> SDoc
text String
" | ") (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [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 })
  = [SDoc] -> SDoc
sep forall a b. (a -> b) -> a -> b
$ SDoc -> [SDoc] -> [SDoc]
punctuate SDoc
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 })
  = String -> SDoc
text String
"rec" SDoc -> SDoc -> SDoc
<+>
    [SDoc] -> SDoc
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)
         , SDoc -> SDoc
whenPprDebug ([SDoc] -> SDoc
vcat [ String -> SDoc
text String
"rec_ids=" SDoc -> SDoc -> SDoc
<> forall a. Outputable a => a -> SDoc
ppr [IdP (GhcPass idR)]
rec_ids
                            , String -> SDoc
text String
"later_ids=" SDoc -> SDoc -> SDoc
<> 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 = [SDoc] -> SDoc
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)
_ HsStmtContext (ApplicativeArgStmCtxPass (GhcPass idL))
_) =
     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 = [SDoc] -> SDoc
sep (SDoc -> [SDoc] -> [SDoc]
punctuate (String -> SDoc
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
       SDoc -> SDoc
whenPprDebug (if forall a. Maybe a -> Bool
isJust Maybe (SyntaxExpr (GhcPass idR))
mb_join then String -> SDoc
text String
"[join]" else SDoc
empty) SDoc -> SDoc -> SDoc
<+>
       (if forall a. [a] -> Int -> Bool
lengthAtLeast [(SyntaxExpr (GhcPass idR), ApplicativeArg (GhcPass idL))]
args Int
2 then SDoc -> SDoc
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 = [SDoc] -> SDoc
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 HsStmtContext (ApplicativeArgStmCtxPass (GhcPass idL))
ctxt) =
     forall a. Outputable a => a -> SDoc
ppr LPat (GhcPass idL)
pat SDoc -> SDoc -> SDoc
<+>
     String -> SDoc
text String
"<-" SDoc -> SDoc -> SDoc
<+>
     forall (p :: Pass) body any.
(OutputableBndrId p, Outputable body,
 Anno (StmtLR (GhcPass p) (GhcPass p) body) ~ SrcSpanAnnA) =>
HsStmtContext any -> [LStmt (GhcPass p) body] -> SDoc
pprDo HsStmtContext (ApplicativeArgStmCtxPass (GhcPass idL))
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
  = [SDoc] -> SDoc
sep [ String -> SDoc
text String
"then" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
whenPprDebug (SDoc -> SDoc
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
  = [SDoc] -> SDoc
sep [ String -> SDoc
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
  = [SDoc] -> SDoc
sep [ String -> SDoc
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 (PtrString -> SDoc
ptext (String -> PtrString
sLit String
"using") SDoc -> SDoc -> SDoc
<+> 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  = SDoc
empty
pprBy (Just body
e) = String -> SDoc
text String
"by" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr body
e

pprDo :: (OutputableBndrId p, Outputable body,
                 Anno (StmtLR (GhcPass p) (GhcPass p) body) ~ SrcSpanAnnA
         )
      => HsStmtContext any -> [LStmt (GhcPass p) body] -> SDoc
pprDo :: forall (p :: Pass) body any.
(OutputableBndrId p, Outputable body,
 Anno (StmtLR (GhcPass p) (GhcPass p) body) ~ SrcSpanAnnA) =>
HsStmtContext any -> [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 SDoc -> SDoc -> SDoc
<> String -> SDoc
text String
"do"  SDoc -> SDoc -> SDoc
<+> 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 HsStmtContext any
GhciStmtCtxt  [LStmt (GhcPass p) body]
stmts = String -> SDoc
text String
"do"  SDoc -> SDoc -> SDoc
<+> 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 HsStmtContext any
ArrowExpr     [LStmt (GhcPass p) body]
stmts = String -> SDoc
text String
"do"  SDoc -> SDoc -> SDoc
<+> 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 SDoc -> SDoc -> SDoc
<> String -> SDoc
text String
"mdo"  SDoc -> SDoc -> SDoc
<+> 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 HsStmtContext any
ListComp      [LStmt (GhcPass p) body]
stmts = SDoc -> SDoc
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 HsStmtContext any
MonadComp     [LStmt (GhcPass p) body]
stmts = SDoc -> SDoc
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 HsStmtContext any
_             [LStmt (GhcPass p) body]
_     = forall a. String -> a
panic String
"pprDo" -- PatGuard, ParStmtCxt

ppr_module_name_prefix :: Maybe ModuleName -> SDoc
ppr_module_name_prefix :: Maybe ModuleName -> SDoc
ppr_module_name_prefix = \case
  Maybe ModuleName
Nothing -> SDoc
empty
  Just ModuleName
module_name -> forall a. Outputable a => a -> SDoc
ppr ModuleName
module_name SDoc -> SDoc -> SDoc
<> Char -> SDoc
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 [SDoc] -> SDoc
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 SDoc -> SDoc -> SDoc
<+> SDoc
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
*                                                                      *
************************************************************************
-}

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

type instance XTypedSplice   (GhcPass _) = EpAnn [AddEpAnn]
type instance XUntypedSplice (GhcPass _) = EpAnn [AddEpAnn]
type instance XQuasiQuote    (GhcPass _) = NoExtField
type instance XSpliced       (GhcPass _) = NoExtField
type instance XXSplice       GhcPs       = NoExtCon
type instance XXSplice       GhcRn       = NoExtCon
type instance XXSplice       GhcTc       = HsSplicedT

-- 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. 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]

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

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

{-
Note [Pending Splices]
~~~~~~~~~~~~~~~~~~~~~~
When we rename an untyped bracket, we name and lift out all the nested
splices, so that when the typechecker hits the bracket, it can
typecheck those nested splices without having to walk over the untyped
bracket code.  So for example
    [| f $(g x) |]
looks like

    HsBracket (HsApp (HsVar "f") (HsSpliceE _ (g x)))

which the renamer rewrites to

    HsRnBracketOut (HsApp (HsVar f) (HsSpliceE sn (g x)))
                   [PendingRnSplice UntypedExpSplice sn (g x)]

* The 'sn' is the Name of the splice point, the SplicePointName

* The PendingRnExpSplice gives the splice that splice-point name maps to;
  and the typechecker can now conveniently find these sub-expressions

* The other copy of the splice, in the second argument of HsSpliceE
                                in the renamed first arg of HsRnBracketOut
  is used only for pretty printing

There are four varieties of pending splices generated by the renamer,
distinguished by their UntypedSpliceFlavour

 * Pending expression splices (UntypedExpSplice), e.g.,
       [|$(f x) + 2|]

   UntypedExpSplice is also used for
     * quasi-quotes, where the pending expression expands to
          $(quoter "...blah...")
       (see GHC.Rename.Splice.makePending, HsQuasiQuote case)

     * cross-stage lifting, where the pending expression expands to
          $(lift x)
       (see GHC.Rename.Splice.checkCrossStageLifting)

 * Pending pattern splices (UntypedPatSplice), e.g.,
       [| \$(f x) -> x |]

 * Pending type splices (UntypedTypeSplice), e.g.,
       [| f :: $(g x) |]

 * Pending declaration (UntypedDeclSplice), e.g.,
       [| let $(f x) in ... |]

There is a fifth variety of pending splice, which is generated by the type
checker:

  * Pending *typed* expression splices, (PendingTcSplice), e.g.,
        [||1 + $$(f 2)||]

It would be possible to eliminate HsRnBracketOut and use HsBracketOut for the
output of the renamer. However, when pretty printing the output of the renamer,
e.g., in a type error message, we *do not* want to print out the pending
splices. In contrast, when pretty printing the output of the type checker, we
*do* want to print the pending splices. So splitting them up seems to make
sense, although I hate to add another constructor to HsExpr.
-}

instance OutputableBndrId p
       => Outputable (HsSplicedThing (GhcPass p)) where
  ppr :: HsSplicedThing (GhcPass p) -> SDoc
ppr (HsSplicedExpr HsExpr (GhcPass p)
e) = forall (p :: Pass).
OutputableBndrId p =>
HsExpr (GhcPass p) -> SDoc
ppr_expr HsExpr (GhcPass p)
e
  ppr (HsSplicedTy   HsType (GhcPass p)
t) = forall a. Outputable a => a -> SDoc
ppr HsType (GhcPass p)
t
  ppr (HsSplicedPat  Pat (GhcPass p)
p) = forall a. Outputable a => a -> SDoc
ppr Pat (GhcPass p)
p

instance (OutputableBndrId p) => Outputable (HsSplice (GhcPass p)) where
  ppr :: HsSplice (GhcPass p) -> SDoc
ppr HsSplice (GhcPass p)
s = forall (p :: Pass).
OutputableBndrId p =>
HsSplice (GhcPass p) -> SDoc
pprSplice HsSplice (GhcPass p)
s

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 = SDoc -> SDoc
angleBrackets (forall a. Outputable a => a -> SDoc
ppr Name
n SDoc -> SDoc -> SDoc
<> SDoc
comma SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr (forall (p :: Pass). LHsExpr (GhcPass p) -> LHsExpr (GhcPass p)
stripParensLHsExpr LHsExpr (GhcPass p)
e))

pprSpliceDecl ::  (OutputableBndrId p)
          => HsSplice (GhcPass p) -> SpliceExplicitFlag -> SDoc
pprSpliceDecl :: forall (p :: Pass).
OutputableBndrId p =>
HsSplice (GhcPass p) -> SpliceExplicitFlag -> SDoc
pprSpliceDecl e :: HsSplice (GhcPass p)
e@HsQuasiQuote{} SpliceExplicitFlag
_ = forall (p :: Pass).
OutputableBndrId p =>
HsSplice (GhcPass p) -> SDoc
pprSplice HsSplice (GhcPass p)
e
pprSpliceDecl HsSplice (GhcPass p)
e SpliceExplicitFlag
ExplicitSplice   = String -> SDoc
text String
"$" SDoc -> SDoc -> SDoc
<> forall (p :: Pass).
OutputableBndrId p =>
HsSplice (GhcPass p) -> SDoc
ppr_splice_decl HsSplice (GhcPass p)
e
pprSpliceDecl HsSplice (GhcPass p)
e SpliceExplicitFlag
ImplicitSplice   = forall (p :: Pass).
OutputableBndrId p =>
HsSplice (GhcPass p) -> SDoc
ppr_splice_decl HsSplice (GhcPass p)
e

ppr_splice_decl :: (OutputableBndrId p)
                => HsSplice (GhcPass p) -> SDoc
ppr_splice_decl :: forall (p :: Pass).
OutputableBndrId p =>
HsSplice (GhcPass p) -> SDoc
ppr_splice_decl (HsUntypedSplice XUntypedSplice (GhcPass p)
_ SpliceDecoration
_ IdP (GhcPass p)
n LHsExpr (GhcPass p)
e) = forall (p :: Pass).
OutputableBndrId p =>
SDoc -> IdP (GhcPass p) -> LHsExpr (GhcPass p) -> SDoc -> SDoc
ppr_splice SDoc
empty IdP (GhcPass p)
n LHsExpr (GhcPass p)
e SDoc
empty
ppr_splice_decl HsSplice (GhcPass p)
e = forall (p :: Pass).
OutputableBndrId p =>
HsSplice (GhcPass p) -> SDoc
pprSplice HsSplice (GhcPass p)
e

pprSplice :: forall p. (OutputableBndrId p) => HsSplice (GhcPass p) -> SDoc
pprSplice :: forall (p :: Pass).
OutputableBndrId p =>
HsSplice (GhcPass p) -> SDoc
pprSplice (HsTypedSplice XTypedSplice (GhcPass p)
_ SpliceDecoration
DollarSplice IdP (GhcPass p)
n LHsExpr (GhcPass p)
e)
  = forall (p :: Pass).
OutputableBndrId p =>
SDoc -> IdP (GhcPass p) -> LHsExpr (GhcPass p) -> SDoc -> SDoc
ppr_splice (String -> SDoc
text String
"$$") IdP (GhcPass p)
n LHsExpr (GhcPass p)
e SDoc
empty
pprSplice (HsTypedSplice XTypedSplice (GhcPass p)
_ SpliceDecoration
BareSplice IdP (GhcPass p)
_ LHsExpr (GhcPass p)
_ )
  = forall a. String -> a
panic String
"Bare typed splice"  -- impossible
pprSplice (HsUntypedSplice XUntypedSplice (GhcPass p)
_ SpliceDecoration
DollarSplice IdP (GhcPass p)
n LHsExpr (GhcPass p)
e)
  = forall (p :: Pass).
OutputableBndrId p =>
SDoc -> IdP (GhcPass p) -> LHsExpr (GhcPass p) -> SDoc -> SDoc
ppr_splice (String -> SDoc
text String
"$")  IdP (GhcPass p)
n LHsExpr (GhcPass p)
e SDoc
empty
pprSplice (HsUntypedSplice XUntypedSplice (GhcPass p)
_ SpliceDecoration
BareSplice IdP (GhcPass p)
n LHsExpr (GhcPass p)
e)
  = forall (p :: Pass).
OutputableBndrId p =>
SDoc -> IdP (GhcPass p) -> LHsExpr (GhcPass p) -> SDoc -> SDoc
ppr_splice SDoc
empty  IdP (GhcPass p)
n LHsExpr (GhcPass p)
e SDoc
empty
pprSplice (HsQuasiQuote XQuasiQuote (GhcPass p)
_ IdP (GhcPass p)
n IdP (GhcPass p)
q SrcSpan
_ FastString
s)      = forall p. OutputableBndr p => p -> p -> FastString -> SDoc
ppr_quasi IdP (GhcPass p)
n IdP (GhcPass p)
q FastString
s
pprSplice (HsSpliced XSpliced (GhcPass p)
_ ThModFinalizers
_ HsSplicedThing (GhcPass p)
thing)         = forall a. Outputable a => a -> SDoc
ppr HsSplicedThing (GhcPass p)
thing
pprSplice (XSplice XXSplice (GhcPass p)
x)                   = case forall (p :: Pass). IsPass p => GhcPass p
ghcPass @p of
#if __GLASGOW_HASKELL__ < 811
                                            GhcPs -> noExtCon x
                                            GhcRn -> noExtCon x
#endif
                                            GhcPass p
GhcTc -> case XXSplice (GhcPass p)
x of
                                                       HsSplicedT DelayedSplice
_ -> String -> SDoc
text String
"Unevaluated typed splice"

ppr_quasi :: OutputableBndr p => p -> p -> FastString -> SDoc
ppr_quasi :: forall p. OutputableBndr p => p -> p -> FastString -> SDoc
ppr_quasi p
n p
quoter FastString
quote = SDoc -> SDoc
whenPprDebug (SDoc -> SDoc
brackets (forall a. Outputable a => a -> SDoc
ppr p
n)) SDoc -> SDoc -> SDoc
<>
                           Char -> SDoc
char Char
'[' SDoc -> SDoc -> SDoc
<> forall a. Outputable a => a -> SDoc
ppr p
quoter SDoc -> SDoc -> SDoc
<> SDoc
vbar SDoc -> SDoc -> SDoc
<>
                           forall a. Outputable a => a -> SDoc
ppr FastString
quote SDoc -> SDoc -> SDoc
<> String -> SDoc
text String
"|]"

ppr_splice :: (OutputableBndrId p)
           => SDoc -> (IdP (GhcPass p)) -> LHsExpr (GhcPass p) -> SDoc -> SDoc
ppr_splice :: forall (p :: Pass).
OutputableBndrId p =>
SDoc -> IdP (GhcPass p) -> LHsExpr (GhcPass p) -> SDoc -> SDoc
ppr_splice SDoc
herald IdP (GhcPass p)
n LHsExpr (GhcPass p)
e SDoc
trail
    = SDoc
herald SDoc -> SDoc -> SDoc
<> SDoc -> SDoc
whenPprDebug (SDoc -> SDoc
brackets (forall a. Outputable a => a -> SDoc
ppr IdP (GhcPass p)
n)) SDoc -> SDoc -> SDoc
<> forall a. Outputable a => a -> SDoc
ppr LHsExpr (GhcPass p)
e SDoc -> SDoc -> SDoc
<> SDoc
trail

type instance XExpBr      (GhcPass _) = NoExtField
type instance XPatBr      (GhcPass _) = NoExtField
type instance XDecBrL     (GhcPass _) = NoExtField
type instance XDecBrG     (GhcPass _) = NoExtField
type instance XTypBr      (GhcPass _) = NoExtField
type instance XVarBr      (GhcPass _) = NoExtField
type instance XTExpBr     (GhcPass _) = NoExtField
type instance XXBracket   (GhcPass _) = NoExtCon

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


pprHsBracket :: (OutputableBndrId p) => HsBracket (GhcPass p) -> SDoc
pprHsBracket :: forall (p :: Pass).
OutputableBndrId p =>
HsBracket (GhcPass p) -> SDoc
pprHsBracket (ExpBr XExpBr (GhcPass p)
_ LHsExpr (GhcPass p)
e)   = SDoc -> SDoc -> SDoc
thBrackets SDoc
empty (forall a. Outputable a => a -> SDoc
ppr LHsExpr (GhcPass p)
e)
pprHsBracket (PatBr XPatBr (GhcPass p)
_ LPat (GhcPass p)
p)   = SDoc -> SDoc -> SDoc
thBrackets (Char -> SDoc
char Char
'p') (forall a. Outputable a => a -> SDoc
ppr LPat (GhcPass p)
p)
pprHsBracket (DecBrG XDecBrG (GhcPass p)
_ HsGroup (GhcPass p)
gp) = SDoc -> SDoc -> SDoc
thBrackets (Char -> SDoc
char Char
'd') (forall a. Outputable a => a -> SDoc
ppr HsGroup (GhcPass p)
gp)
pprHsBracket (DecBrL XDecBrL (GhcPass p)
_ [LHsDecl (GhcPass p)]
ds) = SDoc -> SDoc -> SDoc
thBrackets (Char -> SDoc
char Char
'd') ([SDoc] -> SDoc
vcat (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [LHsDecl (GhcPass p)]
ds))
pprHsBracket (TypBr XTypBr (GhcPass p)
_ LHsType (GhcPass p)
t)   = SDoc -> SDoc -> SDoc
thBrackets (Char -> SDoc
char Char
't') (forall a. Outputable a => a -> SDoc
ppr LHsType (GhcPass p)
t)
pprHsBracket (VarBr XVarBr (GhcPass p)
_ Bool
True LIdP (GhcPass p)
n)
  = Char -> SDoc
char Char
'\'' SDoc -> SDoc -> SDoc
<> forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (forall l e. GenLocated l e -> e
unLoc LIdP (GhcPass p)
n)
pprHsBracket (VarBr XVarBr (GhcPass p)
_ Bool
False LIdP (GhcPass p)
n)
  = String -> SDoc
text String
"''" SDoc -> SDoc -> SDoc
<> forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (forall l e. GenLocated l e -> e
unLoc LIdP (GhcPass p)
n)
pprHsBracket (TExpBr XTExpBr (GhcPass p)
_ LHsExpr (GhcPass p)
e)  = SDoc -> SDoc
thTyBrackets (forall a. Outputable a => a -> SDoc
ppr LHsExpr (GhcPass p)
e)

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

thTyBrackets :: SDoc -> SDoc
thTyBrackets :: SDoc -> SDoc
thTyBrackets SDoc
pp_body = String -> SDoc
text String
"[||" SDoc -> SDoc -> SDoc
<+> SDoc
pp_body SDoc -> SDoc -> SDoc
<+> PtrString -> SDoc
ptext (String -> PtrString
sLit 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

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

instance OutputableBndrId p
         => Outputable (ArithSeqInfo (GhcPass p)) where
    ppr :: ArithSeqInfo (GhcPass p) -> SDoc
ppr (From LHsExpr (GhcPass p)
e1)             = [SDoc] -> SDoc
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)      = [SDoc] -> SDoc
hcat [forall a. Outputable a => a -> SDoc
ppr LHsExpr (GhcPass p)
e1, SDoc
comma, SDoc
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)        = [SDoc] -> SDoc
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)
      = [SDoc] -> SDoc
hcat [forall a. Outputable a => a -> SDoc
ppr LHsExpr (GhcPass p)
e1, SDoc
comma, SDoc
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 = String -> SDoc
text String
" .. "

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

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

instance Outputable HsArrowMatchContext where
  ppr :: HsArrowMatchContext -> SDoc
ppr HsArrowMatchContext
ProcExpr     = String -> SDoc
text String
"ProcExpr"
  ppr HsArrowMatchContext
ArrowCaseAlt = String -> SDoc
text String
"ArrowCaseAlt"
  ppr HsArrowMatchContext
KappaExpr    = String -> SDoc
text String
"KappaExpr"

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

instance OutputableBndrId p
      => Outputable (HsStmtContext (GhcPass p)) where
    ppr :: HsStmtContext (GhcPass p) -> SDoc
ppr = forall p. (Outputable (IdP p), UnXRec 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 p
mc_fun=L Anno (IdGhcP p)
_ IdGhcP p
fun})   = String -> SDoc
text String
"function" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr IdGhcP p
fun
matchContextErrString HsMatchContext (GhcPass p)
CaseAlt                    = String -> SDoc
text String
"case"
matchContextErrString HsMatchContext (GhcPass p)
IfAlt                      = String -> SDoc
text String
"multi-way if"
matchContextErrString HsMatchContext (GhcPass p)
PatBindRhs                 = String -> SDoc
text String
"pattern binding"
matchContextErrString HsMatchContext (GhcPass p)
PatBindGuards              = String -> SDoc
text String
"pattern binding guards"
matchContextErrString HsMatchContext (GhcPass p)
RecUpd                     = String -> SDoc
text String
"record update"
matchContextErrString HsMatchContext (GhcPass p)
LambdaExpr                 = String -> SDoc
text String
"lambda"
matchContextErrString (ArrowMatchCtxt HsArrowMatchContext
c)         = HsArrowMatchContext -> SDoc
matchArrowContextErrString HsArrowMatchContext
c
matchContextErrString HsMatchContext (GhcPass p)
ThPatSplice                = forall a. String -> a
panic String
"matchContextErrString"  -- Not used at runtime
matchContextErrString HsMatchContext (GhcPass p)
ThPatQuote                 = forall a. String -> a
panic String
"matchContextErrString"  -- Not used at runtime
matchContextErrString HsMatchContext (GhcPass p)
PatSyn                     = forall a. 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)
_))      = String -> SDoc
text String
"pattern guard"
matchContextErrString (StmtCtxt HsStmtContext (GhcPass p)
GhciStmtCtxt)      = String -> SDoc
text String
"interactive GHCi command"
matchContextErrString (StmtCtxt (DoExpr Maybe ModuleName
m))        = Maybe ModuleName -> SDoc -> SDoc
prependQualified Maybe ModuleName
m (String -> SDoc
text String
"'do' block")
matchContextErrString (StmtCtxt HsStmtContext (GhcPass p)
ArrowExpr)         = String -> SDoc
text String
"'do' block"
matchContextErrString (StmtCtxt (MDoExpr Maybe ModuleName
m))       = Maybe ModuleName -> SDoc -> SDoc
prependQualified Maybe ModuleName
m (String -> SDoc
text String
"'mdo' block")
matchContextErrString (StmtCtxt HsStmtContext (GhcPass p)
ListComp)          = String -> SDoc
text String
"list comprehension"
matchContextErrString (StmtCtxt HsStmtContext (GhcPass p)
MonadComp)         = String -> SDoc
text String
"monad comprehension"

matchArrowContextErrString :: HsArrowMatchContext -> SDoc
matchArrowContextErrString :: HsArrowMatchContext -> SDoc
matchArrowContextErrString HsArrowMatchContext
ProcExpr     = String -> SDoc
text String
"proc"
matchArrowContextErrString HsArrowMatchContext
ArrowCaseAlt = String -> SDoc
text String
"case"
matchArrowContextErrString HsArrowMatchContext
KappaExpr    = String -> SDoc
text String
"kappa"

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 (String -> SDoc
text String
"In" SDoc -> SDoc -> SDoc
<+> forall p.
(Outputable (IdP p), UnXRec p) =>
HsMatchContext p -> SDoc
pprMatchContext (forall p body. Match p body -> HsMatchContext (NoGhcTc p)
m_ctxt Match (GhcPass idR) body
match)
                                        SDoc -> SDoc -> SDoc
<> SDoc
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,
                  Outputable body,
                 Anno (StmtLR (GhcPass idL) (GhcPass idR) body) ~ SrcSpanAnnA)
              => HsStmtContext (GhcPass idL)
              -> StmtLR (GhcPass idL) (GhcPass idR) body
              -> SDoc
pprStmtInCtxt :: forall (idL :: Pass) (idR :: Pass) body.
(OutputableBndrId idL, OutputableBndrId idR, Outputable body,
 Anno (StmtLR (GhcPass idL) (GhcPass idR) body) ~ SrcSpanAnnA) =>
HsStmtContext (GhcPass idL)
-> StmtLR (GhcPass idL) (GhcPass idR) body -> SDoc
pprStmtInCtxt HsStmtContext (GhcPass idL)
ctxt (LastStmt XLastStmt (GhcPass idL) (GhcPass idR) body
_ body
e Maybe Bool
_ SyntaxExpr (GhcPass idR)
_)
  | forall id. HsStmtContext id -> Bool
isComprehensionContext HsStmtContext (GhcPass idL)
ctxt      -- For [ e | .. ], do not mutter about "stmts"
  = SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"In the expression:") Int
2 (forall a. Outputable a => a -> SDoc
ppr body
e)

pprStmtInCtxt HsStmtContext (GhcPass idL)
ctxt StmtLR (GhcPass idL) (GhcPass idR) body
stmt
  = SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"In a stmt of" SDoc -> SDoc -> SDoc
<+> forall p. (Outputable (IdP p), UnXRec p) => HsStmtContext p -> SDoc
pprAStmtContext HsStmtContext (GhcPass idL)
ctxt SDoc -> SDoc -> SDoc
<> SDoc
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

{-
************************************************************************
*                                                                      *
\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)) = SrcSpan
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)))) = SrcSpan
type instance Anno (GRHS (GhcPass p) (LocatedA (HsCmd  (GhcPass p)))) = SrcSpan
type instance Anno (StmtLR (GhcPass pl) (GhcPass pr) (LocatedA (HsExpr (GhcPass pr)))) = SrcSpanAnnA
type instance Anno (StmtLR (GhcPass pl) (GhcPass pr) (LocatedA (HsCmd  (GhcPass pr)))) = SrcSpanAnnA

type instance Anno (HsSplice (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

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