X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2FcompMan%2FCompManager.lhs;h=82183f1d38688f34938d2442b497d8c086bac066;hb=1004a5a31ae62ab53000f6d1248f117a6c22c5e5;hp=c4c1913a6af5b1bc9d95c44c06f8530674867b7d;hpb=c0c05bb3fbfdd1a82bccdcbc34c77a4927c99316;p=ghc-hetmet.git diff --git a/ghc/compiler/compMan/CompManager.lhs b/ghc/compiler/compMan/CompManager.lhs index c4c1913..82183f1 100644 --- a/ghc/compiler/compMan/CompManager.lhs +++ b/ghc/compiler/compMan/CompManager.lhs @@ -25,9 +25,7 @@ module CompManager ( 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(..), @@ -37,6 +35,9 @@ module CompManager ( cmTypeOfExpr, -- :: CmState -> DynFlags -> String -- -> IO (CmState, Maybe String) + cmKindOfType, -- :: CmState -> DynFlags -> String + -- -> IO (CmState, Maybe String) + cmTypeOfName, -- :: CmState -> Name -> IO (Maybe String) HValue, @@ -81,7 +82,7 @@ import Maybes ( expectJust, orElse, mapCatMaybes ) 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 ) @@ -94,6 +95,7 @@ import BasicTypes ( Fixity ) import Linker ( HValue, unload, extendLinkEnv ) import GHC.Exts ( unsafeCoerce# ) import Foreign +import SrcLoc ( SrcLoc ) import Control.Exception as Exception ( Exception, try ) #endif @@ -218,7 +220,7 @@ cmSetDFlags cm_state dflags -- 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 @@ -316,14 +318,27 @@ cmTypeOfExpr cmstate expr 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)