[PATCH] Adding a new cl::HideUnrelatedOptions API to allow clang to migrate off cl::getRegisteredOptions.

Duncan P. N. Exon Smith dexonsmith at apple.com
Wed Jan 21 11:43:16 PST 2015


Testcase?

LGTM once you add one, with a style nit below.

> On 2015-Jan-21, at 10:44, Chris Bieneman <beanz at apple.com> wrote:
> 
> Hi chandlerc, dexonsmith,
> 
> cl::getRegisteredOptions really exposes some of the innards of how command line parsing is implemented. Exposing new APIs that allow us to disentangle client code from implementation details will allow us to make more extensive changes to command line parsing.
> 
> http://reviews.llvm.org/D7100
> 
> Files:
>  include/llvm/Support/CommandLine.h
>  lib/Support/CommandLine.cpp
> 
> Index: include/llvm/Support/CommandLine.h
> ===================================================================
> --- include/llvm/Support/CommandLine.h
> +++ include/llvm/Support/CommandLine.h
> @@ -1889,6 +1889,15 @@
>                          SmallVectorImpl<const char *> &Argv,
>                          bool MarkEOLs = false);
> 
> +/// \brief Mark all options not part of this category as cl::ReallyHidden.
> +///
> +/// \param Category the category of options to keep displaying
> +///
> +/// Some tools (like clang-format) like to be able to hide all options that are
> +/// not specific to the tool. This function allows a tool to specify a single
> +/// option category to display in the -help output.
> +void HideUnrelatedOptions(cl::OptionCategory &Category);
> +
> } // End namespace cl
> 
> } // End namespace llvm
> Index: lib/Support/CommandLine.cpp
> ===================================================================
> --- lib/Support/CommandLine.cpp
> +++ lib/Support/CommandLine.cpp
> @@ -1826,12 +1826,23 @@
> void cl::getRegisteredOptions(StringMap<Option *> &Map) {
>   // Get all the options.
>   SmallVector<Option *, 4> PositionalOpts; // NOT USED
> -  SmallVector<Option *, 4> SinkOpts; // NOT USED
> +  SmallVector<Option *, 4> SinkOpts;       // NOT USED
>   assert(Map.size() == 0 && "StringMap must be empty");
>   GetOptionInfo(PositionalOpts, SinkOpts, Map);
>   return;
> }
> 
> +void cl::HideUnrelatedOptions(cl::OptionCategory &Category) {
> +  StringMap<cl::Option *> Options;
> +  cl::getRegisteredOptions(Options);
> +  for (StringMap<cl::Option *>::iterator I = Options.begin(), E = Options.end();
> +       I != E; ++I) {

This seems cleaner:

    for (auto &I : Options)
      // ...

> +    if (I->second->Category != &Category && I->first() != "help" &&
> +        I->first() != "version")
> +      I->second->setHiddenFlag(cl::ReallyHidden);
> +  }
> +}
> +
> void LLVMParseCommandLineOptions(int argc, const char *const *argv,
>                                  const char *Overview) {
>   llvm::cl::ParseCommandLineOptions(argc, argv, Overview);
> 
> EMAIL PREFERENCES
>  http://reviews.llvm.org/settings/panel/emailpreferences/
> <D7100.18535.patch>





More information about the llvm-commits mailing list