import PrelNames ( gHC_PRIM, mAIN_NAME )
import StringBuffer ( StringBuffer(..), hGetStringBuffer, hGetStringBufferBlock
, appendStringBuffers )
-import SrcLoc ( Located(..), mkSrcLoc, unLoc, noSrcSpan )
+import SrcLoc
import FastString ( mkFastString )
import DynFlags ( DynFlags )
import ErrUtils
import Outputable
import Pretty ()
import Panic
+import Maybes
import Bag ( emptyBag, listToBag )
import Distribution.Compiler
-import EXCEPTION ( throwDyn )
-import IO
-import List
+import Control.Exception
+import System.IO
+import Data.List
#if __GLASGOW_HASKELL__ >= 601
import System.IO ( openBinaryFile )
PFailed span err -> parseError span err
POk _ rdr_module ->
case rdr_module of
- L _ (HsModule mod _ imps _ _ _ _ _) ->
+ L _ (HsModule mb_mod _ imps _ _ _ _ _) ->
let
- mod_name | Just located_mod <- mod = located_mod
- | otherwise = L noSrcSpan mAIN_NAME
+ mod = mb_mod `orElse` L (srcLocSpan loc) mAIN_NAME
(src_idecls, ord_idecls) = partition isSourceIdecl (map unLoc imps)
source_imps = map getImpMod src_idecls
ordinary_imps = filter ((/= moduleName gHC_PRIM) . unLoc)
(map getImpMod ord_idecls)
-- GHC.Prim doesn't exist physically, so don't go looking for it.
in
- return (source_imps, ordinary_imps, mod_name)
+ return (source_imps, ordinary_imps, mod)
parseError span err = throwDyn $ mkPlainErrMsg span err
getOptionsFromFile :: FilePath -- input file
-> IO [Located String] -- options, if any
getOptionsFromFile filename
- = bracket (openBinaryFile filename ReadMode)
+ = Control.Exception.bracket
+ (openBinaryFile filename ReadMode)
(hClose)
(\handle ->
do buf <- hGetStringBufferBlock handle blockSize