summaryrefslogtreecommitdiff
path: root/compiler/GHC
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/GHC')
-rw-r--r--compiler/GHC/Driver/Main.hs7
-rw-r--r--compiler/GHC/Driver/Plugins.hs22
2 files changed, 22 insertions, 7 deletions
diff --git a/compiler/GHC/Driver/Main.hs b/compiler/GHC/Driver/Main.hs
index 3fa3d581ce..7fd07d31cf 100644
--- a/compiler/GHC/Driver/Main.hs
+++ b/compiler/GHC/Driver/Main.hs
@@ -493,10 +493,11 @@ hscParse' mod_summary
-- apply parse transformation of plugins
let applyPluginAction p opts
- = uncurry (parsedResultAction p opts mod_summary)
+ = parsedResultAction p opts mod_summary
hsc_env <- getHscEnv
- (transformed, (warns, errs)) <-
- withPlugins (hsc_plugins hsc_env) applyPluginAction (res, getPsMessages pst)
+ (ParsedResult transformed (PsMessages warns errs)) <-
+ withPlugins (hsc_plugins hsc_env) applyPluginAction
+ (ParsedResult res (uncurry PsMessages $ getPsMessages pst))
logDiagnostics (GhcPsMessage <$> warns)
unless (isEmptyMessages errs) $ throwErrors (GhcPsMessage <$> errs)
diff --git a/compiler/GHC/Driver/Plugins.hs b/compiler/GHC/Driver/Plugins.hs
index 64e82c42b6..67d8422562 100644
--- a/compiler/GHC/Driver/Plugins.hs
+++ b/compiler/GHC/Driver/Plugins.hs
@@ -12,6 +12,8 @@ module GHC.Driver.Plugins (
, Plugin(..)
, defaultPlugin
, CommandLineOption
+ , PsMessages(..)
+ , ParsedResult(..)
-- ** Recompilation checking
, purePlugin, impurePlugin, flagRecompile
, PluginRecompile(..)
@@ -89,6 +91,19 @@ import GHC.Types.Unique.DFM
-- are given to you as this type
type CommandLineOption = String
+-- | Errors and warnings produced by the parser
+data PsMessages = PsMessages { psWarnings :: Messages PsWarning
+ , psErrors :: Messages PsError
+ }
+
+-- | Result of running the parser and the parser plugin
+data ParsedResult = ParsedResult
+ { -- | Parsed module, potentially modified by a plugin
+ parsedResultModule :: HsParsedModule
+ , -- | Warnings and errors from parser, potentially modified by a plugin
+ parsedResultMessages :: PsMessages
+ }
+
-- | 'Plugin' is the compiler plugin data type. Try to avoid
-- constructing one of these directly, and just modify some fields of
-- 'defaultPlugin' instead: this is to try and preserve source-code
@@ -121,9 +136,8 @@ data Plugin = Plugin {
, pluginRecompile :: [CommandLineOption] -> IO PluginRecompile
-- ^ Specify how the plugin should affect recompilation.
- , parsedResultAction :: [CommandLineOption] -> ModSummary -> HsParsedModule
- -> (Messages PsWarning, Messages PsError)
- -> Hsc (HsParsedModule, (Messages PsWarning, Messages PsError))
+ , parsedResultAction :: [CommandLineOption] -> ModSummary
+ -> ParsedResult -> Hsc ParsedResult
-- ^ Modify the module when it is parsed. This is called by
-- "GHC.Driver.Main" when the parser has produced no or only non-fatal
-- errors.
@@ -237,7 +251,7 @@ defaultPlugin = Plugin {
, driverPlugin = const return
, pluginRecompile = impurePlugin
, renamedResultAction = \_ env grp -> return (env, grp)
- , parsedResultAction = \_ _ mod msgs -> return (mod, msgs)
+ , parsedResultAction = \_ _ -> return
, typeCheckResultAction = \_ _ -> return
, spliceRunAction = \_ -> return
, interfaceLoadAction = \_ -> return