diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-11-25 11:33:30 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-11-25 11:33:30 +0000 |
commit | 3b84f5bab9f134741cf4d3c80086009519b6d968 (patch) | |
tree | a97ba8eb4d9ac995c0ca3fec63dfdbf016e12386 /lib/Driver/ArgList.cpp | |
parent | 1a50628f0689e8b467d7bfa51b8d1f31f158e2cd (diff) |
Add an arg_iterator, for iterating over a subset of arguments in an ArgList.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89860 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver/ArgList.cpp')
-rw-r--r-- | lib/Driver/ArgList.cpp | 112 |
1 files changed, 40 insertions, 72 deletions
diff --git a/lib/Driver/ArgList.cpp b/lib/Driver/ArgList.cpp index ea75c34ea5..8a57d14932 100644 --- a/lib/Driver/ArgList.cpp +++ b/lib/Driver/ArgList.cpp @@ -17,6 +17,23 @@ using namespace clang::driver; +void arg_iterator::SkipToNextArg() { + for (; Current != Args.end(); ++Current) { + // Done if there are no filters. + if (!Id0.isValid()) + break; + + // Otherwise require a match. + const Option &O = (*Current)->getOption(); + if (O.matches(Id0) || + (Id1.isValid() && O.matches(Id1)) || + (Id2.isValid() && O.matches(Id2))) + break; + } +} + +// + ArgList::ArgList(arglist_type &_Args) : Args(_Args) { } @@ -98,95 +115,46 @@ void ArgList::AddLastArg(ArgStringList &Output, OptSpecifier Id) const { } } -void ArgList::AddAllArgs(ArgStringList &Output, OptSpecifier Id0) const { - // FIXME: Make fast. - for (const_iterator it = begin(), ie = end(); it != ie; ++it) { - const Arg *A = *it; - if (A->getOption().matches(Id0)) { - A->claim(); - A->render(*this, Output); - } - } -} - -void ArgList::AddAllArgs(ArgStringList &Output, OptSpecifier Id0, - OptSpecifier Id1) const { - // FIXME: Make fast. - for (const_iterator it = begin(), ie = end(); it != ie; ++it) { - const Arg *A = *it; - if (A->getOption().matches(Id0) || A->getOption().matches(Id1)) { - A->claim(); - A->render(*this, Output); - } - } -} - void ArgList::AddAllArgs(ArgStringList &Output, OptSpecifier Id0, OptSpecifier Id1, OptSpecifier Id2) const { - // FIXME: Make fast. - for (const_iterator it = begin(), ie = end(); it != ie; ++it) { - const Arg *A = *it; - if (A->getOption().matches(Id0) || A->getOption().matches(Id1) || - A->getOption().matches(Id2)) { - A->claim(); - A->render(*this, Output); - } - } -} - -void ArgList::AddAllArgValues(ArgStringList &Output, OptSpecifier Id0) const { - // FIXME: Make fast. - for (const_iterator it = begin(), ie = end(); it != ie; ++it) { - const Arg *A = *it; - if (A->getOption().matches(Id0)) { - A->claim(); - for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) - Output.push_back(A->getValue(*this, i)); - } + for (arg_iterator it = filtered_begin(Id0, Id1, Id2), + ie = filtered_end(); it != ie; ++it) { + it->claim(); + it->render(*this, Output); } } void ArgList::AddAllArgValues(ArgStringList &Output, OptSpecifier Id0, - OptSpecifier Id1) const { - // FIXME: Make fast. - for (const_iterator it = begin(), ie = end(); it != ie; ++it) { - const Arg *A = *it; - if (A->getOption().matches(Id0) || A->getOption().matches(Id1)) { - A->claim(); - for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) - Output.push_back(A->getValue(*this, i)); - } + 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(*this, i)); } } void ArgList::AddAllArgsTranslated(ArgStringList &Output, OptSpecifier Id0, const char *Translation, bool Joined) const { - // FIXME: Make fast. - for (const_iterator it = begin(), ie = end(); it != ie; ++it) { - const Arg *A = *it; - if (A->getOption().matches(Id0)) { - A->claim(); - - if (Joined) { - std::string Value = Translation; - Value += A->getValue(*this, 0); - Output.push_back(MakeArgString(Value.c_str())); - } else { - Output.push_back(Translation); - Output.push_back(A->getValue(*this, 0)); - } + for (arg_iterator it = filtered_begin(Id0), + ie = filtered_end(); it != ie; ++it) { + it->claim(); + + if (Joined) { + Output.push_back(MakeArgString(llvm::StringRef(Translation) + + it->getValue(*this, 0))); + } else { + Output.push_back(Translation); + Output.push_back(it->getValue(*this, 0)); } } } void ArgList::ClaimAllArgs(OptSpecifier Id0) const { - // FIXME: Make fast. - for (const_iterator it = begin(), ie = end(); it != ie; ++it) { - const Arg *A = *it; - if (A->getOption().matches(Id0)) - A->claim(); - } + for (arg_iterator it = filtered_begin(Id0), + ie = filtered_end(); it != ie; ++it) + it->claim(); } const char *ArgList::MakeArgString(const llvm::Twine &T) const { |