cmSetContext, -- :: CmState -> DynFlags -> [String] -> [String] -> IO CmState
cmGetContext, -- :: CmState -> IO ([String],[String])
- cmInfoThing, -- :: CmState -> DynFlags -> String
- -- -> IO (CmState, [(TyThing,Fixity)])
-
+ cmInfoThing, -- :: CmState -> String -> IO (CmState, [(TyThing,Fixity)])
cmBrowseModule, -- :: CmState -> IO [TyThing]
CmRunResult(..),
cmTypeOfExpr, -- :: CmState -> DynFlags -> String
-- -> IO (CmState, Maybe String)
+ cmKindOfType, -- :: CmState -> DynFlags -> String
+ -- -> IO (CmState, Maybe String)
+
cmTypeOfName, -- :: CmState -> Name -> IO (Maybe String)
HValue,
import DATA_IOREF ( readIORef )
#ifdef GHCI
-import HscMain ( hscThing, hscStmt, hscTcExpr )
+import HscMain ( hscThing, hscStmt, hscTcExpr, hscKcType )
import TcRnDriver ( mkExportEnv, getModuleContents )
import IfaceSyn ( IfaceDecl )
import RdrName ( GlobalRdrEnv, plusGlobalRdrEnv )
import Linker ( HValue, unload, extendLinkEnv )
import GHC.Exts ( unsafeCoerce# )
import Foreign
+import SrcLoc ( SrcLoc )
import Control.Exception as Exception ( Exception, try )
#endif
-- A string may refer to more than one TyThing (eg. a constructor,
-- and type constructor), so we return a list of all the possible TyThings.
-cmInfoThing :: CmState -> String -> IO [(IfaceDecl,Fixity)]
+cmInfoThing :: CmState -> String -> IO [(IfaceDecl,Fixity,SrcLoc)]
cmInfoThing cmstate id
= hscThing (cm_hsc cmstate) (cm_ic cmstate) id
case maybe_stuff of
Nothing -> return Nothing
- Just ty -> return (Just str)
+ Just ty -> return (Just res_str)
where
- str = showSDocForUser unqual (text expr <+> dcolon <+> ppr tidy_ty)
+ res_str = showSDocForUser unqual (text expr <+> dcolon <+> ppr tidy_ty)
unqual = icPrintUnqual (cm_ic cmstate)
tidy_ty = tidyType emptyTidyEnv ty
-----------------------------------------------------------------------------
+-- cmKindOfType: returns a string representing the kind of a type
+
+cmKindOfType :: CmState -> String -> IO (Maybe String)
+cmKindOfType cmstate str
+ = do maybe_stuff <- hscKcType (cm_hsc cmstate) (cm_ic cmstate) str
+ case maybe_stuff of
+ Nothing -> return Nothing
+ Just kind -> return (Just res_str)
+ where
+ res_str = showSDocForUser unqual (text str <+> dcolon <+> ppr kind)
+ unqual = icPrintUnqual (cm_ic cmstate)
+
+-----------------------------------------------------------------------------
-- cmTypeOfName: returns a string representing the type of a name.
cmTypeOfName :: CmState -> Name -> IO (Maybe String)
let do_linking = a_root_is_Main || no_hs_main
when (ghci_mode == Batch && isJust ofile && not do_linking
&& verb > 0) $
- hPutStrLn stderr "Warning: output was redirected with -o, but no output will be generated\nbecause there is no Main module."
+ hPutStrLn stderr ("Warning: output was redirected with -o, but no output will be generated\nbecause there is no " ++ main_mod ++ " module.")
-- link everything together
linkresult <- link ghci_mode dflags do_linking (hsc_HPT hsc_env3)