summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-11-09 22:36:44 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-11-09 22:36:44 +0000
commitf1eaab122932a5c61b13ce9ae6d590e24558eb84 (patch)
tree76b76dd5e34e68da9376188bfd56d9a95742b39b
parentb328ee55d86acaafd55ebf0e0c84766b29459530 (diff)
downloadclang-f1eaab122932a5c61b13ce9ae6d590e24558eb84.tar.gz
clang-f1eaab122932a5c61b13ce9ae6d590e24558eb84.tar.bz2
clang-f1eaab122932a5c61b13ce9ae6d590e24558eb84.tar.xz
PR14303: Add a NoDriverOption flag to those options which are not accepted by
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
-rw-r--r--include/clang/Driver/CC1Options.td2
-rw-r--r--include/clang/Driver/OptParser.td3
-rw-r--r--include/clang/Driver/OptTable.h10
-rw-r--r--include/clang/Driver/Option.h3
-rw-r--r--lib/Driver/Driver.cpp4
-rw-r--r--lib/Driver/OptTable.cpp10
-rw-r--r--lib/FrontendTool/ExecuteCompilerInvocation.cpp5
-rw-r--r--test/Driver/immediate-options.c6
8 files changed, 26 insertions, 17 deletions
diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td
index 0c54ecc50a..61c3d4919f 100644
--- a/include/clang/Driver/CC1Options.td
+++ b/include/clang/Driver/CC1Options.td
@@ -11,7 +11,7 @@
//
//===----------------------------------------------------------------------===//
-let Flags = [CC1Option] in {
+let Flags = [CC1Option, NoDriverOption] in {
//===----------------------------------------------------------------------===//
// Target Options
diff --git a/include/clang/Driver/OptParser.td b/include/clang/Driver/OptParser.td
index 9a3eb0984f..d16a2a7793 100644
--- a/include/clang/Driver/OptParser.td
+++ b/include/clang/Driver/OptParser.td
@@ -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> {
diff --git a/include/clang/Driver/OptTable.h b/include/clang/Driver/OptTable.h
index 63bec30d77..53d83a0f38 100644
--- a/include/clang/Driver/OptTable.h
+++ b/include/clang/Driver/OptTable.h
@@ -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;
};
}
}
diff --git a/include/clang/Driver/Option.h b/include/clang/Driver/Option.h
index c96ec68409..c3db773cd9 100644
--- a/include/clang/Driver/Option.h
+++ b/include/clang/Driver/Option.h
@@ -36,7 +36,8 @@ namespace options {
NoArgumentUnused = (1 << 6),
NoForward = (1 << 7),
Unsupported = (1 << 8),
- CC1Option = (1 << 9)
+ CC1Option = (1 << 9),
+ NoDriverOption = (1 << 10)
};
}
diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp
index 7d63bf4ae6..464df333f7 100644
--- a/lib/Driver/Driver.cpp
+++ b/lib/Driver/Driver.cpp
@@ -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 {
diff --git a/lib/Driver/OptTable.cpp b/lib/Driver/OptTable.cpp
index db59298743..6e7b6951fb 100644
--- a/lib/Driver/OptTable.cpp
+++ b/lib/Driver/OptTable.cpp
@@ -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)) {
diff --git a/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/lib/FrontendTool/ExecuteCompilerInvocation.cpp
index 2433cf051e..c7c55b0211 100644
--- a/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ b/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -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;
}
diff --git a/test/Driver/immediate-options.c b/test/Driver/immediate-options.c
index 5a3ec872b4..2b54ecf7c1 100644
--- a/test/Driver/immediate-options.c
+++ b/test/Driver/immediate-options.c
@@ -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