{-# LANGUAGE BlockArguments   #-}
{-# LANGUAGE DataKinds        #-}
{-# LANGUAGE DoAndIfThenElse  #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase       #-}
{-# LANGUAGE MultiWayIf       #-}
{-# LANGUAGE NamedFieldPuns   #-}
{-# LANGUAGE RecordWildCards  #-}
module Language.Haskell.Stylish.Step.Data
  ( Config(..)
  , defaultConfig

  , Indent(..)
  , MaxColumns(..)
  , step
  ) where


--------------------------------------------------------------------------------
import           Control.Monad                     (forM_, unless, when)
import           Data.List                         (sortBy)
import           Data.Maybe                        (listToMaybe, maybeToList)
import qualified GHC.Hs                            as GHC
import qualified GHC.Types.Fixity                  as GHC
import qualified GHC.Types.Name.Reader             as GHC
import qualified GHC.Types.SrcLoc                  as GHC
import           Prelude                           hiding (init)


--------------------------------------------------------------------------------
import           Language.Haskell.Stylish.Comments
import qualified Language.Haskell.Stylish.Editor   as Editor
import           Language.Haskell.Stylish.GHC
import           Language.Haskell.Stylish.Module
import           Language.Haskell.Stylish.Ordering
import           Language.Haskell.Stylish.Printer
import           Language.Haskell.Stylish.Step
import           Language.Haskell.Stylish.Util


--------------------------------------------------------------------------------
data Indent
    = SameLine
    | Indent !Int
  deriving (Int -> Indent -> ShowS
[Indent] -> ShowS
Indent -> String
(Int -> Indent -> ShowS)
-> (Indent -> String) -> ([Indent] -> ShowS) -> Show Indent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Indent] -> ShowS
$cshowList :: [Indent] -> ShowS
show :: Indent -> String
$cshow :: Indent -> String
showsPrec :: Int -> Indent -> ShowS
$cshowsPrec :: Int -> Indent -> ShowS
Show, Indent -> Indent -> Bool
(Indent -> Indent -> Bool)
-> (Indent -> Indent -> Bool) -> Eq Indent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Indent -> Indent -> Bool
$c/= :: Indent -> Indent -> Bool
== :: Indent -> Indent -> Bool
$c== :: Indent -> Indent -> Bool
Eq)

data MaxColumns
  = MaxColumns !Int
  | NoMaxColumns
  deriving (Int -> MaxColumns -> ShowS
[MaxColumns] -> ShowS
MaxColumns -> String
(Int -> MaxColumns -> ShowS)
-> (MaxColumns -> String)
-> ([MaxColumns] -> ShowS)
-> Show MaxColumns
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MaxColumns] -> ShowS
$cshowList :: [MaxColumns] -> ShowS
show :: MaxColumns -> String
$cshow :: MaxColumns -> String
showsPrec :: Int -> MaxColumns -> ShowS
$cshowsPrec :: Int -> MaxColumns -> ShowS
Show, MaxColumns -> MaxColumns -> Bool
(MaxColumns -> MaxColumns -> Bool)
-> (MaxColumns -> MaxColumns -> Bool) -> Eq MaxColumns
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MaxColumns -> MaxColumns -> Bool
$c/= :: MaxColumns -> MaxColumns -> Bool
== :: MaxColumns -> MaxColumns -> Bool
$c== :: MaxColumns -> MaxColumns -> Bool
Eq)

data Config = Config
    { Config -> Indent
cEquals                  :: !Indent
      -- ^ Indent between type constructor and @=@ sign (measured from column 0)
    , Config -> Indent
cFirstField              :: !Indent
      -- ^ Indent between data constructor and @{@ line (measured from column with data constructor name)
    , Config -> Int
cFieldComment            :: !Int
      -- ^ Indent between column with @{@ and start of field line comment (this line has @cFieldComment = 2@)
    , Config -> Int
cDeriving                :: !Int
      -- ^ Indent before @deriving@ lines (measured from column 0)
    , Config -> Bool
cBreakEnums              :: !Bool
      -- ^ Break enums by newlines and follow the above rules
    , Config -> Bool
cBreakSingleConstructors :: !Bool
      -- ^ Break single constructors when enabled, e.g. @Indent 2@ will not cause newline after @=@
    , Config -> Indent
cVia                     :: !Indent
      -- ^ Indentation between @via@ clause and start of deriving column start
    , Config -> Bool
cCurriedContext          :: !Bool
      -- ^ If true, use curried context. E.g: @allValues :: Enum a => Bounded a => Proxy a -> [a]@
    , Config -> Bool
cSortDeriving            :: !Bool
      -- ^ If true, will sort type classes in a @deriving@ list.
    , Config -> MaxColumns
cMaxColumns              :: !MaxColumns
    } deriving (Int -> Config -> ShowS
[Config] -> ShowS
Config -> String
(Int -> Config -> ShowS)
-> (Config -> String) -> ([Config] -> ShowS) -> Show Config
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Config] -> ShowS
$cshowList :: [Config] -> ShowS
show :: Config -> String
$cshow :: Config -> String
showsPrec :: Int -> Config -> ShowS
$cshowsPrec :: Int -> Config -> ShowS
Show)

-- | TODO: pass in MaxColumns?
defaultConfig :: Config
defaultConfig :: Config
defaultConfig = Config :: Indent
-> Indent
-> Int
-> Int
-> Bool
-> Bool
-> Indent
-> Bool
-> Bool
-> MaxColumns
-> Config
Config
    { cEquals :: Indent
cEquals          = Int -> Indent
Indent Int
4
    , cFirstField :: Indent
cFirstField      = Int -> Indent
Indent Int
4
    , cFieldComment :: Int
cFieldComment    = Int
2
    , cDeriving :: Int
cDeriving        = Int
4
    , cBreakEnums :: Bool
cBreakEnums      = Bool
True
    , cBreakSingleConstructors :: Bool
cBreakSingleConstructors = Bool
False
    , cVia :: Indent
cVia             = Int -> Indent
Indent Int
4
    , cSortDeriving :: Bool
cSortDeriving    = Bool
True
    , cMaxColumns :: MaxColumns
cMaxColumns      = MaxColumns
NoMaxColumns
    , cCurriedContext :: Bool
cCurriedContext    = Bool
False
    }

step :: Config -> Step
step :: Config -> Step
step Config
cfg = String -> (Lines -> Module -> Lines) -> Step
makeStep String
"Data" \Lines
ls Module
m -> Edits -> Lines -> Lines
Editor.apply (Module -> Edits
changes Module
m) Lines
ls
  where
    changes :: Module -> Editor.Edits
    changes :: Module -> Edits
changes = (DataDecl -> Edits) -> [DataDecl] -> Edits
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Config -> DataDecl -> Edits
formatDataDecl Config
cfg) ([DataDecl] -> Edits) -> (Module -> [DataDecl]) -> Module -> Edits
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Module -> [DataDecl]
dataDecls

    dataDecls :: Module -> [DataDecl]
    dataDecls :: Module -> [DataDecl]
dataDecls Module
m = do
        GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
ldecl <- HsModule -> [LHsDecl GhcPs]
GHC.hsmodDecls (HsModule -> [LHsDecl GhcPs]) -> HsModule -> [LHsDecl GhcPs]
forall a b. (a -> b) -> a -> b
$ Module -> HsModule
forall l e. GenLocated l e -> e
GHC.unLoc Module
m
        GHC.TyClD XTyClD GhcPs
_ TyClDecl GhcPs
tycld <- HsDecl GhcPs -> [HsDecl GhcPs]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (HsDecl GhcPs -> [HsDecl GhcPs]) -> HsDecl GhcPs -> [HsDecl GhcPs]
forall a b. (a -> b) -> a -> b
$ GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
-> HsDecl GhcPs
forall l e. GenLocated l e -> e
GHC.unLoc GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
ldecl
        RealSrcSpan
loc <- Maybe RealSrcSpan -> [RealSrcSpan]
forall a. Maybe a -> [a]
maybeToList (Maybe RealSrcSpan -> [RealSrcSpan])
-> Maybe RealSrcSpan -> [RealSrcSpan]
forall a b. (a -> b) -> a -> b
$ SrcSpan -> Maybe RealSrcSpan
GHC.srcSpanToRealSrcSpan (SrcSpan -> Maybe RealSrcSpan) -> SrcSpan -> Maybe RealSrcSpan
forall a b. (a -> b) -> a -> b
$ GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
-> SrcSpan
forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
GHC.getLocA GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
ldecl
        case TyClDecl GhcPs
tycld of
            GHC.DataDecl {HsDataDefn GhcPs
LHsQTyVars GhcPs
LIdP GhcPs
XDataDecl GhcPs
LexicalFixity
tcdLName :: forall pass. TyClDecl pass -> LIdP pass
tcdTyVars :: forall pass. TyClDecl pass -> LHsQTyVars pass
tcdFixity :: forall pass. TyClDecl pass -> LexicalFixity
tcdDExt :: forall pass. TyClDecl pass -> XDataDecl pass
tcdDataDefn :: forall pass. TyClDecl pass -> HsDataDefn pass
tcdDataDefn :: HsDataDefn GhcPs
tcdFixity :: LexicalFixity
tcdTyVars :: LHsQTyVars GhcPs
tcdLName :: LIdP GhcPs
tcdDExt :: XDataDecl GhcPs
..} -> DataDecl -> [DataDecl]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (DataDecl -> [DataDecl]) -> DataDecl -> [DataDecl]
forall a b. (a -> b) -> a -> b
$ MkDataDecl :: [LEpaComment]
-> RealSrcSpan
-> LocatedN RdrName
-> LHsQTyVars GhcPs
-> HsDataDefn GhcPs
-> LexicalFixity
-> DataDecl
MkDataDecl
                { dataComments :: [LEpaComment]
dataComments = EpAnn [AddEpAnn] -> [LEpaComment]
forall a. EpAnn a -> [LEpaComment]
epAnnComments XDataDecl GhcPs
EpAnn [AddEpAnn]
tcdDExt
                , dataLoc :: RealSrcSpan
dataLoc      = RealSrcSpan
loc
                , dataDeclName :: LocatedN RdrName
dataDeclName = LIdP GhcPs
LocatedN RdrName
tcdLName
                , dataTypeVars :: LHsQTyVars GhcPs
dataTypeVars = LHsQTyVars GhcPs
tcdTyVars
                , dataDefn :: HsDataDefn GhcPs
dataDefn     = HsDataDefn GhcPs
tcdDataDefn
                , dataFixity :: LexicalFixity
dataFixity   = LexicalFixity
tcdFixity
                }
            TyClDecl GhcPs
_ -> []

data DataDecl = MkDataDecl
    { DataDecl -> [LEpaComment]
dataComments :: [GHC.LEpaComment]
    , DataDecl -> RealSrcSpan
dataLoc      :: GHC.RealSrcSpan
    , DataDecl -> LocatedN RdrName
dataDeclName :: GHC.LocatedN GHC.RdrName
    , DataDecl -> LHsQTyVars GhcPs
dataTypeVars :: GHC.LHsQTyVars GHC.GhcPs
    , DataDecl -> HsDataDefn GhcPs
dataDefn     :: GHC.HsDataDefn GHC.GhcPs
    , DataDecl -> LexicalFixity
dataFixity   :: GHC.LexicalFixity
    }


formatDataDecl :: Config -> DataDecl -> Editor.Edits
formatDataDecl :: Config -> DataDecl -> Edits
formatDataDecl cfg :: Config
cfg@Config{Bool
Int
MaxColumns
Indent
cMaxColumns :: MaxColumns
cSortDeriving :: Bool
cCurriedContext :: Bool
cVia :: Indent
cBreakSingleConstructors :: Bool
cBreakEnums :: Bool
cDeriving :: Int
cFieldComment :: Int
cFirstField :: Indent
cEquals :: Indent
cMaxColumns :: Config -> MaxColumns
cSortDeriving :: Config -> Bool
cCurriedContext :: Config -> Bool
cVia :: Config -> Indent
cBreakSingleConstructors :: Config -> Bool
cBreakEnums :: Config -> Bool
cDeriving :: Config -> Int
cFieldComment :: Config -> Int
cFirstField :: Config -> Indent
cEquals :: Config -> Indent
..} decl :: DataDecl
decl@MkDataDecl {[LEpaComment]
HsDataDefn GhcPs
LHsQTyVars GhcPs
LexicalFixity
RealSrcSpan
LocatedN RdrName
dataFixity :: LexicalFixity
dataDefn :: HsDataDefn GhcPs
dataTypeVars :: LHsQTyVars GhcPs
dataDeclName :: LocatedN RdrName
dataLoc :: RealSrcSpan
dataComments :: [LEpaComment]
dataFixity :: DataDecl -> LexicalFixity
dataDefn :: DataDecl -> HsDataDefn GhcPs
dataTypeVars :: DataDecl -> LHsQTyVars GhcPs
dataDeclName :: DataDecl -> LocatedN RdrName
dataLoc :: DataDecl -> RealSrcSpan
dataComments :: DataDecl -> [LEpaComment]
..} =
    Block String -> (Lines -> Lines) -> Edits
Editor.changeLines Block String
forall a. Block a
originalDeclBlock (Lines -> Lines -> Lines
forall a b. a -> b -> a
const Lines
printedDecl)
  where
    originalDeclBlock :: Block a
originalDeclBlock = Int -> Int -> Block a
forall a. Int -> Int -> Block a
Editor.Block
        (RealSrcSpan -> Int
GHC.srcSpanStartLine RealSrcSpan
dataLoc)
        (RealSrcSpan -> Int
GHC.srcSpanEndLine RealSrcSpan
dataLoc)

    printerConfig :: PrinterConfig
printerConfig = PrinterConfig :: Maybe Int -> PrinterConfig
PrinterConfig
        { columns :: Maybe Int
columns = case MaxColumns
cMaxColumns of
            MaxColumns
NoMaxColumns -> Maybe Int
forall a. Maybe a
Nothing
            MaxColumns Int
n -> Int -> Maybe Int
forall a. a -> Maybe a
Just Int
n
        }

    printedDecl :: Lines
printedDecl = PrinterConfig -> Printer () -> Lines
forall a. PrinterConfig -> Printer a -> Lines
runPrinter_ PrinterConfig
printerConfig (Printer () -> Lines) -> Printer () -> Lines
forall a b. (a -> b) -> a -> b
$ Config -> DataDecl -> Printer ()
putDataDecl Config
cfg DataDecl
decl

putDataDecl :: Config -> DataDecl -> P ()
putDataDecl :: Config -> DataDecl -> Printer ()
putDataDecl cfg :: Config
cfg@Config {Bool
Int
MaxColumns
Indent
cMaxColumns :: MaxColumns
cSortDeriving :: Bool
cCurriedContext :: Bool
cVia :: Indent
cBreakSingleConstructors :: Bool
cBreakEnums :: Bool
cDeriving :: Int
cFieldComment :: Int
cFirstField :: Indent
cEquals :: Indent
cMaxColumns :: Config -> MaxColumns
cSortDeriving :: Config -> Bool
cCurriedContext :: Config -> Bool
cVia :: Config -> Indent
cBreakSingleConstructors :: Config -> Bool
cBreakEnums :: Config -> Bool
cDeriving :: Config -> Int
cFieldComment :: Config -> Int
cFirstField :: Config -> Indent
cEquals :: Config -> Indent
..} DataDecl
decl = do
    let defn :: HsDataDefn GhcPs
defn = DataDecl -> HsDataDefn GhcPs
dataDefn DataDecl
decl
        constructorComments :: [CommentGroup
   (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs))]
constructorComments = (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)
 -> Maybe RealSrcSpan)
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
-> [LEpaComment]
-> [CommentGroup
      (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs))]
forall a.
(a -> Maybe RealSrcSpan)
-> [a] -> [LEpaComment] -> [CommentGroup a]
commentGroups
            (SrcSpan -> Maybe RealSrcSpan
GHC.srcSpanToRealSrcSpan (SrcSpan -> Maybe RealSrcSpan)
-> (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)
    -> SrcSpan)
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)
-> Maybe RealSrcSpan
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)
-> SrcSpan
forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
GHC.getLocA)
            (HsDataDefn GhcPs -> [LConDecl GhcPs]
forall pass. HsDataDefn pass -> [LConDecl pass]
GHC.dd_cons HsDataDefn GhcPs
defn)
            (DataDecl -> [LEpaComment]
dataComments DataDecl
decl)

        onelineEnum :: Bool
