diff options
author | Chris Lattner <sabre@nondot.org> | 2001-07-23 23:02:45 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2001-07-23 23:02:45 +0000 |
commit | dc4693dbcf164ec404a3a91c67cf1dbe5f45a8e5 (patch) | |
tree | 64dd9959f8e46a55d2702c898bb21bac750099a7 /lib | |
parent | 7ae36bbe06a86ac07aff9dc247359e51c653e1a3 (diff) | |
download | external_llvm-dc4693dbcf164ec404a3a91c67cf1dbe5f45a8e5.zip external_llvm-dc4693dbcf164ec404a3a91c67cf1dbe5f45a8e5.tar.gz external_llvm-dc4693dbcf164ec404a3a91c67cf1dbe5f45a8e5.tar.bz2 |
Minor changes to implementation of CommandLine library to let users override
options forced by different subclasses of Option
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Support/CommandLine.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index c7590ab..c3de975 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -73,7 +73,7 @@ void cl::ParseCommandLineOptions(int &argc, char **argv, } // Enforce value requirements - switch (Handler->Flags & ValueMask) { + switch (Handler->getValueExpectedFlag()) { case ValueRequired: if (Value == 0 || *Value == 0) { // No value specified? if (i+1 < argc) { // Steal the next argument, like for '-o filename' @@ -99,7 +99,19 @@ void cl::ParseCommandLineOptions(int &argc, char **argv, ErrorParsing |= Handler->addOccurance(ArgName, Value); } - // TODO: loop over args and make sure all required args are specified! + // Loop over args and make sure all required args are specified! + for (map<string, Option*>::iterator I = getOpts().begin(), + E = getOpts().end(); I != E; ++I) { + switch (I->second->getNumOccurancesFlag()) { + case Required: + case OneOrMore: + if (I->second->getNumOccurances() == 0) + I->second->error(" must be specified at least once!"); + // Fall through + default: + break; + } + } // Free all of the memory allocated to the vector. Command line options may // only be processed once! @@ -113,7 +125,7 @@ void cl::ParseCommandLineOptions(int &argc, char **argv, // Option Base class implementation // Option::Option(const char *argStr, const char *helpStr, int flags) - : NumOccurances(0), ArgStr(argStr), HelpStr(helpStr), Flags(flags) { + : NumOccurances(0), Flags(flags), ArgStr(argStr), HelpStr(helpStr) { AddArgument(ArgStr, this); } @@ -126,7 +138,7 @@ bool Option::error(string Message, const char *ArgName = 0) { bool Option::addOccurance(const char *ArgName, const string &Value) { NumOccurances++; // Increment the number of times we have been seen - switch (Flags & OccurancesMask) { + switch (getNumOccurancesFlag()) { case Optional: if (NumOccurances > 1) return error(": may only occur zero or one times!", ArgName); @@ -325,10 +337,10 @@ namespace { // isHidden/isReallyHidden - Predicates to be used to filter down arg lists. inline bool isHidden(pair<string, Option *> &OptPair) { - return (OptPair.second->Flags & HiddenMask) == Hidden; + return OptPair.second->getOptionHiddenFlag() >= Hidden; } inline bool isReallyHidden(pair<string, Option *> &OptPair) { - return (OptPair.second->Flags & HiddenMask) == ReallyHidden; + return OptPair.second->getOptionHiddenFlag() == ReallyHidden; } class Help : public Option { @@ -393,7 +405,7 @@ public: }; Help HelpOp("help", "display available options" - " (-help-hidden for more)", false); + " (--help-hidden for more)", false); Help HelpHiddenOpt("help-hidden", "display all available options", true); } // End anonymous namespace |