@@ -38,7 +38,6 @@ import qualified HeaderInfo as Hdr
3838import MkIface
3939import StringBuffer as SB
4040import TidyPgm
41−import qualified GHC.LanguageExtensions as LangExt
4241
4342import Control.Monad.Extra
4443import Control.Monad.Except
@@ -264,6 +263,7 @@ getModSummaryFromBuffer fp contents dflags parsed = do
264263 then (HsBootFile, \newExt -> stem <.> newExt ++ "-boot")
265264 else (HsSrcFile , \newExt -> stem <.> newExt)
266265
266+
267267-- | Given a buffer, flags, file path and module summary, produce a
268268-- parsed module (or errors) and any parse warnings.
269269parseFileContents
@@ -273,27 +273,8 @@ parseFileContents
273273 -> Maybe SB.StringBuffer -- ^ Haskell module source text (full Unicode is supported)
274274 -> ExceptT [FileDiagnostic] m ([FileDiagnostic], ParsedModule)
275275parseFileContents sourcePlugin filename mbContents = do
276+ (contents, dflags) <- preprocessor filename mbContents
276277 let loc = mkRealSrcLoc (mkFastString filename) 1 1
277− contents <- liftIO $ maybe (hGetStringBuffer filename) return mbContents
278− let isOnDisk = isNothing mbContents
279−
280− -- unlit content if literate Haskell ending
281− (isOnDisk, contents) <- if ".lhs" `isSuffixOf` filename
282− then do
283− dflags <- getDynFlags
284− newcontent <- liftIO $ runLhs dflags filename mbContents
285− return (False, newcontent)
286− else return (isOnDisk, contents)
287−
288− dflags <- ExceptT $ parsePragmasIntoDynFlags filename contents
289− (contents, dflags) <-
290− if not $ xopt LangExt.Cpp dflags then
291− return (contents, dflags)
292− else do
293− contents <- liftIO $ runCpp dflags filename $ if isOnDisk then Nothing else Just contents
294− dflags <- ExceptT $ parsePragmasIntoDynFlags filename contents
295− return (contents, dflags)
296−
297278 case unP Parser.parseModule (mkPState dflags contents loc) of
298279 PFailed _ locErr msgErr ->
299280 throwE $ diagFromErrMsg "parser" dflags $ mkPlainErrMsg dflags locErr msgErr
@@ -330,16 +311,3 @@ parseFileContents sourcePlugin filename mbContents = do
330311 }
331312 warnings = diagFromErrMsgs "parser" dflags warns
332313 pure (warnings, pm)
333−
334−
335−-- | This reads the pragma information directly from the provided buffer.
336−parsePragmasIntoDynFlags
337− :: GhcMonad m
338− => FilePath
339− -> SB.StringBuffer
340− -> m (Either [FileDiagnostic] DynFlags)
341−parsePragmasIntoDynFlags fp contents = catchSrcErrors "pragmas" $ do
342− dflags0 <- getSessionDynFlags
343− let opts = Hdr.getOptions dflags0 contents fp
344− (dflags, _, _) <- parseDynamicFilePragma dflags0 opts
345− return dflags