onelineEnum =
            DataDecl -> Bool
isEnum DataDecl
decl Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
cBreakEnums Bool -> Bool -> Bool
&&
            (CommentGroup
   (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs))
 -> Bool)
-> [CommentGroup
      (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs))]
-> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Bool -> Bool
not (Bool -> Bool)
-> (CommentGroup
      (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs))
    -> Bool)
-> CommentGroup
     (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs))
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CommentGroup
  (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs))
-> Bool
forall a. CommentGroup a -> Bool
commentGroupHasComments) [CommentGroup
   (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs))]
constructorComments

    String -> Printer ()
putText (String -> Printer ()) -> String -> Printer ()
forall a b. (a -> b) -> a -> b
$ DataDecl -> String
newOrData DataDecl
decl
    Printer ()
space
    DataDecl -> Printer ()
putName DataDecl
decl

    Bool -> Printer () -> Printer ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (DataDecl -> Bool
isGADT DataDecl
decl) (Printer ()
space Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Printer ()
putText String
"where")

    Bool -> Printer () -> Printer ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (DataDecl -> Bool
hasConstructors DataDecl
decl) do
        case (Indent
cEquals, Indent
cFirstField) of
            (Indent
_, Indent Int
x) | DataDecl -> Bool
isEnum DataDecl
decl Bool -> Bool -> Bool
&& Bool
cBreakEnums -> Printer ()
newline Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Printer ()
spaces Int
x
            (Indent
_, Indent
_)
                | Bool -> Bool
not (DataDecl -> Bool
isNewtype DataDecl
decl)
                , DataDecl -> Bool
singleConstructor DataDecl
decl Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
cBreakSingleConstructors ->
                    Printer ()
space
            (Indent Int
x, Indent
_)
                | Bool
onelineEnum -> Printer ()
space
                | Bool
otherwise -> Printer ()
newline Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Printer ()
spaces Int
x
            (Indent
SameLine, Indent
_) -> Printer ()
space

        Int
lineLengthAfterEq <- (Int -> Int) -> Printer Int -> Printer Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
2) Printer Int
getCurrentLineLength

        if  | Bool
onelineEnum ->
                String -> Printer ()
putText String
"=" Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Printer ()
space Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Config -> DataDecl -> Printer ()
putUnbrokenEnum Config
cfg DataDecl
decl
            | DataDecl -> Bool
isNewtype DataDecl
decl -> do
                String -> Printer ()
putText String
"=" Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Printer ()
space
                [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
-> (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)
    -> Printer ())
-> Printer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (HsDataDefn GhcPs -> [LConDecl GhcPs]
forall pass. HsDataDefn pass -> [LConDecl pass]
GHC.dd_cons HsDataDefn GhcPs
defn) ((GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)
  -> Printer ())
 -> Printer ())
-> (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)
    -> Printer ())
-> Printer ()
forall a b. (a -> b) -> a -> b
$ Config -> LConDecl GhcPs -> Printer ()
putNewtypeConstructor Config
cfg
            | Bool -> Bool
not (Bool -> Bool)
-> ([GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
    -> Bool)
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
-> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
 -> Bool)
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
-> Bool
forall a b. (a -> b) -> a -> b
$ HsDataDefn GhcPs -> [LConDecl GhcPs]
forall pass. HsDataDefn pass -> [LConDecl pass]
GHC.dd_cons HsDataDefn GhcPs
defn -> do
                [(CommentGroup
    (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)),
  Bool, Bool)]
-> ((CommentGroup
       (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)),
     Bool, Bool)
    -> Printer ())
-> Printer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ ([CommentGroup
   (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs))]
-> [(CommentGroup
       (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)),
     Bool, Bool)]
forall a. [a] -> [(a, Bool, Bool)]
flagEnds [CommentGroup
   (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs))]
constructorComments) (((CommentGroup
     (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)),
   Bool, Bool)
  -> Printer ())
 -> Printer ())
-> ((CommentGroup
       (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)),
     Bool, Bool)
    -> Printer ())
-> Printer ()
forall a b. (a -> b) -> a -> b
$ \(CommentGroup {[(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs),
  Maybe LEpaComment)]
[LEpaComment]
Block String
cgFollowing :: forall a. CommentGroup a -> [LEpaComment]
cgItems :: forall a. CommentGroup a -> [(a, Maybe LEpaComment)]
cgPrior :: forall a. CommentGroup a -> [LEpaComment]
cgBlock :: forall a. CommentGroup a -> Block String
cgFollowing :: [LEpaComment]
cgItems :: [(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs),
  Maybe LEpaComment)]
cgPrior :: [LEpaComment]
cgBlock :: Block String
..}, Bool
firstGroup, Bool
lastGroup) -> do
                    [LEpaComment] -> (LEpaComment -> Printer ()) -> Printer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [LEpaComment]
cgPrior ((LEpaComment -> Printer ()) -> Printer ())
-> (LEpaComment -> Printer ()) -> Printer ()
forall a b. (a -> b) -> a -> b
$ \LEpaComment
lc -> do
                        EpaComment -> Printer ()
putComment (EpaComment -> Printer ()) -> EpaComment -> Printer ()
forall a b. (a -> b) -> a -> b
$ LEpaComment -> EpaComment
forall l e. GenLocated l e -> e
GHC.unLoc LEpaComment
lc
                        Int -> Printer ()
consIndent Int
lineLengthAfterEq

                    [((GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs),
   Maybe LEpaComment),
  Bool, Bool)]
-> (((GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs),
      Maybe LEpaComment),
     Bool, Bool)
    -> Printer ())
-> Printer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ ([(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs),
  Maybe LEpaComment)]
-> [((GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs),
      Maybe LEpaComment),
     Bool, Bool)]
forall a. [a] -> [(a, Bool, Bool)]
flagEnds [(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs),
  Maybe LEpaComment)]
cgItems) ((((GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs),
    Maybe LEpaComment),
   Bool, Bool)
  -> Printer ())
 -> Printer ())
