-- DLL building
doMkDLL,
- getOptionsFromStringBuffer, -- used in module GHC
+ getOptionsFromStringBuffer, -- used in module GHC
+ optionsErrorMsgs, -- ditto
) where
#include "HsVersions.h"
import Ctype ( is_ident )
import StringBuffer ( StringBuffer(..), lexemeToString )
import ParserCoreUtils ( getCoreModuleName )
+import SrcLoc ( srcLocSpan, mkSrcLoc )
+import FastString ( mkFastString )
+import Bag ( listToBag, emptyBag )
import EXCEPTION
import DATA_IOREF ( readIORef, writeIORef, IORef )
-- It might be better to cache the flags in the ml_hspp_file field,say
let hspp_buf = expectJust "compile:hspp_buf" (ms_hspp_buf mod_summary)
opts = getOptionsFromStringBuffer hspp_buf
- (dflags1,unhandled_flags) <- parseDynamicFlags dflags0 opts
- checkProcessArgsResult unhandled_flags input_fn
+ (dflags1,unhandled_flags) <- parseDynamicFlags dflags0 (map snd opts)
+ if (not (null unhandled_flags))
+ then do msg_act (optionsErrorMsgs unhandled_flags opts input_fn)
+ return CompErrs
+ else do
let (basename, _) = splitFilename input_fn
return (opts ++ rest)
| otherwise -> return []
-getOptionsFromStringBuffer :: StringBuffer -> [String]
+getOptionsFromStringBuffer :: StringBuffer -> [(Int,String)]
getOptionsFromStringBuffer buffer@(StringBuffer _ len# _) =
let
ls = lines (lexemeToString buffer (I# len#)) -- lazy, so it's ok
in
- look ls
+ look 1 ls
where
- look [] = []
- look (l':ls) = do
+ look i [] = []
+ look i (l':ls) = do
let l = removeSpaces l'
case () of
- () | null l -> look ls
- | prefixMatch "#" l -> look ls
- | prefixMatch "{-# LINE" l -> look ls -- -}
+ () | null l -> look (i+1) ls
+ | prefixMatch "#" l -> look (i+1) ls
+ | prefixMatch "{-# LINE" l -> look (i+1) ls -- -}
| Just opts <- matchOptions l
- -> opts ++ look ls
+ -> zip (repeat i) opts ++ look (i+1) ls
| otherwise -> []
-- detect {-# OPTIONS_GHC ... #-}. For the time being, we accept OPTIONS
| otherwise = Nothing
+optionsErrorMsgs :: [String] -> [(Int,String)] -> FilePath -> Messages
+optionsErrorMsgs unhandled_flags flags_lines filename
+ = (emptyBag, listToBag (map mkMsg unhandled_flags_lines))
+ where
+ unhandled_flags_lines = [ (l,f) | f <- unhandled_flags,
+ (l,f') <- flags_lines, f == f' ]
+ mkMsg (line,flag) =
+ ErrUtils.mkPlainErrMsg (srcLocSpan loc) $
+ text "unknown flag in {-# OPTIONS #-} pragma:" <+> text flag
+ where
+ loc = mkSrcLoc (mkFastString filename) line 0
+ -- ToDo: we need a better SrcSpan here
+
-- -----------------------------------------------------------------------------
-- Misc.