+#include "HsVersions.h"
+
+import Bag ( Bag, bagToList, isEmptyBag )
+import SrcLoc ( SrcLoc, noSrcLoc, isGoodSrcLoc )
+import Util ( sortLt )
+import Outputable
+import CmdLineOpts ( DynFlags(..), DynFlag(..), dopt )
+
+import System ( ExitCode(..), exitWith )
+import IO ( hPutStr, hPutStrLn, stderr )
+\end{code}
+
+\begin{code}
+type MsgWithLoc = (SrcLoc, SDoc)
+
+type ErrMsg = MsgWithLoc
+type WarnMsg = MsgWithLoc
+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
+ | isGoodSrcLoc locn = (locn, hang (ppr locn <> colon) 4
+ rest_of_err_msg)
+ | otherwise = (locn, rest_of_err_msg)
+
+addErrLocHdrLine locn hdr rest_of_err_msg
+ = ( locn
+ , hang (ppr locn <> colon<+> hdr)
+ 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))
+ | otherwise = (locn, rest_of_err_msg)
+
+dontAddErrLoc :: Message -> ErrMsg
+dontAddErrLoc msg = (noSrcLoc, msg)