module Hint.Conversions (
      typeToString, kindToString, moduleToString, isSucceeded
) where

import qualified Hint.GHC as GHC

import Hint.Base

-- --------- Types / Kinds -----------------------

typeToString :: MonadInterpreter m => GHC.Type -> m String
typeToString :: Type -> m String
typeToString t :: Type
t
 = do -- Unqualify necessary types
      -- (i.e., do not expose internals)
      PrintUnqualified
unqual <- RunGhc m PrintUnqualified
forall (m :: * -> *) a. MonadInterpreter m => RunGhc m a
runGhc forall (n :: * -> *).
(MonadIO n, MonadMask n) =>
GhcT n PrintUnqualified
forall (m :: * -> *). GhcMonad m => m PrintUnqualified
GHC.getPrintUnqual
      (DynFlags -> m String) -> m String
forall (m :: * -> *) a.
MonadInterpreter m =>
(DynFlags -> m a) -> m a
withDynFlags ((DynFlags -> m String) -> m String)
-> (DynFlags -> m String) -> m String
forall a b. (a -> b) -> a -> b
$ \df :: DynFlags
df ->
        String -> m String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> m String) -> String -> m String
forall a b. (a -> b) -> a -> b
$ DynFlags -> PrintUnqualified -> SDoc -> String
GHC.showSDocForUser DynFlags
df PrintUnqualified
unqual (Type -> SDoc
GHC.pprTypeForUser Type
t)

kindToString :: MonadInterpreter m => GHC.Kind -> m String
kindToString :: Type -> m String
kindToString k :: Type
k
 = (DynFlags -> m String) -> m String
forall (m :: * -> *) a.
MonadInterpreter m =>
(DynFlags -> m a) -> m a
withDynFlags ((DynFlags -> m String) -> m String)
-> (DynFlags -> m String) -> m String
forall a b. (a -> b) -> a -> b
$ \df :: DynFlags
df ->
     String -> m String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> m String) -> String -> m String
forall a b. (a -> b) -> a -> b
$ DynFlags -> SDoc -> String
GHC.showSDoc DynFlags
df (Type -> SDoc
GHC.pprTypeForUser Type
k)

-- ---------------- Modules --------------------------

moduleToString :: GHC.Module -> String
moduleToString :: Module -> String
moduleToString = ModuleName -> String
GHC.moduleNameString (ModuleName -> String)
-> (Module -> ModuleName) -> Module -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Module -> ModuleName
GHC.moduleName

-- ---------------- Misc -----------------------------

isSucceeded :: GHC.SuccessFlag -> Bool
isSucceeded :: SuccessFlag -> Bool
isSucceeded GHC.Succeeded = Bool
True
isSucceeded GHC.Failed    = Bool
False