Files
carbon-lang/toolchain/diagnostics/file_diagnostics.h
T
Jon Ross-Perkins 45ca3d28f5 Drop "diagnostic" from some filenames in the "diagnostics" folder (#6686)
Mainly because "sorting_diagnostic_consumer" is legacy, since
`SortingDiagnosticConsumer` became `SortingConsumer`. Also better
reflecting contents of these files.

Where I'm not renaming, I'm less positive about dropping "diagnostics"
from "file_diagnostics" and "null_diagnostics" (which contain both a
consumer and emitter, and "null.h" seems like poor naming), so not doing
that here. Also "diagnostic.h" contains `struct Diagnostic`, so is a
decent fit.

Assisted-by: Google Antigravity with Gemini 3 Flash
2026-02-04 17:24:55 +00:00

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/emitter.h"
namespace Carbon::Diagnostics {
// We frequently want a `Emitter` 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 FileEmitter : public Emitter<llvm::StringRef> {
public:
using Emitter::Emitter;
protected:
// Converts a filename directly to the diagnostic location.
auto ConvertLoc(llvm::StringRef filename, ContextFnT /*context_fn*/) const
-> ConvertedLoc override {
return {.loc = {.filename = filename}, .last_byte_offset = -1};
}
};
} // namespace Carbon::Diagnostics
#endif // CARBON_TOOLCHAIN_DIAGNOSTICS_FILE_DIAGNOSTICS_H_