-> (((GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs),
      Maybe LEpaComment),
     Bool, Bool)
    -> Printer ())
-> Printer ()
forall a b. (a -> b) -> a -> b
$ \((GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)
lcon, Maybe LEpaComment
mbInlineComment), Bool
firstItem, Bool
lastItem) -> do
                        Bool -> Printer () -> Printer ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (DataDecl -> Bool
isGADT DataDecl
decl) (Printer () -> Printer ()) -> Printer () -> Printer ()
forall a b. (a -> b) -> a -> b
$ do
                            String -> Printer ()
putText (String -> Printer ()) -> String -> Printer ()
forall a b. (a -> b) -> a -> b
$ if Bool
firstGroup Bool -> Bool -> Bool
&& Bool
firstItem then String
"=" else String
"|"
                            Printer ()
space
                        Config -> Int -> LConDecl GhcPs -> Printer ()
putConstructor Config
cfg Int
lineLengthAfterEq LConDecl GhcPs
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)
lcon
                        Maybe EpaComment -> Printer ()
putMaybeLineComment (Maybe EpaComment -> Printer ()) -> Maybe EpaComment -> Printer ()
forall a b. (a -> b) -> a -> b
$ LEpaComment -> EpaComment
forall l e. GenLocated l e -> e
GHC.unLoc (LEpaComment -> EpaComment)
-> Maybe LEpaComment -> Maybe EpaComment
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe LEpaComment
mbInlineComment
                        Bool -> Printer () -> Printer ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Bool
lastGroup Bool -> Bool -> Bool
&& Bool
lastItem) (Printer () -> Printer ()) -> Printer () -> Printer ()
forall a b. (a -> b) -> a -> b
$
                            Int -> Printer ()
consIndent Int
lineLengthAfterEq

                    [LEpaComment] -> (LEpaComment -> Printer ()) -> Printer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [LEpaComment]
cgFollowing ((LEpaComment -> Printer ()) -> Printer ())
-> (LEpaComment -> Printer ()) -> Printer ()
forall a b. (a -> b) -> a -> b
$ \LEpaComment
lc -> do
                        Int -> Printer ()
consIndent Int
lineLengthAfterEq
                        EpaComment -> Printer ()
putComment (EpaComment -> Printer ()) -> EpaComment -> Printer ()
forall a b. (a -> b) -> a -> b
$ LEpaComment -> EpaComment
forall l e. GenLocated l e -> e
GHC.unLoc LEpaComment
lc

            | Bool
otherwise ->
                () -> Printer ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()

    let derivingComments :: [LEpaComment]
derivingComments = [GenLocated SrcSpan (HsDerivingClause GhcPs)] -> [LEpaComment]
forall a. (Data a, Typeable a) => a -> [LEpaComment]
deepAnnComments (HsDataDefn GhcPs -> HsDeriving GhcPs
forall pass. HsDataDefn pass -> HsDeriving pass
GHC.dd_derivs HsDataDefn GhcPs
defn)

    Bool -> Printer () -> Printer ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (DataDecl -> Bool
hasDeriving DataDecl
decl) do
        if Bool
onelineEnum Bool -> Bool -> Bool
&& [LEpaComment] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LEpaComment]
derivingComments then
            Printer ()
space
        else do
            [LEpaComment] -> (LEpaComment -> Printer ()) -> Printer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [LEpaComment]
derivingComments ((LEpaComment -> Printer ()) -> Printer ())
-> (LEpaComment -> Printer ()) -> Printer ()
forall a b. (a -> b) -> a -> b
$ \LEpaComment
lc -> do
                Printer ()
newline
                Int -> Printer ()
spaces Int
cDeriving
                EpaComment -> Printer ()
putComment (EpaComment -> Printer ()) -> EpaComment -> Printer ()
forall a b. (a -> b) -> a -> b
$ LEpaComment -> EpaComment
forall l e. GenLocated l e -> e
GHC.unLoc LEpaComment
lc
            Printer ()
newline
            Int -> Printer ()
spaces Int
cDeriving

        Printer () -> [Printer ()] -> Printer ()
forall a. P a -> [P a] -> Printer ()
sep (Printer ()
newline Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Printer ()
spaces Int
cDeriving) ([Printer ()] -> Printer ()) -> [Printer ()] -> Printer ()
forall a b. (a -> b) -> a -> b
$ (GenLocated SrcSpan (HsDerivingClause GhcPs) -> Printer ())
-> [GenLocated SrcSpan (HsDerivingClause GhcPs)] -> [Printer ()]
forall a b. (a -> b) -> [a] -> [b]
map
            (Config -> LHsDerivingClause GhcPs -> Printer ()
putDeriving Config
cfg)
            (HsDataDefn GhcPs -> HsDeriving GhcPs
forall pass. HsDataDefn pass -> HsDeriving pass
GHC.dd_derivs HsDataDefn GhcPs
defn)
  where
    consIndent :: Int -> Printer ()
consIndent Int
eqIndent = Printer ()
newline Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> case (Indent
cEquals, Indent
cFirstField) of
        (Indent
SameLine, Indent
SameLine) -> Int -> Printer ()
spaces (Int
eqIndent Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
2)
        (Indent
SameLine, Indent Int
y) -> Int -> Printer ()
spaces (Int
eqIndent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
y Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
4)
        (Indent Int
x, Indent Int
_) -> Int -> Printer ()
spaces Int
x
        (Indent Int
x, Indent
SameLine) -> Int -> Printer ()
spaces Int
x

derivingClauseTypes
    :: GHC.HsDerivingClause GHC.GhcPs -> [GHC.LHsSigType GHC.GhcPs]
derivingClauseTypes :: HsDerivingClause GhcPs -> [LHsSigType GhcPs]
derivingClauseTypes GHC.HsDerivingClause {Maybe (LDerivStrategy GhcPs)
LDerivClauseTys GhcPs
XCHsDerivingClause GhcPs
deriv_clause_ext :: forall pass. HsDerivingClause pass -> XCHsDerivingClause pass
deriv_clause_strategy :: forall pass. HsDerivingClause pass -> Maybe (LDerivStrategy pass)
deriv_clause_tys :: forall pass. HsDerivingClause pass -> LDerivClauseTys pass
deriv_clause_tys :: LDerivClauseTys GhcPs
deriv_clause_strategy :: Maybe (LDerivStrategy GhcPs)
deriv_clause_ext :: XCHsDerivingClause GhcPs
..} =
    case GenLocated SrcSpanAnnC (DerivClauseTys GhcPs)
-> DerivClauseTys GhcPs
forall l e. GenLocated l e -> e
GHC.unLoc LDerivClauseTys GhcPs
GenLocated SrcSpanAnnC (DerivClauseTys GhcPs)
deriv_clause_tys of
        GHC.DctSingle XDctSingle GhcPs
_ LHsSigType GhcPs
t -> [LHsSigType GhcPs
t]
        GHC.DctMulti XDctMulti GhcPs
_ [LHsSigType GhcPs]
ts -> [LHsSigType GhcPs]
ts

putDeriving :: Config -> GHC.LHsDerivingClause GHC.GhcPs -> P ()
putDeriving :: Config -> LHsDerivingClause GhcPs -> Printer ()
putDeriving Config{Bool
Int
MaxColumns
Indent
cMaxColumns :: MaxColumns
cSortDeriving :: Bool
cCurriedContext :: Bool
cVia :: Indent
cBreakSingleConstructors :: Bool
cBreakEnums :: Bool
cDeriving :: Int
cFieldComment :: Int
cFirstField :: Indent
cEquals :: Indent
cMaxColumns :: Config -> MaxColumns
cSortDeriving :: Config -> Bool
cCurriedContext :: Config -> Bool
cVia :: Config -> Indent
cBreakSingleConstructors :: Config -> Bool
cBreakEnums :: Config -> Bool
cDeriving :: Config -> Int
cFieldComment :: Config -> Int
cFirstField :: Config -> Indent
cEquals :: Config -> Indent
..} LHsDerivingClause GhcPs
lclause = do
    let clause :: HsDerivingClause GhcPs
clause@GHC.HsDerivingClause {Maybe (LDerivStrategy GhcPs)
LDerivClauseTys GhcPs
XCHsDerivingClause GhcPs
deriv_clause_tys :: LDerivClauseTys GhcPs
deriv_clause_strategy :: Maybe (LDerivStrategy GhcPs)
deriv_clause_ext :: XCHsDerivingClause GhcPs
deriv_clause_ext :: forall pass. HsDerivingClause pass -> XCHsDerivingClause pass
deriv_clause_strategy :: forall pass. HsDerivingClause pass -> Maybe (LDerivStrategy pass)
deriv_clause_tys :: forall pass. HsDerivingClause pass -> LDerivClauseTys pass
..} = GenLocated SrcSpan (HsDerivingClause GhcPs)
-> HsDerivingClause GhcPs
forall l e. GenLocated l e -> e
GHC.unLoc LHsDerivingClause GhcPs
GenLocated SrcSpan (HsDerivingClause GhcPs)
lclause
        tys :: [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
tys = (if Bool
cSortDeriving then (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
 -> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
 -> Ordering)
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
-> Ordering
forall a. Outputable a => a -> a -> Ordering
compareOutputableCI else [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
forall a. a -> a
id) ([GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
 -> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)])
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
forall a b. (a -> b) -> a -> b
$
            (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsSigType GhcPs)
 -> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsSigType GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
forall a b. (a -> b) -> [a] -> [b]
map (HsSigType GhcPs
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
forall pass. HsSigType pass -> LHsType pass
GHC.sig_body (HsSigType GhcPs
 -> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
-> (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsSigType GhcPs)
    -> HsSigType GhcPs)
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsSigType GhcPs)
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsSigType GhcPs)
-> HsSigType GhcPs
forall l e. GenLocated l e -> e
GHC.unLoc) ([GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsSigType GhcPs)]
 -> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)])
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsSigType GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
forall a b. (a -> b) -> a -> b
$
            HsDerivingClause GhcPs -> [LHsSigType GhcPs]
