mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Remove early returns in ParseLangArgs
Several places in language option parsing return early after diagnosing an error when they could instead continue parsing and discover addtional errors to diagnose. Change these to set an error flag instead. OPT_package_description_version still has an early return on the theory that, if you’re using a too-old compiler to parse a Package.swift file, you’re probably confused about the Swift compiler version you’re using and further errors may be for arguments that would be accepted by a newer compiler.
This commit is contained in:
@@ -200,6 +200,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||
DiagnosticEngine &Diags,
|
||||
const FrontendOptions &FrontendOpts) {
|
||||
using namespace options;
|
||||
bool HadError = false;
|
||||
|
||||
if (auto A = Args.getLastArg(OPT_swift_version)) {
|
||||
auto vers = version::Version::parseVersionString(
|
||||
@@ -274,10 +275,10 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||
if (StringRef(A->getValue()).getAsInteger(10, limit)) {
|
||||
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
|
||||
A->getAsString(Args), A->getValue());
|
||||
return true;
|
||||
HadError = true;
|
||||
} else {
|
||||
Opts.TypoCorrectionLimit = limit;
|
||||
}
|
||||
|
||||
Opts.TypoCorrectionLimit = limit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,10 +335,10 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||
if (StringRef(A->getValue()).getAsInteger(10, attempt)) {
|
||||
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
|
||||
A->getAsString(Args), A->getValue());
|
||||
return true;
|
||||
HadError = true;
|
||||
} else {
|
||||
Opts.DebugConstraintSolverAttempt = attempt;
|
||||
}
|
||||
|
||||
Opts.DebugConstraintSolverAttempt = attempt;
|
||||
}
|
||||
|
||||
for (const Arg *A : Args.filtered(OPT_debug_constraints_on_line)) {
|
||||
@@ -345,9 +346,10 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||
if (StringRef(A->getValue()).getAsInteger(10, line)) {
|
||||
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
|
||||
A->getAsString(Args), A->getValue());
|
||||
return true;
|
||||
HadError = true;
|
||||
} else {
|
||||
Opts.DebugConstraintSolverOnLines.push_back(line);
|
||||
}
|
||||
Opts.DebugConstraintSolverOnLines.push_back(line);
|
||||
}
|
||||
llvm::sort(Opts.DebugConstraintSolverOnLines);
|
||||
|
||||
@@ -368,10 +370,10 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||
if (StringRef(A->getValue()).getAsInteger(10, threshold)) {
|
||||
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
|
||||
A->getAsString(Args), A->getValue());
|
||||
return true;
|
||||
HadError = true;
|
||||
} else {
|
||||
Opts.SolverMemoryThreshold = threshold;
|
||||
}
|
||||
|
||||
Opts.SolverMemoryThreshold = threshold;
|
||||
}
|
||||
|
||||
if (const Arg *A = Args.getLastArg(OPT_solver_shrink_unsolved_threshold)) {
|
||||
@@ -379,10 +381,10 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||
if (StringRef(A->getValue()).getAsInteger(10, threshold)) {
|
||||
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
|
||||
A->getAsString(Args), A->getValue());
|
||||
return true;
|
||||
HadError = true;
|
||||
} else {
|
||||
Opts.SolverShrinkUnsolvedThreshold = threshold;
|
||||
}
|
||||
|
||||
Opts.SolverShrinkUnsolvedThreshold = threshold;
|
||||
}
|
||||
|
||||
if (Args.getLastArg(OPT_solver_disable_shrink))
|
||||
@@ -393,10 +395,10 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||
if (StringRef(A->getValue()).getAsInteger(10, threshold)) {
|
||||
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
|
||||
A->getAsString(Args), A->getValue());
|
||||
return true;
|
||||
HadError = true;
|
||||
} else {
|
||||
Opts.MaxCircularityDepth = threshold;
|
||||
}
|
||||
|
||||
Opts.MaxCircularityDepth = threshold;
|
||||
}
|
||||
|
||||
for (const Arg *A : Args.filtered(OPT_D)) {
|
||||
@@ -482,7 +484,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||
Diags.diagnose(SourceLoc(), diag::error_unsupported_target_os, TargetArgOS);
|
||||
}
|
||||
|
||||
return UnsupportedOS || UnsupportedArch;
|
||||
return HadError || UnsupportedOS || UnsupportedArch;
|
||||
}
|
||||
|
||||
static bool ParseClangImporterArgs(ClangImporterOptions &Opts,
|
||||
|
||||
Reference in New Issue
Block a user