[llvm] [CommandLine][NFCI] Do not add 'All' to 'RegisteredSubCommands' (PR #77041)
Igor Kudrin via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 4 20:01:19 PST 2024
https://github.com/igorkudrin updated https://github.com/llvm/llvm-project/pull/77041
>From 53fb135a597aac77f43306863db04a7f68baec94 Mon Sep 17 00:00:00 2001
From: Igor Kudrin <ikudrin at accesssoftek.com>
Date: Fri, 15 Dec 2023 10:55:49 -0800
Subject: [PATCH] [CommandLine][NFCI] Do not add 'All' to
'RegisteredSubCommands'
After #75679, it is no longer necessary to add the `All` pseudo
subcommand to the list of registered subcommands. The change causes the
list to contain only real subcommands, i.e. an unnamed top-level
subcommand and named ones. This simplifies the code a bit by removing
some checks for this special case.
---
llvm/lib/Support/CommandLine.cpp | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index 368dead4491492..d58db277f9ffda 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -166,7 +166,6 @@ class CommandLineParser {
CommandLineParser() {
registerSubCommand(&SubCommand::getTopLevel());
- registerSubCommand(&SubCommand::getAll());
}
void ResetAllOptionOccurrences();
@@ -348,15 +347,14 @@ class CommandLineParser {
// For all options that have been registered for all subcommands, add the
// option to this subcommand now.
- if (sub != &SubCommand::getAll()) {
- for (auto &E : SubCommand::getAll().OptionsMap) {
- Option *O = E.second;
- if ((O->isPositional() || O->isSink() || O->isConsumeAfter()) ||
- O->hasArgStr())
- addOption(O, sub);
- else
- addLiteralOption(*O, sub, E.first());
- }
+ assert(sub != &SubCommand::getAll());
+ for (auto &E : SubCommand::getAll().OptionsMap) {
+ Option *O = E.second;
+ if ((O->isPositional() || O->isSink() || O->isConsumeAfter()) ||
+ O->hasArgStr())
+ addOption(O, sub);
+ else
+ addLiteralOption(*O, sub, E.first());
}
}
@@ -384,7 +382,6 @@ class CommandLineParser {
SubCommand::getTopLevel().reset();
SubCommand::getAll().reset();
registerSubCommand(&SubCommand::getTopLevel());
- registerSubCommand(&SubCommand::getAll());
DefaultOptions.clear();
}
@@ -532,8 +529,7 @@ SubCommand *CommandLineParser::LookupSubCommand(StringRef Name,
// Find a subcommand with the edit distance == 1.
SubCommand *NearestMatch = nullptr;
for (auto *S : RegisteredSubCommands) {
- if (S == &SubCommand::getAll())
- continue;
+ assert(S != &SubCommand::getAll());
if (S->getName().empty())
continue;
More information about the llvm-commits
mailing list