derivingClauseTypes HsDerivingClause GhcPs
clause
        headTy :: Maybe (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
headTy = [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
-> Maybe
     (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
forall a. [a] -> Maybe a
listToMaybe [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
tys
        tailTy :: [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
tailTy = Int
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
forall a. Int -> [a] -> [a]
drop Int
1 [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
tys

    String -> Printer ()
putText String
"deriving"

    Maybe (GenLocated SrcSpan (DerivStrategy GhcPs))
-> (GenLocated SrcSpan (DerivStrategy GhcPs) -> Printer ())
-> Printer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ Maybe (GenLocated SrcSpan (DerivStrategy GhcPs))
deriv_clause_strategy ((GenLocated SrcSpan (DerivStrategy GhcPs) -> Printer ())
 -> Printer ())
-> (GenLocated SrcSpan (DerivStrategy GhcPs) -> Printer ())
-> Printer ()
forall a b. (a -> b) -> a -> b
$ \GenLocated SrcSpan (DerivStrategy GhcPs)
lstrat -> case GenLocated SrcSpan (DerivStrategy GhcPs) -> DerivStrategy GhcPs
forall l e. GenLocated l e -> e
GHC.unLoc GenLocated SrcSpan (DerivStrategy GhcPs)
lstrat of
        GHC.StockStrategy    {} -> Printer ()
space Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Printer ()
putText String
"stock"
        GHC.AnyclassStrategy {} -> Printer ()
space Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Printer ()
putText String
"anyclass"
        GHC.NewtypeStrategy  {} -> Printer ()
space Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Printer ()
putText String
"newtype"
        GHC.ViaStrategy      {} -> () -> Printer ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()

    (PrinterState -> Bool) -> Printer () -> Printer () -> Printer ()
forall b. (PrinterState -> Bool) -> P b -> P b -> P b
putCond
        PrinterState -> Bool
withinColumns
        do
            Printer ()
space
            String -> Printer ()
putText String
"("
            Printer () -> [Printer ()] -> Printer ()
forall a. P a -> [P a] -> Printer ()
sep
                (Printer ()
comma Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Printer ()
space)
                ((GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
 -> Printer ())
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
-> [Printer ()]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
-> Printer ()
forall a. Outputable a => a -> Printer ()
putOutputable [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
tys)
            String -> Printer ()
putText String
")"
        do
            Printer ()
newline
            Int -> Printer ()
spaces Int
indentation
            String -> Printer ()
putText String
"("

            Maybe (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
-> (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
    -> Printer ())
-> Printer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ Maybe (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
headTy \GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
t ->
                Printer ()
space Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
-> Printer ()
forall a. Outputable a => a -> Printer ()
putOutputable GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
t

            [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
-> (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
    -> Printer ())
-> Printer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
tailTy \GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
t -> do
                Printer ()
newline
                Int -> Printer ()
spaces Int
indentation
                Printer ()
comma
                Printer ()
space
                GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
-> Printer ()
forall a. Outputable a => a -> Printer ()
putOutputable GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
t

            Printer ()
newline
            Int -> Printer ()
spaces Int
indentation
            String -> Printer ()
putText String
")"

    Maybe (GenLocated SrcSpan (DerivStrategy GhcPs))
-> (GenLocated SrcSpan (DerivStrategy GhcPs) -> Printer ())
-> Printer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ Maybe (GenLocated SrcSpan (DerivStrategy GhcPs))
deriv_clause_strategy ((GenLocated SrcSpan (DerivStrategy GhcPs) -> Printer ())
 -> Printer ())
-> (GenLocated SrcSpan (DerivStrategy GhcPs) -> Printer ())
-> Printer ()
forall a b. (a -> b) -> a -> b
$ \GenLocated SrcSpan (DerivStrategy GhcPs)
lstrat -> case GenLocated SrcSpan (DerivStrategy GhcPs) -> DerivStrategy GhcPs
forall l e. GenLocated l e -> e
GHC.unLoc GenLocated SrcSpan (DerivStrategy GhcPs)
lstrat of
        GHC.ViaStrategy XViaStrategy GhcPs
tp -> do
            case Indent
cVia of
                Indent
SameLine -> Printer ()
space
                Indent Int
x -> Printer ()
newline Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Printer ()
spaces (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
cDeriving)

            String -> Printer ()
putText String
"via"
            Printer ()
space
            LHsType GhcPs -> Printer ()
putType (LHsType GhcPs -> Printer ()) -> LHsType GhcPs -> Printer ()
forall a b. (a -> b) -> a -> b
$ case XViaStrategy GhcPs
tp of
                GHC.XViaStrategyPs _ ty -> HsSigType GhcPs -> LHsType GhcPs
forall pass. HsSigType pass -> LHsType pass
GHC.sig_body (HsSigType GhcPs -> LHsType GhcPs)
-> HsSigType GhcPs -> LHsType GhcPs
forall a b. (a -> b) -> a -> b
$ GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsSigType GhcPs)
-> HsSigType GhcPs
forall l e. GenLocated l e -> e
GHC.unLoc LHsSigType GhcPs
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsSigType GhcPs)
ty
        DerivStrategy GhcPs
_ -> () -> Printer ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()

    -- putEolComment pos
  where
    withinColumns :: PrinterState -> Bool
withinColumns PrinterState{String
currentLine :: PrinterState -> String
currentLine :: String
currentLine} =
      case MaxColumns
cMaxColumns of
        MaxColumns Int
maxCols -> String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
currentLine Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
maxCols
        MaxColumns
NoMaxColumns       -> Bool
True

    indentation :: Int
indentation =
      Int
cDeriving Int -> Int -> Int
forall a. Num a => a -> a -> a
+ case Indent
cFirstField of
        Indent Int
x -> Int
x
        Indent
SameLine -> Int
0

putUnbrokenEnum :: Config -> DataDecl -> P ()
putUnbrokenEnum :: Config -> DataDecl -> Printer ()
putUnbrokenEnum Config
cfg DataDecl
decl = Printer () -> [Printer ()] -> Printer ()
forall a. P a -> [P a] -> Printer ()
sep
    (Printer ()
space Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Printer ()
putText String
"|" Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Printer ()
space)
    ((GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)
 -> Printer ())
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
-> [Printer ()]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Config -> Int -> LConDecl GhcPs -> Printer ()
putConstructor Config
cfg Int
0) ([GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
 -> [Printer ()])
-> (DataDecl
    -> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)])
-> DataDecl
-> [Printer ()]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsDataDefn GhcPs
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
forall pass. HsDataDefn pass -> [LConDecl pass]
GHC.dd_cons (HsDataDefn GhcPs
 -> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)])
-> (DataDecl -> HsDataDefn GhcPs)
-> DataDecl
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataDecl -> HsDataDefn GhcPs
dataDefn (DataDecl -> [Printer ()]) -> DataDecl -> [Printer ()]
forall a b. (a -> b) -> a -> b
$ DataDecl
decl)

putName :: DataDecl -> P ()
putName :: DataDecl -> Printer ()
putName decl :: DataDecl
decl@MkDataDecl{[LEpaComment]
HsDataDefn GhcPs
LHsQTyVars GhcPs
LexicalFixity
RealSrcSpan
LocatedN RdrName
dataFixity :: LexicalFixity
dataDefn :: HsDataDefn GhcPs
dataTypeVars :: LHsQTyVars GhcPs
dataDeclName :: LocatedN RdrName
dataLoc :: RealSrcSpan
dataComments :: [LEpaComment]
dataFixity :: DataDecl -> LexicalFixity
dataDefn :: DataDecl -> HsDataDefn GhcPs
dataTypeVars :: DataDecl -> LHsQTyVars GhcPs
dataDeclName :: DataDecl -> LocatedN RdrName
dataLoc :: DataDecl -> RealSrcSpan
dataComments :: DataDecl -> [LEpaComment]
..} =
  if DataDecl -> Bool
isInfix DataDecl
decl then do
    Maybe
  (GenLocated
     (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs))
-> (GenLocated
      (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)
    -> Printer ())
-> Printer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ Maybe (LHsTyVarBndr () GhcPs)
Maybe
  (GenLocated
     (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs))
firstTvar (\GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)
t -> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)
-> Printer ()
forall a. Outputable a => a -> Printer ()
putOutputable GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)
t Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Printer ()
space)
    LocatedN RdrName -> Printer ()
putRdrName LocatedN RdrName
dataDeclName
    Printer ()
space
    Maybe
  (GenLocated
     (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs))
-> (GenLocated
      (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)
    -> Printer ())
-> Printer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ Maybe (LHsTyVarBndr () GhcPs)
Maybe
  (GenLocated
     (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs))
secondTvar GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)
-> Printer ()
forall a. Outputable a => a -> Printer ()
putOutputable
    Printer ()
maybePutKindSig
  else do
    LocatedN RdrName -> Printer ()
putRdrName LocatedN RdrName
dataDeclName
    [GenLocated
   (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)]
-> (GenLocated
      (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)
    -> Printer ())
-> Printer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (LHsQTyVars GhcPs -> [LHsTyVarBndr () GhcPs]
forall pass. LHsQTyVars pass -> [LHsTyVarBndr () pass]
GHC.hsq_explicit LHsQTyVars GhcPs
dataTypeVars) (\GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)
t -> Printer ()
space Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)
-> Printer ()
forall a. Outputable a => a -> Printer ()
putOutputable GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)
t)
    Printer ()
maybePutKindSig

  where
    firstTvar :: Maybe (GHC.LHsTyVarBndr () GHC.GhcPs)
    firstTvar :: Maybe (LHsTyVarBndr () GhcPs)
firstTvar = [GenLocated
   (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)]
-> Maybe
     (GenLocated
        (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs))
forall a. [a] -> Maybe a
listToMaybe ([GenLocated
    (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)]
 -> Maybe
      (GenLocated
         (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)))
-> [GenLocated
      (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)]
-> Maybe
     (GenLocated
        (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs))
forall a b. (a -> b) -> a -> b
$ LHsQTyVars GhcPs -> [LHsTyVarBndr () GhcPs]
forall pass. LHsQTyVars pass -> [LHsTyVarBndr () pass]
GHC.hsq_explicit LHsQTyVars GhcPs
dataTypeVars

    secondTvar :: Maybe (GHC.LHsTyVarBndr () GHC.GhcPs)
    secondTvar :: Maybe (LHsTyVarBndr () GhcPs)
secondTvar = [GenLocated
   (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)]
-> Maybe
     (GenLocated
        (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs))
forall a. [a] -> Maybe a
listToMaybe ([GenLocated
    (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)]
 -> Maybe
      (GenLocated
         (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)))
-> ([GenLocated
       (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)]
    -> [GenLocated
          (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)])
-> [GenLocated
      (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)]
