{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ViewPatterns #-}

-- | Rendering of declarations.
module Ormolu.Printer.Meat.Declaration
  ( p_hsDecls,
    p_hsDeclsRespectGrouping,
  )
where

import Data.List (sort)
import Data.List.NonEmpty (NonEmpty (..), (<|))
import qualified Data.List.NonEmpty as NE
import GHC.Hs.Binds
import GHC.Hs.Decls
import GHC.Hs.Extension
import GHC.Hs.Pat
import GHC.Types.Name.Occurrence (occNameFS)
import GHC.Types.Name.Reader
import GHC.Types.SrcLoc
import Ormolu.Printer.Combinators
import Ormolu.Printer.Meat.Common
import Ormolu.Printer.Meat.Declaration.Annotation
import Ormolu.Printer.Meat.Declaration.Class
import Ormolu.Printer.Meat.Declaration.Data
import Ormolu.Printer.Meat.Declaration.Default
import Ormolu.Printer.Meat.Declaration.Foreign
import Ormolu.Printer.Meat.Declaration.Instance
import Ormolu.Printer.Meat.Declaration.RoleAnnotation
import Ormolu.Printer.Meat.Declaration.Rule
import Ormolu.Printer.Meat.Declaration.Signature
import Ormolu.Printer.Meat.Declaration.Splice
import Ormolu.Printer.Meat.Declaration.Type
import Ormolu.Printer.Meat.Declaration.TypeFamily
import Ormolu.Printer.Meat.Declaration.Value
import Ormolu.Printer.Meat.Declaration.Warning
import Ormolu.Printer.Meat.Type
import Ormolu.Utils

data UserGrouping
  = -- | Always put newlines where we think they should be
    Disregard
  | -- | Respect user preferences regarding grouping
    Respect
  deriving (UserGrouping -> UserGrouping -> Bool
(UserGrouping -> UserGrouping -> Bool)
-> (UserGrouping -> UserGrouping -> Bool) -> Eq UserGrouping
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UserGrouping -> UserGrouping -> Bool
$c/= :: UserGrouping -> UserGrouping -> Bool
== :: UserGrouping -> UserGrouping -> Bool
$c== :: UserGrouping -> UserGrouping -> Bool
Eq, Int -> UserGrouping -> ShowS
[UserGrouping] -> ShowS
UserGrouping -> String
(Int -> UserGrouping -> ShowS)
-> (UserGrouping -> String)
-> ([UserGrouping] -> ShowS)
-> Show UserGrouping
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UserGrouping] -> ShowS
$cshowList :: [UserGrouping] -> ShowS
show :: UserGrouping -> String
$cshow :: UserGrouping -> String
showsPrec :: Int -> UserGrouping -> ShowS
$cshowsPrec :: Int -> UserGrouping -> ShowS
Show)

p_hsDecls :: FamilyStyle -> [LHsDecl GhcPs] -> R ()
p_hsDecls :: FamilyStyle -> [LHsDecl GhcPs] -> R ()
p_hsDecls = UserGrouping -> FamilyStyle -> [LHsDecl GhcPs] -> R ()
p_hsDecls' UserGrouping
Disregard

-- | Like 'p_hsDecls' but respects user choices regarding grouping. If the
-- user omits newlines between declarations, we also omit them in most
-- cases, except when said declarations have associated Haddocks.
--
-- Does some normalization (compress subsequent newlines into a single one)
p_hsDeclsRespectGrouping :: FamilyStyle -> [LHsDecl GhcPs] -> R ()
p_hsDeclsRespectGrouping :: FamilyStyle -> [LHsDecl GhcPs] -> R ()
p_hsDeclsRespectGrouping = UserGrouping -> FamilyStyle -> [LHsDecl GhcPs] -> R ()
p_hsDecls' UserGrouping
Respect

p_hsDecls' :: UserGrouping -> FamilyStyle -> [LHsDecl GhcPs] -> R ()
p_hsDecls' :: UserGrouping -> FamilyStyle -> [LHsDecl GhcPs] -> R ()
p_hsDecls' UserGrouping
grouping FamilyStyle
style [LHsDecl GhcPs]
decls =
  (R () -> R ()) -> [R ()] -> R ()
forall a. (a -> R ()) -> [a] -> R ()
sepSemi R () -> R ()
forall a. a -> a
id ([R ()] -> R ()) -> [R ()] -> R ()
forall a b. (a -> b) -> a -> b
$
    -- Return a list of rendered declarations, adding a newline to separate
    -- groups.
    case [LHsDecl GhcPs] -> [NonEmpty (LHsDecl GhcPs)]
groupDecls [LHsDecl GhcPs]
decls of
      [] -> []
      (NonEmpty (LHsDecl GhcPs)
x : [NonEmpty (LHsDecl GhcPs)]
xs) -> NonEmpty (LHsDecl GhcPs) -> [R ()]
renderGroup NonEmpty (LHsDecl GhcPs)
x [R ()] -> [R ()] -> [R ()]
forall a. [a] -> [a] -> [a]
++ [[R ()]] -> [R ()]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ((NonEmpty (LHsDecl GhcPs) -> NonEmpty (LHsDecl GhcPs) -> [R ()])
-> [NonEmpty (LHsDecl GhcPs)]
-> [NonEmpty (LHsDecl GhcPs)]
-> [[R ()]]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith NonEmpty (LHsDecl GhcPs) -> NonEmpty (LHsDecl GhcPs) -> [R ()]
renderGroupWithPrev (NonEmpty (LHsDecl GhcPs)
x NonEmpty (LHsDecl GhcPs)
-> [NonEmpty (LHsDecl GhcPs)] -> [NonEmpty (LHsDecl GhcPs)]
forall a. a -> [a] -> [a]
: [NonEmpty (LHsDecl GhcPs)]
xs) [NonEmpty (LHsDecl GhcPs)]
xs)
  where
    renderGroup :: NonEmpty (LHsDecl GhcPs) -> [R ()]
renderGroup = NonEmpty (R ()) -> [R ()]
forall a. NonEmpty a -> [a]
NE.toList (NonEmpty (R ()) -> [R ()])
-> (NonEmpty (LHsDecl GhcPs) -> NonEmpty (R ()))
-> NonEmpty (LHsDecl GhcPs)
-> [R ()]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LHsDecl GhcPs -> R ())
-> NonEmpty (LHsDecl GhcPs) -> NonEmpty (R ())
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((HsDecl GhcPs -> R ()) -> LHsDecl GhcPs -> R ()
forall a. (a -> R ()) -> Located a -> R ()
located' ((HsDecl GhcPs -> R ()) -> LHsDecl GhcPs -> R ())
-> (HsDecl GhcPs -> R ()) -> LHsDecl GhcPs -> R ()
forall a b. (a -> b) -> a -> b
$ R () -> R ()
dontUseBraces (R () -> R ()) -> (HsDecl GhcPs -> R ()) -> HsDecl GhcPs -> R ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FamilyStyle -> HsDecl GhcPs -> R ()
p_hsDecl FamilyStyle
style)
    renderGroupWithPrev :: NonEmpty (LHsDecl GhcPs) -> NonEmpty (LHsDecl GhcPs) -> [R ()]
