[PATCH] D61574: [CommandLine] Allow Options to specify multiple OptionCategory's.

Don Hinton via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 5 21:17:52 PDT 2019


hintonda marked 2 inline comments as done.
hintonda added a comment.

In D61574#1491471 <https://reviews.llvm.org/D61574#1491471>, @MaskRay wrote:

> May I ask you to share some dumps of `some-command -help` (a demo how you'll make use of the multiple categories)😁


Sure, I work up an example.  Btw, my ultimate plan is to add categories to the passes so that bugpoint help isn't just a huge mess.  That's the motivation for this change.  When I started adding them, I found it wasn't really doable without this change since so many passes shared options.



================
Comment at: llvm/lib/Support/CommandLine.cpp:429
+void Option::addCategory(OptionCategory &C) {
+  assert(!Categories.empty() && "Categories cannot be empty.");
+  // Maintain backward compatibility by replacing the default GeneralCategory
----------------
MaskRay wrote:
> Can you explain why Categories cannot be empty? Is it because an option has one category when it is registered? (Sorry as I'm not very familiar with the code)
The ctor for Option adds GeneralCategory.  The old way just replaced it if the user provided their own.  With this change, it's the first one on the vector.  That's why I check index 0. 


================
Comment at: llvm/unittests/Support/CommandLineTest.cpp:99
+  ASSERT_NE(Retrieved->Categories.end(),
+            std::find_if(Retrieved->Categories.begin(),
+                         Retrieved->Categories.end(),
----------------
MaskRay wrote:
> Since the file includes `STLExtras.h` you may use the range-style `llvm::find_if` to simplify begin/end.
Ah, okay.  Will do, thanks...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61574/new/

https://reviews.llvm.org/D61574





More information about the llvm-commits mailing list