-> Maybe
     (GenLocated
        (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> [GenLocated
      (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)]
-> [GenLocated
      (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)]
forall a. Int -> [a] -> [a]
drop Int
1 ([GenLocated
    (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)]
 -> Maybe
      (GenLocated
         (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)))
-> [GenLocated
      (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)]
-> Maybe
     (GenLocated
        (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs))
forall a b. (a -> b) -> a -> b
$ LHsQTyVars GhcPs -> [LHsTyVarBndr () GhcPs]
forall pass. LHsQTyVars pass -> [LHsTyVarBndr () pass]
GHC.hsq_explicit LHsQTyVars GhcPs
dataTypeVars

    maybePutKindSig :: Printer ()
    maybePutKindSig :: Printer ()
maybePutKindSig = Maybe (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
-> (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
    -> Printer ())
-> Printer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ Maybe (LHsType GhcPs)
Maybe (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
maybeKindSig (\GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
k -> Printer ()
space Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Printer ()
putText String
"::" Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Printer ()
space Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
-> Printer ()
forall a. Outputable a => a -> Printer ()
putOutputable GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
k)

    maybeKindSig :: Maybe (GHC.LHsKind GHC.GhcPs)
    maybeKindSig :: Maybe (LHsType GhcPs)
maybeKindSig = HsDataDefn GhcPs -> Maybe (LHsType GhcPs)
forall pass. HsDataDefn pass -> Maybe (LHsKind pass)
GHC.dd_kindSig HsDataDefn GhcPs
dataDefn

putConstructor :: Config -> Int -> GHC.LConDecl GHC.GhcPs -> P ()
putConstructor :: Config -> Int -> LConDecl GhcPs -> Printer ()
putConstructor Config
cfg Int
consIndent LConDecl GhcPs
lcons = case GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)
-> ConDecl GhcPs
forall l e. GenLocated l e -> e
GHC.unLoc LConDecl GhcPs
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)
lcons of
  GHC.ConDeclGADT {[LIdP GhcPs]
Maybe (LHsContext GhcPs)
Maybe LHsDocString
HsConDeclGADTDetails GhcPs
XRec GhcPs (HsOuterSigTyVarBndrs GhcPs)
LHsType GhcPs
XConDeclGADT GhcPs
con_g_ext :: forall pass. ConDecl pass -> XConDeclGADT pass
con_names :: forall pass. ConDecl pass -> [LIdP pass]
con_bndrs :: forall pass. ConDecl pass -> XRec pass (HsOuterSigTyVarBndrs pass)
con_mb_cxt :: forall pass. ConDecl pass -> Maybe (LHsContext pass)
con_g_args :: forall pass. ConDecl pass -> HsConDeclGADTDetails pass
con_res_ty :: forall pass. ConDecl pass -> LHsType pass
con_doc :: forall pass. ConDecl pass -> Maybe LHsDocString
con_doc :: Maybe LHsDocString
con_res_ty :: LHsType GhcPs
con_g_args :: HsConDeclGADTDetails GhcPs
con_mb_cxt :: Maybe (LHsContext GhcPs)
con_bndrs :: XRec GhcPs (HsOuterSigTyVarBndrs GhcPs)
con_names :: [LIdP GhcPs]
con_g_ext :: XConDeclGADT GhcPs
..} -> do
    -- Put argument to constructor first:
    case HsConDeclGADTDetails GhcPs
con_g_args of
      GHC.PrefixConGADT [HsScaled GhcPs (LHsType GhcPs)]
_ -> Printer () -> [Printer ()] -> Printer ()
forall a. P a -> [P a] -> Printer ()
sep (Printer ()
comma Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Printer ()
space) ([Printer ()] -> Printer ()) -> [Printer ()] -> Printer ()
forall a b. (a -> b) -> a -> b
$ (LocatedN RdrName -> Printer ())
-> [LocatedN RdrName] -> [Printer ()]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap LocatedN RdrName -> Printer ()
putRdrName [LIdP GhcPs]
[LocatedN RdrName]
con_names
      GHC.RecConGADT XRec GhcPs [LConDeclField GhcPs]
_ -> String -> Printer ()
forall a. HasCallStack => String -> a
error (String -> Printer ()) -> (Lines -> String) -> Lines -> Printer ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lines -> String
forall a. Monoid a => [a] -> a
mconcat (Lines -> Printer ()) -> Lines -> Printer ()
forall a b. (a -> b) -> a -> b
$
          [ String
"Language.Haskell.Stylish.Step.Data.putConstructor: "
          , String
"encountered a GADT with record constructors, not supported yet"
          ]

    -- Put type of constructor:
    Printer ()
space
    String -> Printer ()
putText String
"::"
    Printer ()
space

    Bool -> [LHsTyVarBndr Specificity GhcPs] -> Printer ()
forall s.
OutputableBndrFlag s 'Parsed =>
Bool -> [LHsTyVarBndr s GhcPs] -> Printer ()
putForAll
        (case GenLocated
  (SrcSpanAnn' (EpAnn AnnListItem)) (HsOuterSigTyVarBndrs GhcPs)
-> HsOuterSigTyVarBndrs GhcPs
forall l e. GenLocated l e -> e
GHC.unLoc XRec GhcPs (HsOuterSigTyVarBndrs GhcPs)
GenLocated
  (SrcSpanAnn' (EpAnn AnnListItem)) (HsOuterSigTyVarBndrs GhcPs)
con_bndrs of
            GHC.HsOuterImplicit {} -> Bool
False
            GHC.HsOuterExplicit {} -> Bool
True)
        (case GenLocated
  (SrcSpanAnn' (EpAnn AnnListItem)) (HsOuterSigTyVarBndrs GhcPs)
-> HsOuterSigTyVarBndrs GhcPs
forall l e. GenLocated l e -> e
GHC.unLoc XRec GhcPs (HsOuterSigTyVarBndrs GhcPs)
GenLocated
  (SrcSpanAnn' (EpAnn AnnListItem)) (HsOuterSigTyVarBndrs GhcPs)
con_bndrs of
            GHC.HsOuterImplicit {}   -> []
            GHC.HsOuterExplicit {[LHsTyVarBndr Specificity (NoGhcTc GhcPs)]
XHsOuterExplicit GhcPs Specificity
hso_xexplicit :: forall flag pass.
HsOuterTyVarBndrs flag pass -> XHsOuterExplicit pass flag
hso_bndrs :: forall flag pass.
HsOuterTyVarBndrs flag pass -> [LHsTyVarBndr flag (NoGhcTc pass)]
hso_bndrs :: [LHsTyVarBndr Specificity (NoGhcTc GhcPs)]
hso_xexplicit :: XHsOuterExplicit GhcPs Specificity
..} -> [LHsTyVarBndr Specificity GhcPs]
[LHsTyVarBndr Specificity (NoGhcTc GhcPs)]
hso_bndrs)
    Maybe
  (GenLocated
     SrcSpanAnnC
     [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)])
-> (GenLocated
      SrcSpanAnnC
      [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
    -> Printer ())
-> Printer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ Maybe (LHsContext GhcPs)
Maybe
  (GenLocated
     SrcSpanAnnC
     [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)])
con_mb_cxt ((GenLocated
    SrcSpanAnnC
    [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
  -> Printer ())
 -> Printer ())
-> (GenLocated
      SrcSpanAnnC
      [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
    -> Printer ())
-> Printer ()
forall a b. (a -> b) -> a -> b
$ Config -> LHsContext GhcPs -> Printer ()
putContext Config
cfg
    case HsConDeclGADTDetails GhcPs
con_g_args of
        GHC.PrefixConGADT [HsScaled GhcPs (LHsType GhcPs)]
scaledTys -> [HsScaled
   GhcPs
   (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))]
-> (HsScaled
      GhcPs (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
    -> Printer ())
-> Printer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [HsScaled GhcPs (LHsType GhcPs)]
[HsScaled
   GhcPs
   (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))]
scaledTys ((HsScaled
    GhcPs (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
  -> Printer ())
 -> Printer ())
-> (HsScaled
      GhcPs (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
    -> Printer ())
-> Printer ()
forall a b. (a -> b) -> a -> b
$ \HsScaled
  GhcPs (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
scaledTy -> do
            LHsType GhcPs -> Printer ()
putType (LHsType GhcPs -> Printer ()) -> LHsType GhcPs -> Printer ()
forall a b. (a -> b) -> a -> b
$ HsScaled
  GhcPs (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
forall pass a. HsScaled pass a -> a
GHC.hsScaledThing HsScaled
  GhcPs (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
scaledTy
            Printer ()
space Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Printer ()
putText String
"->" Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Printer ()
space
        GHC.RecConGADT XRec GhcPs [LConDeclField GhcPs]
_ -> String -> Printer ()
forall a. HasCallStack => String -> a
error (String -> Printer ()) -> (Lines -> String) -> Lines -> Printer ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lines -> String
forall a. Monoid a => [a] -> a
mconcat (Lines -> Printer ()) -> Lines -> Printer ()
forall a b. (a -> b) -> a -> b
$
            [ String
"Language.Haskell.Stylish.Step.Data.putConstructor: "
            , String
"encountered a GADT with record constructors, not supported yet"
            ]
    LHsType GhcPs -> Printer ()
putType LHsType GhcPs
con_res_ty

  GHC.ConDeclH98 {Bool
[LHsTyVarBndr Specificity GhcPs]
Maybe (LHsContext GhcPs)
Maybe LHsDocString
HsConDeclH98Details GhcPs
LIdP GhcPs
XConDeclH98 GhcPs
con_ext :: forall pass. ConDecl pass -> XConDeclH98 pass
con_name :: forall pass. ConDecl pass -> LIdP pass
con_forall :: forall pass. ConDecl pass -> Bool
con_ex_tvs :: forall pass. ConDecl pass -> [LHsTyVarBndr Specificity pass]
con_args :: forall pass. ConDecl pass -> HsConDeclH98Details pass
con_doc :: Maybe LHsDocString
con_args :: HsConDeclH98Details GhcPs
con_mb_cxt :: Maybe (LHsContext GhcPs)
con_ex_tvs :: [LHsTyVarBndr Specificity GhcPs]
con_forall :: Bool
con_name :: LIdP GhcPs
con_ext :: XConDeclH98 GhcPs
con_mb_cxt :: forall pass. ConDecl pass -> Maybe (LHsContext pass)
con_doc :: forall pass. ConDecl pass -> Maybe LHsDocString
..} -> do
    Bool -> [LHsTyVarBndr Specificity GhcPs] -> Printer ()
forall s.
OutputableBndrFlag s 'Parsed =>
Bool -> [LHsTyVarBndr s GhcPs] -> Printer ()
putForAll Bool
con_forall [LHsTyVarBndr Specificity GhcPs]
con_ex_tvs
    Maybe
  (GenLocated
     SrcSpanAnnC
     [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)])
-> (GenLocated
      SrcSpanAnnC
      [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
    -> Printer ())
-> Printer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ Maybe (LHsContext GhcPs)
Maybe
  (GenLocated
     SrcSpanAnnC
     [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)])
con_mb_cxt ((GenLocated
    SrcSpanAnnC
    [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
  -> Printer ())
 -> Printer ())
-> (GenLocated
      SrcSpanAnnC
      [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
    -> Printer ())
-> Printer ()
forall a b. (a -> b) -> a -> b
$ Config -> LHsContext GhcPs -> Printer ()
putContext Config
cfg
    case HsConDeclH98Details GhcPs
con_args of
      GHC.InfixCon HsScaled GhcPs (LHsType GhcPs)
arg1 HsScaled GhcPs (LHsType GhcPs)
arg2 -> do
        LHsType GhcPs -> Printer ()
putType (LHsType GhcPs -> Printer ()) -> LHsType GhcPs -> Printer ()
forall a b. (a -> b) -> a -> b
$ HsScaled
  GhcPs (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
forall pass a. HsScaled pass a -> a
GHC.hsScaledThing HsScaled GhcPs (LHsType GhcPs)
HsScaled
  GhcPs (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
arg1
        Printer ()
space
        LocatedN RdrName -> Printer ()
putRdrName LIdP GhcPs
LocatedN RdrName
con_name
        Printer ()
space
        LHsType GhcPs -> Printer ()
putType (LHsType GhcPs -> Printer ()) -> LHsType GhcPs -> Printer ()
forall a b. (a -> b) -> a -> b
$ HsScaled
  GhcPs (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
forall pass a. HsScaled pass a -> a
GHC.hsScaledThing HsScaled GhcPs (LHsType GhcPs)
HsScaled
  GhcPs (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
arg2
      GHC.PrefixCon [Void]
_tyargs [HsScaled GhcPs (LHsType GhcPs)]
args -> do
        LocatedN RdrName -> Printer ()
putRdrName LIdP GhcPs
LocatedN RdrName
con_name
        Bool -> Printer () -> Printer ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ([HsScaled
   GhcPs
   (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))]
-> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [HsScaled GhcPs (LHsType GhcPs)]
[HsScaled
   GhcPs
   (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))]
args) Printer ()
space
        Printer () -> [Printer ()] -> Printer ()
forall a. P a -> [P a] -> Printer ()
sep Printer ()
space ((HsScaled
   GhcPs (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
 -> Printer ())
-> [HsScaled
      GhcPs
      (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))]
-> [Printer ()]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap HsScaled
  GhcPs (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
-> Printer ()
forall a. Outputable a => a -> Printer ()
putOutputable [HsScaled GhcPs (LHsType GhcPs)]
[HsScaled
   GhcPs
   (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))]
args)
      GHC.RecCon XRec GhcPs [LConDeclField GhcPs]
largs | GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)
_ : [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)]
_ <- GenLocated
  SrcSpanAnnL
  [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)]
-> [GenLocated
      (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)]
forall l e. GenLocated l e -> e
GHC.unLoc XRec GhcPs [LConDeclField GhcPs]
GenLocated
  SrcSpanAnnL
  [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)]
largs -> do
        LocatedN RdrName -> Printer ()
putRdrName LIdP GhcPs
LocatedN RdrName
con_name
        Printer ()
skipToBrace
        Int
bracePos <- Printer Int
getCurrentLineLength
        String -> Printer ()
putText String
"{"
        let fieldPos :: Int
fieldPos = Int
bracePos Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2
        Printer ()
space

        let commented :: [CommentGroup
   (GenLocated
      (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs))]
commented = (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)
 -> Maybe RealSrcSpan)
-> [GenLocated
      (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)]
-> [LEpaComment]
-> [CommentGroup
      (GenLocated
         (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs))]
forall a.
(a -> Maybe RealSrcSpan)
-> [a] -> [LEpaComment] -> [CommentGroup a]
commentGroups
                (SrcSpan -> Maybe RealSrcSpan
GHC.srcSpanToRealSrcSpan (SrcSpan -> Maybe RealSrcSpan)
-> (GenLocated
      (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)
    -> SrcSpan)
-> GenLocated
     (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)
-> Maybe RealSrcSpan
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)
-> SrcSpan
forall a e. GenLocated (SrcSpanAnn' a) e -> SrcSpan
GHC.getLocA)
                (GenLocated
  SrcSpanAnnL
  [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)]
-> [GenLocated
      (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)]
forall l e. GenLocated l e -> e
GHC.unLoc XRec GhcPs [LConDeclField GhcPs]
GenLocated
  SrcSpanAnnL
  [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)]
largs)
                (EpAnn AnnList -> [LEpaComment]
forall a. EpAnn a -> [LEpaComment]
epAnnComments (EpAnn AnnList -> [LEpaComment])
-> (SrcSpanAnnL -> EpAnn AnnList) -> SrcSpanAnnL -> [LEpaComment]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcSpanAnnL -> EpAnn AnnList
forall a. SrcSpanAnn' a -> a
GHC.ann (SrcSpanAnnL -> [LEpaComment]) -> SrcSpanAnnL -> [LEpaComment]
forall a b. (a -> b) -> a -> b
$ GenLocated
  SrcSpanAnnL
  [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)]
-> SrcSpanAnnL
forall l e. GenLocated l e -> l
GHC.getLoc XRec GhcPs [LConDeclField GhcPs]
GenLocated
  SrcSpanAnnL
  [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)]
largs)

        [(CommentGroup
    (GenLocated
       (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)),
  Bool, Bool)]
-> ((CommentGroup
       (GenLocated
          (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)),
     Bool, Bool)
    -> Printer ())
-> Printer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ ([CommentGroup
   (GenLocated
      (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs))]
-> [(CommentGroup
       (GenLocated
          (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)),
     Bool, Bool)]
forall a. [a] -> [(a, Bool, Bool)]
flagEnds [CommentGroup
   (GenLocated
      (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs))]
commented) (((CommentGroup
     (GenLocated
        (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)),
   Bool, Bool)
  -> Printer ())
 -> Printer ())
-> ((CommentGroup
       (GenLocated
          (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)),
     Bool, Bool)
    -> Printer ())
-> Printer ()
forall a b. (a -> b) -> a -> b
$ \(CommentGroup {[(GenLocated
    (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs),
  Maybe LEpaComment)]
[LEpaComment]
Block String
cgFollowing :: [LEpaComment]
cgItems :: [(GenLocated
    (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs),
  Maybe LEpaComment)]
cgPrior :: [LEpaComment]
cgBlock :: Block String
cgFollowing :: forall a. CommentGroup a -> [LEpaComment]
cgItems :: forall a. CommentGroup a -> [(a, Maybe LEpaComment)]
cgPrior :: forall a. CommentGroup a -> [LEpaComment]
cgBlock :: forall a. CommentGroup a -> Block String
..}, Bool
firstCommentGroup, Bool
_) -> do

        -- Unless everything's configured to be on the same line, put pending
        -- comments
          [LEpaComment] -> (LEpaComment -> Printer ()) -> Printer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [LEpaComment]
cgPrior ((LEpaComment -> Printer ()) -> Printer ())
-> (LEpaComment -> Printer ()) -> Printer ()
forall a b. (a -> b) -> a -> b
$ \LEpaComment
lc -> do
            Int -> Printer ()
pad Int
fieldPos
            EpaComment -> Printer ()
putComment (EpaComment -> Printer ()) -> EpaComment -> Printer ()
forall a b. (a -> b) -> a -> b
$ LEpaComment -> EpaComment
forall l e. GenLocated l e -> e
GHC.unLoc LEpaComment
lc
            Int -> Printer ()
sepDecl Int
bracePos

          [((GenLocated
     (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs),
   Maybe LEpaComment),
  Bool, Bool)]
-> (((GenLocated
        (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs),
      Maybe LEpaComment),
     Bool, Bool)
    -> Printer ())
-> Printer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ ([(GenLocated
    (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs),
  Maybe LEpaComment)]
-> [((GenLocated
        (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs),
      Maybe LEpaComment),
     Bool, Bool)]
forall a. [a] -> [(a, Bool, Bool)]
flagEnds [(GenLocated
    (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs),
  Maybe LEpaComment)]
cgItems) ((((GenLocated
      (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs),
    Maybe LEpaComment),
   Bool, Bool)
  -> Printer ())
 -> Printer ())
-> (((GenLocated
        (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs),
      Maybe LEpaComment),
     Bool, Bool)
    -> Printer ())
-> Printer ()
forall a b. (a -> b) -> a -> b
$ \((GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)
item, Maybe LEpaComment
mbInlineComment), Bool
firstItem, Bool
_) -> do
            if Bool
firstCommentGroup Bool -> Bool -> Bool
&& Bool
firstItem
                then Int -> Printer ()
pad Int
fieldPos
                else do
                    Printer ()
comma
                    Printer ()
space
            Config -> ConDeclField GhcPs -> Printer ()
putConDeclField Config
cfg (ConDeclField GhcPs -> Printer ())
-> ConDeclField GhcPs -> Printer ()
forall a b. (a -> b) -> a -> b
$ GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)
-> ConDeclField GhcPs
forall l e. GenLocated l e -> e
GHC.unLoc GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)
item
            case Maybe LEpaComment
mbInlineComment of
                Just LEpaComment
c -> do
                    Int -> Printer ()
sepDecl Int
bracePos Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Printer ()
spaces (Config -> Int
cFieldComment Config
cfg)
                    EpaComment -> Printer ()
putComment (EpaComment -> Printer ()) -> EpaComment -> Printer ()
forall a b. (a -> b) -> a -> b
$ LEpaComment -> EpaComment
forall l e. GenLocated l e -> e
GHC.unLoc LEpaComment
c
                Maybe LEpaComment
_ -> () -> Printer ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
            Int -> Printer ()
sepDecl Int
bracePos

          [LEpaComment] -> (LEpaComment -> Printer ()) -> Printer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [LEpaComment]
cgFollowing ((LEpaComment -> Printer ()) -> Printer ())
-> (LEpaComment -> Printer ()) -> Printer ()
forall a b. (a -> b) -> a -> b
$ \LEpaComment
lc -> do
            Int -> Printer ()
spaces (Int -> Printer ()) -> Int -> Printer ()
forall a b. (a -> b) -> a -> b
$ Config -> Int
cFieldComment Config
cfg
            EpaComment -> Printer ()
putComment (EpaComment -> Printer ()) -> EpaComment -> Printer ()
forall a b. (a -> b) -> a -> b
$ LEpaComment -> EpaComment
forall l e. GenLocated l e -> e
GHC.unLoc LEpaComment
lc
            Int -> Printer ()
sepDecl Int
bracePos

        -- Print whitespace to closing brace
        String -> Printer ()
putText String
"}"
      GHC.RecCon XRec GhcPs [LConDeclField GhcPs]
_ -> do
        Printer ()
skipToBrace Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Printer ()
putText String
"{"
        Printer ()
skipToBrace Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Printer ()
putText String
"}"

    where
      -- Jump to the first brace of the first record of the first constructor.
      skipToBrace :: Printer ()
skipToBrace = case (Config -> Indent
cEquals Config
cfg, Config -> Indent
cFirstField Config
cfg) of
        (Indent
_, Indent Int
y) | Bool -> Bool
not (Config -> Bool
cBreakSingleConstructors Config
cfg) -> Printer ()
newline Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Printer ()
spaces Int
y
        (Indent
SameLine, Indent
SameLine) -> Printer ()
space
        (Indent Int
x, Indent Int
y) -> Printer ()
newline Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Printer ()
spaces (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
y Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2)
        (Indent
SameLine, Indent Int
y) -> Printer ()
newline Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Printer ()
spaces (Int
consIndent Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
y)
        (Indent Int
_, Indent
SameLine) -> Printer ()
space

      -- Jump to the next declaration.
      sepDecl :: Int -> Printer ()
sepDecl Int
bracePos = Printer ()
newline Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> Printer ()
spaces case (Config -> Indent
cEquals Config
cfg, Config -> Indent
cFirstField Config
cfg) of
        (Indent
_, Indent Int
y) | Bool -> Bool
not (Config -> Bool
cBreakSingleConstructors Config
cfg) -> Int
y
        (Indent
SameLine, Indent
SameLine)                               -> Int
bracePos
        (Indent Int
x, Indent Int
y)                               -> Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
y Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2
        (Indent
SameLine, Indent Int
y)                               -> Int
bracePos Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
y Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
2
        (Indent Int
x, Indent
SameLine)                               -> Int
bracePos Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
2

putNewtypeConstructor :: Config -> GHC.LConDecl GHC.GhcPs -> P ()
putNewtypeConstructor :: Config -> LConDecl GhcPs -> Printer ()
putNewtypeConstructor Config
cfg LConDecl GhcPs
lcons = case GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)
-> ConDecl GhcPs
forall l e. GenLocated l e -> e
GHC.unLoc LConDecl GhcPs
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)
lcons of
  GHC.ConDeclH98{Bool
[LHsTyVarBndr Specificity GhcPs]
Maybe (LHsContext GhcPs)
Maybe LHsDocString
HsConDeclH98Details GhcPs
LIdP GhcPs
XConDeclH98 GhcPs
con_doc :: Maybe LHsDocString
con_args :: HsConDeclH98Details GhcPs
con_mb_cxt :: Maybe (LHsContext GhcPs)
con_ex_tvs :: [LHsTyVarBndr Specificity GhcPs]
con_forall :: Bool
con_name :: LIdP GhcPs
con_ext :: XConDeclH98 GhcPs
con_ext :: forall pass. ConDecl pass -> XConDeclH98 pass
con_name :: forall pass. ConDecl pass -> LIdP pass
con_forall :: forall pass. ConDecl pass -> Bool
con_ex_tvs :: forall pass. ConDecl pass -> [LHsTyVarBndr Specificity pass]
con_args :: forall pass. ConDecl pass -> HsConDeclH98Details pass
con_mb_cxt :: forall pass. ConDecl pass -> Maybe (LHsContext pass)
con_doc :: forall pass. ConDecl pass -> Maybe LHsDocString
..} ->
    LocatedN RdrName -> Printer ()
