[project @ 2001-10-22 13:45:15 by simonmar]
[ghc-hetmet.git] / ghc / compiler / main / ErrUtils.lhs
index ccc03ad..5d3609c 100644 (file)
@@ -8,12 +8,15 @@ module ErrUtils (
        ErrMsg, WarnMsg, Message, Messages, errorsFound, warningsFound,
 
        addShortErrLocLine, addShortWarnLocLine,
-       addErrLocHdrLine, dontAddErrLoc,
+       addErrLocHdrLine, addWarnLocHdrLine, dontAddErrLoc,
 
        printErrorsAndWarnings, pprBagOfErrors, pprBagOfWarnings,
 
+       printError,
        ghcExit,
-       doIfSet, doIfSet_dyn, dumpIfSet, dumpIfSet_core, dumpIfSet_dyn, showPass
+       doIfSet, doIfSet_dyn, 
+       dumpIfSet, dumpIfSet_core, dumpIfSet_dyn, dumpIfSet_dyn_or, 
+       showPass
     ) where
 
 #include "HsVersions.h"
@@ -25,7 +28,7 @@ import Outputable
 import CmdLineOpts     ( DynFlags(..), DynFlag(..), dopt )
 
 import System          ( ExitCode(..), exitWith )
-import IO              ( hPutStr, stderr )
+import IO              ( hPutStr, hPutStrLn, stderr )
 \end{code}
 
 \begin{code}
@@ -37,6 +40,7 @@ type Message = SDoc
 
 addShortErrLocLine  :: SrcLoc -> Message -> ErrMsg
 addErrLocHdrLine    :: SrcLoc -> Message -> Message -> ErrMsg
+addWarnLocHdrLine    :: SrcLoc -> Message -> Message -> ErrMsg
 addShortWarnLocLine :: SrcLoc -> Message -> WarnMsg
 
 addShortErrLocLine locn rest_of_err_msg
@@ -50,6 +54,12 @@ addErrLocHdrLine locn hdr rest_of_err_msg
          4 rest_of_err_msg
     )
 
+addWarnLocHdrLine locn hdr rest_of_err_msg
+  = ( locn
+    , hang (ppr locn <> colon <+> ptext SLIT("Warning:") <+> hdr) 
+         4 (rest_of_err_msg)
+    )
+
 addShortWarnLocLine locn rest_of_err_msg
   | isGoodSrcLoc locn = (locn, hang (ppr locn <> colon) 4 
                                    (ptext SLIT("Warning:") <+> rest_of_err_msg))
@@ -60,6 +70,10 @@ dontAddErrLoc msg = (noSrcLoc, msg)
 
 \end{code}
 
+\begin{code}
+printError :: String -> IO ()
+printError str = hPutStrLn stderr str
+\end{code}
 
 \begin{code}
 type Messages = (Bag WarnMsg, Bag ErrMsg)
@@ -134,6 +148,13 @@ dumpIfSet_dyn dflags flag hdr doc
   | dopt flag dflags || verbosity dflags >= 4 = printDump (dump hdr doc)
   | otherwise                                 = return ()
 
+dumpIfSet_dyn_or :: DynFlags -> [DynFlag] -> String -> SDoc -> IO ()
+dumpIfSet_dyn_or dflags flags hdr doc
+  | or [dopt flag dflags | flag <- flags]
+  || verbosity dflags >= 4 
+  = printDump (dump hdr doc)
+  | otherwise = return ()
+
 dump hdr doc 
    = vcat [text "", 
           line <+> text hdr <+> line,