refactoring.

This commit is contained in:
Kazu Yamamoto 2014-04-11 11:54:39 +09:00
parent e9859980ab
commit dd8f9a5fcb

View File

@ -31,10 +31,6 @@ import TcHsSyn (hsPatType)
---------------------------------------------------------------- ----------------------------------------------------------------
data Cmd = Info | Type deriving Eq
----------------------------------------------------------------
-- | Obtaining information of a target expression. (GHCi's info:) -- | Obtaining information of a target expression. (GHCi's info:)
infoExpr :: Options infoExpr :: Options
-> Cradle -> Cradle
@ -50,7 +46,7 @@ info :: Options
-> Expression -- ^ A Haskell expression. -> Expression -- ^ A Haskell expression.
-> Ghc String -> Ghc String
info opt cradle file expr = info opt cradle file expr =
inModuleContext Info opt cradle file exprToInfo "Cannot show info" inModuleContext opt cradle file exprToInfo "Cannot show info"
where where
exprToInfo = do exprToInfo = do
dflag <- G.getSessionDynFlags dflag <- G.getSessionDynFlags
@ -88,7 +84,7 @@ typeOf :: Options
-> Int -- ^ Column number. -> Int -- ^ Column number.
-> Ghc String -> Ghc String
typeOf opt cradle file lineNo colNo = typeOf opt cradle file lineNo colNo =
inModuleContext Type opt cradle file exprToType errmsg inModuleContext opt cradle file exprToType errmsg
where where
exprToType = do exprToType = do
modGraph <- G.getModuleGraph modGraph <- G.getModuleGraph
@ -136,8 +132,8 @@ pretty dflag style = showOneLine dflag style . Gap.typeForUser
noWaringOptions :: [String] noWaringOptions :: [String]
noWaringOptions = ["-w:"] noWaringOptions = ["-w:"]
inModuleContext :: Cmd -> Options -> Cradle -> FilePath -> Ghc String -> String -> Ghc String inModuleContext :: Options -> Cradle -> FilePath -> Ghc String -> String -> Ghc String
inModuleContext _ opt cradle file action errmsg = ghandle handler $ do inModuleContext opt cradle file action errmsg = ghandle handler $ do
void $ initializeFlagsWithCradle opt cradle noWaringOptions False void $ initializeFlagsWithCradle opt cradle noWaringOptions False
setTargetFiles [file] setTargetFiles [file]
void $ G.load LoadAllTargets void $ G.load LoadAllTargets