From af035f3460f7d758f73987c3f692faf8d6cae062 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 5 Apr 2007 21:58:17 +0000 Subject: [PATCH] remove the dead removeArgument method, rename Options to OptionsMap. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35690 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/CommandLine.h | 1 - lib/Support/CommandLine.cpp | 91 ++++++++++-------------------- 2 files changed, 30 insertions(+), 62 deletions(-) diff --git a/include/llvm/Support/CommandLine.h b/include/llvm/Support/CommandLine.h index f9cf3be9946..8440c97602d 100644 --- a/include/llvm/Support/CommandLine.h +++ b/include/llvm/Support/CommandLine.h @@ -219,7 +219,6 @@ public: // occurrences of -ArgStr on the command line. // void addArgument(const char *ArgStr); - void removeArgument(const char *ArgStr); // Return the width of the option tag for printing... virtual unsigned getOptionWidth() const = 0; diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index e556d76f965..5fa65d82ba5 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -75,12 +75,12 @@ extrahelp::extrahelp(const char *Help) // Basic, shared command line option processing machinery. // -static ManagedStatic > Options; +static ManagedStatic > OptionsMap; static ManagedStatic > PositionalOptions; static Option *getOption(const std::string &Str) { - std::map::iterator I = Options->find(Str); - return I != Options->end() ? I->second : 0; + std::map::iterator I = OptionsMap->find(Str); + return I != OptionsMap->end() ? I->second : 0; } static void AddArgument(const char *ArgName, Option *Opt) { @@ -89,23 +89,31 @@ static void AddArgument(const char *ArgName, Option *Opt) { << ArgName << "' defined more than once!\n"; } else { // Add argument to the argument map! - (*Options)[ArgName] = Opt; + (*OptionsMap)[ArgName] = Opt; } } -// RemoveArgument - It's possible that the argument is no longer in the map if -// options have already been processed and the map has been deleted! -// -static void RemoveArgument(const char *ArgName, Option *Opt) { - if (Options->empty()) return; - -#ifndef NDEBUG - // This disgusting HACK is brought to you courtesy of GCC 3.3.2, which ICE's - // If we pass ArgName directly into getOption here. - std::string Tmp = ArgName; - assert(getOption(Tmp) == Opt && "Arg not in map!"); -#endif - Options->erase(ArgName); +/// LookupOption - Lookup the option specified by the specified option on the +/// command line. If there is a value specified (after an equal sign) return +/// that as well. +static Option *LookupOption(const char *&Arg, const char *&Value) { + while (*Arg == '-') ++Arg; // Eat leading dashes + + const char *ArgEnd = Arg; + while (*ArgEnd && *ArgEnd != '=') + ++ArgEnd; // Scan till end of argument name. + + if (*ArgEnd == '=') // If we have an equals sign... + Value = ArgEnd+1; // Get the value, not the equals + + + if (*Arg == 0) return 0; + + // Look up the option. + std::map &Opts = *OptionsMap; + std::map::iterator I = + Opts.find(std::string(Arg, ArgEnd)); + return (I != Opts.end()) ? I->second : 0; } static inline bool ProvideOption(Option *Handler, const char *ArgName, @@ -276,32 +284,9 @@ void cl::ParseEnvironmentOptions(const char *progName, const char *envVar, free (*i); } -/// LookupOption - Lookup the option specified by the specified option on the -/// command line. If there is a value specified (after an equal sign) return -/// that as well. -static Option *LookupOption(const char *&Arg, const char *&Value) { - while (*Arg == '-') ++Arg; // Eat leading dashes - - const char *ArgEnd = Arg; - while (*ArgEnd && *ArgEnd != '=') - ++ArgEnd; // Scan till end of argument name. - - if (*ArgEnd == '=') // If we have an equals sign... - Value = ArgEnd+1; // Get the value, not the equals - - - if (*Arg == 0) return 0; - - // Look up the option. - std::map &Opts = *Options; - std::map::iterator I = - Opts.find(std::string(Arg, ArgEnd)); - return (I != Opts.end()) ? I->second : 0; -} - void cl::ParseCommandLineOptions(int &argc, char **argv, const char *Overview) { - assert((!Options->empty() || !PositionalOptions->empty()) && + assert((!OptionsMap->empty() || !PositionalOptions->empty()) && "No options specified, or ParseCommandLineOptions called more" " than once!"); sys::Path progname(argv[0]); @@ -314,7 +299,7 @@ void cl::ParseCommandLineOptions(int &argc, char **argv, ProgramOverview = Overview; bool ErrorParsing = false; - std::map &Opts = *Options; + std::map &Opts = *OptionsMap; std::vector &PositionalOpts = *PositionalOptions; // Check out the positional arguments to collect information about them. @@ -665,22 +650,6 @@ void Option::addArgument(const char *ArgStr) { } } -void Option::removeArgument(const char *ArgStr) { - if (ArgStr[0]) - RemoveArgument(ArgStr, this); - - if (getFormattingFlag() == Positional) { - std::vector::iterator I = - std::find(PositionalOptions->begin(), PositionalOptions->end(), this); - assert(I != PositionalOptions->end() && "Arg not registered!"); - PositionalOptions->erase(I); - } else if (getNumOccurrencesFlag() == ConsumeAfter) { - assert(!PositionalOptions->empty() && (*PositionalOptions)[0] == this && - "Arg not registered correctly!"); - PositionalOptions->erase(PositionalOptions->begin()); - } -} - // getValueStr - Get the value description string, using "DefaultMsg" if nothing // has been specified yet. @@ -900,7 +869,7 @@ public: // Copy Options into a vector so we can sort them as we like... std::vector > Opts; - copy(Options->begin(), Options->end(), std::back_inserter(Opts)); + copy(OptionsMap->begin(), OptionsMap->end(), std::back_inserter(Opts)); // Eliminate Hidden or ReallyHidden arguments, depending on ShowHidden Opts.erase(std::remove_if(Opts.begin(), Opts.end(), @@ -955,7 +924,7 @@ public: MoreHelp->clear(); // Halt the program since help information was printed - Options->clear(); // Don't bother making option dtors remove from map. + OptionsMap->clear(); // Don't bother making option dtors remove from map. exit(1); } }; @@ -1001,7 +970,7 @@ public: if (OptionWasSpecified) { if (OverrideVersionPrinter == 0) { print(); - Options->clear(); // Don't bother making option dtors remove from map. + OptionsMap->clear();// Don't bother making option dtors remove from map. exit(1); } else { (*OverrideVersionPrinter)();