mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[clang][cli] Split DefaultAnyOf into a default value and ImpliedByAnyOf
This makes the options API composable, allows boolean flags to imply non-boolean values and makes the code more logical (IMO). Differential Revision: https://reviews.llvm.org/D91861
This commit is contained in:
parent
27280e2609
commit
5bc4c8d4e4
@ -100,6 +100,8 @@ class Option<list<string> prefixes, string name, OptionKind kind> {
|
||||
string MarshallingInfoKind = ?;
|
||||
code KeyPath = ?;
|
||||
code DefaultValue = ?;
|
||||
code ImpliedValue = ?;
|
||||
code ImpliedCheck = "false";
|
||||
bit ShouldAlwaysEmit = false;
|
||||
code NormalizerRetTy = ?;
|
||||
code NormalizedValuesScope = "";
|
||||
@ -145,9 +147,10 @@ class ValuesCode<code valuecode> { code ValuesCode = valuecode; }
|
||||
|
||||
// Helpers for defining marshalling information.
|
||||
|
||||
class DefaultAnyOf<list<Option> options, string default = "false", string separator = " || "> {
|
||||
code DefaultValue = !foldl(default, options, accumulator, option,
|
||||
!strconcat(accumulator, separator, !cast<string>(option.KeyPath)));
|
||||
class ImpliedByAnyOf<list<Option> options, code value = "true"> {
|
||||
code ImpliedCheck = !foldl("false", options, accumulator, option,
|
||||
!strconcat(accumulator, " || ", !cast<string>(option.KeyPath)));
|
||||
code ImpliedValue = value;
|
||||
}
|
||||
|
||||
class MarshallingInfo<code keypath, code defaultvalue> {
|
||||
@ -159,21 +162,21 @@ class MarshallingInfo<code keypath, code defaultvalue> {
|
||||
class MarshallingInfoString<code keypath, code defaultvalue>
|
||||
: MarshallingInfo<keypath, defaultvalue> {}
|
||||
|
||||
class MarshallingInfoFlag<code keypath, DefaultAnyOf defaults = DefaultAnyOf<[]>>
|
||||
: MarshallingInfo<keypath, defaults.DefaultValue> {
|
||||
class MarshallingInfoFlag<code keypath, code defaultvalue = "false">
|
||||
: MarshallingInfo<keypath, defaultvalue> {
|
||||
code Normalizer = "normalizeSimpleFlag";
|
||||
code Denormalizer = "denormalizeSimpleFlag";
|
||||
}
|
||||
|
||||
class MarshallingInfoBitfieldFlag<code keypath, code value>
|
||||
: MarshallingInfoFlag<keypath, DefaultAnyOf<[], "0u", " | ">> {
|
||||
: MarshallingInfoFlag<keypath, "0u"> {
|
||||
code Normalizer = "(normalizeFlagToValue<unsigned, "#value#">)";
|
||||
code ValueMerger = "mergeMaskValue";
|
||||
code ValueExtractor = "(extractMaskValue<unsigned, decltype("#value#"), "#value#">)";
|
||||
}
|
||||
|
||||
class MarshallingInfoBooleanFlag<code keypath, code defaultvalue, Option negopt>
|
||||
: MarshallingInfoFlag<keypath, DefaultAnyOf<[], defaultvalue>> {
|
||||
: MarshallingInfoFlag<keypath, defaultvalue> {
|
||||
bit ShouldAlwaysEmit = 1;
|
||||
string MarshallingInfoKind = "BooleanFlag";
|
||||
code Normalizer = "normalizeBooleanFlag";
|
||||
|
@ -11,15 +11,17 @@
|
||||
struct OptionWithMarshallingInfo {
|
||||
const char *Name;
|
||||
const char *KeyPath;
|
||||
const char *DefaultValue;
|
||||
const char *ImpliedCheck;
|
||||
const char *ImpliedValue;
|
||||
};
|
||||
|
||||
static const OptionWithMarshallingInfo MarshallingTable[] = {
|
||||
#define OPTION_WITH_MARSHALLING( \
|
||||
PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
|
||||
HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, \
|
||||
NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
|
||||
{NAME, #KEYPATH, #DEFAULT_VALUE},
|
||||
IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, \
|
||||
TABLE_INDEX) \
|
||||
{NAME, #KEYPATH, #IMPLIED_CHECK, #IMPLIED_VALUE},
|
||||
#include "Opts.inc"
|
||||
#undef OPTION_WITH_MARSHALLING
|
||||
};
|
||||
@ -38,10 +40,16 @@ TEST(OptionMarshalling, EmittedSpecifiedKeyPath) {
|
||||
ASSERT_STREQ(MarshallingTable[3].KeyPath, "MarshalledFlagA");
|
||||
}
|
||||
|
||||
TEST(OptionMarshalling, DefaultAnyOfConstructedDisjunctionOfKeypaths) {
|
||||
ASSERT_STREQ(MarshallingTable[0].DefaultValue, "false");
|
||||
ASSERT_STREQ(MarshallingTable[1].DefaultValue, "false || MarshalledFlagD");
|
||||
ASSERT_STREQ(MarshallingTable[2].DefaultValue, "false || MarshalledFlagD");
|
||||
ASSERT_STREQ(MarshallingTable[3].DefaultValue,
|
||||
TEST(OptionMarshalling, ImpliedCheckContainsDisjunctionOfKeypaths) {
|
||||
ASSERT_STREQ(MarshallingTable[0].ImpliedCheck, "false");
|
||||
|
||||
ASSERT_STREQ(MarshallingTable[1].ImpliedCheck, "false || MarshalledFlagD");
|
||||
ASSERT_STREQ(MarshallingTable[1].ImpliedValue, "true");
|
||||
|
||||
ASSERT_STREQ(MarshallingTable[2].ImpliedCheck, "false || MarshalledFlagD");
|
||||
ASSERT_STREQ(MarshallingTable[2].ImpliedValue, "true");
|
||||
|
||||
ASSERT_STREQ(MarshallingTable[3].ImpliedCheck,
|
||||
"false || MarshalledFlagC || MarshalledFlagB");
|
||||
ASSERT_STREQ(MarshallingTable[3].ImpliedValue, "true");
|
||||
}
|
||||
|
@ -46,10 +46,13 @@ def Blurmpq_eq : Flag<["--"], "blurmp=">;
|
||||
def DashDash : Option<["--"], "", KIND_REMAINING_ARGS>;
|
||||
|
||||
def marshalled_flag_d : Flag<["-"], "marshalled-flag-d">,
|
||||
MarshallingInfoFlag<"MarshalledFlagD", DefaultAnyOf<[]>>;
|
||||
MarshallingInfoFlag<"MarshalledFlagD">;
|
||||
def marshalled_flag_c : Flag<["-"], "marshalled-flag-c">,
|
||||
MarshallingInfoFlag<"MarshalledFlagC", DefaultAnyOf<[marshalled_flag_d]>>;
|
||||
MarshallingInfoFlag<"MarshalledFlagC">,
|
||||
ImpliedByAnyOf<[marshalled_flag_d], "true">;
|
||||
def marshalled_flag_b : Flag<["-"], "marshalled-flag-b">,
|
||||
MarshallingInfoFlag<"MarshalledFlagB", DefaultAnyOf<[marshalled_flag_d]>>;
|
||||
MarshallingInfoFlag<"MarshalledFlagB">,
|
||||
ImpliedByAnyOf<[marshalled_flag_d], "true">;
|
||||
def marshalled_flag_a : Flag<["-"], "marshalled-flag-a">,
|
||||
MarshallingInfoFlag<"MarshalledFlagA", DefaultAnyOf<[marshalled_flag_c, marshalled_flag_b]>>;
|
||||
MarshallingInfoFlag<"MarshalledFlagA">,
|
||||
ImpliedByAnyOf<[marshalled_flag_c, marshalled_flag_b]>;
|
||||
|
@ -71,6 +71,8 @@ public:
|
||||
StringRef KeyPath;
|
||||
StringRef DefaultValue;
|
||||
StringRef NormalizedValuesScope;
|
||||
StringRef ImpliedCheck;
|
||||
StringRef ImpliedValue;
|
||||
StringRef Normalizer;
|
||||
StringRef Denormalizer;
|
||||
StringRef ValueMerger;
|
||||
@ -113,6 +115,10 @@ struct SimpleEnumValueTable {
|
||||
OS << ", ";
|
||||
emitScopedNormalizedValue(OS, DefaultValue);
|
||||
OS << ", ";
|
||||
OS << ImpliedCheck;
|
||||
OS << ", ";
|
||||
emitScopedNormalizedValue(OS, ImpliedValue);
|
||||
OS << ", ";
|
||||
OS << Normalizer;
|
||||
OS << ", ";
|
||||
OS << Denormalizer;
|
||||
@ -188,6 +194,9 @@ static MarshallingInfo::Ptr createMarshallingInfo(const Record &R) {
|
||||
Ret->KeyPath = R.getValueAsString("KeyPath");
|
||||
Ret->DefaultValue = R.getValueAsString("DefaultValue");
|
||||
Ret->NormalizedValuesScope = R.getValueAsString("NormalizedValuesScope");
|
||||
Ret->ImpliedCheck = R.getValueAsString("ImpliedCheck");
|
||||
Ret->ImpliedValue =
|
||||
R.getValueAsOptionalString("ImpliedValue").getValueOr(Ret->DefaultValue);
|
||||
|
||||
Ret->Normalizer = R.getValueAsString("Normalizer");
|
||||
Ret->Denormalizer = R.getValueAsString("Denormalizer");
|
||||
|
Loading…
x
Reference in New Issue
Block a user