Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
jberryman
GHC
Commits
9d55b184
Commit
9d55b184
authored
May 19, 2004
by
simonpj
Browse files
[project @ 2004-05-19 08:46:21 by simonpj]
Improve error reporting for static flags
parent
812238d6
Changes
1
Hide whitespace changes
Inline
Side-by-side
ghc/compiler/main/CmdLineOpts.lhs
View file @
9d55b184
...
...
@@ -104,6 +104,7 @@ import FastString ( FastString, mkFastString )
import Config
import Maybes ( firstJust )
import Panic ( ghcError, GhcException(UsageError) )
import GLAEXTS
import DATA_IOREF ( IORef, readIORef, writeIORef )
import UNSAFE_IO ( unsafePerformIO )
...
...
@@ -708,19 +709,36 @@ packed_static_opts = map mkFastString unpacked_static_opts
lookUp sw = sw `elem` packed_static_opts
lookup_str sw = firstJust (map (startsWith sw) unpacked_static_opts)
-- (lookup_str "foo") looks for the flag -foo=X or -fooX,
-- and returns the string X
lookup_str sw
= case firstJust (map (startsWith sw) unpacked_static_opts) of
Just ('=' : str) -> Just str
Just str -> Just str
Nothing -> Nothing
lookup_int sw = case (lookup_str sw) of
Nothing -> Nothing
Just xx -> Just (read xx)
Just xx -> Just (
try_
read
sw
xx)
lookup_def_int sw def = case (lookup_str sw) of
Nothing -> def -- Use default
Just xx -> read xx
Just xx ->
try_
read
sw
xx
lookup_def_float sw def = case (lookup_str sw) of
Nothing -> def -- Use default
Just xx -> read xx
Just xx -> try_read sw xx
try_read :: Read a => String -> String -> a
-- (try_read sw str) tries to read s; if it fails, it
-- bleats about flag sw
try_read sw str
= case reads str of
((x,_):_) -> x -- Be forgiving: ignore trailing goop, and alternative parses
[] -> ghcError (UsageError ("Malformed argument " ++ str ++ " for flag " ++ sw))
-- ToDo: hack alert. We should really parse the arugments
-- and announce errors in a more civilised way.
{-
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment