diff --git a/include/llvm/Option/OptParser.td b/include/llvm/Option/OptParser.td index 947abc46b03..94437ef212c 100644 --- a/include/llvm/Option/OptParser.td +++ b/include/llvm/Option/OptParser.td @@ -146,58 +146,67 @@ class ValuesCode { code ValuesCode = valuecode; } // Helpers for defining marshalling information. +class KeyPathAndMacro { + code KeyPath = !strconcat(key_path_prefix, key_path_base); + code MacroPrefix = macro_prefix; +} + +def EmptyKPM : KeyPathAndMacro<"", "">; + class ImpliedByAnyOf options, code value = "true"> { code ImpliedCheck = !foldl("false", options, accumulator, option, !strconcat(accumulator, " || ", option.KeyPath)); code ImpliedValue = value; } -class MarshallingInfo { - code KeyPath = keypath; +class MarshallingInfo { + code KeyPath = kpm.KeyPath; + code MacroPrefix = kpm.MacroPrefix; code DefaultValue = defaultvalue; } -class MarshallingInfoString - : MarshallingInfo { +class MarshallingInfoString + : MarshallingInfo { code Normalizer = "normalizeString"; code Denormalizer = "denormalizeString"; } -class MarshallingInfoStringInt - : MarshallingInfo { +class MarshallingInfoStringInt + : MarshallingInfo { code Normalizer = "normalizeStringIntegral<"#type#">"; code Denormalizer = "denormalizeString"; } -class MarshallingInfoStringVector - : MarshallingInfo({})"> { +class MarshallingInfoStringVector + : MarshallingInfo({})"> { code Normalizer = "normalizeStringVector"; code Denormalizer = "denormalizeStringVector"; } -class MarshallingInfoFlag - : MarshallingInfo { +class MarshallingInfoFlag + : MarshallingInfo { code Normalizer = "normalizeSimpleFlag"; code Denormalizer = "denormalizeSimpleFlag"; } -class MarshallingInfoNegativeFlag - : MarshallingInfo { +class MarshallingInfoNegativeFlag + : MarshallingInfo { code Normalizer = "normalizeSimpleNegativeFlag"; code Denormalizer = "denormalizeSimpleFlag"; } -class MarshallingInfoBitfieldFlag - : MarshallingInfoFlag { +class MarshallingInfoBitfieldFlag + : MarshallingInfoFlag { code Normalizer = "makeFlagToValueNormalizer("#value#")"; code ValueMerger = "mergeMaskValue"; code ValueExtractor = "(extractMaskValue)"; } // Marshalling info for booleans. Applied to the flag setting keypath to false. -class MarshallingInfoBooleanFlag - : MarshallingInfoFlag { + : MarshallingInfoFlag { code Normalizer = "makeBooleanOptionNormalizer("#value#", "#other_value#", OPT_"#other_name#")"; code Denormalizer = "makeBooleanOptionDenormalizer("#value#")"; } diff --git a/unittests/Option/OptionMarshallingTest.cpp b/unittests/Option/OptionMarshallingTest.cpp index 3310cbbb749..85f0d86a869 100644 --- a/unittests/Option/OptionMarshallingTest.cpp +++ b/unittests/Option/OptionMarshallingTest.cpp @@ -34,22 +34,22 @@ TEST(OptionMarshalling, EmittedOrderSameAsDefinitionOrder) { } TEST(OptionMarshalling, EmittedSpecifiedKeyPath) { - ASSERT_STREQ(MarshallingTable[0].KeyPath, "MarshalledFlagD"); - ASSERT_STREQ(MarshallingTable[1].KeyPath, "MarshalledFlagC"); - ASSERT_STREQ(MarshallingTable[2].KeyPath, "MarshalledFlagB"); - ASSERT_STREQ(MarshallingTable[3].KeyPath, "MarshalledFlagA"); + ASSERT_STREQ(MarshallingTable[0].KeyPath, "X->MarshalledFlagD"); + ASSERT_STREQ(MarshallingTable[1].KeyPath, "X->MarshalledFlagC"); + ASSERT_STREQ(MarshallingTable[2].KeyPath, "X->MarshalledFlagB"); + ASSERT_STREQ(MarshallingTable[3].KeyPath, "X->MarshalledFlagA"); } TEST(OptionMarshalling, ImpliedCheckContainsDisjunctionOfKeypaths) { ASSERT_STREQ(MarshallingTable[0].ImpliedCheck, "false"); - ASSERT_STREQ(MarshallingTable[1].ImpliedCheck, "false || MarshalledFlagD"); + ASSERT_STREQ(MarshallingTable[1].ImpliedCheck, "false || X->MarshalledFlagD"); ASSERT_STREQ(MarshallingTable[1].ImpliedValue, "true"); - ASSERT_STREQ(MarshallingTable[2].ImpliedCheck, "false || MarshalledFlagD"); + ASSERT_STREQ(MarshallingTable[2].ImpliedCheck, "false || X->MarshalledFlagD"); ASSERT_STREQ(MarshallingTable[2].ImpliedValue, "true"); ASSERT_STREQ(MarshallingTable[3].ImpliedCheck, - "false || MarshalledFlagC || MarshalledFlagB"); + "false || X->MarshalledFlagC || X->MarshalledFlagB"); ASSERT_STREQ(MarshallingTable[3].ImpliedValue, "true"); } diff --git a/unittests/Option/Opts.td b/unittests/Option/Opts.td index 01275a96420..225c0fad8a2 100644 --- a/unittests/Option/Opts.td +++ b/unittests/Option/Opts.td @@ -45,14 +45,16 @@ def Blurmpq_eq : Flag<["--"], "blurmp=">; def DashDash : Option<["--"], "", KIND_REMAINING_ARGS>; +class XOpts : KeyPathAndMacro<"X->", base> {} + def marshalled_flag_d : Flag<["-"], "marshalled-flag-d">, - MarshallingInfoFlag<"MarshalledFlagD">; + MarshallingInfoFlag>; def marshalled_flag_c : Flag<["-"], "marshalled-flag-c">, - MarshallingInfoFlag<"MarshalledFlagC">, + MarshallingInfoFlag>, ImpliedByAnyOf<[marshalled_flag_d], "true">; def marshalled_flag_b : Flag<["-"], "marshalled-flag-b">, - MarshallingInfoFlag<"MarshalledFlagB">, + MarshallingInfoFlag>, ImpliedByAnyOf<[marshalled_flag_d], "true">; def marshalled_flag_a : Flag<["-"], "marshalled-flag-a">, - MarshallingInfoFlag<"MarshalledFlagA">, + MarshallingInfoFlag>, ImpliedByAnyOf<[marshalled_flag_c, marshalled_flag_b]>;