@@ -59,6 +59,7 @@ import qualified GHC hiding (parseModule)
5959import qualified Control.Monad.IO.Class as GHC
6060import qualified GHC.Data.FastString as GHC
6161import qualified GHC.Data.StringBuffer as GHC
62+ import qualified GHC.Driver.Config.Diagnostic as GHC
6263import qualified GHC.Driver.Config.Parser as GHC
6364import qualified GHC.Driver.Env.Types as GHC
6465import qualified GHC.Driver.Errors.Types as GHC
@@ -117,17 +118,33 @@ runParser parser flags filename str = GHC.unP parser parseState
117118 -- TODO: precompute the macros first, store them in an IORef
118119 -- macros = Nothing
119120 macros = fromMaybe Map. empty macrosFromIORef
120- parseState0 = GHC. initParserStateWithMacrosString flags Nothing (GHC. initParserOpts flags) buffer location
121+ -- opts0 = GHC.initParserOpts flags
122+ -- opts1 = GHC.enableExtBit GHC.UsePosPragsBit opts0
123+ -- opts = opts1
124+ opts = myInitParserOpts flags
125+ parseState0 = GHC. initParserStateWithMacrosString flags Nothing opts buffer location
121126 parseState = parseState0 { GHC. pp = (GHC. pp parseState0) { GHC. pp_defines = macros }
122127 , GHC. buffer = buffer }
123128
129+
124130macroIORef :: IORef (Maybe GHC. MacroDefines )
125131{-# NOINLINE macroIORef #-}
126132macroIORef = unsafePerformIO (newIORef Nothing )
127133
128134macrosFromIORef :: Maybe GHC. MacroDefines
129135macrosFromIORef = unsafePerformIO (readIORef macroIORef)
130136
137+ myInitParserOpts :: GHC. DynFlags -> GHC. ParserOpts
138+ myInitParserOpts =
139+ GHC. mkParserOpts
140+ <$> GHC. extensionFlags
141+ <*> GHC. initDiagOpts
142+ <*> GHC. safeImportsOn
143+ <*> GHC. gopt GHC. Opt_Haddock
144+ <*> GHC. gopt GHC. Opt_KeepRawTokenStream
145+ <*> const False -- do not use LINE/COLUMN to update the internal location
146+
147+
131148-- ---------------------------------------------------------------------
132149
133150-- | Provides a safe way to consume a properly initialised set of
@@ -277,13 +294,9 @@ parseModuleEpAnnsWithGhcCppInternal cppOptions dflags file = do
277294 (fileContents, injectedComments, dflags') <-
278295 if useCpp
279296 then do
280- -- (contents,dflags1) <- getPreprocessedSrcDirect cppOptions file
281- -- cppComments <- getCppTokensAsComments cppOptions file
282- -- return (contents,cppComments,dflags1)
283297 txt <- GHC. liftIO $ readFileGhc file
284- -- let (contents1,lp) = stripLinePragmas txt
285298 let (contents1,lp) = (txt, [] )
286- let no_cpp_dflags = GHC. xopt_unset dflags LangExt. GhcCpp
299+ let no_cpp_dflags = GHC. xopt_unset dflags LangExt. Cpp
287300 return (contents1, lp, GHC. xopt_set no_cpp_dflags LangExt. GhcCpp )
288301 else do
289302 txt <- GHC. liftIO $ readFileGhc file
0 commit comments