renderGroupWithPrev NonEmpty (LHsDecl GhcPs)
prev NonEmpty (LHsDecl GhcPs)
curr =
      -- We can omit a blank line when the user didn't add one, but we must
      -- ensure we always add blank lines around documented declarations
      case UserGrouping
grouping of
        UserGrouping
Disregard ->
          R ()
breakpoint R () -> [R ()] -> [R ()]
forall a. a -> [a] -> [a]
: NonEmpty (LHsDecl GhcPs) -> [R ()]
renderGroup NonEmpty (LHsDecl GhcPs)
curr
        UserGrouping
Respect ->
          if (LHsDecl GhcPs -> SrcSpan)
-> NonEmpty (LHsDecl GhcPs) -> NonEmpty (LHsDecl GhcPs) -> Bool
forall a. (a -> SrcSpan) -> NonEmpty a -> NonEmpty a -> Bool
separatedByBlankNE LHsDecl GhcPs -> SrcSpan
forall l e. GenLocated l e -> l
getLoc NonEmpty (LHsDecl GhcPs)
prev NonEmpty (LHsDecl GhcPs)
curr
            Bool -> Bool -> Bool
|| NonEmpty (LHsDecl GhcPs) -> Bool
isDocumented NonEmpty (LHsDecl GhcPs)
prev
            Bool -> Bool -> Bool
|| NonEmpty (LHsDecl GhcPs) -> Bool
isDocumented NonEmpty (LHsDecl GhcPs)
curr
            then R ()
breakpoint R () -> [R ()] -> [R ()]
forall a. a -> [a] -> [a]
: NonEmpty (LHsDecl GhcPs) -> [R ()]
renderGroup NonEmpty (LHsDecl GhcPs)
curr
            else NonEmpty (LHsDecl GhcPs) -> [R ()]
renderGroup NonEmpty (LHsDecl GhcPs)
curr

-- | Is a declaration group documented?
isDocumented :: NonEmpty (LHsDecl GhcPs) -> Bool
isDocumented :: NonEmpty (LHsDecl GhcPs) -> Bool
isDocumented = (LHsDecl GhcPs -> Bool) -> NonEmpty (LHsDecl GhcPs) -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (HsDecl GhcPs -> Bool
isHaddock (HsDecl GhcPs -> Bool)
-> (LHsDecl GhcPs -> HsDecl GhcPs) -> LHsDecl GhcPs -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LHsDecl GhcPs -> HsDecl GhcPs
forall l e. GenLocated l e -> e
unLoc)
  where
    isHaddock :: HsDecl GhcPs -> Bool
isHaddock HsDecl GhcPs
DocNext = Bool
True
    isHaddock HsDecl GhcPs
DocPrev = Bool
True
    isHaddock HsDecl GhcPs
_ = Bool
False

-- | Group relevant declarations together.
groupDecls :: [LHsDecl GhcPs] -> [NonEmpty (LHsDecl GhcPs)]
groupDecls :: [LHsDecl GhcPs] -> [NonEmpty (LHsDecl GhcPs)]
groupDecls [] = []
groupDecls (l :: LHsDecl GhcPs
l@(L SrcSpan
_ HsDecl GhcPs
DocNext) : [LHsDecl GhcPs]
xs) =
  -- If the first element is a doc string for next element, just include it
  -- in the next block:
  case [LHsDecl GhcPs] -> [NonEmpty (LHsDecl GhcPs)]
groupDecls [LHsDecl GhcPs]
xs of
    [] -> [LHsDecl GhcPs
l LHsDecl GhcPs -> [LHsDecl GhcPs] -> NonEmpty (LHsDecl GhcPs)
forall a. a -> [a] -> NonEmpty a
:| []]
    (NonEmpty (LHsDecl GhcPs)
x : [NonEmpty (LHsDecl GhcPs)]
xs') -> (LHsDecl GhcPs
l LHsDecl GhcPs
-> NonEmpty (LHsDecl GhcPs) -> NonEmpty (LHsDecl GhcPs)
forall a. a -> NonEmpty a -> NonEmpty a
<| NonEmpty (LHsDecl GhcPs)
x) NonEmpty (LHsDecl GhcPs)
-> [NonEmpty (LHsDecl GhcPs)] -> [NonEmpty (LHsDecl GhcPs)]
forall a. a -> [a] -> [a]
: [NonEmpty (LHsDecl GhcPs)]
xs'
groupDecls (LHsDecl GhcPs
header : [LHsDecl GhcPs]
xs) =
  let ([(LHsDecl GhcPs, LHsDecl GhcPs)]
grp, [(LHsDecl GhcPs, LHsDecl GhcPs)]
rest) = (((LHsDecl GhcPs, LHsDecl GhcPs) -> Bool)
 -> [(LHsDecl GhcPs, LHsDecl GhcPs)]
 -> ([(LHsDecl GhcPs, LHsDecl GhcPs)],
     [(LHsDecl GhcPs, LHsDecl GhcPs)]))
-> [(LHsDecl GhcPs, LHsDecl GhcPs)]
-> ((LHsDecl GhcPs, LHsDecl GhcPs) -> Bool)
-> ([(LHsDecl GhcPs, LHsDecl GhcPs)],
    [(LHsDecl GhcPs, LHsDecl GhcPs)])
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((LHsDecl GhcPs, LHsDecl GhcPs) -> Bool)
-> [(LHsDecl GhcPs, LHsDecl GhcPs)]
-> ([(LHsDecl GhcPs, LHsDecl GhcPs)],
    [(LHsDecl GhcPs, LHsDecl GhcPs)])
forall a. (a -> Bool) -> [a] -> ([a], [a])
span ([LHsDecl GhcPs]
-> [LHsDecl GhcPs] -> [(LHsDecl GhcPs, LHsDecl GhcPs)]
forall a b. [a] -> [b] -> [(a, b)]
zip (LHsDecl GhcPs
header LHsDecl GhcPs -> [LHsDecl GhcPs] -> [LHsDecl GhcPs]
forall a. a -> [a] -> [a]
: [LHsDecl GhcPs]
xs) [LHsDecl GhcPs]
xs) (((LHsDecl GhcPs, LHsDecl GhcPs) -> Bool)
 -> ([(LHsDecl GhcPs, LHsDecl GhcPs)],
     [(LHsDecl GhcPs, LHsDecl GhcPs)]))
