@@ -36,30 +36,30 @@ import GHC.Utils.Outputable (renderWithContext)
36
36
37
37
-- | Given a file and some contents, apply any necessary preprocessors,
38
38
-- e.g. unlit/cpp. Return the resulting buffer and the DynFlags it implies.
39
- preprocessor :: HscEnv -> FilePath -> Maybe Util. StringBuffer -> ExceptT [FileDiagnostic ] IO (Util. StringBuffer , [String ], DynFlags )
40
- preprocessor env0 filename mbContents = do
39
+ preprocessor :: HscEnv -> FilePath -> Maybe Util. StringBuffer -> ExceptT [FileDiagnostic ] IO (Util. StringBuffer , [String ], HscEnv )
40
+ preprocessor env filename mbContents = do
41
41
-- Perform unlit
42
42
(isOnDisk, contents) <-
43
43
if isLiterate filename then do
44
- newcontent <- liftIO $ runLhs env0 filename mbContents
44
+ newcontent <- liftIO $ runLhs env filename mbContents
45
45
return (False , newcontent)
46
46
else do
47
47
contents <- liftIO $ maybe (Util. hGetStringBuffer filename) return mbContents
48
48
let isOnDisk = isNothing mbContents
49
49
return (isOnDisk, contents)
50
50
51
51
-- Perform cpp
52
- (opts, dflags ) <- ExceptT $ parsePragmasIntoDynFlags env0 filename contents
53
- let env1 = hscSetFlags dflags env0
54
- let logger = hsc_logger env1
55
- (isOnDisk, contents, opts, dflags ) <-
52
+ (opts, env ) <- ExceptT $ parsePragmasIntoHscEnv env filename contents
53
+ let dflags = hsc_dflags env
54
+ let logger = hsc_logger env
55
+ (isOnDisk, contents, opts, env ) <-
56
56
if not $ xopt LangExt. Cpp dflags then
57
- return (isOnDisk, contents, opts, dflags )
57
+ return (isOnDisk, contents, opts, env )
58
58
else do
59
59
cppLogs <- liftIO $ newIORef []
60
60
let newLogger = pushLogHook (const (logActionCompat $ logAction cppLogs)) logger
61
61
contents <- ExceptT
62
- $ (Right <$> (runCpp (putLogHook newLogger env1 ) filename
62
+ $ (Right <$> (runCpp (putLogHook newLogger env ) filename
63
63
$ if isOnDisk then Nothing else Just contents))
64
64
`catch`
65
65
( \ (e :: Util. GhcException ) -> do
@@ -68,16 +68,16 @@ preprocessor env0 filename mbContents = do
68
68
[] -> throw e
69
69
diags -> return $ Left diags
70
70
)
71
- (opts, dflags ) <- ExceptT $ parsePragmasIntoDynFlags env1 filename contents
72
- return (False , contents, opts, dflags )
71
+ (opts, env ) <- ExceptT $ parsePragmasIntoHscEnv env filename contents
72
+ return (False , contents, opts, env )
73
73
74
74
-- Perform preprocessor
75
75
if not $ gopt Opt_Pp dflags then
76
- return (contents, opts, dflags )
76
+ return (contents, opts, env )
77
77
else do
78
- contents <- liftIO $ runPreprocessor env1 filename $ if isOnDisk then Nothing else Just contents
79
- (opts, dflags ) <- ExceptT $ parsePragmasIntoDynFlags env1 filename contents
80
- return (contents, opts, dflags )
78
+ contents <- liftIO $ runPreprocessor env filename $ if isOnDisk then Nothing else Just contents
79
+ (opts, env ) <- ExceptT $ parsePragmasIntoHscEnv env filename contents
80
+ return (contents, opts, env )
81
81
where
82
82
logAction :: IORef [CPPLog ] -> LogActionCompat
83
83
logAction cppLogs dflags _reason severity srcSpan _style msg = do
@@ -137,12 +137,12 @@ isLiterate x = takeExtension x `elem` [".lhs",".lhs-boot"]
137
137
138
138
139
139
-- | This reads the pragma information directly from the provided buffer.
140
- parsePragmasIntoDynFlags
140
+ parsePragmasIntoHscEnv
141
141
:: HscEnv
142
142
-> FilePath
143
143
-> Util. StringBuffer
144
- -> IO (Either [FileDiagnostic ] ([String ], DynFlags ))
145
- parsePragmasIntoDynFlags env fp contents = catchSrcErrors dflags0 " pragmas" $ do
144
+ -> IO (Either [FileDiagnostic ] ([String ], HscEnv ))
145
+ parsePragmasIntoHscEnv env fp contents = catchSrcErrors dflags0 " pragmas" $ do
146
146
#if MIN_VERSION_ghc(9,3,0)
147
147
let (_warns,opts) = getOptions (initParserOpts dflags0) contents fp
148
148
#else
@@ -154,7 +154,7 @@ parsePragmasIntoDynFlags env fp contents = catchSrcErrors dflags0 "pragmas" $ do
154
154
155
155
(dflags, _, _) <- parseDynamicFilePragma dflags0 opts
156
156
hsc_env' <- initializePlugins (hscSetFlags dflags env)
157
- return (map unLoc opts, disableWarningsAsErrors ( hsc_dflags hsc_env'))
157
+ return (map unLoc opts, hscSetFlags (disableWarningsAsErrors $ hsc_dflags hsc_env') hsc_env' )
158
158
where dflags0 = hsc_dflags env
159
159
160
160
-- | Run (unlit) literate haskell preprocessor on a file, or buffer if set
0 commit comments