diff options
Diffstat (limited to 'llvm/lib/Support/CommandLine.cpp')
-rw-r--r-- | llvm/lib/Support/CommandLine.cpp | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index 5e7d631..b86be5e 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -167,8 +167,8 @@ public: SmallPtrSet<SubCommand *, 4> RegisteredSubCommands; CommandLineParser() { - registerSubCommand(&*TopLevelSubCommand); - registerSubCommand(&*AllSubCommands); + registerSubCommand(&SubCommand::getTopLevel()); + registerSubCommand(&SubCommand::getAll()); } void ResetAllOptionOccurrences(); @@ -188,7 +188,7 @@ public: // If we're adding this to all sub-commands, add it to the ones that have // already been registered. - if (SC == &*AllSubCommands) { + if (SC == &SubCommand::getAll()) { for (auto *Sub : RegisteredSubCommands) { if (SC == Sub) continue; @@ -199,7 +199,7 @@ public: void addLiteralOption(Option &Opt, StringRef Name) { if (Opt.Subs.empty()) - addLiteralOption(Opt, &*TopLevelSubCommand, Name); + addLiteralOption(Opt, &SubCommand::getTopLevel(), Name); else { for (auto *SC : Opt.Subs) addLiteralOption(Opt, SC, Name); @@ -244,7 +244,7 @@ public: // If we're adding this to all sub-commands, add it to the ones that have // already been registered. - if (SC == &*AllSubCommands) { + if (SC == &SubCommand::getAll()) { for (auto *Sub : RegisteredSubCommands) { if (SC == Sub) continue; @@ -260,7 +260,7 @@ public: } if (O->Subs.empty()) { - addOption(O, &*TopLevelSubCommand); + addOption(O, &SubCommand::getTopLevel()); } else { for (auto *SC : O->Subs) addOption(O, SC); @@ -302,7 +302,7 @@ public: void removeOption(Option *O) { if (O->Subs.empty()) - removeOption(O, &*TopLevelSubCommand); + removeOption(O, &SubCommand::getTopLevel()); else { if (O->isInAllSubCommands()) { for (auto *SC : RegisteredSubCommands) @@ -341,7 +341,7 @@ public: void updateArgStr(Option *O, StringRef NewName) { if (O->Subs.empty()) - updateArgStr(O, NewName, &*TopLevelSubCommand); + updateArgStr(O, NewName, &SubCommand::getTopLevel()); else { if (O->isInAllSubCommands()) { for (auto *SC : RegisteredSubCommands) @@ -376,8 +376,8 @@ public: // For all options that have been registered for all subcommands, add the // option to this subcommand now. - if (sub != &*AllSubCommands) { - for (auto &E : AllSubCommands->OptionsMap) { + if (sub != &SubCommand::getAll()) { + for (auto &E : SubCommand::getAll().OptionsMap) { Option *O = E.second; if ((O->isPositional() || O->isSink() || O->isConsumeAfter()) || O->hasArgStr()) @@ -409,10 +409,10 @@ public: ResetAllOptionOccurrences(); RegisteredSubCommands.clear(); - TopLevelSubCommand->reset(); - AllSubCommands->reset(); - registerSubCommand(&*TopLevelSubCommand); - registerSubCommand(&*AllSubCommands); + SubCommand::getTopLevel().reset(); + SubCommand::getAll().reset(); + registerSubCommand(&SubCommand::getTopLevel()); + registerSubCommand(&SubCommand::getAll()); DefaultOptions.clear(); } @@ -491,6 +491,10 @@ ManagedStatic<SubCommand> llvm::cl::TopLevelSubCommand; // A special subcommand that can be used to put an option into all subcommands. ManagedStatic<SubCommand> llvm::cl::AllSubCommands; +SubCommand &SubCommand::getTopLevel() { return *TopLevelSubCommand; } + +SubCommand &SubCommand::getAll() { return *AllSubCommands; } + void SubCommand::registerSubCommand() { GlobalParser->registerSubCommand(this); } @@ -523,7 +527,7 @@ Option *CommandLineParser::LookupOption(SubCommand &Sub, StringRef &Arg, // Reject all dashes. if (Arg.empty()) return nullptr; - assert(&Sub != &*AllSubCommands); + assert(&Sub != &SubCommand::getAll()); size_t EqualPos = Arg.find('='); @@ -551,9 +555,9 @@ Option *CommandLineParser::LookupOption(SubCommand &Sub, StringRef &Arg, SubCommand *CommandLineParser::LookupSubCommand(StringRef Name) { if (Name.empty()) - return &*TopLevelSubCommand; + return &SubCommand::getTopLevel(); for (auto *S : RegisteredSubCommands) { - if (S == &*AllSubCommands) + if (S == &SubCommand::getAll()) continue; if (S->getName().empty()) continue; @@ -561,7 +565,7 @@ SubCommand *CommandLineParser::LookupSubCommand(StringRef Name) { if (StringRef(S->getName()) == StringRef(Name)) return S; } - return &*TopLevelSubCommand; + return &SubCommand::getTopLevel(); } /// LookupNearestOption - Lookup the closest match to the option specified by @@ -1452,12 +1456,12 @@ bool CommandLineParser::ParseCommandLineOptions(int argc, bool HasUnlimitedPositionals = false; int FirstArg = 1; - SubCommand *ChosenSubCommand = &*TopLevelSubCommand; + SubCommand *ChosenSubCommand = &SubCommand::getTopLevel(); if (argc >= 2 && argv[FirstArg][0] != '-') { // If the first argument specifies a valid subcommand, start processing // options from the second argument. ChosenSubCommand = LookupSubCommand(StringRef(argv[FirstArg])); - if (ChosenSubCommand != &*TopLevelSubCommand) + if (ChosenSubCommand != &SubCommand::getTopLevel()) FirstArg = 2; } GlobalParser->ActiveSubCommand = ChosenSubCommand; @@ -2289,7 +2293,7 @@ public: if (!GlobalParser->ProgramOverview.empty()) outs() << "OVERVIEW: " << GlobalParser->ProgramOverview << "\n"; - if (Sub == &*TopLevelSubCommand) { + if (Sub == &SubCommand::getTopLevel()) { outs() << "USAGE: " << GlobalParser->ProgramName; if (Subs.size() > 2) outs() << " [subcommand]"; @@ -2313,7 +2317,7 @@ public: if (ConsumeAfterOpt) outs() << " " << ConsumeAfterOpt->HelpStr; - if (Sub == &*TopLevelSubCommand && !Subs.empty()) { + if (Sub == &SubCommand::getTopLevel() && !Subs.empty()) { // Compute the maximum subcommand length... size_t MaxSubLen = 0; for (size_t i = 0, e = Subs.size(); i != e; ++i) @@ -2519,7 +2523,7 @@ struct CommandLineCommonOptions { cl::Hidden, cl::ValueDisallowed, cl::cat(GenericCategory), - cl::sub(*AllSubCommands)}; + cl::sub(SubCommand::getAll())}; cl::opt<HelpPrinter, true, parser<bool>> HLHOp{ "help-list-hidden", @@ -2528,7 +2532,7 @@ struct CommandLineCommonOptions { cl::Hidden, cl::ValueDisallowed, cl::cat(GenericCategory), - cl::sub(*AllSubCommands)}; + cl::sub(SubCommand::getAll())}; // Define uncategorized/categorized help printers. These printers change their // behaviour at runtime depending on whether one or more Option categories @@ -2539,7 +2543,7 @@ struct CommandLineCommonOptions { cl::location(WrappedNormalPrinter), cl::ValueDisallowed, cl::cat(GenericCategory), - cl::sub(*AllSubCommands)}; + cl::sub(SubCommand::getAll())}; cl::alias HOpA{"h", cl::desc("Alias for --help"), cl::aliasopt(HOp), cl::DefaultOption}; @@ -2551,7 +2555,7 @@ struct CommandLineCommonOptions { cl::Hidden, cl::ValueDisallowed, cl::cat(GenericCategory), - cl::sub(*AllSubCommands)}; + cl::sub(SubCommand::getAll())}; cl::opt<bool> PrintOptions{ "print-options", @@ -2559,7 +2563,7 @@ struct CommandLineCommonOptions { cl::Hidden, cl::init(false), cl::cat(GenericCategory), - cl::sub(*AllSubCommands)}; + cl::sub(SubCommand::getAll())}; cl::opt<bool> PrintAllOptions{ "print-all-options", @@ -2567,7 +2571,7 @@ struct CommandLineCommonOptions { cl::Hidden, cl::init(false), cl::cat(GenericCategory), - cl::sub(*AllSubCommands)}; + cl::sub(SubCommand::getAll())}; VersionPrinterTy OverrideVersionPrinter = nullptr; |