; return (Nothing, mkModuleName m, [], []) }
other -> do { buf <- hGetStringBuffer input_fn
- ; (src_imps,imps,L _ mod_name) <- getImports dflags buf input_fn
+ ; (src_imps,imps,L _ mod_name) <- getImports dflags buf input_fn (basename `joinFileExt` suff)
; return (Just buf, mod_name, imps, src_imps) }
-- Build a ModLocation to pass to hscMain.
(dflags', hspp_fn, buf)
<- preprocessFile dflags file mb_phase maybe_buf
- (srcimps,the_imps, L _ mod_name) <- getImports dflags' buf hspp_fn
+ (srcimps,the_imps, L _ mod_name) <- getImports dflags' buf hspp_fn file
-- Make a ModLocation for this file
location <- mkHomeModLocation dflags mod_name file
-- Preprocess the source file and get its imports
-- The dflags' contains the OPTIONS pragmas
(dflags', hspp_fn, buf) <- preprocessFile dflags src_fn Nothing maybe_buf
- (srcimps, the_imps, L mod_loc mod_name) <- getImports dflags' buf hspp_fn
+ (srcimps, the_imps, L mod_loc mod_name) <- getImports dflags' buf hspp_fn src_fn
when (mod_name /= wanted_mod) $
throwDyn $ mkPlainErrMsg mod_loc $
-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
-- for details
-module HeaderInfo ( getImportsFromFile, getImports
+module HeaderInfo ( getImports
, getOptionsFromFile, getOptions
, optionsErrorMsgs ) where
openBinaryFile fp mode = openFileEx fp (BinaryMode mode)
#endif
--- getImportsFromFile is careful to close the file afterwards, otherwise
--- we can end up with a large number of open handles before the garbage
--- collector gets around to closing them.
-getImportsFromFile :: DynFlags -> FilePath
- -> IO ([Located ModuleName], [Located ModuleName], Located ModuleName)
-getImportsFromFile dflags filename = do
- buf <- hGetStringBuffer filename
- getImports dflags buf filename
-
-getImports :: DynFlags -> StringBuffer -> FilePath
+getImports :: DynFlags -> StringBuffer -> FilePath -> FilePath
-> IO ([Located ModuleName], [Located ModuleName], Located ModuleName)
-getImports dflags buf filename = do
+getImports dflags buf filename source_filename = do
let loc = mkSrcLoc (mkFastString filename) 1 0
case unP parseHeader (mkPState buf loc dflags) of
PFailed span err -> parseError span err
case rdr_module of
L _ (HsModule mb_mod _ imps _ _ _ _ _) ->
let
- mod = mb_mod `orElse` L (srcLocSpan loc) mAIN_NAME
+ main_loc = mkSrcLoc (mkFastString source_filename) 1 0
+ mod = mb_mod `orElse` L (srcLocSpan main_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)