1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
-- | Printing related functions that depend on session state (DynFlags)
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 )
-- | Show a SDoc as a String with the default user style
showSDoc :: DynFlags -> SDoc -> String
showSDoc dflags sdoc = renderWithContext (initSDocContext dflags defaultUserStyle) sdoc
showPpr :: Outputable a => DynFlags -> a -> String
showPpr dflags thing = showSDoc dflags (ppr thing)
-- | Allows caller to specify the NamePprCtx to use
showSDocForUser :: DynFlags -> UnitState -> NamePprCtx -> SDoc -> String
showSDocForUser dflags unit_state name_ppr_ctx doc = renderWithContext (initSDocContext dflags sty) doc'
where
sty = mkUserStyle name_ppr_ctx AllTheWay
doc' = pprWithUnitState unit_state doc
printForUser :: DynFlags -> Handle -> NamePprCtx -> Depth -> SDoc -> IO ()
printForUser dflags handle name_ppr_ctx depth doc
= printSDocLn ctx (PageMode False) handle doc
where ctx = initSDocContext dflags (mkUserStyle name_ppr_ctx depth)
|