]> granicus.if.org Git - clang/commitdiff
PR14303: Add a NoDriverOption flag to those options which are not accepted by
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 9 Nov 2012 22:36:44 +0000 (22:36 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 9 Nov 2012 22:36:44 +0000 (22:36 +0000)
the driver (the options defined in CC1Options.td) and exclude their help from
"clang --help".

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167638 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/CC1Options.td
include/clang/Driver/OptParser.td
include/clang/Driver/OptTable.h
include/clang/Driver/Option.h
lib/Driver/Driver.cpp
lib/Driver/OptTable.cpp
lib/FrontendTool/ExecuteCompilerInvocation.cpp
test/Driver/immediate-options.c

index 0c54ecc50a7c29f43997960780ebcad71dbdf9b9..61c3d4919fbef007d62b6171293a5c402897e115 100644 (file)
@@ -11,7 +11,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-let Flags = [CC1Option] in {
+let Flags = [CC1Option, NoDriverOption] in {
 
 //===----------------------------------------------------------------------===//
 // Target Options
index 9a3eb0984f0ed660e1d3f0f2df2dbc3e3b658f1d..d16a2a779324b1646b4277a1c0734694f5eb56c3 100644 (file)
@@ -88,6 +88,9 @@ def NoForward : OptionFlag;
 // CC1Option - This option should be accepted by clang -cc1.
 def CC1Option : OptionFlag;
 
+// NoDriverOption - This option should not be accepted by the driver.
+def NoDriverOption : OptionFlag;
+
 // Define the option group class.
 
 class OptionGroup<string name> {
index 63bec30d7782333573fd73b3fc06fb2c94461b82..53d83a0f38aaead54d5c2b61484587f9bfe181cf 100644 (file)
@@ -99,9 +99,6 @@ namespace driver {
       return getInfo(id).GroupID;
     }
 
-    /// \brief Should the help for the given option be hidden by default.
-    bool isOptionHelpHidden(OptSpecifier id) const;
-
     /// \brief Get the help text to use to describe this option.
     const char *getOptionHelpText(OptSpecifier id) const {
       return getInfo(id).HelpText;
@@ -151,9 +148,12 @@ namespace driver {
     /// \param OS - The stream to write the help text to.
     /// \param Name - The name to use in the usage line.
     /// \param Title - The title to use in the usage line.
-    /// \param ShowHidden - Whether help-hidden arguments should be shown.
+    /// \param FlagsToInclude - If non-zero, only include options with any
+    ///                         of these flags set.
+    /// \param FlagsToExclude - Exclude options with any of these flags set.
     void PrintHelp(raw_ostream &OS, const char *Name,
-                   const char *Title, bool ShowHidden = false) const;
+                   const char *Title, unsigned short FlagsToInclude = 0,
+                   unsigned short FlagsToExclude = 0) const;
   };
 }
 }
index c96ec68409d19a0649b9e5d1deb596294d4a0cec..c3db773cd922656c41a1fc00ecbe48c2fe2abae7 100644 (file)
@@ -36,7 +36,8 @@ namespace options {
     NoArgumentUnused = (1 << 6),
     NoForward        = (1 << 7),
     Unsupported      = (1 << 8),
-    CC1Option        = (1 << 9)
+    CC1Option        = (1 << 9),
+    NoDriverOption   = (1 << 10)
   };
 }
 
index 7d63bf4ae6550654a361a973a1cd862b0ee4fffb..464df333f7cd1335f1da63222838e7ca95efb87b 100644 (file)
@@ -564,7 +564,9 @@ void Driver::PrintOptions(const ArgList &Args) const {
 
 void Driver::PrintHelp(bool ShowHidden) const {
   getOpts().PrintHelp(llvm::outs(), Name.c_str(), DriverTitle.c_str(),
-                      ShowHidden);
+                      /*Include*/0,
+                      /*Exclude*/options::NoDriverOption |
+                      (ShowHidden ? 0 : options::HelpHidden));
 }
 
 void Driver::PrintVersion(const Compilation &C, raw_ostream &OS) const {
index db592987431f427a7521e8deee2544d7f69e4e5b..6e7b6951fb83958029da66c40e3e07ef0658d914 100644 (file)
@@ -163,10 +163,6 @@ const Option OptTable::getOption(OptSpecifier Opt) const {
   return Option(&getInfo(id), this);
 }
 
-bool OptTable::isOptionHelpHidden(OptSpecifier id) const {
-  return getInfo(id).Flags & options::HelpHidden;
-}
-
 static bool isInput(const llvm::StringSet<> &Prefixes, StringRef Arg) {
   if (Arg == "-")
     return true;
@@ -350,7 +346,8 @@ static const char *getOptionHelpGroup(const OptTable &Opts, OptSpecifier Id) {
 }
 
 void OptTable::PrintHelp(raw_ostream &OS, const char *Name,
-                         const char *Title, bool ShowHidden) const {
+                         const char *Title, unsigned short FlagsToInclude,
+                         unsigned short FlagsToExclude) const {
   OS << "OVERVIEW: " << Title << "\n";
   OS << '\n';
   OS << "USAGE: " << Name << " [options] <inputs>\n";
@@ -369,7 +366,8 @@ void OptTable::PrintHelp(raw_ostream &OS, const char *Name,
     if (getOptionKind(Id) == Option::GroupClass)
       continue;
 
-    if (!ShowHidden && isOptionHelpHidden(Id))
+    if ((FlagsToInclude && !(getInfo(Id).Flags & FlagsToInclude)) ||
+        getInfo(Id).Flags & FlagsToExclude)
       continue;
 
     if (const char *Text = getOptionHelpText(Id)) {
index 2433cf051e6fc80609113e905644f0cab5ded46f..c7c55b02114556d966351a9e98740c91651d2576 100644 (file)
@@ -16,6 +16,7 @@
 #include "clang/StaticAnalyzer/Frontend/FrontendActions.h"
 #include "clang/ARCMigrate/ARCMTActions.h"
 #include "clang/CodeGen/CodeGenAction.h"
+#include "clang/Driver/Option.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/OptTable.h"
 #include "clang/Frontend/CompilerInvocation.h"
@@ -137,7 +138,9 @@ bool clang::ExecuteCompilerInvocation(CompilerInstance *Clang) {
   if (Clang->getFrontendOpts().ShowHelp) {
     OwningPtr<driver::OptTable> Opts(driver::createDriverOptTable());
     Opts->PrintHelp(llvm::outs(), "clang -cc1",
-                    "LLVM 'Clang' Compiler: http://clang.llvm.org");
+                    "LLVM 'Clang' Compiler: http://clang.llvm.org",
+                    /*Include=*/driver::options::CC1Option,
+                    /*Exclude=*/0);
     return 0;
   }
 
index 5a3ec872b4fe33ecd9fd20dc0237af8ff5231013..2b54ecf7c1501e33670e1b1a0b658fbec410b213 100644 (file)
@@ -1,4 +1,6 @@
-// RUN: %clang --help
-// RUN: %clang --help-hidden
+// RUN: %clang --help | grep isystem
+// RUN: %clang --help | not grep ast-dump
+// RUN: %clang --help | not grep ccc-cxx
+// RUN: %clang --help-hidden | grep ccc-cxx
 // RUN: %clang -dumpversion
 // RUN: %clang -print-search-dirs