diff options
author | Fangrui Song <i@maskray.me> | 2022-04-11 12:29:25 -0700 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2022-04-11 12:29:25 -0700 |
commit | aefa4b60cebaeada796a161bab036bf145790b00 (patch) | |
tree | 44ba33e8c210479bf566364bc2c212a7f5f92b23 /llvm | |
parent | 4df4922da6cd9d4f58aa17bd3a54435d947570fd (diff) | |
download | llvm-aefa4b60cebaeada796a161bab036bf145790b00.zip llvm-aefa4b60cebaeada796a161bab036bf145790b00.tar.gz llvm-aefa4b60cebaeada796a161bab036bf145790b00.tar.bz2 |
[Driver] Simplify hasFlag pattern with addOptInFlag/addOptOutFlag helpers
Reviewed By: dexonsmith
Differential Revision: https://reviews.llvm.org/D123468
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/include/llvm/Option/ArgList.h | 10 | ||||
-rw-r--r-- | llvm/lib/Option/ArgList.cpp | 7 |
2 files changed, 17 insertions, 0 deletions
diff --git a/llvm/include/llvm/Option/ArgList.h b/llvm/include/llvm/Option/ArgList.h index c9dd7da..6a07e1c 100644 --- a/llvm/include/llvm/Option/ArgList.h +++ b/llvm/include/llvm/Option/ArgList.h @@ -307,6 +307,16 @@ public: bool hasFlag(OptSpecifier Pos, OptSpecifier PosAlias, OptSpecifier Neg, bool Default) const; + /// Given an option Pos and its negative form Neg, render the option if Pos is + /// present. + void addOptInFlag(ArgStringList &Output, OptSpecifier Pos, + OptSpecifier Neg) const; + /// Render the option if Neg is present. + void addOptOutFlag(ArgStringList &Output, OptSpecifier Pos, + OptSpecifier Neg) const { + addOptInFlag(Output, Neg, Pos); + } + /// Render only the last argument match \p Id0, if present. template<typename ...OptSpecifiers> void AddLastArg(ArgStringList &Output, OptSpecifiers ...Ids) const { diff --git a/llvm/lib/Option/ArgList.cpp b/llvm/lib/Option/ArgList.cpp index ad7be5f..fab0fb0 100644 --- a/llvm/lib/Option/ArgList.cpp +++ b/llvm/lib/Option/ArgList.cpp @@ -95,6 +95,13 @@ std::vector<std::string> ArgList::getAllArgValues(OptSpecifier Id) const { return std::vector<std::string>(Values.begin(), Values.end()); } +void ArgList::addOptInFlag(ArgStringList &Output, OptSpecifier Pos, + OptSpecifier Neg) const { + if (Arg *A = getLastArg(Pos, Neg)) + if (A->getOption().matches(Pos)) + A->render(*this, Output); +} + void ArgList::AddAllArgsExcept(ArgStringList &Output, ArrayRef<OptSpecifier> Ids, ArrayRef<OptSpecifier> ExcludeIds) const { |