X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fmain%2FHeaderInfo.hs;h=26c854b3a7f8f069a0dae2b40d23fb17f82ae098;hb=e761a777f2440ca1b8d8b40848cc5aa30d889ff6;hp=a9e205165c88287477706a6f7a259870e95a25c6;hpb=3023a007dfcaf51813c5504e823cb7e8eea002be;p=ghc-hetmet.git diff --git a/compiler/main/HeaderInfo.hs b/compiler/main/HeaderInfo.hs index a9e2051..26c854b 100644 --- a/compiler/main/HeaderInfo.hs +++ b/compiler/main/HeaderInfo.hs @@ -17,7 +17,8 @@ module HeaderInfo ( getImports , getOptionsFromFile, getOptions - , optionsErrorMsgs ) where + , optionsErrorMsgs, + checkProcessArgsResult ) where #include "HsVersions.h" @@ -45,17 +46,6 @@ import System.Exit import System.IO import Data.List -#if !defined(__GLASGOW_HASKELL__) || __GLASGOW_HASKELL__ >= 601 - -- already imported above ---import System.IO ( openBinaryFile ) -#else -import IOExts ( openFileEx, IOModeEx(..) ) -#endif - -#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ < 601 -openBinaryFile fp mode = openFileEx fp (BinaryMode mode) -#endif - getImports :: DynFlags -> StringBuffer -> FilePath -> FilePath -> IO ([Located ModuleName], [Located ModuleName], Located ModuleName) getImports dflags buf filename source_filename = do @@ -93,9 +83,10 @@ getImpMod (ImportDecl located_mod _ _ _ _) = located_mod -------------------------------------------------------------- -getOptionsFromFile :: FilePath -- input file +getOptionsFromFile :: DynFlags + -> FilePath -- input file -> IO [Located String] -- options, if any -getOptionsFromFile filename +getOptionsFromFile dflags filename = Control.Exception.bracket (openBinaryFile filename ReadMode) (hClose) @@ -106,7 +97,7 @@ getOptionsFromFile filename loop handle buf | len buf == 0 = return [] | otherwise - = case getOptions' buf filename of + = case getOptions' dflags buf filename of (Nothing, opts) -> return opts (Just buf', opts) -> do nextBlock <- hGetStringBufferBlock handle blockSize newBuf <- appendStringBuffers buf' nextBlock @@ -115,22 +106,23 @@ getOptionsFromFile filename else do opts' <- loop handle newBuf return (opts++opts') -getOptions :: StringBuffer -> FilePath -> [Located String] -getOptions buf filename - = case getOptions' buf filename of +getOptions :: DynFlags -> StringBuffer -> FilePath -> [Located String] +getOptions dflags buf filename + = case getOptions' dflags buf filename of (_,opts) -> opts -- The token parser is written manually because Happy can't -- return a partial result when it encounters a lexer error. -- We want to extract options before the buffer is passed through -- CPP, so we can't use the same trick as 'getImports'. -getOptions' :: StringBuffer -- Input buffer +getOptions' :: DynFlags + -> StringBuffer -- Input buffer -> FilePath -- Source file. Used for msgs only. -> ( Maybe StringBuffer -- Just => we can use more input , [Located String] -- Options. ) -getOptions' buf filename - = parseToks (lexAll (pragState buf loc)) +getOptions' dflags buf filename + = parseToks (lexAll (pragState dflags buf loc)) where loc = mkSrcLoc (mkFastString filename) 1 0 getToken (_buf,L _loc tok) = tok @@ -184,6 +176,19 @@ getOptions' buf filename POk state' t -> (buffer state,t):lexAll state' _ -> [(buffer state,L (last_loc state) ITeof)] +----------------------------------------------------------------------------- +-- Complain about non-dynamic flags in OPTIONS pragmas + +checkProcessArgsResult :: [String] -> FilePath -> IO () +checkProcessArgsResult flags filename + = do when (notNull flags) (throwDyn (ProgramError ( + showSDoc (hang (text filename <> char ':') + 4 (text "unknown flags in {-# OPTIONS #-} pragma:" <+> + hsep (map text flags))) + ))) + +----------------------------------------------------------------------------- + checkExtension :: Located FastString -> Located String checkExtension (L l ext) -- Checks if a given extension is valid, and if so returns