mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Constify DiagnosticState::determineBehavior
Split out the state mutation into a new `updateFor` function that we call for diagnostic emission, allowing `DiagnosticTransaction::hasErrors` to query the behavior without mutating any state.
This commit is contained in:
@@ -618,7 +618,10 @@ namespace swift {
|
|||||||
|
|
||||||
/// Figure out the Behavior for the given diagnostic, taking current
|
/// Figure out the Behavior for the given diagnostic, taking current
|
||||||
/// state such as fatality into account.
|
/// state such as fatality into account.
|
||||||
DiagnosticBehavior determineBehavior(const Diagnostic &diag);
|
DiagnosticBehavior determineBehavior(const Diagnostic &diag) const;
|
||||||
|
|
||||||
|
/// Updates the diagnostic state for a diagnostic to emit.
|
||||||
|
void updateFor(DiagnosticBehavior behavior);
|
||||||
|
|
||||||
bool hadAnyError() const { return anyErrorOccurred; }
|
bool hadAnyError() const { return anyErrorOccurred; }
|
||||||
bool hasFatalErrorOccurred() const { return fatalErrorOccurred; }
|
bool hasFatalErrorOccurred() const { return fatalErrorOccurred; }
|
||||||
@@ -646,7 +649,7 @@ namespace swift {
|
|||||||
|
|
||||||
/// Returns a Boolean value indicating whether warnings belonging to the
|
/// Returns a Boolean value indicating whether warnings belonging to the
|
||||||
/// diagnostic group identified by `id` should be escalated to errors.
|
/// diagnostic group identified by `id` should be escalated to errors.
|
||||||
bool getWarningsAsErrorsForDiagGroupID(DiagGroupID id) {
|
bool getWarningsAsErrorsForDiagGroupID(DiagGroupID id) const {
|
||||||
return warningsAsErrors[(unsigned)id];
|
return warningsAsErrors[(unsigned)id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1287,7 +1287,8 @@ llvm::cl::opt<bool> AssertOnError("swift-diagnostics-assert-on-error",
|
|||||||
llvm::cl::opt<bool> AssertOnWarning("swift-diagnostics-assert-on-warning",
|
llvm::cl::opt<bool> AssertOnWarning("swift-diagnostics-assert-on-warning",
|
||||||
llvm::cl::init(false));
|
llvm::cl::init(false));
|
||||||
|
|
||||||
DiagnosticBehavior DiagnosticState::determineBehavior(const Diagnostic &diag) {
|
DiagnosticBehavior
|
||||||
|
DiagnosticState::determineBehavior(const Diagnostic &diag) const {
|
||||||
// We determine how to handle a diagnostic based on the following rules
|
// We determine how to handle a diagnostic based on the following rules
|
||||||
// 1) Map the diagnostic to its "intended" behavior, applying the behavior
|
// 1) Map the diagnostic to its "intended" behavior, applying the behavior
|
||||||
// limit for this particular emission
|
// limit for this particular emission
|
||||||
@@ -1334,21 +1335,23 @@ DiagnosticBehavior DiagnosticState::determineBehavior(const Diagnostic &diag) {
|
|||||||
if (suppressRemarks)
|
if (suppressRemarks)
|
||||||
lvl = DiagnosticBehavior::Ignore;
|
lvl = DiagnosticBehavior::Ignore;
|
||||||
}
|
}
|
||||||
|
return lvl;
|
||||||
|
}
|
||||||
|
|
||||||
// 5) Update current state for use during the next diagnostic
|
void DiagnosticState::updateFor(DiagnosticBehavior behavior) {
|
||||||
if (lvl == DiagnosticBehavior::Fatal) {
|
// Update current state for use during the next diagnostic
|
||||||
|
if (behavior == DiagnosticBehavior::Fatal) {
|
||||||
fatalErrorOccurred = true;
|
fatalErrorOccurred = true;
|
||||||
anyErrorOccurred = true;
|
anyErrorOccurred = true;
|
||||||
} else if (lvl == DiagnosticBehavior::Error) {
|
} else if (behavior == DiagnosticBehavior::Error) {
|
||||||
anyErrorOccurred = true;
|
anyErrorOccurred = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT((!AssertOnError || !anyErrorOccurred) && "We emitted an error?!");
|
ASSERT((!AssertOnError || !anyErrorOccurred) && "We emitted an error?!");
|
||||||
ASSERT((!AssertOnWarning || (lvl != DiagnosticBehavior::Warning)) &&
|
ASSERT((!AssertOnWarning || (behavior != DiagnosticBehavior::Warning)) &&
|
||||||
"We emitted a warning?!");
|
"We emitted a warning?!");
|
||||||
|
|
||||||
previousBehavior = lvl;
|
previousBehavior = behavior;
|
||||||
return lvl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiagnosticEngine::flushActiveDiagnostic() {
|
void DiagnosticEngine::flushActiveDiagnostic() {
|
||||||
@@ -1393,6 +1396,8 @@ std::optional<DiagnosticInfo>
|
|||||||
DiagnosticEngine::diagnosticInfoForDiagnostic(const Diagnostic &diagnostic,
|
DiagnosticEngine::diagnosticInfoForDiagnostic(const Diagnostic &diagnostic,
|
||||||
bool includeDiagnosticName) {
|
bool includeDiagnosticName) {
|
||||||
auto behavior = state.determineBehavior(diagnostic);
|
auto behavior = state.determineBehavior(diagnostic);
|
||||||
|
state.updateFor(behavior);
|
||||||
|
|
||||||
if (behavior == DiagnosticBehavior::Ignore)
|
if (behavior == DiagnosticBehavior::Ignore)
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user