[project @ 2000-11-07 13:12:21 by simonpj]
[ghc-hetmet.git] / ghc / compiler / main / ErrUtils.lhs
index d6a64f3..b6d9bad 100644 (file)
@@ -11,7 +11,7 @@ module ErrUtils (
        dontAddErrLoc,
        printErrorsAndWarnings, pprBagOfErrors, pprBagOfWarnings,
        ghcExit,
-       doIfSet, dumpIfSet
+       doIfSet, doIfSet_dyn, dumpIfSet, dumpIfSet_dyn
     ) where
 
 #include "HsVersions.h"
@@ -20,7 +20,7 @@ import Bag            ( Bag, bagToList, isEmptyBag )
 import SrcLoc          ( SrcLoc, noSrcLoc )
 import Util            ( sortLt )
 import Outputable
-import CmdLineOpts     ( DynFlags )
+import CmdLineOpts     ( DynFlags, DynFlag, dopt )
 
 import System          ( ExitCode(..), exitWith )
 import IO              ( hPutStr, stderr )
@@ -61,9 +61,9 @@ dontAddErrLoc title rest_of_err_msg
  | otherwise  =
     ( noSrcLoc, hang (text title <> colon) 4 rest_of_err_msg )
 
-printErrorsAndWarnings :: Bag ErrMsg -> Bag WarnMsg -> IO ()
+printErrorsAndWarnings :: (Bag WarnMsg, Bag ErrMsg) -> IO ()
        -- Don't print any warnings if there are errors
-printErrorsAndWarnings errs warns
+printErrorsAndWarnings (warns, errs)
   | no_errs && no_warns  = return ()
   | no_errs             = printErrs (pprBagOfWarnings warns)
   | otherwise           = printErrs (pprBagOfErrors   errs)
@@ -96,17 +96,28 @@ ghcExit val
 doIfSet :: Bool -> IO () -> IO ()
 doIfSet flag action | flag      = action
                    | otherwise = return ()
+
+doIfSet_dyn :: DynFlags -> DynFlag -> IO () -> IO()
+doIfSet_dyn dflags flag action | dopt flag dflags = action
+                              | otherwise        = return ()
 \end{code}
 
 \begin{code}
-dumpIfSet :: DynFlags -> (DynFlags -> Bool) -> String -> SDoc -> IO ()
-dumpIfSet dflags flag hdr doc
-  | not (flag dflags)  = return ()
-  | otherwise          = printDump dump
-  where
-    dump = vcat [text "", 
-                line <+> text hdr <+> line,
-                doc,
-                text ""]
-    line = text (take 20 (repeat '='))
+dumpIfSet :: Bool -> String -> SDoc -> IO ()
+dumpIfSet flag hdr doc
+  | not flag   = return ()
+  | otherwise  = printDump (dump hdr doc)
+
+dumpIfSet_dyn :: DynFlags -> DynFlag -> String -> SDoc -> IO ()
+dumpIfSet_dyn dflags flag hdr doc
+  | not (dopt flag dflags)  = return ()
+  | otherwise               = printDump (dump hdr doc)
+
+dump hdr doc 
+   = vcat [text "", 
+          line <+> text hdr <+> line,
+          doc,
+          text ""]
+     where 
+        line = text (take 20 (repeat '='))
 \end{code}