mirror of
https://github.com/RPCS3/llvm.git
synced 2025-01-29 14:42:01 +00:00
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
This commit is contained in:
parent
33c06adcf1
commit
341620b276
@ -171,8 +171,11 @@ static Option *LookupOption(const char *&Arg, const char *&Value,
|
|||||||
return I != OptionsMap.end() ? I->second : 0;
|
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,
|
static inline bool ProvideOption(Option *Handler, StringRef ArgName,
|
||||||
const char *Value, int argc, char **argv,
|
StringRef Value, int argc, char **argv,
|
||||||
int &i) {
|
int &i) {
|
||||||
// Is this a multi-argument option?
|
// Is this a multi-argument option?
|
||||||
unsigned NumAdditionalVals = Handler->getNumAdditionalVals();
|
unsigned NumAdditionalVals = Handler->getNumAdditionalVals();
|
||||||
@ -180,7 +183,7 @@ static inline bool ProvideOption(Option *Handler, StringRef ArgName,
|
|||||||
// Enforce value requirements
|
// Enforce value requirements
|
||||||
switch (Handler->getValueExpectedFlag()) {
|
switch (Handler->getValueExpectedFlag()) {
|
||||||
case ValueRequired:
|
case ValueRequired:
|
||||||
if (Value == 0) { // No value specified?
|
if (Value.data() == 0) { // No value specified?
|
||||||
if (i+1 >= argc)
|
if (i+1 >= argc)
|
||||||
return Handler->error("requires a value!");
|
return Handler->error("requires a value!");
|
||||||
// Steal the next argument, like for '-o filename'
|
// 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"
|
return Handler->error("multi-valued option specified"
|
||||||
" with ValueDisallowed modifier!");
|
" with ValueDisallowed modifier!");
|
||||||
|
|
||||||
if (Value)
|
if (Value.data())
|
||||||
return Handler->error("does not allow a value! '" +
|
return Handler->error("does not allow a value! '" +
|
||||||
Twine(Value) + "' specified.");
|
Twine(Value) + "' specified.");
|
||||||
break;
|
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 this isn't a multi-arg option, just run the handler.
|
||||||
if (NumAdditionalVals == 0)
|
if (NumAdditionalVals == 0)
|
||||||
return Handler->addOccurrence(i, ArgName, Value ? Value : "");
|
return Handler->addOccurrence(i, ArgName, Value);
|
||||||
|
|
||||||
// If it is, run the handle several times.
|
// If it is, run the handle several times.
|
||||||
bool MultiArg = false;
|
bool MultiArg = false;
|
||||||
|
|
||||||
if (Value) {
|
if (Value.data()) {
|
||||||
if (Handler->addOccurrence(i, ArgName, Value, MultiArg))
|
if (Handler->addOccurrence(i, ArgName, Value, MultiArg))
|
||||||
return true;
|
return true;
|
||||||
--NumAdditionalVals;
|
--NumAdditionalVals;
|
||||||
@ -235,7 +238,7 @@ static inline bool ProvideOption(Option *Handler, StringRef ArgName,
|
|||||||
|
|
||||||
static bool ProvidePositionalOption(Option *Handler, StringRef Arg, int i) {
|
static bool ProvidePositionalOption(Option *Handler, StringRef Arg, int i) {
|
||||||
int Dummy = 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!");
|
"Option can not be cl::Grouping AND cl::ValueRequired!");
|
||||||
int Dummy;
|
int Dummy;
|
||||||
ErrorParsing |= ProvideOption(PGOpt, RealArgName,
|
ErrorParsing |= ProvideOption(PGOpt, RealArgName,
|
||||||
0, 0, 0, Dummy);
|
StringRef(), 0, 0, Dummy);
|
||||||
|
|
||||||
// Get the next grouping option.
|
// Get the next grouping option.
|
||||||
PGOpt = getOptionPred(RealName, Length, isGrouping, Opts);
|
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
|
// 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) {
|
if (Value && Handler->getMiscFlags() & CommaSeparated) {
|
||||||
std::string Val(Value);
|
StringRef Val(Value);
|
||||||
std::string::size_type Pos = Val.find(',');
|
StringRef::size_type Pos = Val.find(',');
|
||||||
|
|
||||||
while (Pos != std::string::npos) {
|
while (Pos != StringRef::npos) {
|
||||||
// Process the portion before the comma...
|
// Process the portion before the comma.
|
||||||
ErrorParsing |= ProvideOption(Handler, ArgName,
|
ErrorParsing |= ProvideOption(Handler, ArgName, Val.substr(0, Pos),
|
||||||
std::string(Val.begin(),
|
|
||||||
Val.begin()+Pos).c_str(),
|
|
||||||
argc, argv, i);
|
argc, argv, i);
|
||||||
// Erase the portion before the comma, AND the comma...
|
// Erase the portion before the comma, AND the comma.
|
||||||
Val.erase(Val.begin(), Val.begin()+Pos+1);
|
Val = Val.substr(Pos+1);
|
||||||
Value += Pos+1; // Increment the original value pointer as well...
|
Value += Pos+1; // Increment the original value pointer as well.
|
||||||
|
|
||||||
// Check for another comma...
|
// Check for another comma.
|
||||||
Pos = Val.find(',');
|
Pos = Val.find(',');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -626,8 +627,12 @@ void cl::ParseCommandLineOptions(int argc, char **argv,
|
|||||||
// active one...
|
// active one...
|
||||||
if (Handler->getFormattingFlag() == cl::Positional)
|
if (Handler->getFormattingFlag() == cl::Positional)
|
||||||
ActivePositionalArg = Handler;
|
ActivePositionalArg = Handler;
|
||||||
else
|
else if (Value)
|
||||||
ErrorParsing |= ProvideOption(Handler, ArgName, Value, argc, argv, i);
|
ErrorParsing |= ProvideOption(Handler, ArgName, Value, argc, argv, i);
|
||||||
|
else
|
||||||
|
ErrorParsing |= ProvideOption(Handler, ArgName, StringRef(),
|
||||||
|
argc, argv, i);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check and handle positional arguments now...
|
// Check and handle positional arguments now...
|
||||||
|
Loading…
x
Reference in New Issue
Block a user