-> ((LHsDecl GhcPs, LHsDecl GhcPs) -> Bool)
-> ([(LHsDecl GhcPs, LHsDecl GhcPs)],
    [(LHsDecl GhcPs, LHsDecl GhcPs)])
forall a b. (a -> b) -> a -> b
$ \(LHsDecl GhcPs
previous, LHsDecl GhcPs
current) ->
        let relevantToHdr :: Bool
relevantToHdr = LHsDecl GhcPs -> LHsDecl GhcPs -> Bool
groupedDecls LHsDecl GhcPs
header LHsDecl GhcPs
current
            relevantToPrev :: Bool
relevantToPrev = LHsDecl GhcPs -> LHsDecl GhcPs -> Bool
groupedDecls LHsDecl GhcPs
previous LHsDecl GhcPs
current
            isDeclSeries :: Bool
isDeclSeries = LHsDecl GhcPs -> LHsDecl GhcPs -> Bool
declSeries LHsDecl GhcPs
previous LHsDecl GhcPs
current
         in Bool
isDeclSeries Bool -> Bool -> Bool
|| Bool
relevantToHdr Bool -> Bool -> Bool
|| Bool
relevantToPrev
   in (LHsDecl GhcPs
header LHsDecl GhcPs -> [LHsDecl GhcPs] -> NonEmpty (LHsDecl GhcPs)
forall a. a -> [a] -> NonEmpty a
:| ((LHsDecl GhcPs, LHsDecl GhcPs) -> LHsDecl GhcPs)
-> [(LHsDecl GhcPs, LHsDecl GhcPs)] -> [LHsDecl GhcPs]
forall a b. (a -> b) -> [a] -> [b]
map (LHsDecl GhcPs, LHsDecl GhcPs) -> LHsDecl GhcPs
forall a b. (a, b) -> b
snd [(LHsDecl GhcPs, LHsDecl GhcPs)]
grp) NonEmpty (LHsDecl GhcPs)
-> [NonEmpty (LHsDecl GhcPs)] -> [NonEmpty (LHsDecl GhcPs)]
forall a. a -> [a] -> [a]
: [LHsDecl GhcPs] -> [NonEmpty (LHsDecl GhcPs)]
groupDecls (((LHsDecl GhcPs, LHsDecl GhcPs) -> LHsDecl GhcPs)
-> [(LHsDecl GhcPs, LHsDecl GhcPs)] -> [LHsDecl GhcPs]
forall a b. (a -> b) -> [a] -> [b]
map (LHsDecl GhcPs, LHsDecl GhcPs) -> LHsDecl GhcPs
forall a b. (a, b) -> b
snd [(LHsDecl GhcPs, LHsDecl GhcPs)]
rest)

p_hsDecl :: FamilyStyle -> HsDecl GhcPs -> R ()
p_hsDecl :: FamilyStyle -> HsDecl GhcPs -> R ()
p_hsDecl FamilyStyle
style = \case
  TyClD XTyClD GhcPs
NoExtField TyClDecl GhcPs
x -> FamilyStyle -> TyClDecl GhcPs -> R ()
p_tyClDecl FamilyStyle
style TyClDecl GhcPs
x
  ValD XValD GhcPs
NoExtField HsBind GhcPs
x -> HsBind GhcPs -> R ()
p_valDecl HsBind GhcPs
x
  SigD XSigD GhcPs
NoExtField Sig GhcPs
x -> Sig GhcPs -> R ()
p_sigDecl Sig GhcPs
x
  InstD XInstD GhcPs
NoExtField InstDecl GhcPs
x -> FamilyStyle -> InstDecl GhcPs -> R ()
p_instDecl FamilyStyle
style InstDecl GhcPs
x
  DerivD XDerivD GhcPs
NoExtField DerivDecl GhcPs
x -> DerivDecl GhcPs -> R ()
p_standaloneDerivDecl DerivDecl GhcPs
x
  DefD XDefD GhcPs
NoExtField DefaultDecl GhcPs
x -> DefaultDecl GhcPs -> R ()
p_defaultDecl DefaultDecl GhcPs
x
  ForD XForD GhcPs
NoExtField ForeignDecl GhcPs
x -> ForeignDecl GhcPs -> R ()
p_foreignDecl ForeignDecl GhcPs
x
  WarningD XWarningD GhcPs
NoExtField WarnDecls GhcPs
x -> WarnDecls GhcPs -> R ()
p_warnDecls WarnDecls GhcPs
x
  AnnD XAnnD GhcPs
NoExtField AnnDecl GhcPs
x -> AnnDecl GhcPs -> R ()
p_annDecl AnnDecl GhcPs
x
  RuleD XRuleD GhcPs
NoExtField RuleDecls GhcPs
x -> RuleDecls GhcPs -> R ()
p_ruleDecls RuleDecls GhcPs
x
  SpliceD XSpliceD GhcPs
NoExtField SpliceDecl GhcPs
x -> SpliceDecl GhcPs -> R ()
p_spliceDecl SpliceDecl GhcPs
x
  DocD XDocD GhcPs
NoExtField DocDecl
docDecl ->
    case DocDecl
docDecl of
      DocCommentNext HsDocString
str -> HaddockStyle -> Bool -> LHsDocString -> R ()
p_hsDocString HaddockStyle
Pipe Bool
False (HsDocString -> LHsDocString
forall e. e -> Located e
noLoc HsDocString
str)
      DocCommentPrev HsDocString
str -> HaddockStyle -> Bool -> LHsDocString -> R ()
p_hsDocString HaddockStyle
Caret Bool
False (HsDocString -> LHsDocString
forall e. e -> Located e
noLoc HsDocString
str)
      DocCommentNamed String
name HsDocString
str -> HaddockStyle -> Bool -> LHsDocString -> R ()
p_hsDocString (String -> HaddockStyle
Named String
name) Bool
False (HsDocString -> LHsDocString
forall e. e -> Located e
noLoc HsDocString
str)
      DocGroup Int
n HsDocString
str -> HaddockStyle -> Bool -> LHsDocString -> R ()
p_hsDocString (Int -> HaddockStyle
Asterisk Int
n) Bool
False (HsDocString -> LHsDocString
forall e. e -> Located e
noLoc HsDocString
str)
  RoleAnnotD XRoleAnnotD GhcPs
NoExtField RoleAnnotDecl GhcPs
x -> RoleAnnotDecl GhcPs -> R ()
p_roleAnnot RoleAnnotDecl GhcPs
x
  KindSigD XKindSigD GhcPs
NoExtField StandaloneKindSig GhcPs
s -> StandaloneKindSig GhcPs -> R ()
p_standaloneKindSig StandaloneKindSig GhcPs
s

