[commit: ghc] master: Add --show-options to list all flags (Fixes #7843) (a28731b)

Edward Z. Yang ezyang at MIT.EDU
Fri Jun 7 00:24:19 CEST 2013


Repository : http://darcs.haskell.org/ghc.git/

On branch  : master

https://github.com/ghc/ghc/commit/a28731b3a14ff6ef9c7dca8327d073e6ebb6b773

>---------------------------------------------------------------

commit a28731b3a14ff6ef9c7dca8327d073e6ebb6b773
Author: Jan Stolarek <jan.stolarek at p.lodz.pl>
Date:   Tue Jun 4 10:28:32 2013 +0200

    Add --show-options to list all flags (Fixes #7843)

>---------------------------------------------------------------

 compiler/main/StaticFlags.hs | 13 ++++++++++---
 ghc/Main.hs                  | 21 ++++++++++++++++++++-
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/compiler/main/StaticFlags.hs b/compiler/main/StaticFlags.hs
index a1104de..09d5772 100644
--- a/compiler/main/StaticFlags.hs
+++ b/compiler/main/StaticFlags.hs
@@ -35,7 +35,10 @@ module StaticFlags (
         addOpt, removeOpt, v_opt_C_ready,
 
         -- Saving/restoring globals
-        saveStaticFlagGlobals, restoreStaticFlagGlobals
+        saveStaticFlagGlobals, restoreStaticFlagGlobals,
+
+        -- For options autocompletion
+        flagsStatic, flagsStaticNames
   ) where
 
 #include "HsVersions.h"
@@ -139,9 +142,13 @@ flagsStatic = [
   ]
 
 
+
 isStaticFlag :: String -> Bool
-isStaticFlag f =
-  f `elem` [
+isStaticFlag f = f `elem` flagsStaticNames
+
+
+flagsStaticNames :: [String]
+flagsStaticNames = [
     "fdicts-strict",
     "fno-state-hack",
     "fno-opt-coercion",
diff --git a/ghc/Main.hs b/ghc/Main.hs
index f636c38..52a90d0 100644
--- a/ghc/Main.hs
+++ b/ghc/Main.hs
@@ -109,6 +109,7 @@ main = do
                    ShowSupportedExtensions -> showSupportedExtensions
                    ShowVersion             -> showVersion
                    ShowNumVersion          -> putStrLn cProjectVersion
+                   ShowOptions             -> showOptions
         Right postStartupMode ->
             -- start our GHC session
             GHC.runGhc mbMinusB $ do
@@ -371,11 +372,13 @@ data PreStartupMode
   = ShowVersion             -- ghc -V/--version
   | ShowNumVersion          -- ghc --numeric-version
   | ShowSupportedExtensions -- ghc --supported-extensions
+  | ShowOptions             -- ghc --show-options
 
-showVersionMode, showNumVersionMode, showSupportedExtensionsMode :: Mode
+showVersionMode, showNumVersionMode, showSupportedExtensionsMode, showOptionsMode :: Mode
 showVersionMode             = mkPreStartupMode ShowVersion
 showNumVersionMode          = mkPreStartupMode ShowNumVersion
 showSupportedExtensionsMode = mkPreStartupMode ShowSupportedExtensions
+showOptionsMode             = mkPreStartupMode ShowOptions
 
 mkPreStartupMode :: PreStartupMode -> Mode
 mkPreStartupMode = Left
@@ -519,6 +522,7 @@ mode_flags =
   , Flag "-version"              (PassFlag (setMode showVersionMode))
   , Flag "-numeric-version"      (PassFlag (setMode showNumVersionMode))
   , Flag "-info"                 (PassFlag (setMode showInfoMode))
+  , Flag "-show-options"         (PassFlag (setMode showOptionsMode))
   , Flag "-supported-languages"  (PassFlag (setMode showSupportedExtensionsMode))
   , Flag "-supported-extensions" (PassFlag (setMode showSupportedExtensionsMode))
   ] ++
@@ -693,6 +697,21 @@ showSupportedExtensions = mapM_ putStrLn supportedLanguagesAndExtensions
 showVersion :: IO ()
 showVersion = putStrLn (cProjectName ++ ", version " ++ cProjectVersion)
 
+showOptions :: IO ()
+showOptions = putStr (unlines availableOptions)
+    where
+      availableOptions     = map ((:) '-') . filter ((>2) . length) $
+                             getFlagNames mode_flags   ++
+                             getFlagNames flagsDynamic ++
+                             (filterUnwantedStatic . getFlagNames $ flagsStatic) ++
+                             flagsStaticNames
+      getFlagNames opts         = map getFlagName opts
+      getFlagName (Flag name _) = name
+      -- this is a hack to get rid of two unwanted entries that get listed
+      -- as static flags. Hopefully this hack will disappear one day together
+      -- with static flags
+      filterUnwantedStatic      = filter (\x -> not (x `elem` ["f", "fno-"]))
+
 showGhcUsage :: DynFlags -> IO ()
 showGhcUsage = showUsage False
 





More information about the ghc-commits mailing list