[llvm] r212615 - Generic: add range-adapter for option parsing.
Tim Northover
tnorthover at apple.com
Wed Jul 9 06:03:37 PDT 2014
Author: tnorthover
Date: Wed Jul 9 08:03:37 2014
New Revision: 212615
URL: http://llvm.org/viewvc/llvm-project?rev=212615&view=rev
Log:
Generic: add range-adapter for option parsing.
I want to use it in lld, but while I'm here I'll update LLVM uses.
Modified:
llvm/trunk/include/llvm/Option/ArgList.h
llvm/trunk/lib/Option/ArgList.cpp
Modified: llvm/trunk/include/llvm/Option/ArgList.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Option/ArgList.h?rev=212615&r1=212614&r2=212615&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Option/ArgList.h (original)
+++ llvm/trunk/include/llvm/Option/ArgList.h Wed Jul 9 08:03:37 2014
@@ -150,6 +150,13 @@ public:
return arg_iterator(Args.end(), *this);
}
+ iterator_range<arg_iterator> filtered(OptSpecifier Id0 = 0U,
+ OptSpecifier Id1 = 0U,
+ OptSpecifier Id2 = 0U) const {
+ return iterator_range<arg_iterator>(filtered_begin(Id0, Id1, Id2),
+ filtered_end());
+ }
+
/// @}
/// @name Arg Removal
/// @{
Modified: llvm/trunk/lib/Option/ArgList.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Option/ArgList.cpp?rev=212615&r1=212614&r2=212615&view=diff
==============================================================================
--- llvm/trunk/lib/Option/ArgList.cpp (original)
+++ llvm/trunk/lib/Option/ArgList.cpp Wed Jul 9 08:03:37 2014
@@ -234,44 +234,40 @@ void ArgList::AddLastArg(ArgStringList &
void ArgList::AddAllArgs(ArgStringList &Output, OptSpecifier Id0,
OptSpecifier Id1, OptSpecifier Id2) const {
- for (arg_iterator it = filtered_begin(Id0, Id1, Id2),
- ie = filtered_end(); it != ie; ++it) {
- (*it)->claim();
- (*it)->render(*this, Output);
+ for (auto Arg: filtered(Id0, Id1, Id2)) {
+ Arg->claim();
+ Arg->render(*this, Output);
}
}
void ArgList::AddAllArgValues(ArgStringList &Output, OptSpecifier Id0,
OptSpecifier Id1, OptSpecifier Id2) const {
- for (arg_iterator it = filtered_begin(Id0, Id1, Id2),
- ie = filtered_end(); it != ie; ++it) {
- (*it)->claim();
- for (unsigned i = 0, e = (*it)->getNumValues(); i != e; ++i)
- Output.push_back((*it)->getValue(i));
+ for (auto Arg : filtered(Id0, Id1, Id2)) {
+ Arg->claim();
+ for (unsigned i = 0, e = Arg->getNumValues(); i != e; ++i)
+ Output.push_back(Arg->getValue(i));
}
}
void ArgList::AddAllArgsTranslated(ArgStringList &Output, OptSpecifier Id0,
const char *Translation,
bool Joined) const {
- for (arg_iterator it = filtered_begin(Id0),
- ie = filtered_end(); it != ie; ++it) {
- (*it)->claim();
+ for (auto Arg: filtered(Id0)) {
+ Arg->claim();
if (Joined) {
Output.push_back(MakeArgString(StringRef(Translation) +
- (*it)->getValue(0)));
+ Arg->getValue(0)));
} else {
Output.push_back(Translation);
- Output.push_back((*it)->getValue(0));
+ Output.push_back(Arg->getValue(0));
}
}
}
void ArgList::ClaimAllArgs(OptSpecifier Id0) const {
- for (arg_iterator it = filtered_begin(Id0),
- ie = filtered_end(); it != ie; ++it)
- (*it)->claim();
+ for (auto Arg : filtered(Id0))
+ Arg->claim();
}
void ArgList::ClaimAllArgs() const {
More information about the llvm-commits
mailing list