summaryrefslogtreecommitdiff
path: root/compiler/GHC/Driver
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2020-09-10 18:20:45 +0200
committerSylvain Henry <sylvain@haskus.fr>2020-09-29 17:24:03 +0200
commit8e3f00dd24936b6674d0a2322f8410125968583e (patch)
treed9630cc481aff867c16300b049b28e8cdd1a7aa2 /compiler/GHC/Driver
parent4365d77a0b306ada61654c3648b844cfa0f4fdcf (diff)
downloadhaskell-8e3f00dd24936b6674d0a2322f8410125968583e.tar.gz
Make the parser module less dependent on DynFlags
Bump haddock submodule
Diffstat (limited to 'compiler/GHC/Driver')
-rw-r--r--compiler/GHC/Driver/Backpack.hs3
-rw-r--r--compiler/GHC/Driver/Config.hs14
-rw-r--r--compiler/GHC/Driver/Main.hs5
3 files changed, 19 insertions, 3 deletions
diff --git a/compiler/GHC/Driver/Backpack.hs b/compiler/GHC/Driver/Backpack.hs
index 36be9d15db..494cffb785 100644
--- a/compiler/GHC/Driver/Backpack.hs
+++ b/compiler/GHC/Driver/Backpack.hs
@@ -27,6 +27,7 @@ import GHC.Parser.Annotation
import GHC hiding (Failed, Succeeded)
import GHC.Parser
import GHC.Parser.Lexer
+import GHC.Driver.Config
import GHC.Driver.Monad
import GHC.Driver.Session
import GHC.Driver.Ppr
@@ -83,7 +84,7 @@ doBackpack [src_filename] = do
buf <- liftIO $ hGetStringBuffer src_filename
let loc = mkRealSrcLoc (mkFastString src_filename) 1 1 -- TODO: not great
- case unP parseBackpack (mkPState dflags buf loc) of
+ case unP parseBackpack (initParserState (initParserOpts dflags) buf loc) of
PFailed pst -> throwErrors (getErrorMessages pst dflags)
POk _ pkgname_bkp -> do
-- OK, so we have an LHsUnit PackageName, but we want an
diff --git a/compiler/GHC/Driver/Config.hs b/compiler/GHC/Driver/Config.hs
index f178597d1c..9cb566437b 100644
--- a/compiler/GHC/Driver/Config.hs
+++ b/compiler/GHC/Driver/Config.hs
@@ -2,6 +2,7 @@
module GHC.Driver.Config
( initOptCoercionOpts
, initSimpleOpts
+ , initParserOpts
)
where
@@ -10,6 +11,7 @@ import GHC.Prelude
import GHC.Driver.Session
import GHC.Core.SimpleOpt
import GHC.Core.Coercion.Opt
+import GHC.Parser.Lexer
-- | Initialise coercion optimiser configuration from DynFlags
initOptCoercionOpts :: DynFlags -> OptCoercionOpts
@@ -23,3 +25,15 @@ initSimpleOpts dflags = SimpleOpts
{ so_uf_opts = unfoldingOpts dflags
, so_co_opts = initOptCoercionOpts dflags
}
+
+-- | Extracts the flag information needed for parsing
+initParserOpts :: DynFlags -> ParserOpts
+initParserOpts =
+ mkParserOpts
+ <$> warningFlags
+ <*> extensionFlags
+ <*> homeUnitId_
+ <*> safeImportsOn
+ <*> gopt Opt_Haddock
+ <*> gopt Opt_KeepRawTokenStream
+ <*> const True
diff --git a/compiler/GHC/Driver/Main.hs b/compiler/GHC/Driver/Main.hs
index 44babeec18..593251a253 100644
--- a/compiler/GHC/Driver/Main.hs
+++ b/compiler/GHC/Driver/Main.hs
@@ -138,6 +138,7 @@ import GHC.Cmm.Info.Build
import GHC.Cmm.Pipeline
import GHC.Cmm.Info
import GHC.Driver.CodeOutput
+import GHC.Driver.Config
import GHC.Core.InstEnv
import GHC.Core.FamInstEnv
import GHC.Utils.Fingerprint ( Fingerprint )
@@ -353,7 +354,7 @@ hscParse' mod_summary
= parseSignature
| otherwise = parseModule
- case unP parseMod (mkPState dflags buf loc) of
+ case unP parseMod (initParserState (initParserOpts dflags) buf loc) of
PFailed pst ->
handleWarningsThrowErrors (getMessages pst dflags)
POk pst rdr_module -> do
@@ -1875,7 +1876,7 @@ hscParseThingWithLocation source linenumber parser str
let buf = stringToStringBuffer str
loc = mkRealSrcLoc (fsLit source) linenumber 1
- case unP parser (mkPState dflags buf loc) of
+ case unP parser (initParserState (initParserOpts dflags) buf loc) of
PFailed pst -> do
handleWarningsThrowErrors (getMessages pst dflags)