putRdrName LIdP GhcPs
LocatedN RdrName
con_name Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> case HsConDeclH98Details GhcPs
con_args of
      GHC.PrefixCon [Void]
_ [HsScaled GhcPs (LHsType GhcPs)]
args -> do
        Bool -> Printer () -> Printer ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ([HsScaled
   GhcPs
   (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))]
-> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [HsScaled GhcPs (LHsType GhcPs)]
[HsScaled
   GhcPs
   (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))]
args) Printer ()
space
        Printer () -> [Printer ()] -> Printer ()
forall a. P a -> [P a] -> Printer ()
sep Printer ()
space ((HsScaled
   GhcPs (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
 -> Printer ())
-> [HsScaled
      GhcPs
      (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))]
-> [Printer ()]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap HsScaled
  GhcPs (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))
-> Printer ()
forall a. Outputable a => a -> Printer ()
putOutputable [HsScaled GhcPs (LHsType GhcPs)]
[HsScaled
   GhcPs
   (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs))]
args)
      GHC.RecCon XRec GhcPs [LConDeclField GhcPs]
largs | [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)
firstArg] <- GenLocated
  SrcSpanAnnL
  [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)]
-> [GenLocated
      (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)]
forall l e. GenLocated l e -> e
GHC.unLoc XRec GhcPs [LConDeclField GhcPs]
GenLocated
  SrcSpanAnnL
  [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)]
