Skip to content

Commit 58114f6

Browse files
committed
[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.
1 parent 7c963fd commit 58114f6

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

llvm/lib/Support/CommandLine.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,7 @@ class CommandLineParser {
164164
// This collects the different subcommands that have been registered.
165165
SmallPtrSet<SubCommand *, 4> RegisteredSubCommands;
166166

167-
CommandLineParser() {
168-
registerSubCommand(&SubCommand::getTopLevel());
169-
registerSubCommand(&SubCommand::getAll());
170-
}
167+
CommandLineParser() { registerSubCommand(&SubCommand::getTopLevel()); }
171168

172169
void ResetAllOptionOccurrences();
173170

@@ -348,15 +345,14 @@ class CommandLineParser {
348345

349346
// For all options that have been registered for all subcommands, add the
350347
// option to this subcommand now.
351-
if (sub != &SubCommand::getAll()) {
352-
for (auto &E : SubCommand::getAll().OptionsMap) {
353-
Option *O = E.second;
354-
if ((O->isPositional() || O->isSink() || O->isConsumeAfter()) ||
355-
O->hasArgStr())
356-
addOption(O, sub);
357-
else
358-
addLiteralOption(*O, sub, E.first());
359-
}
348+
assert(sub != &SubCommand::getAll());
349+
for (auto &E : SubCommand::getAll().OptionsMap) {
350+
Option *O = E.second;
351+
if ((O->isPositional() || O->isSink() || O->isConsumeAfter()) ||
352+
O->hasArgStr())
353+
addOption(O, sub);
354+
else
355+
addLiteralOption(*O, sub, E.first());
360356
}
361357
}
362358

@@ -384,7 +380,6 @@ class CommandLineParser {
384380
SubCommand::getTopLevel().reset();
385381
SubCommand::getAll().reset();
386382
registerSubCommand(&SubCommand::getTopLevel());
387-
registerSubCommand(&SubCommand::getAll());
388383

389384
DefaultOptions.clear();
390385
}
@@ -532,8 +527,7 @@ SubCommand *CommandLineParser::LookupSubCommand(StringRef Name,
532527
// Find a subcommand with the edit distance == 1.
533528
SubCommand *NearestMatch = nullptr;
534529
for (auto *S : RegisteredSubCommands) {
535-
if (S == &SubCommand::getAll())
536-
continue;
530+
assert(S != &SubCommand::getAll());
537531
if (S->getName().empty())
538532
continue;
539533

0 commit comments

Comments
 (0)