mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-01 22:02:45 +01:00
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
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/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_
|