largs -> do
        Printer ()
space
        String -> Printer ()
putText String
"{"
        Printer ()
space
        Config -> ConDeclField GhcPs -> Printer ()
putConDeclField Config
cfg (ConDeclField GhcPs -> Printer ())
-> ConDeclField GhcPs -> Printer ()
forall a b. (a -> b) -> a -> b
$ GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)
-> ConDeclField GhcPs
forall l e. GenLocated l e -> e
GHC.unLoc GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDeclField GhcPs)
firstArg
        Printer ()
space
        String -> Printer ()
putText String
"}"
      GHC.RecCon {} ->
        String -> Printer ()
forall a. HasCallStack => String -> a
error (String -> Printer ()) -> (Lines -> String) -> Lines -> Printer ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lines -> String
forall a. Monoid a => [a] -> a
mconcat (Lines -> Printer ()) -> Lines -> Printer ()
forall a b. (a -> b) -> a -> b
$
          [ String
"Language.Haskell.Stylish.Step.Data.putNewtypeConstructor: "
          , String
"encountered newtype with several arguments"
          ]
      GHC.InfixCon {} ->
        String -> Printer ()
forall a. HasCallStack => String -> a
error (String -> Printer ()) -> (Lines -> String) -> Lines -> Printer ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lines -> String
forall a. Monoid a => [a] -> a
mconcat (Lines -> Printer ()) -> Lines -> Printer ()
forall a b. (a -> b) -> a -> b
$
          [ String
"Language.Haskell.Stylish.Step.Data.putNewtypeConstructor: "
          , String
"infix newtype constructor"
          ]
  GHC.ConDeclGADT{} ->
    String -> Printer ()
forall a. HasCallStack => String -> a
error (String -> Printer ()) -> (Lines -> String) -> Lines -> Printer ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lines -> String
forall a. Monoid a => [a] -> a
mconcat (Lines -> Printer ()) -> Lines -> Printer ()
forall a b. (a -> b) -> a -> b
$
      [ String
"Language.Haskell.Stylish.Step.Data.putNewtypeConstructor: "
      , String
"GADT encountered in newtype"
      ]

putForAll
    :: GHC.OutputableBndrFlag s 'GHC.Parsed
    => Bool -> [GHC.LHsTyVarBndr s GHC.GhcPs] -> P ()
putForAll :: Bool -> [LHsTyVarBndr s GhcPs] -> Printer ()
putForAll Bool
forall [LHsTyVarBndr s GhcPs]
ex_tvs = Bool -> Printer () -> Printer ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
forall do
    String -> Printer ()
putText String
"forall"
    Printer ()
space
    Printer () -> [Printer ()] -> Printer ()
forall a. P a -> [P a] -> Printer ()
sep Printer ()
space ([Printer ()] -> Printer ()) -> [Printer ()] -> Printer ()
forall a b. (a -> b) -> a -> b
$ HsTyVarBndr s GhcPs -> Printer ()
forall a. Outputable a => a -> Printer ()
putOutputable (HsTyVarBndr s GhcPs -> Printer ())
-> (GenLocated
      (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr s GhcPs)
    -> HsTyVarBndr s GhcPs)
-> GenLocated
     (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr s GhcPs)
-> Printer ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr s GhcPs)
-> HsTyVarBndr s GhcPs
forall l e. GenLocated l e -> e
GHC.unLoc (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr s GhcPs)
 -> Printer ())
-> [GenLocated
      (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr s GhcPs)]
-> [Printer ()]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [LHsTyVarBndr s GhcPs]
[GenLocated
   (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr s GhcPs)]
ex_tvs
    Printer ()
dot
    Printer ()
space

