mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
When we crash, include the source location of the parse node that we were handling, as well as the name of the check function that we were calling. Also include the source snippet, since it's easy to do so, and may avoid the need to look at the input file in some cases.
36 lines
966 B
C++
36 lines
966 B
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#include "toolchain/diagnostics/diagnostic_consumer.h"
|
|
|
|
#include <algorithm>
|
|
#include <cstdint>
|
|
|
|
namespace Carbon {
|
|
|
|
auto StreamDiagnosticConsumer::HandleDiagnostic(Diagnostic diagnostic) -> void {
|
|
if (printed_diagnostic_) {
|
|
*stream_ << "\n";
|
|
} else {
|
|
printed_diagnostic_ = true;
|
|
}
|
|
|
|
for (const auto& message : diagnostic.messages) {
|
|
message.loc.FormatLocation(*stream_);
|
|
*stream_ << ": ";
|
|
if (message.level == DiagnosticLevel::Error) {
|
|
*stream_ << "ERROR: ";
|
|
}
|
|
*stream_ << message.format_fn(message) << "\n";
|
|
message.loc.FormatSnippet(*stream_);
|
|
}
|
|
}
|
|
|
|
auto ConsoleDiagnosticConsumer() -> DiagnosticConsumer& {
|
|
static auto* consumer = new StreamDiagnosticConsumer(llvm::errs());
|
|
return *consumer;
|
|
}
|
|
|
|
} // namespace Carbon
|