diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Support/CommandLine.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Support/CommandLine.cpp | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/contrib/llvm-project/llvm/lib/Support/CommandLine.cpp b/contrib/llvm-project/llvm/lib/Support/CommandLine.cpp index 7360d733d96e..cb9eb9183f73 100644 --- a/contrib/llvm-project/llvm/lib/Support/CommandLine.cpp +++ b/contrib/llvm-project/llvm/lib/Support/CommandLine.cpp @@ -164,10 +164,7 @@ public: // 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(); @@ -183,6 +180,7 @@ public: if (Opt.Subs.size() == 1 && *Opt.Subs.begin() == &SubCommand::getAll()) { for (auto *SC : RegisteredSubCommands) Action(*SC); + Action(SubCommand::getAll()); return; } for (auto *SC : Opt.Subs) { @@ -348,15 +346,15 @@ public: // 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 +382,6 @@ public: SubCommand::getTopLevel().reset(); SubCommand::getAll().reset(); registerSubCommand(&SubCommand::getTopLevel()); - registerSubCommand(&SubCommand::getAll()); DefaultOptions.clear(); } @@ -532,8 +529,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; @@ -1633,10 +1630,8 @@ bool CommandLineParser::ParseCommandLineOptions(int argc, // otherwise feed it to the eating positional. ArgName = StringRef(argv[i] + 1); // Eat second dash. - if (!ArgName.empty() && ArgName[0] == '-') { + if (ArgName.consume_front("-")) HaveDoubleDash = true; - ArgName = ArgName.substr(1); - } Handler = LookupLongOption(*ChosenSubCommand, ArgName, Value, LongOptionsUseDoubleDash, HaveDoubleDash); @@ -1647,10 +1642,8 @@ bool CommandLineParser::ParseCommandLineOptions(int argc, } else { // We start with a '-', must be an argument. ArgName = StringRef(argv[i] + 1); // Eat second dash. - if (!ArgName.empty() && ArgName[0] == '-') { + if (ArgName.consume_front("-")) HaveDoubleDash = true; - ArgName = ArgName.substr(1); - } Handler = LookupLongOption(*ChosenSubCommand, ArgName, Value, LongOptionsUseDoubleDash, HaveDoubleDash); |