@@ -1137,21 +1137,28 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
11371137
11381138 Opts.WarnOnEditorPlaceholder |= Args.hasArg (OPT_warn_on_editor_placeholder);
11391139
1140- if (auto A = Args.getLastArg (OPT_disable_typo_correction,
1141- OPT_typo_correction_limit)) {
1142- if (A->getOption ().matches (OPT_disable_typo_correction))
1143- Opts.TypoCorrectionLimit = 0 ;
1144- else {
1145- unsigned limit;
1146- if (StringRef (A->getValue ()).getAsInteger (10 , limit)) {
1147- Diags.diagnose (SourceLoc (), diag::error_invalid_arg_value,
1148- A->getAsString (Args), A->getValue ());
1149- HadError = true ;
1150- } else {
1151- Opts.TypoCorrectionLimit = limit;
1152- }
1153- }
1154- }
1140+ auto setUnsignedIntegerArgument =
1141+ [&Args, &Diags, &HadError](options::ID optionID, unsigned &valueToSet) {
1142+ if (const Arg *A = Args.getLastArg (optionID)) {
1143+ unsigned attempt;
1144+ if (StringRef (A->getValue ()).getAsInteger (/* radix*/ 10 , attempt)) {
1145+ Diags.diagnose (SourceLoc (), diag::error_invalid_arg_value,
1146+ A->getAsString (Args), A->getValue ());
1147+ HadError = true ;
1148+ } else {
1149+ valueToSet = attempt;
1150+ }
1151+ }
1152+ };
1153+
1154+ setUnsignedIntegerArgument (OPT_typo_correction_limit,
1155+ Opts.TypoCorrectionLimit );
1156+
1157+ if (Args.hasArg (OPT_disable_typo_correction))
1158+ Opts.TypoCorrectionLimit = 0 ;
1159+
1160+ setUnsignedIntegerArgument (OPT_value_recursion_threshold,
1161+ Opts.MaxCircularityDepth );
11551162
11561163 if (auto A = Args.getLastArg (OPT_enable_target_os_checking,
11571164 OPT_disable_target_os_checking)) {
@@ -1227,17 +1234,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
12271234 Opts.AvailabilityMacros .push_back (A->getValue ());
12281235 }
12291236
1230- if (const Arg *A = Args.getLastArg (OPT_value_recursion_threshold)) {
1231- unsigned threshold;
1232- if (StringRef (A->getValue ()).getAsInteger (10 , threshold)) {
1233- Diags.diagnose (SourceLoc (), diag::error_invalid_arg_value,
1234- A->getAsString (Args), A->getValue ());
1235- HadError = true ;
1236- } else {
1237- Opts.MaxCircularityDepth = threshold;
1238- }
1239- }
1240-
12411237 for (const Arg *A : Args.filtered (OPT_D)) {
12421238 Opts.addCustomConditionalCompilationFlag (A->getValue ());
12431239 }
@@ -1737,71 +1733,18 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
17371733 if (const Arg *A = Args.getLastArg (OPT_debug_requirement_machine))
17381734 Opts.DebugRequirementMachine = A->getValue ();
17391735
1740- if (const Arg *A = Args.getLastArg (OPT_requirement_machine_max_rule_count)) {
1741- unsigned limit;
1742- if (StringRef (A->getValue ()).getAsInteger (10 , limit)) {
1743- Diags.diagnose (SourceLoc (), diag::error_invalid_arg_value,
1744- A->getAsString (Args), A->getValue ());
1745- HadError = true ;
1746- } else {
1747- Opts.RequirementMachineMaxRuleCount = limit;
1748- }
1749- }
1750-
1751- if (const Arg *A = Args.getLastArg (OPT_requirement_machine_max_rule_length)) {
1752- unsigned limit;
1753- if (StringRef (A->getValue ()).getAsInteger (10 , limit)) {
1754- Diags.diagnose (SourceLoc (), diag::error_invalid_arg_value,
1755- A->getAsString (Args), A->getValue ());
1756- HadError = true ;
1757- } else {
1758- Opts.RequirementMachineMaxRuleLength = limit;
1759- }
1760- }
1761-
1762- if (const Arg *A = Args.getLastArg (OPT_requirement_machine_max_concrete_nesting)) {
1763- unsigned limit;
1764- if (StringRef (A->getValue ()).getAsInteger (10 , limit)) {
1765- Diags.diagnose (SourceLoc (), diag::error_invalid_arg_value,
1766- A->getAsString (Args), A->getValue ());
1767- HadError = true ;
1768- } else {
1769- Opts.RequirementMachineMaxConcreteNesting = limit;
1770- }
1771- }
1772-
1773- if (const Arg *A = Args.getLastArg (OPT_requirement_machine_max_concrete_size)) {
1774- unsigned limit;
1775- if (StringRef (A->getValue ()).getAsInteger (10 , limit)) {
1776- Diags.diagnose (SourceLoc (), diag::error_invalid_arg_value,
1777- A->getAsString (Args), A->getValue ());
1778- HadError = true ;
1779- } else {
1780- Opts.RequirementMachineMaxConcreteSize = limit;
1781- }
1782- }
1783-
1784- if (const Arg *A = Args.getLastArg (OPT_requirement_machine_max_type_differences)) {
1785- unsigned limit;
1786- if (StringRef (A->getValue ()).getAsInteger (10 , limit)) {
1787- Diags.diagnose (SourceLoc (), diag::error_invalid_arg_value,
1788- A->getAsString (Args), A->getValue ());
1789- HadError = true ;
1790- } else {
1791- Opts.RequirementMachineMaxTypeDifferences = limit;
1792- }
1793- }
1794-
1795- if (const Arg *A = Args.getLastArg (OPT_requirement_machine_max_split_concrete_equiv_class_attempts)) {
1796- unsigned limit;
1797- if (StringRef (A->getValue ()).getAsInteger (10 , limit)) {
1798- Diags.diagnose (SourceLoc (), diag::error_invalid_arg_value,
1799- A->getAsString (Args), A->getValue ());
1800- HadError = true ;
1801- } else {
1802- Opts.RequirementMachineMaxSplitConcreteEquivClassAttempts = limit;
1803- }
1804- }
1736+ setUnsignedIntegerArgument (OPT_requirement_machine_max_rule_count,
1737+ Opts.RequirementMachineMaxRuleCount );
1738+ setUnsignedIntegerArgument (OPT_requirement_machine_max_rule_length,
1739+ Opts.RequirementMachineMaxRuleLength );
1740+ setUnsignedIntegerArgument (OPT_requirement_machine_max_concrete_nesting,
1741+ Opts.RequirementMachineMaxConcreteNesting );
1742+ setUnsignedIntegerArgument (OPT_requirement_machine_max_concrete_size,
1743+ Opts.RequirementMachineMaxConcreteSize );
1744+ setUnsignedIntegerArgument (OPT_requirement_machine_max_type_differences,
1745+ Opts.RequirementMachineMaxTypeDifferences );
1746+ setUnsignedIntegerArgument (OPT_requirement_machine_max_split_concrete_equiv_class_attempts,
1747+ Opts.RequirementMachineMaxSplitConcreteEquivClassAttempts );
18051748
18061749 if (Args.hasArg (OPT_disable_requirement_machine_concrete_contraction))
18071750 Opts.EnableRequirementMachineConcreteContraction = false ;
@@ -1848,7 +1791,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
18481791 HadError = true ;
18491792 }
18501793
1851- if (!FrontendOpts.InputsAndOutputs .isWholeModule () && FrontendOptions::doesActionGenerateSIL (FrontendOpts.RequestedAction )) {
1794+ if (!FrontendOpts.InputsAndOutputs .isWholeModule () &&
1795+ FrontendOptions::doesActionGenerateSIL (FrontendOpts.RequestedAction )) {
18521796 Diags.diagnose (SourceLoc (), diag::wmo_with_embedded);
18531797 HadError = true ;
18541798 }
0 commit comments