putContext :: Config -> GHC.LHsContext GHC.GhcPs -> P ()
putContext :: Config -> LHsContext GhcPs -> Printer ()
putContext Config{Bool
Int
MaxColumns
Indent
cMaxColumns :: MaxColumns
cSortDeriving :: Bool
cCurriedContext :: Bool
cVia :: Indent
cBreakSingleConstructors :: Bool
cBreakEnums :: Bool
cDeriving :: Int
cFieldComment :: Int
cFirstField :: Indent
cEquals :: Indent
cMaxColumns :: Config -> MaxColumns
cSortDeriving :: Config -> Bool
cCurriedContext :: Config -> Bool
cVia :: Config -> Indent
cBreakSingleConstructors :: Config -> Bool
cBreakEnums :: Config -> Bool
cDeriving :: Config -> Int
cFieldComment :: Config -> Int
cFirstField :: Config -> Indent
cEquals :: Config -> Indent
..} LHsContext GhcPs
lctx = Printer () -> Printer () -> Printer ()
forall a b. P a -> P b -> P a
suffix (Printer ()
space Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Printer ()
putText String
"=>" Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Printer ()
space) (Printer () -> Printer ()) -> Printer () -> Printer ()
forall a b. (a -> b) -> a -> b
$
    case [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
ltys of
        [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
lty] | GHC.HsParTy XParTy GhcPs
_ LHsType GhcPs
tp <- GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
-> HsType GhcPs
forall l e. GenLocated l e -> e
GHC.unLoc GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
lty, Bool
cCurriedContext ->
          LHsType GhcPs -> Printer ()
putType LHsType GhcPs
tp
        [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
ctx] ->
          LHsType GhcPs -> Printer ()
putType LHsType GhcPs
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
ctx
        [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
ctxs | Bool
cCurriedContext ->
          Printer () -> [Printer ()] -> Printer ()
forall a. P a -> [P a] -> Printer ()
sep (Printer ()
space Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Printer ()
putText String
"=>" Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Printer ()
space) ((GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
 -> Printer ())
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
-> [Printer ()]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap LHsType GhcPs -> Printer ()
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
-> Printer ()
putType [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
ctxs)
        [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
ctxs ->
          Printer () -> Printer ()
forall a. P a -> P a
parenthesize (Printer () -> Printer ()) -> Printer () -> Printer ()
forall a b. (a -> b) -> a -> b
$ Printer () -> [Printer ()] -> Printer ()
forall a. P a -> [P a] -> Printer ()
sep (Printer ()
comma Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Printer ()
space) ((GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
 -> Printer ())
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
-> [Printer ()]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap LHsType GhcPs -> Printer ()
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
-> Printer ()
putType [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
ctxs)
  where
    ltys :: [LHsType GhcPs]
ltys = GenLocated
  SrcSpanAnnC
  [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
forall l e. GenLocated l e -> e
GHC.unLoc LHsContext GhcPs
GenLocated
  SrcSpanAnnC
  [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
lctx :: [GHC.LHsType GHC.GhcPs]

putConDeclField :: Config -> GHC.ConDeclField GHC.GhcPs -> P ()
putConDeclField :: Config -> ConDeclField GhcPs -> Printer ()
putConDeclField Config
cfg GHC.ConDeclField {[LFieldOcc GhcPs]
Maybe LHsDocString
LHsType GhcPs
XConDeclField GhcPs
cd_fld_ext :: forall pass. ConDeclField pass -> XConDeclField pass
cd_fld_names :: forall pass. ConDeclField pass -> [LFieldOcc pass]
cd_fld_type :: forall pass. ConDeclField pass -> LBangType pass
cd_fld_doc :: forall pass. ConDeclField pass -> Maybe LHsDocString
cd_fld_doc :: Maybe LHsDocString
cd_fld_type :: LHsType GhcPs
cd_fld_names :: [LFieldOcc GhcPs]
cd_fld_ext :: XConDeclField GhcPs
..} = do
    Printer () -> [Printer ()] -> Printer ()
forall a. P a -> [P a] -> Printer ()
sep
        (Printer ()
comma Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Printer ()
space)
        ((GenLocated SrcSpan (FieldOcc GhcPs) -> Printer ())
-> [GenLocated SrcSpan (FieldOcc GhcPs)] -> [Printer ()]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap GenLocated SrcSpan (FieldOcc GhcPs) -> Printer ()
forall a. Outputable a => a -> Printer ()
putOutputable [LFieldOcc GhcPs]
[GenLocated SrcSpan (FieldOcc GhcPs)]
cd_fld_names)
    Printer ()
space
    String -> Printer ()
putText String
"::"
    Printer ()
space
    Config -> LHsType GhcPs -> Printer ()
putType' Config
cfg LHsType GhcPs
cd_fld_type

-- | A variant of 'putType' that takes 'cCurriedContext' into account
putType' :: Config -> GHC.LHsType GHC.GhcPs -> P ()
putType' :: Config -> LHsType GhcPs -> Printer ()
putType' Config
cfg LHsType GhcPs
lty = case GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
-> HsType GhcPs
forall l e. GenLocated l e -> e
GHC.unLoc LHsType GhcPs
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)
lty of
    GHC.HsForAllTy XForAllTy GhcPs
GHC.NoExtField HsForAllTelescope GhcPs
tele LHsType GhcPs
tp -> do
        String -> Printer ()
putText String
"forall"
        Printer ()
space
        Printer () -> [Printer ()] -> Printer ()
forall a. P a -> [P a] -> Printer ()
sep Printer ()
space ([Printer ()] -> Printer ()) -> [Printer ()] -> Printer ()
forall a b. (a -> b) -> a -> b
$ case HsForAllTelescope GhcPs
tele of
            GHC.HsForAllVis   {[LHsTyVarBndr () GhcPs]
XHsForAllVis GhcPs
hsf_xvis :: forall pass. HsForAllTelescope pass -> XHsForAllVis pass
hsf_vis_bndrs :: forall pass. HsForAllTelescope pass -> [LHsTyVarBndr () pass]
hsf_vis_bndrs :: [LHsTyVarBndr () GhcPs]
hsf_xvis :: XHsForAllVis GhcPs
..} -> HsTyVarBndr () GhcPs -> Printer ()
forall a. Outputable a => a -> Printer ()
putOutputable (HsTyVarBndr () GhcPs -> Printer ())
-> (GenLocated
      (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)
    -> HsTyVarBndr () GhcPs)
-> GenLocated
     (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)
-> Printer ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)
-> HsTyVarBndr () GhcPs
forall l e. GenLocated l e -> e
GHC.unLoc (GenLocated
   (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)
 -> Printer ())
-> [GenLocated
      (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)]
-> [Printer ()]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [LHsTyVarBndr () GhcPs]
[GenLocated
   (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr () GhcPs)]
hsf_vis_bndrs
            GHC.HsForAllInvis {[LHsTyVarBndr Specificity GhcPs]
XHsForAllInvis GhcPs
hsf_xinvis :: forall pass. HsForAllTelescope pass -> XHsForAllInvis pass
hsf_invis_bndrs :: forall pass.
HsForAllTelescope pass -> [LHsTyVarBndr Specificity pass]
hsf_invis_bndrs :: [LHsTyVarBndr Specificity GhcPs]
hsf_xinvis :: XHsForAllInvis GhcPs
..} -> HsTyVarBndr Specificity GhcPs -> Printer ()
forall a. Outputable a => a -> Printer ()
putOutputable (HsTyVarBndr Specificity GhcPs -> Printer ())
-> (GenLocated
      (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr Specificity GhcPs)
    -> HsTyVarBndr Specificity GhcPs)
-> GenLocated
     (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr Specificity GhcPs)
-> Printer ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated
  (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr Specificity GhcPs)
-> HsTyVarBndr Specificity GhcPs
forall l e. GenLocated l e -> e
GHC.unLoc (GenLocated
   (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr Specificity GhcPs)
 -> Printer ())
-> [GenLocated
      (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr Specificity GhcPs)]
-> [Printer ()]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [LHsTyVarBndr Specificity GhcPs]
[GenLocated
   (SrcSpanAnn' (EpAnn AnnListItem)) (HsTyVarBndr Specificity GhcPs)]
hsf_invis_bndrs
        case HsForAllTelescope GhcPs
tele of
            GHC.HsForAllVis   {} -> Printer ()
space Printer () -> Printer () -> Printer ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Printer ()
putText String
"->"
            GHC.HsForAllInvis {} -> String -> Printer ()
putText String
"."
        Printer ()
space
        Config -> LHsType GhcPs -> Printer ()
putType' Config
cfg LHsType GhcPs
tp
    GHC.HsQualTy XQualTy GhcPs
GHC.NoExtField Maybe (LHsContext GhcPs)
ctx LHsType GhcPs
tp -> do
        Maybe
  (GenLocated
     SrcSpanAnnC
     [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)])
-> (GenLocated
      SrcSpanAnnC
      [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
    -> Printer ())
-> Printer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ Maybe (LHsContext GhcPs)
Maybe
  (GenLocated
     SrcSpanAnnC
     [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)])
ctx ((GenLocated
    SrcSpanAnnC
    [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
  -> Printer ())
 -> Printer ())
-> (GenLocated
      SrcSpanAnnC
      [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsType GhcPs)]
    -> Printer ())
-> Printer ()
forall a b. (a -> b) -> a -> b
$ Config -> LHsContext GhcPs -> Printer ()
putContext Config
cfg
        Config -> LHsType GhcPs -> Printer ()
putType' Config
cfg LHsType GhcPs
tp
    HsType GhcPs
_ -> LHsType GhcPs -> Printer ()
putType LHsType GhcPs
lty

newOrData :: DataDecl -> String
newOrData :: DataDecl -> String
newOrData DataDecl
decl = if DataDecl -> Bool
isNewtype DataDecl
decl then String
"newtype" else String
"data"

isGADT :: DataDecl -> Bool
isGADT :: DataDecl -> Bool
isGADT = (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)
 -> Bool)
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
-> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)
-> Bool
forall l pass. GenLocated l (ConDecl pass) -> Bool
isGADTCons ([GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
 -> Bool)
-> (DataDecl
    -> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)])
-> DataDecl
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsDataDefn GhcPs
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
forall pass. HsDataDefn pass -> [LConDecl pass]
GHC.dd_cons (HsDataDefn GhcPs
 -> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)])
-> (DataDecl -> HsDataDefn GhcPs)
-> DataDecl
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataDecl -> HsDataDefn GhcPs
dataDefn
  where
    isGADTCons :: GenLocated l (ConDecl pass) -> Bool
isGADTCons GenLocated l (ConDecl pass)
c = case GenLocated l (ConDecl pass) -> ConDecl pass
forall l e. GenLocated l e -> e
GHC.unLoc GenLocated l (ConDecl pass)
c of
      GHC.ConDeclGADT {} -> Bool
True
      ConDecl pass
_                  -> Bool
False

isNewtype :: DataDecl -> Bool
isNewtype :: DataDecl -> Bool
isNewtype = (NewOrData -> NewOrData -> Bool
forall a. Eq a => a -> a -> Bool
== NewOrData
GHC.NewType) (NewOrData -> Bool) -> (DataDecl -> NewOrData) -> DataDecl -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsDataDefn GhcPs -> NewOrData
forall pass. HsDataDefn pass -> NewOrData
GHC.dd_ND (HsDataDefn GhcPs -> NewOrData)
-> (DataDecl -> HsDataDefn GhcPs) -> DataDecl -> NewOrData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataDecl -> HsDataDefn GhcPs
dataDefn

isInfix :: DataDecl -> Bool
isInfix :: DataDecl -> Bool
isInfix = (LexicalFixity -> LexicalFixity -> Bool
forall a. Eq a => a -> a -> Bool
== LexicalFixity
GHC.Infix) (LexicalFixity -> Bool)
-> (DataDecl -> LexicalFixity) -> DataDecl -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataDecl -> LexicalFixity
dataFixity

isEnum :: DataDecl -> Bool
isEnum :: DataDecl -> Bool
isEnum = (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)
 -> Bool)
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
-> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)
-> Bool
forall l pass. GenLocated l (ConDecl pass) -> Bool
isUnary ([GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
 -> Bool)
-> (DataDecl
    -> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)])
-> DataDecl
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsDataDefn GhcPs
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
forall pass. HsDataDefn pass -> [LConDecl pass]
GHC.dd_cons (HsDataDefn GhcPs
 -> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)])
-> (DataDecl -> HsDataDefn GhcPs)
-> DataDecl
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataDecl -> HsDataDefn GhcPs
dataDefn
  where
    isUnary :: GenLocated l (ConDecl pass) -> Bool
isUnary GenLocated l (ConDecl pass)
c = case GenLocated l (ConDecl pass) -> ConDecl pass
forall l e. GenLocated l e -> e
GHC.unLoc GenLocated l (ConDecl pass)
c of
      GHC.ConDeclH98 {Bool
[LHsTyVarBndr Specificity pass]
Maybe (LHsContext pass)
Maybe LHsDocString
HsConDeclH98Details pass
LIdP pass
XConDeclH98 pass
con_doc :: Maybe LHsDocString
con_args :: HsConDeclH98Details pass
con_mb_cxt :: Maybe (LHsContext pass)
con_ex_tvs :: [LHsTyVarBndr Specificity pass]
con_forall :: Bool
con_name :: LIdP pass
con_ext :: XConDeclH98 pass
con_ext :: forall pass. ConDecl pass -> XConDeclH98 pass
con_name :: forall pass. ConDecl pass -> LIdP pass
con_forall :: forall pass. ConDecl pass -> Bool
con_ex_tvs :: forall pass. ConDecl pass -> [LHsTyVarBndr Specificity pass]
con_args :: forall pass. ConDecl pass -> HsConDeclH98Details pass
con_mb_cxt :: forall pass. ConDecl pass -> Maybe (LHsContext pass)
con_doc :: forall pass. ConDecl pass -> Maybe LHsDocString
..} -> case HsConDeclH98Details pass
con_args of
        GHC.PrefixCon [Void]
tyargs [HsScaled pass (LBangType pass)]
args -> [Void] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Void]
tyargs Bool -> Bool -> Bool
&& [HsScaled pass (LBangType pass)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [HsScaled pass (LBangType pass)]
args
        HsConDeclH98Details pass
_                         -> Bool
False
      ConDecl pass
_ -> Bool
False

hasConstructors :: DataDecl -> Bool
hasConstructors :: DataDecl -> Bool
hasConstructors = Bool -> Bool
not (Bool -> Bool) -> (DataDecl -> Bool) -> DataDecl -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
-> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
 -> Bool)
-> (DataDecl
    -> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)])
-> DataDecl
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsDataDefn GhcPs
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
forall pass. HsDataDefn pass -> [LConDecl pass]
GHC.dd_cons (HsDataDefn GhcPs
 -> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)])
-> (DataDecl -> HsDataDefn GhcPs)
-> DataDecl
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataDecl -> HsDataDefn GhcPs
dataDefn

singleConstructor :: DataDecl -> Bool
singleConstructor :: DataDecl -> Bool
singleConstructor = (Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1) (Int -> Bool) -> (DataDecl -> Int) -> DataDecl -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
-> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ([GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
 -> Int)
-> (DataDecl
    -> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)])
-> DataDecl
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsDataDefn GhcPs
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
forall pass. HsDataDefn pass -> [LConDecl pass]
GHC.dd_cons (HsDataDefn GhcPs
 -> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)])
-> (DataDecl -> HsDataDefn GhcPs)
-> DataDecl
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (ConDecl GhcPs)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataDecl -> HsDataDefn GhcPs
dataDefn

hasDeriving :: DataDecl -> Bool
hasDeriving :: DataDecl -> Bool
hasDeriving = Bool -> Bool
not (Bool -> Bool) -> (DataDecl -> Bool) -> DataDecl -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [GenLocated SrcSpan (HsDerivingClause GhcPs)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([GenLocated SrcSpan (HsDerivingClause GhcPs)] -> Bool)
-> (DataDecl -> [GenLocated SrcSpan (HsDerivingClause GhcPs)])
-> DataDecl
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HsDataDefn GhcPs -> [GenLocated SrcSpan (HsDerivingClause GhcPs)]
forall pass. HsDataDefn pass -> HsDeriving pass
GHC.dd_derivs (HsDataDefn GhcPs -> [GenLocated SrcSpan (HsDerivingClause GhcPs)])
-> (DataDecl -> HsDataDefn GhcPs)
-> DataDecl
-> [GenLocated SrcSpan (HsDerivingClause GhcPs)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataDecl -> HsDataDefn GhcPs
dataDefn