1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
-- | Functions for initialising error message printing configuration from the
-- GHC session flags.
module GHC.Driver.Config.Diagnostic
( initDiagOpts
, initPrintConfig
, initPsMessageOpts
, initDsMessageOpts
, initTcMessageOpts
, initDriverMessageOpts
, initIfaceMessageOpts
)
where
import GHC.Driver.Flags
import GHC.Driver.Session
import GHC.Prelude
import GHC.Utils.Outputable
import GHC.Utils.Error (DiagOpts (..))
import GHC.Driver.Errors.Types (GhcMessage, GhcMessageOpts (..), PsMessage, DriverMessage, DriverMessageOpts (..))
import GHC.Driver.Errors.Ppr ()
import GHC.Tc.Errors.Types
import GHC.HsToCore.Errors.Types
import GHC.Types.Error
import GHC.Tc.Errors.Ppr
import GHC.Iface.Errors.Types
import GHC.Iface.Errors.Ppr
-- | Initialise the general configuration for printing diagnostic messages
-- For example, this configuration controls things like whether warnings are
-- treated like errors.
initDiagOpts :: DynFlags -> DiagOpts
initDiagOpts dflags = DiagOpts
{ diag_warning_flags = warningFlags dflags
, diag_fatal_warning_flags = fatalWarningFlags dflags
, diag_custom_warning_categories = customWarningCategories dflags
, diag_fatal_custom_warning_categories = fatalCustomWarningCategories dflags
, diag_warn_is_error = gopt Opt_WarnIsError dflags
, diag_reverse_errors = reverseErrors dflags
, diag_max_errors = maxErrors dflags
, diag_ppr_ctx = initSDocContext dflags defaultErrStyle
}
-- | Initialise the configuration for printing specific diagnostic messages
initPrintConfig :: DynFlags -> DiagnosticOpts GhcMessage
initPrintConfig dflags =
GhcMessageOpts { psMessageOpts = initPsMessageOpts dflags
, tcMessageOpts = initTcMessageOpts dflags
, dsMessageOpts = initDsMessageOpts dflags
, driverMessageOpts= initDriverMessageOpts dflags }
initPsMessageOpts :: DynFlags -> DiagnosticOpts PsMessage
initPsMessageOpts _ = NoDiagnosticOpts
initTcMessageOpts :: DynFlags -> DiagnosticOpts TcRnMessage
initTcMessageOpts dflags =
TcRnMessageOpts { tcOptsShowContext = gopt Opt_ShowErrorContext dflags
, tcOptsIfaceOpts = initIfaceMessageOpts dflags }
initDsMessageOpts :: DynFlags -> DiagnosticOpts DsMessage
initDsMessageOpts _ = NoDiagnosticOpts
initIfaceMessageOpts :: DynFlags -> DiagnosticOpts IfaceMessage
initIfaceMessageOpts dflags =
IfaceMessageOpts { ifaceShowTriedFiles = verbosity dflags >= 3 }
initDriverMessageOpts :: DynFlags -> DiagnosticOpts DriverMessage
initDriverMessageOpts dflags = DriverMessageOpts (initPsMessageOpts dflags) (initIfaceMessageOpts dflags)
|