diff options
author | Don Hinton <hintonda@gmail.com> | 2019-04-15 17:18:10 +0000 |
---|---|---|
committer | Don Hinton <hintonda@gmail.com> | 2019-04-15 17:18:10 +0000 |
commit | b85f74a283a62246d60083f52c779171a65a091c (patch) | |
tree | a040f295ef3cd48b61571e1f0a4adf7f755f1fc2 /llvm/include/llvm/Support/CommandLine.h | |
parent | 8e364c680fab1724bd0d4749b8d1177843164aa7 (diff) | |
download | bcm5719-llvm-b85f74a283a62246d60083f52c779171a65a091c.tar.gz bcm5719-llvm-b85f74a283a62246d60083f52c779171a65a091c.zip |
[CommandLineParser] Add DefaultOption flag
Summary: Add DefaultOption flag to CommandLineParser which provides a
default option or alias, but allows users to override it for some
other purpose as needed.
Also, add `-h` as a default alias to `-help`, which can be seamlessly
overridden by applications like llvm-objdump and llvm-readobj which
use `-h` as an alias for other options.
(relanding after revert, r358414)
Added DefaultOptions.clear() to reset().
Reviewers: alexfh, klimek
Reviewed By: klimek
Subscribers: kristina, MaskRay, mehdi_amini, inglorion, dexonsmith, hiraditya, llvm-commits, jhenderson, arphaman, cfe-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D59746
llvm-svn: 358428
Diffstat (limited to 'llvm/include/llvm/Support/CommandLine.h')
-rw-r--r-- | llvm/include/llvm/Support/CommandLine.h | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h index cb85534ad8e..1fb95957244 100644 --- a/llvm/include/llvm/Support/CommandLine.h +++ b/llvm/include/llvm/Support/CommandLine.h @@ -175,7 +175,10 @@ enum MiscFlags { // Miscellaneous flags to adjust argument // If this is enabled, multiple letter options are allowed to bunch together // with only a single hyphen for the whole group. This allows emulation // of the behavior that ls uses for example: ls -la === ls -l -a - Grouping = 0x08 + Grouping = 0x08, + + // Default option + DefaultOption = 0x10 }; //===----------------------------------------------------------------------===// @@ -270,7 +273,7 @@ class Option { unsigned Value : 2; unsigned HiddenFlag : 2; // enum OptionHidden unsigned Formatting : 2; // enum FormattingFlags - unsigned Misc : 4; + unsigned Misc : 5; unsigned Position = 0; // Position of last occurrence of the option unsigned AdditionalVals = 0; // Greater than 0 for multi-valued option. @@ -306,6 +309,7 @@ public: bool hasArgStr() const { return !ArgStr.empty(); } bool isPositional() const { return getFormattingFlag() == cl::Positional; } bool isSink() const { return getMiscFlags() & cl::Sink; } + bool isDefaultOption() const { return getMiscFlags() & cl::DefaultOption; } bool isConsumeAfter() const { return getNumOccurrencesFlag() == cl::ConsumeAfter; @@ -382,7 +386,7 @@ public: } inline int getNumOccurrences() const { return NumOccurrences; } - inline void reset() { NumOccurrences = 0; } + void reset(); }; //===----------------------------------------------------------------------===// @@ -1732,7 +1736,10 @@ class alias : public Option { error("cl::alias must have argument name specified!"); if (!AliasFor) error("cl::alias must have an cl::aliasopt(option) specified!"); + if (!Subs.empty()) + error("cl::alias must not have cl::sub(), aliased option's cl::sub() will be used!"); Subs = AliasFor->Subs; + Category = AliasFor->Category; addArgument(); } |