summaryrefslogtreecommitdiffstats
path: root/llvm/include/llvm/Support/CommandLine.h
diff options
context:
space:
mode:
authorDon Hinton <hintonda@gmail.com>2019-06-22 23:32:36 +0000
committerDon Hinton <hintonda@gmail.com>2019-06-22 23:32:36 +0000
commit64b0924531cc113029a3b738e9a3c2091e1740b3 (patch)
tree4cc7e5a45d46c7e4f5076d018796986552e46139 /llvm/include/llvm/Support/CommandLine.h
parent1fa07ebd929383f769994818c3f8c55919bf0a0e (diff)
downloadbcm5719-llvm-64b0924531cc113029a3b738e9a3c2091e1740b3.tar.gz
bcm5719-llvm-64b0924531cc113029a3b738e9a3c2091e1740b3.zip
Revert [CommandLine] Remove OptionCategory and SubCommand caches from the Option class.
This reverts r364134 (git commit a5b83bc9e3b8e8945b55068c762bd6c73621a4b0) Caused errors in the asan bot, so the GeneralCategory global needs to be changed to ManagedStatic. Differential Revision: https://reviews.llvm.org/D62105 llvm-svn: 364141
Diffstat (limited to 'llvm/include/llvm/Support/CommandLine.h')
-rw-r--r--llvm/include/llvm/Support/CommandLine.h46
1 files changed, 20 insertions, 26 deletions
diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h
index 2f88150b5a1..3cc2c3c0121 100644
--- a/llvm/include/llvm/Support/CommandLine.h
+++ b/llvm/include/llvm/Support/CommandLine.h
@@ -201,8 +201,6 @@ public:
StringRef getName() const { return Name; }
StringRef getDescription() const { return Description; }
-
- SmallPtrSet<Option *, 16> MemberOptions;
};
// The general Option Category (used as default category).
@@ -285,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;
@@ -322,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
//
@@ -335,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; }
@@ -350,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.
///
@@ -468,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); }
};
//===----------------------------------------------------------------------===//
@@ -1775,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:
@@ -1792,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) {
OpenPOWER on IntegriCloud