module GHC.Driver.Ppr
( showSDoc
, showSDocUnsafe
, showSDocForUser
, showPpr
, showPprUnsafe
, printForUser
)
where
import GHC.Prelude
import GHC.Driver.Session
import GHC.Unit.State
import GHC.Utils.Outputable
import GHC.Utils.Ppr ( Mode(..) )
import System.IO ( Handle )
showSDoc :: DynFlags -> SDoc -> String
showSDoc :: DynFlags -> SDoc -> String
showSDoc DynFlags
dflags SDoc
sdoc = SDocContext -> SDoc -> String
renderWithContext (DynFlags -> PprStyle -> SDocContext
initSDocContext DynFlags
dflags PprStyle
defaultUserStyle) SDoc
sdoc
showPpr :: Outputable a => DynFlags -> a -> String
showPpr :: forall a. Outputable a => DynFlags -> a -> String
showPpr DynFlags
dflags a
thing = DynFlags -> SDoc -> String
showSDoc DynFlags
dflags (a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
thing)
showSDocForUser :: DynFlags -> UnitState -> PrintUnqualified -> SDoc -> String
showSDocForUser :: DynFlags -> UnitState -> PrintUnqualified -> SDoc -> String
showSDocForUser DynFlags
dflags UnitState
unit_state PrintUnqualified
unqual SDoc
doc = SDocContext -> SDoc -> String
renderWithContext (DynFlags -> PprStyle -> SDocContext
initSDocContext DynFlags
dflags PprStyle
sty) SDoc
doc'
where
sty :: PprStyle
sty = PrintUnqualified -> Depth -> PprStyle
mkUserStyle PrintUnqualified
unqual Depth
AllTheWay
doc' :: SDoc
doc' = UnitState -> SDoc -> SDoc
pprWithUnitState UnitState
unit_state SDoc
doc
printForUser :: DynFlags -> Handle -> PrintUnqualified -> Depth -> SDoc -> IO ()
printForUser :: DynFlags -> Handle -> PrintUnqualified -> Depth -> SDoc -> IO ()
printForUser DynFlags
dflags Handle
handle PrintUnqualified
unqual Depth
depth SDoc
doc
= SDocContext -> Mode -> Handle -> SDoc -> IO ()
printSDocLn SDocContext
ctx (Bool -> Mode
PageMode Bool
False) Handle
handle SDoc
doc
where ctx :: SDocContext
ctx = DynFlags -> PprStyle -> SDocContext
initSDocContext DynFlags
dflags (PrintUnqualified -> Depth -> PprStyle
mkUserStyle PrintUnqualified
unqual Depth
depth)