From 845c00e2e6261b17ff47af2774492b21b7a8a96c Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Fri, 13 Feb 2015 22:54:32 +0000 Subject: [PATCH] NFC. Moving the RegisteredOptionCategories global into the CommandLineParser class. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229172 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/CommandLine.cpp | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index 3fd08b25ea0..ba2cd02622a 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -101,6 +101,9 @@ public: Option *ConsumeAfterOpt; // The ConsumeAfter option if it exists. + // This collects the different option categories that have been registered. + SmallPtrSet RegisteredOptionCategories; + CommandLineParser() : ProgramOverview(nullptr), ConsumeAfterOpt(nullptr) {} void ParseCommandLineOptions(int argc, const char *const *argv, @@ -191,6 +194,17 @@ public: void printOptionValues(); + void registerCategory(OptionCategory *cat) { + assert(std::count_if(RegisteredOptionCategories.begin(), + RegisteredOptionCategories.end(), + [cat](const OptionCategory *Category) { + return getName() == Category->getName(); + }) == 0 && + "Duplicate option categories"); + + RegisteredOptionCategories.insert(cat); + } + private: Option *LookupOption(StringRef &Arg, StringRef &Value); }; @@ -220,22 +234,11 @@ void Option::setArgStr(const char *S) { ArgStr = S; } -// This collects the different option categories that have been registered. -typedef SmallPtrSet OptionCatSet; -static ManagedStatic RegisteredOptionCategories; - // Initialise the general option category. OptionCategory llvm::cl::GeneralCategory("General options"); void OptionCategory::registerCategory() { - assert(std::count_if(RegisteredOptionCategories->begin(), - RegisteredOptionCategories->end(), - [this](const OptionCategory *Category) { - return getName() == Category->getName(); - }) == 0 && - "Duplicate option categories"); - - RegisteredOptionCategories->insert(this); + GlobalParser->registerCategory(this); } //===----------------------------------------------------------------------===// @@ -1577,8 +1580,8 @@ protected: // Collect registered option categories into vector in preparation for // sorting. - for (OptionCatSet::const_iterator I = RegisteredOptionCategories->begin(), - E = RegisteredOptionCategories->end(); + for (auto I = GlobalParser->RegisteredOptionCategories.begin(), + E = GlobalParser->RegisteredOptionCategories.end(); I != E; ++I) { SortedCategories.push_back(*I); } @@ -1721,7 +1724,7 @@ void HelpPrinterWrapper::operator=(bool Value) { // Decide which printer to invoke. If more than one option category is // registered then it is useful to show the categorized help instead of // uncategorized help. - if (RegisteredOptionCategories->size() > 1) { + if (GlobalParser->RegisteredOptionCategories.size() > 1) { // unhide -help-list option so user can have uncategorized output if they // want it. HLOp.setHiddenFlag(NotHidden); -- 2.34.1