p_tyClDecl :: FamilyStyle -> TyClDecl GhcPs -> R ()
p_tyClDecl :: FamilyStyle -> TyClDecl GhcPs -> R ()
p_tyClDecl FamilyStyle
style = \case
  FamDecl XFamDecl GhcPs
NoExtField FamilyDecl GhcPs
x -> FamilyStyle -> FamilyDecl GhcPs -> R ()
p_famDecl FamilyStyle
style FamilyDecl GhcPs
x
  SynDecl {LHsQTyVars GhcPs
XSynDecl GhcPs
LexicalFixity
LHsType GhcPs
Located (IdP GhcPs)
tcdSExt :: forall pass. TyClDecl pass -> XSynDecl pass
tcdLName :: forall pass. TyClDecl pass -> Located (IdP pass)
tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
tcdFixity :: forall pass. TyClDecl pass -> LexicalFixity
tcdRhs :: forall pass. TyClDecl pass -> LHsType pass
tcdRhs :: LHsType GhcPs
tcdFixity :: LexicalFixity
tcdTyVars :: LHsQTyVars GhcPs
tcdLName :: Located (IdP GhcPs)
tcdSExt :: XSynDecl GhcPs
..} -> Located RdrName
-> LexicalFixity -> LHsQTyVars GhcPs -> LHsType GhcPs -> R ()
p_synDecl Located (IdP GhcPs)
Located RdrName
tcdLName LexicalFixity
tcdFixity LHsQTyVars GhcPs
tcdTyVars LHsType GhcPs
tcdRhs
  DataDecl {HsDataDefn GhcPs
LHsQTyVars GhcPs
XDataDecl GhcPs
LexicalFixity
Located (IdP GhcPs)
tcdDExt :: forall pass. TyClDecl pass -> XDataDecl pass
tcdDataDefn :: forall pass. TyClDecl pass -> HsDataDefn pass
tcdDataDefn :: HsDataDefn GhcPs
tcdFixity :: LexicalFixity
tcdTyVars :: LHsQTyVars GhcPs
tcdLName :: Located (IdP GhcPs)
tcdDExt :: XDataDecl GhcPs
tcdLName :: forall pass. TyClDecl pass -> Located (IdP pass)
tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
tcdFixity :: forall pass. TyClDecl pass -> LexicalFixity
..} ->
    FamilyStyle
-> Located RdrName
-> HsTyPats GhcPs
-> LexicalFixity
-> HsDataDefn GhcPs
-> R ()
p_dataDecl
      FamilyStyle
Associated
      Located (IdP GhcPs)
Located RdrName
tcdLName
      (LHsQTyVars GhcPs -> HsTyPats GhcPs
tyVarsToTyPats LHsQTyVars GhcPs
tcdTyVars)
      LexicalFixity
tcdFixity
      HsDataDefn GhcPs
tcdDataDefn
  ClassDecl {[LHsFunDep GhcPs]
[LFamilyDecl GhcPs]
[LTyFamDefltDecl GhcPs]
[LDocDecl]
[LSig GhcPs]
LHsQTyVars GhcPs
XClassDecl GhcPs
LexicalFixity
LHsContext GhcPs
Located (IdP GhcPs)
LHsBinds GhcPs
tcdCExt :: forall pass. TyClDecl pass -> XClassDecl pass
tcdCtxt :: forall pass. TyClDecl pass -> LHsContext pass
tcdFDs :: forall pass. TyClDecl pass -> [LHsFunDep pass]
tcdSigs :: forall pass. TyClDecl pass -> [LSig pass]
tcdMeths :: forall pass. TyClDecl pass -> LHsBinds pass
tcdATs :: forall pass. TyClDecl pass -> [LFamilyDecl pass]
tcdATDefs :: forall pass. TyClDecl pass -> [LTyFamDefltDecl pass]
tcdDocs :: forall pass. TyClDecl pass -> [LDocDecl]
tcdDocs :: [LDocDecl]
tcdATDefs :: [LTyFamDefltDecl GhcPs]
tcdATs :: [LFamilyDecl GhcPs]
tcdMeths :: LHsBinds GhcPs
tcdSigs :: [LSig GhcPs]
tcdFDs :: [LHsFunDep GhcPs]
tcdFixity :: LexicalFixity
tcdTyVars :: LHsQTyVars GhcPs
tcdLName :: Located (IdP GhcPs)
tcdCtxt :: LHsContext GhcPs
tcdCExt :: XClassDecl GhcPs
tcdLName :: forall pass. TyClDecl pass -> Located (IdP pass)
tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
tcdFixity :: forall pass. TyClDecl pass -> LexicalFixity
..} ->
    LHsContext GhcPs
-> Located RdrName
-> LHsQTyVars GhcPs
-> LexicalFixity
-> [Located (FunDep (Located RdrName))]
-> [LSig GhcPs]
-> LHsBinds GhcPs
-> [LFamilyDecl GhcPs]
-> [LTyFamDefltDecl GhcPs]
-> [LDocDecl]
-> R ()
p_classDecl
      LHsContext GhcPs
tcdCtxt
      Located (IdP GhcPs)
Located RdrName
tcdLName
      LHsQTyVars GhcPs
tcdTyVars
      LexicalFixity
tcdFixity
      [LHsFunDep GhcPs]
[Located (FunDep (Located RdrName))]
tcdFDs
      [LSig GhcPs]
tcdSigs
      LHsBinds GhcPs
tcdMeths
      [LFamilyDecl GhcPs]
tcdATs
      [LTyFamDefltDecl GhcPs]
tcdATDefs
      [LDocDecl]
tcdDocs

p_instDecl :: FamilyStyle -> InstDecl GhcPs -> R ()
p_instDecl :: FamilyStyle -> InstDecl GhcPs -> R ()
p_instDecl FamilyStyle
style = \case
  ClsInstD XClsInstD GhcPs
NoExtField ClsInstDecl GhcPs
x -> ClsInstDecl GhcPs -> R ()
p_clsInstDecl ClsInstDecl GhcPs
x
  TyFamInstD XTyFamInstD GhcPs
NoExtField TyFamInstDecl GhcPs
x -> FamilyStyle -> TyFamInstDecl GhcPs -> R ()
p_tyFamInstDecl FamilyStyle
style TyFamInstDecl GhcPs
x
  DataFamInstD XDataFamInstD GhcPs
NoExtField DataFamInstDecl GhcPs
x -> FamilyStyle -> DataFamInstDecl GhcPs -> R ()
p_dataFamInstDecl FamilyStyle
style DataFamInstDecl GhcPs
x

-- | Determine if these declarations should be grouped together.
groupedDecls ::
  LHsDecl GhcPs ->
  LHsDecl GhcPs ->
  Bool
