dang created this revision.
dang added a reviewer: Bigcheese.
Herald added subscribers: llvm-commits, cfe-commits, dexonsmith.
Herald added projects: clang, LLVM.
Depends on D84188 <https://reviews.llvm.org/D84188>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D84189
Files:
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp
llvm/include/llvm/Option/OptParser.td
Index: llvm/include/llvm/Option/OptParser.td
===================================================================
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -198,9 +198,6 @@
code Normalizer = "normalizeSimpleEnum";
code Denormalizer = "denormalizeSimpleEnum";
}
-class AutoNormalizeEnumJoined : AutoNormalizeEnum {
- code Denormalizer = "denormalizeSimpleEnumJoined";
-}
class ValueMerger<code merger> { code ValueMerger = merger; }
class ValueExtractor<code extractor> { code ValueExtractor = extractor; }
Index: clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -143,7 +143,8 @@
void denormalizeSimpleFlag(SmallVectorImpl<const char *> &Args,
const char *Spelling,
CompilerInvocation::StringAllocator SA,
- unsigned TableIndex, T Value) {
+ Option::OptionClass OptClass, unsigned TableIndex,
+ T Value) {
Args.push_back(Spelling);
}
@@ -177,6 +178,38 @@
Args.push_back(NegSpelling);
}
+static Optional<std::string> normalizeString(OptSpecifier Opt, int TableIndex,
+ const ArgList &Args,
+ DiagnosticsEngine &Diags) {
+ auto *Arg = Args.getLastArg(Opt);
+ if (!Arg)
+ return None;
+ return std::string(Arg->getValue());
+}
+
+template <typename T>
+static void denormalizeString(SmallVectorImpl<const char *> &Args,
+ const char *Spelling,
+ CompilerInvocation::StringAllocator SA,
+ Option::OptionClass OptClass, unsigned TableIndex,
+ T &&Value) {
+ static_assert(std::is_constructible<Twine, T>::value,
+ "Cannot convert this value to Twine");
+ switch (OptClass) {
+ case Option::SeparateClass:
+ case Option::JoinedOrSeparateClass:
+ Args.push_back(Spelling);
+ Args.push_back(SA(Twine(std::forward<T>(Value))));
+ break;
+ case Option::JoinedClass:
+ Args.push_back(SA(Twine(Spelling) + Twine(std::forward<T>(Value))));
+ break;
+ default:
+ llvm_unreachable("Cannot denormalize an option with option class "
+ "incompatible with string denormalization.");
+ }
+}
+
static Optional<SimpleEnumValue>
findValueTableByName(const SimpleEnumValueTable &Table, StringRef Name) {
for (int I = 0, E = Table.Size; I != E; ++I)
@@ -218,51 +251,19 @@
static void denormalizeSimpleEnum(SmallVectorImpl<const char *> &Args,
const char *Spelling,
CompilerInvocation::StringAllocator SA,
+ Option::OptionClass OptClass,
unsigned TableIndex, unsigned Value) {
assert(TableIndex < SimpleEnumValueTablesSize);
const SimpleEnumValueTable &Table = SimpleEnumValueTables[TableIndex];
if (auto MaybeEnumVal = findValueTableByValue(Table, Value)) {
- Args.push_back(Spelling);
- Args.push_back(MaybeEnumVal->Name);
+ denormalizeString(Args, Spelling, SA, OptClass, TableIndex,
+ MaybeEnumVal->Name);
} else {
llvm_unreachable("The simple enum value was not correctly defined in "
"the tablegen option description");
}
}
-static void denormalizeSimpleEnumJoined(SmallVectorImpl<const char *> &Args,
- const char *Spelling,
- CompilerInvocation::StringAllocator SA,
- unsigned TableIndex, unsigned Value) {
- assert(TableIndex < SimpleEnumValueTablesSize);
- const SimpleEnumValueTable &Table = SimpleEnumValueTables[TableIndex];
- if (auto MaybeEnumVal = findValueTableByValue(Table, Value))
- Args.push_back(SA(Twine(Spelling) + MaybeEnumVal->Name));
- else
- llvm_unreachable("The simple enum value was not correctly defined in "
- "the tablegen option description");
-}
-
-static Optional<std::string> normalizeString(OptSpecifier Opt, int TableIndex,
- const ArgList &Args,
- DiagnosticsEngine &Diags) {
- auto *Arg = Args.getLastArg(Opt);
- if (!Arg)
- return None;
- return std::string(Arg->getValue());
-}
-
-template <typename T>
-static void denormalizeString(SmallVectorImpl<const char *> &Args,
- const char *Spelling,
- CompilerInvocation::StringAllocator SA,
- unsigned TableIndex, T &&Value) {
- static_assert(std::is_constructible<Twine, T>::value,
- "Cannot convert this value to Twine");
- Args.push_back(Spelling);
- Args.push_back(SA(Twine(std::forward<T>(Value))));
-}
-
template <typename IntTy>
static Optional<IntTy> normalizeStringIntegral(OptSpecifier Opt, int TableIndex,
const ArgList &Args,
@@ -3474,7 +3475,8 @@
const auto &Extracted = EXTRACTOR(this->KEYPATH); \
if (ALWAYS_EMIT || \
static_cast<decltype(DEFAULT_VALUE)>(Extracted) != DEFAULT_VALUE) \
- DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, Extracted); \
+ DENORMALIZER(Args, SPELLING, SA, Option::KIND##Class, TABLE_INDEX, \
+ Extracted); \
}
#define OPTION_WITH_MARSHALLING_BOOLEAN( \
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -554,7 +554,7 @@
NormalizedValuesScope<"FrontendOptions">,
NormalizedValues<["ARCMT_Check", "ARCMT_Modify", "ARCMT_Migrate"]>,
MarshallingInfoString<"FrontendOpts.ARCMTAction", "ARCMT_None">,
- AutoNormalizeEnumJoined;
+ AutoNormalizeEnum;
def print_stats : Flag<["-"], "print-stats">,
HelpText<"Print performance metrics and statistics">,
MarshallingInfoFlag<"FrontendOpts.ShowStats", "false">;
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits