[llvm] r227140 - Add new HideUnrelatedOptions API that takes a SmallVectorImpl.

Chris Bieneman beanz at apple.com
Mon Jan 26 13:57:30 PST 2015


Author: cbieneman
Date: Mon Jan 26 15:57:29 2015
New Revision: 227140

URL: http://llvm.org/viewvc/llvm-project?rev=227140&view=rev
Log:
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.

Modified:
    llvm/trunk/include/llvm/Support/CommandLine.h
    llvm/trunk/lib/Support/CommandLine.cpp

Modified: llvm/trunk/include/llvm/Support/CommandLine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/CommandLine.h?rev=227140&r1=227139&r2=227140&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/CommandLine.h (original)
+++ llvm/trunk/include/llvm/Support/CommandLine.h Mon Jan 26 15:57:29 2015
@@ -1931,6 +1931,15 @@ bool ExpandResponseFiles(StringSaver &Sa
 /// 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<cl::OptionCategory *> &Categories);
+
 } // End namespace cl
 
 } // End namespace llvm

Modified: llvm/trunk/lib/Support/CommandLine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/CommandLine.cpp?rev=227140&r1=227139&r2=227140&view=diff
==============================================================================
--- llvm/trunk/lib/Support/CommandLine.cpp (original)
+++ llvm/trunk/lib/Support/CommandLine.cpp Mon Jan 26 15:57:29 2015
@@ -1861,6 +1861,20 @@ void cl::HideUnrelatedOptions(cl::Option
   }
 }
 
+void cl::HideUnrelatedOptions(
+    SmallVectorImpl<cl::OptionCategory *> &Categories) {
+  auto CategoriesBegin = Categories.begin();
+  auto CategoriesEnd = Categories.end();
+  StringMap<cl::Option *> 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);





More information about the llvm-commits mailing list