groupedDecls :: LHsDecl GhcPs -> LHsDecl GhcPs -> Bool
groupedDecls (L SrcSpan
l_x HsDecl GhcPs
x') (L SrcSpan
l_y HsDecl GhcPs
y') =
  case (HsDecl GhcPs
x', HsDecl GhcPs
y') of
    (TypeSignature [RdrName]
ns, FunctionBody [RdrName]
ns') -> [RdrName]
ns [RdrName] -> [RdrName] -> Bool
forall a. Ord a => [a] -> [a] -> Bool
`intersects` [RdrName]
ns'
    (TypeSignature [RdrName]
ns, DefaultSignature [RdrName]
ns') -> [RdrName]
ns [RdrName] -> [RdrName] -> Bool
forall a. Ord a => [a] -> [a] -> Bool
`intersects` [RdrName]
ns'
    (DefaultSignature [RdrName]
ns, TypeSignature [RdrName]
ns') -> [RdrName]
ns [RdrName] -> [RdrName] -> Bool
forall a. Ord a => [a] -> [a] -> Bool
`intersects` [RdrName]
ns'
    (DefaultSignature [RdrName]
ns, FunctionBody [RdrName]
ns') -> [RdrName]
ns [RdrName] -> [RdrName] -> Bool
forall a. Ord a => [a] -> [a] -> Bool
`intersects` [RdrName]
ns'
    (HsDecl GhcPs
x, FunctionBody [RdrName]
ns) | Just [RdrName]
ns' <- HsDecl GhcPs -> Maybe [RdrName]
isPragma HsDecl GhcPs
x -> [RdrName]
ns [RdrName] -> [RdrName] -> Bool
forall a. Ord a => [a] -> [a] -> Bool
`intersects` [RdrName]
ns'
    (FunctionBody [RdrName]
ns, HsDecl GhcPs
x) | Just [RdrName]
ns' <- HsDecl GhcPs -> Maybe [RdrName]
isPragma HsDecl GhcPs
x -> [RdrName]
ns [RdrName] -> [RdrName] -> Bool
forall a. Ord a => [a] -> [a] -> Bool
`intersects` [RdrName]
ns'
    (HsDecl GhcPs
x, DataDeclaration RdrName
n) | Just [RdrName]
ns <- HsDecl GhcPs -> Maybe [RdrName]
isPragma HsDecl GhcPs
x -> RdrName
n RdrName -> [RdrName] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [RdrName]
ns
    (DataDeclaration RdrName
n, HsDecl GhcPs
x)
      | Just [RdrName]
ns <- HsDecl GhcPs -> Maybe [RdrName]
isPragma HsDecl GhcPs
x ->
        let f :: RdrName -> FastString
f = OccName -> FastString
occNameFS (OccName -> FastString)
-> (RdrName -> OccName) -> RdrName -> FastString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RdrName -> OccName
rdrNameOcc in RdrName -> FastString
f RdrName
n FastString -> [FastString] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` (RdrName -> FastString) -> [RdrName] -> [FastString]
forall a b. (a -> b) -> [a] -> [b]
map RdrName -> FastString
f [RdrName]
ns
    (HsDecl GhcPs
x, HsDecl GhcPs
y)
      | Just [RdrName]
ns <- HsDecl GhcPs -> Maybe [RdrName]
isPragma HsDecl GhcPs
x,
        Just [RdrName]
ns' <- HsDecl GhcPs -> Maybe [RdrName]
isPragma HsDecl GhcPs
y ->
        [RdrName]
ns [RdrName] -> [RdrName] -> Bool
forall a. Ord a => [a] -> [a] -> Bool
`intersects` [RdrName]
ns'
    (HsDecl GhcPs
x, TypeSignature [RdrName]
ns) | Just [RdrName]
ns' <- HsDecl GhcPs -> Maybe [RdrName]
isPragma HsDecl GhcPs
x -> [RdrName]
ns [RdrName] -> [RdrName] -> Bool
forall a. Ord a => [a] -> [a] -> Bool
`intersects` [RdrName]
ns'
    (TypeSignature [RdrName]
ns, HsDecl GhcPs
x) | Just [RdrName]
ns' <- HsDecl GhcPs -> Maybe [RdrName]
isPragma HsDecl GhcPs
x -> [RdrName]
ns [RdrName] -> [RdrName] -> Bool
forall a. Ord a => [a] -> [a] -> Bool
`intersects` [RdrName]
ns'
    (PatternSignature [RdrName]
ns, Pattern RdrName
n) -> RdrName
n RdrName -> [RdrName] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [RdrName]
ns
    (KindSignature RdrName
n, DataDeclaration RdrName
n') -> RdrName
n RdrName -> RdrName -> Bool
forall a. Eq a => a -> a -> Bool
== RdrName
n'
    (KindSignature RdrName
n, ClassDeclaration RdrName
n') -> RdrName
n RdrName -> RdrName -> Bool
forall a. Eq a => a -> a -> Bool
== RdrName
n'
    (KindSignature RdrName
n, FamilyDeclaration RdrName
n') -> RdrName
n RdrName -> RdrName -> Bool
forall a. Eq a => a -> a -> Bool
== RdrName
n'
    (KindSignature RdrName
n, TypeSynonym RdrName
n') -> RdrName
n RdrName -> RdrName -> Bool
forall a. Eq a => a -> a -> Bool
== RdrName
n'
    -- Special case for TH splices, we look at locations
    (HsDecl GhcPs
Splice, HsDecl GhcPs
Splice) -> Bool -> Bool
not ((SrcSpan -> SrcSpan) -> SrcSpan -> SrcSpan -> Bool
forall a. (a -> SrcSpan) -> a -> a -> Bool
separatedByBlank SrcSpan -> SrcSpan
forall a. a -> a
id SrcSpan
l_x SrcSpan
l_y)
    -- This looks only at Haddocks, normal comments are handled elsewhere
    (HsDecl GhcPs
DocNext, HsDecl GhcPs
_) -> Bool
True
    (HsDecl GhcPs
_, HsDecl GhcPs
DocPrev) -> Bool
True
    (HsDecl GhcPs, HsDecl GhcPs)
_ -> Bool
False

-- | Detect declaration series that should not have blanks between them.
declSeries ::
  LHsDecl GhcPs ->
  LHsDecl GhcPs ->
  Bool
declSeries :: LHsDecl GhcPs -> LHsDecl GhcPs -> Bool
declSeries (L SrcSpan
_ HsDecl GhcPs
x) (L SrcSpan
_ HsDecl GhcPs
y) =
  case (HsDecl GhcPs
x, HsDecl GhcPs
y) of
    ( SigD XSigD GhcPs
NoExtField (TypeSig XTypeSig GhcPs
NoExtField [Located (IdP GhcPs)]
_ LHsSigWcType GhcPs
_),
      SigD XSigD GhcPs
NoExtField (TypeSig XTypeSig GhcPs
NoExtField [Located (IdP GhcPs)]
_ LHsSigWcType GhcPs
_)
      ) -> Bool
True
    (HsDecl GhcPs, HsDecl GhcPs)
_ -> Bool
False

intersects :: Ord a => [a] -> [a] -> Bool
intersects :: [a] -> [a] -> Bool
intersects [a]
a [a]
b = [a] -> [a] -> Bool
forall a. Ord a => [a] -> [a] -> Bool
go ([a] -> [a]
forall a. Ord a => [a] -> [a]
sort [a]
a) ([a] -> [a]
forall a. Ord a => [a] -> [a]
sort [a]
b)
  where
    go :: Ord a => [a] -> [a] -> Bool
    go :: [a] -> [a] -> Bool
go [a]
_ [] = Bool
False
    go [] [a]
_ = Bool
False
    go (a
x : [a]
xs) (a
y : [a]
ys)
      | a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
y = [a] -> [a] -> Bool
forall a. Ord a => [a] -> [a] -> Bool
go [a]
xs (a
y a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
ys)
      | a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
y = [a] -> [a] -> Bool
forall a. Ord a => [a] -> [a] -> Bool
go (a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
xs) [a]
ys
      | Bool
otherwise = Bool
True

isPragma ::
  HsDecl GhcPs ->
  Maybe [RdrName]
isPragma :: HsDecl GhcPs -> Maybe [RdrName]
isPragma = \case
  InlinePragma RdrName
n -> [RdrName] -> Maybe [RdrName]
forall a. a -> Maybe a
Just [RdrName
n]
  SpecializePragma RdrName
n -> [RdrName] -> Maybe [RdrName]
forall a. a -> Maybe a
Just [RdrName
n]
  SCCPragma RdrName
n -> [RdrName] -> Maybe [RdrName]
forall a. a -> Maybe a
Just [RdrName
n]
  AnnTypePragma RdrName
n -> [RdrName] -> Maybe [RdrName]
forall a. a -> Maybe a
Just [RdrName
n]
  AnnValuePragma RdrName
n -> [RdrName] -> Maybe [RdrName]
forall a. a -> Maybe a
Just [RdrName
n]
  WarningPragma [RdrName]
n -> [RdrName] -> Maybe [RdrName]
forall a. a -> Maybe a
Just [RdrName]
n
  HsDecl GhcPs
_ -> Maybe [RdrName]
forall a. Maybe a
Nothing

-- Declarations that do not refer to names

pattern Splice :: HsDecl GhcPs
pattern $mSplice :: forall r. HsDecl GhcPs -> (Void# -> r) -> (Void# -> r) -> r
Splice <- SpliceD NoExtField (SpliceDecl NoExtField _ _)

-- Declarations referring to a single name

pattern
  InlinePragma,
  SpecializePragma,
  SCCPragma,
  AnnTypePragma,
  AnnValuePragma,
  Pattern,
  DataDeclaration,
  ClassDeclaration,
  KindSignature,
  FamilyDeclaration,
  TypeSynonym ::
    RdrName -> HsDecl GhcPs
pattern $mInlinePragma :: forall r. HsDecl GhcPs -> (RdrName -> r) -> (Void# -> r) -> r
InlinePragma n <- SigD NoExtField (InlineSig NoExtField (L _ n) _)
pattern $mSpecializePragma :: forall r. HsDecl GhcPs -> (RdrName -> r) -> (Void# -> r) -> r
SpecializePragma n <- SigD NoExtField (SpecSig NoExtField (L _ n) _ _)
pattern $mSCCPragma :: forall r. HsDecl GhcPs -> (RdrName -> r) -> (Void# -> r) -> r
SCCPragma n <- SigD NoExtField (SCCFunSig NoExtField _ (L _ n) _)
pattern $mAnnTypePragma :: forall r. HsDecl GhcPs -> (RdrName -> r) -> (Void# -> r) -> r
AnnTypePragma n <- AnnD NoExtField (HsAnnotation NoExtField _ (TypeAnnProvenance (L _ n)) _)
pattern $mAnnValuePragma :: forall r. HsDecl GhcPs -> (RdrName -> r) -> (Void# -> r) -> r
AnnValuePragma n <- AnnD NoExtField (HsAnnotation NoExtField _ (ValueAnnProvenance (L _ n)) _)
pattern $mPattern :: forall r. HsDecl GhcPs -> (RdrName -> r) -> (Void# -> r) -> r
Pattern n <- ValD NoExtField (PatSynBind NoExtField (PSB _ (L _ n) _ _ _))
pattern $mDataDeclaration :: forall r. HsDecl GhcPs -> (RdrName -> r) -> (Void# -> r) -> r
DataDeclaration n <- TyClD NoExtField (DataDecl NoExtField (L _ n) _ _ _)
pattern $mClassDeclaration :: forall r. HsDecl GhcPs -> (RdrName -> r) -> (Void# -> r) -> r
ClassDeclaration n <- TyClD NoExtField (ClassDecl _ _ (L _ n) _ _ _ _ _ _ _ _)
pattern $mKindSignature :: forall r. HsDecl GhcPs -> (RdrName -> r) -> (Void# -> r) -> r
KindSignature n <- KindSigD NoExtField (StandaloneKindSig NoExtField (L _ n) _)
pattern $mFamilyDeclaration :: forall r. HsDecl GhcPs -> (RdrName -> r) -> (Void# -> r) -> r
FamilyDeclaration n <- TyClD NoExtField (FamDecl NoExtField (FamilyDecl NoExtField _ (L _ n) _ _ _ _))
pattern $mTypeSynonym :: forall r. HsDecl GhcPs -> (RdrName -> r) -> (Void# -> r) -> r
TypeSynonym n <- TyClD NoExtField (SynDecl NoExtField (L _ n) _ _ _)

-- Declarations which can refer to multiple names

pattern
  TypeSignature,
  DefaultSignature,
  FunctionBody,
  PatternSignature,
  WarningPragma ::
    [RdrName] -> HsDecl GhcPs
pattern $mTypeSignature :: forall r. HsDecl GhcPs -> ([RdrName] -> r) -> (Void# -> r) -> r
TypeSignature n <- (sigRdrNames -> Just n)
pattern $mDefaultSignature :: forall r. HsDecl GhcPs -> ([RdrName] -> r) -> (Void# -> r) -> r
DefaultSignature n <- (defSigRdrNames -> Just n)
pattern $mFunctionBody :: forall r. HsDecl GhcPs -> ([RdrName] -> r) -> (Void# -> r) -> r
FunctionBody n <- (funRdrNames -> Just n)
pattern $mPatternSignature :: forall r. HsDecl GhcPs -> ([RdrName] -> r) -> (Void# -> r) -> r
PatternSignature n <- (patSigRdrNames -> Just n)
pattern $mWarningPragma :: forall r. HsDecl GhcPs -> ([RdrName] -> r) -> (Void# -> r) -> r
WarningPragma n <- (warnSigRdrNames -> Just n)

pattern DocNext, DocPrev :: HsDecl GhcPs
pattern $mDocNext :: forall r. HsDecl GhcPs -> (Void# -> r) -> (Void# -> r) -> r
DocNext <- (DocD NoExtField (DocCommentNext _))
pattern $mDocPrev :: forall r. HsDecl GhcPs -> (Void# -> r) -> (Void# -> r) -> r
DocPrev <- (DocD NoExtField (DocCommentPrev _))

sigRdrNames :: HsDecl GhcPs -> Maybe [RdrName]
sigRdrNames :: HsDecl GhcPs -> Maybe [RdrName]
sigRdrNames (SigD XSigD GhcPs
NoExtField (TypeSig XTypeSig GhcPs
NoExtField [Located (IdP GhcPs)]
ns LHsSigWcType GhcPs
_)) = [RdrName] -> Maybe [RdrName]
forall a. a -> Maybe a
Just ([RdrName] -> Maybe [RdrName]) -> [RdrName] -> Maybe [RdrName]
forall a b. (a -> b) -> a -> b
$ (Located RdrName -> RdrName) -> [Located RdrName] -> [RdrName]
forall a b. (a -> b) -> [a] -> [b]
map Located RdrName -> RdrName
forall l e. GenLocated l e -> e
unLoc [Located (IdP GhcPs)]
[Located RdrName]
ns
sigRdrNames (SigD XSigD GhcPs
NoExtField (ClassOpSig XClassOpSig GhcPs
NoExtField Bool
_ [Located (IdP GhcPs)]
ns LHsSigType GhcPs
_)) = [RdrName] -> Maybe [RdrName]
forall a. a -> Maybe a
Just ([RdrName] -> Maybe [RdrName]) -> [RdrName] -> Maybe [RdrName]
forall a b. (a -> b) -> a -> b
$ (Located RdrName -> RdrName) -> [Located RdrName] -> [RdrName]
forall a b. (a -> b) -> [a] -> [b]
map Located RdrName -> RdrName
forall l e. GenLocated l e -> e
unLoc [Located (IdP GhcPs)]
[Located RdrName]
ns
sigRdrNames (SigD XSigD GhcPs
NoExtField (PatSynSig XPatSynSig GhcPs
NoExtField [Located (IdP GhcPs)]
ns LHsSigType GhcPs
_)) = [RdrName] -> Maybe [RdrName]
forall a. a -> Maybe a
Just ([RdrName] -> Maybe [RdrName]) -> [RdrName] -> Maybe [RdrName]
forall a b. (a -> b) -> a -> b
$ (Located RdrName -> RdrName) -> [Located RdrName] -> [RdrName]
forall a b. (a -> b) -> [a] -> [b]
map Located RdrName -> RdrName
forall l e. GenLocated l e -> e
unLoc [Located (IdP GhcPs)]
[Located RdrName]
ns
sigRdrNames HsDecl GhcPs
_ = Maybe [RdrName]
forall a. Maybe a
Nothing

defSigRdrNames :: HsDecl GhcPs -> Maybe [RdrName]
defSigRdrNames :: HsDecl GhcPs -> Maybe [RdrName]
defSigRdrNames (SigD XSigD GhcPs
NoExtField (ClassOpSig XClassOpSig GhcPs
NoExtField Bool
True [Located (IdP GhcPs)]
ns LHsSigType GhcPs
_)) = [RdrName] -> Maybe [RdrName]
forall a. a -> Maybe a
Just ([RdrName] -> Maybe [RdrName]) -> [RdrName] -> Maybe [RdrName]
forall a b. (a -> b) -> a -> b
$ (Located RdrName -> RdrName) -> [Located RdrName] -> [RdrName]
forall a b. (a -> b) -> [a] -> [b]
map Located RdrName -> RdrName
forall l e. GenLocated l e -> e
unLoc [Located (IdP GhcPs)]
[Located RdrName]
ns
defSigRdrNames HsDecl GhcPs
_ = Maybe [RdrName]
forall a. Maybe a
Nothing

funRdrNames :: HsDecl GhcPs -> Maybe [RdrName]
funRdrNames :: HsDecl GhcPs -> Maybe [RdrName]
funRdrNames (ValD XValD GhcPs
NoExtField (FunBind XFunBind GhcPs GhcPs
NoExtField (L SrcSpan
_ IdP GhcPs
n) MatchGroup GhcPs (LHsExpr GhcPs)
_ [Tickish Id]
_)) = [RdrName] -> Maybe [RdrName]
forall a. a -> Maybe a
Just [IdP GhcPs
RdrName
n]
funRdrNames (ValD XValD GhcPs
NoExtField (PatBind XPatBind GhcPs GhcPs
NoExtField (L _ n) GRHSs GhcPs (LHsExpr GhcPs)
_ ([Tickish Id], [[Tickish Id]])
_)) = [RdrName] -> Maybe [RdrName]
forall a. a -> Maybe a
Just ([RdrName] -> Maybe [RdrName]) -> [RdrName] -> Maybe [RdrName]
forall a b. (a -> b) -> a -> b
$ Pat GhcPs -> [RdrName]
patBindNames Pat GhcPs
n
funRdrNames HsDecl GhcPs
_ = Maybe [RdrName]
forall a. Maybe a
Nothing

patSigRdrNames :: HsDecl GhcPs -> Maybe [RdrName]
patSigRdrNames :: HsDecl GhcPs -> Maybe [RdrName]
patSigRdrNames (SigD XSigD GhcPs
NoExtField (PatSynSig XPatSynSig GhcPs
NoExtField [Located (IdP GhcPs)]
ns LHsSigType GhcPs
_)) = [RdrName] -> Maybe [RdrName]
forall a. a -> Maybe a
Just ([RdrName] -> Maybe [RdrName]) -> [RdrName] -> Maybe [RdrName]
forall a b. (a -> b) -> a -> b
$ (Located RdrName -> RdrName) -> [Located RdrName] -> [RdrName]
forall a b. (a -> b) -> [a] -> [b]
map Located RdrName -> RdrName
forall l e. GenLocated l e -> e
unLoc [Located (IdP GhcPs)]
[Located RdrName]
ns
patSigRdrNames HsDecl GhcPs
_ = Maybe [RdrName]
forall a. Maybe a
Nothing

warnSigRdrNames :: HsDecl GhcPs -> Maybe [RdrName]
warnSigRdrNames :: HsDecl GhcPs -> Maybe [RdrName]
warnSigRdrNames (WarningD XWarningD GhcPs
NoExtField (Warnings XWarnings GhcPs
NoExtField SourceText
_ [LWarnDecl GhcPs]
ws)) = [RdrName] -> Maybe [RdrName]
forall a. a -> Maybe a
Just ([RdrName] -> Maybe [RdrName]) -> [RdrName] -> Maybe [RdrName]
forall a b. (a -> b) -> a -> b
$
  ((LWarnDecl GhcPs -> [RdrName]) -> [LWarnDecl GhcPs] -> [RdrName])
-> [LWarnDecl GhcPs] -> (LWarnDecl GhcPs -> [RdrName]) -> [RdrName]
forall a b c. (a -> b -> c) -> b -> a -> c
flip (LWarnDecl GhcPs -> [RdrName]) -> [LWarnDecl GhcPs] -> [RdrName]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap [LWarnDecl GhcPs]
ws ((LWarnDecl GhcPs -> [RdrName]) -> [RdrName])
-> (LWarnDecl GhcPs -> [RdrName]) -> [RdrName]
forall a b. (a -> b) -> a -> b
$ \(L SrcSpan
_ (Warning XWarning GhcPs
NoExtField [Located (IdP GhcPs)]
ns WarningTxt
_)) -> (Located RdrName -> RdrName) -> [Located RdrName] -> [RdrName]
forall a b. (a -> b) -> [a] -> [b]
map Located RdrName -> RdrName
forall l e. GenLocated l e -> e
unLoc [Located (IdP GhcPs)]
[Located RdrName]
ns
warnSigRdrNames HsDecl GhcPs
_ = Maybe [RdrName]
forall a. Maybe a
Nothing

patBindNames :: Pat GhcPs -> [RdrName]
patBindNames :: Pat GhcPs -> [RdrName]
patBindNames (TuplePat XTuplePat GhcPs
NoExtField [LPat GhcPs]
ps Boxity
_) = (GenLocated SrcSpan (Pat GhcPs) -> [RdrName])
-> [GenLocated SrcSpan (Pat GhcPs)] -> [RdrName]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Pat GhcPs -> [RdrName]
patBindNames (Pat GhcPs -> [RdrName])
-> (GenLocated SrcSpan (Pat GhcPs) -> Pat GhcPs)
-> GenLocated SrcSpan (Pat GhcPs)
-> [RdrName]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpan (Pat GhcPs) -> Pat GhcPs
forall l e. GenLocated l e -> e
unLoc) [LPat GhcPs]
[GenLocated SrcSpan (Pat GhcPs)]
ps
patBindNames (VarPat XVarPat GhcPs
NoExtField (L SrcSpan
_ IdP GhcPs
n)) = [IdP GhcPs
RdrName
n]
patBindNames (WildPat XWildPat GhcPs
NoExtField) = []
patBindNames (LazyPat XLazyPat GhcPs
NoExtField (L _ p)) = Pat GhcPs -> [RdrName]
patBindNames Pat GhcPs
p
patBindNames (BangPat XBangPat GhcPs
NoExtField (L _ p)) = Pat GhcPs -> [RdrName]
patBindNames Pat GhcPs
p
patBindNames (ParPat XParPat GhcPs
NoExtField (L _ p)) = Pat GhcPs -> [RdrName]
patBindNames Pat GhcPs
p
patBindNames (ListPat XListPat GhcPs
NoExtField [LPat GhcPs]
ps) = (GenLocated SrcSpan (Pat GhcPs) -> [RdrName])
-> [GenLocated SrcSpan (Pat GhcPs)] -> [RdrName]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Pat GhcPs -> [RdrName]
patBindNames (Pat GhcPs -> [RdrName])
-> (GenLocated SrcSpan (Pat GhcPs) -> Pat GhcPs)
-> GenLocated SrcSpan (Pat GhcPs)
-> [RdrName]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpan (Pat GhcPs) -> Pat GhcPs
forall l e. GenLocated l e -> e
unLoc) [LPat GhcPs]
[GenLocated SrcSpan (Pat GhcPs)]
ps
patBindNames (AsPat XAsPat GhcPs
NoExtField (L SrcSpan
_ IdP GhcPs
n) (L _ p)) = IdP GhcPs
RdrName
n RdrName -> [RdrName] -> [RdrName]
forall a. a -> [a] -> [a]
: Pat GhcPs -> [RdrName]
patBindNames Pat GhcPs
p
patBindNames (SumPat XSumPat GhcPs
NoExtField (L _ p) Int
_ Int
_) = Pat GhcPs -> [RdrName]
patBindNames Pat GhcPs
p
patBindNames (ViewPat XViewPat GhcPs
NoExtField LHsExpr GhcPs
_ (L _ p)) = Pat GhcPs -> [RdrName]
patBindNames Pat GhcPs
p
patBindNames (SplicePat XSplicePat GhcPs
NoExtField HsSplice GhcPs
_) = []
patBindNames (LitPat XLitPat GhcPs
NoExtField HsLit GhcPs
_) = []
patBindNames (SigPat XSigPat GhcPs
_ (L _ p) HsPatSigType (NoGhcTc GhcPs)
_) = Pat GhcPs -> [RdrName]
patBindNames Pat GhcPs
p
patBindNames (NPat XNPat GhcPs
NoExtField Located (HsOverLit GhcPs)
_ Maybe (SyntaxExpr GhcPs)
_ SyntaxExpr GhcPs
_) = []
patBindNames (NPlusKPat XNPlusKPat GhcPs
NoExtField (L SrcSpan
_ IdP GhcPs
n) Located (HsOverLit GhcPs)
_ HsOverLit GhcPs
_ SyntaxExpr GhcPs
_ SyntaxExpr GhcPs
_) = [IdP GhcPs
RdrName
n]
patBindNames (ConPat XConPat GhcPs
NoExtField Located (ConLikeP GhcPs)
_ HsConPatDetails GhcPs
d) = (GenLocated SrcSpan (Pat GhcPs) -> [RdrName])
-> [GenLocated SrcSpan (Pat GhcPs)] -> [RdrName]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Pat GhcPs -> [RdrName]
patBindNames (Pat GhcPs -> [RdrName])
-> (GenLocated SrcSpan (Pat GhcPs) -> Pat GhcPs)
-> GenLocated SrcSpan (Pat GhcPs)
-> [RdrName]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated SrcSpan (Pat GhcPs) -> Pat GhcPs
forall l e. GenLocated l e -> e
unLoc) (HsConPatDetails GhcPs -> [LPat GhcPs]
forall p. HsConPatDetails p -> [LPat p]
hsConPatArgs HsConPatDetails GhcPs
d)