summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorDean Michael Berris <dberris@google.com>2016-10-05 05:20:08 +0000
committerDean Michael Berris <dberris@google.com>2016-10-05 05:20:08 +0000
commit27358cff88f929cee961d96e03706083d12ae7c7 (patch)
tree0374253222ebe9e0f0a493f25477d75451459b1c /llvm/lib
parent3fce2fdf4c660df108cf506ca7d308c795842243 (diff)
downloadbcm5719-llvm-27358cff88f929cee961d96e03706083d12ae7c7.tar.gz
bcm5719-llvm-27358cff88f929cee961d96e03706083d12ae7c7.zip
[Support][CommandLine] Add cl::getRegisteredSubcommands()
This should allow users of the library to get a range to iterate through all the subcommands that are registered to the global parser. This allows users to define subcommands in libraries that self-register to have dispatch done at a different stage (like main). It allows for writing code like the following: for (auto *S : cl::getRegisteredSubcommands()) { if (*S) { // Dispatch on S->getName(). } } This change also contains tests that show this usage pattern. Reviewers: zturner, dblaikie, echristo Subscribers: llvm-commits, mehdi_amini Differential Revision: https://reviews.llvm.org/D24489 llvm-svn: 283296
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Support/CommandLine.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index c5ca2149de3..76bf45e8f51 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -309,6 +309,12 @@ public:
RegisteredSubCommands.erase(sub);
}
+ iterator_range<typename SmallPtrSet<SubCommand *, 4>::iterator>
+ getRegisteredSubcommands() {
+ return make_range(RegisteredSubCommands.begin(),
+ RegisteredSubCommands.end());
+ }
+
void reset() {
ActiveSubCommand = nullptr;
ProgramName.clear();
@@ -2107,6 +2113,11 @@ StringMap<Option *> &cl::getRegisteredOptions(SubCommand &Sub) {
return Sub.OptionsMap;
}
+iterator_range<typename SmallPtrSet<SubCommand *, 4>::iterator>
+cl::getRegisteredSubcommands() {
+ return GlobalParser->getRegisteredSubcommands();
+}
+
void cl::HideUnrelatedOptions(cl::OptionCategory &Category, SubCommand &Sub) {
for (auto &I : Sub.OptionsMap) {
if (I.second->Category != &Category &&
OpenPOWER on IntegriCloud