diff --git a/toolchain/check/BUILD b/toolchain/check/BUILD index 19578e2fbab8..ca72ba77c7a1 100644 --- a/toolchain/check/BUILD +++ b/toolchain/check/BUILD @@ -160,10 +160,10 @@ cc_library( hdrs = ["check.h"], deps = [ ":context", + ":diagnostic_emitter", ":dump", ":impl", ":pointer_dereference", - ":sem_ir_loc_diagnostic_emitter", "//common:check", "//common:error", "//common:map", @@ -287,9 +287,9 @@ cc_library( ) cc_library( - name = "sem_ir_loc_diagnostic_emitter", - srcs = ["sem_ir_loc_diagnostic_emitter.cpp"], - hdrs = ["sem_ir_loc_diagnostic_emitter.h"], + name = "diagnostic_emitter", + srcs = ["diagnostic_emitter.cpp"], + hdrs = ["diagnostic_emitter.h"], deps = [ ":context", "//common:raw_string_ostream", diff --git a/toolchain/check/check.cpp b/toolchain/check/check.cpp index 98e2e65539b0..3c7c434fc6f7 100644 --- a/toolchain/check/check.cpp +++ b/toolchain/check/check.cpp @@ -8,8 +8,8 @@ #include "common/map.h" #include "toolchain/check/check_unit.h" #include "toolchain/check/context.h" +#include "toolchain/check/diagnostic_emitter.h" #include "toolchain/check/diagnostic_helpers.h" -#include "toolchain/check/sem_ir_loc_diagnostic_emitter.h" #include "toolchain/diagnostics/diagnostic.h" #include "toolchain/diagnostics/format_providers.h" #include "toolchain/lex/token_kind.h" diff --git a/toolchain/check/check.h b/toolchain/check/check.h index 43f55031bab3..b983feca7b38 100644 --- a/toolchain/check/check.h +++ b/toolchain/check/check.h @@ -8,7 +8,7 @@ #include "common/ostream.h" #include "toolchain/base/shared_value_stores.h" #include "toolchain/base/timings.h" -#include "toolchain/check/sem_ir_loc_diagnostic_emitter.h" +#include "toolchain/check/diagnostic_emitter.h" #include "toolchain/diagnostics/diagnostic_emitter.h" #include "toolchain/parse/tree_and_subtrees.h" #include "toolchain/sem_ir/file.h" diff --git a/toolchain/check/check_unit.h b/toolchain/check/check_unit.h index a8e0bdaf570d..3010a0615cc0 100644 --- a/toolchain/check/check_unit.h +++ b/toolchain/check/check_unit.h @@ -9,7 +9,7 @@ #include "llvm/ADT/SmallVector.h" #include "toolchain/check/check.h" #include "toolchain/check/context.h" -#include "toolchain/check/sem_ir_loc_diagnostic_emitter.h" +#include "toolchain/check/diagnostic_emitter.h" #include "toolchain/parse/node_ids.h" #include "toolchain/sem_ir/ids.h" @@ -181,7 +181,7 @@ class CheckUnit { llvm::IntrusiveRefCntPtr fs_; llvm::raw_ostream* vlog_stream_; - SemIRLocDiagnosticEmitter emitter_; + DiagnosticEmitter emitter_; Context context_; }; diff --git a/toolchain/check/context.cpp b/toolchain/check/context.cpp index 4bca4f0d51c3..dd9ee8d8c274 100644 --- a/toolchain/check/context.cpp +++ b/toolchain/check/context.cpp @@ -8,7 +8,7 @@ namespace Carbon::Check { -Context::Context(Diagnostics::Emitter* emitter, +Context::Context(DiagnosticEmitterBase* emitter, Parse::GetTreeAndSubtreesFn tree_and_subtrees_getter, SemIR::File* sem_ir, int imported_ir_count, int total_ir_count, llvm::raw_ostream* vlog_stream) diff --git a/toolchain/check/context.h b/toolchain/check/context.h index 22b338888183..bff0ddb45744 100644 --- a/toolchain/check/context.h +++ b/toolchain/check/context.h @@ -13,6 +13,7 @@ #include "toolchain/base/value_store.h" #include "toolchain/check/decl_introducer_state.h" #include "toolchain/check/decl_name_stack.h" +#include "toolchain/check/diagnostic_helpers.h" #include "toolchain/check/full_pattern_stack.h" #include "toolchain/check/generic_region_stack.h" #include "toolchain/check/global_init.h" @@ -50,7 +51,7 @@ namespace Carbon::Check { class Context { public: // Stores references for work. - explicit Context(Diagnostics::Emitter* emitter, + explicit Context(DiagnosticEmitterBase* emitter, Parse::GetTreeAndSubtreesFn tree_and_subtrees_getter, SemIR::File* sem_ir, int imported_ir_count, int total_ir_count, llvm::raw_ostream* vlog_stream); @@ -69,7 +70,7 @@ class Context { return tokens().GetKind(parse_tree().node_token(node_id)); } - auto emitter() -> Diagnostics::Emitter& { return *emitter_; } + auto emitter() -> DiagnosticEmitterBase& { return *emitter_; } auto parse_tree_and_subtrees() -> const Parse::TreeAndSubtrees& { return tree_and_subtrees_getter_(); @@ -276,7 +277,7 @@ class Context { private: // Handles diagnostics. - Diagnostics::Emitter* emitter_; + DiagnosticEmitterBase* emitter_; // Returns a lazily constructed TreeAndSubtrees. Parse::GetTreeAndSubtreesFn tree_and_subtrees_getter_; diff --git a/toolchain/check/sem_ir_loc_diagnostic_emitter.cpp b/toolchain/check/diagnostic_emitter.cpp similarity index 86% rename from toolchain/check/sem_ir_loc_diagnostic_emitter.cpp rename to toolchain/check/diagnostic_emitter.cpp index b4bdf525ffec..448b83468220 100644 --- a/toolchain/check/sem_ir_loc_diagnostic_emitter.cpp +++ b/toolchain/check/diagnostic_emitter.cpp @@ -2,7 +2,7 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#include "toolchain/check/sem_ir_loc_diagnostic_emitter.h" +#include "toolchain/check/diagnostic_emitter.h" #include "common/raw_string_ostream.h" #include "toolchain/sem_ir/absolute_node_id.h" @@ -10,8 +10,7 @@ namespace Carbon::Check { -auto SemIRLocDiagnosticEmitter::ConvertLoc(SemIRLoc loc, - ContextFnT context_fn) const +auto DiagnosticEmitter::ConvertLoc(SemIRLoc loc, ContextFnT context_fn) const -> Diagnostics::ConvertedLoc { auto converted = ConvertLocImpl(loc, context_fn); @@ -33,8 +32,8 @@ auto SemIRLocDiagnosticEmitter::ConvertLoc(SemIRLoc loc, return converted; } -auto SemIRLocDiagnosticEmitter::ConvertLocImpl(SemIRLoc loc, - ContextFnT context_fn) const +auto DiagnosticEmitter::ConvertLocImpl(SemIRLoc loc, + ContextFnT context_fn) const -> Diagnostics::ConvertedLoc { llvm::SmallVector absolute_node_ids = loc.is_inst_id_ ? SemIR::GetAbsoluteNodeId(sem_ir_, loc.inst_id_) @@ -57,16 +56,17 @@ auto SemIRLocDiagnosticEmitter::ConvertLocImpl(SemIRLoc loc, return ConvertLocInFile(final_node_id, loc.token_only_, context_fn); } -auto SemIRLocDiagnosticEmitter::ConvertLocInFile( - SemIR::AbsoluteNodeId absolute_node_id, bool token_only, - ContextFnT /*context_fn*/) const -> Diagnostics::ConvertedLoc { +auto DiagnosticEmitter::ConvertLocInFile(SemIR::AbsoluteNodeId absolute_node_id, + bool token_only, + ContextFnT /*context_fn*/) const + -> Diagnostics::ConvertedLoc { const auto& tree_and_subtrees = tree_and_subtrees_getters_[absolute_node_id.check_ir_id.index](); return tree_and_subtrees.NodeToDiagnosticLoc(absolute_node_id.node_id, token_only); } -auto SemIRLocDiagnosticEmitter::ConvertArg(llvm::Any arg) const -> llvm::Any { +auto DiagnosticEmitter::ConvertArg(llvm::Any arg) const -> llvm::Any { if (auto* library_name_id = llvm::any_cast(&arg)) { std::string library_name; if (*library_name_id == SemIR::LibraryNameId::Default) { @@ -121,7 +121,7 @@ auto SemIRLocDiagnosticEmitter::ConvertArg(llvm::Any arg) const -> llvm::Any { return llvm::APSInt(typed_int->value, !sem_ir_->types().IsSignedInt(typed_int->type)); } - return Diagnostics::Emitter::ConvertArg(arg); + return DiagnosticEmitterBase::ConvertArg(arg); } } // namespace Carbon::Check diff --git a/toolchain/check/sem_ir_loc_diagnostic_emitter.h b/toolchain/check/diagnostic_emitter.h similarity index 87% rename from toolchain/check/sem_ir_loc_diagnostic_emitter.h rename to toolchain/check/diagnostic_emitter.h index 1c562482d9d8..cc1ea61b588a 100644 --- a/toolchain/check/sem_ir_loc_diagnostic_emitter.h +++ b/toolchain/check/diagnostic_emitter.h @@ -2,8 +2,8 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#ifndef CARBON_TOOLCHAIN_CHECK_SEM_IR_LOC_DIAGNOSTIC_EMITTER_H_ -#define CARBON_TOOLCHAIN_CHECK_SEM_IR_LOC_DIAGNOSTIC_EMITTER_H_ +#ifndef CARBON_TOOLCHAIN_CHECK_DIAGNOSTIC_EMITTER_H_ +#define CARBON_TOOLCHAIN_CHECK_DIAGNOSTIC_EMITTER_H_ #include "llvm/ADT/ArrayRef.h" #include "toolchain/check/diagnostic_helpers.h" @@ -17,13 +17,13 @@ namespace Carbon::Check { // Handles the transformation of a SemIRLoc to a DiagnosticLoc. -class SemIRLocDiagnosticEmitter : public Diagnostics::Emitter { +class DiagnosticEmitter : public DiagnosticEmitterBase { public: - explicit SemIRLocDiagnosticEmitter( + explicit DiagnosticEmitter( Diagnostics::Consumer* consumer, llvm::ArrayRef tree_and_subtrees_getters, const SemIR::File* sem_ir) - : Emitter(consumer), + : DiagnosticEmitterBase(consumer), tree_and_subtrees_getters_(tree_and_subtrees_getters), sem_ir_(sem_ir) {} @@ -69,4 +69,4 @@ class SemIRLocDiagnosticEmitter : public Diagnostics::Emitter { } // namespace Carbon::Check -#endif // CARBON_TOOLCHAIN_CHECK_SEM_IR_LOC_DIAGNOSTIC_EMITTER_H_ +#endif // CARBON_TOOLCHAIN_CHECK_DIAGNOSTIC_EMITTER_H_ diff --git a/toolchain/check/diagnostic_helpers.h b/toolchain/check/diagnostic_helpers.h index bbfe37be4d7e..e9cbf68cfa72 100644 --- a/toolchain/check/diagnostic_helpers.h +++ b/toolchain/check/diagnostic_helpers.h @@ -33,7 +33,7 @@ class SemIRLoc { private: // Only allow member access for diagnostics. - friend class SemIRLocDiagnosticEmitter; + friend class DiagnosticEmitter; // And also for eval to unwrap a LocId for calling into the rest of Check. friend class UnwrapSemIRLoc; @@ -46,7 +46,11 @@ class SemIRLoc { bool token_only_; }; -using DiagnosticBuilder = Diagnostics::Emitter::DiagnosticBuilder; +// We define the emitter separately for dependencies, so only provide a base +// here. +using DiagnosticEmitterBase = Diagnostics::Emitter; + +using DiagnosticBuilder = DiagnosticEmitterBase::Builder; // A function that forms a diagnostic for some kind of problem. The // DiagnosticBuilder is returned rather than emitted so that the caller diff --git a/toolchain/check/eval.cpp b/toolchain/check/eval.cpp index 06a133fc071d..0707e44175a4 100644 --- a/toolchain/check/eval.cpp +++ b/toolchain/check/eval.cpp @@ -187,9 +187,7 @@ class EvalContext { auto sem_ir() -> SemIR::File& { return context().sem_ir(); } - auto emitter() -> Diagnostics::Emitter& { - return context().emitter(); - } + auto emitter() -> DiagnosticEmitterBase& { return context().emitter(); } private: // The type-checking context in which we're performing evaluation. diff --git a/toolchain/check/modifiers.cpp b/toolchain/check/modifiers.cpp index 4fe2eddc9448..668de98cb930 100644 --- a/toolchain/check/modifiers.cpp +++ b/toolchain/check/modifiers.cpp @@ -14,7 +14,7 @@ static auto StartDiagnoseNotAllowed( Context& context, const Diagnostics::DiagnosticBase& diagnostic_base, Parse::NodeId modifier_node, Lex::TokenKind declaration_kind) - -> Diagnostics::Emitter::DiagnosticBuilder { + -> DiagnosticBuilder { if constexpr (sizeof...(TokenKinds) == 0) { return context.emitter().Build(modifier_node, diagnostic_base); } else if constexpr (sizeof...(TokenKinds) == 1) { diff --git a/toolchain/diagnostics/diagnostic_emitter.h b/toolchain/diagnostics/diagnostic_emitter.h index eb1077655995..4846cf003099 100644 --- a/toolchain/diagnostics/diagnostic_emitter.h +++ b/toolchain/diagnostics/diagnostic_emitter.h @@ -69,19 +69,18 @@ class Emitter { // expected usage. // This is nodiscard to protect against accidentally building a diagnostic // without emitting it. - class [[nodiscard]] DiagnosticBuilder { + class [[nodiscard]] Builder { public: - // DiagnosticBuilder is move-only and cannot be copied. - DiagnosticBuilder(DiagnosticBuilder&&) noexcept = default; - auto operator=(DiagnosticBuilder&&) noexcept - -> DiagnosticBuilder& = default; + // Builder is move-only and cannot be copied. + Builder(Builder&&) noexcept = default; + auto operator=(Builder&&) noexcept -> Builder& = default; // Adds a note diagnostic attached to the main diagnostic being built. // The API mirrors the main emission API: `Emitter::Emit`. // For the expected usage see the builder API: `Emitter::Build`. template auto Note(LocT loc, const DiagnosticBase& diagnostic_base, - Internal::NoTypeDeduction... args) -> DiagnosticBuilder&; + Internal::NoTypeDeduction... args) -> Builder&; // Emits the built diagnostic and its attached notes. // For the expected usage see the builder API: `Emitter::Build`. @@ -92,7 +91,7 @@ class Emitter { template auto Emit() && -> void; - // Returns true if this DiagnosticBuilder may emit a diagnostic. Can be used + // Returns true if this Builder may emit a diagnostic. Can be used // to avoid excess work computing notes, etc, if no diagnostic is going to // be emitted anyway. explicit operator bool() { return emitter_; } @@ -101,13 +100,13 @@ class Emitter { friend class Emitter; template - explicit DiagnosticBuilder(Emitter* emitter, LocT loc, - const DiagnosticBase& diagnostic_base, - llvm::SmallVector args); + explicit Builder(Emitter* emitter, LocT loc, + const DiagnosticBase& diagnostic_base, + llvm::SmallVector args); - // Create a null `DiagnosticBuilder` that will not emit anything. Notes will + // Create a null `Builder` that will not emit anything. Notes will // be silently ignored. - DiagnosticBuilder() : emitter_(nullptr) {} + Builder() : emitter_(nullptr) {} // Adds a message to the diagnostic, handling conversion of the location and // arguments. @@ -156,11 +155,11 @@ class Emitter { // .Emit(); template auto Build(LocT loc, const DiagnosticBase& diagnostic_base, - Internal::NoTypeDeduction... args) -> DiagnosticBuilder; + Internal::NoTypeDeduction... args) -> Builder; - // Create a null `DiagnosticBuilder` that will not emit anything. Notes will + // Create a null `Builder` that will not emit anything. Notes will // be silently ignored. - auto BuildSuppressed() -> DiagnosticBuilder { return DiagnosticBuilder(); } + auto BuildSuppressed() -> Builder { return Builder(); } protected: // Callback type used to report context messages from ConvertLoc. @@ -189,7 +188,7 @@ class Emitter { friend class AnnotationScope; Consumer* consumer_; - llvm::SmallVectorvoid>> + llvm::SmallVectorvoid>> annotate_fns_; }; @@ -223,7 +222,7 @@ class NoLocEmitter : public Emitter { // be annotated in some way. // // This object is given a function `annotate` that will be called with a -// `DiagnosticBuilder& builder` for any diagnostic that is emitted through the +// `Builder& builder` for any diagnostic that is emitted through the // given emitter. That function can annotate the diagnostic by calling // `builder.Note` to add notes. template @@ -269,9 +268,9 @@ struct DiagnosticTypeForArg : public Arg::DiagnosticType {}; template template -auto Emitter::DiagnosticBuilder::Note( +auto Emitter::Builder::Note( LocT loc, const DiagnosticBase& diagnostic_base, - Internal::NoTypeDeduction... args) -> DiagnosticBuilder& { + Internal::NoTypeDeduction... args) -> Builder& { if (!emitter_) { return *this; } @@ -284,7 +283,7 @@ auto Emitter::DiagnosticBuilder::Note( template template -auto Emitter::DiagnosticBuilder::Emit() & -> void { +auto Emitter::Builder::Emit() & -> void { if (!emitter_) { return; } @@ -301,7 +300,7 @@ concept AlwaysFalse = false; template template -auto Emitter::DiagnosticBuilder::Emit() && -> void { +auto Emitter::Builder::Emit() && -> void { // TODO: This is required by clang-16, but `false` may work in newer clang // versions. Replace when possible. static_assert(Internal::AlwaysFalse, @@ -312,10 +311,9 @@ auto Emitter::DiagnosticBuilder::Emit() && -> void { template template -Emitter::DiagnosticBuilder::DiagnosticBuilder( - Emitter* emitter, LocT loc, - const DiagnosticBase& diagnostic_base, - llvm::SmallVector args) +Emitter::Builder::Builder(Emitter* emitter, LocT loc, + const DiagnosticBase& diagnostic_base, + llvm::SmallVector args) : emitter_(emitter), diagnostic_({.level = diagnostic_base.Level}) { AddMessage(loc, diagnostic_base, std::move(args)); CARBON_CHECK(diagnostic_base.Level != Level::Note); @@ -323,7 +321,7 @@ Emitter::DiagnosticBuilder::DiagnosticBuilder( template template -auto Emitter::DiagnosticBuilder::AddMessage( +auto Emitter::Builder::AddMessage( LocT loc, const DiagnosticBase& diagnostic_base, llvm::SmallVector args) -> void { if (!emitter_) { @@ -343,7 +341,7 @@ auto Emitter::DiagnosticBuilder::AddMessage( template template -auto Emitter::DiagnosticBuilder::AddMessageWithLoc( +auto Emitter::Builder::AddMessageWithLoc( Loc loc, const DiagnosticBase& diagnostic_base, llvm::SmallVector args) -> void { if (!emitter_) { @@ -363,8 +361,8 @@ auto Emitter::DiagnosticBuilder::AddMessageWithLoc( template template -auto Emitter::DiagnosticBuilder::FormatFn( - const Message& message, std::index_sequence /*indices*/) +auto Emitter::Builder::FormatFn(const Message& message, + std::index_sequence /*indices*/) -> std::string { static_assert(sizeof...(Args) == sizeof...(N), "Invalid template args"); CARBON_CHECK(message.format_args.size() == sizeof...(Args), @@ -382,8 +380,7 @@ template auto Emitter::Emit(LocT loc, const DiagnosticBase& diagnostic_base, Internal::NoTypeDeduction... args) -> void { - DiagnosticBuilder builder(this, loc, diagnostic_base, - {MakeAny(args)...}); + Builder builder(this, loc, diagnostic_base, {MakeAny(args)...}); builder.Emit(); } @@ -391,10 +388,8 @@ template template auto Emitter::Build(LocT loc, const DiagnosticBase& diagnostic_base, - Internal::NoTypeDeduction... args) - -> DiagnosticBuilder { - return DiagnosticBuilder(this, loc, diagnostic_base, - {MakeAny(args)...}); + Internal::NoTypeDeduction... args) -> Builder { + return Builder(this, loc, diagnostic_base, {MakeAny(args)...}); } template diff --git a/toolchain/language_server/context.cpp b/toolchain/language_server/context.cpp index 77592405e8cd..f02845a22190 100644 --- a/toolchain/language_server/context.cpp +++ b/toolchain/language_server/context.cpp @@ -19,15 +19,16 @@ namespace Carbon::LanguageServer { +namespace { // A consumer for turning diagnostics into a `textDocument/publishDiagnostics` // notification. // https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_publishDiagnostics -class PublishDiagnosticConsumer : public Diagnostics::Consumer { +class DiagnosticConsumer : public Diagnostics::Consumer { public: // Initializes params with the target file information. - explicit PublishDiagnosticConsumer(Context* context, - const clang::clangd::URIForFile& uri, - std::optional version) + explicit DiagnosticConsumer(Context* context, + const clang::clangd::URIForFile& uri, + std::optional version) : context_(context), params_{.uri = uri, .version = version} {} // Turns a diagnostic into an LSP diagnostic. @@ -98,6 +99,7 @@ class PublishDiagnosticConsumer : public Diagnostics::Consumer { Context* context_; clang::clangd::PublishDiagnosticsParams params_; }; +} // namespace auto Context::File::SetText(Context& context, std::optional version, llvm::StringRef text) -> void { @@ -109,7 +111,7 @@ auto Context::File::SetText(Context& context, std::optional version, source_.reset(); // A consumer to gather diagnostics for the file. - PublishDiagnosticConsumer consumer(&context, uri_, version); + DiagnosticConsumer consumer(&context, uri_, version); // TODO: Make the processing asynchronous, to better handle rapid text // updates. diff --git a/toolchain/lex/string_literal.cpp b/toolchain/lex/string_literal.cpp index f21de09fc6c9..2c4398f9744b 100644 --- a/toolchain/lex/string_literal.cpp +++ b/toolchain/lex/string_literal.cpp @@ -14,7 +14,7 @@ namespace Carbon::Lex { -using LexerDiagnosticEmitter = Diagnostics::Emitter; +using DiagnosticEmitter = Diagnostics::Emitter; static constexpr char MultiLineIndicator[] = R"(''')"; static constexpr char DoubleQuotedMultiLineIndicator[] = R"(""")"; @@ -202,7 +202,7 @@ static auto ComputeIndentOfFinalLine(llvm::StringRef text) -> llvm::StringRef { // Check the literal is indented properly, if it's a multi-line litera. // Find the leading whitespace that should be removed from each line of a // multi-line string literal. -static auto CheckIndent(LexerDiagnosticEmitter& emitter, llvm::StringRef text, +static auto CheckIndent(DiagnosticEmitter& emitter, llvm::StringRef text, llvm::StringRef content) -> llvm::StringRef { // Find the leading horizontal whitespace on the final line of this literal. // Note that for an empty literal, this might not be inside the content. @@ -222,7 +222,7 @@ static auto CheckIndent(LexerDiagnosticEmitter& emitter, llvm::StringRef text, } // Expand a `\u{HHHHHH}` escape sequence into a sequence of UTF-8 code units. -static auto ExpandUnicodeEscapeSequence(LexerDiagnosticEmitter& emitter, +static auto ExpandUnicodeEscapeSequence(DiagnosticEmitter& emitter, llvm::StringRef digits, char*& buffer_cursor) -> bool { unsigned code_point; @@ -279,7 +279,7 @@ static auto AppendFrontOfContents(char*& buffer_cursor, // `result` string. `content` is the string content, starting from the first // character after the escape sequence introducer (for example, the `n` in // `\n`), and will be updated to remove the leading escape sequence. -static auto ExpandAndConsumeEscapeSequence(LexerDiagnosticEmitter& emitter, +static auto ExpandAndConsumeEscapeSequence(DiagnosticEmitter& emitter, llvm::StringRef& content, char*& buffer_cursor) -> void { CARBON_CHECK(!content.empty(), "should have escaped closing delimiter"); @@ -364,7 +364,7 @@ static auto ExpandAndConsumeEscapeSequence(LexerDiagnosticEmitter& emitter, // Expand any escape sequences in the given string literal. static auto ExpandEscapeSequencesAndRemoveIndent( - LexerDiagnosticEmitter& emitter, llvm::StringRef contents, int hash_level, + DiagnosticEmitter& emitter, llvm::StringRef contents, int hash_level, llvm::StringRef indent, char* buffer) -> llvm::StringRef { char* buffer_cursor = buffer; @@ -464,7 +464,7 @@ static auto ExpandEscapeSequencesAndRemoveIndent( } auto StringLiteral::ComputeValue(llvm::BumpPtrAllocator& allocator, - LexerDiagnosticEmitter& emitter) const + DiagnosticEmitter& emitter) const -> llvm::StringRef { if (!is_terminated_) { return ""; diff --git a/toolchain/lower/BUILD b/toolchain/lower/BUILD index af3404d77dc9..de6ff638d71a 100644 --- a/toolchain/lower/BUILD +++ b/toolchain/lower/BUILD @@ -17,7 +17,6 @@ cc_library( hdrs = ["lower.h"], deps = [ ":context", - "//toolchain/check:sem_ir_loc_diagnostic_emitter", "//toolchain/parse:tree", "//toolchain/sem_ir:file", "//toolchain/sem_ir:inst_namer", @@ -50,7 +49,7 @@ cc_library( "//common:raw_string_ostream", "//common:vlog", "//toolchain/base:kind_switch", - "//toolchain/check:sem_ir_loc_diagnostic_emitter", + "//toolchain/parse:tree", "//toolchain/sem_ir:absolute_node_id", "//toolchain/sem_ir:entry_point", "//toolchain/sem_ir:file", diff --git a/toolchain/lower/file_context.h b/toolchain/lower/file_context.h index c748fd4a9770..95c4c841b666 100644 --- a/toolchain/lower/file_context.h +++ b/toolchain/lower/file_context.h @@ -9,7 +9,7 @@ #include "llvm/IR/DIBuilder.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" -#include "toolchain/check/sem_ir_loc_diagnostic_emitter.h" +#include "toolchain/parse/tree_and_subtrees.h" #include "toolchain/sem_ir/file.h" #include "toolchain/sem_ir/ids.h" #include "toolchain/sem_ir/inst_namer.h" diff --git a/toolchain/parse/context.h b/toolchain/parse/context.h index 04bb6a42b1d4..903753705447 100644 --- a/toolchain/parse/context.h +++ b/toolchain/parse/context.h @@ -35,9 +35,10 @@ enum class Lookahead : int32_t { class Context { public: // A token-based emitter for use during parse. - class TokenEmitter : public Diagnostics::Emitter { + class DiagnosticEmitter : public Diagnostics::Emitter { public: - explicit TokenEmitter(Diagnostics::Consumer* consumer, Context* context) + explicit DiagnosticEmitter(Diagnostics::Consumer* consumer, + Context* context) : Emitter(consumer), context_(context) {} protected: @@ -407,7 +408,7 @@ class Context { auto has_errors() const -> bool { return err_tracker_.seen_error(); } - auto emitter() -> TokenEmitter& { return emitter_; } + auto emitter() -> DiagnosticEmitter& { return emitter_; } auto position() -> Lex::TokenIterator& { return position_; } auto position() const -> Lex::TokenIterator { return position_; } @@ -441,7 +442,7 @@ class Context { Lex::TokenizedBuffer* tokens_; Diagnostics::ErrorTrackingConsumer err_tracker_; - TokenEmitter emitter_; + DiagnosticEmitter emitter_; // Whether to print verbose output. llvm::raw_ostream* vlog_stream_;