Move diagnostic helpers from Context to other files (#4949)

Trying to find more specific homes for shared diagnostic function calls.
This commit is contained in:
Jon Ross-Perkins
2025-02-13 18:08:11 +00:00
committed by GitHub
parent 6dda094928
commit e70f9cd71d
14 changed files with 130 additions and 121 deletions
-70
View File
@@ -214,76 +214,6 @@ auto Context::ReplaceInstPreservingConstantValue(SemIR::InstId inst_id,
CARBON_CHECK(old_const_id == new_const_id);
}
auto Context::DiagnoseDuplicateName(SemIRLoc dup_def, SemIRLoc prev_def)
-> void {
CARBON_DIAGNOSTIC(NameDeclDuplicate, Error,
"duplicate name being declared in the same scope");
CARBON_DIAGNOSTIC(NameDeclPrevious, Note, "name is previously declared here");
emitter_->Build(dup_def, NameDeclDuplicate)
.Note(prev_def, NameDeclPrevious)
.Emit();
}
auto Context::DiagnosePoisonedName(SemIR::LocId poisoning_loc_id,
SemIR::LocId decl_name_loc_id) -> void {
CARBON_CHECK(poisoning_loc_id.has_value(),
"Trying to diagnose poisoned name with no poisoning location");
CARBON_DIAGNOSTIC(NameUseBeforeDecl, Error,
"name used before it was declared");
CARBON_DIAGNOSTIC(NameUseBeforeDeclNote, Note, "declared here");
emitter_->Build(poisoning_loc_id, NameUseBeforeDecl)
.Note(decl_name_loc_id, NameUseBeforeDeclNote)
.Emit();
}
auto Context::DiagnoseNameNotFound(SemIRLoc loc, SemIR::NameId name_id)
-> void {
CARBON_DIAGNOSTIC(NameNotFound, Error, "name `{0}` not found", SemIR::NameId);
emitter_->Emit(loc, NameNotFound, name_id);
}
auto Context::NoteAbstractClass(SemIR::ClassId class_id,
DiagnosticBuilder& builder) -> void {
const auto& class_info = classes().Get(class_id);
CARBON_CHECK(
class_info.inheritance_kind == SemIR::Class::InheritanceKind::Abstract,
"Class is not abstract");
CARBON_DIAGNOSTIC(ClassAbstractHere, Note,
"class was declared abstract here");
builder.Note(class_info.definition_id, ClassAbstractHere);
}
auto Context::NoteIncompleteClass(SemIR::ClassId class_id,
DiagnosticBuilder& builder) -> void {
const auto& class_info = classes().Get(class_id);
CARBON_CHECK(!class_info.is_defined(), "Class is not incomplete");
if (class_info.has_definition_started()) {
CARBON_DIAGNOSTIC(ClassIncompleteWithinDefinition, Note,
"class is incomplete within its definition");
builder.Note(class_info.definition_id, ClassIncompleteWithinDefinition);
} else {
CARBON_DIAGNOSTIC(ClassForwardDeclaredHere, Note,
"class was forward declared here");
builder.Note(class_info.latest_decl_id(), ClassForwardDeclaredHere);
}
}
auto Context::NoteUndefinedInterface(SemIR::InterfaceId interface_id,
DiagnosticBuilder& builder) -> void {
const auto& interface_info = interfaces().Get(interface_id);
CARBON_CHECK(!interface_info.is_defined(), "Interface is not incomplete");
if (interface_info.is_being_defined()) {
CARBON_DIAGNOSTIC(InterfaceUndefinedWithinDefinition, Note,
"interface is currently being defined");
builder.Note(interface_info.definition_id,
InterfaceUndefinedWithinDefinition);
} else {
CARBON_DIAGNOSTIC(InterfaceForwardDeclaredHere, Note,
"interface was forward declared here");
builder.Note(interface_info.latest_decl_id(), InterfaceForwardDeclaredHere);
}
}
auto Context::Finalize() -> void {
// Pop information for the file-level scope.
sem_ir().set_top_inst_block_id(inst_block_stack().Pop());