mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-20 13:16:46 +00:00
At present, we typically define a DiagnosticConverter, then store an instance of it and a DiagnosticEmitter that wraps it. This is relatively minor in general, but I've been trying to create more self-contained DiagnosticEmitter classes (which hold their own DiagnosticConverter, similar to NullDiagnosticEmitter), and there it just gets in the way. Since we don't reuse DiagnosticConverter instances, this combines the definition into DiagnosticEmitter. Mainly this means we don't have a separate object in play, and less to carry around. The most impact is probably to SemIRDiagnosticConverter, which was also the most complex. Now `SemIRLocDiagnosticEmitter`, this gets some different construction flow. Note in the PR I've split the file rename to its own commit, to try to help delta views. However, the most substantial parts of the refactoring are split into #4876, which this depends upon.
33 lines
1.1 KiB
C++
33 lines
1.1 KiB
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
|
|
|
|
#ifndef CARBON_TOOLCHAIN_DIAGNOSTICS_FILE_DIAGNOSTICS_H_
|
|
#define CARBON_TOOLCHAIN_DIAGNOSTICS_FILE_DIAGNOSTICS_H_
|
|
|
|
#include "toolchain/diagnostics/diagnostic_emitter.h"
|
|
|
|
namespace Carbon {
|
|
|
|
// We frequently want a `DiagnosticEmitter` that directly uses a filename. Note
|
|
// that an empty string can be used for a diagnostic that has no particular
|
|
// location.
|
|
//
|
|
// Note this provides no way to set a line or column on diagnostics. More
|
|
// specific emitters must be used for that.
|
|
class FileDiagnosticEmitter : public DiagnosticEmitter<llvm::StringRef> {
|
|
public:
|
|
using DiagnosticEmitter::DiagnosticEmitter;
|
|
|
|
protected:
|
|
// Converts a filename directly to the diagnostic location.
|
|
auto ConvertLoc(llvm::StringRef filename, ContextFnT /*context_fn*/) const
|
|
-> ConvertedDiagnosticLoc override {
|
|
return {.loc = {.filename = filename}, .last_byte_offset = -1};
|
|
}
|
|
};
|
|
|
|
} // namespace Carbon
|
|
|
|
#endif // CARBON_TOOLCHAIN_DIAGNOSTICS_FILE_DIAGNOSTICS_H_
|