mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-25 04:39:44 +00:00
ArrayRef-ify ParseArgs
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240233 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
87ae2e8ab0
commit
006bce7764
@ -10,6 +10,7 @@
|
||||
#ifndef LLVM_OPTION_OPTTABLE_H
|
||||
#define LLVM_OPTION_OPTTABLE_H
|
||||
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/ADT/StringSet.h"
|
||||
#include "llvm/Option/OptSpecifier.h"
|
||||
|
||||
@ -152,10 +153,8 @@ public:
|
||||
/// is the default and means exclude nothing.
|
||||
/// \return An InputArgList; on error this will contain all the options
|
||||
/// which could be parsed.
|
||||
InputArgList *ParseArgs(const char* const *ArgBegin,
|
||||
const char* const *ArgEnd,
|
||||
unsigned &MissingArgIndex,
|
||||
unsigned &MissingArgCount,
|
||||
InputArgList *ParseArgs(ArrayRef<const char *> Args,
|
||||
unsigned &MissingArgIndex, unsigned &MissingArgCount,
|
||||
unsigned FlagsToInclude = 0,
|
||||
unsigned FlagsToExclude = 0) const;
|
||||
|
||||
|
@ -114,8 +114,8 @@ int llvm::libDriverMain(int Argc, const char **Argv) {
|
||||
LibOptTable Table;
|
||||
unsigned MissingIndex;
|
||||
unsigned MissingCount;
|
||||
std::unique_ptr<llvm::opt::InputArgList> Args(
|
||||
Table.ParseArgs(&Argv[1], &Argv[Argc], MissingIndex, MissingCount));
|
||||
std::unique_ptr<llvm::opt::InputArgList> Args(Table.ParseArgs(
|
||||
makeArrayRef(Argv, Argc).slice(1), MissingIndex, MissingCount));
|
||||
if (MissingCount) {
|
||||
llvm::errs() << "missing arg value for \""
|
||||
<< Args->getArgString(MissingIndex)
|
||||
|
@ -247,18 +247,17 @@ Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index,
|
||||
return new Arg(getOption(TheUnknownOptionID), Str, Index++, Str);
|
||||
}
|
||||
|
||||
InputArgList *OptTable::ParseArgs(const char *const *ArgBegin,
|
||||
const char *const *ArgEnd,
|
||||
InputArgList *OptTable::ParseArgs(ArrayRef<const char *> ArgArr,
|
||||
unsigned &MissingArgIndex,
|
||||
unsigned &MissingArgCount,
|
||||
unsigned FlagsToInclude,
|
||||
unsigned FlagsToExclude) const {
|
||||
InputArgList *Args = new InputArgList(ArgBegin, ArgEnd);
|
||||
InputArgList *Args = new InputArgList(ArgArr.begin(), ArgArr.end());
|
||||
|
||||
// FIXME: Handle '@' args (or at least error on them).
|
||||
|
||||
MissingArgIndex = MissingArgCount = 0;
|
||||
unsigned Index = 0, End = ArgEnd - ArgBegin;
|
||||
unsigned Index = 0, End = ArgArr.size();
|
||||
while (Index < End) {
|
||||
// Ingore nullptrs, they are response file's EOL markers
|
||||
if (Args->getArgString(Index) == nullptr) {
|
||||
|
@ -67,8 +67,7 @@ const char *Args[] = {
|
||||
TEST(Option, OptionParsing) {
|
||||
TestOptTable T;
|
||||
unsigned MAI, MAC;
|
||||
std::unique_ptr<InputArgList> AL(
|
||||
T.ParseArgs(std::begin(Args), std::end(Args), MAI, MAC));
|
||||
std::unique_ptr<InputArgList> AL(T.ParseArgs(Args, MAI, MAC));
|
||||
|
||||
// Check they all exist.
|
||||
EXPECT_TRUE(AL->hasArg(OPT_A));
|
||||
@ -114,7 +113,7 @@ TEST(Option, ParseWithFlagExclusions) {
|
||||
std::unique_ptr<InputArgList> AL;
|
||||
|
||||
// Exclude flag3 to avoid parsing as OPT_SLASH_C.
|
||||
AL.reset(T.ParseArgs(std::begin(Args), std::end(Args), MAI, MAC,
|
||||
AL.reset(T.ParseArgs(Args, MAI, MAC,
|
||||
/*FlagsToInclude=*/0,
|
||||
/*FlagsToExclude=*/OptFlag3));
|
||||
EXPECT_TRUE(AL->hasArg(OPT_A));
|
||||
@ -122,7 +121,7 @@ TEST(Option, ParseWithFlagExclusions) {
|
||||
EXPECT_FALSE(AL->hasArg(OPT_SLASH_C));
|
||||
|
||||
// Exclude flag1 to avoid parsing as OPT_C.
|
||||
AL.reset(T.ParseArgs(std::begin(Args), std::end(Args), MAI, MAC,
|
||||
AL.reset(T.ParseArgs(Args, MAI, MAC,
|
||||
/*FlagsToInclude=*/0,
|
||||
/*FlagsToExclude=*/OptFlag1));
|
||||
EXPECT_TRUE(AL->hasArg(OPT_B));
|
||||
@ -130,7 +129,7 @@ TEST(Option, ParseWithFlagExclusions) {
|
||||
EXPECT_TRUE(AL->hasArg(OPT_SLASH_C));
|
||||
|
||||
const char *NewArgs[] = { "/C", "foo", "--C=bar" };
|
||||
AL.reset(T.ParseArgs(std::begin(NewArgs), std::end(NewArgs), MAI, MAC));
|
||||
AL.reset(T.ParseArgs(NewArgs, MAI, MAC));
|
||||
EXPECT_TRUE(AL->hasArg(OPT_SLASH_C));
|
||||
EXPECT_TRUE(AL->hasArg(OPT_C));
|
||||
EXPECT_EQ(AL->getLastArgValue(OPT_SLASH_C), "foo");
|
||||
@ -142,8 +141,7 @@ TEST(Option, ParseAliasInGroup) {
|
||||
unsigned MAI, MAC;
|
||||
|
||||
const char *MyArgs[] = { "-I" };
|
||||
std::unique_ptr<InputArgList> AL(
|
||||
T.ParseArgs(std::begin(MyArgs), std::end(MyArgs), MAI, MAC));
|
||||
std::unique_ptr<InputArgList> AL(T.ParseArgs(MyArgs, MAI, MAC));
|
||||
EXPECT_TRUE(AL->hasArg(OPT_H));
|
||||
}
|
||||
|
||||
@ -152,8 +150,7 @@ TEST(Option, AliasArgs) {
|
||||
unsigned MAI, MAC;
|
||||
|
||||
const char *MyArgs[] = { "-J", "-Joo" };
|
||||
std::unique_ptr<InputArgList> AL(
|
||||
T.ParseArgs(std::begin(MyArgs), std::end(MyArgs), MAI, MAC));
|
||||
std::unique_ptr<InputArgList> AL(T.ParseArgs(MyArgs, MAI, MAC));
|
||||
EXPECT_TRUE(AL->hasArg(OPT_B));
|
||||
EXPECT_EQ(AL->getAllArgValues(OPT_B)[0], "foo");
|
||||
EXPECT_EQ(AL->getAllArgValues(OPT_B)[1], "bar");
|
||||
@ -164,8 +161,7 @@ TEST(Option, IgnoreCase) {
|
||||
unsigned MAI, MAC;
|
||||
|
||||
const char *MyArgs[] = { "-a", "-joo" };
|
||||
std::unique_ptr<InputArgList> AL(
|
||||
T.ParseArgs(std::begin(MyArgs), std::end(MyArgs), MAI, MAC));
|
||||
std::unique_ptr<InputArgList> AL(T.ParseArgs(MyArgs, MAI, MAC));
|
||||
EXPECT_TRUE(AL->hasArg(OPT_A));
|
||||
EXPECT_TRUE(AL->hasArg(OPT_B));
|
||||
}
|
||||
@ -175,8 +171,7 @@ TEST(Option, DoNotIgnoreCase) {
|
||||
unsigned MAI, MAC;
|
||||
|
||||
const char *MyArgs[] = { "-a", "-joo" };
|
||||
std::unique_ptr<InputArgList> AL(
|
||||
T.ParseArgs(std::begin(MyArgs), std::end(MyArgs), MAI, MAC));
|
||||
std::unique_ptr<InputArgList> AL(T.ParseArgs(MyArgs, MAI, MAC));
|
||||
EXPECT_FALSE(AL->hasArg(OPT_A));
|
||||
EXPECT_FALSE(AL->hasArg(OPT_B));
|
||||
}
|
||||
@ -186,8 +181,7 @@ TEST(Option, SlurpEmpty) {
|
||||
unsigned MAI, MAC;
|
||||
|
||||
const char *MyArgs[] = { "-A", "-slurp" };
|
||||
std::unique_ptr<InputArgList> AL(
|
||||
T.ParseArgs(std::begin(MyArgs), std::end(MyArgs), MAI, MAC));
|
||||
std::unique_ptr<InputArgList> AL(T.ParseArgs(MyArgs, MAI, MAC));
|
||||
EXPECT_TRUE(AL->hasArg(OPT_A));
|
||||
EXPECT_TRUE(AL->hasArg(OPT_Slurp));
|
||||
EXPECT_EQ(AL->getAllArgValues(OPT_Slurp).size(), 0U);
|
||||
@ -198,8 +192,7 @@ TEST(Option, Slurp) {
|
||||
unsigned MAI, MAC;
|
||||
|
||||
const char *MyArgs[] = { "-A", "-slurp", "-B", "--", "foo" };
|
||||
std::unique_ptr<InputArgList> AL(
|
||||
T.ParseArgs(std::begin(MyArgs), std::end(MyArgs), MAI, MAC));
|
||||
std::unique_ptr<InputArgList> AL(T.ParseArgs(MyArgs, MAI, MAC));
|
||||
EXPECT_EQ(AL->size(), 2U);
|
||||
EXPECT_TRUE(AL->hasArg(OPT_A));
|
||||
EXPECT_FALSE(AL->hasArg(OPT_B));
|
||||
@ -216,8 +209,7 @@ TEST(Option, FlagAliasToJoined) {
|
||||
|
||||
// Check that a flag alias provides an empty argument to a joined option.
|
||||
const char *MyArgs[] = { "-K" };
|
||||
std::unique_ptr<InputArgList> AL(
|
||||
T.ParseArgs(std::begin(MyArgs), std::end(MyArgs), MAI, MAC));
|
||||
std::unique_ptr<InputArgList> AL(T.ParseArgs(MyArgs, MAI, MAC));
|
||||
EXPECT_EQ(AL->size(), 1U);
|
||||
EXPECT_TRUE(AL->hasArg(OPT_B));
|
||||
EXPECT_EQ(AL->getAllArgValues(OPT_B).size(), 1U);
|
||||
|
Loading…
Reference in New Issue
Block a user