diff options
author | Chris Lattner <sabre@nondot.org> | 2009-09-20 01:49:31 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-09-20 01:49:31 +0000 |
commit | 341620b2762e604fbf8c75913a1cc5b9c9297b7d (patch) | |
tree | 583e1e73e02402662721d1a9df02e09c5db5ee78 /lib/Support | |
parent | 33c06adcf10d3ef7bbfc70f09f4966eec2e6c85e (diff) | |
download | external_llvm-341620b2762e604fbf8c75913a1cc5b9c9297b7d.zip external_llvm-341620b2762e604fbf8c75913a1cc5b9c9297b7d.tar.gz external_llvm-341620b2762e604fbf8c75913a1cc5b9c9297b7d.tar.bz2 |
Change CommaSeparated processing to do it with StringRef instead of temporary std::strings.
This requires StringRef'izing ProvideOption which I also did.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82350 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r-- | lib/Support/CommandLine.cpp | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index 54b5631..eb49153 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -171,8 +171,11 @@ static Option *LookupOption(const char *&Arg, const char *&Value, return I != OptionsMap.end() ? I->second : 0; } +/// ProvideOption - For Value, this differentiates between an empty value ("") +/// and a null value (StringRef()). The later is accepted for arguments that +/// don't allow a value (-foo) the former is rejected (-foo=). static inline bool ProvideOption(Option *Handler, StringRef ArgName, - const char *Value, int argc, char **argv, + StringRef Value, int argc, char **argv, int &i) { // Is this a multi-argument option? unsigned NumAdditionalVals = Handler->getNumAdditionalVals(); @@ -180,7 +183,7 @@ static inline bool ProvideOption(Option *Handler, StringRef ArgName, // Enforce value requirements switch (Handler->getValueExpectedFlag()) { case ValueRequired: - if (Value == 0) { // No value specified? + if (Value.data() == 0) { // No value specified? if (i+1 >= argc) return Handler->error("requires a value!"); // Steal the next argument, like for '-o filename' @@ -192,7 +195,7 @@ static inline bool ProvideOption(Option *Handler, StringRef ArgName, return Handler->error("multi-valued option specified" " with ValueDisallowed modifier!"); - if (Value) + if (Value.data()) return Handler->error("does not allow a value! '" + Twine(Value) + "' specified."); break; @@ -208,12 +211,12 @@ static inline bool ProvideOption(Option *Handler, StringRef ArgName, // If this isn't a multi-arg option, just run the handler. if (NumAdditionalVals == 0) - return Handler->addOccurrence(i, ArgName, Value ? Value : ""); + return Handler->addOccurrence(i, ArgName, Value); // If it is, run the handle several times. bool MultiArg = false; - if (Value) { + if (Value.data()) { if (Handler->addOccurrence(i, ArgName, Value, MultiArg)) return true; --NumAdditionalVals; @@ -235,7 +238,7 @@ static inline bool ProvideOption(Option *Handler, StringRef ArgName, static bool ProvidePositionalOption(Option *Handler, StringRef Arg, int i) { int Dummy = i; - return ProvideOption(Handler, Handler->ArgStr, Arg.data(), 0, 0, Dummy); + return ProvideOption(Handler, Handler->ArgStr, Arg, 0, 0, Dummy); } @@ -576,7 +579,7 @@ void cl::ParseCommandLineOptions(int argc, char **argv, "Option can not be cl::Grouping AND cl::ValueRequired!"); int Dummy; ErrorParsing |= ProvideOption(PGOpt, RealArgName, - 0, 0, 0, Dummy); + StringRef(), 0, 0, Dummy); // Get the next grouping option. PGOpt = getOptionPred(RealName, Length, isGrouping, Opts); @@ -602,22 +605,20 @@ void cl::ParseCommandLineOptions(int argc, char **argv, } // Check to see if this option accepts a comma separated list of values. If - // it does, we have to split up the value into multiple values... + // it does, we have to split up the value into multiple values. if (Value && Handler->getMiscFlags() & CommaSeparated) { - std::string Val(Value); - std::string::size_type Pos = Val.find(','); - - while (Pos != std::string::npos) { - // Process the portion before the comma... - ErrorParsing |= ProvideOption(Handler, ArgName, - std::string(Val.begin(), - Val.begin()+Pos).c_str(), + StringRef Val(Value); + StringRef::size_type Pos = Val.find(','); + + while (Pos != StringRef::npos) { + // Process the portion before the comma. + ErrorParsing |= ProvideOption(Handler, ArgName, Val.substr(0, Pos), argc, argv, i); - // Erase the portion before the comma, AND the comma... - Val.erase(Val.begin(), Val.begin()+Pos+1); - Value += Pos+1; // Increment the original value pointer as well... + // Erase the portion before the comma, AND the comma. + Val = Val.substr(Pos+1); + Value += Pos+1; // Increment the original value pointer as well. - // Check for another comma... + // Check for another comma. Pos = Val.find(','); } } @@ -626,8 +627,12 @@ void cl::ParseCommandLineOptions(int argc, char **argv, // active one... if (Handler->getFormattingFlag() == cl::Positional) ActivePositionalArg = Handler; - else + else if (Value) ErrorParsing |= ProvideOption(Handler, ArgName, Value, argc, argv, i); + else + ErrorParsing |= ProvideOption(Handler, ArgName, StringRef(), + argc, argv, i); + } // Check and handle positional arguments now... |