[llvm] fb7fe49 - [CommandLine][NFCI] Do not add 'All' to 'RegisteredSubCommands' (#77041)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 10 12:45:17 PST 2024
Author: Igor Kudrin
Date: 2024-01-11T03:45:13+07:00
New Revision: fb7fe49960ae053c92985f3376d85a15bbd10d1a
URL: https://github.com/llvm/llvm-project/commit/fb7fe49960ae053c92985f3376d85a15bbd10d1a
DIFF: https://github.com/llvm/llvm-project/commit/fb7fe49960ae053c92985f3376d85a15bbd10d1a.diff
LOG: [CommandLine][NFCI] Do not add 'All' to 'RegisteredSubCommands' (#77041)
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.
Added:
Modified:
llvm/lib/Support/CommandLine.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index 7360d733d96e7b..9a57936be2db70 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -164,10 +164,7 @@ class CommandLineParser {
// This collects the
diff erent subcommands that have been registered.
SmallPtrSet<SubCommand *, 4> RegisteredSubCommands;
- CommandLineParser() {
- registerSubCommand(&SubCommand::getTopLevel());
- registerSubCommand(&SubCommand::getAll());
- }
+ CommandLineParser() { registerSubCommand(&SubCommand::getTopLevel()); }
void ResetAllOptionOccurrences();
@@ -348,15 +345,15 @@ 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() &&
+ "SubCommand::getAll() should not be registered");
+ 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 +381,6 @@ class CommandLineParser {
SubCommand::getTopLevel().reset();
SubCommand::getAll().reset();
registerSubCommand(&SubCommand::getTopLevel());
- registerSubCommand(&SubCommand::getAll());
DefaultOptions.clear();
}
@@ -532,8 +528,8 @@ 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() &&
+ "SubCommand::getAll() is not expected in RegisteredSubCommands");
if (S->getName().empty())
continue;
More information about the llvm-commits
mailing list