2010-03-11 10:03:17 +00:00
|
|
|
module Check (checkSyntax) where
|
|
|
|
|
|
|
|
import Control.Applicative
|
2013-03-13 04:17:22 +00:00
|
|
|
import Control.Monad
|
2011-08-24 06:58:12 +00:00
|
|
|
import CoreMonad
|
2011-08-24 07:50:26 +00:00
|
|
|
import ErrMsg
|
|
|
|
import Exception
|
2010-04-28 12:43:32 +00:00
|
|
|
import GHC
|
2012-02-14 07:09:53 +00:00
|
|
|
import GHCApi
|
2012-10-16 10:27:35 +00:00
|
|
|
import Prelude
|
2010-04-30 09:36:31 +00:00
|
|
|
import Types
|
2010-03-11 10:03:17 +00:00
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
2013-03-02 07:14:55 +00:00
|
|
|
checkSyntax :: Options -> Cradle -> String -> IO String
|
|
|
|
checkSyntax opt cradle file = unlines <$> check opt cradle file
|
2010-04-28 12:43:32 +00:00
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
2013-03-02 07:14:55 +00:00
|
|
|
check :: Options -> Cradle -> String -> IO [String]
|
2013-03-04 04:41:56 +00:00
|
|
|
check opt cradle fileName = withGHC fileName $ checkIt `gcatch` handleErrMsg
|
2010-03-11 10:03:17 +00:00
|
|
|
where
|
2011-08-24 07:50:26 +00:00
|
|
|
checkIt = do
|
2013-03-13 04:17:22 +00:00
|
|
|
readLog <- initializeFlagsWithCradle opt cradle options True
|
2013-03-01 07:42:22 +00:00
|
|
|
setTargetFile fileName
|
2013-03-13 04:22:02 +00:00
|
|
|
-- To check TH, a session module graph is necessary.
|
|
|
|
-- "load" sets a session module graph using "depanal".
|
|
|
|
-- But we have to set "-fno-code" to DynFlags before "load".
|
|
|
|
-- So, this is necessary redundancy.
|
2013-03-13 04:17:22 +00:00
|
|
|
slow <- needsTemplateHaskell <$> depanal [] False
|
|
|
|
when slow setSlowDynFlags
|
|
|
|
void $ load LoadAllTargets
|
2011-08-24 07:50:26 +00:00
|
|
|
liftIO readLog
|
2012-02-27 02:23:56 +00:00
|
|
|
options
|
2013-02-12 05:21:48 +00:00
|
|
|
| expandSplice opt = "-w:" : ghcOpts opt
|
|
|
|
| otherwise = "-Wall" : ghcOpts opt
|