diff options
| author | Haojian Wu <hokein@google.com> | 2019-07-11 08:54:28 +0000 |
|---|---|---|
| committer | Haojian Wu <hokein@google.com> | 2019-07-11 08:54:28 +0000 |
| commit | e6695821e592f95bffe1340b28be7bcfcce04284 (patch) | |
| tree | 77154c23f6f271f7a53cf3658fe8ec371594b26d /llvm/include/llvm/Support/CommandLine.h | |
| parent | c1b7db9edaaffdb31ce4ff53a8a91181daeca80a (diff) | |
| download | bcm5719-llvm-e6695821e592f95bffe1340b28be7bcfcce04284.tar.gz bcm5719-llvm-e6695821e592f95bffe1340b28be7bcfcce04284.zip | |
Revert Recommit "[CommandLine] Remove OptionCategory and SubCommand caches from the Option class."
This reverts r365675 (git commit 43d75f977853c3ec891a440c362b2df183a211b5)
The patch causes a crash in SupportTests (CommandLineTest.AliasesWithArguments).
llvm-svn: 365742
Diffstat (limited to 'llvm/include/llvm/Support/CommandLine.h')
| -rw-r--r-- | llvm/include/llvm/Support/CommandLine.h | 57 |
1 files changed, 25 insertions, 32 deletions
diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h index 036830282a5..3cc2c3c0121 100644 --- a/llvm/include/llvm/Support/CommandLine.h +++ b/llvm/include/llvm/Support/CommandLine.h @@ -187,27 +187,24 @@ enum MiscFlags { // Miscellaneous flags to adjust argument // class OptionCategory { private: - StringRef Name = "General Category"; - StringRef Description; + StringRef const Name; + StringRef const Description; void registerCategory(); public: - OptionCategory(StringRef Name, - StringRef Description = "") + OptionCategory(StringRef const Name, + StringRef const Description = "") : Name(Name), Description(Description) { registerCategory(); } - OptionCategory() = default; StringRef getName() const { return Name; } StringRef getDescription() const { return Description; } - - SmallPtrSet<Option *, 16> MemberOptions; }; // The general Option Category (used as default category). -extern ManagedStatic<OptionCategory> GeneralCategory; +extern OptionCategory GeneralCategory; //===----------------------------------------------------------------------===// // SubCommand class @@ -286,12 +283,9 @@ public: StringRef ArgStr; // The argument string itself (ex: "help", "o") StringRef HelpStr; // The descriptive text message for -help StringRef ValueStr; // String describing what the value of this option is - - // Return the set of OptionCategories that this Option belongs to. - SmallPtrSet<OptionCategory *, 1> getCategories() const; - - // Return the set of SubCommands that this Option belongs to. - SmallPtrSet<SubCommand *, 1> getSubCommands() const; + SmallVector<OptionCategory *, 1> + Categories; // The Categories this option belongs to + SmallPtrSet<SubCommand *, 1> Subs; // The subcommands this option belongs to. inline enum NumOccurrencesFlag getNumOccurrencesFlag() const { return (enum NumOccurrencesFlag)Occurrences; @@ -323,6 +317,12 @@ public: return getNumOccurrencesFlag() == cl::ConsumeAfter; } + bool isInAllSubCommands() const { + return any_of(Subs, [](const SubCommand *SC) { + return SC == &*AllSubCommands; + }); + } + //-------------------------------------------------------------------------=== // Accessor functions set by OptionModifiers // @@ -336,13 +336,16 @@ public: void setMiscFlag(enum MiscFlags M) { Misc |= M; } void setPosition(unsigned pos) { Position = pos; } void addCategory(OptionCategory &C); + void addSubCommand(SubCommand &S) { Subs.insert(&S); } protected: explicit Option(enum NumOccurrencesFlag OccurrencesFlag, enum OptionHidden Hidden) : NumOccurrences(0), Occurrences(OccurrencesFlag), Value(0), HiddenFlag(Hidden), Formatting(NormalFormatting), Misc(0), - FullyInitialized(false), Position(0), AdditionalVals(0) {} + FullyInitialized(false), Position(0), AdditionalVals(0) { + Categories.push_back(&GeneralCategory); + } inline void setNumAdditionalVals(unsigned n) { AdditionalVals = n; } @@ -351,14 +354,7 @@ public: // addArgument - Register this argument with the commandline system. // - virtual void addArgument(SubCommand &SC); - - // addArgument - Only called in done() method to add default - // TopLevelSubCommand. - void addArgument() { - if (!FullyInitialized) - addArgument(*TopLevelSubCommand); - } + void addArgument(); /// Unregisters this option from the CommandLine system. /// @@ -469,7 +465,7 @@ struct sub { sub(SubCommand &S) : Sub(S) {} - template <class Opt> void apply(Opt &O) const { O.addArgument(Sub); } + template <class Opt> void apply(Opt &O) const { O.addSubCommand(Sub); } }; //===----------------------------------------------------------------------===// @@ -1776,10 +1772,11 @@ class alias : public Option { error("cl::alias must have argument name specified!"); if (!AliasFor) error("cl::alias must have an cl::aliasopt(option) specified!"); - for(OptionCategory *Cat: AliasFor->getCategories()) - addCategory(*Cat); - for(SubCommand *SC: AliasFor->getSubCommands()) - Option::addArgument(*SC); + if (!Subs.empty()) + error("cl::alias must not have cl::sub(), aliased option's cl::sub() will be used!"); + Subs = AliasFor->Subs; + Categories = AliasFor->Categories; + addArgument(); } public: @@ -1793,10 +1790,6 @@ public: AliasFor = &O; } - // Does nothing when called via apply. Aliases call Option::addArgument - // directly in the done() method to actually add the option.. - void addArgument(SubCommand &SC) override {} - template <class... Mods> explicit alias(const Mods &... Ms) : Option(Optional, Hidden), AliasFor(nullptr) { |

