Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions llvm/lib/Support/CommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,7 @@ class CommandLineParser {
// This collects the different subcommands that have been registered.
SmallPtrSet<SubCommand *, 4> RegisteredSubCommands;

CommandLineParser() {
registerSubCommand(&SubCommand::getTopLevel());
registerSubCommand(&SubCommand::getAll());
}
CommandLineParser() { registerSubCommand(&SubCommand::getTopLevel()); }

void ResetAllOptionOccurrences();

Expand Down Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -384,7 +381,6 @@ class CommandLineParser {
SubCommand::getTopLevel().reset();
SubCommand::getAll().reset();
registerSubCommand(&SubCommand::getTopLevel());
registerSubCommand(&SubCommand::getAll());

DefaultOptions.clear();
}
Expand Down Expand Up @@ -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;

Expand Down