From 044eb2f6afba375a914ac9d8024f8f5142bb912e Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 18 Dec 2017 20:10:56 +0000 Subject: Vendor import of llvm trunk r321017: https://llvm.org/svn/llvm-project/llvm/trunk@321017 --- lib/Support/CommandLine.cpp | 54 +++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 36 deletions(-) (limited to 'lib/Support/CommandLine.cpp') diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index 8eeb685a18a9..b547a0932709 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -19,7 +19,6 @@ #include "llvm/Support/CommandLine.h" #include "llvm-c/Support.h" #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallPtrSet.h" @@ -46,17 +45,6 @@ using namespace cl; #define DEBUG_TYPE "commandline" -#if LLVM_ENABLE_ABI_BREAKING_CHECKS -namespace llvm { -// If LLVM_ENABLE_ABI_BREAKING_CHECKS is set the flag -mllvm -reverse-iterate -// can be used to toggle forward/reverse iteration of unordered containers. -// This will help uncover differences in codegen caused due to undefined -// iteration order. -static cl::opt ReverseIteration("reverse-iterate", - cl::location(ReverseIterate::value)); -} -#endif - //===----------------------------------------------------------------------===// // Template instantiations and anchors. // @@ -1769,7 +1757,13 @@ public: void operator=(bool Value) { if (!Value) return; + printHelp(); + + // Halt the program since help information was printed + exit(0); + } + void printHelp() { SubCommand *Sub = GlobalParser->getActiveSubCommand(); auto &OptionsMap = Sub->OptionsMap; auto &PositionalOpts = Sub->PositionalOpts; @@ -1837,9 +1831,6 @@ public: for (auto I : GlobalParser->MoreHelp) outs() << I; GlobalParser->MoreHelp.clear(); - - // Halt the program since help information was printed - exit(0); } }; @@ -2039,9 +2030,9 @@ void CommandLineParser::printOptionValues() { Opts[i].second->printOptionValue(MaxArgLen, PrintAllOptions); } -static void (*OverrideVersionPrinter)() = nullptr; +static VersionPrinterTy OverrideVersionPrinter = nullptr; -static std::vector *ExtraVersionPrinters = nullptr; +static std::vector *ExtraVersionPrinters = nullptr; namespace { class VersionPrinter { @@ -2081,7 +2072,7 @@ public: return; if (OverrideVersionPrinter != nullptr) { - (*OverrideVersionPrinter)(); + OverrideVersionPrinter(outs()); exit(0); } print(); @@ -2090,10 +2081,8 @@ public: // information. if (ExtraVersionPrinters != nullptr) { outs() << '\n'; - for (std::vector::iterator I = ExtraVersionPrinters->begin(), - E = ExtraVersionPrinters->end(); - I != E; ++I) - (*I)(); + for (auto I : *ExtraVersionPrinters) + I(outs()); } exit(0); @@ -2111,31 +2100,24 @@ static cl::opt> // Utility function for printing the help message. void cl::PrintHelpMessage(bool Hidden, bool Categorized) { - // This looks weird, but it actually prints the help message. The Printers are - // types of HelpPrinter and the help gets printed when its operator= is - // invoked. That's because the "normal" usages of the help printer is to be - // assigned true/false depending on whether -help or -help-hidden was given or - // not. Since we're circumventing that we have to make it look like -help or - // -help-hidden were given, so we assign true. - if (!Hidden && !Categorized) - UncategorizedNormalPrinter = true; + UncategorizedNormalPrinter.printHelp(); else if (!Hidden && Categorized) - CategorizedNormalPrinter = true; + CategorizedNormalPrinter.printHelp(); else if (Hidden && !Categorized) - UncategorizedHiddenPrinter = true; + UncategorizedHiddenPrinter.printHelp(); else - CategorizedHiddenPrinter = true; + CategorizedHiddenPrinter.printHelp(); } /// Utility function for printing version number. void cl::PrintVersionMessage() { VersionPrinterInstance.print(); } -void cl::SetVersionPrinter(void (*func)()) { OverrideVersionPrinter = func; } +void cl::SetVersionPrinter(VersionPrinterTy func) { OverrideVersionPrinter = func; } -void cl::AddExtraVersionPrinter(void (*func)()) { +void cl::AddExtraVersionPrinter(VersionPrinterTy func) { if (!ExtraVersionPrinters) - ExtraVersionPrinters = new std::vector; + ExtraVersionPrinters = new std::vector; ExtraVersionPrinters->push_back(func); } -- cgit v1.2.3