From 7006a12ba39cf2016850dd3e5b8543e5fc5f2f41 Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Mon, 26 Jan 2015 21:57:29 +0000 Subject: [PATCH] Add new HideUnrelatedOptions API that takes a SmallVectorImpl. Need a new API for clang-modernize that allows specifying a list of option categories to remain visible. This will allow clang-modernize to move off getRegisteredOptions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227140 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/CommandLine.h | 9 +++++++++ lib/Support/CommandLine.cpp | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/llvm/Support/CommandLine.h b/include/llvm/Support/CommandLine.h index 2d75c59cf20..e53ac06a3cd 100644 --- a/include/llvm/Support/CommandLine.h +++ b/include/llvm/Support/CommandLine.h @@ -1931,6 +1931,15 @@ bool ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer, /// option category to display in the -help output. void HideUnrelatedOptions(cl::OptionCategory &Category); +/// \brief Mark all options not part of the categories as cl::ReallyHidden. +/// +/// \param Categories the categories 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(SmallVectorImpl &Categories); + } // End namespace cl } // End namespace llvm diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index 87f2261def5..4cd6f0c5f0a 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -1861,6 +1861,20 @@ void cl::HideUnrelatedOptions(cl::OptionCategory &Category) { } } +void cl::HideUnrelatedOptions( + SmallVectorImpl &Categories) { + auto CategoriesBegin = Categories.begin(); + auto CategoriesEnd = Categories.end(); + StringMap Options; + cl::getRegisteredOptions(Options); + for (auto &I : Options) { + if (std::find(CategoriesBegin, CategoriesEnd, I.second->Category) == + CategoriesEnd && + I.second->Category != &GenericCategory) + I.second->setHiddenFlag(cl::ReallyHidden); + } +} + void LLVMParseCommandLineOptions(int argc, const char *const *argv, const char *Overview) { llvm::cl::ParseCommandLineOptions(argc, argv, Overview); -- 2.34.1