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 = ?;
|
string MarshallingInfoKind = ?;
|
||||||
code KeyPath = ?;
|
code KeyPath = ?;
|
||||||
code DefaultValue = ?;
|
code DefaultValue = ?;
|
||||||
|
code ImpliedValue = ?;
|
||||||
|
code ImpliedCheck = "false";
|
||||||
bit ShouldAlwaysEmit = false;
|
bit ShouldAlwaysEmit = false;
|
||||||
code NormalizerRetTy = ?;
|
code NormalizerRetTy = ?;
|
||||||
code NormalizedValuesScope = "";
|
code NormalizedValuesScope = "";
|
||||||
@ -145,9 +147,10 @@ class ValuesCode<code valuecode> { code ValuesCode = valuecode; }
|
|||||||
|
|
||||||
// Helpers for defining marshalling information.
|
// Helpers for defining marshalling information.
|
||||||
|
|
||||||
class DefaultAnyOf<list<Option> options, string default = "false", string separator = " || "> {
|
class ImpliedByAnyOf<list<Option> options, code value = "true"> {
|
||||||
code DefaultValue = !foldl(default, options, accumulator, option,
|
code ImpliedCheck = !foldl("false", options, accumulator, option,
|
||||||
!strconcat(accumulator, separator, !cast<string>(option.KeyPath)));
|
!strconcat(accumulator, " || ", !cast<string>(option.KeyPath)));
|
||||||
|
code ImpliedValue = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
class MarshallingInfo<code keypath, code defaultvalue> {
|
class MarshallingInfo<code keypath, code defaultvalue> {
|
||||||
@ -159,21 +162,21 @@ class MarshallingInfo<code keypath, code defaultvalue> {
|
|||||||
class MarshallingInfoString<code keypath, code defaultvalue>
|
class MarshallingInfoString<code keypath, code defaultvalue>
|
||||||
: MarshallingInfo<keypath, defaultvalue> {}
|
: MarshallingInfo<keypath, defaultvalue> {}
|
||||||
|
|
||||||
class MarshallingInfoFlag<code keypath, DefaultAnyOf defaults = DefaultAnyOf<[]>>
|
class MarshallingInfoFlag<code keypath, code defaultvalue = "false">
|
||||||
: MarshallingInfo<keypath, defaults.DefaultValue> {
|
: MarshallingInfo<keypath, defaultvalue> {
|
||||||
code Normalizer = "normalizeSimpleFlag";
|
code Normalizer = "normalizeSimpleFlag";
|
||||||
code Denormalizer = "denormalizeSimpleFlag";
|
code Denormalizer = "denormalizeSimpleFlag";
|
||||||
}
|
}
|
||||||
|
|
||||||
class MarshallingInfoBitfieldFlag<code keypath, code value>
|
class MarshallingInfoBitfieldFlag<code keypath, code value>
|
||||||
: MarshallingInfoFlag<keypath, DefaultAnyOf<[], "0u", " | ">> {
|
: MarshallingInfoFlag<keypath, "0u"> {
|
||||||
code Normalizer = "(normalizeFlagToValue<unsigned, "#value#">)";
|
code Normalizer = "(normalizeFlagToValue<unsigned, "#value#">)";
|
||||||
code ValueMerger = "mergeMaskValue";
|
code ValueMerger = "mergeMaskValue";
|
||||||
code ValueExtractor = "(extractMaskValue<unsigned, decltype("#value#"), "#value#">)";
|
code ValueExtractor = "(extractMaskValue<unsigned, decltype("#value#"), "#value#">)";
|
||||||
}
|
}
|
||||||
|
|
||||||
class MarshallingInfoBooleanFlag<code keypath, code defaultvalue, Option negopt>
|
class MarshallingInfoBooleanFlag<code keypath, code defaultvalue, Option negopt>
|
||||||
: MarshallingInfoFlag<keypath, DefaultAnyOf<[], defaultvalue>> {
|
: MarshallingInfoFlag<keypath, defaultvalue> {
|
||||||
bit ShouldAlwaysEmit = 1;
|
bit ShouldAlwaysEmit = 1;
|
||||||
string MarshallingInfoKind = "BooleanFlag";
|
string MarshallingInfoKind = "BooleanFlag";
|
||||||
code Normalizer = "normalizeBooleanFlag";
|
code Normalizer = "normalizeBooleanFlag";
|
||||||
|
@ -11,15 +11,17 @@
|
|||||||
struct OptionWithMarshallingInfo {
|
struct OptionWithMarshallingInfo {
|
||||||
const char *Name;
|
const char *Name;
|
||||||
const char *KeyPath;
|
const char *KeyPath;
|
||||||
const char *DefaultValue;
|
const char *ImpliedCheck;
|
||||||
|
const char *ImpliedValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const OptionWithMarshallingInfo MarshallingTable[] = {
|
static const OptionWithMarshallingInfo MarshallingTable[] = {
|
||||||
#define OPTION_WITH_MARSHALLING( \
|
#define OPTION_WITH_MARSHALLING( \
|
||||||
PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
|
PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
|
||||||
HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, \
|
HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, \
|
||||||
NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
|
IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, \
|
||||||
{NAME, #KEYPATH, #DEFAULT_VALUE},
|
TABLE_INDEX) \
|
||||||
|
{NAME, #KEYPATH, #IMPLIED_CHECK, #IMPLIED_VALUE},
|
||||||
#include "Opts.inc"
|
#include "Opts.inc"
|
||||||
#undef OPTION_WITH_MARSHALLING
|
#undef OPTION_WITH_MARSHALLING
|
||||||
};
|
};
|
||||||
@ -38,10 +40,16 @@ TEST(OptionMarshalling, EmittedSpecifiedKeyPath) {
|
|||||||
ASSERT_STREQ(MarshallingTable[3].KeyPath, "MarshalledFlagA");
|
ASSERT_STREQ(MarshallingTable[3].KeyPath, "MarshalledFlagA");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(OptionMarshalling, DefaultAnyOfConstructedDisjunctionOfKeypaths) {
|
TEST(OptionMarshalling, ImpliedCheckContainsDisjunctionOfKeypaths) {
|
||||||
ASSERT_STREQ(MarshallingTable[0].DefaultValue, "false");
|
ASSERT_STREQ(MarshallingTable[0].ImpliedCheck, "false");
|
||||||
ASSERT_STREQ(MarshallingTable[1].DefaultValue, "false || MarshalledFlagD");
|
|
||||||
ASSERT_STREQ(MarshallingTable[2].DefaultValue, "false || MarshalledFlagD");
|
ASSERT_STREQ(MarshallingTable[1].ImpliedCheck, "false || MarshalledFlagD");
|
||||||
ASSERT_STREQ(MarshallingTable[3].DefaultValue,
|
ASSERT_STREQ(MarshallingTable[1].ImpliedValue, "true");
|
||||||
"false || MarshalledFlagC || MarshalledFlagB");
|
|
||||||
|
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 DashDash : Option<["--"], "", KIND_REMAINING_ARGS>;
|
||||||
|
|
||||||
def marshalled_flag_d : Flag<["-"], "marshalled-flag-d">,
|
def marshalled_flag_d : Flag<["-"], "marshalled-flag-d">,
|
||||||
MarshallingInfoFlag<"MarshalledFlagD", DefaultAnyOf<[]>>;
|
MarshallingInfoFlag<"MarshalledFlagD">;
|
||||||
def marshalled_flag_c : Flag<["-"], "marshalled-flag-c">,
|
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">,
|
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">,
|
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 KeyPath;
|
||||||
StringRef DefaultValue;
|
StringRef DefaultValue;
|
||||||
StringRef NormalizedValuesScope;
|
StringRef NormalizedValuesScope;
|
||||||
|
StringRef ImpliedCheck;
|
||||||
|
StringRef ImpliedValue;
|
||||||
StringRef Normalizer;
|
StringRef Normalizer;
|
||||||
StringRef Denormalizer;
|
StringRef Denormalizer;
|
||||||
StringRef ValueMerger;
|
StringRef ValueMerger;
|
||||||
@ -113,6 +115,10 @@ struct SimpleEnumValueTable {
|
|||||||
OS << ", ";
|
OS << ", ";
|
||||||
emitScopedNormalizedValue(OS, DefaultValue);
|
emitScopedNormalizedValue(OS, DefaultValue);
|
||||||
OS << ", ";
|
OS << ", ";
|
||||||
|
OS << ImpliedCheck;
|
||||||
|
OS << ", ";
|
||||||
|
emitScopedNormalizedValue(OS, ImpliedValue);
|
||||||
|
OS << ", ";
|
||||||
OS << Normalizer;
|
OS << Normalizer;
|
||||||
OS << ", ";
|
OS << ", ";
|
||||||
OS << Denormalizer;
|
OS << Denormalizer;
|
||||||
@ -188,6 +194,9 @@ static MarshallingInfo::Ptr createMarshallingInfo(const Record &R) {
|
|||||||
Ret->KeyPath = R.getValueAsString("KeyPath");
|
Ret->KeyPath = R.getValueAsString("KeyPath");
|
||||||
Ret->DefaultValue = R.getValueAsString("DefaultValue");
|
Ret->DefaultValue = R.getValueAsString("DefaultValue");
|
||||||
Ret->NormalizedValuesScope = R.getValueAsString("NormalizedValuesScope");
|
Ret->NormalizedValuesScope = R.getValueAsString("NormalizedValuesScope");
|
||||||
|
Ret->ImpliedCheck = R.getValueAsString("ImpliedCheck");
|
||||||
|
Ret->ImpliedValue =
|
||||||
|
R.getValueAsOptionalString("ImpliedValue").getValueOr(Ret->DefaultValue);
|
||||||
|
|
||||||
Ret->Normalizer = R.getValueAsString("Normalizer");
|
Ret->Normalizer = R.getValueAsString("Normalizer");
|
||||||
Ret->Denormalizer = R.getValueAsString("Denormalizer");
|
Ret->Denormalizer = R.getValueAsString("Denormalizer");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user