ghc-mod "expand" to expand TH.

This commit is contained in:
Kazu Yamamoto 2012-02-27 11:23:56 +09:00
parent e795b35502
commit 2c69ee4c8a
4 changed files with 27 additions and 16 deletions

View File

@ -25,4 +25,6 @@ check opt fileName = withGHC $ checkIt `gcatch` handleErrMsg
setTargetFile file
load LoadAllTargets
liftIO readLog
options = ["-Wall","-fno-warn-unused-do-bind"] ++ ghcOpts opt
options
| expandSplice opt = ghcOpts opt
| otherwise = ["-Wall","-fno-warn-unused-do-bind"] ++ ghcOpts opt

View File

@ -31,20 +31,24 @@ initSession opt cmdOpts idirs logging = do
dflags <- getSessionDynFlags
let opts = map noLoc cmdOpts
(dflags',_,_) <- parseDynamicFlags dflags opts
(dflags'',readLog) <- liftIO . (>>= setLogger logging) . setGhcFlags opt . setFlags dflags' $ idirs
(dflags'',readLog) <- liftIO . (>>= setLogger logging) . setGhcFlags opt . setFlags opt dflags' $ idirs
setSessionDynFlags dflags''
return readLog
----------------------------------------------------------------
setFlags :: DynFlags -> [FilePath] -> DynFlags
setFlags d idirs = d'
setFlags :: Options -> DynFlags -> [FilePath] -> DynFlags
setFlags opt d idirs = d'
where
d' = d {
packageFlags = ghcPackage : packageFlags d
, importPaths = idirs
, ghcLink = NoLink
, hscTarget = HscInterpreted
, flags = if expandSplice opt then
flags d ++ [Opt_D_dump_splices]
else
flags d
}
ghcPackage :: PackageFlag

View File

@ -35,6 +35,7 @@ usage = "ghc-mod version " ++ showVersion version ++ "\n"
++ "\t ghc-mod flag [-l]\n"
++ "\t ghc-mod browse" ++ ghcOptHelp ++ "[-l] [-o] <module> [<module> ...]\n"
++ "\t ghc-mod check" ++ ghcOptHelp ++ "<HaskellFile>\n"
++ "\t ghc-mod expand" ++ ghcOptHelp ++ "<HaskellFile>\n"
++ "\t ghc-mod info" ++ ghcOptHelp ++ "<HaskellFile> <module> <expression>\n"
++ "\t ghc-mod type" ++ ghcOptHelp ++ "<HaskellFile> <module> <line-no> <column-no>\n"
++ "\t ghc-mod lint [-h opt] <HaskellFile>\n"
@ -43,14 +44,6 @@ usage = "ghc-mod version " ++ showVersion version ++ "\n"
----------------------------------------------------------------
defaultOptions :: Options
defaultOptions = Options {
outputStyle = PlainStyle
, hlintOpts = []
, ghcOpts = []
, operators = False
}
argspec :: [OptDescr (Options -> Options)]
argspec = [ Option "l" ["tolisp"]
(NoArg (\opts -> opts { outputStyle = LispStyle }))
@ -91,6 +84,8 @@ main = flip catches handlers $ do
"browse" -> concat <$> mapM (browseModule opt) (tail cmdArg)
"list" -> listModules opt
"check" -> withFile (checkSyntax opt) (safelist cmdArg 1)
"expand" -> withFile (checkSyntax opt { expandSplice = True })
(safelist cmdArg 1)
"type" -> withFile (typeExpr opt (safelist cmdArg 2) (read $ safelist cmdArg 3) (read $ safelist cmdArg 4)) (safelist cmdArg 1)
"info" -> withFile (infoExpr opt (safelist cmdArg 2) (safelist cmdArg 3)) (safelist cmdArg 1)
"lint" -> withFile (lintSyntax opt) (safelist cmdArg 1)

View File

@ -9,6 +9,16 @@ data Options = Options {
, hlintOpts :: [String]
, ghcOpts :: [String]
, operators :: Bool
, expandSplice :: Bool
}
defaultOptions :: Options
defaultOptions = Options {
outputStyle = PlainStyle
, hlintOpts = []
, ghcOpts = []
, operators = False
, expandSplice = False
}
----------------------------------------------------------------