@@ -1137,21 +1137,28 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
1137
1137
1138
1138
Opts.WarnOnEditorPlaceholder |= Args.hasArg (OPT_warn_on_editor_placeholder);
1139
1139
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 );
1155
1162
1156
1163
if (auto A = Args.getLastArg (OPT_enable_target_os_checking,
1157
1164
OPT_disable_target_os_checking)) {
@@ -1227,17 +1234,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
1227
1234
Opts.AvailabilityMacros .push_back (A->getValue ());
1228
1235
}
1229
1236
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
-
1241
1237
for (const Arg *A : Args.filtered (OPT_D)) {
1242
1238
Opts.addCustomConditionalCompilationFlag (A->getValue ());
1243
1239
}
@@ -1737,71 +1733,18 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
1737
1733
if (const Arg *A = Args.getLastArg (OPT_debug_requirement_machine))
1738
1734
Opts.DebugRequirementMachine = A->getValue ();
1739
1735
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 );
1805
1748
1806
1749
if (Args.hasArg (OPT_disable_requirement_machine_concrete_contraction))
1807
1750
Opts.EnableRequirementMachineConcreteContraction = false ;
@@ -1848,7 +1791,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
1848
1791
HadError = true ;
1849
1792
}
1850
1793
1851
- if (!FrontendOpts.InputsAndOutputs .isWholeModule () && FrontendOptions::doesActionGenerateSIL (FrontendOpts.RequestedAction )) {
1794
+ if (!FrontendOpts.InputsAndOutputs .isWholeModule () &&
1795
+ FrontendOptions::doesActionGenerateSIL (FrontendOpts.RequestedAction )) {
1852
1796
Diags.diagnose (SourceLoc (), diag::wmo_with_embedded);
1853
1797
HadError = true ;
1854
1798
}
0 commit comments