X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fmain%2FHeaderInfo.hs;h=90c6155788d3217d0a1e714706c1a0b36544651c;hb=7fc749a43b4b6b85d234fa95d4928648259584f4;hp=48eda2245249c82ef151aedce3e48da26ac2d157;hpb=190f24892156953d73b55401d0467a6f1a88ce5d;p=ghc-hetmet.git diff --git a/compiler/main/HeaderInfo.hs b/compiler/main/HeaderInfo.hs index 48eda22..90c6155 100644 --- a/compiler/main/HeaderInfo.hs +++ b/compiler/main/HeaderInfo.hs @@ -8,6 +8,13 @@ -- ----------------------------------------------------------------------------- +{-# OPTIONS -w #-} +-- The above warning supression flag is a temporary kludge. +-- While working on this module you are encouraged to remove it and fix +-- any warnings in the module. See +-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings +-- for details + module HeaderInfo ( getImportsFromFile, getImports , getOptionsFromFile, getOptions , optionsErrorMsgs ) where @@ -15,29 +22,29 @@ module HeaderInfo ( getImportsFromFile, getImports #include "HsVersions.h" import Parser ( parseHeader ) -import Lexer ( P(..), ParseResult(..), mkPState, pragState - , lexer, Token(..), PState(..) ) +import Lexer import FastString import HsSyn ( ImportDecl(..), HsModule(..) ) import Module ( ModuleName, moduleName ) import PrelNames ( gHC_PRIM, mAIN_NAME ) import StringBuffer ( StringBuffer(..), hGetStringBuffer, hGetStringBufferBlock , appendStringBuffers ) -import SrcLoc ( Located(..), mkSrcLoc, unLoc, noSrcSpan ) -import FastString ( mkFastString ) -import DynFlags ( DynFlags ) +import Config +import SrcLoc +import DynFlags import ErrUtils import Util 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 Control.Monad +import System.Exit +import System.IO +import Data.List #if __GLASGOW_HASKELL__ >= 601 import System.IO ( openBinaryFile ) @@ -64,19 +71,21 @@ getImports dflags buf filename = do let loc = mkSrcLoc (mkFastString filename) 1 0 case unP parseHeader (mkPState buf loc dflags) of PFailed span err -> parseError span err - POk _ rdr_module -> + POk pst rdr_module -> do + let ms = getMessages pst + printErrorsAndWarnings dflags ms + when (errorsFound dflags ms) $ exitWith (ExitFailure 1) 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 @@ -92,7 +101,8 @@ getImpMod (ImportDecl located_mod _ _ _ _) = located_mod 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 @@ -172,11 +182,13 @@ getOptions' buf filename checkExtension :: Located FastString -> Located String checkExtension (L l ext) - = case reads (unpackFS ext) of - [] -> languagePragParseError l - (okExt,""):_ -> case extensionsToGHCFlag [okExt] of - ([],[opt]) -> L l opt - _ -> unsupportedExtnError l okExt +-- Checks if a given extension is valid, and if so returns +-- its corresponding flag. Otherwise it throws an exception. + = let ext' = unpackFS ext in + if ext' `elem` supportedLanguages + || ext' `elem` (map ("No"++) supportedLanguages) + then L l ("-X"++ext') + else unsupportedExtnError l ext' languagePragParseError loc = pgmError (showSDoc (mkLocMessage loc ( @@ -185,7 +197,7 @@ languagePragParseError loc = unsupportedExtnError loc unsup = pgmError (showSDoc (mkLocMessage loc ( text "unsupported extension: " <> - (text.show) unsup))) + text unsup))) optionsErrorMsgs :: [String] -> [Located String] -> FilePath -> Messages