[llvm] r240233 - ArrayRef-ify ParseArgs
David Blaikie
dblaikie at gmail.com
Sat Jun 20 23:31:53 PDT 2015
Author: dblaikie
Date: Sun Jun 21 01:31:53 2015
New Revision: 240233
URL: http://llvm.org/viewvc/llvm-project?rev=240233&view=rev
Log:
ArrayRef-ify ParseArgs
Modified:
llvm/trunk/include/llvm/Option/OptTable.h
llvm/trunk/lib/LibDriver/LibDriver.cpp
llvm/trunk/lib/Option/OptTable.cpp
llvm/trunk/unittests/Option/OptionParsingTest.cpp
Modified: llvm/trunk/include/llvm/Option/OptTable.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Option/OptTable.h?rev=240233&r1=240232&r2=240233&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Option/OptTable.h (original)
+++ llvm/trunk/include/llvm/Option/OptTable.h Sun Jun 21 01:31:53 2015
@@ -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;
Modified: llvm/trunk/lib/LibDriver/LibDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LibDriver/LibDriver.cpp?rev=240233&r1=240232&r2=240233&view=diff
==============================================================================
--- llvm/trunk/lib/LibDriver/LibDriver.cpp (original)
+++ llvm/trunk/lib/LibDriver/LibDriver.cpp Sun Jun 21 01:31:53 2015
@@ -114,8 +114,8 @@ int llvm::libDriverMain(int Argc, const
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)
Modified: llvm/trunk/lib/Option/OptTable.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Option/OptTable.cpp?rev=240233&r1=240232&r2=240233&view=diff
==============================================================================
--- llvm/trunk/lib/Option/OptTable.cpp (original)
+++ llvm/trunk/lib/Option/OptTable.cpp Sun Jun 21 01:31:53 2015
@@ -247,18 +247,17 @@ Arg *OptTable::ParseOneArg(const ArgList
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) {
Modified: llvm/trunk/unittests/Option/OptionParsingTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Option/OptionParsingTest.cpp?rev=240233&r1=240232&r2=240233&view=diff
==============================================================================
--- llvm/trunk/unittests/Option/OptionParsingTest.cpp (original)
+++ llvm/trunk/unittests/Option/OptionParsingTest.cpp Sun Jun 21 01:31:53 2015
@@ -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);
More information about the llvm-commits
mailing list