mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-28 22:24:28 +00:00
Implement the new cl::PositionalEatsArgs flag, refactor code a bit
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13388 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -242,6 +242,29 @@ void cl::ParseEnvironmentOptions (const char *progName, const char *envVar,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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...
|
||||||
|
|
||||||
|
Value = ArgEnd;
|
||||||
|
if (*Value) // If we have an equals sign...
|
||||||
|
++Value; // Advance to value...
|
||||||
|
|
||||||
|
if (*Arg == 0) return 0;
|
||||||
|
|
||||||
|
// Look up the option.
|
||||||
|
std::map<std::string, Option*> &Opts = getOpts();
|
||||||
|
std::map<std::string, Option*>::iterator I =
|
||||||
|
Opts.find(std::string(Arg, ArgEnd));
|
||||||
|
return (I != Opts.end()) ? I->second : 0;
|
||||||
|
}
|
||||||
|
|
||||||
void cl::ParseCommandLineOptions(int &argc, char **argv,
|
void cl::ParseCommandLineOptions(int &argc, char **argv,
|
||||||
const char *Overview) {
|
const char *Overview) {
|
||||||
assert((!getOpts().empty() || !getPositionalOpts().empty()) &&
|
assert((!getOpts().empty() || !getPositionalOpts().empty()) &&
|
||||||
@ -335,32 +358,30 @@ void cl::ParseCommandLineOptions(int &argc, char **argv,
|
|||||||
// Delay processing positional arguments until the end...
|
// Delay processing positional arguments until the end...
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else { // We start with a '-', must be an argument...
|
} else if (argv[i][0] == '-' && argv[i][1] == '-' && argv[i][2] == 0 &&
|
||||||
ArgName = argv[i]+1;
|
!DashDashFound) {
|
||||||
while (*ArgName == '-') ++ArgName; // Eat leading dashes
|
DashDashFound = true; // This is the mythical "--"?
|
||||||
|
|
||||||
if (*ArgName == 0 && !DashDashFound) { // Is this the mythical "--"?
|
|
||||||
DashDashFound = true; // Yup, take note of that fact...
|
|
||||||
continue; // Don't try to process it as an argument itself.
|
continue; // Don't try to process it as an argument itself.
|
||||||
|
} else if (ActivePositionalArg &&
|
||||||
|
(ActivePositionalArg->getMiscFlags() & PositionalEatsArgs)) {
|
||||||
|
// If there is a positional argument eating options, check to see if this
|
||||||
|
// option is another positional argument. If so, treat it as an argument,
|
||||||
|
// otherwise feed it to the eating positional.
|
||||||
|
ArgName = argv[i]+1;
|
||||||
|
Handler = LookupOption(ArgName, Value);
|
||||||
|
if (!Handler || Handler->getFormattingFlag() != cl::Positional) {
|
||||||
|
ProvidePositionalOption(ActivePositionalArg, argv[i]);
|
||||||
|
continue; // We are done!
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *ArgNameEnd = ArgName;
|
} else { // We start with a '-', must be an argument...
|
||||||
while (*ArgNameEnd && *ArgNameEnd != '=')
|
ArgName = argv[i]+1;
|
||||||
++ArgNameEnd; // Scan till end of argument name...
|
Handler = LookupOption(ArgName, Value);
|
||||||
|
|
||||||
Value = ArgNameEnd;
|
// Check to see if this "option" is really a prefixed or grouped argument.
|
||||||
if (*Value) // If we have an equals sign...
|
if (Handler == 0 && *Value == 0) {
|
||||||
++Value; // Advance to value...
|
std::string RealName(ArgName);
|
||||||
|
if (RealName.size() > 1) {
|
||||||
if (*ArgName != 0) {
|
|
||||||
std::string RealName(ArgName, ArgNameEnd);
|
|
||||||
// Extract arg name part
|
|
||||||
std::map<std::string, Option*>::iterator I = Opts.find(RealName);
|
|
||||||
|
|
||||||
if (I == Opts.end() && !*Value && RealName.size() > 1) {
|
|
||||||
// Check to see if this "option" is really a prefixed or grouped
|
|
||||||
// argument...
|
|
||||||
//
|
|
||||||
unsigned Length = 0;
|
unsigned Length = 0;
|
||||||
Option *PGOpt = getOptionPred(RealName, Length, isPrefixedOrGrouping);
|
Option *PGOpt = getOptionPred(RealName, Length, isPrefixedOrGrouping);
|
||||||
|
|
||||||
@ -369,17 +390,18 @@ void cl::ParseCommandLineOptions(int &argc, char **argv,
|
|||||||
// setting up the argument name flags and value fields.
|
// setting up the argument name flags and value fields.
|
||||||
//
|
//
|
||||||
if (PGOpt && PGOpt->getFormattingFlag() == cl::Prefix) {
|
if (PGOpt && PGOpt->getFormattingFlag() == cl::Prefix) {
|
||||||
ArgNameEnd = ArgName+Length;
|
Value = ArgName+Length;
|
||||||
Value = ArgNameEnd;
|
assert(Opts.find(std::string(ArgName, Value)) != Opts.end() &&
|
||||||
I = Opts.find(std::string(ArgName, ArgNameEnd));
|
Opts.find(std::string(ArgName, Value))->second == PGOpt);
|
||||||
assert(I->second == PGOpt);
|
Handler = PGOpt;
|
||||||
} else if (PGOpt) {
|
} else if (PGOpt) {
|
||||||
// This must be a grouped option... handle all of them now...
|
// This must be a grouped option... handle them now.
|
||||||
assert(isGrouping(PGOpt) && "Broken getOptionPred!");
|
assert(isGrouping(PGOpt) && "Broken getOptionPred!");
|
||||||
|
|
||||||
do {
|
do {
|
||||||
// Move current arg name out of RealName into RealArgName...
|
// Move current arg name out of RealName into RealArgName...
|
||||||
std::string RealArgName(RealName.begin(),RealName.begin()+Length);
|
std::string RealArgName(RealName.begin(),
|
||||||
|
RealName.begin() + Length);
|
||||||
RealName.erase(RealName.begin(), RealName.begin() + Length);
|
RealName.erase(RealName.begin(), RealName.begin() + Length);
|
||||||
|
|
||||||
// Because ValueRequired is an invalid flag for grouped arguments,
|
// Because ValueRequired is an invalid flag for grouped arguments,
|
||||||
@ -388,25 +410,16 @@ void cl::ParseCommandLineOptions(int &argc, char **argv,
|
|||||||
assert(PGOpt->getValueExpectedFlag() != cl::ValueRequired &&
|
assert(PGOpt->getValueExpectedFlag() != cl::ValueRequired &&
|
||||||
"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.c_str(), "",
|
ErrorParsing |= ProvideOption(PGOpt, RealArgName.c_str(),
|
||||||
0, 0, Dummy);
|
"", 0, 0, Dummy);
|
||||||
|
|
||||||
// Get the next grouping option...
|
// Get the next grouping option...
|
||||||
if (!RealName.empty())
|
|
||||||
PGOpt = getOptionPred(RealName, Length, isGrouping);
|
PGOpt = getOptionPred(RealName, Length, isGrouping);
|
||||||
} while (!RealName.empty() && PGOpt);
|
} while (PGOpt && Length != RealName.size());
|
||||||
|
|
||||||
if (RealName.empty()) // Processed all of the options, move on
|
Handler = PGOpt; // Ate all of the options.
|
||||||
continue; // to the next argv[] value...
|
|
||||||
|
|
||||||
// If RealName is not empty, that means we did not match one of the
|
|
||||||
// options! This is an error.
|
|
||||||
//
|
|
||||||
I = Opts.end();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Handler = I != Opts.end() ? I->second : 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user