diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-03-18 09:29:36 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-03-18 09:29:36 +0000 |
commit | 18a7f33af877fca8f72cfde00d52f4aef600547f (patch) | |
tree | 6184ed0779cc1e1c6e286323d82bc26082626c1c /lib/Driver/ArgList.cpp | |
parent | b488c1dac8e53206f07103d794a62a3f5012c0f4 (diff) |
Driver: Add argument translation utilities to ArgList.
- Support things like telling which -ffoo -fno-foo option won, and
forwarding all arguments matching a certain set of options to the
tool.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67189 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver/ArgList.cpp')
-rw-r--r-- | lib/Driver/ArgList.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/lib/Driver/ArgList.cpp b/lib/Driver/ArgList.cpp index 3c67f8f1e9..ee201f28bd 100644 --- a/lib/Driver/ArgList.cpp +++ b/lib/Driver/ArgList.cpp @@ -58,6 +58,16 @@ Arg *ArgList::getLastArg(options::ID Id0, options::ID Id1, bool Claim) const { return Res; } +bool ArgList::hasFlag(options::ID Pos, options::ID Neg, bool Default) const { + Arg *PosA = getLastArg(Pos); + Arg *NegA = getLastArg(Pos); + if (PosA && NegA) + return NegA->getIndex() < PosA->getIndex(); + if (PosA) return true; + if (NegA) return false; + return Default; +} + unsigned ArgList::MakeIndex(const char *String0) const { unsigned Index = ArgStrings.size(); @@ -97,3 +107,58 @@ Arg *ArgList::MakeJoinedArg(const Option *Opt, const char *Value) const { Joined += Value; return new JoinedArg(Opt, MakeIndex(Joined.c_str())); } + +void ArgList::AddLastArg(ArgStringList &Output, options::ID Id) const { + if (Arg *A = getLastArg(Id)) { + A->claim(); + A->render(*this, Output); + } +} + +void ArgList::AddAllArgs(ArgStringList &Output, options::ID 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, options::ID Id0, + options::ID 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, options::ID Id0, + options::ID Id1, options::ID 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, options::ID 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)); + } + } +} |